@lifi/sdk-provider-sui 4.2.7 → 4.2.8

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +9 -0
  3. package/dist/esm/actions/getSuiBalance.d.ts.map +1 -1
  4. package/dist/esm/actions/getSuiBalance.js +5 -4
  5. package/dist/esm/actions/getSuiBalance.js.map +1 -1
  6. package/dist/esm/client/suiClient.d.ts +2 -1
  7. package/dist/esm/client/suiClient.d.ts.map +1 -1
  8. package/dist/esm/client/suiClient.js +14 -15
  9. package/dist/esm/client/suiClient.js.map +1 -1
  10. package/dist/esm/core/SuiStepExecutor.d.ts.map +1 -1
  11. package/dist/esm/core/SuiStepExecutor.js +2 -2
  12. package/dist/esm/core/SuiStepExecutor.js.map +1 -1
  13. package/dist/esm/core/constants.d.ts +7 -0
  14. package/dist/esm/core/constants.d.ts.map +1 -0
  15. package/dist/esm/core/constants.js +9 -0
  16. package/dist/esm/core/constants.js.map +1 -0
  17. package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts.map +1 -1
  18. package/dist/esm/core/tasks/SuiSignAndExecuteTask.js +54 -7
  19. package/dist/esm/core/tasks/SuiSignAndExecuteTask.js.map +1 -1
  20. package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts.map +1 -1
  21. package/dist/esm/core/tasks/SuiWaitForTransactionTask.js +110 -12
  22. package/dist/esm/core/tasks/SuiWaitForTransactionTask.js.map +1 -1
  23. package/dist/esm/core/tasks/helpers/callWithinDeadline.d.ts +19 -0
  24. package/dist/esm/core/tasks/helpers/callWithinDeadline.d.ts.map +1 -0
  25. package/dist/esm/core/tasks/helpers/callWithinDeadline.js +45 -0
  26. package/dist/esm/core/tasks/helpers/callWithinDeadline.js.map +1 -0
  27. package/dist/esm/core/tasks/helpers/isSuiTransactionDropped.d.ts +24 -0
  28. package/dist/esm/core/tasks/helpers/isSuiTransactionDropped.d.ts.map +1 -0
  29. package/dist/esm/core/tasks/helpers/isSuiTransactionDropped.js +141 -0
  30. package/dist/esm/core/tasks/helpers/isSuiTransactionDropped.js.map +1 -0
  31. package/dist/esm/errors/parseSuiErrors.js +5 -4
  32. package/dist/esm/errors/parseSuiErrors.js.map +1 -1
  33. package/dist/esm/utils/getSuiTxLink.d.ts +5 -0
  34. package/dist/esm/utils/getSuiTxLink.d.ts.map +1 -0
  35. package/dist/esm/utils/getSuiTxLink.js +6 -0
  36. package/dist/esm/utils/getSuiTxLink.js.map +1 -0
  37. package/dist/esm/utils/suiSignedTransaction.d.ts +39 -0
  38. package/dist/esm/utils/suiSignedTransaction.d.ts.map +1 -0
  39. package/dist/esm/utils/suiSignedTransaction.js +73 -0
  40. package/dist/esm/utils/suiSignedTransaction.js.map +1 -0
  41. package/dist/esm/version.d.ts +1 -1
  42. package/dist/esm/version.js +1 -1
  43. package/dist/esm/version.js.map +1 -1
  44. package/package.json +3 -3
  45. package/src/actions/getSuiBalance.ts +40 -24
  46. package/src/client/suiClient.ts +21 -18
  47. package/src/core/SuiStepExecutor.ts +9 -3
  48. package/src/core/constants.ts +21 -0
  49. package/src/core/tasks/SuiSignAndExecuteTask.ts +107 -8
  50. package/src/core/tasks/SuiWaitForTransactionTask.ts +249 -22
  51. package/src/core/tasks/helpers/callWithinDeadline.ts +48 -0
  52. package/src/core/tasks/helpers/isSuiTransactionDropped.ts +292 -0
  53. package/src/errors/parseSuiErrors.ts +19 -19
  54. package/src/utils/getSuiTxLink.ts +4 -0
  55. package/src/utils/suiSignedTransaction.ts +109 -0
  56. package/src/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @lifi/sdk-provider-sui
2
2
 
