Skip to content

Commit

Permalink
feat(all): aptos, solana now all in their now package (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Dec 31, 2022
1 parent e7a7edd commit c9f092d
Show file tree
Hide file tree
Showing 80 changed files with 362 additions and 242 deletions.
15 changes: 2 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,9 @@ jobs:
- checkout
- node/install-packages:
pkg-manager: yarn
# - run:
# command: yarn install
# name: Yarn Install
- run:
command: yarn build_all && yarn gen && yarn test || yarn test # TODO remove this hack, understand why test will fail in first run
name: Test SDK
working_directory: packages/sdk
# - run:
# command: yarn build
# name: Build CLI
# working_directory: cli
- run:
command: ./scripts/build-all.sh
name: Build All
command: ./scripts/test-all.sh
name: Build & Test All
- run:
command: sudo npm link
name: Link CLI globally for template testing
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
packages/sdk/src/builtin/*
!packages/sdk/src/builtin/solana
!packages/sdk/src/builtin/aptos/index.ts
!packages/sdk/src/builtin/index.ts

packages/sdk-aptos/src/builtin/
!packages/sdk-aptos/src/builtin/index.ts

node_modules
dist
lib
Expand Down
10 changes: 7 additions & 3 deletions .ls-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ ignore:
- packages/sdk/lib
- packages/sdk/node_modules
- examples
- packages/sdk/src/tests/abis
- packages/sdk/src/tests/types
- packages/sdk/src/tests
- packages/base/lib
- packages/base/node_modules
- packages/protos/lib
- packages/protos/node_modules
- packages/runtime/lib
- packages/runtime/node_modules
- packages/runtime/node_modules
- packages/sdk-aptos/lib
- packages/sdk-aptos/node_modules
- packages/sdk-solana/lib
- packages/sdk-solana/node_modules
- packages/sdk-solana/src/tests
5 changes: 3 additions & 2 deletions examples/aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sentio/example-aptos",
"name": "@sentio-example/aptos",
"license": "Apache-2.0",
"version": "1.0.0",
"private": "true",
Expand All @@ -11,7 +11,8 @@
"cli": "ts-node --files src/cli.ts"
},
"dependencies": {
"@sentio/sdk": "^1.0.0-development"
"@sentio/sdk": "^1.0.0-development",
"@sentio/sdk-aptos": "^1.0.0-development"
},
"devDependencies": {
"@sentio/cli": "^1.0.0"
Expand Down
17 changes: 9 additions & 8 deletions examples/aptos/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { SouffleChefCampaign, CandyMachine } from './types/aptos/souffle'
import { token } from '@sentio/sdk/lib/builtin/aptos/0x3'
import { coin } from '@sentio/sdk/lib/builtin/aptos/0x1'
import { AccountEventTracker, aptos } from '@sentio/sdk'
import { token } from '@sentio/sdk-aptos/lib/builtin/0x3'
import { coin } from '@sentio/sdk-aptos/lib/builtin/0x1'
import { AccountEventTracker } from '@sentio/sdk'
import { AptosNetwork, TYPE_REGISTRY } from '@sentio/sdk-aptos'

const accountTracker = AccountEventTracker.register('pull')

coin.bind({ network: aptos.AptosNetwork.MAIN_NET }).onEventWithdrawEvent((evt, ctx) => {
coin.bind({ network: AptosNetwork.MAIN_NET }).onEventWithdrawEvent((evt, ctx) => {
if (evt.guid.account_address === '0x9c5382a5aa6cd92f38ffa50bd8ec2879833997116499cc5bcd6d4688a962e330') {
ctx.meter.Counter('air_dropped').add(evt.data_typed.amount)
}
ctx.meter.Counter('evt_cnt').add(1)
})

SouffleChefCampaign.bind({ network: aptos.AptosNetwork.TEST_NET, startVersion: 6604913 })
SouffleChefCampaign.bind({ network: AptosNetwork.TEST_NET, startVersion: 6604913 })
.onEntryPullTokenV2((call, ctx) => {
ctx.meter.Counter('call_num').add(1)
ctx.meter.Counter('pulled').add(call.arguments_typed[3])
Expand All @@ -23,19 +24,19 @@ SouffleChefCampaign.bind({ network: aptos.AptosNetwork.TEST_NET, startVersion: 6
ctx.meter.Counter('burned').add(1)
})
.onTransaction((txn, ctx) => {
const events = aptos.TYPE_REGISTRY.filterAndDecodeEvents<token.DepositEvent>('0x3::token::DepositEvent', txn.events)
const events = TYPE_REGISTRY.filterAndDecodeEvents<token.DepositEvent>('0x3::token::DepositEvent', txn.events)
for (const event of events) {
// const depositEventInstance = DEFAULT_TYPE_REGISTRY.decodeEvent(event) as DepositEventInstance
ctx.meter.Counter('deposit_token_count').add(event.data_typed.amount)
}
})

CandyMachine.bind({ network: aptos.AptosNetwork.TEST_NET, startVersion: 6604913 }).onEntryPullToken((call, ctx) => {
CandyMachine.bind({ network: AptosNetwork.TEST_NET, startVersion: 6604913 }).onEntryPullToken((call, ctx) => {
ctx.meter.Counter('pulled').add(call.arguments_typed[2], { coin: call.type_arguments[0] })
})

token
.bind({ network: aptos.AptosNetwork.TEST_NET, startVersion: 282159141 })
.bind({ network: AptosNetwork.TEST_NET, startVersion: 282159141 })
.onEventWithdrawEvent((evt: token.WithdrawEventInstance, ctx) => {
ctx.meter.Counter('with_draw').add(evt.data_typed.amount, { token: evt.data_typed.id.token_data_id.name })
})
2 changes: 1 addition & 1 deletion examples/aurory/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sentio/example-aurory",
"name": "@sentio-example/aurory",
"version": "1.0.0",
"private": "true",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/sui/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sentio/example-sui",
"name": "@sentio-example/sui",
"license": "Apache-2.0",
"version": "1.0.0",
"private": "true",
Expand Down
5 changes: 3 additions & 2 deletions examples/wormhole/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sentio/example-wormhole",
"name": "@sentio-example/wormhole",
"license": "Apache-2.0",
"version": "1.0.0",
"private": "true",
Expand All @@ -10,7 +10,8 @@
"build_all": "yarn lerna run --scope=@sentio/example-wormhole build --include-dependencies"
},
"dependencies": {
"@sentio/sdk": "^1.0.0-development"
"@sentio/sdk": "^1.0.0-development",
"@sentio/sdk-solana": "^1.0.0-development"
},
"devDependencies": {
"@sentio/cli": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/wormhole/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WETH9Processor, WETH9Context } from '@sentio/sdk/lib/builtin/weth9'
import { SPLTokenProcessor } from '@sentio/sdk/lib/builtin/solana'
import { SPLTokenProcessor } from '@sentio/sdk-solana/lib/builtin'

const TOKEN_BRIDGE_ADDRESS = '0x3ee18B2214AFF97000D974cf647E7C347E8fa585'

Expand Down
2 changes: 1 addition & 1 deletion examples/x2y2-complex/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sentio/example-x2y2-complex",
"name": "@sentio-example/x2y2-complex",
"license": "Apache-2.0",
"version": "1.0.0",
"private": "true",
Expand Down
2 changes: 1 addition & 1 deletion examples/x2y2/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@sentio/example-x2y2",
"name": "@sentio-example/x2y2",
"license": "Apache-2.0",
"version": "1.0.0",
"private": "true",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"jest": "^29.0.3",
"lerna": "^6.3.0",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"prettier": "^2.8.1",
"prettier-plugin-sh": "^0.12.8",
"semantic-release": "^19.0.5",
"semantic-release-monorepo": "^7.0.5",
Expand Down
1 change: 1 addition & 0 deletions packages/base/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './plugin'
export * from './state'
export * from './utils'
20 changes: 20 additions & 0 deletions packages/base/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ProcessResult } from '@sentio/protos'

export function mergeProcessResults(results: ProcessResult[]): ProcessResult {
const res = ProcessResult.fromPartial({})

for (const r of results) {
res.counters = res.counters.concat(r.counters)
res.gauges = res.gauges.concat(r.gauges)
res.logs = res.logs.concat(r.logs)
res.events = res.events.concat(r.events)
res.exports = res.exports.concat(r.exports)
}
return res
}

export function errorString(e: Error): string {
return e.stack || e.message
}

export const USER_PROCESSOR = 'user_processor'
4 changes: 2 additions & 2 deletions packages/cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ async function buildProcessorForTarget(onlyGen: boolean) {
await codeGenEthersProcessor(path.join('abis', 'evm'))

// eslint-disable-next-line @typescript-eslint/no-var-requires
const solanaModule = require('@sentio/sdk/lib/solana-codegen/codegen')
const solanaModule = require('@sentio/sdk-solana/lib/codegen/codegen')
solanaModule.codeGenSolanaProcessor(path.join('abis', 'solana'))

// eslint-disable-next-line @typescript-eslint/no-var-requires
const aptosModuole = require('@sentio/sdk/lib/aptos-codegen/codegen')
const aptosModuole = require('@sentio/sdk-aptos/lib/codegen/codegen')
aptosModuole.codeGenAptosProcessor(path.join('abis', 'aptos'))

if (onlyGen) {
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/commands/run-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,19 @@ export async function runCreate(argv: string[]) {
cliVersion = '^' + cliVersion
}

packageJson.dependencies['@sentio/sdk'] = '^' + (await latestVersion('@sentio/sdk'))
const sdkVersion = '^' + (await latestVersion('@sentio/sdk'))
packageJson.dependencies['@sentio/sdk'] = sdkVersion

switch (chainType) {
case 'aptos':
packageJson.dependencies['@sentio/sdk-aptos'] = sdkVersion
break
case 'solana':
packageJson.dependencies['@sentio/sdk-solana'] = sdkVersion
break
default:
}

packageJson.dependencies['@sentio/cli'] = cliVersion
packageJson.name = projectName

Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ module.exports = {
if (/^@(ethersproject|solana|project-serum|nice-grpc).*$/.test(request)) {
return callback(null, 'commonjs ' + request)
}
if (request.startsWith("@sentio/sdk")) {
return callback(null, 'commonjs2 ' + request)
if (/^nice-grpc.*$/.test(request)) {
return callback(null, 'commonjs ' + request)
}
if (/^@sentio\/(sdk|runtime|base|protos).*$/.test(request)) {
return callback(null, 'commonjs ' + request)
}
callback()
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/templates/aptos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"upload": "sentio upload"
},
"dependencies": {
"@sentio/sdk": "^1.0.0-development"
"@sentio/sdk": "^1.0.0-development",
"@sentio/sdk-aptos": "^1.0.0-development"
},
"devDependencies": {
"@types/jest": "^29.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/templates/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"upload": "sentio upload"
},
"dependencies": {
"@sentio/sdk": "^1.0.0-development"
"@sentio/sdk": "^1.0.0-development",
"@sentio/sdk-solana": "^1.0.0-development"
},
"devDependencies": {
"@types/jest": "^29.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/templates/solana/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SPLTokenProcessor } from '@sentio/sdk/lib/builtin/solana'
import { SPLTokenProcessor } from '@sentio/sdk-solana/lib/builtin'

SPLTokenProcessor.bind({
address: 'wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb',
Expand Down
11 changes: 11 additions & 0 deletions packages/sdk-all/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');

// TODO seems not fully ignored
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/lib/", "<rootDir>/templates/"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' } )
};
25 changes: 25 additions & 0 deletions packages/sdk-all/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@sentio/sdk-all",
"license": "Apache-2.0",
"version": "1.0.0",
"scripts": {
"compile": "tsc -p .",
"build": "yarn compile",
"build_all": "yarn lerna run --scope=@sentio/sdk-all build --include-dependencies",
"test": "jest"
},
"dependencies": {
"@sentio/sdk": "^1.0.0",
"@sentio/runtime": "^1.0.0",
"@sentio/sdk-aptos": "^1.0.0",
"@sentio/sdk-solana": "^1.0.0"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"files": [
"{lib,src}",
"!{lib,src}/tests",
"!**/*.test.{js,ts}"
]
}
1 change: 1 addition & 0 deletions packages/sdk-all/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
10 changes: 10 additions & 0 deletions packages/sdk-all/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"inlineSources": true,
"rootDir": "./src",
"baseUrl": "./src",
"outDir": "lib"
},
"exclude": ["lib"]
}
11 changes: 11 additions & 0 deletions packages/sdk-aptos/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const { pathsToModuleNameMapper } = require('ts-jest');
const { compilerOptions } = require('./tsconfig');

