@lifi/sdk-provider-sui 4.0.0-beta.4 → 4.0.0-beta.6
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/dist/esm/actions/getSuiBalance.js +10 -3
- package/dist/esm/actions/getSuiBalance.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +5 -5
- package/src/actions/getSuiBalance.ts +10 -10
- package/src/version.ts +1 -1
|
@@ -10,7 +10,8 @@ async function getSuiBalance(client, walletAddress, tokens) {
|
|
|
10
10
|
}
|
|
11
11
|
const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) => {
|
|
12
12
|
const [coins, checkpoint] = await Promise.allSettled([withDedupe(() => callSuiWithRetry(client, (client) => client.getAllBalances({ owner: walletAddress })), { id: `${getSuiBalanceDefault.name}.getAllBalances` }), withDedupe(() => callSuiWithRetry(client, (client) => client.getLatestCheckpointSequenceNumber()), { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` })]);
|
|
13
|
-
const
|
|
13
|
+
const coinsOk = coins.status === "fulfilled";
|
|
14
|
+
const coinsResult = coinsOk ? coins.value : [];
|
|
14
15
|
const blockNumber = checkpoint.status === "fulfilled" ? BigInt(checkpoint.value) : 0n;
|
|
15
16
|
const walletTokenAmounts = coinsResult.reduce((tokenAmounts, coin) => {
|
|
16
17
|
const amount = BigInt(coin.totalBalance);
|
|
@@ -20,9 +21,15 @@ const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) =>
|
|
|
20
21
|
const suiTokenBalance = coinsResult.find((coin) => coin.coinType === SuiTokenShortAddress);
|
|
21
22
|
if (suiTokenBalance?.totalBalance) walletTokenAmounts[SuiTokenLongAddress] = BigInt(suiTokenBalance.totalBalance);
|
|
22
23
|
return tokens.map((token) => {
|
|
23
|
-
|
|
24
|
+
const found = walletTokenAmounts[token.address];
|
|
25
|
+
if (found !== void 0) return {
|
|
24
26
|
...token,
|
|
25
|
-
amount:
|
|
27
|
+
amount: found,
|
|
28
|
+
blockNumber
|
|
29
|
+
};
|
|
30
|
+
if (coinsOk) return {
|
|
31
|
+
...token,
|
|
32
|
+
amount: 0n,
|
|
26
33
|
blockNumber
|
|
27
34
|
};
|
|
28
35
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSuiBalance.js","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport { callSuiWithRetry } from '../client/suiClient.js'\nimport { SuiTokenLongAddress, SuiTokenShortAddress } from '../types.js'\n\nexport async function getSuiBalance(\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> {\n if (tokens.length === 0) {\n return []\n }\n\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n\n return getSuiBalanceDefault(client, chainId, tokens, walletAddress)\n}\n\nconst getSuiBalanceDefault = async (\n client: SDKClient,\n _chainId: number,\n tokens: Token[],\n walletAddress: string\n): Promise<TokenAmount[]> => {\n const [coins, checkpoint] = await Promise.allSettled([\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getAllBalances({\n owner: walletAddress,\n })\n ),\n { id: `${getSuiBalanceDefault.name}.getAllBalances` }\n ),\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getLatestCheckpointSequenceNumber()\n ),\n { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }\n ),\n ])\n\n const
|
|
1
|
+
{"version":3,"file":"getSuiBalance.js","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport { callSuiWithRetry } from '../client/suiClient.js'\nimport { SuiTokenLongAddress, SuiTokenShortAddress } from '../types.js'\n\nexport async function getSuiBalance(\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> {\n if (tokens.length === 0) {\n return []\n }\n\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n\n return getSuiBalanceDefault(client, chainId, tokens, walletAddress)\n}\n\nconst getSuiBalanceDefault = async (\n client: SDKClient,\n _chainId: number,\n tokens: Token[],\n walletAddress: string\n): Promise<TokenAmount[]> => {\n const [coins, checkpoint] = await Promise.allSettled([\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getAllBalances({\n owner: walletAddress,\n })\n ),\n { id: `${getSuiBalanceDefault.name}.getAllBalances` }\n ),\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getLatestCheckpointSequenceNumber()\n ),\n { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }\n ),\n ])\n\n const coinsOk = coins.status === 'fulfilled'\n const coinsResult = coinsOk ? coins.value : []\n const blockNumber =\n checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n\n\n const walletTokenAmounts = coinsResult.reduce(\n (tokenAmounts, coin) => {\n const amount = BigInt(coin.totalBalance)\n if (amount > 0n) {\n tokenAmounts[coin.coinType] = amount\n }\n return tokenAmounts\n },\n {} as Record<string, bigint>\n )\n\n const suiTokenBalance = coinsResult.find(\n (coin) => coin.coinType === SuiTokenShortAddress\n )\n if (suiTokenBalance?.totalBalance) {\n walletTokenAmounts[SuiTokenLongAddress] = BigInt(\n suiTokenBalance.totalBalance\n )\n }\n\n const tokenAmounts: TokenAmount[] = tokens.map((token) => {\n const found = walletTokenAmounts[token.address]\n if (found !== undefined) {\n return { ...token, amount: found, blockNumber }\n }\n if (coinsOk) {\n // Wallet genuinely has no coins of this type.\n return { ...token, amount: 0n, blockNumber }\n }\n // RPC failed — leave amount undefined.\n return { ...token,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,SAAO;GAAE,GAAG;GAAO;GAAa;GAChC"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-sui'\nexport const version = '4.0.0-beta.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-sui'\nexport const version = '4.0.0-beta.6'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-sui",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.6",
|
|
4
4
|
"description": "LI.FI Sui SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "Eugene Chybisov <eugene@li.finance>",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"sideEffects": false,
|
|
18
|
-
"main": "./dist/
|
|
18
|
+
"main": "./dist/esm/index.js",
|
|
19
19
|
"module": "./dist/esm/index.js",
|
|
20
20
|
"types": "./dist/esm/index.d.ts",
|
|
21
21
|
"typings": "./dist/esm/index.d.ts",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
".": {
|
|
24
24
|
"types": "./dist/esm/index.d.ts",
|
|
25
25
|
"import": "./dist/esm/index.js",
|
|
26
|
-
"default": "./dist/
|
|
26
|
+
"default": "./dist/esm/index.js"
|
|
27
27
|
},
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mysten/sui": "^2.
|
|
32
|
-
"@lifi/sdk": "4.0.0-beta.
|
|
31
|
+
"@mysten/sui": "^2.15.0",
|
|
32
|
+
"@lifi/sdk": "4.0.0-beta.6"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
@@ -51,7 +51,8 @@ const getSuiBalanceDefault = async (
|
|
|
51
51
|
),
|
|
52
52
|
])
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const coinsOk = coins.status === 'fulfilled'
|
|
55
|
+
const coinsResult = coinsOk ? coins.value : []
|
|
55
56
|
const blockNumber =
|
|
56
57
|
checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n
|
|
57
58
|
|
|
@@ -76,17 +77,16 @@ const getSuiBalanceDefault = async (
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
const tokenAmounts: TokenAmount[] = tokens.map((token) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
amount: walletTokenAmounts[token.address],
|
|
83
|
-
blockNumber,
|
|
84
|
-
}
|
|
80
|
+
const found = walletTokenAmounts[token.address]
|
|
81
|
+
if (found !== undefined) {
|
|
82
|
+
return { ...token, amount: found, blockNumber }
|
|
85
83
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
blockNumber
|
|
84
|
+
if (coinsOk) {
|
|
85
|
+
// Wallet genuinely has no coins of this type.
|
|
86
|
+
return { ...token, amount: 0n, blockNumber }
|
|
89
87
|
}
|
|
88
|
+
// RPC failed — leave amount undefined.
|
|
89
|
+
return { ...token, blockNumber }
|
|
90
90
|
})
|
|
91
91
|
return tokenAmounts
|
|
92
92
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-sui'
|
|
2
|
-
export const version = '4.0.0-beta.
|
|
2
|
+
export const version = '4.0.0-beta.6'
|