3
+ ## 4.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#510](https://github.com/lifinance/sdk/pull/510) [`bb964c0`](https://github.com/lifinance/sdk/commit/bb964c03d8ea1770303ab1bba803373a80e6388f) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: viem to 2.57.3, @stellar/stellar-sdk to 17.2.1,
8
+ @mysten/sui to 2.35.0, @lifi/types to 18.13.0 and @bigmi/core to 0.9.3.
9
+
10
+ - [#507](https://github.com/lifinance/sdk/pull/507) [`14f4ecc`](https://github.com/lifinance/sdk/commit/14f4ecc2714799449d57b61ff06b040df505184e) Thanks [@chybisov](https://github.com/chybisov)! - Resume a signed or executed transaction instead of signing again. Signing and execution are split (same `signer.signTransaction` call), the signed bytes are stored in `txHex` before execution, and the digest is stored right after it, also for a failed execution. The sign task checks the action again after the wallet returns: if a stopped run's transaction merged into it while the prompt was open, the step fails with `TransactionConflict` and the new signature is neither stored nor executed. Stored bytes are re-executed only within two minutes of signing. After a node refuses the first execution, "Try again" cannot sign a new transaction until about 17 minutes after signing (the two-minute resend window, a 10-minute clock skew margin and a 5-minute head margin): no node can prove the transaction absent before then. The digest lookup and the absence-proof calls of a resume give each node 10 seconds to answer, so a hung node cannot hold the route: a node that does not answer in time counts as failed and the next node is asked; when no node answers, the outcome stays unknown. The final wait keeps its 60-second limit per node. A stored zkLogin signature cannot be verified offline, so such a route is never resent or declared dropped and stays unknown (the user deletes the route). A failed execution now reports the chain's error message instead of `[object Object]`. A wallet rejection is recognized at the signing call; a node message that contains "reject" is no longer reported as `SignatureRejected`, and an SDK error keeps its own code.
11
+
12
+ - [#509](https://github.com/lifinance/sdk/pull/509) [`34ecf9c`](https://github.com/lifinance/sdk/commit/34ecf9c4dcfa54cb2e60cacc931257fdc700c682) Thanks [@chybisov](https://github.com/chybisov)! - Sui calls and `getSuiBalance` now use only the RPC URLs of their own SDK client. A call no longer tries every Sui RPC URL that any SDK client in the process has used, and two SDK clients no longer share an in-flight balance read; either could send a request to another tenant's URL and API key. The Sui client cache now holds at most 64 clients.
13
+ - Updated dependencies [[`bb964c0`](https://github.com/lifinance/sdk/commit/bb964c03d8ea1770303ab1bba803373a80e6388f), [`48af3ae`](https://github.com/lifinance/sdk/commit/48af3aeb250299ef9d2ff9eb79a38a6b8f52d409), [`14f4ecc`](https://github.com/lifinance/sdk/commit/14f4ecc2714799449d57b61ff06b040df505184e)]:
14
+ - @lifi/sdk@4.11.0
15
+
3
16
  ## 4.2.7
4
17
 
5
18
  ### Patch Changes
package/README.md CHANGED
@@ -83,6 +83,13 @@ needs no ecosystem library. To discover and connect browser wallets such as Frei
83
83
  xBull, or Lobstr, we recommend
84
84
  [Stellar Wallets Kit](https://github.com/Creit-Tech/Stellar-Wallets-Kit).
85
85
 
86
+ **Zcash**
87
+ ```bash
88
+ pnpm add @lifi/sdk-provider-zcash
89
+ ```
90
+
91
+ ZEC is a destination-only chain: `ZcashProvider` validates transparent `t1` and `t3` receivers, and unified `u1` receivers that carry an Orchard receiver, and needs no wallet. Register it after `BitcoinProvider`; it serves ZEC only.
92
+
86
93
  ## Architecture
87
94
 
88
95
  The LI.FI SDK uses a modular provider architecture:
@@ -134,6 +141,7 @@ import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
134
141
  import { SuiProvider } from '@lifi/sdk-provider-sui'
135
142
  import { TronProvider } from '@lifi/sdk-provider-tron'
136
143
  import { StellarProvider } from '@lifi/sdk-provider-stellar'
144
+ import { ZcashProvider } from '@lifi/sdk-provider-zcash'
137
145
 
138
146
  const client = createClient({
139
147
  integrator: 'Your dApp/company name',
@@ -144,6 +152,7 @@ const client = createClient({
144
152
  SuiProvider({ /* options */ }),
145
153
  TronProvider({ /* options */ }),
146
154
  StellarProvider({ /* options */ }),
155
+ ZcashProvider(),
147
156
  ],
148
157
  })
149
158
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"getSuiBalance.d.ts","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"mappings":";;wBAUsB,cACpB,QAAQ,WACR,uBACA,QAAQ,UACP,QAAQ"}
1
+ {"version":3,"file":"getSuiBalance.d.ts","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"mappings":";;wBAWsB,cACpB,QAAQ,WACR,uBACA,QAAQ,UACP,QAAQ"}
@@ -1,6 +1,6 @@
1
1
  import { callSuiWithRetry } from "../client/suiClient.js";
2
2
  import { SuiTokenLongAddress, SuiTokenShortAddress } from "../types.js";
3
- import { withDedupe } from "@lifi/sdk";
3
+ import { ChainId, withDedupe } from "@lifi/sdk";
4
4
  //#region src/actions/getSuiBalance.ts
5
5
  async function getSuiBalance(client, walletAddress, tokens) {
6
6
  if (tokens.length === 0) return [];
@@ -9,7 +9,8 @@ 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, async (suiClient) => {
12
+ const rpcUrlsKey = client.getRpcUrlsByChainId(ChainId.SUI).then((rpcUrls) => rpcUrls.join(" "));
13
+ const [coins, checkpoint] = await Promise.allSettled([rpcUrlsKey.then((urlsKey) => withDedupe(() => callSuiWithRetry(client, async (suiClient) => {
13
14
  const balances = [];
14
15
  let cursor;
15
16
  do {
@@ -21,10 +22,10 @@ const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) =>
21
22
  cursor = page.hasNextPage ? page.cursor : null;
22
23
  } while (cursor);
23
24
  return balances;
24
- }), { id: `${getSuiBalanceDefault.name}.listBalances.${walletAddress}` }), withDedupe(() => callSuiWithRetry(client, async (suiClient) => {
25
+ }), { id: `${getSuiBalanceDefault.name}.listBalances.${walletAddress}.${urlsKey}` })), rpcUrlsKey.then((urlsKey) => withDedupe(() => callSuiWithRetry(client, async (suiClient) => {
25
26
  const { response } = await suiClient.ledgerService.getServiceInfo({});
26
27
  return response.checkpointHeight ?? 0n;
27
- }), { id: `${getSuiBalanceDefault.name}.getServiceInfo` })]);
28
+ }), { id: `${getSuiBalanceDefault.name}.getServiceInfo.${urlsKey}` }))]);
28
29
  const coinsOk = coins.status === "fulfilled";
29
30
  const coinsResult = coinsOk ? coins.value : [];
30
31
  const blockNumber = checkpoint.status === "fulfilled" ? checkpoint.value : 0n;
@@ -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 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.${walletAddress}` }\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,gBAAgB,gBAAgB,CACrE,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
+ {"version":3,"file":"getSuiBalance.js","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"sourcesContent":["import {\n ChainId,\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 // The dedupe ids carry the RPC URLs of this SDK client. Two SDK clients\n // with different URLs (one per tenant, each with its own API key) must not\n // share a request. The lookup runs inside each settled entry, so a failed\n // lookup leaves the amounts undefined, as a failed request does.\n const rpcUrlsKey = client\n .getRpcUrlsByChainId(ChainId.SUI)\n .then((rpcUrls) => rpcUrls.join(' '))\n const [coins, checkpoint] = await Promise.allSettled([\n rpcUrlsKey.then((urlsKey) =>\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 {\n id: `${getSuiBalanceDefault.name}.listBalances.${walletAddress}.${urlsKey}`,\n }\n )\n ),\n rpcUrlsKey.then((urlsKey) =>\n withDedupe(\n () =>\n callSuiWithRetry(client, async (suiClient) => {\n const { response } = await suiClient.ledgerService.getServiceInfo(\n {}\n )\n return response.checkpointHeight ?? 0n\n }),\n { id: `${getSuiBalanceDefault.name}.getServiceInfo.${urlsKey}` }\n )\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":";;;;AAWA,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;CAK3B,MAAM,aAAa,OAChB,oBAAoB,QAAQ,GAAG,CAAC,CAChC,MAAM,YAAY,QAAQ,KAAK,GAAG,CAAC;CACtC,MAAM,CAAC,OAAO,cAAc,MAAM,QAAQ,WAAW,CACnD,WAAW,MAAM,YACf,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,EACE,IAAI,GAAG,qBAAqB,KAAK,gBAAgB,cAAc,GAAG,UACpE,CACF,CACF,GACA,WAAW,MAAM,YACf,iBAEI,iBAAiB,QAAQ,OAAO,cAAc;EAC5C,MAAM,EAAE,aAAa,MAAM,UAAU,cAAc,eACjD,CAAC,CACH;EACA,OAAO,SAAS,oBAAoB;CACtC,CAAC,GACH,EAAE,IAAI,GAAG,qBAAqB,KAAK,kBAAkB,UAAU,CACjE,CACF,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"}
@@ -2,7 +2,8 @@ import { SDKClient } from "@lifi/sdk";
2
2
  import { SuiGrpcClient } from "@mysten/sui/grpc";
3
3
  //#region src/client/suiClient.d.ts
4
4
  /**
5
- * Calls a function on the SuiGrpcClient instances with retry logic.
5
+ * Calls a function on a SuiGrpcClient for each RPC URL of the SDK client, in
6
+ * order, until one call succeeds.
6
7
  * @param client - The SDK client
7
8
  * @param fn - The function to call, which receives a SuiGrpcClient instance.
8
9
  * @returns - The result of the function call.
@@ -1 +1 @@
1
- {"version":3,"file":"suiClient.d.ts","names":[],"sources":["../../../src/client/suiClient.ts"],"mappings":";;;;;;;;;wBAyBsB,iBAAiB,GACrC,QAAQ,WACR,KAAK,QAAQ,kBAAkB,QAAQ,KACtC,QAAQ"}
1
+ {"version":3,"file":"suiClient.d.ts","names":[],"sources":["../../../src/client/suiClient.ts"],"mappings":";;;;;;;;;;wBAwBsB,iBAAiB,GACrC,QAAQ,WACR,KAAK,QAAQ,kBAAkB,QAAQ,KACtC,QAAQ"}
@@ -1,32 +1,31 @@
1
- import { ChainId } from "@lifi/sdk";
1
+ import { ChainId, LruMap } from "@lifi/sdk";
2
2
  import { SuiGrpcClient } from "@mysten/sui/grpc";
3
3
  //#region src/client/suiClient.ts
4
- const clients = /* @__PURE__ */ new Map();
5
- /**
6
- * Initializes the Sui clients if they haven't been initialized yet.
7
- * @returns - Promise that resolves when clients are initialized.
8
- */
9
- const ensureClients = async (client) => {
10
- const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI);
11
- for (const rpcUrl of rpcUrls) if (!clients.get(rpcUrl)) {
12
- const client = new SuiGrpcClient({
4
+ const clients = new LruMap(64);
5
+ const getSuiClient = (rpcUrl) => {
6
+ let suiClient = clients.get(rpcUrl);
7
+ if (!suiClient) {
8
+ suiClient = new SuiGrpcClient({
13
9
  network: "mainnet",
14
10
  baseUrl: rpcUrl
15
11
  });
16
- clients.set(rpcUrl, client);
12
+ clients.set(rpcUrl, suiClient);
17
13
  }
14
+ return suiClient;
18
15
  };
19
16
  /**
20
- * Calls a function on the SuiGrpcClient instances with retry logic.
17
+ * Calls a function on a SuiGrpcClient for each RPC URL of the SDK client, in
18
+ * order, until one call succeeds.
21
19
  * @param client - The SDK client
22
20
  * @param fn - The function to call, which receives a SuiGrpcClient instance.
23
21
  * @returns - The result of the function call.
24
22
  */
25
23
  async function callSuiWithRetry(client, fn) {
26
- await ensureClients(client);
24
+ const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI);
25
+ if (!rpcUrls.length) throw new Error("No Sui RPC URLs available");
27
26
  let lastError = null;
28
- for (const client of clients.values()) try {
29
- return await fn(client);
27
+ for (const rpcUrl of rpcUrls) try {
28
+ return await fn(getSuiClient(rpcUrl));
30
29
  } catch (error) {
31
30
  lastError = error;
32
31
  }
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"suiClient.js","names":[],"sources":["../../../src/client/suiClient.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'\nimport { SuiGrpcClient } from '@mysten/sui/grpc'\n\n// One client per RPC URL, shared by every SDK client in the process. The cap\n// keeps a process that sees many URLs (one per tenant, or a changed\n// configuration) from holding every client it ever built.\nconst clients = new LruMap<SuiGrpcClient>(64)\n\nconst getSuiClient = (rpcUrl: string): SuiGrpcClient => {\n let suiClient = clients.get(rpcUrl)\n if (!suiClient) {\n suiClient = new SuiGrpcClient({ network: 'mainnet', baseUrl: rpcUrl })\n clients.set(rpcUrl, suiClient)\n }\n return suiClient\n}\n\n/**\n * Calls a function on a SuiGrpcClient for each RPC URL of the SDK client, in\n * order, until one call succeeds.\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 // Only the URLs of this SDK client: another SDK client's URL can carry\n // another tenant's API key.\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI)\n if (!rpcUrls.length) {\n throw new Error('No Sui RPC URLs available')\n }\n let lastError: any = null\n for (const rpcUrl of rpcUrls) {\n try {\n const result = await fn(getSuiClient(rpcUrl))\n return result\n } catch (error) {\n lastError = error\n }\n }\n // Throw the last encountered error\n throw lastError\n}\n"],"mappings":";;;AAMA,MAAM,UAAU,IAAI,OAAsB,EAAE;AAE5C,MAAM,gBAAgB,WAAkC;CACtD,IAAI,YAAY,QAAQ,IAAI,MAAM;CAClC,IAAI,CAAC,WAAW;EACd,YAAY,IAAI,cAAc;GAAE,SAAS;GAAW,SAAS;EAAO,CAAC;EACrE,QAAQ,IAAI,QAAQ,SAAS;CAC/B;CACA,OAAO;AACT;;;;;;;;AASA,eAAsB,iBACpB,QACA,IACY;CAGZ,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,IAAI,CAAC,QAAQ,QACX,MAAM,IAAI,MAAM,2BAA2B;CAE7C,IAAI,YAAiB;CACrB,KAAK,MAAM,UAAU,SACnB,IAAI;EAEF,OAAO,MADc,GAAG,aAAa,MAAM,CAAC;CAE9C,SAAS,OAAO;EACd,YAAY;CACd;CAGF,MAAM;AACR"}
@@ -1 +1 @@
1
- {"version":3,"file":"SuiStepExecutor.d.ts","names":[],"sources":["../../../src/core/SuiStepExecutor.ts"],"mappings":";;;qBAuBa,wBAAwB;UAC3B;UACA;EAER,YAAY,SAAS;EAMrB,cAAe,MAAM;WAWZ,cACP,OAAO,OACP,OAAO,kBACP,SAAS,oBACR,QAAQ;WAEF,gBACP,aAAa,4BACZ,QAAQ;WASF,iBAAkB,SAAS,2BAAyB"}
1
+ {"version":3,"file":"SuiStepExecutor.d.ts","names":[],"sources":["../../../src/core/SuiStepExecutor.ts"],"mappings":";;;qBAwBa,wBAAwB;UAC3B;UACA;EAER,YAAY,SAAS;EAMrB,cAAe,MAAM;WAWZ,cACP,OAAO,OACP,OAAO,kBACP,SAAS,oBACR,QAAQ;WAEF,gBACP,aAAa,4BACZ,QAAQ;WASF,iBAAkB,SAAS,2BAAyB"}
@@ -1,7 +1,7 @@
1
1
  import { parseSuiErrors } from "../errors/parseSuiErrors.js";
2
2
  import { SuiSignAndExecuteTask } from "./tasks/SuiSignAndExecuteTask.js";
3
3
  import { SuiWaitForTransactionTask } from "./tasks/SuiWaitForTransactionTask.js";
4
- import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, PrepareTransactionTask, TaskPipeline, TransactionError, WaitForTransactionStatusTask } from "@lifi/sdk";
4
+ import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, PrepareTransactionTask, TaskPipeline, TransactionError, WaitForTransactionStatusTask, hasOpenTransaction } from "@lifi/sdk";
5
5
  //#region src/core/SuiStepExecutor.ts
6
6
  var SuiStepExecutor = class extends BaseStepExecutor {
7
7
  client;
@@ -33,7 +33,7 @@ var SuiStepExecutor = class extends BaseStepExecutor {
33
33
  new WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
34
34
  ];
35
35
  const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
36
- const firstTask = swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === "DONE" ? WaitForTransactionStatusTask : CheckBalanceTask;
36
+ const firstTask = hasOpenTransaction(swapOrBridgeAction) ? swapOrBridgeAction?.status === "DONE" ? WaitForTransactionStatusTask : SuiWaitForTransactionTask : CheckBalanceTask;
37
37
  const firstTaskIndex = tasks.findIndex((task) => task.constructor === firstTask);
38
38
  if (firstTaskIndex === -1) throw new TransactionError(LiFiErrorCode.InternalError, "SuiStepExecutor.createPipeline: first task not found");
39
39
  const tasksToRun = tasks.slice(firstTaskIndex);
@@ -1 +1 @@
1
- {"version":3,"file":"SuiStepExecutor.js","names":[],"sources":["../../../src/core/SuiStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { ClientWithCoreApi } from '@mysten/sui/client'\nimport type { Signer } from '@mysten/sui/cryptography'\nimport { parseSuiErrors } from '../errors/parseSuiErrors.js'\nimport type {\n SuiStepExecutorContext,\n SuiStepExecutorOptions,\n} from '../types.js'\nimport { SuiSignAndExecuteTask } from './tasks/SuiSignAndExecuteTask.js'\nimport { SuiWaitForTransactionTask } from './tasks/SuiWaitForTransactionTask.js'\n\nexport class SuiStepExecutor extends BaseStepExecutor {\n private client: ClientWithCoreApi\n private signer: Signer\n\n constructor(options: SuiStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.signer = options.signer\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n // Prevent execution of the quote by wallet different from the one which requested the quote\n const address = this.signer.toSuiAddress()\n if (address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSuiErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SuiStepExecutorContext> => {\n return {\n ...baseContext,\n suiClient: this.client,\n signer: this.signer,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (context: SuiStepExecutorContext): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SuiSignAndExecuteTask(),\n new SuiWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const firstTask =\n swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'SuiStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;AAuBA,IAAa,kBAAb,cAAqC,iBAAiB;CACpD;CACA;CAEA,YAAY,SAAiC;EAC3C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAG9C,IADgB,KAAK,OAAO,aAClB,MAAM,KAAK,OAAO,aAC1B,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsB,eAAe,OAAO,MAAM,MAAM;CAE1D,gBAAyB,OACvB,gBACoC;EACpC,OAAO;GACL,GAAG;GACH,WAAW,KAAK;GAChB,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBAA2B,YAAkD;EAC3E,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,sBAAsB;GAC1B,IAAI,0BAA0B;GAC9B,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,YACJ,oBAAoB,UAAU,oBAAoB,WAAW,SACzD,+BACA;EAIN,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,sDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
1
+ {"version":3,"file":"SuiStepExecutor.js","names":[],"sources":["../../../src/core/SuiStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { ClientWithCoreApi } from '@mysten/sui/client'\nimport type { Signer } from '@mysten/sui/cryptography'\nimport { parseSuiErrors } from '../errors/parseSuiErrors.js'\nimport type {\n SuiStepExecutorContext,\n SuiStepExecutorOptions,\n} from '../types.js'\nimport { SuiSignAndExecuteTask } from './tasks/SuiSignAndExecuteTask.js'\nimport { SuiWaitForTransactionTask } from './tasks/SuiWaitForTransactionTask.js'\n\nexport class SuiStepExecutor extends BaseStepExecutor {\n private client: ClientWithCoreApi\n private signer: Signer\n\n constructor(options: SuiStepExecutorOptions) {\n super(options)\n this.client = options.client\n this.signer = options.signer\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n // Prevent execution of the quote by wallet different from the one which requested the quote\n const address = this.signer.toSuiAddress()\n if (address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSuiErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SuiStepExecutorContext> => {\n return {\n ...baseContext,\n suiClient: this.client,\n signer: this.signer,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (context: SuiStepExecutorContext): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SuiSignAndExecuteTask(),\n new SuiWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // A transaction signed for this action may still land (`txHex` from\n // signing, `txHash` after execution). Resume at the confirmation wait:\n // re-preparing or re-signing could execute the swap twice. A final failure\n // is not open, so \"Try again\" signs anew.\n const firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : SuiWaitForTransactionTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'SuiStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;AAwBA,IAAa,kBAAb,cAAqC,iBAAiB;CACpD;CACA;CAEA,YAAY,SAAiC;EAC3C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAG9C,IADgB,KAAK,OAAO,aAClB,MAAM,KAAK,OAAO,aAC1B,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsB,eAAe,OAAO,MAAM,MAAM;CAE1D,gBAAyB,OACvB,gBACoC;EACpC,OAAO;GACL,GAAG;GACH,WAAW,KAAK;GAChB,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBAA2B,YAAkD;EAC3E,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,sBAAsB;GAC1B,IAAI,0BAA0B;GAC9B,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAMA,MAAM,YAAY,mBAAmB,kBAAkB,IACnD,oBAAoB,WAAW,SAC7B,+BACA,4BACF;EAIJ,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,sDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
@@ -0,0 +1,7 @@
1
+ //#region src/core/constants.d.ts
2
+ export declare const SUI_HEAD_MARGIN_MS: number;
3
+ export declare const SUI_CANARY_TIP_OFFSET = 120n;
4
+ export declare const SUI_MIN_CHECKPOINT_INTERVAL_MS = 200;
5
+ export declare const SUI_LOOKUP_TIMEOUT_MS = 1e4;
6
+ //#endregion
7
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","names":[],"sources":["../../../src/core/constants.ts"],"mappings":";qBAEa;qBAIA;qBAIA;qBAUA"}
@@ -0,0 +1,9 @@
1
+ //#region src/core/constants.ts
2
+ const SUI_HEAD_MARGIN_MS = 3e5;
3
+ const SUI_CANARY_TIP_OFFSET = 120n;
4
+ const SUI_MIN_CHECKPOINT_INTERVAL_MS = 200;
5
+ const SUI_LOOKUP_TIMEOUT_MS = 1e4;
6
+ //#endregion
7
+ export { SUI_CANARY_TIP_OFFSET, SUI_HEAD_MARGIN_MS, SUI_LOOKUP_TIMEOUT_MS, SUI_MIN_CHECKPOINT_INTERVAL_MS };
8
+
9
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../src/core/constants.ts"],"sourcesContent":["// Added after the latest landing time (signing + resend age cap + clock skew)\n// before a checkpoint counts as past it: fullnode retries and node lag.\nexport const SUI_HEAD_MARGIN_MS: number = 5 * 60_000\n\n// The head canary comes from this many checkpoints behind the tip (about\n// 30 s on mainnet), so every backend behind a load-balanced RPC has it.\nexport const SUI_CANARY_TIP_OFFSET = 120n\n\n// A lower bound of the checkpoint interval. Estimating a checkpoint for a\n// time with it lands at or before that time.\nexport const SUI_MIN_CHECKPOINT_INTERVAL_MS = 200\n\n// The budget of each resume lookup call to one node: the digest lookup, a\n// checkpoint read and the batch lookup. A node that has not answered by then\n// counts as failed and the next node is asked; a timeout alone never decides\n// the outcome. A healthy node answers in well under a second. Each node gets\n// the full 10 s, so a slow pool can use up the two-minute resend age cap\n// before the resend decision. Then the resend is lost, but it is never sent\n// late: the re-execution checks the cap before each node and aborts when the\n// cap passes.\nexport const SUI_LOOKUP_TIMEOUT_MS = 10_000\n"],"mappings":";AAEA,MAAa,qBAA6B;AAI1C,MAAa,wBAAwB;AAIrC,MAAa,iCAAiC;AAU9C,MAAa,wBAAwB"}
@@ -1 +1 @@
1
- {"version":3,"file":"SuiSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SuiSignAndExecuteTask.ts"],"mappings":";;;qBAUa,8BAA8B;EACzC,IAAU,SAAS,yBAAyB,QAAQ"}
1
+ {"version":3,"file":"SuiSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SuiSignAndExecuteTask.ts"],"mappings":";;;qBAea,8BAA8B;EACzC,IAAU,SAAS,yBAAyB,QAAQ"}
@@ -1,25 +1,72 @@
1
- import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, getTransactionRequestData } from "@lifi/sdk";
1
+ import { getSuiTxLink } from "../../utils/getSuiTxLink.js";
2
+ import { serializeSuiSignedTransaction } from "../../utils/suiSignedTransaction.js";
3
+ import { BaseError, BaseStepExecutionTask, CLEARED_TRANSACTION_FIELDS, LiFiErrorCode, TransactionError, assertNoOpenTransaction, getTransactionRequestData } from "@lifi/sdk";
2
4
  import { Transaction } from "@mysten/sui/transactions";
3
5
  //#region src/core/tasks/SuiSignAndExecuteTask.ts
4
6
  var SuiSignAndExecuteTask = class extends BaseStepExecutionTask {
5
7
  async run(context) {
6
- const { step, suiClient, signer, statusManager, executionOptions, isBridgeExecution, checkWallet } = context;
8
+ const { step, suiClient, signer, statusManager, executionOptions, isBridgeExecution, checkWallet, fromChain } = context;
7
9
  const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
8
10
  if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
11
+ assertNoOpenTransaction(action);
9
12
  const transactionRequestData = await getTransactionRequestData(step, executionOptions);
10
13
  checkWallet(step);
11
- const { $kind, FailedTransaction, Transaction: TransactionResult } = await suiClient.core.signAndExecuteTransaction({
12
- signer,
13
- transaction: Transaction.from(transactionRequestData)
14
+ const transaction = Transaction.from(transactionRequestData);
15
+ transaction.setSenderIfNotSet(signer.toSuiAddress());
16
+ const transactionBytes = await transaction.build({ client: suiClient });
17
+ assertNoOpenTransaction(statusManager.findAction(step, action.type));
18
+ let signature;
19
+ try {
20
+ signature = (await signer.signTransaction(transactionBytes)).signature;
21
+ } catch (error) {
22
+ throw toSuiSignerError(error);
23
+ }
24
+ assertNoOpenTransaction(statusManager.findAction(step, action.type));
25
+ const txHex = serializeSuiSignedTransaction(transactionBytes, signature);
26
+ if (!txHex) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. The signed transaction is incomplete.");
27
+ statusManager.updateAction(step, action.type, "PENDING", {
28
+ ...CLEARED_TRANSACTION_FIELDS,
29
+ txHex,
30
+ signedAt: Date.now()
14
31
  });
15
- statusManager.updateAction(step, action.type, "PENDING", { signedAt: Date.now() });
16
- if ($kind !== "Transaction" || !TransactionResult) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${FailedTransaction?.status.error ?? `Unexpected transaction result: ${$kind}`}`);
32
+ const { $kind, FailedTransaction, Transaction: TransactionResult } = await suiClient.core.executeTransaction({
33
+ transaction: transactionBytes,
34
+ signatures: [signature]
35
+ });
36
+ const executedTransaction = TransactionResult ?? FailedTransaction;
37
+ if (executedTransaction) statusManager.updateAction(step, action.type, "PENDING", {
38
+ txHash: executedTransaction.digest,
39
+ txLink: getSuiTxLink(fromChain, executedTransaction.digest)
40
+ });
41
+ if ($kind !== "Transaction" || !TransactionResult) {
42
+ if (FailedTransaction) statusManager.updateAction(step, action.type, "PENDING", { txHex: void 0 });
43
+ throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${FailedTransaction?.status.error?.message ?? `Unexpected transaction result: ${$kind}`}`, void 0, FailedTransaction ? { final: true } : void 0);
44
+ }
17
45
  return {
18
46
  status: "COMPLETED",
19
47
  context: { signedTransaction: TransactionResult }
20
48
  };
21
49
  }
22
50
  };
51
+ /** For a wallet that rejects with code 4001 and gives no message. */
52
+ const SIGNATURE_REJECTED_MESSAGE = "The wallet rejected the signature request.";
53
+ /**
54
+ * Classifies an error thrown by `signer.signTransaction`, the only call to the
55
+ * user's signer in this package. The wallet refused to sign when its error
56
+ * says "reject" (in any case) or carries the EIP-1193 code 4001. Wallets throw
57
+ * an Error, a plain object or a string, so no shape is assumed. An SDK error
58
+ * keeps its code, and any other value is returned as it is.
59
+ *
60
+ * A remote or zkLogin signer whose own network call says "reject" is tagged
61
+ * too. That is the safe direction: nothing was signed, so nothing can land.
62
+ */
63
+ function toSuiSignerError(error) {
64
+ if (error instanceof BaseError) return error;
65
+ const fields = error ?? {};
66
+ const message = typeof error === "string" ? error : typeof fields.message === "string" ? fields.message : void 0;
67
+ if (fields.code === 4001 || message?.toLowerCase().includes("reject")) return new TransactionError(LiFiErrorCode.SignatureRejected, message || SIGNATURE_REJECTED_MESSAGE, error);
68
+ return error;
69
+ }
23
70
  //#endregion
24
71
  export { SuiSignAndExecuteTask };
25
72
 
@@ -1 +1 @@
1
- {"version":3,"file":"SuiSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/SuiSignAndExecuteTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { Transaction } from '@mysten/sui/transactions'\nimport type { SuiStepExecutorContext } from '../../types.js'\n\nexport class SuiSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SuiStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n suiClient,\n signer,\n statusManager,\n executionOptions,\n isBridgeExecution,\n checkWallet,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkWallet(step)\n\n // We give users 2 minutes to sign the transaction\n const {\n $kind,\n FailedTransaction,\n Transaction: TransactionResult,\n } = await suiClient.core.signAndExecuteTransaction({\n signer,\n transaction: Transaction.from(transactionRequestData),\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n signedAt: Date.now(),\n })\n\n if ($kind !== 'Transaction' || !TransactionResult) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${FailedTransaction?.status.error ?? `Unexpected transaction result: ${$kind}`}`\n )\n }\n\n return {\n status: 'COMPLETED',\n context: { signedTransaction: TransactionResult },\n }\n }\n}\n"],"mappings":";;;AAUA,IAAa,wBAAb,cAA2C,sBAAsB;CAC/D,MAAM,IAAI,SAAsD;EAC9D,MAAM,EACJ,MACA,WACA,QACA,eACA,kBACA,mBACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,yBAAyB,MAAM,0BACnC,MACA,gBACF;EAEA,YAAY,IAAI;EAGhB,MAAM,EACJ,OACA,mBACA,aAAa,sBACX,MAAM,UAAU,KAAK,0BAA0B;GACjD;GACA,aAAa,YAAY,KAAK,sBAAsB;EACtD,CAAC;EAED,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,UAAU,KAAK,IAAI,EACrB,CAAC;EAED,IAAI,UAAU,iBAAiB,CAAC,mBAC9B,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,mBAAmB,OAAO,SAAS,kCAAkC,SAC9F;EAGF,OAAO;GACL,QAAQ;GACR,SAAS,EAAE,mBAAmB,kBAAkB;EAClD;CACF;AACF"}
1
+ {"version":3,"file":"SuiSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/SuiSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseError,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { Transaction } from '@mysten/sui/transactions'\nimport type { SuiStepExecutorContext } from '../../types.js'\nimport { getSuiTxLink } from '../../utils/getSuiTxLink.js'\nimport { serializeSuiSignedTransaction } from '../../utils/suiSignedTransaction.js'\n\nexport class SuiSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SuiStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n suiClient,\n signer,\n statusManager,\n executionOptions,\n isBridgeExecution,\n checkWallet,\n fromChain,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // A transaction signed earlier for this action may still land. Signing a\n // second one could execute the swap twice.\n assertNoOpenTransaction(action)\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkWallet(step)\n\n // Built and signed exactly as `suiClient.core.signAndExecuteTransaction`\n // does, in two steps: the signed bytes are stored before they are sent,\n // so a reload re-executes them instead of asking for a second signature.\n const transaction = Transaction.from(transactionRequestData)\n transaction.setSenderIfNotSet(signer.toSuiAddress())\n const transactionBytes = await transaction.build({ client: suiClient })\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the awaits above.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n // Only the wallet's own answer is classified: an error from building the\n // transaction above can quote a node that \"rejected\" it.\n let signature: string\n try {\n signature = (await signer.signTransaction(transactionBytes)).signature\n } catch (error) {\n throw toSuiSignerError(error)\n }\n\n // Checked once more after the wallet: a stopped run's late write can\n // merge its transaction into this action while the prompt is open.\n // Nothing awaits from here to the write below.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const txHex = serializeSuiSignedTransaction(transactionBytes, signature)\n if (!txHex) {\n // Nothing was sent yet, so \"Try again\" signs a new transaction.\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. The signed transaction is incomplete.'\n )\n }\n\n // One write: the previous transaction's data is cleared together with\n // storing the new bytes, so no stale hash can look open again.\n statusManager.updateAction(step, action.type, 'PENDING', {\n ...CLEARED_TRANSACTION_FIELDS,\n txHex,\n signedAt: Date.now(),\n })\n\n const {\n $kind,\n FailedTransaction,\n Transaction: TransactionResult,\n } = await suiClient.core.executeTransaction({\n transaction: transactionBytes,\n signatures: [signature],\n })\n\n // A failed transaction has a digest too: it is on chain.\n const executedTransaction = TransactionResult ?? FailedTransaction\n if (executedTransaction) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: executedTransaction.digest,\n txLink: getSuiTxLink(fromChain, executedTransaction.digest),\n })\n }\n\n if ($kind !== 'Transaction' || !TransactionResult) {\n if (FailedTransaction) {\n // Executed and failed: the outcome is final and the bytes are spent.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: undefined,\n })\n }\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${FailedTransaction?.status.error?.message ?? `Unexpected transaction result: ${$kind}`}`,\n undefined,\n FailedTransaction ? { final: true } : undefined\n )\n }\n\n return {\n status: 'COMPLETED',\n context: { signedTransaction: TransactionResult },\n }\n }\n}\n\n/** For a wallet that rejects with code 4001 and gives no message. */\nconst SIGNATURE_REJECTED_MESSAGE = 'The wallet rejected the signature request.'\n\n/**\n * Classifies an error thrown by `signer.signTransaction`, the only call to the\n * user's signer in this package. The wallet refused to sign when its error\n * says \"reject\" (in any case) or carries the EIP-1193 code 4001. Wallets throw\n * an Error, a plain object or a string, so no shape is assumed. An SDK error\n * keeps its code, and any other value is returned as it is.\n *\n * A remote or zkLogin signer whose own network call says \"reject\" is tagged\n * too. That is the safe direction: nothing was signed, so nothing can land.\n */\nfunction toSuiSignerError(error: unknown): unknown {\n if (error instanceof BaseError) {\n return error\n }\n const fields = (error ?? {}) as { code?: unknown; message?: unknown }\n const message =\n typeof error === 'string'\n ? error\n : typeof fields.message === 'string'\n ? fields.message\n : undefined\n if (fields.code === 4001 || message?.toLowerCase().includes('reject')) {\n return new TransactionError(\n LiFiErrorCode.SignatureRejected,\n message || SIGNATURE_REJECTED_MESSAGE,\n // Kept as thrown, also when it is a string or a plain object.\n error as Error\n )\n }\n return error\n}\n"],"mappings":";;;;;AAeA,IAAa,wBAAb,cAA2C,sBAAsB;CAC/D,MAAM,IAAI,SAAsD;EAC9D,MAAM,EACJ,MACA,WACA,QACA,eACA,kBACA,mBACA,aACA,cACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAKF,wBAAwB,MAAM;EAE9B,MAAM,yBAAyB,MAAM,0BACnC,MACA,gBACF;EAEA,YAAY,IAAI;EAKhB,MAAM,cAAc,YAAY,KAAK,sBAAsB;EAC3D,YAAY,kBAAkB,OAAO,aAAa,CAAC;EACnD,MAAM,mBAAmB,MAAM,YAAY,MAAM,EAAE,QAAQ,UAAU,CAAC;EAItE,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAInE,IAAI;EACJ,IAAI;GACF,aAAa,MAAM,OAAO,gBAAgB,gBAAgB,EAAA,CAAG;EAC/D,SAAS,OAAO;GACd,MAAM,iBAAiB,KAAK;EAC9B;EAKA,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,QAAQ,8BAA8B,kBAAkB,SAAS;EACvE,IAAI,CAAC,OAEH,MAAM,IAAI,iBACR,cAAc,uBACd,sEACF;EAKF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,GAAG;GACH;GACA,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,MAAM,EACJ,OACA,mBACA,aAAa,sBACX,MAAM,UAAU,KAAK,mBAAmB;GAC1C,aAAa;GACb,YAAY,CAAC,SAAS;EACxB,CAAC;EAGD,MAAM,sBAAsB,qBAAqB;EACjD,IAAI,qBACF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,oBAAoB;GAC5B,QAAQ,aAAa,WAAW,oBAAoB,MAAM;EAC5D,CAAC;EAGH,IAAI,UAAU,iBAAiB,CAAC,mBAAmB;GACjD,IAAI,mBAEF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,OAAO,KAAA,EACT,CAAC;GAEH,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,mBAAmB,OAAO,OAAO,WAAW,kCAAkC,WACrG,KAAA,GACA,oBAAoB,EAAE,OAAO,KAAK,IAAI,KAAA,CACxC;EACF;EAEA,OAAO;GACL,QAAQ;GACR,SAAS,EAAE,mBAAmB,kBAAkB;EAClD;CACF;AACF;;AAGA,MAAM,6BAA6B;;;;;;;;;;;AAYnC,SAAS,iBAAiB,OAAyB;CACjD,IAAI,iBAAiB,WACnB,OAAO;CAET,MAAM,SAAU,SAAS,CAAC;CAC1B,MAAM,UACJ,OAAO,UAAU,WACb,QACA,OAAO,OAAO,YAAY,WACxB,OAAO,UACP,KAAA;CACR,IAAI,OAAO,SAAS,QAAQ,SAAS,YAAY,CAAC,CAAC,SAAS,QAAQ,GAClE,OAAO,IAAI,iBACT,cAAc,mBACd,WAAW,4BAEX,KACF;CAEF,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"SuiWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SuiWaitForTransactionTask.ts"],"mappings":";;;qBASa,kCAAkC;EAC7C,IAAU,SAAS,yBAAyB,QAAQ"}
1
+ {"version":3,"file":"SuiWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SuiWaitForTransactionTask.ts"],"mappings":";;;qBA2Ba,kCAAkC;EAC7C,IAAU,SAAS,yBAAyB,QAAQ"}
@@ -1,23 +1,121 @@
1
1
  import { callSuiWithRetry } from "../../client/suiClient.js";
