@sentio/sdk 2.15.0-rc.4 → 2.15.0-rc.6
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/ext/aptos-dex.d.ts +1 -0
- package/lib/aptos/ext/aptos-dex.js +4 -1
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/move/ext/move-dex.d.ts +1 -1
- package/lib/move/ext/move-dex.js +22 -22
- package/lib/move/ext/move-dex.js.map +1 -1
- package/lib/sui/ext/move-dex.d.ts +1 -0
- package/lib/sui/ext/move-dex.js +4 -1
- package/lib/sui/ext/move-dex.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +4 -0
- package/lib/sui/sui-processor.js +14 -0
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/ext/aptos-dex.ts +11 -1
- package/src/move/ext/move-dex.ts +30 -29
- package/src/sui/ext/move-dex.ts +11 -1
- package/src/sui/sui-processor.ts +22 -0
@@ -13,3 +13,4 @@ export declare class AptosDex<T> extends MoveDex<AptosNetwork, MoveModuleBytecod
|
|
13
13
|
coinList: CoinList;
|
14
14
|
poolAdaptor: PoolAdaptor<T>;
|
15
15
|
}
|
16
|
+
export declare function getPairValue(ctx: AptosContext, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint): Promise<BigDecimal>;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js';
|
2
|
-
import { MoveDex } from '../../move/ext/index.js';
|
2
|
+
import { MoveDex, moveGetPairValue } from '../../move/ext/index.js';
|
3
3
|
export class CoinList {
|
4
4
|
calculateValueInUsd(amount, coinInfo, timestamp) {
|
5
5
|
return calculateValueInUsd(amount, coinInfo, timestamp);
|
@@ -18,4 +18,7 @@ export const AptosCoinList = new CoinList();
|
|
18
18
|
export class AptosDex extends MoveDex {
|
19
19
|
coinList = new CoinList();
|
20
20
|
}
|
21
|
+
export async function getPairValue(ctx, coinx, coiny, coinXAmount, coinYAmount) {
|
22
|
+
return moveGetPairValue(AptosCoinList, ctx, coinx, coiny, coinXAmount, coinYAmount);
|
23
|
+
}
|
21
24
|
//# sourceMappingURL=aptos-dex.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AASzF,OAAO,EAAgB,OAAO,EAAmC,MAAM,yBAAyB,CAAA;
|
1
|
+
{"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AASzF,OAAO,EAAgB,OAAO,EAAE,gBAAgB,EAAmC,MAAM,yBAAyB,CAAA;AAIlH,MAAM,OAAO,QAAQ;IACnB,mBAAmB,CAAC,MAAc,EAAE,QAAwB,EAAE,SAAiB;QAC7E,OAAO,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;IACzD,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAED,cAAc;QACZ,OAAO,cAAc,EAAE,CAAA;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,QAAQ,EAAE,CAAA;AAE3C,MAAM,OAAO,QAAY,SAAQ,OAQhC;IACC,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAA;CAE1B;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAiB,EACjB,KAAa,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB;IAEnB,OAAO,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;AACrF,CAAC","sourcesContent":["import { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport {\n AptosResourcesContext,\n MoveResource,\n AptosContext,\n AptosNetwork,\n MoveModuleBytecode,\n Event,\n} from '@sentio/sdk/aptos'\nimport { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'\n\nexport type PoolAdaptor<T> = MovePoolAdaptor<MoveResource, T>\n\nexport class CoinList implements MoveCoinList {\n calculateValueInUsd(amount: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<BigDecimal> {\n return calculateValueInUsd(amount, coinInfo, timestamp)\n }\n\n getCoinInfo(type: string): SimpleCoinInfo {\n return getCoinInfo(type)\n }\n\n whiteListed(type: string): boolean {\n return whiteListed(type)\n }\n\n whitelistCoins(): Map<string, SimpleCoinInfo> {\n return whitelistCoins()\n }\n}\n\nexport const AptosCoinList = new CoinList()\n\nexport class AptosDex<T> extends MoveDex<\n AptosNetwork,\n MoveModuleBytecode,\n MoveResource,\n Event,\n AptosContext,\n AptosResourcesContext,\n T\n> {\n coinList = new CoinList()\n declare poolAdaptor: PoolAdaptor<T>\n}\n\nexport async function getPairValue(\n ctx: AptosContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n return moveGetPairValue(AptosCoinList, ctx, coinx, coiny, coinXAmount, coinYAmount)\n}\n"]}
|
@@ -30,5 +30,5 @@ export declare class MoveDex<Network, ModuleType, StructType, EventType, Context
|
|
30
30
|
recordTradingVolume(ctx: ContextType, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint, extraLabels?: any): Promise<BigDecimal>;
|
31
31
|
syncPools(resources: StructType[], ctx: AccountContextType, poolsHandler?: (pools: DecodedStruct<StructType, T>[]) => Promise<void> | void): Promise<void>;
|
32
32
|
getPair(coinx: string, coiny: string): Promise<string>;
|
33
|
-
getPairValue(ctx: ContextType, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint): Promise<BigDecimal>;
|
34
33
|
}
|
34
|
+
export declare function moveGetPairValue<ContextType extends MoveAccountContext<any, any, any>>(coinList: MoveCoinList, ctx: ContextType, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint): Promise<BigDecimal>;
|
package/lib/move/ext/move-dex.js
CHANGED
@@ -151,30 +151,30 @@ export class MoveDex {
|
|
151
151
|
}
|
152
152
|
return `${coinXInfo.symbol}-${coinYInfo.symbol}`;
|
153
153
|
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
154
|
+
}
|
155
|
+
export async function moveGetPairValue(coinList, ctx, coinx, coiny, coinXAmount, coinYAmount) {
|
156
|
+
const whitelistx = coinList.whiteListed(coinx);
|
157
|
+
const whitelisty = coinList.whiteListed(coiny);
|
158
|
+
const coinXInfo = await coinList.getCoinInfo(coinx);
|
159
|
+
const coinYInfo = await coinList.getCoinInfo(coiny);
|
160
|
+
const timestamp = ctx.getTimestamp();
|
161
|
+
let result = BigDecimal(0.0);
|
162
|
+
if (!whitelistx || !whitelisty) {
|
163
|
+
return result;
|
164
|
+
}
|
165
|
+
if (whitelistx) {
|
166
|
+
const value = await coinList.calculateValueInUsd(coinXAmount, coinXInfo, timestamp);
|
167
|
+
result = value;
|
168
|
+
if (!whitelisty) {
|
169
|
+
result = result.plus(value);
|
170
170
|
}
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
171
|
+
}
|
172
|
+
if (whitelisty) {
|
173
|
+
const value = await coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp);
|
174
|
+
if (!whitelistx) {
|
175
|
+
result = result.plus(value);
|
176
176
|
}
|
177
|
-
return result;
|
178
177
|
}
|
178
|
+
return result;
|
179
179
|
}
|
180
180
|
//# sourceMappingURL=move-dex.js.map
|
@@ -1 +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,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,GAAgB,EAChB,KAAa,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB,EACnB,WAAiB;QAEjB,IAAI,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;QAE1B,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACnD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACnD,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;YAC9B,OAAO,M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,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB;QAEnB,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACnD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACnD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACxD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QACxD,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,EAAE,CAAA;QACpC,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;QAE5B,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;YAC9B,OAAO,MAAM,CAAA;SACd;QAED,IAAI,UAAU,EAAE;YACd,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;YACxF,MAAM,GAAG,KAAK,CAAA;YAEd,IAAI,CAAC,UAAU,EAAE;gBACf,MAAM,GAAG,MAAM,CAAC,IAAI,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"]}
|
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,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,GAAgB,EAChB,KAAa,EACb,KAAa,EACb,WAAmB,EAC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CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC","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\nexport async function moveGetPairValue<ContextType extends MoveAccountContext<any, any, any>>(\n coinList: MoveCoinList,\n ctx: ContextType,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n const whitelistx = coinList.whiteListed(coinx)\n const whitelisty = coinList.whiteListed(coiny)\n const coinXInfo = await coinList.getCoinInfo(coinx)\n const coinYInfo = await 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 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 coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n if (!whitelistx) {\n result = result.plus(value)\n }\n }\n\n return result\n}\n"]}
|
@@ -16,3 +16,4 @@ export declare class SuiDex<T> extends MoveDex<SuiNetwork, SuiMovePackage, SuiMo
|
|
16
16
|
coinList: CoinList;
|
17
17
|
poolAdaptor: PoolAdaptor<T>;
|
18
18
|
}
|
19
|
+
export declare function getPairValue(ctx: SuiContext, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint): Promise<BigDecimal>;
|
package/lib/sui/ext/move-dex.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js';
|
2
|
-
import { MoveDex } from '../../move/ext/index.js';
|
2
|
+
import { MoveDex, moveGetPairValue } from '../../move/ext/index.js';
|
3
3
|
export class CoinList {
|
4
4
|
calculateValueInUsd(amount, coinInfo, timestamp) {
|
5
5
|
return calculateValueInUsd(amount, coinInfo, timestamp);
|
@@ -18,4 +18,7 @@ export const SuiCoinList = new CoinList();
|
|
18
18
|
export class SuiDex extends MoveDex {
|
19
19
|
coinList = SuiCoinList;
|
20
20
|
}
|
21
|
+
export async function getPairValue(ctx, coinx, coiny, coinXAmount, coinYAmount) {
|
22
|
+
return moveGetPairValue(SuiCoinList, ctx, coinx, coiny, coinXAmount, coinYAmount);
|
23
|
+
}
|
21
24
|
//# sourceMappingURL=move-dex.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"move-dex.js","sourceRoot":"","sources":["../../../src/sui/ext/move-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAAgB,OAAO,EAAmC,MAAM,yBAAyB,CAAA;
|
1
|
+
{"version":3,"file":"move-dex.js","sourceRoot":"","sources":["../../../src/sui/ext/move-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAAgB,OAAO,EAAE,gBAAgB,EAAmC,MAAM,yBAAyB,CAAA;AAOlH,MAAM,OAAO,QAAQ;IACnB,mBAAmB,CAAC,MAAc,EAAE,QAAwB,EAAE,SAAiB;QAC7E,OAAO,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;IACzD,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAED,WAAW,CAAC,IAAY;QACtB,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC;IAED,cAAc;QACZ,OAAO,cAAc,EAAE,CAAA;IACzB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,QAAQ,EAAE,CAAA;AAEzC,MAAM,OAAO,MAAU,SAAQ,OAQ9B;IACC,QAAQ,GAAG,WAAW,CAAA;CAEvB;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAe,EACf,KAAa,EACb,KAAa,EACb,WAAmB,EACnB,WAAmB;IAEnB,OAAO,gBAAgB,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;AACnF,CAAC","sourcesContent":["import { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'\nimport { SuiMoveObject, SuiMovePackage } from '@mysten/sui.js'\nimport { SuiNetwork } from '../network.js'\nimport { SuiContext, SuiObjectsContext } from '../context.js'\n\nexport type PoolAdaptor<T> = MovePoolAdaptor<SuiMoveObject, T>\n\nexport class CoinList implements MoveCoinList {\n calculateValueInUsd(amount: bigint, coinInfo: SimpleCoinInfo, timestamp: number): Promise<BigDecimal> {\n return calculateValueInUsd(amount, coinInfo, timestamp)\n }\n\n getCoinInfo(type: string): SimpleCoinInfo {\n return getCoinInfo(type)\n }\n\n whiteListed(type: string): boolean {\n return whiteListed(type)\n }\n\n whitelistCoins(): Map<string, SimpleCoinInfo> {\n return whitelistCoins()\n }\n}\n\nexport const SuiCoinList = new CoinList()\n\nexport class SuiDex<T> extends MoveDex<\n SuiNetwork,\n SuiMovePackage,\n SuiMoveObject,\n Event,\n SuiContext,\n SuiObjectsContext,\n T\n> {\n coinList = SuiCoinList\n declare poolAdaptor: PoolAdaptor<T>\n}\n\nexport async function getPairValue(\n ctx: SuiContext,\n coinx: string,\n coiny: string,\n coinXAmount: bigint,\n coinYAmount: bigint\n): Promise<BigDecimal> {\n return moveGetPairValue(SuiCoinList, ctx, coinx, coiny, coinXAmount, coinYAmount)\n}\n"]}
|
@@ -72,4 +72,8 @@ export declare class SuiObjectProcessor extends SuiBaseObjectsProcessor<(self: S
|
|
72
72
|
static bind(options: SuiObjectBindOptions): SuiObjectProcessor;
|
73
73
|
protected doHandle(handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
74
74
|
}
|
75
|
+
export declare class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
76
|
+
static bind(options: SuiObjectBindOptions): SuiObjectProcessor;
|
77
|
+
protected doHandle(handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
78
|
+
}
|
75
79
|
export {};
|
package/lib/sui/sui-processor.js
CHANGED
@@ -227,4 +227,18 @@ export class SuiObjectProcessor extends SuiBaseObjectsProcessor {
|
|
227
227
|
return handler(data.self, data.objects, ctx);
|
228
228
|
}
|
229
229
|
}
|
230
|
+
export class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor {
|
231
|
+
static bind(options) {
|
232
|
+
return new SuiObjectProcessor({
|
233
|
+
address: options.objectId,
|
234
|
+
network: options.network,
|
235
|
+
startCheckpoint: options.startCheckpoint,
|
236
|
+
ownerType: MoveOnIntervalConfig_OwnerType.WRAPPED_OBJECT,
|
237
|
+
baseLabels: options.baseLabels,
|
238
|
+
});
|
239
|
+
}
|
240
|
+
doHandle(handler, data, ctx) {
|
241
|
+
return handler(data.objects, ctx);
|
242
|
+
}
|
243
|
+
}
|
230
244
|
//# sourceMappingURL=sui-processor.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/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AG,CAAC,6BAA6B,GAAG,CAAC,IAAI,gCAAgC,CAAC,CAAA;YAClF,OAAM;SACP;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAqB,EAAE,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IAClF,CAAC;CACF","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n HandleInterval,\n MoveFetchConfig,\n MoveOnIntervalConfig_OwnerType,\n ProcessResult,\n} from '@sentio/protos'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport { SuiNetwork } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport {\n getProgrammableTransaction,\n getTransactionKind,\n MoveCallSuiTransaction,\n SuiEvent,\n SuiMoveObject,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { Labels, PromiseOrVoid } from '../core/index.js'\n// import { dynamic_field } from './builtin/0x2.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startCheckpoint: bigint\n baseLabels?: Labels\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: Labels\n}\n\nexport class SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: { [key: string]: string }\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n coder: MoveCoder\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n public onMoveEvent(\n handler: (event: SuiEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionBlockResponse\n if (!txn.events || !txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn,\n idx,\n processor.config.baseLabels\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n const allFunctionType = new Set(_filters.map((f) => processor.config.address + '::' + f.function))\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionBlockResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx,\n 0,\n processor.config.baseLabels\n )\n if (tx) {\n const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)\n // if (calls.length !== 1) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n // }\n const txKind = getTransactionKind(tx)\n if (!txKind) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')\n }\n const programmableTx = getProgrammableTransaction(txKind)\n\n let matched: MoveCallSuiTransaction\n // TODO potential pass index\n for (const call of calls) {\n if (allFunctionType.has(call.function)) {\n matched = call\n break\n }\n\n const payload = calls[0]\n const decoded = await processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])\n await handler(decoded, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nclass SuiObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOnIntervalConfig_OwnerType\n}\n\nabstract class SuiBaseObjectsProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOnIntervalConfig_OwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n // protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]\n\n protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid\n\n protected onInterval(\n handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.objectHandlers.push({\n handler: async function (data) {\n const ctx = new SuiObjectsContext(\n processor.config.network,\n processor.config.address,\n data.slot,\n data.timestamp || new Date(0),\n processor.config.baseLabels\n )\n await processor.doHandle(handler, data, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: HandlerType,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type\n )\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startCheckpoint: options.startCheckpoint || 0n,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n baseLabels: options.baseLabels,\n }\n}\n\nexport class SuiAddressProcessor extends SuiBaseObjectsProcessor<\n (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiBindOptions): SuiAddressProcessor {\n return new SuiAddressProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS })\n }\n\n protected doHandle(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n// export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {\nexport class SuiObjectProcessor extends SuiBaseObjectsProcessor<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiObjectProcessor {\n return new SuiObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n if (!data.self) {\n console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`)\n return\n }\n return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,eAAe,EACf,8BAA8B,GAE/B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,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ACC,MAAM,CAAC,IAAI,CAAC,OAA6B;QACvC,OAAO,IAAI,kBAAkB,CAAC;YAC5B,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,8BAA8B,CAAC,cAAc;YACxD,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAAwF,EACxF,IAAoB,EACpB,GAAsB;QAEtB,OAAO,OAAO,CAAC,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n HandleInterval,\n MoveFetchConfig,\n MoveOnIntervalConfig_OwnerType,\n ProcessResult,\n} from '@sentio/protos'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport { SuiNetwork } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport {\n getProgrammableTransaction,\n getTransactionKind,\n MoveCallSuiTransaction,\n SuiEvent,\n SuiMoveObject,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { Labels, PromiseOrVoid } from '../core/index.js'\n// import { dynamic_field } from './builtin/0x2.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startCheckpoint: bigint\n baseLabels?: Labels\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: Labels\n}\n\nexport class SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: { [key: string]: string }\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n coder: MoveCoder\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n public onMoveEvent(\n handler: (event: SuiEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionBlockResponse\n if (!txn.events || !txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn,\n idx,\n processor.config.baseLabels\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n const allFunctionType = new Set(_filters.map((f) => processor.config.address + '::' + f.function))\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionBlockResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx,\n 0,\n processor.config.baseLabels\n )\n if (tx) {\n const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)\n // if (calls.length !== 1) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n // }\n const txKind = getTransactionKind(tx)\n if (!txKind) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')\n }\n const programmableTx = getProgrammableTransaction(txKind)\n\n let matched: MoveCallSuiTransaction\n // TODO potential pass index\n for (const call of calls) {\n if (allFunctionType.has(call.function)) {\n matched = call\n break\n }\n\n const payload = calls[0]\n const decoded = await processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])\n await handler(decoded, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nclass SuiObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOnIntervalConfig_OwnerType\n}\n\nabstract class SuiBaseObjectsProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOnIntervalConfig_OwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n // protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]\n\n protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid\n\n protected onInterval(\n handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.objectHandlers.push({\n handler: async function (data) {\n const ctx = new SuiObjectsContext(\n processor.config.network,\n processor.config.address,\n data.slot,\n data.timestamp || new Date(0),\n processor.config.baseLabels\n )\n await processor.doHandle(handler, data, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: HandlerType,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type\n )\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startCheckpoint: options.startCheckpoint || 0n,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n baseLabels: options.baseLabels,\n }\n}\n\nexport class SuiAddressProcessor extends SuiBaseObjectsProcessor<\n (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiBindOptions): SuiAddressProcessor {\n return new SuiAddressProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS })\n }\n\n protected doHandle(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n// export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {\nexport class SuiObjectProcessor extends SuiBaseObjectsProcessor<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiObjectProcessor {\n return new SuiObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n if (!data.self) {\n console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`)\n return\n }\n return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiObjectProcessor {\n return new SuiObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOnIntervalConfig_OwnerType.WRAPPED_OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\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.6",
|
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.6",
|
72
|
+
"@sentio/runtime": "^2.15.0-rc.6"
|
73
73
|
},
|
74
74
|
"peerDependencies": {
|
75
75
|
"tsup": "npm:@sentio/tsup@^6.7.0"
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
MoveModuleBytecode,
|
9
9
|
Event,
|
10
10
|
} from '@sentio/sdk/aptos'
|
11
|
-
import { MoveCoinList, MoveDex, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
|
11
|
+
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
|
12
12
|
|
13
13
|
export type PoolAdaptor<T> = MovePoolAdaptor<MoveResource, T>
|
14
14
|
|
@@ -44,3 +44,13 @@ export class AptosDex<T> extends MoveDex<
|
|
44
44
|
coinList = new CoinList()
|
45
45
|
declare poolAdaptor: PoolAdaptor<T>
|
46
46
|
}
|
47
|
+
|
48
|
+
export async function getPairValue(
|
49
|
+
ctx: AptosContext,
|
50
|
+
coinx: string,
|
51
|
+
coiny: string,
|
52
|
+
coinXAmount: bigint,
|
53
|
+
coinYAmount: bigint
|
54
|
+
): Promise<BigDecimal> {
|
55
|
+
return moveGetPairValue(AptosCoinList, ctx, coinx, coiny, coinXAmount, coinYAmount)
|
56
|
+
}
|
package/src/move/ext/move-dex.ts
CHANGED
@@ -215,41 +215,42 @@ export class MoveDex<
|
|
215
215
|
}
|
216
216
|
return `${coinXInfo.symbol}-${coinYInfo.symbol}`
|
217
217
|
}
|
218
|
+
}
|
218
219
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
220
|
+
export async function moveGetPairValue<ContextType extends MoveAccountContext<any, any, any>>(
|
221
|
+
coinList: MoveCoinList,
|
222
|
+
ctx: ContextType,
|
223
|
+
coinx: string,
|
224
|
+
coiny: string,
|
225
|
+
coinXAmount: bigint,
|
226
|
+
coinYAmount: bigint
|
227
|
+
): Promise<BigDecimal> {
|
228
|
+
const whitelistx = coinList.whiteListed(coinx)
|
229
|
+
const whitelisty = coinList.whiteListed(coiny)
|
230
|
+
const coinXInfo = await coinList.getCoinInfo(coinx)
|
231
|
+
const coinYInfo = await coinList.getCoinInfo(coiny)
|
232
|
+
const timestamp = ctx.getTimestamp()
|
233
|
+
let result = BigDecimal(0.0)
|
232
234
|
|
233
|
-
|
234
|
-
|
235
|
-
|
235
|
+
if (!whitelistx || !whitelisty) {
|
236
|
+
return result
|
237
|
+
}
|
236
238
|
|
237
|
-
|
238
|
-
|
239
|
-
|
239
|
+
if (whitelistx) {
|
240
|
+
const value = await coinList.calculateValueInUsd(coinXAmount, coinXInfo, timestamp)
|
241
|
+
result = value
|
240
242
|
|
241
|
-
|
242
|
-
|
243
|
-
}
|
243
|
+
if (!whitelisty) {
|
244
|
+
result = result.plus(value)
|
244
245
|
}
|
245
|
-
|
246
|
-
|
246
|
+
}
|
247
|
+
if (whitelisty) {
|
248
|
+
const value = await coinList.calculateValueInUsd(coinYAmount, coinYInfo, timestamp)
|
247
249
|
|
248
|
-
|
249
|
-
|
250
|
-
}
|
250
|
+
if (!whitelistx) {
|
251
|
+
result = result.plus(value)
|
251
252
|
}
|
252
|
-
|
253
|
-
return result
|
254
253
|
}
|
254
|
+
|
255
|
+
return result
|
255
256
|
}
|
package/src/sui/ext/move-dex.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { BigDecimal } from '@sentio/bigdecimal'
|
2
2
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
3
|
-
import { MoveCoinList, MoveDex, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
|
3
|
+
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
|
4
4
|
import { SuiMoveObject, SuiMovePackage } from '@mysten/sui.js'
|
5
5
|
import { SuiNetwork } from '../network.js'
|
6
6
|
import { SuiContext, SuiObjectsContext } from '../context.js'
|
@@ -39,3 +39,13 @@ export class SuiDex<T> extends MoveDex<
|
|
39
39
|
coinList = SuiCoinList
|
40
40
|
declare poolAdaptor: PoolAdaptor<T>
|
41
41
|
}
|
42
|
+
|
43
|
+
export async function getPairValue(
|
44
|
+
ctx: SuiContext,
|
45
|
+
coinx: string,
|
46
|
+
coiny: string,
|
47
|
+
coinXAmount: bigint,
|
48
|
+
coinYAmount: bigint
|
49
|
+
): Promise<BigDecimal> {
|
50
|
+
return moveGetPairValue(SuiCoinList, ctx, coinx, coiny, coinXAmount, coinYAmount)
|
51
|
+
}
|
package/src/sui/sui-processor.ts
CHANGED
@@ -351,3 +351,25 @@ export class SuiObjectProcessor extends SuiBaseObjectsProcessor<
|
|
351
351
|
return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)
|
352
352
|
}
|
353
353
|
}
|
354
|
+
|
355
|
+
export class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<
|
356
|
+
(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid
|
357
|
+
> {
|
358
|
+
static bind(options: SuiObjectBindOptions): SuiObjectProcessor {
|
359
|
+
return new SuiObjectProcessor({
|
360
|
+
address: options.objectId,
|
361
|
+
network: options.network,
|
362
|
+
startCheckpoint: options.startCheckpoint,
|
363
|
+
ownerType: MoveOnIntervalConfig_OwnerType.WRAPPED_OBJECT,
|
364
|
+
baseLabels: options.baseLabels,
|
365
|
+
})
|
366
|
+
}
|
367
|
+
|
368
|
+
protected doHandle(
|
369
|
+
handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
370
|
+
data: Data_SuiObject,
|
371
|
+
ctx: SuiObjectsContext
|
372
|
+
): PromiseOrVoid {
|
373
|
+
return handler(data.objects as SuiMoveObject[], ctx)
|
374
|
+
}
|
375
|
+
}
|