@lifi/sdk-provider-sui 4.0.1 → 4.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @lifi/sdk-provider-sui
2
2
 
3
+ ## 4.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#407](https://github.com/lifinance/sdk/pull/407) [`2254196`](https://github.com/lifinance/sdk/commit/2254196129bccec1ba8d3afe8e7a4cb714230831) Thanks [@chybisov](https://github.com/chybisov)! - Use the `getJsonRpcFullnodeUrl` helper for the default Sui fullnode URL in SuiNS resolution instead of a hardcoded string. No behavior change — the helper returns the same mainnet endpoint.
8
+
9
+ - Updated dependencies [[`e8c8b69`](https://github.com/lifinance/sdk/commit/e8c8b6999ba8ffc127d47ba4a648d0a2792a4870), [`82b6c17`](https://github.com/lifinance/sdk/commit/82b6c17ceadfe3968e27e2c7bb3b8a1a0ded1840), [`2ced1e4`](https://github.com/lifinance/sdk/commit/2ced1e4881923ac14e110b3009150a5bd4f9d318), [`6e1b100`](https://github.com/lifinance/sdk/commit/6e1b1009700561571d0dca864f539129951c162b)]:
10
+ - @lifi/sdk@4.1.0
11
+
12
+ ## 4.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#404](https://github.com/lifinance/sdk/pull/404) [`e85d5e7`](https://github.com/lifinance/sdk/commit/e85d5e7c2da581a2397429392e14f2d47b4efa87) Thanks [@chybisov](https://github.com/chybisov)! - Migrate the Sui integration off the deprecated JSON-RPC client (`SuiJsonRpcClient`) to the gRPC Core API (`SuiGrpcClient` / `client.core.*`) ahead of Sui's JSON-RPC sunset. Balance fetching (`listBalances`, now paginated), latest-checkpoint lookup (`ledgerService.getServiceInfo`), transaction confirmation (`core.waitForTransaction`), and SuiNS resolution (`nameService.lookupName`) now use gRPC. No public API changes.
17
+
3
18
  ## 4.0.1
4
19
 
5
20
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"getSuiBalance.d.ts","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"mappings":";;;iBASsB,aAAA,CACpB,MAAA,EAAQ,SAAA,EACR,aAAA,UACA,MAAA,EAAQ,KAAA,KACP,OAAA,CAAQ,WAAA"}
1
+ {"version":3,"file":"getSuiBalance.d.ts","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"mappings":";;;iBAUsB,aAAA,CACpB,MAAA,EAAQ,SAAA,EACR,aAAA,UACA,MAAA,EAAQ,KAAA,KACP,OAAA,CAAQ,WAAA"}
@@ -9,17 +9,36 @@ async function getSuiBalance(client, walletAddress, tokens) {
9
9
  return getSuiBalanceDefault(client, chainId, tokens, walletAddress);
10
10
  }
11
11
  const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) => {
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` })]);
12
+ const [coins, checkpoint] = await Promise.allSettled([withDedupe(() => callSuiWithRetry(client, async (suiClient) => {
13
+ const balances = [];
14
+ let cursor;
15
+ do {
16
+ const page = await suiClient.core.listBalances({
17
+ owner: walletAddress,
18
+ cursor
19
+ });
20
+ balances.push(...page.balances);
21
+ cursor = page.hasNextPage ? page.cursor : null;
22
+ } while (cursor);
23
+ return balances;
24
+ }), { id: `${getSuiBalanceDefault.name}.listBalances` }), withDedupe(() => callSuiWithRetry(client, async (suiClient) => {
25
+ const { response } = await suiClient.ledgerService.getServiceInfo({});
26
+ return response.checkpointHeight ?? 0n;
27
+ }), { id: `${getSuiBalanceDefault.name}.getServiceInfo` })]);
13
28
  const coinsOk = coins.status === "fulfilled";
14
29
  const coinsResult = coinsOk ? coins.value : [];
15
- const blockNumber = checkpoint.status === "fulfilled" ? BigInt(checkpoint.value) : 0n;
30
+ const blockNumber = checkpoint.status === "fulfilled" ? checkpoint.value : 0n;
16
31
  const walletTokenAmounts = coinsResult.reduce((tokenAmounts, coin) => {
17
- const amount = BigInt(coin.totalBalance);
32
+ const amount = BigInt(coin.balance);
18
33
  if (amount > 0n) tokenAmounts[coin.coinType] = amount;
19
34
  return tokenAmounts;
20
35
  }, {});
21
- const suiTokenBalance = coinsResult.find((coin) => coin.coinType === SuiTokenShortAddress);
22
- if (suiTokenBalance?.totalBalance) walletTokenAmounts[SuiTokenLongAddress] = BigInt(suiTokenBalance.totalBalance);
36
+ const suiTokenBalance = coinsResult.find((coin) => coin.coinType === "0x2::sui::SUI" || coin.coinType === "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI");
37
+ if (suiTokenBalance?.balance) {
38
+ const suiAmount = BigInt(suiTokenBalance.balance);
39
+ walletTokenAmounts[SuiTokenShortAddress] = suiAmount;
40
+ walletTokenAmounts[SuiTokenLongAddress] = suiAmount;
41
+ }
23
42
  return tokens.map((token) => {
24
43
  const found = walletTokenAmounts[token.address];
25
44
  if (found !== void 0) 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 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, blockNumber }\n })\n return tokenAmounts\n}\n"],"mappings":";;;;AASA,eAAsB,cACpB,QACA,eACA,QACwB;CACxB,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAIjE,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,aAAa;AACpE;AAEA,MAAM,uBAAuB,OAC3B,QACA,UACA,QACA,kBAC2B;CAC3B,MAAM,CAAC,OAAO,cAAc,MAAM,QAAQ,WAAW,CACnD,iBAEI,iBAAiB,SAAS,WACxB,OAAO,eAAe,EACpB,OAAO,cACT,CAAC,CACH,GACF,EAAE,IAAI,GAAG,qBAAqB,KAAK,iBAAiB,CACtD,GACA,iBAEI,iBAAiB,SAAS,WACxB,OAAO,kCAAkC,CAC3C,GACF,EAAE,IAAI,GAAG,qBAAqB,KAAK,oCAAoC,CACzE,CACF,CAAC;CAED,MAAM,UAAU,MAAM,WAAW;CACjC,MAAM,cAAc,UAAU,MAAM,QAAQ,CAAC;CAC7C,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,KAAK,IAAI;CAEjE,MAAM,qBAAqB,YAAY,QACpC,cAAc,SAAS;EACtB,MAAM,SAAS,OAAO,KAAK,YAAY;EACvC,IAAI,SAAS,IACX,aAAa,KAAK,YAAY;EAEhC,OAAO;CACT,GACA,CAAC,CACH;CAEA,MAAM,kBAAkB,YAAY,MACjC,SAAS,KAAK,aAAa,oBAC9B;CACA,IAAI,iBAAiB,cACnB,mBAAmB,uBAAuB,OACxC,gBAAgB,YAClB;CAeF,OAZoC,OAAO,KAAK,UAAU;EACxD,MAAM,QAAQ,mBAAmB,MAAM;EACvC,IAAI,UAAU,KAAA,GACZ,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAO;EAAY;EAEhD,IAAI,SAEF,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAI;EAAY;EAG7C,OAAO;GAAE,GAAG;GAAO;EAAY;CACjC,CACkB;AACpB"}
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 type { SuiClientTypes } from '@mysten/sui/client'\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, async (suiClient) => {\n // listBalances is paginated; page through to collect every coin type.\n const balances: SuiClientTypes.Balance[] = []\n let cursor: string | null | undefined\n do {\n const page = await suiClient.core.listBalances({\n owner: walletAddress,\n cursor,\n })\n balances.push(...page.balances)\n cursor = page.hasNextPage ? page.cursor : null\n } while (cursor)\n return balances\n }),\n { id: `${getSuiBalanceDefault.name}.listBalances` }\n ),\n withDedupe(\n () =>\n callSuiWithRetry(client, async (suiClient) => {\n const { response } = await suiClient.ledgerService.getServiceInfo({})\n return response.checkpointHeight ?? 0n\n }),\n { id: `${getSuiBalanceDefault.name}.getServiceInfo` }\n ),\n ])\n\n const coinsOk = coins.status === 'fulfilled'\n const coinsResult = coinsOk ? coins.value : []\n const blockNumber = checkpoint.status === 'fulfilled' ? checkpoint.value : 0n\n\n const walletTokenAmounts = coinsResult.reduce(\n (tokenAmounts, coin) => {\n const amount = BigInt(coin.balance)\n if (amount > 0n) {\n tokenAmounts[coin.coinType] = amount\n }\n return tokenAmounts\n },\n {} as Record<string, bigint>\n )\n\n // The native SUI coin type can be returned in short (`0x2::sui::SUI`) or\n // fully-normalized (`0x0000…0002::sui::SUI`) form depending on the RPC.\n // Map both so token lists using either format resolve.\n const suiTokenBalance = coinsResult.find(\n (coin) =>\n coin.coinType === SuiTokenShortAddress ||\n coin.coinType === SuiTokenLongAddress\n )\n if (suiTokenBalance?.balance) {\n const suiAmount = BigInt(suiTokenBalance.balance)\n walletTokenAmounts[SuiTokenShortAddress] = suiAmount\n walletTokenAmounts[SuiTokenLongAddress] = suiAmount\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, blockNumber }\n })\n return tokenAmounts\n}\n"],"mappings":";;;;AAUA,eAAsB,cACpB,QACA,eACA,QACwB;CACxB,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAIjE,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,aAAa;AACpE;AAEA,MAAM,uBAAuB,OAC3B,QACA,UACA,QACA,kBAC2B;CAC3B,MAAM,CAAC,OAAO,cAAc,MAAM,QAAQ,WAAW,CACnD,iBAEI,iBAAiB,QAAQ,OAAO,cAAc;EAE5C,MAAM,WAAqC,CAAC;EAC5C,IAAI;EACJ,GAAG;GACD,MAAM,OAAO,MAAM,UAAU,KAAK,aAAa;IAC7C,OAAO;IACP;GACF,CAAC;GACD,SAAS,KAAK,GAAG,KAAK,QAAQ;GAC9B,SAAS,KAAK,cAAc,KAAK,SAAS;EAC5C,SAAS;EACT,OAAO;CACT,CAAC,GACH,EAAE,IAAI,GAAG,qBAAqB,KAAK,eAAe,CACpD,GACA,iBAEI,iBAAiB,QAAQ,OAAO,cAAc;EAC5C,MAAM,EAAE,aAAa,MAAM,UAAU,cAAc,eAAe,CAAC,CAAC;EACpE,OAAO,SAAS,oBAAoB;CACtC,CAAC,GACH,EAAE,IAAI,GAAG,qBAAqB,KAAK,iBAAiB,CACtD,CACF,CAAC;CAED,MAAM,UAAU,MAAM,WAAW;CACjC,MAAM,cAAc,UAAU,MAAM,QAAQ,CAAC;CAC7C,MAAM,cAAc,WAAW,WAAW,cAAc,WAAW,QAAQ;CAE3E,MAAM,qBAAqB,YAAY,QACpC,cAAc,SAAS;EACtB,MAAM,SAAS,OAAO,KAAK,OAAO;EAClC,IAAI,SAAS,IACX,aAAa,KAAK,YAAY;EAEhC,OAAO;CACT,GACA,CAAC,CACH;CAKA,MAAM,kBAAkB,YAAY,MACjC,SACC,KAAK,aAAA,mBACL,KAAK,aAAA,8EACT;CACA,IAAI,iBAAiB,SAAS;EAC5B,MAAM,YAAY,OAAO,gBAAgB,OAAO;EAChD,mBAAmB,wBAAwB;EAC3C,mBAAmB,uBAAuB;CAC5C;CAcA,OAZoC,OAAO,KAAK,UAAU;EACxD,MAAM,QAAQ,mBAAmB,MAAM;EACvC,IAAI,UAAU,KAAA,GACZ,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAO;EAAY;EAEhD,IAAI,SAEF,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAI;EAAY;EAG7C,OAAO;GAAE,GAAG;GAAO;EAAY;CACjC,CACkB;AACpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"getSuiNSAddress.d.ts","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"mappings":";;;iBAMsB,eAAA,CACpB,IAAA,UACA,MAAA,WACA,OAAA,GAAU,cAAA,CAAe,OAAA,GACxB,OAAA"}
1
+ {"version":3,"file":"getSuiNSAddress.d.ts","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"mappings":";;;iBAIsB,eAAA,CACpB,IAAA,UACA,MAAA,WACA,OAAA,GAAU,cAAA,CAAe,OAAA,GACxB,OAAA"}
@@ -1,20 +1,14 @@
1
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
1
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
+ import { getJsonRpcFullnodeUrl } from "@mysten/sui/jsonRpc";
2
3
  //#region src/actions/getSuiNSAddress.ts
3
- const SNS_REGISTRY_ID = "0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4";
4
4
  async function getSuiNSAddress(name, rpcUrl, network) {
5
- const client = new SuiJsonRpcClient({
6
- url: rpcUrl || "https://fullnode.mainnet.sui.io:443",
7
- network: network || "mainnet"
5
+ const client = new SuiGrpcClient({
6
+ network: network || "mainnet",
7
+ baseUrl: rpcUrl || getJsonRpcFullnodeUrl("mainnet")
8
8
  });
9
9
  try {
10
- const result = await client.getObject({
11
- id: SNS_REGISTRY_ID,
12
- options: { showContent: true }
13
- });
14
- if (!result.data?.content) return;
15
- const nameRecord = result.data.content.fields.records.find((record) => record.fields.name === name);
16
- if (!nameRecord) return;
17
- return nameRecord.fields.address;
10
+ const { response } = await client.nameService.lookupName({ name });
11
+ return response.record?.targetAddress;
18
12
  } catch (error) {
19
13
  console.error("Error resolving SuiNS address:", error);
20
14
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"getSuiNSAddress.js","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"sourcesContent":["import type { SuiClientTypes } from '@mysten/sui/client'\nimport { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'\n\nconst SNS_REGISTRY_ID =\n '0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4'\n\nexport async function getSuiNSAddress(\n name: string,\n rpcUrl?: string,\n network?: SuiClientTypes.Network\n): Promise<string | undefined> {\n const client = new SuiJsonRpcClient({\n url: rpcUrl || 'https://fullnode.mainnet.sui.io:443',\n network: network || 'mainnet',\n })\n\n try {\n const result = await client.getObject({\n id: SNS_REGISTRY_ID,\n options: {\n showContent: true,\n },\n })\n\n if (!result.data?.content) {\n return\n }\n\n const registry = result.data.content as any\n const nameRecord = registry.fields.records.find(\n (record: any) => record.fields.name === name\n )\n\n if (!nameRecord) {\n return\n }\n\n return nameRecord.fields.address\n } catch (error) {\n console.error('Error resolving SuiNS address:', error)\n return\n }\n}\n"],"mappings":";;AAGA,MAAM,kBACJ;AAEF,eAAsB,gBACpB,MACA,QACA,SAC6B;CAC7B,MAAM,SAAS,IAAI,iBAAiB;EAClC,KAAK,UAAU;EACf,SAAS,WAAW;CACtB,CAAC;CAED,IAAI;EACF,MAAM,SAAS,MAAM,OAAO,UAAU;GACpC,IAAI;GACJ,SAAS,EACP,aAAa,KACf;EACF,CAAC;EAED,IAAI,CAAC,OAAO,MAAM,SAChB;EAIF,MAAM,aADW,OAAO,KAAK,QACD,OAAO,QAAQ,MACxC,WAAgB,OAAO,OAAO,SAAS,IAC1C;EAEA,IAAI,CAAC,YACH;EAGF,OAAO,WAAW,OAAO;CAC3B,SAAS,OAAO;EACd,QAAQ,MAAM,kCAAkC,KAAK;EACrD;CACF;AACF"}
1
+ {"version":3,"file":"getSuiNSAddress.js","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"sourcesContent":["import type { SuiClientTypes } from '@mysten/sui/client'\nimport { SuiGrpcClient } from '@mysten/sui/grpc'\nimport { getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc'\n\nexport async function getSuiNSAddress(\n name: string,\n rpcUrl?: string,\n network?: SuiClientTypes.Network\n): Promise<string | undefined> {\n const client = new SuiGrpcClient({\n network: network || 'mainnet',\n baseUrl: rpcUrl || getJsonRpcFullnodeUrl('mainnet'),\n })\n\n try {\n const { response } = await client.nameService.lookupName({ name })\n return response.record?.targetAddress\n } catch (error) {\n console.error('Error resolving SuiNS address:', error)\n return\n }\n}\n"],"mappings":";;;AAIA,eAAsB,gBACpB,MACA,QACA,SAC6B;CAC7B,MAAM,SAAS,IAAI,cAAc;EAC/B,SAAS,WAAW;EACpB,SAAS,UAAU,sBAAsB,SAAS;CACpD,CAAC;CAED,IAAI;EACF,MAAM,EAAE,aAAa,MAAM,OAAO,YAAY,WAAW,EAAE,KAAK,CAAC;EACjE,OAAO,SAAS,QAAQ;CAC1B,SAAS,OAAO;EACd,QAAQ,MAAM,kCAAkC,KAAK;EACrD;CACF;AACF"}
@@ -1,14 +1,14 @@
1
1
  import { SDKClient } from "@lifi/sdk";
2
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
2
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
3
3
 
4
4
  //#region src/client/suiClient.d.ts
5
5
  /**
6
- * Calls a function on the SuiJsonRpcClient instances with retry logic.
6
+ * Calls a function on the SuiGrpcClient instances with retry logic.
7
7
  * @param client - The SDK client
8
- * @param fn - The function to call, which receives a SuiJsonRpcClient instance.
8
+ * @param fn - The function to call, which receives a SuiGrpcClient instance.
9
9
  * @returns - The result of the function call.
10
10
  */
11
- declare function callSuiWithRetry<R>(client: SDKClient, fn: (client: SuiJsonRpcClient) => Promise<R>): Promise<R>;
11
+ declare function callSuiWithRetry<R>(client: SDKClient, fn: (client: SuiGrpcClient) => Promise<R>): Promise<R>;
12
12
  //#endregion
13
13
  export { callSuiWithRetry };
14
14
  //# sourceMappingURL=suiClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"suiClient.d.ts","names":[],"sources":["../../../src/client/suiClient.ts"],"mappings":";;;;;;AAyBA;;;;iBAAsB,gBAAA,IACpB,MAAA,EAAQ,SAAA,EACR,EAAA,GAAK,MAAA,EAAQ,gBAAA,KAAqB,OAAA,CAAQ,CAAA,IACzC,OAAA,CAAQ,CAAA"}
1
+ {"version":3,"file":"suiClient.d.ts","names":[],"sources":["../../../src/client/suiClient.ts"],"mappings":";;;;;;AAyBA;;;;iBAAsB,gBAAA,IACpB,MAAA,EAAQ,SAAA,EACR,EAAA,GAAK,MAAA,EAAQ,aAAA,KAAkB,OAAA,CAAQ,CAAA,IACtC,OAAA,CAAQ,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { ChainId } from "@lifi/sdk";
2
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
2
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
3
3
  //#region src/client/suiClient.ts
4
4
  const clients = /* @__PURE__ */ new Map();
5
5
  /**
@@ -9,17 +9,17 @@ const clients = /* @__PURE__ */ new Map();
9
9
  const ensureClients = async (client) => {
10
10
  const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI);
11
11
  for (const rpcUrl of rpcUrls) if (!clients.get(rpcUrl)) {
12
- const client = new SuiJsonRpcClient({
13
- url: rpcUrl,
14
- network: "mainnet"
12
+ const client = new SuiGrpcClient({
13
+ network: "mainnet",
14
+ baseUrl: rpcUrl
15
15
  });
16
16
  clients.set(rpcUrl, client);
17
17
  }
18
18
  };
19
19
  /**
20
- * Calls a function on the SuiJsonRpcClient instances with retry logic.
20
+ * Calls a function on the SuiGrpcClient instances with retry logic.
21
21
  * @param client - The SDK client
22
- * @param fn - The function to call, which receives a SuiJsonRpcClient instance.
22
+ * @param fn - The function to call, which receives a SuiGrpcClient instance.
23
23
  * @returns - The result of the function call.
24
24
  */
25
25
  async function callSuiWithRetry(client, fn) {
@@ -1 +1 @@
1
- {"version":3,"file":"suiClient.js","names":[],"sources":["../../../src/client/suiClient.ts"],"sourcesContent":["import { ChainId, type SDKClient } from '@lifi/sdk'\nimport { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'\n\nconst clients = new Map<string, SuiJsonRpcClient>()\n\n/**\n * Initializes the Sui clients if they haven't been initialized yet.\n * @returns - Promise that resolves when clients are initialized.\n */\nconst ensureClients = async (client: SDKClient): Promise<void> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI)\n for (const rpcUrl of rpcUrls) {\n if (!clients.get(rpcUrl)) {\n const client = new SuiJsonRpcClient({ url: rpcUrl, network: 'mainnet' })\n clients.set(rpcUrl, client)\n }\n }\n}\n\n/**\n * Calls a function on the SuiJsonRpcClient instances with retry logic.\n * @param client - The SDK client\n * @param fn - The function to call, which receives a SuiJsonRpcClient instance.\n * @returns - The result of the function call.\n */\nexport async function callSuiWithRetry<R>(\n client: SDKClient,\n fn: (client: SuiJsonRpcClient) => Promise<R>\n): Promise<R> {\n // Ensure clients are initialized\n await ensureClients(client)\n let lastError: any = null\n for (const client of clients.values()) {\n try {\n const result = await fn(client)\n return result\n } catch (error) {\n lastError = error\n }\n }\n // Throw the last encountered error\n throw lastError\n}\n"],"mappings":";;;AAGA,MAAM,0BAAU,IAAI,IAA8B;;;;;AAMlD,MAAM,gBAAgB,OAAO,WAAqC;CAChE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,QAAQ,IAAI,MAAM,GAAG;EACxB,MAAM,SAAS,IAAI,iBAAiB;GAAE,KAAK;GAAQ,SAAS;EAAU,CAAC;EACvE,QAAQ,IAAI,QAAQ,MAAM;CAC5B;AAEJ;;;;;;;AAQA,eAAsB,iBACpB,QACA,IACY;CAEZ,MAAM,cAAc,MAAM;CAC1B,IAAI,YAAiB;CACrB,KAAK,MAAM,UAAU,QAAQ,OAAO,GAClC,IAAI;EAEF,OAAO,MADc,GAAG,MAAM;CAEhC,SAAS,OAAO;EACd,YAAY;CACd;CAGF,MAAM;AACR"}
1
+ {"version":3,"file":"suiClient.js","names":[],"sources":["../../../src/client/suiClient.ts"],"sourcesContent":["import { ChainId, type SDKClient } from '@lifi/sdk'\nimport { SuiGrpcClient } from '@mysten/sui/grpc'\n\nconst clients = new Map<string, SuiGrpcClient>()\n\n/**\n * Initializes the Sui clients if they haven't been initialized yet.\n * @returns - Promise that resolves when clients are initialized.\n */\nconst ensureClients = async (client: SDKClient): Promise<void> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI)\n for (const rpcUrl of rpcUrls) {\n if (!clients.get(rpcUrl)) {\n const client = new SuiGrpcClient({ network: 'mainnet', baseUrl: rpcUrl })\n clients.set(rpcUrl, client)\n }\n }\n}\n\n/**\n * Calls a function on the SuiGrpcClient instances with retry logic.\n * @param client - The SDK client\n * @param fn - The function to call, which receives a SuiGrpcClient instance.\n * @returns - The result of the function call.\n */\nexport async function callSuiWithRetry<R>(\n client: SDKClient,\n fn: (client: SuiGrpcClient) => Promise<R>\n): Promise<R> {\n // Ensure clients are initialized\n await ensureClients(client)\n let lastError: any = null\n for (const client of clients.values()) {\n try {\n const result = await fn(client)\n return result\n } catch (error) {\n lastError = error\n }\n }\n // Throw the last encountered error\n throw lastError\n}\n"],"mappings":";;;AAGA,MAAM,0BAAU,IAAI,IAA2B;;;;;AAM/C,MAAM,gBAAgB,OAAO,WAAqC;CAChE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,QAAQ,IAAI,MAAM,GAAG;EACxB,MAAM,SAAS,IAAI,cAAc;GAAE,SAAS;GAAW,SAAS;EAAO,CAAC;EACxE,QAAQ,IAAI,QAAQ,MAAM;CAC5B;AAEJ;;;;;;;AAQA,eAAsB,iBACpB,QACA,IACY;CAEZ,MAAM,cAAc,MAAM;CAC1B,IAAI,YAAiB;CACrB,KAAK,MAAM,UAAU,QAAQ,OAAO,GAClC,IAAI;EAEF,OAAO,MADc,GAAG,MAAM;CAEhC,SAAS,OAAO;EACd,YAAY;CACd;CAGF,MAAM;AACR"}
@@ -7,14 +7,12 @@ var SuiWaitForTransactionTask = class extends BaseStepExecutionTask {
7
7
  if (!signedTransaction) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transaction is not found.");
8
8
  const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
9
9
  if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
10
- const result = await callSuiWithRetry(client, (client) => client.waitForTransaction({
11
- digest: signedTransaction.digest,
12
- options: { showEffects: true }
13
- }));
14
- if (result.effects?.status.status !== "success") throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${result.effects?.status.error}`);
10
+ const result = await callSuiWithRetry(client, (client) => client.core.waitForTransaction({ digest: signedTransaction.digest }));
11
+ const transaction = result.Transaction ?? result.FailedTransaction;
12
+ if (!transaction?.status.success) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${transaction?.status.error?.message ?? `Unexpected transaction result: ${result.$kind}`}`);
15
13
  statusManager.updateAction(step, action.type, "PENDING", {
16
- txHash: result.digest,
17
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${result.digest}`
14
+ txHash: transaction.digest,
15
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${transaction.digest}`
18
16
  });
19
17
  if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
20
18
  return { status: "COMPLETED" };
@@ -1 +1 @@
1
- {"version":3,"file":"SuiWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SuiWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { callSuiWithRetry } from '../../client/suiClient.js'\nimport type { SuiStepExecutorContext } from '../../types.js'\n\nexport class SuiWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SuiStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransaction,\n } = context\n\n if (!signedTransaction) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transaction is not found.'\n )\n }\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const result = await callSuiWithRetry(client, (client) =>\n client.waitForTransaction({\n digest: signedTransaction.digest,\n options: {\n showEffects: true,\n },\n })\n )\n\n if (result.effects?.status.status !== 'success') {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${result.effects?.status.error}`\n )\n }\n\n // Transaction has been confirmed and we can update the action\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: result.digest,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${result.digest}`,\n })\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;AASA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAAsD;EAC9D,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,sBACE;EAEJ,IAAI,CAAC,mBACH,MAAM,IAAI,iBACR,cAAc,uBACd,iEACF;EAGF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,SAAS,MAAM,iBAAiB,SAAS,WAC7C,OAAO,mBAAmB;GACxB,QAAQ,kBAAkB;GAC1B,SAAS,EACP,aAAa,KACf;EACF,CAAC,CACH;EAEA,IAAI,OAAO,SAAS,OAAO,WAAW,WACpC,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,OAAO,SAAS,OAAO,OAChD;EAIF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,OAAO;GACf,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,UAAU,OAAO;EACtE,CAAC;EAED,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
1
+ {"version":3,"file":"SuiWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SuiWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { callSuiWithRetry } from '../../client/suiClient.js'\nimport type { SuiStepExecutorContext } from '../../types.js'\n\nexport class SuiWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SuiStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransaction,\n } = context\n\n if (!signedTransaction) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transaction is not found.'\n )\n }\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const result = await callSuiWithRetry(client, (client) =>\n client.core.waitForTransaction({\n digest: signedTransaction.digest,\n })\n )\n\n const transaction = result.Transaction ?? result.FailedTransaction\n if (!transaction?.status.success) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${transaction?.status.error?.message ?? `Unexpected transaction result: ${result.$kind}`}`\n )\n }\n\n // Transaction has been confirmed and we can update the action\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.digest,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${transaction.digest}`,\n })\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;AASA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAAsD;EAC9D,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,sBACE;EAEJ,IAAI,CAAC,mBACH,MAAM,IAAI,iBACR,cAAc,uBACd,iEACF;EAGF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,SAAS,MAAM,iBAAiB,SAAS,WAC7C,OAAO,KAAK,mBAAmB,EAC7B,QAAQ,kBAAkB,OAC5B,CAAC,CACH;EAEA,MAAM,cAAc,OAAO,eAAe,OAAO;EACjD,IAAI,CAAC,aAAa,OAAO,SACvB,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,aAAa,OAAO,OAAO,WAAW,kCAAkC,OAAO,SACxG;EAIF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,UAAU,YAAY;EAC3E,CAAC;EAED,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
@@ -1,6 +1,6 @@
1
1
  //#region src/version.d.ts
2
2
  declare const name = "@lifi/sdk-provider-sui";
3
- declare const version = "4.0.1";
3
+ declare const version = "4.1.1";
4
4
  //#endregion
5
5
  export { name, version };
6
6
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-sui";
3
- const version = "4.0.1";
3
+ const version = "4.1.1";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -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.1'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-sui'\nexport const version = '4.1.1'\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.1",
3
+ "version": "4.1.1",
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": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@mysten/sui": "^2.19.0",
32
- "@lifi/sdk": "4.0.1"
32
+ "@lifi/sdk": "4.1.0"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
@@ -4,6 +4,7 @@ import {
4
4
  type TokenAmount,
5
5
  withDedupe,
6
6
  } from '@lifi/sdk'
7
+ import type { SuiClientTypes } from '@mysten/sui/client'
7
8
  import { callSuiWithRetry } from '../client/suiClient.js'
8
9
  import { SuiTokenLongAddress, SuiTokenShortAddress } from '../types.js'
9
10
 
@@ -35,30 +36,39 @@ const getSuiBalanceDefault = async (
35
36
  const [coins, checkpoint] = await Promise.allSettled([
36
37
  withDedupe(
37
38
  () =>
38
- callSuiWithRetry(client, (client) =>
39
- client.getAllBalances({
40
- owner: walletAddress,
41
- })
42
- ),
43
- { id: `${getSuiBalanceDefault.name}.getAllBalances` }
39
+ callSuiWithRetry(client, async (suiClient) => {
40
+ // listBalances is paginated; page through to collect every coin type.
41
+ const balances: SuiClientTypes.Balance[] = []
42
+ let cursor: string | null | undefined
43
+ do {
44
+ const page = await suiClient.core.listBalances({
45
+ owner: walletAddress,
46
+ cursor,
47
+ })
48
+ balances.push(...page.balances)
49
+ cursor = page.hasNextPage ? page.cursor : null
50
+ } while (cursor)
51
+ return balances
52
+ }),
53
+ { id: `${getSuiBalanceDefault.name}.listBalances` }
44
54
  ),
45
55
  withDedupe(
46
56
  () =>
47
- callSuiWithRetry(client, (client) =>
48
- client.getLatestCheckpointSequenceNumber()
49
- ),
50
- { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }
57
+ callSuiWithRetry(client, async (suiClient) => {
58
+ const { response } = await suiClient.ledgerService.getServiceInfo({})
59
+ return response.checkpointHeight ?? 0n
60
+ }),
61
+ { id: `${getSuiBalanceDefault.name}.getServiceInfo` }
51
62
  ),
52
63
  ])
53
64
 
54
65
  const coinsOk = coins.status === 'fulfilled'
55
66
  const coinsResult = coinsOk ? coins.value : []
56
- const blockNumber =
57
- checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n
67
+ const blockNumber = checkpoint.status === 'fulfilled' ? checkpoint.value : 0n
58
68
 
59
69
  const walletTokenAmounts = coinsResult.reduce(
60
70
  (tokenAmounts, coin) => {
61
- const amount = BigInt(coin.totalBalance)
71
+ const amount = BigInt(coin.balance)
62
72
  if (amount > 0n) {
63
73
  tokenAmounts[coin.coinType] = amount
64
74
  }
@@ -67,13 +77,18 @@ const getSuiBalanceDefault = async (
67
77
  {} as Record<string, bigint>
68
78
  )
69
79
 
80
+ // The native SUI coin type can be returned in short (`0x2::sui::SUI`) or
81
+ // fully-normalized (`0x0000…0002::sui::SUI`) form depending on the RPC.
82
+ // Map both so token lists using either format resolve.
70
83
  const suiTokenBalance = coinsResult.find(
71
- (coin) => coin.coinType === SuiTokenShortAddress
84
+ (coin) =>
85
+ coin.coinType === SuiTokenShortAddress ||
86
+ coin.coinType === SuiTokenLongAddress
72
87
  )
73
- if (suiTokenBalance?.totalBalance) {
74
- walletTokenAmounts[SuiTokenLongAddress] = BigInt(
75
- suiTokenBalance.totalBalance
76
- )
88
+ if (suiTokenBalance?.balance) {
89
+ const suiAmount = BigInt(suiTokenBalance.balance)
90
+ walletTokenAmounts[SuiTokenShortAddress] = suiAmount
91
+ walletTokenAmounts[SuiTokenLongAddress] = suiAmount
77
92
  }
78
93
 
79
94
  const tokenAmounts: TokenAmount[] = tokens.map((token) => {
@@ -1,41 +1,20 @@
1
1
  import type { SuiClientTypes } from '@mysten/sui/client'
2
- import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'
3
-
4
- const SNS_REGISTRY_ID =
5
- '0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4'
2
+ import { SuiGrpcClient } from '@mysten/sui/grpc'
3
+ import { getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc'
6
4
 
7
5
  export async function getSuiNSAddress(
8
6
  name: string,
9
7
  rpcUrl?: string,
10
8
  network?: SuiClientTypes.Network
11
9
  ): Promise<string | undefined> {
12
- const client = new SuiJsonRpcClient({
13
- url: rpcUrl || 'https://fullnode.mainnet.sui.io:443',
10
+ const client = new SuiGrpcClient({
14
11
  network: network || 'mainnet',
12
+ baseUrl: rpcUrl || getJsonRpcFullnodeUrl('mainnet'),
15
13
  })
16
14
 
17
15
  try {
18
- const result = await client.getObject({
19
- id: SNS_REGISTRY_ID,
20
- options: {
21
- showContent: true,
22
- },
23
- })
24
-
25
- if (!result.data?.content) {
26
- return
27
- }
28
-
29
- const registry = result.data.content as any
30
- const nameRecord = registry.fields.records.find(
31
- (record: any) => record.fields.name === name
32
- )
33
-
34
- if (!nameRecord) {
35
- return
36
- }
37
-
38
- return nameRecord.fields.address
16
+ const { response } = await client.nameService.lookupName({ name })
17
+ return response.record?.targetAddress
39
18
  } catch (error) {
40
19
  console.error('Error resolving SuiNS address:', error)
41
20
  return
@@ -1,7 +1,7 @@
1
1
  import { ChainId, type SDKClient } from '@lifi/sdk'
2
- import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'
2
+ import { SuiGrpcClient } from '@mysten/sui/grpc'
3
3
 
4
- const clients = new Map<string, SuiJsonRpcClient>()
4
+ const clients = new Map<string, SuiGrpcClient>()
5
5
 
6
6
  /**
7
7
  * Initializes the Sui clients if they haven't been initialized yet.
@@ -11,21 +11,21 @@ const ensureClients = async (client: SDKClient): Promise<void> => {
11
11
  const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI)
12
12
  for (const rpcUrl of rpcUrls) {
13
13
  if (!clients.get(rpcUrl)) {
14
- const client = new SuiJsonRpcClient({ url: rpcUrl, network: 'mainnet' })
14
+ const client = new SuiGrpcClient({ network: 'mainnet', baseUrl: rpcUrl })
15
15
  clients.set(rpcUrl, client)
16
16
  }
17
17
  }
18
18
  }
19
19
 
20
20
  /**
21
- * Calls a function on the SuiJsonRpcClient instances with retry logic.
21
+ * Calls a function on the SuiGrpcClient instances with retry logic.
22
22
  * @param client - The SDK client
23
- * @param fn - The function to call, which receives a SuiJsonRpcClient instance.
23
+ * @param fn - The function to call, which receives a SuiGrpcClient instance.
24
24
  * @returns - The result of the function call.
25
25
  */
26
26
  export async function callSuiWithRetry<R>(
27
27
  client: SDKClient,
28
- fn: (client: SuiJsonRpcClient) => Promise<R>
28
+ fn: (client: SuiGrpcClient) => Promise<R>
29
29
  ): Promise<R> {
30
30
  // Ensure clients are initialized
31
31
  await ensureClients(client)
@@ -37,25 +37,23 @@ export class SuiWaitForTransactionTask extends BaseStepExecutionTask {
37
37
  }
38
38
 
39
39
  const result = await callSuiWithRetry(client, (client) =>
40
- client.waitForTransaction({
40
+ client.core.waitForTransaction({
41
41
  digest: signedTransaction.digest,
42
- options: {
43
- showEffects: true,
44
- },
45
42
  })
46
43
  )
47
44
 
48
- if (result.effects?.status.status !== 'success') {
45
+ const transaction = result.Transaction ?? result.FailedTransaction
46
+ if (!transaction?.status.success) {
49
47
  throw new TransactionError(
50
48
  LiFiErrorCode.TransactionFailed,
51
- `Transaction failed: ${result.effects?.status.error}`
49
+ `Transaction failed: ${transaction?.status.error?.message ?? `Unexpected transaction result: ${result.$kind}`}`
52
50
  )
53
51
  }
54
52
 
55
53
  // Transaction has been confirmed and we can update the action
56
54
  statusManager.updateAction(step, action.type, 'PENDING', {
57
- txHash: result.digest,
58
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${result.digest}`,
55
+ txHash: transaction.digest,
56
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${transaction.digest}`,
59
57
  })
60
58
 
61
59
  if (isBridgeExecution) {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-sui'
2
- export const version = '4.0.1'
2
+ export const version = '4.1.1'