2
- import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
2
+ import { getSuiTxLink } from "../../utils/getSuiTxLink.js";
3
+ import { parseSuiSignedTransaction, verifySuiSignedTransaction } from "../../utils/suiSignedTransaction.js";
4
+ import { SUI_LOOKUP_TIMEOUT_MS } from "../constants.js";
5
+ import { callWithinDeadline } from "./helpers/callWithinDeadline.js";
6
+ import { isSuiTransactionDropped } from "./helpers/isSuiTransactionDropped.js";
7
+ import { BaseStepExecutionTask, LiFiErrorCode, MAX_RESEND_AGE_MS, TransactionError, isResendAllowed } from "@lifi/sdk";
8
+ import { GrpcStatusCode, RpcError } from "@mysten/sui/grpc";
9
+ import { TransactionError as TransactionError$1 } from "@mysten/sui/client";
3
10
  //#region src/core/tasks/SuiWaitForTransactionTask.ts
4
11
  var SuiWaitForTransactionTask = class extends BaseStepExecutionTask {
5
12
  async run(context) {
6
- const { client, step, statusManager, fromChain, isBridgeExecution, signedTransaction } = context;
7
- if (!signedTransaction) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transaction is not found.");
13
+ const { client, step, statusManager, isBridgeExecution, signedTransaction } = context;
8
14
  const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
9
15
  if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
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}`}`);
13
- statusManager.updateAction(step, action.type, "PENDING", {
14
- txHash: transaction.digest,
15
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${transaction.digest}`
16
- });
17
- if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
18
- return { status: "COMPLETED" };
16
+ if (signedTransaction) return complete(context, action, await callSuiWithRetry(client, (client) => client.core.waitForTransaction({ digest: signedTransaction.digest })));
17
+ const storedTransaction = action.txHex ? parseSuiSignedTransaction(action.txHex) : void 0;
18
+ if (action.txHex && !storedTransaction) {
19
+ statusManager.updateAction(step, action.type, "PENDING", { txHex: void 0 });
20
+ if (!action.txHash) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to resume transaction. The stored signed transaction is invalid.");
21
+ }
22
+ const digest = action.txHash ?? storedTransaction?.digest;
23
+ if (!digest) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transaction is not found.");
24
+ const found = await findSuiTransaction(client, digest);
25
+ if (found) return complete(context, action, found);
26
+ const doubtful = !!storedTransaction && (storedTransaction.digest !== digest || !await isVerifiedSuiTransaction(storedTransaction));
27
+ const signedAt = step.execution?.signedAt;
28
+ if (!doubtful && storedTransaction && signedAt !== void 0 && isResendAllowed(signedAt)) try {
29
+ await reexecuteWithinAgeCap(client, storedTransaction, signedAt);
30
+ } catch (error) {
31
+ if (!isDefiniteSuiRejection(error)) throw error;
32
+ const landed = await findSuiTransaction(client, digest);
33
+ if (landed) return complete(context, action, landed);
34
+ throw error;
35
+ }
36
+ else if (!doubtful && await isSuiTransactionDropped(client, step, digest)) throw dropped(context, action);
37
+ return complete(context, action, await callSuiWithRetry(client, (client) => client.core.waitForTransaction({ digest })));
19
38
  }
20
39
  };
40
+ /**
41
+ * Looks the digest up once. Resolves `undefined` only when the RPCs answer
42
+ * that it is unknown; any other error propagates as an unknown outcome.
43
+ * Each node has `SUI_LOOKUP_TIMEOUT_MS` to answer; a node that does not
44
+ * counts as failed, so the next node is asked.
45
+ */
46
+ async function findSuiTransaction(client, digest) {
47
+ try {
48
+ return await callSuiWithRetry(client, (client) => callWithinDeadline((signal) => client.core.getTransaction({
49
+ digest,
50
+ signal
51
+ }), SUI_LOOKUP_TIMEOUT_MS));
52
+ } catch (error) {
53
+ if (error instanceof TransactionError$1 && error.reason === "notFound") return;
54
+ throw error;
55
+ }
56
+ }
57
+ /**
58
+ * Re-executes the stored bytes. `callSuiWithRetry` tries the nodes one by
59
+ * one, so the age cap is checked before every try, and each try aborts when
60
+ * the cap passes. Past the cap it throws a plain error, which is
61
+ * not a definite rejection, so the outcome stays unknown.
62
+ *
63
+ * Not `AbortSignal.timeout`: a published SDK should not raise its runtime
64
+ * floor for it; one controller and one timer cover it.
65
+ */
66
+ async function reexecuteWithinAgeCap(client, transaction, signedAt) {
67
+ await callSuiWithRetry(client, async (client) => {
68
+ if (!isResendAllowed(signedAt)) throw createAgeCapError();
69
+ const controller = new AbortController();
70
+ const timer = setTimeout(() => controller.abort(createAgeCapError()), Math.max(0, signedAt + MAX_RESEND_AGE_MS - Date.now()));
71
+ timer.unref?.();
72
+ try {
73
+ return await client.core.executeTransaction({
74
+ transaction: transaction.bytes,
75
+ signatures: [transaction.signature],
76
+ signal: controller.signal
77
+ });
78
+ } finally {
79
+ clearTimeout(timer);
80
+ }
81
+ });
82
+ }
83
+ /**
84
+ * The resend age cap passed. The name makes the gRPC transport report an
85
+ * abort with this reason as DEADLINE_EXCEEDED, as for any timeout.
86
+ */
87
+ function createAgeCapError() {
88
+ const error = /* @__PURE__ */ new Error("The resend age cap passed before the re-execution.");
89
+ error.name = "TimeoutError";
90
+ return error;
91
+ }
92
+ /** True only when the check runs and confirms the sender's signature. */
93
+ async function isVerifiedSuiTransaction(transaction) {
94
+ try {
95
+ return await verifySuiSignedTransaction(transaction) === true;
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
100
+ function isDefiniteSuiRejection(error) {
101
+ return error instanceof RpcError && error.code === GrpcStatusCode[GrpcStatusCode.INVALID_ARGUMENT];
102
+ }
103
+ function complete(context, action, result) {
104
+ const { step, statusManager, fromChain, isBridgeExecution } = context;
105
+ const transaction = result.Transaction ?? result.FailedTransaction;
106
+ if (transaction) statusManager.updateAction(step, action.type, "PENDING", {
107
+ txHash: transaction.digest,
108
+ txLink: getSuiTxLink(fromChain, transaction.digest),
109
+ txHex: void 0
110
+ });
111
+ if (!transaction?.status.success) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${transaction?.status.error?.message ?? `Unexpected transaction result: ${result.$kind}`}`, void 0, transaction ? { final: true } : void 0);
112
+ if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
113
+ return { status: "COMPLETED" };
114
+ }
115
+ function dropped(context, action) {
116
+ context.statusManager.updateAction(context.step, action.type, "PENDING", { txHex: void 0 });
117
+ return new TransactionError(LiFiErrorCode.TransactionExpired, "Transaction expired before it was executed.", void 0, { final: true });
118
+ }
21
119
  //#endregion
