Skip to content

Commit

Permalink
feat(aptos): aptos dex support fatoken (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Nov 8, 2024
1 parent 2061e49 commit 6527ada
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 1,659 deletions.
4 changes: 2 additions & 2 deletions packages/sdk/src/aptos/aptos-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ServerError, Status } from 'nice-grpc'

import { AptosProcessorState, AptosResourceProcessorState } from './aptos-processor.js'

import { initCoinList } from './ext/coin.js'
import { initTokenList } from './ext/token.js'
import { AptosChainId } from '@sentio/chain'
import { AptosResourcesContext } from './context.js'
import {
Expand All @@ -42,7 +42,7 @@ export class AptosPlugin extends Plugin {
}

async start(request: StartRequest) {
await initCoinList()
await initTokenList()

const allowedChainIds = new Set<string>(Object.values(AptosChainId))
for (const instance of request.templateInstances) {
Expand Down
21 changes: 11 additions & 10 deletions packages/sdk/src/aptos/ext/aptos-dex.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import { BigDecimal } from '@sentio/bigdecimal'
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
import { AptosResourcesContext, AptosContext, AptosNetwork } from '../index.js'
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor } from '../../move/ext/index.js'
import { MoveResource, Event, MoveModuleBytecode } from '@aptos-labs/ts-sdk'
import { getTokenInfoWithFallback, TokenInfo, tokenTokenValueInUsd, whitelistTokens } from './token.js'

export type PoolAdaptor<T> = MovePoolAdaptor<MoveResource, T>

export class CoinList implements MoveCoinList<AptosNetwork> {
export class CoinList implements MoveCoinList<TokenInfo, AptosNetwork> {
calculateValueInUsd(
amount: bigint,
coinInfo: SimpleCoinInfo,
coinInfo: TokenInfo,
timestamp: number,
network: AptosNetwork = AptosNetwork.MAIN_NET
): Promise<BigDecimal> {
return calculateValueInUsd(amount, coinInfo, timestamp, network)
return tokenTokenValueInUsd(amount, coinInfo, timestamp, network)
}

getCoinInfo(type: string): SimpleCoinInfo {
return getCoinInfo(type)
async getCoinInfo(type: string) {
return getTokenInfoWithFallback(type)
}

whiteListed(type: string): boolean {
return whiteListed(type)
return whitelistTokens().has(type)
}

whitelistCoins(): Map<string, SimpleCoinInfo> {
return whitelistCoins()
whitelistCoins() {
return whitelistTokens()
}
}

export const AptosCoinList = new CoinList()

export class AptosDex<T> extends MoveDex<
TokenInfo,
AptosNetwork,
MoveModuleBytecode,
MoveResource,
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/aptos/ext/coin.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describe, test } from 'node:test'
import { getCoinInfoWithFallback } from './coin.js'
import { expect } from 'chai'
import { getTokenInfoWithFallback } from './token.js'

describe('coin test', () => {
test('get coin info', async () => {
const info = await getCoinInfoWithFallback(
const info = await getTokenInfoWithFallback(
'0xe4ccb6d39136469f376242c31b34d10515c8eaaa38092f804db8e08a8f53c5b2::assets_v1::EchoCoin002'
)

Expand Down
Loading

0 comments on commit 6527ada

Please sign in to comment.