@sentio/sdk 2.15.0-rc.2 → 2.15.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/context.d.ts +7 -8
- package/lib/aptos/context.js +10 -7
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +11 -19
- package/lib/aptos/ext/aptos-dex.js +13 -172
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/ext/coin.d.ts +2 -10
- package/lib/aptos/ext/coin.js +0 -3
- package/lib/aptos/ext/coin.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +1 -1
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/ext/coin-list.d.ts +8 -0
- package/lib/move/ext/coin-list.js +2 -0
- package/lib/move/ext/coin-list.js.map +1 -0
- package/lib/move/ext/index.d.ts +2 -0
- package/lib/move/ext/index.js +3 -0
- package/lib/move/ext/index.js.map +1 -0
- package/lib/move/ext/move-dex.d.ts +34 -0
- package/lib/move/ext/move-dex.js +180 -0
- package/lib/move/ext/move-dex.js.map +1 -0
- package/lib/move/index.d.ts +1 -0
- package/lib/move/index.js +1 -0
- package/lib/move/index.js.map +1 -1
- package/lib/move/move-context.d.ts +14 -0
- package/lib/move/move-context.js +12 -0
- package/lib/move/move-context.js.map +1 -0
- package/lib/sui/context.d.ts +9 -8
- package/lib/sui/context.js +11 -6
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/ext/coin.d.ts +14 -0
- package/lib/sui/ext/coin.js +508 -0
- package/lib/sui/ext/coin.js.map +1 -0
- package/lib/sui/ext/move-dex.d.ts +18 -0
- package/lib/sui/ext/move-dex.js +21 -0
- package/lib/sui/ext/move-dex.js.map +1 -0
- package/lib/sui/sui-plugin.d.ts +2 -1
- package/lib/sui/sui-plugin.js +4 -0
- package/lib/sui/sui-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/context.ts +13 -8
- package/src/aptos/ext/aptos-dex.ts +34 -224
- package/src/aptos/ext/coin.ts +2 -11
- package/src/move/abstract-move-coder.ts +1 -1
- package/src/move/ext/coin-list.ts +9 -0
- package/src/move/ext/index.ts +2 -0
- package/src/move/ext/move-dex.ts +255 -0
- package/src/move/index.ts +1 -0
- package/src/move/move-context.ts +18 -0
- package/src/sui/context.ts +26 -8
- package/src/sui/ext/coin.ts +537 -0
- package/src/sui/ext/move-dex.ts +41 -0
- package/src/sui/sui-plugin.ts +5 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAKZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAQxD,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,EAAE;QACpB,iBAAiB,EAAE,EAAE;KACtB,CAAA;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MAAM,QAAQ,GAAa;YACzB,eAAe,EAAE,EAAE;YACnB,gBAAgB,EAAE,EAAE;YACpB,iBAAiB,EAAE,EAAE;SACtB,CAAA;QACD,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,iBAAi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zD,CAAC;IAED,cAAc,CAAC,OAAoB;QACjC,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,WAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: suiProcessor.config.network,\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
|
1
|
+
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAMZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAQ5C,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,EAAE;QACpB,iBAAiB,EAAE,EAAE;KACtB,CAAA;IACD,KAAK,CAAC,KAAK,CAAC,KAAmB;QAC7B,MAAM,YAAY,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MAAM,QAAQ,GAAa;YACzB,eAAe,EAAE,EAAE;YACnB,gBAAgB,EAAE,EAAE;YACpB,iBAAiB,EAAE,EAAE;SACtB,CAAA;QACD,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,Y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AK,WAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\nimport { initCoinList } from './ext/coin.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n async start(start: StartRequest): Promise<void> {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: suiProcessor.config.network,\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.15.0-rc.
|
3
|
+
"version": "2.15.0-rc.4",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -68,8 +68,8 @@
|
|
68
68
|
"typechain": "^8.0.0",
|
69
69
|
"typedoc": "^0.24.1",
|
70
70
|
"yaml": "^2.2.1",
|
71
|
-
"@sentio/protos": "^2.15.0-rc.
|
72
|
-
"@sentio/runtime": "^2.15.0-rc.
|
71
|
+
"@sentio/protos": "^2.15.0-rc.4",
|
72
|
+
"@sentio/runtime": "^2.15.0-rc.4"
|
73
73
|
},
|
74
74
|
"peerDependencies": {
|
75
75
|
"tsup": "npm:@sentio/tsup@^6.7.0"
|
package/src/aptos/context.ts
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
import { RecordMetaData } from '@sentio/protos'
|
2
|
-
import { type Labels,
|
3
|
-
import { Transaction_UserTransaction } from './move-types.js'
|
2
|
+
import { type Labels, normalizeLabels } from '@sentio/sdk'
|
3
|
+
import { Event, MoveModuleBytecode, MoveResource, Transaction_UserTransaction } from './move-types.js'
|
4
4
|
import { AptosNetwork } from './network.js'
|
5
5
|
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
6
6
|
import { Endpoints } from '@sentio/runtime'
|
7
7
|
import { ServerError, Status } from 'nice-grpc'
|
8
8
|
import { AptosClient } from 'aptos-sdk'
|
9
|
+
import { MoveAccountContext, MoveContext } from '../move/index.js'
|
9
10
|
|
10
|
-
export class AptosContext extends
|
11
|
-
address: string
|
12
|
-
network: AptosNetwork
|
11
|
+
export class AptosContext extends MoveContext<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
13
12
|
moduleName: string
|
14
13
|
version: bigint
|
15
14
|
transaction: Transaction_UserTransaction
|
@@ -41,6 +40,10 @@ export class AptosContext extends BaseContext {
|
|
41
40
|
return this.network
|
42
41
|
}
|
43
42
|
|
43
|
+
getTimestamp(): number {
|
44
|
+
return parseInt(this.transaction.timestamp)
|
45
|
+
}
|
46
|
+
|
44
47
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
45
48
|
return {
|
46
49
|
address: this.address,
|
@@ -56,9 +59,7 @@ export class AptosContext extends BaseContext {
|
|
56
59
|
}
|
57
60
|
}
|
58
61
|
|
59
|
-
export class AptosResourcesContext extends
|
60
|
-
address: string
|
61
|
-
network: AptosNetwork
|
62
|
+
export class AptosResourcesContext extends MoveAccountContext<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
62
63
|
version: bigint
|
63
64
|
timestampInMicros: number
|
64
65
|
coder: MoveCoder
|
@@ -76,6 +77,10 @@ export class AptosResourcesContext extends BaseContext {
|
|
76
77
|
return this.network
|
77
78
|
}
|
78
79
|
|
80
|
+
getTimestamp(): number {
|
81
|
+
return this.timestampInMicros
|
82
|
+
}
|
83
|
+
|
79
84
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
80
85
|
return {
|
81
86
|
address: this.address,
|
@@ -1,236 +1,46 @@
|
|
1
|
-
import { Gauge } from '@sentio/sdk'
|
2
1
|
import { BigDecimal } from '@sentio/bigdecimal'
|
3
2
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
4
|
-
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
}
|
13
|
-
|
14
|
-
export
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
tvlByPool: Gauge
|
20
|
-
tvlByCoin: Gauge
|
21
|
-
|
22
|
-
constructor(
|
23
|
-
volume: Gauge,
|
24
|
-
volumeByCoin: Gauge,
|
25
|
-
tvlAll: Gauge,
|
26
|
-
tvlByCoin: Gauge,
|
27
|
-
tvlByPool: Gauge,
|
28
|
-
poolAdaptor: PoolAdaptor<T>
|
29
|
-
) {
|
30
|
-
this.volume = volume
|
31
|
-
this.volumeByCoin = volumeByCoin
|
32
|
-
this.tvlAll = tvlAll
|
33
|
-
this.tvlByPool = tvlByPool
|
34
|
-
this.tvlByCoin = tvlByCoin
|
35
|
-
this.poolAdaptor = poolAdaptor
|
3
|
+
import {
|
4
|
+
AptosResourcesContext,
|
5
|
+
MoveResource,
|
6
|
+
AptosContext,
|
7
|
+
AptosNetwork,
|
8
|
+
MoveModuleBytecode,
|
9
|
+
Event,
|
10
|
+
} from '@sentio/sdk/aptos'
|
11
|
+
import { MoveCoinList, MoveDex, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
|
12
|
+
|
13
|
+
export type PoolAdaptor<T> = MovePoolAdaptor<MoveResource, T>
|
14
|
+
|
15
|
+
export class CoinList implements MoveCoinList {
|
16
|
+
calculateValueInUsd(amount: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<BigDecimal> {
|
17
|
+
return calculateValueInUsd(amount, coinInfo, timestamp)
|
36
18
|
}
|
37
19
|
|
38
|
-
|
39
|
-
|
40
|
-
coinx: string,
|
41
|
-
coiny: string,
|
42
|
-
coinXAmount: bigint,
|
43
|
-
coinYAmount: bigint,
|
44
|
-
extraLabels?: any
|
45
|
-
): Promise<BigDecimal> {
|
46
|
-
let result = BigDecimal(0)
|
47
|
-
|
48
|
-
const whitelistx = whiteListed(coinx)
|
49
|
-
const whitelisty = whiteListed(coiny)
|
50
|
-
if (!whitelistx && !whitelisty) {
|
51
|
-
return result
|
52
|
-
}
|
53
|
-
const coinXInfo = await getCoinInfo(coinx)
|
54
|
-
const coinYInfo = await getCoinInfo(coiny)
|
55
|
-
const timestamp = ctx.transaction.timestamp
|
56
|
-
let resultX = BigDecimal(0)
|
57
|
-
let resultY = BigDecimal(0)
|
58
|
-
const pair = await getPair(coinx, coiny)
|
59
|
-
const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }
|
60
|
-
if (whitelistx) {
|
61
|
-
resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)
|
62
|
-
}
|
63
|
-
if (whitelisty) {
|
64
|
-
resultY = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)
|
65
|
-
}
|
66
|
-
if (resultX.eq(0)) {
|
67
|
-
resultX = BigDecimal(resultY)
|
68
|
-
}
|
69
|
-
if (resultY.eq(0)) {
|
70
|
-
resultY = BigDecimal(resultX)
|
71
|
-
}
|
72
|
-
const total = resultX.plus(resultY)
|
73
|
-
if (total.gt(0)) {
|
74
|
-
this.volume.record(ctx, total, {
|
75
|
-
...baseLabels,
|
76
|
-
bridge: coinXInfo.bridge,
|
77
|
-
})
|
78
|
-
}
|
79
|
-
if (resultX.gt(0)) {
|
80
|
-
this.volumeByCoin.record(ctx, resultX, {
|
81
|
-
coin: coinXInfo.symbol,
|
82
|
-
bridge: coinXInfo.bridge,
|
83
|
-
type: coinXInfo.token_type.type,
|
84
|
-
})
|
85
|
-
}
|
86
|
-
if (resultY.gt(0)) {
|
87
|
-
this.volumeByCoin.record(ctx, resultY, {
|
88
|
-
coin: coinYInfo.symbol,
|
89
|
-
bridge: coinYInfo.bridge,
|
90
|
-
type: coinYInfo.token_type.type,
|
91
|
-
})
|
92
|
-
}
|
93
|
-
result = resultX.plus(resultY).div(2)
|
94
|
-
return result
|
20
|
+
getCoinInfo(type: string): SimpleCoinInfo {
|
21
|
+
return getCoinInfo(type)
|
95
22
|
}
|
96
23
|
|
97
|
-
|
98
|
-
|
99
|
-
ctx: AptosResourcesContext,
|
100
|
-
poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void
|
101
|
-
) {
|
102
|
-
const pools = await ctx.coder.filterAndDecodeResources(this.poolAdaptor.poolType, resources)
|
103
|
-
|
104
|
-
const volumeByCoin = new Map<string, BigDecimal>()
|
105
|
-
const timestamp = ctx.timestampInMicros
|
106
|
-
|
107
|
-
console.log('num of pools: ', pools.length, ctx.version.toString())
|
108
|
-
|
109
|
-
let tvlAllValue = BigDecimal(0)
|
110
|
-
for (const pool of pools) {
|
111
|
-
// savePool(ctx.version, pool.type_arguments)
|
112
|
-
const coinx = pool.type_arguments[0]
|
113
|
-
const coiny = pool.type_arguments[1]
|
114
|
-
const whitelistx = whiteListed(coinx)
|
115
|
-
const whitelisty = whiteListed(coiny)
|
116
|
-
if (!whitelistx && !whitelisty) {
|
117
|
-
continue
|
118
|
-
}
|
119
|
-
|
120
|
-
const pair = await getPair(coinx, coiny)
|
121
|
-
const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)
|
122
|
-
const baseLabels: Record<string, string> = { ...extraLabels, pair }
|
123
|
-
|
124
|
-
const coinXInfo = await getCoinInfo(coinx)
|
125
|
-
const coinYInfo = await getCoinInfo(coiny)
|
126
|
-
|
127
|
-
const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded)
|
128
|
-
const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded)
|
129
|
-
|
130
|
-
let resultX = BigDecimal(0)
|
131
|
-
let resultY = BigDecimal(0)
|
132
|
-
|
133
|
-
if (whitelistx) {
|
134
|
-
resultX = await calculateValueInUsd(coinx_amount, coinXInfo, timestamp)
|
135
|
-
let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type)
|
136
|
-
if (!coinXTotal) {
|
137
|
-
coinXTotal = resultX
|
138
|
-
} else {
|
139
|
-
coinXTotal = coinXTotal.plus(resultX)
|
140
|
-
}
|
141
|
-
volumeByCoin.set(coinXInfo.token_type.type, coinXTotal)
|
142
|
-
}
|
143
|
-
if (whitelisty) {
|
144
|
-
resultY = await calculateValueInUsd(coiny_amount, coinYInfo, timestamp)
|
145
|
-
let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type)
|
146
|
-
if (!coinYTotal) {
|
147
|
-
coinYTotal = resultY
|
148
|
-
} else {
|
149
|
-
coinYTotal = coinYTotal.plus(resultY)
|
150
|
-
}
|
151
|
-
volumeByCoin.set(coinYInfo.token_type.type, coinYTotal)
|
152
|
-
}
|
153
|
-
|
154
|
-
if (resultX.eq(0)) {
|
155
|
-
resultX = BigDecimal(resultY)
|
156
|
-
}
|
157
|
-
if (resultY.eq(0)) {
|
158
|
-
resultY = BigDecimal(resultX)
|
159
|
-
}
|
160
|
-
|
161
|
-
const poolValue = resultX.plus(resultY)
|
162
|
-
|
163
|
-
if (poolValue.isGreaterThan(0)) {
|
164
|
-
this.tvlByPool.record(ctx, poolValue, baseLabels)
|
165
|
-
}
|
166
|
-
tvlAllValue = tvlAllValue.plus(poolValue)
|
167
|
-
}
|
168
|
-
this.tvlAll.record(ctx, tvlAllValue)
|
169
|
-
|
170
|
-
if (poolsHandler) {
|
171
|
-
poolsHandler(pools)
|
172
|
-
}
|
173
|
-
|
174
|
-
for (const [k, v] of volumeByCoin) {
|
175
|
-
const coinInfo = whitelistCoins().get(k)
|
176
|
-
if (!coinInfo) {
|
177
|
-
throw Error('unexpected coin ' + k)
|
178
|
-
}
|
179
|
-
// const price = await getPrice(coinInfo, timestamp)
|
180
|
-
// priceGauge.record(ctx, price, { coin: coinInfo.symbol })
|
181
|
-
if (v.isGreaterThan(0)) {
|
182
|
-
this.tvlByCoin.record(ctx, v, {
|
183
|
-
coin: coinInfo.symbol,
|
184
|
-
bridge: coinInfo.bridge,
|
185
|
-
type: coinInfo.token_type.type,
|
186
|
-
})
|
187
|
-
}
|
188
|
-
}
|
24
|
+
whiteListed(type: string): boolean {
|
25
|
+
return whiteListed(type)
|
189
26
|
}
|
190
|
-
}
|
191
27
|
|
192
|
-
|
193
|
-
|
194
|
-
const coinYInfo = await getCoinInfo(coiny)
|
195
|
-
if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {
|
196
|
-
return `${coinYInfo.symbol}-${coinXInfo.symbol}`
|
28
|
+
whitelistCoins(): Map<string, SimpleCoinInfo> {
|
29
|
+
return whitelistCoins()
|
197
30
|
}
|
198
|
-
return `${coinXInfo.symbol}-${coinYInfo.symbol}`
|
199
31
|
}
|
200
32
|
|
201
|
-
export
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
if (!whitelistx || !whitelisty) {
|
216
|
-
return result
|
217
|
-
}
|
218
|
-
|
219
|
-
if (whitelistx) {
|
220
|
-
const value = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)
|
221
|
-
result = value
|
222
|
-
|
223
|
-
if (!whitelisty) {
|
224
|
-
result = result.plus(value)
|
225
|
-
}
|
226
|
-
}
|
227
|
-
if (whitelisty) {
|
228
|
-
const value = await calculateValueInUsd(coinYAmount, coinYInfo, timestamp)
|
229
|
-
|
230
|
-
if (!whitelistx) {
|
231
|
-
result = result.plus(value)
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
|
-
return result
|
33
|
+
export const AptosCoinList = new CoinList()
|
34
|
+
|
35
|
+
export class AptosDex<T> extends MoveDex<
|
36
|
+
AptosNetwork,
|
37
|
+
MoveModuleBytecode,
|
38
|
+
MoveResource,
|
39
|
+
Event,
|
40
|
+
AptosContext,
|
41
|
+
AptosResourcesContext,
|
42
|
+
T
|
43
|
+
> {
|
44
|
+
coinList = new CoinList()
|
45
|
+
declare poolAdaptor: PoolAdaptor<T>
|
236
46
|
}
|
package/src/aptos/ext/coin.ts
CHANGED
@@ -3,16 +3,10 @@ import fetch from 'node-fetch'
|
|
3
3
|
import { validateAndNormalizeAddress } from '../utils.js'
|
4
4
|
import { SPLITTER } from '../../move/index.js'
|
5
5
|
import { AptosChainId } from '../../core/chain.js'
|
6
|
+
import { SimpleCoinInfo } from '../../move/ext/move-dex.js'
|
6
7
|
|
7
8
|
const WHITELISTED_COINS = new Map<string, SimpleCoinInfo>()
|
8
9
|
|
9
|
-
export interface SimpleCoinInfo {
|
10
|
-
token_type: { type: string; account_address: string }
|
11
|
-
symbol: string
|
12
|
-
decimals: number
|
13
|
-
bridge: string
|
14
|
-
}
|
15
|
-
|
16
10
|
export async function initCoinList() {
|
17
11
|
let list = DEFAULT_LIST
|
18
12
|
try {
|
@@ -81,10 +75,7 @@ export async function getPrice(coinType: string, timestamp: number): Promise<num
|
|
81
75
|
}
|
82
76
|
}
|
83
77
|
|
84
|
-
export async function calculateValueInUsd(n: bigint, coinInfo: SimpleCoinInfo, timestamp: number
|
85
|
-
if (typeof timestamp === 'string') {
|
86
|
-
timestamp = parseInt(timestamp)
|
87
|
-
}
|
78
|
+
export async function calculateValueInUsd(n: bigint, coinInfo: SimpleCoinInfo, timestamp: number) {
|
88
79
|
const price = await getPrice(coinInfo.token_type.type, timestamp)
|
89
80
|
const amount = n.scaleDown(coinInfo.decimals)
|
90
81
|
return amount.multipliedBy(price)
|
@@ -270,7 +270,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
|
|
270
270
|
return this.decodeArray(res, f.return)
|
271
271
|
}
|
272
272
|
|
273
|
-
|
273
|
+
async filterAndDecodeStruct<T, ST extends StructType>(
|
274
274
|
typeMatcher: TypeDescriptor<T>,
|
275
275
|
structsWithTags: ST[]
|
276
276
|
): Promise<DecodedStruct<ST, T>[]> {
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { BigDecimal } from '@sentio/bigdecimal'
|
2
|
+
import { SimpleCoinInfo } from './move-dex.js'
|
3
|
+
|
4
|
+
export interface MoveCoinList {
|
5
|
+
whiteListed(type: string): boolean
|
6
|
+
whitelistCoins(): Map<string, SimpleCoinInfo>
|
7
|
+
getCoinInfo(type: string): SimpleCoinInfo
|
8
|
+
calculateValueInUsd(amount: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<BigDecimal>
|
9
|
+
}
|