@sentio/sdk 2.15.0-rc.2 → 2.15.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/lib/aptos/context.d.ts +7 -8
  2. package/lib/aptos/context.js +10 -7
  3. package/lib/aptos/context.js.map +1 -1
  4. package/lib/aptos/ext/aptos-dex.d.ts +11 -19
  5. package/lib/aptos/ext/aptos-dex.js +13 -172
  6. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  7. package/lib/aptos/ext/coin.d.ts +2 -10
  8. package/lib/aptos/ext/coin.js +0 -3
  9. package/lib/aptos/ext/coin.js.map +1 -1
  10. package/lib/move/abstract-move-coder.d.ts +1 -1
  11. package/lib/move/abstract-move-coder.js.map +1 -1
  12. package/lib/move/ext/coin-list.d.ts +8 -0
  13. package/lib/move/ext/coin-list.js +2 -0
  14. package/lib/move/ext/coin-list.js.map +1 -0
  15. package/lib/move/ext/index.d.ts +2 -0
  16. package/lib/move/ext/index.js +3 -0
  17. package/lib/move/ext/index.js.map +1 -0
  18. package/lib/move/ext/move-dex.d.ts +34 -0
  19. package/lib/move/ext/move-dex.js +180 -0
  20. package/lib/move/ext/move-dex.js.map +1 -0
  21. package/lib/move/index.d.ts +1 -0
  22. package/lib/move/index.js +1 -0
  23. package/lib/move/index.js.map +1 -1
  24. package/lib/move/move-context.d.ts +14 -0
  25. package/lib/move/move-context.js +12 -0
  26. package/lib/move/move-context.js.map +1 -0
  27. package/lib/sui/context.d.ts +9 -8
  28. package/lib/sui/context.js +11 -6
  29. package/lib/sui/context.js.map +1 -1
  30. package/lib/sui/ext/coin.d.ts +14 -0
  31. package/lib/sui/ext/coin.js +508 -0
  32. package/lib/sui/ext/coin.js.map +1 -0
  33. package/lib/sui/ext/move-dex.d.ts +18 -0
  34. package/lib/sui/ext/move-dex.js +21 -0
  35. package/lib/sui/ext/move-dex.js.map +1 -0
  36. package/lib/sui/sui-plugin.d.ts +2 -1
  37. package/lib/sui/sui-plugin.js +4 -0
  38. package/lib/sui/sui-plugin.js.map +1 -1
  39. package/package.json +3 -3
  40. package/src/aptos/context.ts +13 -8
  41. package/src/aptos/ext/aptos-dex.ts +34 -224
  42. package/src/aptos/ext/coin.ts +2 -11
  43. package/src/move/abstract-move-coder.ts +1 -1
  44. package/src/move/ext/coin-list.ts +9 -0
  45. package/src/move/ext/index.ts +2 -0
  46. package/src/move/ext/move-dex.ts +255 -0
  47. package/src/move/index.ts +1 -0
  48. package/src/move/move-context.ts +18 -0
  49. package/src/sui/context.ts +26 -8
  50. package/src/sui/ext/coin.ts +537 -0
  51. package/src/sui/ext/move-dex.ts +41 -0
  52. package/src/sui/sui-plugin.ts +5 -0
@@ -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,S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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"]}
@@ -3,4 +3,5 @@ export * from './types.js';
3
3
  export * from './utils.js';
4
4
  export * from './account.js';
5
5
  export * from './chain-adapter.js';
6
+ export * from './move-context.js';
6
7
  export { MoveFetchConfig } from '@sentio/protos';
package/lib/move/index.js CHANGED
@@ -3,5 +3,6 @@ export * from './types.js';
3
3
  export * from './utils.js';
4
4
  export * from './account.js';
5
5
  export * from './chain-adapter.js';
6
+ export * from './move-context.js';
6
7
  export { MoveFetchConfig } from '@sentio/protos';
7
8
  //# sourceMappingURL=index.js.map
@@ -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;AAElC,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'\n\nexport { MoveFetchConfig } from '@sentio/protos'\n"]}
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"]}
@@ -1,11 +1,10 @@
1
1
  import { RecordMetaData } from '@sentio/protos';
2
- import { type Labels, BaseContext } from '../index.js';
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
- export declare class SuiContext extends BaseContext {
7
- address: string;
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(): any;
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 BaseContext {
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(): any;
27
+ getChainId(): import("../index.js").SuiChainId;
28
28
  getMetaDataInternal(name: string, labels: Labels): RecordMetaData;
29
29
  get client(): JsonRpcProvider;
30
+ getTimestamp(): number;
30
31
  }
@@ -1,11 +1,10 @@
1
- import { BaseContext, normalizeLabels } from '../index.js';
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
- export class SuiContext extends BaseContext {
7
- address;
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 BaseContext {
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
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sui/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEvE,OAAO,EAA+B,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACzF,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;AAE/C,MAAM,OAAO,UAAW,SAAQ,WAAW;IACzC,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,UAAU,CAAQ;IAClB,SAAS,CAAM;IACf,IAAI,CAAQ;IACZ,WAAW,CA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AI,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;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '../index.js'\nimport { SuiNetwork } from './network.js'\nimport { SuiTransactionBlockResponse, JsonRpcProvider, Connection } from '@mysten/sui.js'\nimport { MoveCoder, defaultMoveCoder } from './move-coder.js'\nimport { Endpoints } from '@sentio/runtime'\nimport { ServerError, Status } from 'nice-grpc'\n\nexport class SuiContext extends BaseContext {\n address: string\n network: SuiNetwork\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 as any\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 BaseContext {\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 as any\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"]}
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;IAEhB,YACE,UAAkB,EAClB,OAAmB,EACnB,OAAe,EACf,SAAe,EACf,IAAY,EACZ,WAAwC,EACxC,UAAkB,EAClB,UAA8B;QAE9B,KAAK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Ae,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>;