@sentio/sdk 2.15.0-rc.4 → 2.15.0-rc.5
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/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
| @@ -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,C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,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,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,MAAM,CAAA;SACd;QACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,Q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ACnB,WAAmB;IAEnB,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IACnD,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,EAAE,CAAA;IACpC,IAAI,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAA;IAE5B,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;QAC9B,OAAO,MAAM,CAAA;KACd;IAED,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QACnF,MAAM,GAAG,KAAK,CAAA;QAEd,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IACD,IAAI,UAAU,EAAE;QACd,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAEnF,IAAI,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"]}
         | 
    
        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.5",
         | 
| 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.5",
         | 
| 72 | 
            +
                "@sentio/runtime": "^2.15.0-rc.5"
         | 
| 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 | 
            +
            }
         |