@sentio/sdk 2.15.0-rc.1 → 2.15.0-rc.3
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/core/chain.d.ts +2 -0
- package/lib/core/chain.js +1 -0
- package/lib/core/chain.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 +509 -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/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/core/chain.ts +1 -0
- 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 +544 -0
- package/src/sui/ext/move-dex.ts +41 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/move/abstract-move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAiB,SAAS,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAA;AAEpF,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,MAAM,OAAgB,iBAAiB;IAC3B,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;IACnD,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAA;IAC7D,OAAO,CAAS;IAChB,OAAO,CAA+C;IAEtD,YAAsB,OAAgB;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,QAAQ,CAAC,OAAe,EAAE,IAAY;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;IACtD,CAAC;IAIS,YAAY,CAAC,MAA0B;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,2BAA2B,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACxE,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;YACvC,OAAM;SACP;QACD,IAAI,CAAC,aAAa,C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AC,CAAA;QACtE,MAAM,aAAa,GAAG,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAA;QAE1E,IAAI,SAAS,GAAG,SAAS,CAAA;QACzB,IAAI;YACF,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;SAC1D;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,KAAK,CAAC,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;YACpF,mBAAmB;SACpB;QACD,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,aAAa;SAC9B,CAAA;IACH,CAAC;IACD,KAAK,CAAC,WAAW,CAAQ,UAAc,EAAE,IAAuB;QAC9D,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,IAAI,SAAS,EAAE;YAClD,OAAO,UAAiB,CAAA;SACzB;QACD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,IAAI,MAAM,IAAI,UAAU,EAAE;gBACxB,MAAM,YAAY,GAAG,aAAa,CAAE,UAAU,CAAC,IAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC7E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE;oBAClC,OAAO,SAAS,CAAA;iBACjB;aACF;SACF;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC5C,CAAC;CACF","sourcesContent":["import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'\nimport { DecodedStruct, matchType, parseMoveType, TypeDescriptor } from './types.js'\nimport { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { bytesToBigInt } from '../utils/index.js'\nimport { ChainAdapter } from './chain-adapter.js'\n\nexport abstract class AbstractMoveCoder<Network, ModuleType, StructType> {\n protected moduleMapping = new Map<string, InternalMoveModule>()\n private typeMapping = new Map<string, InternalMoveStruct>()\n private funcMapping = new Map<string, InternalMoveFunction>()\n network: Network\n adapter: ChainAdapter<Network, ModuleType, StructType>\n\n protected constructor(network: Network) {\n this.network = network\n }\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n abstract load(module: ModuleType): InternalMoveModule\n\n protected loadInternal(module: InternalMoveModule) {\n const account = this.adapter.validateAndNormalizeAddress(module.address)\n if (this.contains(account, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname({ address: account, name: module.name }), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [account, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposedFunctions) {\n // if (!func.isEntry) {\n // continue\n // }\n const key = [account, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n protected decodeBigInt(data: any): bigint {\n if (Array.isArray(data)) {\n // Only sui function need this, strange\n const bytes = data as number[]\n return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))\n } else {\n return BigInt(data)\n }\n }\n\n protected encodeBigInt(data: bigint): any {\n return '0x' + data.toString(16)\n }\n\n private requestMap = new Map<string, Promise<InternalMoveModule>>()\n\n async getMoveStruct(type: string): Promise<InternalMoveStruct> {\n const [account_, module, typeName] = type.split(SPLITTER)\n const account = this.adapter.validateAndNormalizeAddress(account_)\n type = [account, module, typeName].join(SPLITTER)\n\n let struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n async getMoveFunction(type: string): Promise<InternalMoveFunction> {\n const [account_, module, typeName] = type.split(SPLITTER)\n const account = this.adapter.validateAndNormalizeAddress(account_)\n type = [account, module, typeName].join(SPLITTER)\n\n let func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n protected async decode<T>(data: any, type: TypeDescriptor<T>): Promise<T> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n return this.decodeBigInt(data) as any\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(await this.decode(entry, type.typeArgs[0]))\n }\n return res as any\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const fieldValue = this.adapter.getData(data)[field.name]\n const value = await this.decode(fieldValue, filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n protected async encode(data: any, type: TypeDescriptor): Promise<any> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n case 'u256':\n case 'U256':\n return this.encodeBigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.encode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = await this.encode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n async decodeArray(entries: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entriesDecoded: any[] = []\n for (const [idx, arg] of entries.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entriesDecoded.push(await this.decode(arg, argType))\n } catch (e) {\n throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\n }\n }\n return entriesDecoded\n }\n\n async encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entries: any[] = []\n for (const [idx, arg] of entriesDecoded.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entries.push(await this.encode(arg, argType))\n } catch (e) {\n throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\n }\n }\n return entries\n }\n\n async encodeCallArgs(args: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.encodeArray(args, this.adapter.getMeaningfulFunctionParams(f.params))\n }\n\n async decodeCallResult(res: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.decodeArray(res, f.return)\n }\n\n protected async filterAndDecodeStruct<T, ST extends StructType>(\n typeMatcher: TypeDescriptor<T>,\n structsWithTags: ST[]\n ): Promise<DecodedStruct<ST, T>[]> {\n if (!structsWithTags) {\n return [] as any\n }\n // const typeMatcherDescriptor = parseMoveType(typeMatcher)\n const results: DecodedStruct<ST, T>[] = []\n for (const resource of structsWithTags) {\n const resourceType = this.adapter.getType(resource)\n const resourceTypeDescriptor = parseMoveType(resourceType)\n if (!matchType(typeMatcher, resourceTypeDescriptor)) {\n continue\n }\n\n const result = await this.decodedStruct<T, ST>(resource)\n if (result) {\n results.push(result)\n } else {\n console.error('decoding error')\n }\n }\n return results\n }\n\n protected async decodedStruct<T, ST extends StructType>(typeStruct: ST): Promise<DecodedStruct<ST, T> | undefined> {\n const typeDescriptor = parseMoveType(this.adapter.getType(typeStruct))\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = await this.decode(typeStruct, typeDescriptor)\n } catch (e) {\n throw Error('Decoding error for struct' + JSON.stringify(typeStruct) + e.toString())\n // return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n }\n }\n async decodedType<T, ST>(typeStruct: ST, type: TypeDescriptor<T>): Promise<T | undefined> {\n if (typeStruct === null || typeStruct == undefined) {\n return typeStruct as any\n }\n if (typeof typeStruct === 'object') {\n if ('type' in typeStruct) {\n const typeInStruct = parseMoveType((typeStruct.type as any).toString() || '')\n if (!matchType(type, typeInStruct)) {\n return undefined\n }\n }\n }\n\n return await this.decode(typeStruct, type)\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/move/abstract-move-coder.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,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;YACpF,mBAAmB;SACpB;QACD,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,aAAa;SAC9B,CAAA;IACH,CAAC;IACD,KAAK,CAAC,WAAW,CAAQ,UAAc,EAAE,IAAuB;QAC9D,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,IAAI,SAAS,EAAE;YAClD,OAAO,UAAiB,CAAA;SACzB;QACD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,IAAI,MAAM,IAAI,UAAU,EAAE;gBACxB,MAAM,YAAY,GAAG,aAAa,CAAE,UAAU,CAAC,IAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC7E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE;oBAClC,OAAO,SAAS,CAAA;iBACjB;aACF;SACF;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC5C,CAAC;CACF","sourcesContent":["import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'\nimport { DecodedStruct, matchType, parseMoveType, TypeDescriptor } from './types.js'\nimport { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { bytesToBigInt } from '../utils/index.js'\nimport { ChainAdapter } from './chain-adapter.js'\n\nexport abstract class AbstractMoveCoder<Network, ModuleType, StructType> {\n protected moduleMapping = new Map<string, InternalMoveModule>()\n private typeMapping = new Map<string, InternalMoveStruct>()\n private funcMapping = new Map<string, InternalMoveFunction>()\n network: Network\n adapter: ChainAdapter<Network, ModuleType, StructType>\n\n protected constructor(network: Network) {\n this.network = network\n }\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n abstract load(module: ModuleType): InternalMoveModule\n\n protected loadInternal(module: InternalMoveModule) {\n const account = this.adapter.validateAndNormalizeAddress(module.address)\n if (this.contains(account, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname({ address: account, name: module.name }), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [account, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposedFunctions) {\n // if (!func.isEntry) {\n // continue\n // }\n const key = [account, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n protected decodeBigInt(data: any): bigint {\n if (Array.isArray(data)) {\n // Only sui function need this, strange\n const bytes = data as number[]\n return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))\n } else {\n return BigInt(data)\n }\n }\n\n protected encodeBigInt(data: bigint): any {\n return '0x' + data.toString(16)\n }\n\n private requestMap = new Map<string, Promise<InternalMoveModule>>()\n\n async getMoveStruct(type: string): Promise<InternalMoveStruct> {\n const [account_, module, typeName] = type.split(SPLITTER)\n const account = this.adapter.validateAndNormalizeAddress(account_)\n type = [account, module, typeName].join(SPLITTER)\n\n let struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n async getMoveFunction(type: string): Promise<InternalMoveFunction> {\n const [account_, module, typeName] = type.split(SPLITTER)\n const account = this.adapter.validateAndNormalizeAddress(account_)\n type = [account, module, typeName].join(SPLITTER)\n\n let func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n protected async decode<T>(data: any, type: TypeDescriptor<T>): Promise<T> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n return this.decodeBigInt(data) as any\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(await this.decode(entry, type.typeArgs[0]))\n }\n return res as any\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const fieldValue = this.adapter.getData(data)[field.name]\n const value = await this.decode(fieldValue, filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n protected async encode(data: any, type: TypeDescriptor): Promise<any> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n case 'u256':\n case 'U256':\n return this.encodeBigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.encode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = await this.encode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n async decodeArray(entries: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entriesDecoded: any[] = []\n for (const [idx, arg] of entries.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entriesDecoded.push(await this.decode(arg, argType))\n } catch (e) {\n throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\n }\n }\n return entriesDecoded\n }\n\n async encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entries: any[] = []\n for (const [idx, arg] of entriesDecoded.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entries.push(await this.encode(arg, argType))\n } catch (e) {\n throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\n }\n }\n return entries\n }\n\n async encodeCallArgs(args: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.encodeArray(args, this.adapter.getMeaningfulFunctionParams(f.params))\n }\n\n async decodeCallResult(res: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.decodeArray(res, f.return)\n }\n\n async filterAndDecodeStruct<T, ST extends StructType>(\n typeMatcher: TypeDescriptor<T>,\n structsWithTags: ST[]\n ): Promise<DecodedStruct<ST, T>[]> {\n if (!structsWithTags) {\n return [] as any\n }\n // const typeMatcherDescriptor = parseMoveType(typeMatcher)\n const results: DecodedStruct<ST, T>[] = []\n for (const resource of structsWithTags) {\n const resourceType = this.adapter.getType(resource)\n const resourceTypeDescriptor = parseMoveType(resourceType)\n if (!matchType(typeMatcher, resourceTypeDescriptor)) {\n continue\n }\n\n const result = await this.decodedStruct<T, ST>(resource)\n if (result) {\n results.push(result)\n } else {\n console.error('decoding error')\n }\n }\n return results\n }\n\n protected async decodedStruct<T, ST extends StructType>(typeStruct: ST): Promise<DecodedStruct<ST, T> | undefined> {\n const typeDescriptor = parseMoveType(this.adapter.getType(typeStruct))\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = await this.decode(typeStruct, typeDescriptor)\n } catch (e) {\n throw Error('Decoding error for struct' + JSON.stringify(typeStruct) + e.toString())\n // return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n }\n }\n async decodedType<T, ST>(typeStruct: ST, type: TypeDescriptor<T>): Promise<T | undefined> {\n if (typeStruct === null || typeStruct == undefined) {\n return typeStruct as any\n }\n if (typeof typeStruct === 'object') {\n if ('type' in typeStruct) {\n const typeInStruct = parseMoveType((typeStruct.type as any).toString() || '')\n if (!matchType(type, typeInStruct)) {\n return undefined\n }\n }\n }\n\n return await this.decode(typeStruct, type)\n }\n}\n"]}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { BigDecimal } from '@sentio/bigdecimal';
|
2
|
+
import { SimpleCoinInfo } from './move-dex.js';
|
3
|
+
export interface MoveCoinList {
|
4
|
+
whiteListed(type: string): boolean;
|
5
|
+
whitelistCoins(): Map<string, SimpleCoinInfo>;
|
6
|
+
getCoinInfo(type: string): SimpleCoinInfo;
|
7
|
+
calculateValueInUsd(amount: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<BigDecimal>;
|
8
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"coin-list.js","sourceRoot":"","sources":["../../../src/move/ext/coin-list.ts"],"names":[],"mappings":"","sourcesContent":["import { BigDecimal } from '@sentio/bigdecimal'\nimport { SimpleCoinInfo } from './move-dex.js'\n\nexport interface MoveCoinList {\n whiteListed(type: string): boolean\n whitelistCoins(): Map<string, SimpleCoinInfo>\n getCoinInfo(type: string): SimpleCoinInfo\n calculateValueInUsd(amount: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<BigDecimal>\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/move/ext/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA","sourcesContent":["export * from './coin-list.js'\nexport * from './move-dex.js'\n"]}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { DecodedStruct, TypeDescriptor } from '../types.js';
|
2
|
+
import { BigDecimal } from '@sentio/bigdecimal';
|
3
|
+
import { Gauge } from '../../core/index.js';
|
4
|
+
import { MoveAccountContext, MoveContext } from '../move-context.js';
|
5
|
+
import { MoveCoinList } from './coin-list.js';
|
6
|
+
export interface SimpleCoinInfo {
|
7
|
+
token_type: {
|
8
|
+
type: string;
|
9
|
+
account_address: string;
|
10
|
+
};
|
11
|
+
symbol: string;
|
12
|
+
decimals: number;
|
13
|
+
bridge: string;
|
14
|
+
}
|
15
|
+
export interface MovePoolAdaptor<StructType, T> {
|
16
|
+
getXReserve(pool: T): bigint;
|
17
|
+
getYReserve(pool: T): bigint;
|
18
|
+
getExtraPoolTags(pool: DecodedStruct<StructType, T>): any;
|
19
|
+
poolType: TypeDescriptor<T>;
|
20
|
+
}
|
21
|
+
export declare class MoveDex<Network, ModuleType, StructType, EventType, ContextType extends MoveContext<Network, ModuleType, StructType | EventType>, AccountContextType extends MoveAccountContext<Network, ModuleType, StructType | EventType>, T> {
|
22
|
+
coinList: MoveCoinList;
|
23
|
+
poolAdaptor: MovePoolAdaptor<StructType, T>;
|
24
|
+
volume: Gauge;
|
25
|
+
volumeByCoin: Gauge;
|
26
|
+
tvlAll: Gauge;
|
27
|
+
tvlByPool: Gauge;
|
28
|
+
tvlByCoin: Gauge;
|
29
|
+
constructor(volume: Gauge, volumeByCoin: Gauge, tvlAll: Gauge, tvlByCoin: Gauge, tvlByPool: Gauge, poolAdaptor: MovePoolAdaptor<StructType, T>);
|
30
|
+
recordTradingVolume(ctx: ContextType, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint, extraLabels?: any): Promise<BigDecimal>;
|
31
|
+
syncPools(resources: StructType[], ctx: AccountContextType, poolsHandler?: (pools: DecodedStruct<StructType, T>[]) => Promise<void> | void): Promise<void>;
|
32
|
+
getPair(coinx: string, coiny: string): Promise<string>;
|
33
|
+
getPairValue(ctx: ContextType, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint): Promise<BigDecimal>;
|
34
|
+
}
|
@@ -0,0 +1,180 @@
|
|
1
|
+
import { BigDecimal } from '@sentio/bigdecimal';
|
2
|
+
export class MoveDex {
|
3
|
+
coinList;
|
4
|
+
poolAdaptor;
|
5
|
+
volume;
|
6
|
+
volumeByCoin;
|
7
|
+
tvlAll;
|
8
|
+
tvlByPool;
|
9
|
+
tvlByCoin;
|
10
|
+
constructor(volume, volumeByCoin, tvlAll, tvlByCoin, tvlByPool, poolAdaptor) {
|
11
|
+
this.volume = volume;
|
12
|
+
this.volumeByCoin = volumeByCoin;
|
13
|
+
this.tvlAll = tvlAll;
|
14
|
+
this.tvlByPool = tvlByPool;
|
15
|
+
this.tvlByCoin = tvlByCoin;
|
16
|
+
this.poolAdaptor = poolAdaptor;
|
17
|
+
}
|
18
|
+
async recordTradingVolume(ctx, coinx, coiny, coinXAmount, coinYAmount, extraLabels) {
|
19
|
+
let result = BigDecimal(0);
|
20
|
+
const whitelistx = this.coinList.whiteListed(coinx);
|
21
|
+
const whitelisty = this.coinList.whiteListed(coiny);
|
22
|
+
if (!whitelistx && !whitelisty) {
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
const coinXInfo = await this.coinList.getCoinInfo(coinx);
|
26
|
+
const coinYInfo = await this.coinList.getCoinInfo(coiny);
|
27
|
+
const timestamp = ctx.getTimestamp();
|
28
|
+
let resultX = BigDecimal(0);
|
29
|
+
let resultY = BigDecimal(0);
|
30
|
+
const pair = await this.getPair(coinx, coiny);
|
31
|
+
const baseLabels = extraLabels ? { ...extraLabels, pair } : { pair };
|
32
|
+
if (whitelistx) {
|
33
|
+
resultX = await this.coinList.calculateValueInUsd(coinXAmount, coinXInfo, timestamp);
|
34
|
+
}
|
35
|
+
if (whitelisty) {
|
36
|
+
resultY = await this.coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp);
|
37
|
+
}
|
38
|
+
if (resultX.eq(0)) {
|
39
|
+
resultX = BigDecimal(resultY);
|
40
|
+
}
|
41
|
+
if (resultY.eq(0)) {
|
42
|
+
resultY = BigDecimal(resultX);
|
43
|
+
}
|
44
|
+
const total = resultX.plus(resultY);
|
45
|
+
if (total.gt(0)) {
|
46
|
+
this.volume.record(ctx, total, {
|
47
|
+
...baseLabels,
|
48
|
+
bridge: coinXInfo.bridge,
|
49
|
+
});
|
50
|
+
}
|
51
|
+
if (resultX.gt(0)) {
|
52
|
+
this.volumeByCoin.record(ctx, resultX, {
|
53
|
+
coin: coinXInfo.symbol,
|
54
|
+
bridge: coinXInfo.bridge,
|
55
|
+
type: coinXInfo.token_type.type,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
if (resultY.gt(0)) {
|
59
|
+
this.volumeByCoin.record(ctx, resultY, {
|
60
|
+
coin: coinYInfo.symbol,
|
61
|
+
bridge: coinYInfo.bridge,
|
62
|
+
type: coinYInfo.token_type.type,
|
63
|
+
});
|
64
|
+
}
|
65
|
+
result = resultX.plus(resultY).div(2);
|
66
|
+
return result;
|
67
|
+
}
|
68
|
+
async syncPools(resources, ctx, poolsHandler) {
|
69
|
+
const pools = await ctx.coder.filterAndDecodeStruct(this.poolAdaptor.poolType, resources);
|
70
|
+
const volumeByCoin = new Map();
|
71
|
+
const timestamp = ctx.getTimestamp();
|
72
|
+
console.log('num of pools: ', pools.length, timestamp);
|
73
|
+
let tvlAllValue = BigDecimal(0);
|
74
|
+
for (const pool of pools) {
|
75
|
+
// savePool(ctx.version, pool.type_arguments)
|
76
|
+
const coinx = pool.type_arguments[0];
|
77
|
+
const coiny = pool.type_arguments[1];
|
78
|
+
const whitelistx = this.coinList.whiteListed(coinx);
|
79
|
+
const whitelisty = this.coinList.whiteListed(coiny);
|
80
|
+
if (!whitelistx && !whitelisty) {
|
81
|
+
continue;
|
82
|
+
}
|
83
|
+
const pair = await this.getPair(coinx, coiny);
|
84
|
+
const extraLabels = this.poolAdaptor.getExtraPoolTags(pool);
|
85
|
+
const baseLabels = { ...extraLabels, pair };
|
86
|
+
const coinXInfo = await this.coinList.getCoinInfo(coinx);
|
87
|
+
const coinYInfo = await this.coinList.getCoinInfo(coiny);
|
88
|
+
const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded);
|
89
|
+
const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded);
|
90
|
+
let resultX = BigDecimal(0);
|
91
|
+
let resultY = BigDecimal(0);
|
92
|
+
if (whitelistx) {
|
93
|
+
resultX = await this.coinList.calculateValueInUsd(coinx_amount, coinXInfo, timestamp);
|
94
|
+
let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type);
|
95
|
+
if (!coinXTotal) {
|
96
|
+
coinXTotal = resultX;
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
coinXTotal = coinXTotal.plus(resultX);
|
100
|
+
}
|
101
|
+
volumeByCoin.set(coinXInfo.token_type.type, coinXTotal);
|
102
|
+
}
|
103
|
+
if (whitelisty) {
|
104
|
+
resultY = await this.coinList.calculateValueInUsd(coiny_amount, coinYInfo, timestamp);
|
105
|
+
let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type);
|
106
|
+
if (!coinYTotal) {
|
107
|
+
coinYTotal = resultY;
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
coinYTotal = coinYTotal.plus(resultY);
|
111
|
+
}
|
112
|
+
volumeByCoin.set(coinYInfo.token_type.type, coinYTotal);
|
113
|
+
}
|
114
|
+
if (resultX.eq(0)) {
|
115
|
+
resultX = BigDecimal(resultY);
|
116
|
+
}
|
117
|
+
if (resultY.eq(0)) {
|
118
|
+
resultY = BigDecimal(resultX);
|
119
|
+
}
|
120
|
+
const poolValue = resultX.plus(resultY);
|
121
|
+
if (poolValue.isGreaterThan(0)) {
|
122
|
+
this.tvlByPool.record(ctx, poolValue, baseLabels);
|
123
|
+
}
|
124
|
+
tvlAllValue = tvlAllValue.plus(poolValue);
|
125
|
+
}
|
126
|
+
this.tvlAll.record(ctx, tvlAllValue);
|
127
|
+
if (poolsHandler) {
|
128
|
+
poolsHandler(pools);
|
129
|
+
}
|
130
|
+
for (const [k, v] of volumeByCoin) {
|
131
|
+
const coinInfo = this.coinList.whitelistCoins().get(k);
|
132
|
+
if (!coinInfo) {
|
133
|
+
throw Error('unexpected coin ' + k);
|
134
|
+
}
|
135
|
+
// const price = await getPrice(coinInfo, timestamp)
|
136
|
+
// priceGauge.record(ctx, price, { coin: coinInfo.symbol })
|
137
|
+
if (v.isGreaterThan(0)) {
|
138
|
+
this.tvlByCoin.record(ctx, v, {
|
139
|
+
coin: coinInfo.symbol,
|
140
|
+
bridge: coinInfo.bridge,
|
141
|
+
type: coinInfo.token_type.type,
|
142
|
+
});
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
async getPair(coinx, coiny) {
|
147
|
+
const coinXInfo = await this.coinList.getCoinInfo(coinx);
|
148
|
+
const coinYInfo = await this.coinList.getCoinInfo(coiny);
|
149
|
+
if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {
|
150
|
+
return `${coinYInfo.symbol}-${coinXInfo.symbol}`;
|
151
|
+
}
|
152
|
+
return `${coinXInfo.symbol}-${coinYInfo.symbol}`;
|
153
|
+
}
|
154
|
+
async getPairValue(ctx, coinx, coiny, coinXAmount, coinYAmount) {
|
155
|
+
const whitelistx = this.coinList.whiteListed(coinx);
|
156
|
+
const whitelisty = this.coinList.whiteListed(coiny);
|
157
|
+
const coinXInfo = await this.coinList.getCoinInfo(coinx);
|
158
|
+
const coinYInfo = await this.coinList.getCoinInfo(coiny);
|
159
|
+
const timestamp = ctx.getTimestamp();
|
160
|
+
let result = BigDecimal(0.0);
|
161
|
+
if (!whitelistx || !whitelisty) {
|
162
|
+
return result;
|
163
|
+
}
|
164
|
+
if (whitelistx) {
|
165
|
+
const value = await this.coinList.calculateValueInUsd(coinXAmount, coinXInfo, timestamp);
|
166
|
+
result = value;
|
167
|
+
if (!whitelisty) {
|
168
|
+
result = result.plus(value);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
if (whitelisty) {
|
172
|
+
const value = await this.coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp);
|
173
|
+
if (!whitelistx) {
|
174
|
+
result = result.plus(value);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
return result;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
//# sourceMappingURL=move-dex.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"move-dex.js","sourceRoot":"","sources":["../../../src/move/ext/move-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAsB/C,MAAM,OAAO,OAAO;IASlB,QAAQ,CAAc;IACtB,WAAW,CAAgC;IAC3C,MAAM,CAAO;IACb,YAAY,CAAO;IACnB,MAAM,CAAO;IACb,SAAS,CAAO;IAChB,SAAS,CAAO;IAEhB,YACE,MAAa,EACb,YAAmB,EACnB,MAAa,EACb,SAAgB,EAChB,SAAgB,EAChB,WAA2C;QAE3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,SAAS,GAA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,CAAC,KAAK,CAAC,CAAA;aAC5B;SACF;QACD,IAAI,UAAU,EAAE;YACd,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;YAExF,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;aAC5B;SACF;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { DecodedStruct, TypeDescriptor } from '../types.js'\nimport { BigDecimal } from '@sentio/bigdecimal'\nimport { Gauge } from '../../core/index.js'\nimport { MoveAccountContext, MoveContext } from '../move-context.js'\nimport { MoveCoinList } from './coin-list.js'\n\nexport interface SimpleCoinInfo {\n token_type: { type: string; account_address: string }\n symbol: string\n decimals: number\n bridge: string\n}\n\nexport interface MovePoolAdaptor<StructType, T> {\n getXReserve(pool: T): bigint\n\n getYReserve(pool: T): bigint\n\n getExtraPoolTags(pool: DecodedStruct<StructType, T>): any\n\n poolType: TypeDescriptor<T>\n}\n\nexport class MoveDex<\n Network,\n ModuleType,\n StructType,\n EventType,\n ContextType extends MoveContext<Network, ModuleType, StructType | EventType>,\n AccountContextType extends MoveAccountContext<Network, ModuleType, StructType | EventType>,\n T\n> {\n coinList: MoveCoinList\n poolAdaptor: MovePoolAdaptor<StructType, T>\n volume: Gauge\n volumeByCoin: Gauge\n tvlAll: Gauge\n tvlByPool: Gauge\n tvlByCoin: Gauge\n\n constructor(\n volume: Gauge,\n volumeByCoin: Gauge,\n tvlAll: Gauge,\n tvlByCoin: Gauge,\n tvlByPool: Gauge,\n poolAdaptor: MovePoolAdaptor<StructType, T>\n ) {\n this.volume = volume\n this.volumeByCoin = volumeByCoin\n this.tvlAll = tvlAll\n this.tvlByPool = tvlByPool\n this.tvlByCoin = tvlByCoin\n this.poolAdaptor = poolAdaptor\n }\n\n async recordTradingVolume(\n ctx: ContextType,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint,\n extraLabels?: any\n ): Promise<BigDecimal> {\n let result = BigDecimal(0)\n\n const whitelistx = this.coinList.whiteListed(coinx)\n const whitelisty = this.coinList.whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n return result\n }\n const coinXInfo = await this.coinList.getCoinInfo(coinx)\n const coinYInfo = await this.coinList.getCoinInfo(coiny)\n const timestamp = ctx.getTimestamp()\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n const pair = await this.getPair(coinx, coiny)\n const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n if (whitelistx) {\n resultX = await this.coinList.calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n }\n if (whitelisty) {\n resultY = await this.coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n }\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n const total = resultX.plus(resultY)\n if (total.gt(0)) {\n this.volume.record(ctx, total, {\n ...baseLabels,\n bridge: coinXInfo.bridge,\n })\n }\n if (resultX.gt(0)) {\n this.volumeByCoin.record(ctx, resultX, {\n coin: coinXInfo.symbol,\n bridge: coinXInfo.bridge,\n type: coinXInfo.token_type.type,\n })\n }\n if (resultY.gt(0)) {\n this.volumeByCoin.record(ctx, resultY, {\n coin: coinYInfo.symbol,\n bridge: coinYInfo.bridge,\n type: coinYInfo.token_type.type,\n })\n }\n result = resultX.plus(resultY).div(2)\n return result\n }\n\n async syncPools(\n resources: StructType[],\n ctx: AccountContextType,\n poolsHandler?: (pools: DecodedStruct<StructType, T>[]) => Promise<void> | void\n ) {\n const pools = await ctx.coder.filterAndDecodeStruct(this.poolAdaptor.poolType, resources)\n\n const volumeByCoin = new Map<string, BigDecimal>()\n const timestamp = ctx.getTimestamp()\n\n console.log('num of pools: ', pools.length, timestamp)\n\n let tvlAllValue = BigDecimal(0)\n for (const pool of pools) {\n // savePool(ctx.version, pool.type_arguments)\n const coinx = pool.type_arguments[0]\n const coiny = pool.type_arguments[1]\n const whitelistx = this.coinList.whiteListed(coinx)\n const whitelisty = this.coinList.whiteListed(coiny)\n if (!whitelistx && !whitelisty) {\n continue\n }\n\n const pair = await this.getPair(coinx, coiny)\n const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n const coinXInfo = await this.coinList.getCoinInfo(coinx)\n const coinYInfo = await this.coinList.getCoinInfo(coiny)\n\n const coinx_amount = this.poolAdaptor.getXReserve(pool.data_decoded)\n const coiny_amount = this.poolAdaptor.getYReserve(pool.data_decoded)\n\n let resultX = BigDecimal(0)\n let resultY = BigDecimal(0)\n\n if (whitelistx) {\n resultX = await this.coinList.calculateValueInUsd(coinx_amount, coinXInfo, timestamp)\n let coinXTotal = volumeByCoin.get(coinXInfo.token_type.type)\n if (!coinXTotal) {\n coinXTotal = resultX\n } else {\n coinXTotal = coinXTotal.plus(resultX)\n }\n volumeByCoin.set(coinXInfo.token_type.type, coinXTotal)\n }\n if (whitelisty) {\n resultY = await this.coinList.calculateValueInUsd(coiny_amount, coinYInfo, timestamp)\n let coinYTotal = volumeByCoin.get(coinYInfo.token_type.type)\n if (!coinYTotal) {\n coinYTotal = resultY\n } else {\n coinYTotal = coinYTotal.plus(resultY)\n }\n volumeByCoin.set(coinYInfo.token_type.type, coinYTotal)\n }\n\n if (resultX.eq(0)) {\n resultX = BigDecimal(resultY)\n }\n if (resultY.eq(0)) {\n resultY = BigDecimal(resultX)\n }\n\n const poolValue = resultX.plus(resultY)\n\n if (poolValue.isGreaterThan(0)) {\n this.tvlByPool.record(ctx, poolValue, baseLabels)\n }\n tvlAllValue = tvlAllValue.plus(poolValue)\n }\n this.tvlAll.record(ctx, tvlAllValue)\n\n if (poolsHandler) {\n poolsHandler(pools)\n }\n\n for (const [k, v] of volumeByCoin) {\n const coinInfo = this.coinList.whitelistCoins().get(k)\n if (!coinInfo) {\n throw Error('unexpected coin ' + k)\n }\n // const price = await getPrice(coinInfo, timestamp)\n // priceGauge.record(ctx, price, { coin: coinInfo.symbol })\n if (v.isGreaterThan(0)) {\n this.tvlByCoin.record(ctx, v, {\n coin: coinInfo.symbol,\n bridge: coinInfo.bridge,\n type: coinInfo.token_type.type,\n })\n }\n }\n }\n\n async getPair(coinx: string, coiny: string): Promise<string> {\n const coinXInfo = await this.coinList.getCoinInfo(coinx)\n const coinYInfo = await this.coinList.getCoinInfo(coiny)\n if (coinXInfo.symbol.localeCompare(coinYInfo.symbol) > 0) {\n return `${coinYInfo.symbol}-${coinXInfo.symbol}`\n }\n return `${coinXInfo.symbol}-${coinYInfo.symbol}`\n }\n\n async getPairValue(\n ctx: ContextType,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n ): Promise<BigDecimal> {\n const whitelistx = this.coinList.whiteListed(coinx)\n const whitelisty = this.coinList.whiteListed(coiny)\n const coinXInfo = await this.coinList.getCoinInfo(coinx)\n const coinYInfo = await this.coinList.getCoinInfo(coiny)\n const timestamp = ctx.getTimestamp()\n let result = BigDecimal(0.0)\n\n if (!whitelistx || !whitelisty) {\n return result\n }\n\n if (whitelistx) {\n const value = await this.coinList.calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n result = value\n\n if (!whitelisty) {\n result = result.plus(value)\n }\n }\n if (whitelisty) {\n const value = await this.coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n if (!whitelistx) {\n result = result.plus(value)\n }\n }\n\n return result\n }\n}\n"]}
|
package/lib/move/index.d.ts
CHANGED
package/lib/move/index.js
CHANGED
package/lib/move/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/move/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/move/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA","sourcesContent":["export * from './filter.js'\nexport * from './types.js'\nexport * from './utils.js'\nexport * from './account.js'\nexport * from './chain-adapter.js'\nexport * from './move-context.js'\n\nexport { MoveFetchConfig } from '@sentio/protos'\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { BaseContext } from '../core/index.js';
|
2
|
+
import { AbstractMoveCoder } from './abstract-move-coder.js';
|
3
|
+
export declare abstract class MoveContext<Network, ModuleType, StructType> extends BaseContext {
|
4
|
+
address: string;
|
5
|
+
coder: AbstractMoveCoder<Network, ModuleType, StructType>;
|
6
|
+
network: Network;
|
7
|
+
abstract getTimestamp(): number;
|
8
|
+
}
|
9
|
+
export declare abstract class MoveAccountContext<Network, ModuleType, StructType> extends BaseContext {
|
10
|
+
address: string;
|
11
|
+
coder: AbstractMoveCoder<Network, ModuleType, StructType>;
|
12
|
+
network: Network;
|
13
|
+
abstract getTimestamp(): number;
|
14
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { BaseContext } from '../core/index.js';
|
2
|
+
export class MoveContext extends BaseContext {
|
3
|
+
address;
|
4
|
+
coder;
|
5
|
+
network;
|
6
|
+
}
|
7
|
+
export class MoveAccountContext extends BaseContext {
|
8
|
+
address;
|
9
|
+
coder;
|
10
|
+
network;
|
11
|
+
}
|
12
|
+
//# sourceMappingURL=move-context.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"move-context.js","sourceRoot":"","sources":["../../src/move/move-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG9C,MAAM,OAAgB,WAA6C,SAAQ,WAAW;IACpF,OAAO,CAAQ;IACf,KAAK,CAAoD;IACzD,OAAO,CAAS;CAGjB;AAED,MAAM,OAAgB,kBAAoD,SAAQ,WAAW;IAC3F,OAAO,CAAQ;IACf,KAAK,CAAoD;IACzD,OAAO,CAAS;CAGjB","sourcesContent":["import { BaseContext } from '../core/index.js'\nimport { AbstractMoveCoder } from './abstract-move-coder.js'\n\nexport abstract class MoveContext<Network, ModuleType, StructType> extends BaseContext {\n address: string\n coder: AbstractMoveCoder<Network, ModuleType, StructType>\n network: Network\n\n abstract getTimestamp(): number\n}\n\nexport abstract class MoveAccountContext<Network, ModuleType, StructType> extends BaseContext {\n address: string\n coder: AbstractMoveCoder<Network, ModuleType, StructType>\n network: Network\n\n abstract getTimestamp(): number\n}\n"]}
|
package/lib/sui/context.d.ts
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
import { RecordMetaData } from '@sentio/protos';
|
2
|
-
import { type Labels
|
2
|
+
import { type Labels } from '../index.js';
|
3
3
|
import { SuiNetwork } from './network.js';
|
4
|
-
import { SuiTransactionBlockResponse, JsonRpcProvider } from '@mysten/sui.js';
|
4
|
+
import { SuiTransactionBlockResponse, JsonRpcProvider, SuiEvent, SuiMoveNormalizedModule, SuiMoveObject } from '@mysten/sui.js';
|
5
5
|
import { MoveCoder } from './move-coder.js';
|
6
|
-
|
7
|
-
|
8
|
-
network: SuiNetwork;
|
6
|
+
import { MoveAccountContext, MoveContext } from '../move/index.js';
|
7
|
+
export declare class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
9
8
|
moduleName: string;
|
10
9
|
timestamp: Date;
|
11
10
|
slot: bigint;
|
@@ -13,18 +12,20 @@ export declare class SuiContext extends BaseContext {
|
|
13
12
|
eventIndex: number;
|
14
13
|
coder: MoveCoder;
|
15
14
|
constructor(moduleName: string, network: SuiNetwork, address: string, timestamp: Date, slot: bigint, transaction: SuiTransactionBlockResponse, eventIndex: number, baseLabels: Labels | undefined);
|
16
|
-
getChainId():
|
15
|
+
getChainId(): import("../index.js").SuiChainId;
|
16
|
+
getTimestamp(): number;
|
17
17
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData;
|
18
18
|
get client(): JsonRpcProvider;
|
19
19
|
}
|
20
|
-
export declare class SuiObjectsContext extends
|
20
|
+
export declare class SuiObjectsContext extends MoveAccountContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
21
21
|
address: string;
|
22
22
|
network: SuiNetwork;
|
23
23
|
slot: bigint;
|
24
24
|
timestamp: Date;
|
25
25
|
coder: MoveCoder;
|
26
26
|
constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date, baseLabels: Labels | undefined);
|
27
|
-
getChainId():
|
27
|
+
getChainId(): import("../index.js").SuiChainId;
|
28
28
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData;
|
29
29
|
get client(): JsonRpcProvider;
|
30
|
+
getTimestamp(): number;
|
30
31
|
}
|
package/lib/sui/context.js
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import { JsonRpcProvider, Connection } from '@mysten/sui.js';
|
1
|
+
import { normalizeLabels } from '../index.js';
|
2
|
+
import { JsonRpcProvider, Connection, } from '@mysten/sui.js';
|
3
3
|
import { defaultMoveCoder } from './move-coder.js';
|
4
4
|
import { Endpoints } from '@sentio/runtime';
|
5
5
|
import { ServerError, Status } from 'nice-grpc';
|
6
|
-
|
7
|
-
|
8
|
-
network;
|
6
|
+
import { MoveAccountContext, MoveContext } from '../move/index.js';
|
7
|
+
export class SuiContext extends MoveContext {
|
9
8
|
moduleName;
|
10
9
|
timestamp;
|
11
10
|
slot;
|
@@ -28,6 +27,9 @@ export class SuiContext extends BaseContext {
|
|
28
27
|
getChainId() {
|
29
28
|
return this.network;
|
30
29
|
}
|
30
|
+
getTimestamp() {
|
31
|
+
return this.timestamp.getDate();
|
32
|
+
}
|
31
33
|
getMetaDataInternal(name, labels) {
|
32
34
|
return {
|
33
35
|
address: this.address,
|
@@ -49,7 +51,7 @@ export class SuiContext extends BaseContext {
|
|
49
51
|
return new JsonRpcProvider(new Connection({ fullnode: chainServer }));
|
50
52
|
}
|
51
53
|
}
|
52
|
-
export class SuiObjectsContext extends
|
54
|
+
export class SuiObjectsContext extends MoveAccountContext {
|
53
55
|
address;
|
54
56
|
network;
|
55
57
|
slot;
|
@@ -86,5 +88,8 @@ export class SuiObjectsContext extends BaseContext {
|
|
86
88
|
}
|
87
89
|
return new JsonRpcProvider(new Connection({ fullnode: chainServer }));
|
88
90
|
}
|
91
|
+
getTimestamp() {
|
92
|
+
return this.timestamp.getDate();
|
93
|
+
}
|
89
94
|
}
|
90
95
|
//# sourceMappingURL=context.js.map
|
package/lib/sui/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sui/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sui/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,eAAe,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAEL,eAAe,EACf,UAAU,GAIX,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAa,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAElE,MAAM,OAAO,UAAW,SAAQ,WAA0E;IACxG,UAAU,CAAQ;IAClB,SAAS,CAAM;IACf,IAAI,CAAQ;IACZ,WAAW,CAA6B;IACxC,UAAU,CAAQ;IAClB,KAAK,CAAW;IA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C,WAAW,EAAE;YAChB,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAA;SACpE;QACD,OAAO,IAAI,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;IACvE,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;IACjC,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, normalizeLabels } from '../index.js'\nimport { SuiNetwork } from './network.js'\nimport {\n SuiTransactionBlockResponse,\n JsonRpcProvider,\n Connection,\n SuiEvent,\n SuiMoveNormalizedModule,\n SuiMoveObject,\n} from '@mysten/sui.js'\nimport { MoveCoder, defaultMoveCoder } from './move-coder.js'\nimport { Endpoints } from '@sentio/runtime'\nimport { ServerError, Status } from 'nice-grpc'\nimport { MoveAccountContext, MoveContext } from '../move/index.js'\n\nexport class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n moduleName: string\n timestamp: Date\n slot: bigint\n transaction: SuiTransactionBlockResponse\n eventIndex: number\n coder: MoveCoder\n\n constructor(\n moduleName: string,\n network: SuiNetwork,\n address: string,\n timestamp: Date,\n slot: bigint,\n transaction: SuiTransactionBlockResponse,\n eventIndex: number,\n baseLabels: Labels | undefined\n ) {\n super(baseLabels)\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.timestamp = timestamp\n this.slot = slot\n this.eventIndex = eventIndex\n this.coder = defaultMoveCoder(network)\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId() {\n return this.network\n }\n\n getTimestamp(): number {\n return this.timestamp.getDate()\n }\n\n getMetaDataInternal(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: this.transaction?.digest || '', // TODO\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n\n get client(): JsonRpcProvider {\n const chainServer = Endpoints.INSTANCE.chainServer.get(this.network)\n if (!chainServer) {\n throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')\n }\n return new JsonRpcProvider(new Connection({ fullnode: chainServer }))\n }\n}\n\nexport class SuiObjectsContext extends MoveAccountContext<\n SuiNetwork,\n SuiMoveNormalizedModule,\n SuiEvent | SuiMoveObject\n> {\n address: string\n network: SuiNetwork\n slot: bigint\n timestamp: Date\n coder: MoveCoder\n\n constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date, baseLabels: Labels | undefined) {\n super(baseLabels)\n this.address = address\n this.network = network\n this.slot = slot\n this.timestamp = timestamp\n this.coder = defaultMoveCoder(network)\n }\n\n getChainId() {\n return this.network\n }\n\n getMetaDataInternal(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'objects',\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n\n get client(): JsonRpcProvider {\n const chainServer = Endpoints.INSTANCE.chainServer.get(this.network)\n if (!chainServer) {\n throw new ServerError(Status.INTERNAL, 'RPC endpoint not provided')\n }\n return new JsonRpcProvider(new Connection({ fullnode: chainServer }))\n }\n\n getTimestamp(): number {\n return this.timestamp.getDate()\n }\n}\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { SimpleCoinInfo } from '../../move/ext/index.js';
|
2
|
+
export declare function initCoinList(): Promise<void>;
|
3
|
+
export interface SuiCoinInfo {
|
4
|
+
network: string;
|
5
|
+
address: string;
|
6
|
+
symbol: string;
|
7
|
+
name: string;
|
8
|
+
decimals: number;
|
9
|
+
}
|
10
|
+
export declare function whitelistCoins(): Map<string, SimpleCoinInfo>;
|
11
|
+
export declare function whiteListed(coin: string): boolean;
|
12
|
+
export declare function getCoinInfo(type: string): SimpleCoinInfo;
|
13
|
+
export declare function getPrice(coinType: string, timestamp: number): Promise<number>;
|
14
|
+
export declare function calculateValueInUsd(n: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<import("@sentio/bigdecimal").BigDecimal>;
|