// TODO seems not fully ignored
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePathIgnorePatterns: ["<rootDir>/dist/", "<rootDir>/lib/", "<rootDir>/templates/"],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' } )
};
26 changes: 26 additions & 0 deletions packages/sdk-aptos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@sentio/sdk-aptos",
"license": "Apache-2.0",
"version": "1.0.0",
"scripts": {
"compile": "tsc -p .",
"build": "yarn gen && yarn gen_test && yarn compile",
"build_all": "yarn lerna run --scope=@sentio/sdk-aptos build --include-dependencies",
"test": "yarn gen_test && yarn jest",
"gen": "ts-node src/run-codegen.ts src/abis src/builtin",
"gen_test": "ts-node src/run-codegen.ts src/tests/abis src/tests/types"
},
"dependencies": {
"@sentio/sdk": "^1.0.0",
"aptos-sdk": "npm:aptos@^1.3.17",
"prettier": "^2.8.1"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./lib/index.js",
"files": [
"{lib,src}",
"!{lib,src}/tests",
"!**/*.test.{js,ts}"
]
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { createChannel, createClient } from 'nice-grpc'

export function getChainQueryClient(address?: string): AptosQueryClient {
if (!address) {
// @ts-ignore
address = global.ENDPOINTS.chainQueryAPI
}
const channel = createChannel(address)
const channel = createChannel(address!)

return createClient(AptosQueryDefinition, channel)
}
Loading

0 comments on commit c9f092d

Please sign in to comment.