@sentio/sdk 2.7.3 → 2.7.4-rc.1
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.
| 
         @@ -10,11 +10,11 @@ export interface PoolAdaptor<T> { 
     | 
|
| 
       10 
10 
     | 
    
         
             
            export declare class AptosDex<T> {
         
     | 
| 
       11 
11 
     | 
    
         
             
                poolAdaptor: PoolAdaptor<T>;
         
     | 
| 
       12 
12 
     | 
    
         
             
                volume: Gauge;
         
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
      
 13 
     | 
    
         
            +
                volumeByCoin: Gauge;
         
     | 
| 
       14 
14 
     | 
    
         
             
                tvlAll: Gauge;
         
     | 
| 
       15 
15 
     | 
    
         
             
                tvlByPool: Gauge;
         
     | 
| 
       16 
16 
     | 
    
         
             
                tvlByCoin: Gauge;
         
     | 
| 
       17 
     | 
    
         
            -
                constructor(volume: Gauge, tvlAll: Gauge, tvlByCoin: Gauge, tvlByPool: Gauge, poolAdaptor: PoolAdaptor<T>);
         
     | 
| 
      
 17 
     | 
    
         
            +
                constructor(volume: Gauge, volumeByCoin: Gauge, tvlAll: Gauge, tvlByCoin: Gauge, tvlByPool: Gauge, poolAdaptor: PoolAdaptor<T>);
         
     | 
| 
       18 
18 
     | 
    
         
             
                recordTradingVolume(ctx: AptosContext, coinx: string, coiny: string, coinXAmount: bigint, coinYAmount: bigint, extraLabels?: any): Promise<BigDecimal>;
         
     | 
| 
       19 
19 
     | 
    
         
             
                syncPools(resources: MoveResource[], ctx: AptosResourceContext, poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void): Promise<void>;
         
     | 
| 
       20 
20 
     | 
    
         
             
            }
         
     | 
| 
         @@ -4,15 +4,13 @@ import { defaultMoveCoder, } from '@sentio/sdk/aptos'; 
     | 
|
| 
       4 
4 
     | 
    
         
             
            export class AptosDex {
         
     | 
| 
       5 
5 
     | 
    
         
             
                poolAdaptor;
         
     | 
| 
       6 
6 
     | 
    
         
             
                volume;
         
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
      
 7 
     | 
    
         
            +
                volumeByCoin;
         
     | 
| 
       8 
8 
     | 
    
         
             
                tvlAll;
         
     | 
| 
       9 
9 
     | 
    
         
             
                tvlByPool;
         
     | 
| 
       10 
10 
     | 
    
         
             
                tvlByCoin;
         
     | 
| 
       11 
     | 
    
         
            -
                constructor(volume, 
         
     | 
| 
       12 
     | 
    
         
            -
                // volumeSingle: Gauge,
         
     | 
| 
       13 
     | 
    
         
            -
                tvlAll, tvlByCoin, tvlByPool, poolAdaptor) {
         
     | 
| 
      
 11 
     | 
    
         
            +
                constructor(volume, volumeByCoin, tvlAll, tvlByCoin, tvlByPool, poolAdaptor) {
         
     | 
| 
       14 
12 
     | 
    
         
             
                    this.volume = volume;
         
     | 
| 
       15 
     | 
    
         
            -
                     
     | 
| 
      
 13 
     | 
    
         
            +
                    this.volumeByCoin = volumeByCoin;
         
     | 
| 
       16 
14 
     | 
    
         
             
                    this.tvlAll = tvlAll;
         
     | 
| 
       17 
15 
     | 
    
         
             
                    this.tvlByPool = tvlByPool;
         
     | 
| 
       18 
16 
     | 
    
         
             
                    this.tvlByCoin = tvlByCoin;
         
     | 
| 
         @@ -44,19 +42,22 @@ export class AptosDex { 
     | 
|
| 
       44 
42 
     | 
    
         
             
                    if (resultY.eq(0)) {
         
     | 
| 
       45 
43 
     | 
    
         
             
                        resultY = BigDecimal(resultX);
         
     | 
| 
       46 
44 
     | 
    
         
             
                    }
         
     | 
| 
       47 
     | 
    
         
            -
                     
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                    const total = resultX.plus(resultY);
         
     | 
| 
      
 46 
     | 
    
         
            +
                    if (total.gt(0)) {
         
     | 
| 
      
 47 
     | 
    
         
            +
                        this.volume.record(ctx, total, {
         
     | 
| 
       49 
48 
     | 
    
         
             
                            ...baseLabels,
         
     | 
| 
       50 
     | 
    
         
            -
                            coin: coinXInfo.symbol,
         
     | 
| 
       51 
49 
     | 
    
         
             
                            bridge: coinXInfo.bridge,
         
     | 
| 
      
 50 
     | 
    
         
            +
                        });
         
     | 
| 
      
 51 
     | 
    
         
            +
                    }
         
     | 
| 
      
 52 
     | 
    
         
            +
                    if (resultX.gt(0)) {
         
     | 
| 
      
 53 
     | 
    
         
            +
                        this.volumeByCoin.record(ctx, resultX, {
         
     | 
| 
      
 54 
     | 
    
         
            +
                            coin: coinXInfo.symbol,
         
     | 
| 
       52 
55 
     | 
    
         
             
                            type: coinXInfo.token_type.type,
         
     | 
| 
       53 
56 
     | 
    
         
             
                        });
         
     | 
| 
       54 
57 
     | 
    
         
             
                    }
         
     | 
| 
       55 
58 
     | 
    
         
             
                    if (resultY.gt(0)) {
         
     | 
| 
       56 
     | 
    
         
            -
                        this. 
     | 
| 
       57 
     | 
    
         
            -
                            ...baseLabels,
         
     | 
| 
      
 59 
     | 
    
         
            +
                        this.volumeByCoin.record(ctx, resultY, {
         
     | 
| 
       58 
60 
     | 
    
         
             
                            coin: coinYInfo.symbol,
         
     | 
| 
       59 
     | 
    
         
            -
                            bridge: coinYInfo.bridge,
         
     | 
| 
       60 
61 
     | 
    
         
             
                            type: coinYInfo.token_type.type,
         
     | 
| 
       61 
62 
     | 
    
         
             
                        });
         
     | 
| 
       62 
63 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAIL,gBAAgB,GAEjB,MAAM,mBAAmB,CAAA;AAS1B,MAAM,OAAO,QAAQ;IACnB,WAAW,CAAgB;IAC3B,MAAM,CAAO;IAC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Info, whitelistCoins, whiteListed } from './coin.js'\nimport {\n  AptosResourceContext,\n  TypedMoveResource,\n  MoveResource,\n  defaultMoveCoder,\n  AptosContext,\n} from '@sentio/sdk/aptos'\n\nexport interface PoolAdaptor<T> {\n  getXReserve(pool: T): bigint\n  getYReserve(pool: T): bigint\n  getExtraPoolTags(pool: TypedMoveResource<T>): any\n  poolTypeName: string\n}\n\nexport class AptosDex<T> {\n  poolAdaptor: PoolAdaptor<T>\n  volume: Gauge\n  volumeSingle: Gauge\n  tvlAll: Gauge\n  tvlByPool: Gauge\n  tvlByCoin: Gauge\n\n  constructor(\n    volume: Gauge,\n    // volumeSingle: Gauge,\n    tvlAll: Gauge,\n    tvlByCoin: Gauge,\n    tvlByPool: Gauge,\n    poolAdaptor: PoolAdaptor<T>\n  ) {\n    this.volume = volume\n    // this.volumeSingle = volumeSingle\n    this.tvlAll = tvlAll\n    this.tvlByPool = tvlByPool\n    this.tvlByCoin = tvlByCoin\n    this.poolAdaptor = poolAdaptor\n  }\n\n  async recordTradingVolume(\n    ctx: AptosContext,\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 = whiteListed(coinx)\n    const whitelisty = whiteListed(coiny)\n    if (!whitelistx && !whitelisty) {\n      return result\n    }\n    const coinXInfo = await getCoinInfo(coinx)\n    const coinYInfo = await getCoinInfo(coiny)\n    const timestamp = ctx.transaction.timestamp\n    let resultX = BigDecimal(0)\n    let resultY = BigDecimal(0)\n    const pair = await getPair(coinx, coiny)\n    const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n    if (whitelistx) {\n      resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n    }\n    if (whitelisty) {\n      resultY = await 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    if (resultX.gt(0)) {\n      this.volume.record(ctx, resultX, {\n        ...baseLabels,\n        coin: coinXInfo.symbol,\n        bridge: coinXInfo.bridge,\n        type: coinXInfo.token_type.type,\n      })\n    }\n    if (resultY.gt(0)) {\n      this.volume.record(ctx, resultY, {\n        ...baseLabels,\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: MoveResource[],\n    ctx: AptosResourceContext,\n    poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void\n  ) {\n    const pools: TypedMoveResource<T>[] = defaultMoveCoder().filterAndDecodeResources(\n      this.poolAdaptor.poolTypeName,\n      resources\n    )\n\n    const volumeByCoin = new Map<string, BigDecimal>()\n    const timestamp = ctx.timestampInMicros\n\n    console.log('num of pools: ', pools.length, ctx.version.toString())\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 = whiteListed(coinx)\n      const whitelisty = whiteListed(coiny)\n      if (!whitelistx && !whitelisty) {\n        continue\n      }\n\n      const pair = await getPair(coinx, coiny)\n      const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n      const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n      const coinXInfo = await getCoinInfo(coinx)\n      const coinYInfo = await 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 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 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 = 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\nexport async function getPair(coinx: string, coiny: string): Promise<string> {\n  const coinXInfo = await getCoinInfo(coinx)\n  const coinYInfo = await 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\nexport async function getPairValue(\n  ctx: AptosContext,\n  coinx: string,\n  coiny: string,\n  coinXAmount: bigint,\n  coinYAmount: bigint\n): Promise<BigDecimal> {\n  const whitelistx = whiteListed(coinx)\n  const whitelisty = whiteListed(coiny)\n  const coinXInfo = await getCoinInfo(coinx)\n  const coinYInfo = await getCoinInfo(coiny)\n  const timestamp = ctx.transaction.timestamp\n  let result = BigDecimal(0.0)\n\n  if (!whitelistx || !whitelisty) {\n    return result\n  }\n\n  if (whitelistx) {\n    const value = await 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 calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n    if (!whitelistx) {\n      result = result.plus(value)\n    }\n  }\n\n  return result\n}\n"]}
         
     | 
| 
      
 1 
     | 
    
         
            +
            {"version":3,"file":"aptos-dex.js","sourceRoot":"","sources":["../../../src/aptos/ext/aptos-dex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAIL,gBAAgB,GAEjB,MAAM,mBAAmB,CAAA;AAS1B,MAAM,OAAO,QAAQ;IACnB,WAAW,CAAgB;IAC3B,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,WAA2B;QAE3B,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,CACv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AC,KAAK,CAAC,CAAA;IACrC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAA;IAC3C,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,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAC1E,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,mBAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { Gauge } from '@sentio/sdk'\nimport { BigDecimal } from '@sentio/bigdecimal'\nimport { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'\nimport {\n  AptosResourceContext,\n  TypedMoveResource,\n  MoveResource,\n  defaultMoveCoder,\n  AptosContext,\n} from '@sentio/sdk/aptos'\n\nexport interface PoolAdaptor<T> {\n  getXReserve(pool: T): bigint\n  getYReserve(pool: T): bigint\n  getExtraPoolTags(pool: TypedMoveResource<T>): any\n  poolTypeName: string\n}\n\nexport class AptosDex<T> {\n  poolAdaptor: PoolAdaptor<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: PoolAdaptor<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: AptosContext,\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 = whiteListed(coinx)\n    const whitelisty = whiteListed(coiny)\n    if (!whitelistx && !whitelisty) {\n      return result\n    }\n    const coinXInfo = await getCoinInfo(coinx)\n    const coinYInfo = await getCoinInfo(coiny)\n    const timestamp = ctx.transaction.timestamp\n    let resultX = BigDecimal(0)\n    let resultY = BigDecimal(0)\n    const pair = await getPair(coinx, coiny)\n    const baseLabels: Record<string, string> = extraLabels ? { ...extraLabels, pair } : { pair }\n    if (whitelistx) {\n      resultX = await calculateValueInUsd(coinXAmount, coinXInfo, timestamp)\n    }\n    if (whitelisty) {\n      resultY = await 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        type: coinXInfo.token_type.type,\n      })\n    }\n    if (resultY.gt(0)) {\n      this.volumeByCoin.record(ctx, resultY, {\n        coin: coinYInfo.symbol,\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: MoveResource[],\n    ctx: AptosResourceContext,\n    poolsHandler?: (pools: TypedMoveResource<T>[]) => Promise<void> | void\n  ) {\n    const pools: TypedMoveResource<T>[] = defaultMoveCoder().filterAndDecodeResources(\n      this.poolAdaptor.poolTypeName,\n      resources\n    )\n\n    const volumeByCoin = new Map<string, BigDecimal>()\n    const timestamp = ctx.timestampInMicros\n\n    console.log('num of pools: ', pools.length, ctx.version.toString())\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 = whiteListed(coinx)\n      const whitelisty = whiteListed(coiny)\n      if (!whitelistx && !whitelisty) {\n        continue\n      }\n\n      const pair = await getPair(coinx, coiny)\n      const extraLabels = this.poolAdaptor.getExtraPoolTags(pool)\n      const baseLabels: Record<string, string> = { ...extraLabels, pair }\n\n      const coinXInfo = await getCoinInfo(coinx)\n      const coinYInfo = await 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 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 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 = 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\nexport async function getPair(coinx: string, coiny: string): Promise<string> {\n  const coinXInfo = await getCoinInfo(coinx)\n  const coinYInfo = await 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\nexport async function getPairValue(\n  ctx: AptosContext,\n  coinx: string,\n  coiny: string,\n  coinXAmount: bigint,\n  coinYAmount: bigint\n): Promise<BigDecimal> {\n  const whitelistx = whiteListed(coinx)\n  const whitelisty = whiteListed(coiny)\n  const coinXInfo = await getCoinInfo(coinx)\n  const coinYInfo = await getCoinInfo(coiny)\n  const timestamp = ctx.transaction.timestamp\n  let result = BigDecimal(0.0)\n\n  if (!whitelistx || !whitelisty) {\n    return result\n  }\n\n  if (whitelistx) {\n    const value = await 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 calculateValueInUsd(coinYAmount, coinYInfo, timestamp)\n\n    if (!whitelistx) {\n      result = result.plus(value)\n    }\n  }\n\n  return result\n}\n"]}
         
     | 
    
        package/package.json
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "@sentio/sdk",
         
     | 
| 
       3 
3 
     | 
    
         
             
              "license": "Apache-2.0",
         
     | 
| 
       4 
     | 
    
         
            -
              "version": "2.7. 
     | 
| 
      
 4 
     | 
    
         
            +
              "version": "2.7.4-rc.1",
         
     | 
| 
       5 
5 
     | 
    
         
             
              "type": "module",
         
     | 
| 
       6 
6 
     | 
    
         
             
              "scripts": {
         
     | 
| 
       7 
7 
     | 
    
         
             
                "compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
         
     | 
| 
         @@ -23,8 +23,8 @@ 
     | 
|
| 
       23 
23 
     | 
    
         
             
                "@project-serum/anchor": "^0.26.0",
         
     | 
| 
       24 
24 
     | 
    
         
             
                "@sentio/bigdecimal": "^9.1.1-patch.3",
         
     | 
| 
       25 
25 
     | 
    
         
             
                "@sentio/ethers-v6": "^1.0.25",
         
     | 
| 
       26 
     | 
    
         
            -
                "@sentio/protos": "^2.7. 
     | 
| 
       27 
     | 
    
         
            -
                "@sentio/runtime": "^2.7. 
     | 
| 
      
 26 
     | 
    
         
            +
                "@sentio/protos": "^2.7.4-rc.1",
         
     | 
| 
      
 27 
     | 
    
         
            +
                "@sentio/runtime": "^2.7.4-rc.1",
         
     | 
| 
       28 
28 
     | 
    
         
             
                "@solana/web3.js": "^1.73.2",
         
     | 
| 
       29 
29 
     | 
    
         
             
                "@types/prettier": "^2.7.2",
         
     | 
| 
       30 
30 
     | 
    
         
             
                "aptos-sdk": "npm:aptos@^1.7.1",
         
     | 
| 
         @@ -80,5 +80,5 @@ 
     | 
|
| 
       80 
80 
     | 
    
         
             
              "engines": {
         
     | 
| 
       81 
81 
     | 
    
         
             
                "node": ">=16"
         
     | 
| 
       82 
82 
     | 
    
         
             
              },
         
     | 
| 
       83 
     | 
    
         
            -
              "gitHead": " 
     | 
| 
      
 83 
     | 
    
         
            +
              "gitHead": "82655a66635104bb5725e8dcb0dea4cb312c2973"
         
     | 
| 
       84 
84 
     | 
    
         
             
            }
         
     | 
| 
         @@ -19,21 +19,21 @@ export interface PoolAdaptor<T> { 
     | 
|
| 
       19 
19 
     | 
    
         
             
            export class AptosDex<T> {
         
     | 
| 
       20 
20 
     | 
    
         
             
              poolAdaptor: PoolAdaptor<T>
         
     | 
| 
       21 
21 
     | 
    
         
             
              volume: Gauge
         
     | 
| 
       22 
     | 
    
         
            -
               
     | 
| 
      
 22 
     | 
    
         
            +
              volumeByCoin: Gauge
         
     | 
| 
       23 
23 
     | 
    
         
             
              tvlAll: Gauge
         
     | 
| 
       24 
24 
     | 
    
         
             
              tvlByPool: Gauge
         
     | 
| 
       25 
25 
     | 
    
         
             
              tvlByCoin: Gauge
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
              constructor(
         
     | 
| 
       28 
28 
     | 
    
         
             
                volume: Gauge,
         
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
      
 29 
     | 
    
         
            +
                volumeByCoin: Gauge,
         
     | 
| 
       30 
30 
     | 
    
         
             
                tvlAll: Gauge,
         
     | 
| 
       31 
31 
     | 
    
         
             
                tvlByCoin: Gauge,
         
     | 
| 
       32 
32 
     | 
    
         
             
                tvlByPool: Gauge,
         
     | 
| 
       33 
33 
     | 
    
         
             
                poolAdaptor: PoolAdaptor<T>
         
     | 
| 
       34 
34 
     | 
    
         
             
              ) {
         
     | 
| 
       35 
35 
     | 
    
         
             
                this.volume = volume
         
     | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
      
 36 
     | 
    
         
            +
                this.volumeByCoin = volumeByCoin
         
     | 
| 
       37 
37 
     | 
    
         
             
                this.tvlAll = tvlAll
         
     | 
| 
       38 
38 
     | 
    
         
             
                this.tvlByPool = tvlByPool
         
     | 
| 
       39 
39 
     | 
    
         
             
                this.tvlByCoin = tvlByCoin
         
     | 
| 
         @@ -74,19 +74,22 @@ export class AptosDex<T> { 
     | 
|
| 
       74 
74 
     | 
    
         
             
                if (resultY.eq(0)) {
         
     | 
| 
       75 
75 
     | 
    
         
             
                  resultY = BigDecimal(resultX)
         
     | 
| 
       76 
76 
     | 
    
         
             
                }
         
     | 
| 
       77 
     | 
    
         
            -
                 
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
                const total = resultX.plus(resultY)
         
     | 
| 
      
 78 
     | 
    
         
            +
                if (total.gt(0)) {
         
     | 
| 
      
 79 
     | 
    
         
            +
                  this.volume.record(ctx, total, {
         
     | 
| 
       79 
80 
     | 
    
         
             
                    ...baseLabels,
         
     | 
| 
       80 
     | 
    
         
            -
                    coin: coinXInfo.symbol,
         
     | 
| 
       81 
81 
     | 
    
         
             
                    bridge: coinXInfo.bridge,
         
     | 
| 
      
 82 
     | 
    
         
            +
                  })
         
     | 
| 
      
 83 
     | 
    
         
            +
                }
         
     | 
| 
      
 84 
     | 
    
         
            +
                if (resultX.gt(0)) {
         
     | 
| 
      
 85 
     | 
    
         
            +
                  this.volumeByCoin.record(ctx, resultX, {
         
     | 
| 
      
 86 
     | 
    
         
            +
                    coin: coinXInfo.symbol,
         
     | 
| 
       82 
87 
     | 
    
         
             
                    type: coinXInfo.token_type.type,
         
     | 
| 
       83 
88 
     | 
    
         
             
                  })
         
     | 
| 
       84 
89 
     | 
    
         
             
                }
         
     | 
| 
       85 
90 
     | 
    
         
             
                if (resultY.gt(0)) {
         
     | 
| 
       86 
     | 
    
         
            -
                  this. 
     | 
| 
       87 
     | 
    
         
            -
                    ...baseLabels,
         
     | 
| 
      
 91 
     | 
    
         
            +
                  this.volumeByCoin.record(ctx, resultY, {
         
     | 
| 
       88 
92 
     | 
    
         
             
                    coin: coinYInfo.symbol,
         
     | 
| 
       89 
     | 
    
         
            -
                    bridge: coinYInfo.bridge,
         
     | 
| 
       90 
93 
     | 
    
         
             
                    type: coinYInfo.token_type.type,
         
     | 
| 
       91 
94 
     | 
    
         
             
                  })
         
     | 
| 
       92 
95 
     | 
    
         
             
                }
         
     |