22
120
  export { SuiWaitForTransactionTask };
23
121
 
@@ -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.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
+ {"version":3,"file":"SuiWaitForTransactionTask.js","names":["SuiClientTransactionError"],"sources":["../../../../src/core/tasks/SuiWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n isResendAllowed,\n LiFiErrorCode,\n MAX_RESEND_AGE_MS,\n type SDKClient,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport {\n TransactionError as SuiClientTransactionError,\n type SuiClientTypes,\n} from '@mysten/sui/client'\nimport { GrpcStatusCode, RpcError } from '@mysten/sui/grpc'\nimport { callSuiWithRetry } from '../../client/suiClient.js'\nimport type { SuiStepExecutorContext } from '../../types.js'\nimport { getSuiTxLink } from '../../utils/getSuiTxLink.js'\nimport {\n parseSuiSignedTransaction,\n type SuiSignedTransaction,\n verifySuiSignedTransaction,\n} from '../../utils/suiSignedTransaction.js'\nimport { SUI_LOOKUP_TIMEOUT_MS } from '../constants.js'\nimport { callWithinDeadline } from './helpers/callWithinDeadline.js'\nimport { isSuiTransactionDropped } from './helpers/isSuiTransactionDropped.js'\n\nexport class SuiWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SuiStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n isBridgeExecution,\n signedTransaction,\n } = context\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 if (signedTransaction) {\n const result = await callSuiWithRetry(client, (client) =>\n client.core.waitForTransaction({\n digest: signedTransaction.digest,\n })\n )\n return complete(context, action, result)\n }\n\n // Resuming: the signing task did not run in this session. Continue with\n // the bytes and the digest persisted on the action; never sign again.\n const storedTransaction = action.txHex\n ? parseSuiSignedTransaction(action.txHex)\n : undefined\n\n if (action.txHex && !storedTransaction) {\n // Bytes that do not decode, or that are not canonical, can never be\n // executed or looked up.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: undefined,\n })\n if (!action.txHash) {\n // No execution ever returned for these bytes, so \"Try again\" signs again.\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to resume transaction. The stored signed transaction is invalid.'\n )\n }\n }\n\n const digest = action.txHash ?? storedTransaction?.digest\n if (!digest) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transaction is not found.'\n )\n }\n\n const found = await findSuiTransaction(client, digest)\n if (found) {\n return complete(context, action, found)\n }\n\n // Stored bytes prove nothing when their digest is not the stored txHash\n // (damaged storage) or their signature does not verify: the check also\n // fails for a scheme it cannot parse or cannot run, and the bytes may\n // have been sent. Then the SDK neither sends nor drops; it only waits,\n // and the outcome stays unknown.\n const doubtful =\n !!storedTransaction &&\n (storedTransaction.digest !== digest ||\n !(await isVerifiedSuiTransaction(storedTransaction)))\n\n const signedAt = step.execution?.signedAt\n if (\n !doubtful &&\n storedTransaction &&\n signedAt !== undefined &&\n isResendAllowed(signedAt)\n ) {\n // A digest executes at most once, so re-executing the stored bytes can\n // never run the swap twice.\n try {\n await reexecuteWithinAgeCap(client, storedTransaction, signedAt)\n } catch (error) {\n if (!isDefiniteSuiRejection(error)) {\n throw error\n }\n // The first execution may have landed meanwhile; then the refusal\n // only says that its inputs are spent.\n const landed = await findSuiTransaction(client, digest)\n if (landed) {\n return complete(context, action, landed)\n }\n // A node refusal does not prove the transaction absent, so the\n // outcome stays unknown.\n throw error\n }\n } else if (\n !doubtful &&\n (await isSuiTransactionDropped(client, step, digest))\n ) {\n // No resend: past the age cap, with no stored bytes, or with an unknown\n // signing time. Past the cap the bytes are never sent again, so a swap\n // on an old quote cannot execute hours later; the batch lookup proves\n // absence. Within the cap with only a txHash, and with an unknown\n // signing time, `isSuiTransactionDropped` returns false, so the task\n // waits.\n throw dropped(context, action)\n }\n\n const result = await callSuiWithRetry(client, (client) =>\n client.core.waitForTransaction({ digest })\n )\n return complete(context, action, result)\n }\n}\n\n/**\n * Looks the digest up once. Resolves `undefined` only when the RPCs answer\n * that it is unknown; any other error propagates as an unknown outcome.\n * Each node has `SUI_LOOKUP_TIMEOUT_MS` to answer; a node that does not\n * counts as failed, so the next node is asked.\n */\nasync function findSuiTransaction(\n client: SDKClient,\n digest: string\n): Promise<SuiClientTypes.TransactionResult | undefined> {\n try {\n return await callSuiWithRetry(client, (client) =>\n callWithinDeadline(\n (signal) => client.core.getTransaction({ digest, signal }),\n SUI_LOOKUP_TIMEOUT_MS\n )\n )\n } catch (error) {\n if (\n error instanceof SuiClientTransactionError &&\n error.reason === 'notFound'\n ) {\n return undefined\n }\n throw error\n }\n}\n\n/**\n * Re-executes the stored bytes. `callSuiWithRetry` tries the nodes one by\n * one, so the age cap is checked before every try, and each try aborts when\n * the cap passes. Past the cap it throws a plain error, which is\n * not a definite rejection, so the outcome stays unknown.\n *\n * Not `AbortSignal.timeout`: a published SDK should not raise its runtime\n * floor for it; one controller and one timer cover it.\n */\nasync function reexecuteWithinAgeCap(\n client: SDKClient,\n transaction: SuiSignedTransaction,\n signedAt: number\n): Promise<void> {\n await callSuiWithRetry(client, async (client) => {\n if (!isResendAllowed(signedAt)) {\n throw createAgeCapError()\n }\n const controller = new AbortController()\n const timer = setTimeout(\n () => controller.abort(createAgeCapError()),\n Math.max(0, signedAt + MAX_RESEND_AGE_MS - Date.now())\n )\n // A pending timer keeps Node's event loop alive. The `finally` clears it;\n // the unref only covers a path that skips it.\n const handle = timer as unknown as { unref?: () => void }\n handle.unref?.()\n try {\n return await client.core.executeTransaction({\n transaction: transaction.bytes,\n signatures: [transaction.signature],\n signal: controller.signal,\n })\n } finally {\n clearTimeout(timer)\n }\n })\n}\n\n/**\n * The resend age cap passed. The name makes the gRPC transport report an\n * abort with this reason as DEADLINE_EXCEEDED, as for any timeout.\n */\nfunction createAgeCapError(): Error {\n const error = new Error('The resend age cap passed before the re-execution.')\n error.name = 'TimeoutError'\n return error\n}\n\n/** True only when the check runs and confirms the sender's signature. */\nasync function isVerifiedSuiTransaction(\n transaction: SuiSignedTransaction\n): Promise<boolean> {\n try {\n return (await verifySuiSignedTransaction(transaction)) === true\n } catch {\n return false\n }\n}\n\n// The validators refused the transaction itself, e.g. because its input object\n// versions are no longer available. Network errors and overloaded nodes do not\n// count: the transaction may still land.\nfunction isDefiniteSuiRejection(error: unknown): boolean {\n return (\n error instanceof RpcError &&\n error.code === GrpcStatusCode[GrpcStatusCode.INVALID_ARGUMENT]\n )\n}\n\nfunction complete(\n context: SuiStepExecutorContext,\n action: ExecutionAction,\n result: SuiClientTypes.TransactionResult\n): TaskResult {\n const { step, statusManager, fromChain, isBridgeExecution } = context\n\n const transaction = result.Transaction ?? result.FailedTransaction\n if (transaction) {\n // Executed: the stored bytes are no longer needed.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.digest,\n txLink: getSuiTxLink(fromChain, transaction.digest),\n txHex: undefined,\n })\n }\n\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 undefined,\n // Executed and failed on chain: final. A malformed answer is not.\n transaction ? { final: true } : undefined\n )\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n}\n\nfunction dropped(\n context: SuiStepExecutorContext,\n action: ExecutionAction\n): TransactionError {\n context.statusManager.updateAction(context.step, action.type, 'PENDING', {\n txHex: undefined,\n })\n return new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction expired before it was executed.',\n undefined,\n { final: true }\n )\n}\n"],"mappings":";;;;;;;;;;AA2BA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAAsD;EAC9D,MAAM,EACJ,QACA,MACA,eACA,mBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,IAAI,mBAMF,OAAO,SAAS,SAAS,QAAQ,MALZ,iBAAiB,SAAS,WAC7C,OAAO,KAAK,mBAAmB,EAC7B,QAAQ,kBAAkB,OAC5B,CAAC,CACH,CACuC;EAKzC,MAAM,oBAAoB,OAAO,QAC7B,0BAA0B,OAAO,KAAK,IACtC,KAAA;EAEJ,IAAI,OAAO,SAAS,CAAC,mBAAmB;GAGtC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,OAAO,KAAA,EACT,CAAC;GACD,IAAI,CAAC,OAAO,QAEV,MAAM,IAAI,iBACR,cAAc,uBACd,yEACF;EAEJ;EAEA,MAAM,SAAS,OAAO,UAAU,mBAAmB;EACnD,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,iEACF;EAGF,MAAM,QAAQ,MAAM,mBAAmB,QAAQ,MAAM;EACrD,IAAI,OACF,OAAO,SAAS,SAAS,QAAQ,KAAK;EAQxC,MAAM,WACJ,CAAC,CAAC,sBACD,kBAAkB,WAAW,UAC5B,CAAE,MAAM,yBAAyB,iBAAiB;EAEtD,MAAM,WAAW,KAAK,WAAW;EACjC,IACE,CAAC,YACD,qBACA,aAAa,KAAA,KACb,gBAAgB,QAAQ,GAIxB,IAAI;GACF,MAAM,sBAAsB,QAAQ,mBAAmB,QAAQ;EACjE,SAAS,OAAO;GACd,IAAI,CAAC,uBAAuB,KAAK,GAC/B,MAAM;GAIR,MAAM,SAAS,MAAM,mBAAmB,QAAQ,MAAM;GACtD,IAAI,QACF,OAAO,SAAS,SAAS,QAAQ,MAAM;GAIzC,MAAM;EACR;OACK,IACL,CAAC,YACA,MAAM,wBAAwB,QAAQ,MAAM,MAAM,GAQnD,MAAM,QAAQ,SAAS,MAAM;EAM/B,OAAO,SAAS,SAAS,QAAQ,MAHZ,iBAAiB,SAAS,WAC7C,OAAO,KAAK,mBAAmB,EAAE,OAAO,CAAC,CAC3C,CACuC;CACzC;AACF;;;;;;;AAQA,eAAe,mBACb,QACA,QACuD;CACvD,IAAI;EACF,OAAO,MAAM,iBAAiB,SAAS,WACrC,oBACG,WAAW,OAAO,KAAK,eAAe;GAAE;GAAQ;EAAO,CAAC,GACzD,qBACF,CACF;CACF,SAAS,OAAO;EACd,IACE,iBAAiBA,sBACjB,MAAM,WAAW,YAEjB;EAEF,MAAM;CACR;AACF;;;;;;;;;;AAWA,eAAe,sBACb,QACA,aACA,UACe;CACf,MAAM,iBAAiB,QAAQ,OAAO,WAAW;EAC/C,IAAI,CAAC,gBAAgB,QAAQ,GAC3B,MAAM,kBAAkB;EAE1B,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,QAAQ,iBACN,WAAW,MAAM,kBAAkB,CAAC,GAC1C,KAAK,IAAI,GAAG,WAAW,oBAAoB,KAAK,IAAI,CAAC,CACvD;EAIA,MAAO,QAAQ;EACf,IAAI;GACF,OAAO,MAAM,OAAO,KAAK,mBAAmB;IAC1C,aAAa,YAAY;IACzB,YAAY,CAAC,YAAY,SAAS;IAClC,QAAQ,WAAW;GACrB,CAAC;EACH,UAAU;GACR,aAAa,KAAK;EACpB;CACF,CAAC;AACH;;;;;AAMA,SAAS,oBAA2B;CAClC,MAAM,wBAAQ,IAAI,MAAM,oDAAoD;CAC5E,MAAM,OAAO;CACb,OAAO;AACT;;AAGA,eAAe,yBACb,aACkB;CAClB,IAAI;EACF,OAAQ,MAAM,2BAA2B,WAAW,MAAO;CAC7D,QAAQ;EACN,OAAO;CACT;AACF;AAKA,SAAS,uBAAuB,OAAyB;CACvD,OACE,iBAAiB,YACjB,MAAM,SAAS,eAAe,eAAe;AAEjD;AAEA,SAAS,SACP,SACA,QACA,QACY;CACZ,MAAM,EAAE,MAAM,eAAe,WAAW,sBAAsB;CAE9D,MAAM,cAAc,OAAO,eAAe,OAAO;CACjD,IAAI,aAEF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;EACvD,QAAQ,YAAY;EACpB,QAAQ,aAAa,WAAW,YAAY,MAAM;EAClD,OAAO,KAAA;CACT,CAAC;CAGH,IAAI,CAAC,aAAa,OAAO,SACvB,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,aAAa,OAAO,OAAO,WAAW,kCAAkC,OAAO,WACtG,KAAA,GAEA,cAAc,EAAE,OAAO,KAAK,IAAI,KAAA,CAClC;CAGF,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;CAGtD,OAAO,EAAE,QAAQ,YAAY;AAC/B;AAEA,SAAS,QACP,SACA,QACkB;CAClB,QAAQ,cAAc,aAAa,QAAQ,MAAM,OAAO,MAAM,WAAW,EACvE,OAAO,KAAA,EACT,CAAC;CACD,OAAO,IAAI,iBACT,cAAc,oBACd,+CACA,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;AACF"}
@@ -0,0 +1,19 @@
1
+ //#region src/core/tasks/helpers/callWithinDeadline.d.ts
2
+ /**
3
+ * Runs one call to one node with its own abort signal and a budget of
4
+ * `timeoutMs`. Past the budget it aborts the call and rejects with a
5
+ * `TimeoutError`, so a node that accepts the connection and never answers
6
+ * cannot hold the caller open. The race does not rely on the transport to
7
+ * honour the abort, and the `finally` clears the timer on every exit.
8
+ *
9
+ * A timeout says nothing about the transaction: it is never a "not found",
10
+ * so the outcome stays unknown.
11
+ *
12
+ * The gRPC `timeout` call option is not enough: the gRPC-web transport only
13
+ * sends it as the `grpc-timeout` header, which a node that never answers
14
+ * ignores. Not `AbortSignal.timeout`: a published SDK should not raise its
15
+ * runtime floor for it.
16
+ */
17
+ export declare function callWithinDeadline<T>(call: (signal: AbortSignal) => PromiseLike<T>, timeoutMs: number): Promise<T>;
18
+ //#endregion
19
+ //# sourceMappingURL=callWithinDeadline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callWithinDeadline.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/callWithinDeadline.ts"],"mappings":";;;;;;;;;;;;;;;;wBAesB,mBAAmB,GACvC,OAAO,QAAQ,gBAAgB,YAAY,IAC3C,oBACC,QAAQ"}