@sentio/sdk 2.44.7-rc.5 → 2.45.0-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.
- package/lib/aptos/aptos-plugin.js +2 -2
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +7 -6
- package/lib/aptos/ext/aptos-dex.d.ts.map +1 -1
- package/lib/aptos/ext/aptos-dex.js +6 -6
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/ext/coin.test.js.map +1 -1
- package/lib/aptos/ext/index.d.ts +0 -1
- package/lib/aptos/ext/index.d.ts.map +1 -1
- package/lib/aptos/ext/index.js +0 -1
- package/lib/aptos/ext/index.js.map +1 -1
- package/lib/aptos/ext/token.d.ts +7 -5
- package/lib/aptos/ext/token.d.ts.map +1 -1
- package/lib/aptos/ext/token.js +6 -0
- package/lib/aptos/ext/token.js.map +1 -1
- package/lib/move/ext/coin.d.ts +15 -0
- package/lib/move/ext/coin.d.ts.map +1 -0
- package/lib/move/ext/coin.js +2 -0
- package/lib/move/ext/coin.js.map +1 -0
- package/lib/move/ext/index.d.ts +1 -1
- package/lib/move/ext/index.d.ts.map +1 -1
- package/lib/move/ext/index.js +1 -1
- package/lib/move/ext/index.js.map +1 -1
- package/lib/move/ext/move-dex.d.ts +4 -14
- package/lib/move/ext/move-dex.d.ts.map +1 -1
- package/lib/move/ext/move-dex.js +7 -7
- package/lib/move/ext/move-dex.js.map +1 -1
- package/lib/sui/codegen/codegen.js +1 -0
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/ext/coin.d.ts +5 -5
- package/lib/sui/ext/coin.d.ts.map +1 -1
- package/lib/sui/ext/coin.js +4 -7
- package/lib/sui/ext/coin.js.map +1 -1
- package/lib/sui/ext/move-dex.d.ts +6 -6
- package/lib/sui/ext/move-dex.d.ts.map +1 -1
- package/lib/sui/ext/move-dex.js +1 -1
- package/lib/sui/ext/move-dex.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/aptos-plugin.ts +2 -2
- package/src/aptos/ext/aptos-dex.ts +11 -10
- package/src/aptos/ext/index.ts +0 -1
- package/src/aptos/ext/token.ts +18 -10
- package/src/move/ext/coin.ts +17 -0
- package/src/move/ext/index.ts +1 -1
- package/src/move/ext/move-dex.ts +16 -19
- package/src/sui/codegen/codegen.ts +1 -0
- package/src/sui/ext/coin.ts +9 -12
- package/src/sui/ext/move-dex.ts +6 -5
- package/lib/aptos/ext/coin.d.ts +0 -12
- package/lib/aptos/ext/coin.d.ts.map +0 -1
- package/lib/aptos/ext/coin.js +0 -1557
- package/lib/aptos/ext/coin.js.map +0 -1
- package/lib/move/ext/coin-list.d.ts +0 -9
- package/lib/move/ext/coin-list.d.ts.map +0 -1
- package/lib/move/ext/coin-list.js +0 -2
- package/lib/move/ext/coin-list.js.map +0 -1
- package/src/aptos/ext/coin.ts +0 -1583
- package/src/move/ext/coin-list.ts +0 -14
@@ -1,17 +1,17 @@
|
|
1
1
|
import { BigDecimal } from '@sentio/bigdecimal';
|
2
|
-
import { MoveCoinList, MoveDex, MovePoolAdaptor,
|
2
|
+
import { MoveCoinList, MoveDex, MovePoolAdaptor, BaseCoinInfo } from '../../move/ext/index.js';
|
3
3
|
import { SuiEvent, SuiMoveNormalizedModule, SuiMoveObject } from '@mysten/sui/client';
|
4
4
|
import { SuiNetwork } from '../network.js';
|
5
5
|
import { SuiContext, SuiObjectContext } from '../context.js';
|
6
6
|
export type PoolAdaptor<T> = MovePoolAdaptor<SuiMoveObject, T>;
|
7
|
-
export declare class CoinList implements MoveCoinList<SuiNetwork> {
|
8
|
-
calculateValueInUsd(amount: bigint, coinInfo:
|
9
|
-
getCoinInfo(type: string):
|
7
|
+
export declare class CoinList implements MoveCoinList<BaseCoinInfo, SuiNetwork> {
|
8
|
+
calculateValueInUsd(amount: bigint, coinInfo: BaseCoinInfo, timestamp: number): Promise<BigDecimal>;
|
9
|
+
getCoinInfo(type: string): Promise<BaseCoinInfo>;
|
10
10
|
whiteListed(type: string): boolean;
|
11
|
-
whitelistCoins(): Map<string,
|
11
|
+
whitelistCoins(): Map<string, BaseCoinInfo>;
|
12
12
|
}
|
13
13
|
export declare const SuiCoinList: CoinList;
|
14
|
-
export declare class SuiDex<T> extends MoveDex<SuiNetwork, SuiMoveNormalizedModule, SuiMoveObject, SuiEvent, SuiContext, SuiObjectContext, T> {
|
14
|
+
export declare class SuiDex<T> extends MoveDex<BaseCoinInfo, SuiNetwork, SuiMoveNormalizedModule, SuiMoveObject, SuiEvent, SuiContext, SuiObjectContext, T> {
|
15
15
|
coinList: CoinList;
|
16
16
|
poolAdaptor: PoolAdaptor<T>;
|
17
17
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"move-dex.d.ts","sourceRoot":"","sources":["../../../src/sui/ext/move-dex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAoB,eAAe,EAAE,
|
1
|
+
{"version":3,"file":"move-dex.d.ts","sourceRoot":"","sources":["../../../src/sui/ext/move-dex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAE/C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAoB,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAChH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAE5D,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,eAAe,CAAC,aAAa,EAAE,CAAC,CAAC,CAAA;AAE9D,qBAAa,QAAS,YAAW,YAAY,CAAC,YAAY,EAAE,UAAU,CAAC;IACrE,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAI7F,WAAW,CAAC,IAAI,EAAE,MAAM;IAI9B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIlC,cAAc,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;CAG5C;AAED,eAAO,MAAM,WAAW,UAAiB,CAAA;AAEzC,qBAAa,MAAM,CAAC,CAAC,CAAE,SAAQ,OAAO,CACpC,YAAY,EACZ,UAAU,EACV,uBAAuB,EACvB,aAAa,EACb,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,CAAC,CACF;IACC,QAAQ,WAAc;IACd,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CACpC;AAED,wBAAsB,YAAY,CAChC,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,CAErB"}
|
package/lib/sui/ext/move-dex.js
CHANGED
@@ -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,EAAE,gBAAgB,
|
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,EAAiC,MAAM,yBAAyB,CAAA;AAOhH,MAAM,OAAO,QAAQ;IACnB,mBAAmB,CAAC,MAAc,EAAE,QAAsB,EAAE,SAAiB;QAC3E,OAAO,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;IACzD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAY;QAC5B,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,OAS9B;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"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.45.0-rc.1",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -84,8 +84,8 @@
|
|
84
84
|
"typechain": "^8.3.2",
|
85
85
|
"utility-types": "^3.11.0",
|
86
86
|
"yaml": "^2.3.4",
|
87
|
-
"@sentio/
|
88
|
-
"@sentio/
|
87
|
+
"@sentio/runtime": "^2.45.0-rc.1",
|
88
|
+
"@sentio/protos": "2.45.0-rc.1"
|
89
89
|
},
|
90
90
|
"peerDependencies": {
|
91
91
|
"tsup": "npm:@sentio/tsup@^6.7.6"
|
@@ -19,7 +19,7 @@ import { ServerError, Status } from 'nice-grpc'
|
|
19
19
|
|
20
20
|
import { AptosProcessorState, AptosResourceProcessorState } from './aptos-processor.js'
|
21
21
|
|
22
|
-
import {
|
22
|
+
import { initTokenList } from './ext/token.js'
|
23
23
|
import { AptosChainId } from '@sentio/chain'
|
24
24
|
import { AptosResourcesContext } from './context.js'
|
25
25
|
import {
|
@@ -42,7 +42,7 @@ export class AptosPlugin extends Plugin {
|
|
42
42
|
}
|
43
43
|
|
44
44
|
async start(request: StartRequest) {
|
45
|
-
await
|
45
|
+
await initTokenList()
|
46
46
|
|
47
47
|
const allowedChainIds = new Set<string>(Object.values(AptosChainId))
|
48
48
|
for (const instance of request.templateInstances) {
|
@@ -1,37 +1,38 @@
|
|
1
1
|
import { BigDecimal } from '@sentio/bigdecimal'
|
2
|
-
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
3
2
|
import { AptosResourcesContext, AptosContext, AptosNetwork } from '../index.js'
|
4
|
-
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor
|
3
|
+
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor } from '../../move/ext/index.js'
|
5
4
|
import { MoveResource, Event, MoveModuleBytecode } from '@aptos-labs/ts-sdk'
|
5
|
+
import { getTokenInfoWithFallback, TokenInfo, tokenTokenValueInUsd, whitelistTokens } from './token.js'
|
6
6
|
|
7
7
|
export type PoolAdaptor<T> = MovePoolAdaptor<MoveResource, T>
|
8
8
|
|
9
|
-
export class CoinList implements MoveCoinList<AptosNetwork> {
|
9
|
+
export class CoinList implements MoveCoinList<TokenInfo, AptosNetwork> {
|
10
10
|
calculateValueInUsd(
|
11
11
|
amount: bigint,
|
12
|
-
coinInfo:
|
12
|
+
coinInfo: TokenInfo,
|
13
13
|
timestamp: number,
|
14
14
|
network: AptosNetwork = AptosNetwork.MAIN_NET
|
15
15
|
): Promise<BigDecimal> {
|
16
|
-
return
|
16
|
+
return tokenTokenValueInUsd(amount, coinInfo, timestamp, network)
|
17
17
|
}
|
18
18
|
|
19
|
-
getCoinInfo(type: string)
|
20
|
-
return
|
19
|
+
async getCoinInfo(type: string) {
|
20
|
+
return getTokenInfoWithFallback(type)
|
21
21
|
}
|
22
22
|
|
23
23
|
whiteListed(type: string): boolean {
|
24
|
-
return
|
24
|
+
return whitelistTokens().has(type)
|
25
25
|
}
|
26
26
|
|
27
|
-
whitelistCoins()
|
28
|
-
return
|
27
|
+
whitelistCoins() {
|
28
|
+
return whitelistTokens()
|
29
29
|
}
|
30
30
|
}
|
31
31
|
|
32
32
|
export const AptosCoinList = new CoinList()
|
33
33
|
|
34
34
|
export class AptosDex<T> extends MoveDex<
|
35
|
+
TokenInfo,
|
35
36
|
AptosNetwork,
|
36
37
|
MoveModuleBytecode,
|
37
38
|
MoveResource,
|
package/src/aptos/ext/index.ts
CHANGED
package/src/aptos/ext/token.ts
CHANGED
@@ -6,8 +6,9 @@ import { coin } from '../builtin/0x1.js'
|
|
6
6
|
import { MoveStructId } from '@aptos-labs/ts-sdk'
|
7
7
|
import { AptosChainId } from '@sentio/chain'
|
8
8
|
import DEFAULT_TOKEN_LIST from './token-list.json' assert { type: 'json' }
|
9
|
+
import { BaseCoinInfo } from '../../move/ext/index.js'
|
9
10
|
|
10
|
-
type
|
11
|
+
type InternalTokenInfo = {
|
11
12
|
chainId: number
|
12
13
|
tokenAddress: `0x${string}` | null
|
13
14
|
faAddress: `0x${string}` | null
|
@@ -26,7 +27,8 @@ type TokenInfo = {
|
|
26
27
|
coinMarketCapId: number | null
|
27
28
|
}
|
28
29
|
|
29
|
-
export
|
30
|
+
export interface TokenInfo extends BaseCoinInfo {
|
31
|
+
type: `0x${string}` // either tokenAddress or faAddress
|
30
32
|
tokenAddress?: `0x${string}`
|
31
33
|
faAddress?: `0x${string}`
|
32
34
|
name: string
|
@@ -40,15 +42,15 @@ export type SimpleTokenInfo = {
|
|
40
42
|
coinMarketCapId?: number
|
41
43
|
}
|
42
44
|
|
43
|
-
const TOKEN_MAP = new Map<string,
|
45
|
+
const TOKEN_MAP = new Map<string, TokenInfo>()
|
44
46
|
|
45
47
|
export async function initTokenList() {
|
46
|
-
let list = DEFAULT_TOKEN_LIST as
|
48
|
+
let list = DEFAULT_TOKEN_LIST as InternalTokenInfo[]
|
47
49
|
try {
|
48
50
|
const resp = await fetch(
|
49
51
|
'https://raw.githubusercontent.com/PanoraExchange/Aptos-Tokens/refs/heads/main/token-list.json'
|
50
52
|
)
|
51
|
-
list = (await resp.json()) as
|
53
|
+
list = (await resp.json()) as InternalTokenInfo[]
|
52
54
|
} catch (e) {
|
53
55
|
console.warn("Can't not fetch newest token list, use default list")
|
54
56
|
}
|
@@ -56,8 +58,13 @@ export async function initTokenList() {
|
|
56
58
|
setTokenList(list)
|
57
59
|
}
|
58
60
|
|
59
|
-
function tokenInfoToSimple(info:
|
61
|
+
function tokenInfoToSimple(info: InternalTokenInfo): TokenInfo {
|
62
|
+
const type = info.tokenAddress || info.faAddress
|
63
|
+
if (!type) {
|
64
|
+
throw Error('Token info must have tokenAddress or faAddress')
|
65
|
+
}
|
60
66
|
return {
|
67
|
+
type,
|
61
68
|
tokenAddress: info.tokenAddress || undefined,
|
62
69
|
faAddress: info.faAddress || undefined,
|
63
70
|
name: info.name,
|
@@ -72,7 +79,7 @@ function tokenInfoToSimple(info: TokenInfo): SimpleTokenInfo {
|
|
72
79
|
}
|
73
80
|
}
|
74
81
|
|
75
|
-
function setTokenList(list:
|
82
|
+
function setTokenList(list: InternalTokenInfo[]) {
|
76
83
|
for (const info of list) {
|
77
84
|
const simpleInfo = tokenInfoToSimple(info)
|
78
85
|
if (
|
@@ -107,7 +114,7 @@ export function isWhiteListToken(token: string): boolean {
|
|
107
114
|
const TOKEN_METADATA_CACHE = new Map<string, Promise<any | null>>()
|
108
115
|
|
109
116
|
// token: address of the fungible asset, e.g. "0xa", or the coin type, e.g. "0x1::aptos::AptosCoin"
|
110
|
-
export async function getTokenInfoWithFallback(token: string, network?: AptosNetwork): Promise<
|
117
|
+
export async function getTokenInfoWithFallback(token: string, network?: AptosNetwork): Promise<TokenInfo> {
|
111
118
|
const r = TOKEN_MAP.get(token)
|
112
119
|
if (!r) {
|
113
120
|
network = network || AptosNetwork.MAIN_NET
|
@@ -134,6 +141,7 @@ export async function getTokenInfoWithFallback(token: string, network?: AptosNet
|
|
134
141
|
|
135
142
|
// const parts = type.split(SPLITTER)
|
136
143
|
return {
|
144
|
+
type: token as `0x${string}`,
|
137
145
|
category: 'Native',
|
138
146
|
tokenAddress: token as `0x${string}`,
|
139
147
|
name: meta.name,
|
@@ -166,7 +174,7 @@ export async function getPriceForToken(
|
|
166
174
|
|
167
175
|
export async function tokenTokenValueInUsd(
|
168
176
|
n: bigint,
|
169
|
-
coinInfo:
|
177
|
+
coinInfo: TokenInfo,
|
170
178
|
timestamp: number,
|
171
179
|
network = AptosChainId.APTOS_MAINNET
|
172
180
|
) {
|
@@ -179,4 +187,4 @@ export async function tokenTokenValueInUsd(
|
|
179
187
|
throw Error('Token not found' + JSON.stringify(coinInfo))
|
180
188
|
}
|
181
189
|
|
182
|
-
setTokenList(DEFAULT_TOKEN_LIST as
|
190
|
+
setTokenList(DEFAULT_TOKEN_LIST as InternalTokenInfo[])
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { BigDecimal } from '@sentio/bigdecimal'
|
2
|
+
|
3
|
+
export interface BaseCoinInfo {
|
4
|
+
// token_type: { type: string; account_address: string }
|
5
|
+
type: string
|
6
|
+
symbol: string
|
7
|
+
hippo_symbol?: string
|
8
|
+
decimals: number
|
9
|
+
bridge: string
|
10
|
+
}
|
11
|
+
|
12
|
+
export interface MoveCoinList<TokenType extends BaseCoinInfo, Network> {
|
13
|
+
whiteListed(type: string): boolean
|
14
|
+
whitelistCoins(): Map<string, TokenType>
|
15
|
+
getCoinInfo(type: string): Promise<TokenType>
|
16
|
+
calculateValueInUsd(amount: bigint, coinInfo: TokenType, timestamp: number, network: Network): Promise<BigDecimal>
|
17
|
+
}
|
package/src/move/ext/index.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './coin
|
1
|
+
export * from './coin.js'
|
2
2
|
export * from './move-dex.js'
|
package/src/move/ext/move-dex.ts
CHANGED
@@ -2,15 +2,7 @@ import { DecodedStruct, TypeDescriptor } from '@typemove/move'
|
|
2
2
|
import { BigDecimal } from '@sentio/bigdecimal'
|
3
3
|
import { Gauge } from '../../core/index.js'
|
4
4
|
import { MoveAccountContext, MoveContext } from '../move-context.js'
|
5
|
-
import { MoveCoinList } from './coin
|
6
|
-
|
7
|
-
export interface SimpleCoinInfo {
|
8
|
-
token_type: { type: string; account_address: string }
|
9
|
-
symbol: string
|
10
|
-
hippo_symbol?: string
|
11
|
-
decimals: number
|
12
|
-
bridge: string
|
13
|
-
}
|
5
|
+
import { MoveCoinList, BaseCoinInfo } from './coin.js'
|
14
6
|
|
15
7
|
export interface MovePoolAdaptor<StructType, T> {
|
16
8
|
getXReserve(pool: T): bigint
|
@@ -23,6 +15,7 @@ export interface MovePoolAdaptor<StructType, T> {
|
|
23
15
|
}
|
24
16
|
|
25
17
|
export class MoveDex<
|
18
|
+
TokenType extends BaseCoinInfo,
|
26
19
|
Network,
|
27
20
|
ModuleType,
|
28
21
|
StructType,
|
@@ -31,7 +24,7 @@ export class MoveDex<
|
|
31
24
|
AccountContextType extends MoveAccountContext<Network, ModuleType, StructType | EventType>,
|
32
25
|
T
|
33
26
|
> {
|
34
|
-
coinList: MoveCoinList<Network>
|
27
|
+
coinList: MoveCoinList<TokenType, Network>
|
35
28
|
poolAdaptor: MovePoolAdaptor<StructType, T>
|
36
29
|
volume: Gauge
|
37
30
|
volumeByCoin: Gauge
|
@@ -100,14 +93,14 @@ export class MoveDex<
|
|
100
93
|
this.volumeByCoin.record(ctx, resultX, {
|
101
94
|
coin: coinXInfo.symbol,
|
102
95
|
bridge: coinXInfo.bridge,
|
103
|
-
type: coinXInfo.
|
96
|
+
type: coinXInfo.type
|
104
97
|
})
|
105
98
|
}
|
106
99
|
if (resultY.gt(0)) {
|
107
100
|
this.volumeByCoin.record(ctx, resultY, {
|
108
101
|
coin: coinYInfo.symbol,
|
109
102
|
bridge: coinYInfo.bridge,
|
110
|
-
type: coinYInfo.
|
103
|
+
type: coinYInfo.type
|
111
104
|
})
|
112
105
|
}
|
113
106
|
result = resultX.plus(resultY).div(2)
|
@@ -152,23 +145,23 @@ export class MoveDex<
|
|
152
145
|
|
153
146
|
if (whitelistx) {
|
154
147
|
resultX = await this.coinList.calculateValueInUsd(coinx_amount, coinXInfo, timestamp, ctx.network)
|
155
|
-
let coinXTotal = volumeByCoin.get(coinXInfo.
|
148
|
+
let coinXTotal = volumeByCoin.get(coinXInfo.type)
|
156
149
|
if (!coinXTotal) {
|
157
150
|
coinXTotal = resultX
|
158
151
|
} else {
|
159
152
|
coinXTotal = coinXTotal.plus(resultX)
|
160
153
|
}
|
161
|
-
volumeByCoin.set(coinXInfo.
|
154
|
+
volumeByCoin.set(coinXInfo.type, coinXTotal)
|
162
155
|
}
|
163
156
|
if (whitelisty) {
|
164
157
|
resultY = await this.coinList.calculateValueInUsd(coiny_amount, coinYInfo, timestamp, ctx.network)
|
165
|
-
let coinYTotal = volumeByCoin.get(coinYInfo.
|
158
|
+
let coinYTotal = volumeByCoin.get(coinYInfo.type)
|
166
159
|
if (!coinYTotal) {
|
167
160
|
coinYTotal = resultY
|
168
161
|
} else {
|
169
162
|
coinYTotal = coinYTotal.plus(resultY)
|
170
163
|
}
|
171
|
-
volumeByCoin.set(coinYInfo.
|
164
|
+
volumeByCoin.set(coinYInfo.type, coinYTotal)
|
172
165
|
}
|
173
166
|
|
174
167
|
if (resultX.eq(0)) {
|
@@ -202,7 +195,7 @@ export class MoveDex<
|
|
202
195
|
this.tvlByCoin.record(ctx, v, {
|
203
196
|
coin: coinInfo.symbol,
|
204
197
|
bridge: coinInfo.bridge,
|
205
|
-
type: coinInfo.
|
198
|
+
type: coinInfo.type
|
206
199
|
})
|
207
200
|
}
|
208
201
|
}
|
@@ -218,8 +211,12 @@ export class MoveDex<
|
|
218
211
|
}
|
219
212
|
}
|
220
213
|
|
221
|
-
export async function moveGetPairValue<
|
222
|
-
|
214
|
+
export async function moveGetPairValue<
|
215
|
+
TokenType extends BaseCoinInfo,
|
216
|
+
Network,
|
217
|
+
ContextType extends MoveAccountContext<Network, any, any>
|
218
|
+
>(
|
219
|
+
coinList: MoveCoinList<TokenType, Network>,
|
223
220
|
ctx: ContextType,
|
224
221
|
coinx: string,
|
225
222
|
coiny: string,
|
@@ -24,6 +24,7 @@ export async function codegen(
|
|
24
24
|
|
25
25
|
class SuiNetworkCodegen extends BaseSuiCodegen {
|
26
26
|
moduleGenerator: SharedNetworkCodegen<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject>
|
27
|
+
SYSTEM_PACKAGE = '@sentio/sdk/sui'
|
27
28
|
|
28
29
|
constructor(network: SuiNetwork) {
|
29
30
|
const endpoint = getRpcEndpoint(network)
|
package/src/sui/ext/coin.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { BaseCoinInfo } from '../../move/ext/index.js'
|
2
2
|
import fetch from 'node-fetch'
|
3
3
|
import { accountTypeString, SPLITTER } from '../../move/index.js'
|
4
4
|
import { getPriceByType } from '../../utils/index.js'
|
@@ -7,7 +7,7 @@ import { SuiChainId } from '@sentio/chain'
|
|
7
7
|
import { getClient, SuiNetwork } from '../network.js'
|
8
8
|
import { CoinMetadata } from '@mysten/sui/client'
|
9
9
|
|
10
|
-
const WHITELISTED_COINS = new Map<string,
|
10
|
+
const WHITELISTED_COINS = new Map<string, BaseCoinInfo>()
|
11
11
|
|
12
12
|
export async function initCoinList() {
|
13
13
|
let list = DEFAULT_LIST.coinlist
|
@@ -48,10 +48,7 @@ function setCoinList(list: SuiCoinInfo[]) {
|
|
48
48
|
bridge = 'Wormhole'
|
49
49
|
}
|
50
50
|
WHITELISTED_COINS.set(info.address, {
|
51
|
-
|
52
|
-
type: info.address,
|
53
|
-
account_address: info.address.split('::')[0]
|
54
|
-
},
|
51
|
+
type: info.address,
|
55
52
|
symbol: info.symbol,
|
56
53
|
decimals: info.decimals,
|
57
54
|
bridge
|
@@ -69,13 +66,13 @@ export function whiteListed(coin: string): boolean {
|
|
69
66
|
return WHITELISTED_COINS.has(normalized)
|
70
67
|
}
|
71
68
|
|
72
|
-
export function getCoinInfo(type: string):
|
69
|
+
export function getCoinInfo(type: string): BaseCoinInfo {
|
73
70
|
const r = WHITELISTED_COINS.get(type)
|
74
71
|
if (!r) {
|
75
72
|
const parts = type.split('::')
|
76
73
|
// TDDO retrive from network
|
77
74
|
return {
|
78
|
-
|
75
|
+
type,
|
79
76
|
symbol: parts[2],
|
80
77
|
decimals: 8,
|
81
78
|
bridge: 'native'
|
@@ -86,7 +83,7 @@ export function getCoinInfo(type: string): SimpleCoinInfo {
|
|
86
83
|
|
87
84
|
const COIN_METADATA_CACHE = new Map<string, Promise<CoinMetadata | null>>()
|
88
85
|
|
89
|
-
export async function getCoinInfoWithFallback(type: string, network?: SuiNetwork): Promise<
|
86
|
+
export async function getCoinInfoWithFallback(type: string, network?: SuiNetwork): Promise<BaseCoinInfo> {
|
90
87
|
const r = WHITELISTED_COINS.get(type)
|
91
88
|
if (!r) {
|
92
89
|
network = network || SuiChainId.SUI_MAINNET
|
@@ -104,7 +101,7 @@ export async function getCoinInfoWithFallback(type: string, network?: SuiNetwork
|
|
104
101
|
|
105
102
|
const parts = type.split(SPLITTER)
|
106
103
|
return {
|
107
|
-
|
104
|
+
type,
|
108
105
|
symbol: meta.symbol,
|
109
106
|
decimals: meta.decimals,
|
110
107
|
bridge: 'native'
|
@@ -126,8 +123,8 @@ export async function getPrice(coinType: string, timestamp: number): Promise<num
|
|
126
123
|
}
|
127
124
|
}
|
128
125
|
|
129
|
-
export async function calculateValueInUsd(n: bigint, coinInfo:
|
130
|
-
const price = await getPrice(coinInfo.
|
126
|
+
export async function calculateValueInUsd(n: bigint, coinInfo: BaseCoinInfo, timestamp: number) {
|
127
|
+
const price = await getPrice(coinInfo.type, timestamp)
|
131
128
|
const amount = n.scaleDown(coinInfo.decimals)
|
132
129
|
return amount.multipliedBy(price)
|
133
130
|
}
|
package/src/sui/ext/move-dex.ts
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
import { BigDecimal } from '@sentio/bigdecimal'
|
2
2
|
import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from './coin.js'
|
3
|
-
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor,
|
3
|
+
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, BaseCoinInfo } from '../../move/ext/index.js'
|
4
4
|
import { SuiEvent, SuiMoveNormalizedModule, SuiMoveObject } from '@mysten/sui/client'
|
5
5
|
import { SuiNetwork } from '../network.js'
|
6
6
|
import { SuiContext, SuiObjectContext } from '../context.js'
|
7
7
|
|
8
8
|
export type PoolAdaptor<T> = MovePoolAdaptor<SuiMoveObject, T>
|
9
9
|
|
10
|
-
export class CoinList implements MoveCoinList<SuiNetwork> {
|
11
|
-
calculateValueInUsd(amount: bigint, coinInfo:
|
10
|
+
export class CoinList implements MoveCoinList<BaseCoinInfo, SuiNetwork> {
|
11
|
+
calculateValueInUsd(amount: bigint, coinInfo: BaseCoinInfo, timestamp: number): Promise<BigDecimal> {
|
12
12
|
return calculateValueInUsd(amount, coinInfo, timestamp)
|
13
13
|
}
|
14
14
|
|
15
|
-
getCoinInfo(type: string)
|
15
|
+
async getCoinInfo(type: string) {
|
16
16
|
return getCoinInfo(type)
|
17
17
|
}
|
18
18
|
|
@@ -20,7 +20,7 @@ export class CoinList implements MoveCoinList<SuiNetwork> {
|
|
20
20
|
return whiteListed(type)
|
21
21
|
}
|
22
22
|
|
23
|
-
whitelistCoins(): Map<string,
|
23
|
+
whitelistCoins(): Map<string, BaseCoinInfo> {
|
24
24
|
return whitelistCoins()
|
25
25
|
}
|
26
26
|
}
|
@@ -28,6 +28,7 @@ export class CoinList implements MoveCoinList<SuiNetwork> {
|
|
28
28
|
export const SuiCoinList = new CoinList()
|
29
29
|
|
30
30
|
export class SuiDex<T> extends MoveDex<
|
31
|
+
BaseCoinInfo,
|
31
32
|
SuiNetwork,
|
32
33
|
SuiMoveNormalizedModule,
|
33
34
|
SuiMoveObject,
|
package/lib/aptos/ext/coin.d.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { SimpleCoinInfo } from '../../move/ext/move-dex.js';
|
2
|
-
import { AptosNetwork } from '../network.js';
|
3
|
-
import { AptosChainId } from '@sentio/chain';
|
4
|
-
export declare function initCoinList(): Promise<void>;
|
5
|
-
export declare function whitelistCoins(): Map<string, SimpleCoinInfo>;
|
6
|
-
export declare function whiteListed(coin: string): boolean;
|
7
|
-
export declare function getCoinInfo(type: string): SimpleCoinInfo;
|
8
|
-
export declare function getCoinInfoWithFallback(type: string, network?: AptosNetwork): Promise<SimpleCoinInfo>;
|
9
|
-
export declare function getPrice(coinType: string, timestamp: number, network?: AptosChainId): Promise<number>;
|
10
|
-
export declare function calculateValueInUsd(n: bigint, coinInfo: SimpleCoinInfo, timestamp: number, network?: AptosChainId): Promise<import("@sentio/bigdecimal").BigDecimal>;
|
11
|
-
export declare function delay(ms: number): Promise<unknown>;
|
12
|
-
//# sourceMappingURL=coin.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"coin.d.ts","sourceRoot":"","sources":["../../../src/aptos/ext/coin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAa,MAAM,eAAe,CAAA;AAGvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAI5C,wBAAsB,YAAY,kBAYjC;AA6BD,wBAAgB,cAAc,gCAE7B;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIjD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAaxD;AAID,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CA4B3G;AAED,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,eAA6B,GACnC,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED,wBAAsB,mBAAmB,CACvC,CAAC,EAAE,MAAM,EACT,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,MAAM,EACjB,OAAO,eAA6B,oDAKrC;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAE/B"}
|