@aurora-is-near/intents-connect 7.29.0 → 7.31.0

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 (192) hide show
  1. package/README.md +172 -2
  2. package/dist/account/index.d.ts +1 -0
  3. package/dist/account/intentsAccountId.d.ts +30 -0
  4. package/dist/account/stellar.d.ts +6 -0
  5. package/dist/account/ton.d.ts +10 -0
  6. package/dist/account/tron.d.ts +8 -0
  7. package/dist/api/createIntentsConnectApi.d.ts +2 -10
  8. package/dist/balances/alchemy.d.ts +23 -0
  9. package/dist/balances/evm.d.ts +25 -0
  10. package/dist/balances/getWalletBalances.d.ts +36 -0
  11. package/dist/balances/index.d.ts +7 -0
  12. package/dist/balances/jsonRpc.d.ts +25 -0
  13. package/dist/balances/near.d.ts +11 -0
  14. package/dist/balances/rpcs.d.ts +15 -0
  15. package/dist/balances/solana.d.ts +18 -0
  16. package/dist/balances/stellar.d.ts +18 -0
  17. package/dist/balances/tokens.d.ts +28 -0
  18. package/dist/balances/ton.d.ts +18 -0
  19. package/dist/balances/tron.d.ts +16 -0
  20. package/dist/balances/types.d.ts +24 -0
  21. package/dist/chains.d.ts +4 -5
  22. package/dist/chunks/recovery-CJRVfzVh.js +3936 -0
  23. package/dist/chunks/recovery-CJRVfzVh.js.map +1 -0
  24. package/dist/errors.d.ts +12 -0
  25. package/dist/funding/errors.d.ts +45 -0
  26. package/dist/funding/fundIntermediary.d.ts +101 -0
  27. package/dist/funding/index.d.ts +7 -0
  28. package/dist/funding/intermediaryBalance.d.ts +16 -0
  29. package/dist/funding/preparedIntent.d.ts +45 -0
  30. package/dist/funding/quoteRequest.d.ts +17 -0
  31. package/dist/funding/store.d.ts +28 -0
  32. package/dist/funding/types.d.ts +88 -0
  33. package/dist/http.d.ts +50 -0
  34. package/dist/index.d.ts +14 -3
  35. package/dist/index.js +328 -154
  36. package/dist/index.js.map +1 -1
  37. package/dist/intentsApi/createIntentsApi.d.ts +11 -0
  38. package/dist/intentsApi/index.d.ts +2 -0
  39. package/dist/intentsApi/types.d.ts +239 -0
  40. package/dist/near/errors.d.ts +25 -0
  41. package/dist/near/index.d.ts +3 -0
  42. package/dist/near/rpc.d.ts +44 -0
  43. package/dist/near/rpcUrls.d.ts +15 -0
  44. package/dist/ownership/errors.d.ts +16 -0
  45. package/dist/ownership/index.d.ts +7 -0
  46. package/dist/ownership/nonce.d.ts +14 -0
  47. package/dist/ownership/payload.d.ts +23 -0
  48. package/dist/ownership/salt.d.ts +11 -0
  49. package/dist/ownership/sign.d.ts +21 -0
  50. package/dist/ownership/signMultiPayload.d.ts +26 -0
  51. package/dist/ownership/types.d.ts +55 -0
  52. package/dist/ownership/verify.d.ts +22 -0
  53. package/dist/react/IntentsAccountProvider.d.ts +13 -0
  54. package/dist/react/IntentsConnectProvider.d.ts +5 -3
  55. package/dist/react/accountContext.d.ts +71 -0
  56. package/dist/react/index.d.ts +15 -0
  57. package/dist/react/index.js +971 -125
  58. package/dist/react/index.js.map +1 -1
  59. package/dist/react/useConfidentialBalances.d.ts +21 -0
  60. package/dist/react/useExecution.d.ts +3 -1
  61. package/dist/react/useFundingPreview.d.ts +33 -0
  62. package/dist/react/useIntentsAccount.d.ts +9 -0
  63. package/dist/react/useIntentsAuth.d.ts +31 -0
  64. package/dist/react/useIntentsBalances.d.ts +20 -0
  65. package/dist/react/useIntentsConnectFlow.d.ts +66 -0
  66. package/dist/react/useIntentsFundedFlow.d.ts +70 -0
  67. package/dist/react/useIntentsOutFlow.d.ts +56 -0
  68. package/dist/react/useIntermediaryBalance.d.ts +21 -0
  69. package/dist/react/useLiveResult.d.ts +21 -0
  70. package/dist/react/useQuotePreview.d.ts +40 -0
  71. package/dist/react/useResourceKey.d.ts +16 -0
  72. package/dist/react/useSupportedTokens.d.ts +23 -0
  73. package/dist/react/useWalletBalances.d.ts +30 -0
  74. package/dist/react/useWalletExecutions.d.ts +29 -0
  75. package/dist/react/useWalletVerification.d.ts +18 -0
  76. package/dist/resource.d.ts +44 -0
  77. package/dist/runner/flows/resume.d.ts +2 -0
  78. package/dist/runner/flows/runOut.d.ts +11 -0
  79. package/dist/runner/identity.d.ts +1 -1
  80. package/dist/runner/index.d.ts +2 -1
  81. package/dist/runner/planHelpers.d.ts +14 -2
  82. package/dist/runner/stages/planOut.d.ts +22 -0
  83. package/dist/runner/types.d.ts +53 -0
  84. package/dist/session/createIntentsSession.d.ts +94 -0
  85. package/dist/session/index.d.ts +1 -0
  86. package/dist/signers/intentsConnect.d.ts +7 -6
  87. package/dist/signers/standards/index.d.ts +2 -0
  88. package/dist/signers/standards/tip191.d.ts +17 -0
  89. package/dist/signers/standards/tonConnect.d.ts +17 -0
  90. package/dist/storage.d.ts +27 -0
  91. package/dist/types/execution.d.ts +13 -1
  92. package/dist/types/providers.d.ts +39 -0
  93. package/dist/types/signing.d.ts +3 -5
  94. package/dist/types/transfer.d.ts +2 -0
  95. package/dist/verification/index.d.ts +2 -0
  96. package/dist/verification/store.d.ts +33 -0
  97. package/dist/verification/verifyWallet.d.ts +24 -0
  98. package/package.json +1 -1
  99. package/src/account/index.ts +6 -0
  100. package/src/account/intentsAccountId.ts +130 -0
  101. package/src/account/stellar.ts +48 -0
  102. package/src/account/ton.ts +35 -0
  103. package/src/account/tron.ts +24 -0
  104. package/src/api/createIntentsConnectApi.ts +27 -96
  105. package/src/balances/alchemy.ts +217 -0
  106. package/src/balances/evm.ts +126 -0
  107. package/src/balances/getWalletBalances.ts +269 -0
  108. package/src/balances/index.ts +24 -0
  109. package/src/balances/jsonRpc.ts +154 -0
  110. package/src/balances/near.ts +90 -0
  111. package/src/balances/rpcs.ts +48 -0
  112. package/src/balances/solana.ts +160 -0
  113. package/src/balances/stellar.ts +145 -0
  114. package/src/balances/tokens.ts +75 -0
  115. package/src/balances/ton.ts +204 -0
  116. package/src/balances/tron.ts +169 -0
  117. package/src/balances/types.ts +31 -0
  118. package/src/chains.ts +18 -5
  119. package/src/errors.ts +31 -3
  120. package/src/funding/errors.ts +53 -0
  121. package/src/funding/fundIntermediary.ts +859 -0
  122. package/src/funding/index.ts +51 -0
  123. package/src/funding/intermediaryBalance.ts +40 -0
  124. package/src/funding/preparedIntent.ts +283 -0
  125. package/src/funding/quoteRequest.ts +45 -0
  126. package/src/funding/store.ts +161 -0
  127. package/src/funding/types.ts +125 -0
  128. package/src/http.ts +143 -0
  129. package/src/index.ts +179 -1
  130. package/src/intentsApi/createIntentsApi.ts +154 -0
  131. package/src/intentsApi/index.ts +32 -0
  132. package/src/intentsApi/types.ts +280 -0
  133. package/src/near/errors.ts +36 -0
  134. package/src/near/index.ts +13 -0
  135. package/src/near/rpc.ts +312 -0
  136. package/src/near/rpcUrls.ts +30 -0
  137. package/src/ownership/errors.ts +22 -0
  138. package/src/ownership/index.ts +29 -0
  139. package/src/ownership/nonce.ts +94 -0
  140. package/src/ownership/payload.ts +61 -0
  141. package/src/ownership/salt.ts +57 -0
  142. package/src/ownership/sign.ts +105 -0
  143. package/src/ownership/signMultiPayload.ts +131 -0
  144. package/src/ownership/types.ts +61 -0
  145. package/src/ownership/verify.ts +114 -0
  146. package/src/react/IntentsAccountProvider.tsx +305 -0
  147. package/src/react/IntentsConnectProvider.tsx +29 -5
  148. package/src/react/accountContext.ts +105 -0
  149. package/src/react/index.ts +75 -0
  150. package/src/react/useConfidentialBalances.ts +71 -0
  151. package/src/react/useExecution.ts +10 -0
  152. package/src/react/useFundingPreview.ts +83 -0
  153. package/src/react/useIntentsAccount.ts +21 -0
  154. package/src/react/useIntentsAuth.ts +99 -0
  155. package/src/react/useIntentsBalances.ts +53 -0
  156. package/src/react/useIntentsConnectFlow.ts +213 -0
  157. package/src/react/useIntentsFundedFlow.ts +580 -0
  158. package/src/react/useIntentsOutFlow.ts +210 -0
  159. package/src/react/useIntermediaryBalance.ts +59 -0
  160. package/src/react/useLiveResult.ts +118 -0
  161. package/src/react/useQuotePreview.ts +72 -0
  162. package/src/react/useResourceKey.ts +53 -0
  163. package/src/react/useSupportedTokens.ts +58 -0
  164. package/src/react/useWalletBalances.ts +74 -0
  165. package/src/react/useWalletExecutions.ts +70 -0
  166. package/src/react/useWalletVerification.ts +98 -0
  167. package/src/resource.ts +135 -0
  168. package/src/runner/createExecutionRunner.ts +4 -0
  169. package/src/runner/depositPlan.ts +7 -1
  170. package/src/runner/flows/resume.ts +10 -3
  171. package/src/runner/flows/runOut.ts +70 -0
  172. package/src/runner/identity.ts +1 -1
  173. package/src/runner/index.ts +5 -0
  174. package/src/runner/planHelpers.ts +66 -1
  175. package/src/runner/stages/planOut.ts +122 -0
  176. package/src/runner/types.ts +54 -0
  177. package/src/session/createIntentsSession.ts +488 -0
  178. package/src/session/index.ts +10 -0
  179. package/src/signers/intentsConnect.ts +48 -9
  180. package/src/signers/standards/index.ts +5 -0
  181. package/src/signers/standards/tip191.ts +42 -0
  182. package/src/signers/standards/tonConnect.ts +48 -0
  183. package/src/storage.ts +73 -0
  184. package/src/types/execution.ts +13 -1
  185. package/src/types/providers.ts +42 -0
  186. package/src/types/signing.ts +7 -7
  187. package/src/types/transfer.ts +4 -0
  188. package/src/verification/index.ts +10 -0
  189. package/src/verification/store.ts +159 -0
  190. package/src/verification/verifyWallet.ts +44 -0
  191. package/dist/chunks/recovery-C4NJU6-O.js +0 -1611
  192. package/dist/chunks/recovery-C4NJU6-O.js.map +0 -1
package/README.md CHANGED
@@ -99,8 +99,8 @@ amount. Two ways out:
99
99
  subpath per chain). It supplies the address, signing standard, providers, and
100
100
  the deposit transfer.
101
101
 
102
- Signing standards implemented: `erc191`, `raw_ed25519`, `nep413`, `sep53`.
103
- `tip191` (Tron) and `ton_connect` (TON) are not yet covered.
102
+ Signing standards implemented: `erc191`, `tip191`, `raw_ed25519`, `nep413`,
103
+ `sep53`, `ton_connect`.
104
104
 
105
105
  ## Guards
106
106
 
@@ -174,6 +174,65 @@ Notes:
174
174
  synchronously, so `run(plan).catch(…)` behaves.
175
175
 
176
176
 
177
+ ### Account hooks
178
+
179
+ With `intentsApi` on the provider, the same bindings read an account screen:
180
+ `useWalletBalances`, `useIntentsBalances`, `useWalletVerification`,
181
+ `useIntentsAuth` and `useConfidentialBalances`, plus `useIntentsConnectFlow`
182
+ (and `useIntentsOutFlow` for out-operations) for the submit / recovery glue
183
+ around `useExecution`. Stores live at provider
184
+ level, so hooks reading the same data share one request. See below.
185
+
186
+ Three more need no `intentsApi`:
187
+
188
+ - `useSupportedTokens({ flow? })` gives `origins` (what an execution can
189
+ start from) and `destinations` (what a recipe can receive), fetched once
190
+ per provider.
191
+ - `useQuotePreview({ exec, plan })` keeps a live quote for a plan the user is
192
+ still editing: a debounced `preview`, refreshed every 30 s, with results
193
+ for an older plan dropped. Run `preview.plan` to commit to exactly the
194
+ quoted steps.
195
+ - `useWalletExecutions({ status?, address? })` lists the provider wallet's
196
+ executions, newest first, or another wallet's by `address` (as its
197
+ connector reports it), e.g. a history across the wallets a user has.
198
+ With `IN_FLIGHT_STATUSES` it finds the one holding the wallet's lock, to
199
+ resume or cancel after a reload.
200
+
201
+ ## Account & balances
202
+
203
+ Everything an account screen needs, for EVM, Solana and NEAR wallets, through
204
+ the Aurora intents API (`createIntentsApi({ apiKey })`):
205
+
206
+ - **Intents account** — `getWalletIntentsAccountId(wallet)`.
207
+ - **Wallet balances** — `getWalletBalances({ family, address, tokens })`:
208
+ Alchemy for the chains it indexes when `alchemyApiKey` is set, JSON-RPC
209
+ otherwise (`DEFAULT_RPCS`, overridden per chain by `rpcs`). Chains fail
210
+ independently into `errors`. Free Solana RPCs refuse token-account queries,
211
+ so SPL balances need Alchemy or a keyed RPC.
212
+ - **Public intents balances** — `intentsApi.getIntentsAccountBalances(id)`.
213
+
214
+ ### Verification & authorization
215
+
216
+ Both rest on an **ownership proof**: an empty intent (`"intents": []`) the
217
+ wallet signs with a versioned, salted nonce. It moves nothing.
218
+
219
+ - `verifyWallet` has `intents.near` simulate the proof and remembers a pass
220
+ (`localStorage` by default). RPC failures throw rather than reading as
221
+ "not verified". Named NEAR accounts need their key registered on
222
+ `intents.near` (`add_public_key`), reported as `PUBLIC_KEY_NOT_REGISTERED`.
223
+ - `createIntentsSession` exchanges a proof for a 1Click user session and
224
+ reads confidential balances with it, refreshing the access token as needed.
225
+ Pass the proof `verifyWallet` returned to verify and authorize with **one**
226
+ signature.
227
+
228
+ Sessions live **in memory by default**. A persisted refresh token can mint
229
+ access tokens until it expires — anything that can read the storage can read
230
+ the user's confidential balances — so persist only deliberately
231
+ (`createIntentsSession({ storage: webStorage(sessionStorage) })`).
232
+
233
+ The intents API's NEAR RPC proxy is rate-limited per API key, shared by all
234
+ of an integration's users; the SDK uses it first only for proof calls.
235
+
177
236
  ## Solana bridge-in previews
178
237
 
179
238
  Use `SolanaRecipe<TParams>` for a Solana destination. Its asynchronous
@@ -297,3 +356,114 @@ Steps-only and bridge-in executions share the per-wallet in-flight lock: a live
297
356
  one of either kind blocks the other until it settles or is cancelled. A `503`
298
357
  from the steps endpoint means no Solana durable-nonce account was free — retry
299
358
  shortly. `retryDeposit()` does not apply; there is nothing to deposit.
359
+
360
+ ## Funding from intents balances
361
+
362
+ An Intents Connect quote's deposit address is on the origin chain, so it can
363
+ only be funded by an on-chain transfer. To spend **intents** (or
364
+ **confidential**) balances instead, `funding/` runs a deposit in two legs:
365
+
366
+ 1. **Leg A** — a 1Click swap from the user's intents account to their
367
+ intermediary, paid out as the recipe's destination token. One signature:
368
+ the transfer intent 1Click prepares (`generateIntent` → `signPreparedIntent`
369
+ → `submitIntent`). Refunds go back to the intents account.
370
+ 2. **Leg B** — a `steps-only` execution that spends what arrived at the
371
+ intermediary (the recipe with `flow: 'steps-only'`). A second signature.
372
+
373
+ ```ts
374
+ const record = await fundIntermediaryFromIntents(
375
+ {
376
+ source: 'intents', // or 'confidential' (needs `withAccessToken`)
377
+ originAsset: 'nep141:base-0x8335…omft.near', // intents token id
378
+ amount: '1000000',
379
+ destination: recipe.destination, // EVM chains only
380
+ },
381
+ { intentsApi, connectApi, wallet, store: createFundingStore() },
382
+ );
383
+ // record.stage === 'arrived' — now spend it:
384
+ const amount = await getIntermediaryBalance({ intermediary: { evm: record.recipient }, destination: recipe.destination });
385
+ await runner.runSteps({ recipe: stepsRecipe, params, amount, feeFromAmount: true });
386
+ ```
387
+
388
+ In React, `useIntentsFundedFlow({ exec, buildFunding, buildStepsPlan })` runs
389
+ both legs. `useIntermediaryBalance({ destination })` shows funds still waiting
390
+ at the intermediary, for a "supply what's waiting" button.
391
+
392
+ To price a funding while the user types, use `previewFunding(request, options)`
393
+ or `useFundingPreview({ request })`. It's a dry 1Click quote: no deposit
394
+ address, no record and no prompt. It returns what reaches the intermediary
395
+ (`minAmountOut`) and how soon. To show what leg B then spends, pass
396
+ `minAmountOut` to `exec.previewSteps(buildStepsPlan(...))`.
397
+
398
+ Safety:
399
+
400
+ - The quote must echo what was asked: recipient, refund and assets.
401
+ - The intent must be exactly one transfer of the amount to the quote's deposit
402
+ address.
403
+ - Both are checked before the wallet prompts.
404
+ - `submitting` is persisted before submitting. After a reload, a signed
405
+ transfer is only watched, never signed again (`resumeFunding`).
406
+ - The funding store is per account and lives in `localStorage` by default.
407
+
408
+ Leg B is a public transaction on the destination chain, from an intermediary
409
+ that is deterministic per wallet. Confidential funding hides where the funds
410
+ came from, not where they went.
411
+
412
+ ## Out-operations
413
+
414
+ An out-operation runs the steps where the intermediary holds funds (e.g.
415
+ withdrawing a lending position on Monad). It then sends what they released to
416
+ a 1Click deposit address, and 1Click pays it out to `quote.recipient`: an
417
+ address on any chain, or an intents account with `recipientType: 'INTENTS'`.
418
+ There is one signature and no deposit leg.
419
+
420
+ ```ts
421
+ const withdraw: Recipe<{ all: boolean }> = {
422
+ id: 'aave-withdraw', intent: 'aave_withdraw', title: 'Withdraw from Aave',
423
+ flow: 'out-operation', type: 'evm',
424
+ destination: { chain: 'monad', assetId: MONAD_USDC_ASSET, tokenAddress: MONAD_USDC },
425
+ // Release only: the runner appends the transfer to the deposit address.
426
+ buildSteps: ({ amount, intermediary }, { all }) => [
427
+ { to: POOL, functionSignature: 'withdraw(address,uint256,address)',
428
+ parameters: [MONAD_USDC, all ? MAX_UINT256 : amount, intermediary], value: '0' },
429
+ ],
430
+ };
431
+
432
+ await runner.runOut({
433
+ recipe: withdraw, params: { all: false },
434
+ amount: '5000000', // released by the steps
435
+ quote: { destinationAsset: BASE_USDC_ASSET, recipient: walletAddress },
436
+ });
437
+ ```
438
+
439
+ How the amounts work:
440
+
441
+ 1. **Measure the fee.** One dry create prices the fee.
442
+ 2. **Send less than `amount`.** The runner sends `amount − budget` to 1Click.
443
+ The budget is the fee plus `feeReserveBps` of headroom (default 50%), so the
444
+ intermediary can pay a fee that moved by the real create.
445
+ 3. **Check before signing.** A real fee above the budget is refused
446
+ (`FEE_EXCEEDS_AMOUNT`), and so is a quote that does not echo the payout
447
+ (`QUOTE_MOVED`).
448
+ 4. **Small overpayment, refunded.** 1Click quotes the deposit at `sent − fee`
449
+ and refunds the small excess.
450
+
451
+ In React, `useIntentsOutFlow({ buildPlan })` wraps it. `submit(args)` builds
452
+ the plan, runs it, and resolves the settled execution, or `undefined` with the
453
+ reason on `error`. `stage` folds the phases into `preparing`, `signing`,
454
+ `paying-out`, `success` and `failed`, plus `in-flight` when another execution
455
+ holds the lock (`resume()` or `cancel()`). `networkFee`, `payout` and `quote`
456
+ give the figures to show before and during the signature.
457
+
458
+ ```tsx
459
+ const out = useIntentsOutFlow({
460
+ buildPlan: (amount: string) => ({ recipe: withdraw, params: { all: false }, amount, quote }),
461
+ });
462
+
463
+ const settled = await out.submit('5000000');
464
+ if (settled) refreshPosition();
465
+ ```
466
+
467
+ The API rejects the `{INTERMEDIARY}` placeholder in EVM address parameters, so
468
+ use `ctx.intermediary`. `{AMOUNT_IN}` works only with `EXACT_OUTPUT`, which
469
+ `runOut` does not use.
@@ -0,0 +1 @@
1
+ export { getFamilyForStandard, getIntentsAccountId, getWalletIntentsAccountId, type IntentsAccountFamily, } from './intentsAccountId';
@@ -0,0 +1,30 @@
1
+ import { SigningStandard } from '../types/signing';
2
+ import { WalletConnector } from '../types/wallet';
3
+ /** The wallet families an intents account can be derived for. */
4
+ export type IntentsAccountFamily = 'evm' | 'sol' | 'near' | 'stellar' | 'tron' | 'ton';
5
+ /**
6
+ * The `intents.near` account id a wallet address signs for.
7
+ *
8
+ * - EVM and NEAR: the address, lower-cased.
9
+ * - Solana: the hex of the 32-byte public key the base58 address encodes.
10
+ * - Stellar: the hex of the 32-byte public key the `G…` StrKey encodes.
11
+ * - TRON: `0x` and the hex of the 20 address bytes the `T…` address encodes,
12
+ * which is how the MPC path names it.
13
+ * - TON: none from the address. It's the hex of the wallet's public key,
14
+ * which a TON address doesn't carry.
15
+ *
16
+ * Returns `undefined` for an address that does not fit its family, rather than
17
+ * deriving an id nobody can sign for.
18
+ */
19
+ export declare const getIntentsAccountId: ({ family, address, }: {
20
+ family: IntentsAccountFamily;
21
+ address: string | undefined;
22
+ }) => string | undefined;
23
+ /** The account family a signing standard proves ownership for. */
24
+ export declare const getFamilyForStandard: (standard: SigningStandard) => IntentsAccountFamily | undefined;
25
+ /**
26
+ * The intents account id of a connected `WalletConnector`, or `undefined` while
27
+ * it is disconnected or signs with a standard this package cannot derive an
28
+ * account for.
29
+ */
30
+ export declare const getWalletIntentsAccountId: (wallet: Pick<WalletConnector, "signingStandard" | "getAddress"> | null | undefined) => string | undefined;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The 32-byte ed25519 public key a Stellar account id (`G…`) encodes, or
3
+ * `undefined` for anything that isn't a well-formed one. Its hex is the
4
+ * account's intents id. No `@stellar/stellar-sdk` needed.
5
+ */
6
+ export declare const decodeStellarAccount: (address: string) => Uint8Array | undefined;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A TON address in one comparable form, `<workchain>:<hash hex>`, from
3
+ * either the raw (`0:ab…`) or the user-friendly (`EQ…`/`UQ…`) form, or
4
+ * `undefined` for neither. Bounceability and the test flag are dropped:
5
+ * they're how an address is shown, not which account it is.
6
+ *
7
+ * The friendly form's CRC16 is not verified: addresses come from wallets
8
+ * and token lists, not from typing.
9
+ */
10
+ export declare const tonAddressKey: (address: string) => string | undefined;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The 20 address bytes a TRON base58 address (`T…`) encodes, or `undefined`
3
+ * for anything that isn't shaped like one.
4
+ *
5
+ * The checksum (double SHA-256) is not verified: that needs a hash this
6
+ * package doesn't carry, and addresses come from the wallet, not from typing.
7
+ */
8
+ export declare const decodeTronAddress: (address: string) => Uint8Array | undefined;
@@ -1,14 +1,6 @@
1
+ import { FetchLike } from '../http';
1
2
  import { IntentsConnectApi } from './types';
2
- export type FetchLike = (input: string, init?: {
3
- method?: string;
4
- headers?: Record<string, string>;
5
- body?: string;
6
- signal?: AbortSignal;
7
- }) => Promise<{
8
- ok: boolean;
9
- status: number;
10
- text: () => Promise<string>;
11
- }>;
3
+ export type { FetchLike };
12
4
  export type IntentsConnectApiOptions = {
13
5
  baseUrl: string;
14
6
  /**
@@ -0,0 +1,23 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ /** 1Click chain slug → Alchemy network. Chains outside it use RPCs. */
3
+ export declare const ALCHEMY_NETWORKS: Readonly<Record<string, string>>;
4
+ export declare const isAlchemyChain: (chain: string) => boolean;
5
+ /**
6
+ * Balances of one address across every Alchemy-indexed chain in `tokens`, in
7
+ * as few as one request. Tokens are matched on (chain, contract) — several
8
+ * asset ids sharing a contract all get its balance — and a token absent from
9
+ * a complete result reads as zero.
10
+ */
11
+ export declare const readAlchemyBalances: ({ apiKey, address, tokens, ...transport }: {
12
+ apiKey: string;
13
+ address: string;
14
+ /** Tokens on Alchemy chains only. */
15
+ tokens: readonly BalanceToken[];
16
+ } & BalanceTransportOptions) => Promise<{
17
+ balances: Record<string, string>;
18
+ /**
19
+ * Tokens Alchemy did not report before the page cap. Only non-empty for
20
+ * wallets holding hundreds of tokens; read them another way.
21
+ */
22
+ unread: BalanceToken[];
23
+ }>;
@@ -0,0 +1,25 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ export declare const encodeBalanceOf: (owner: string) => string;
3
+ /**
4
+ * Balances of one EVM chain over plain JSON-RPC: `eth_getBalance` for the gas
5
+ * token, `eth_call balanceOf` for ERC-20s. One call per distinct contract,
6
+ * even when several asset ids share it.
7
+ */
8
+ export declare const readEvmBalances: ({ address, tokens, rpcUrls, ...transport }: {
9
+ address: string;
10
+ /** Tokens of ONE chain. */
11
+ tokens: readonly BalanceToken[];
12
+ rpcUrls: readonly string[];
13
+ } & BalanceTransportOptions) => Promise<Record<string, string>>;
14
+ /**
15
+ * One EVM balance: `balanceOf` for an ERC-20, `eth_getBalance` without
16
+ * `tokenAddress`. Throws `BalanceRpcError` rather than reading a failure as
17
+ * zero — a caller deciding whether funds arrived must not mistake an outage
18
+ * for an empty account.
19
+ */
20
+ export declare const readEvmTokenBalance: ({ owner, tokenAddress, rpcUrls, ...transport }: {
21
+ owner: string;
22
+ /** Undefined reads the chain's native asset. */
23
+ tokenAddress?: string;
24
+ rpcUrls: readonly string[];
25
+ } & BalanceTransportOptions) => Promise<string>;
@@ -0,0 +1,36 @@
1
+ import { IntentsAccountFamily } from '../account';
2
+ import { BalanceToken, BalanceTransportOptions, ChainRpcUrls, WalletBalances } from './types';
3
+ import { IntentsApi } from '../intentsApi/types';
4
+ export type BalanceSource = 'alchemy' | 'rpc' | 'none';
5
+ /** Alchemy when keyed and indexed, else RPCs when configured, else nothing. */
6
+ export declare const getBalanceSource: (chain: string, { alchemyApiKey, rpcs }: {
7
+ alchemyApiKey?: string;
8
+ rpcs: ChainRpcUrls;
9
+ }) => BalanceSource;
10
+ export type GetWalletBalancesArgs = {
11
+ family: IntentsAccountFamily;
12
+ address: string;
13
+ /** From `getTokens(intentsApi)`; tokens of other families are ignored. */
14
+ tokens: readonly BalanceToken[];
15
+ /** Reads EVM and Solana chains Alchemy indexes in one request. */
16
+ alchemyApiKey?: string;
17
+ /** TronGrid's `TRON-PRO-API-KEY`: without one, ~1 request per second. */
18
+ tronGridApiKey?: string;
19
+ /** toncenter's `X-API-Key`: without one, ~1 request per second. */
20
+ tonCenterApiKey?: string;
21
+ /**
22
+ * Per-chain endpoints, merged over `DEFAULT_RPCS` chain by chain. `near`
23
+ * replaces the public NEAR endpoints.
24
+ */
25
+ rpcs?: ChainRpcUrls;
26
+ /** Adds the intents-api NEAR proxy as the last NEAR fallback. */
27
+ intentsApi?: Pick<IntentsApi, 'nearRpcUrl'>;
28
+ } & BalanceTransportOptions;
29
+ /**
30
+ * The wallet's balance of every listed token it can hold.
31
+ *
32
+ * Chains are read in parallel and fail independently: one unreachable RPC
33
+ * lands in `errors` without hiding the others. If Alchemy fails, its chains
34
+ * fall back to RPCs.
35
+ */
36
+ export declare const getWalletBalances: ({ family, address, tokens, alchemyApiKey, tronGridApiKey, tonCenterApiKey, rpcs: customRpcs, intentsApi, ...transport }: GetWalletBalancesArgs) => Promise<WalletBalances>;
@@ -0,0 +1,7 @@
1
+ export { getTokens, getBalanceFamily, isNativeToken, NATIVE_NEAR_ASSET_ID, normalizeTokens, toQuoteAssetId, } from './tokens';
2
+ export { DEFAULT_RPCS, resolveRpcs } from './rpcs';
3
+ export { ALCHEMY_NETWORKS, isAlchemyChain } from './alchemy';
4
+ export { BalanceRpcError } from './jsonRpc';
5
+ export { readEvmTokenBalance } from './evm';
6
+ export { getBalanceSource, getWalletBalances, type BalanceSource, type GetWalletBalancesArgs, } from './getWalletBalances';
7
+ export type { BalanceToken, BalanceTransportOptions, ChainRpcUrls, WalletBalances, } from './types';
@@ -0,0 +1,25 @@
1
+ import { BalanceTransportOptions } from './types';
2
+ import { IntentsConnectError } from '../errors';
3
+ export type JsonRpcRequest = {
4
+ method: string;
5
+ params: unknown[];
6
+ };
7
+ export type JsonRpcOutcome = {
8
+ ok: true;
9
+ result: unknown;
10
+ } | {
11
+ ok: false;
12
+ error: string;
13
+ };
14
+ /** Every endpoint of a chain failed for transport reasons. */
15
+ export declare class BalanceRpcError extends IntentsConnectError {
16
+ constructor(message: string, options?: {
17
+ cause?: unknown;
18
+ });
19
+ }
20
+ /**
21
+ * JSON-RPC calls in batches of `MAX_BATCH`, each batch failing over across
22
+ * `urls` on transport errors. A per-request error (a reverted `eth_call`)
23
+ * stays local to that request.
24
+ */
25
+ export declare const jsonRpcBatch: (urls: readonly string[], requests: readonly JsonRpcRequest[], options?: BalanceTransportOptions) => Promise<JsonRpcOutcome[]>;
@@ -0,0 +1,11 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ /**
3
+ * NEAR balances: `view_account` for native NEAR and `ft_balance_of` for each
4
+ * NEP-141 (NEAR token lists are short). A token whose contract rejects the
5
+ * call is skipped; the chain only fails when the RPC itself is unreachable.
6
+ */
7
+ export declare const readNearBalances: ({ address, tokens, rpcUrls, ...transport }: {
8
+ address: string;
9
+ tokens: readonly BalanceToken[];
10
+ rpcUrls: readonly string[];
11
+ } & BalanceTransportOptions) => Promise<Record<string, string>>;
@@ -0,0 +1,15 @@
1
+ import { ChainRpcUrls } from './types';
2
+ /**
3
+ * Public endpoints per chain — the same set the swap widget ships. NEAR is
4
+ * resolved separately (`balanceRpcUrls`), so it can fall back to the
5
+ * intents-api proxy.
6
+ */
7
+ export declare const DEFAULT_RPCS: Readonly<Record<string, readonly string[]>>;
8
+ /**
9
+ * Custom endpoints override the defaults chain by chain: passing only
10
+ * `{ base: [...] }` keeps every other chain on its default. (The widget
11
+ * replaced the whole map, silently dropping every chain not listed.)
12
+ *
13
+ * An empty list disables RPC reads for that chain.
14
+ */
15
+ export declare const resolveRpcs: (custom?: ChainRpcUrls) => ChainRpcUrls;
@@ -0,0 +1,18 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ /**
3
+ * Solana balances in three requests however many tokens: `getBalance` for
4
+ * SOL, and one `getTokenAccountsByOwner` per token program, summing every
5
+ * account of a mint (the widget read only the first account).
6
+ *
7
+ * SPL reads need an endpoint that serves token-account queries — public
8
+ * endpoints mostly do not. SOL is read on its own, so it survives that, and
9
+ * the SPL failure comes back as `partialError`.
10
+ */
11
+ export declare const readSolanaBalances: ({ address, tokens, rpcUrls, ...transport }: {
12
+ address: string;
13
+ tokens: readonly BalanceToken[];
14
+ rpcUrls: readonly string[];
15
+ } & BalanceTransportOptions) => Promise<{
16
+ balances: Record<string, string>;
17
+ partialError?: Error;
18
+ }>;
@@ -0,0 +1,18 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ /**
3
+ * What a Stellar account can spend, from Horizon (`/accounts/{G…}`), in
4
+ * stroops:
5
+ * - XLM: the balance less the minimum the account must keep,
6
+ * `(2 + subentries + sponsoring − sponsored) × 0.5 XLM`, and its selling
7
+ * liabilities;
8
+ * - an issued asset (USDC…): its balance on the trustline whose code and
9
+ * issuer match the token (`contractAddress` is the issuer), less selling
10
+ * liabilities.
11
+ *
12
+ * An account that doesn't exist yet holds nothing.
13
+ */
14
+ export declare const readStellarBalances: ({ address, tokens, horizonUrls, ...transport }: {
15
+ address: string;
16
+ tokens: readonly BalanceToken[];
17
+ horizonUrls: readonly string[];
18
+ } & BalanceTransportOptions) => Promise<Record<string, string>>;
@@ -0,0 +1,28 @@
1
+ import { IntentsAccountFamily } from '../account';
2
+ import { BalanceToken } from './types';
3
+ import { IntentsApi, IntentsApiToken } from '../intentsApi/types';
4
+ /**
5
+ * Asset id of native NEAR. The token list only carries wNEAR (`wrap.near`);
6
+ * native NEAR is synthesised from it, as the widget does, because a NEAR
7
+ * wallet holds both.
8
+ */
9
+ export declare const NATIVE_NEAR_ASSET_ID = "native-near";
10
+ /**
11
+ * The asset id a quote takes for a balance token: native NEAR is quoted as
12
+ * wNEAR (1Click has no native NEAR asset), and its deposit wraps it on the
13
+ * way. Every other token is quoted as itself.
14
+ */
15
+ export declare const toQuoteAssetId: ({ assetId }: Pick<BalanceToken, "assetId">) => string;
16
+ /** The wallet family whose balances can be read on a chain. */
17
+ export declare const getBalanceFamily: (chain: string) => IntentsAccountFamily | undefined;
18
+ /** A chain's gas token: no contract address (native NEAR is synthesised). */
19
+ export declare const isNativeToken: (token: BalanceToken) => boolean;
20
+ /**
21
+ * 1Click's whole token list, on every chain, with lower-cased chain slugs,
22
+ * and native NEAR added next to wNEAR. Wallet balances are only read on the
23
+ * chains of the wallet's family (`getWalletBalances` skips the rest); an
24
+ * intents account can hold, and pay with, any of them (Bitcoin, XRP…).
25
+ */
26
+ export declare const normalizeTokens: (tokens: readonly IntentsApiToken[]) => BalanceToken[];
27
+ /** The intents API's token list, ready for `getWalletBalances`. */
28
+ export declare const getTokens: (intentsApi: Pick<IntentsApi, "getTokens">) => Promise<BalanceToken[]>;
@@ -0,0 +1,18 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ /**
3
+ * TON and jetton balances of a TON wallet from toncenter's v3 API
4
+ * (`walletInformation`, then `jetton/wallets`). Jettons are matched by their
5
+ * master (`contractAddress`, any address form). An account that doesn't
6
+ * exist yet reads as zero.
7
+ *
8
+ * Without `apiKey` toncenter allows about one request per second: the two
9
+ * calls are spaced, and reads of one account a moment apart share them.
10
+ */
11
+ export declare const readTonBalances: ({ address, tokens, apiUrls, apiKey, fetch: fetchImpl, timeout, }: {
12
+ address: string;
13
+ tokens: readonly BalanceToken[];
14
+ /** toncenter-compatible endpoints, tried in order. */
15
+ apiUrls: readonly string[];
16
+ /** toncenter's `X-API-Key`. */
17
+ apiKey?: string;
18
+ } & BalanceTransportOptions) => Promise<Record<string, string>>;
@@ -0,0 +1,16 @@
1
+ import { BalanceToken, BalanceTransportOptions } from './types';
2
+ /**
3
+ * TRX and TRC-20 balances of a TRON account, in one TronGrid call
4
+ * (`/v1/accounts/{T…}`). TRC-20 tokens are matched by their contract
5
+ * (`contractAddress`, base58). Frozen TRX is not spendable and not counted.
6
+ *
7
+ * An account that isn't activated yet holds nothing.
8
+ */
9
+ export declare const readTronBalances: ({ address, tokens, apiUrls, apiKey, ...transport }: {
10
+ address: string;
11
+ tokens: readonly BalanceToken[];
12
+ /** TronGrid-compatible endpoints, tried in order. */
13
+ apiUrls: readonly string[];
14
+ /** TronGrid's `TRON-PRO-API-KEY`, for more than ~1 request per second. */
15
+ apiKey?: string;
16
+ } & BalanceTransportOptions) => Promise<Record<string, string>>;
@@ -0,0 +1,24 @@
1
+ import { FetchLike } from '../http';
2
+ import { IntentsApiToken } from '../intentsApi/types';
3
+ /** A token whose wallet balance can be read. */
4
+ export type BalanceToken = Pick<IntentsApiToken, 'assetId' | 'symbol' | 'blockchain' | 'decimals' | 'contractAddress' | 'price'>;
5
+ /** Per-chain RPC endpoints, tried in order. Keys are 1Click chain slugs. */
6
+ export type ChainRpcUrls = Partial<Record<string, readonly string[]>>;
7
+ export type WalletBalances = {
8
+ /**
9
+ * Smallest-unit balances keyed by asset id. Includes zeros for tokens that
10
+ * were read; a token missing from the map could not be read.
11
+ */
12
+ balances: Record<string, string>;
13
+ /**
14
+ * Chains that could not be read, fully or partly (e.g. SOL read but SPL
15
+ * tokens refused by the endpoint), keyed by chain slug.
16
+ */
17
+ errors: Record<string, Error>;
18
+ };
19
+ export type BalanceTransportOptions = {
20
+ /** Defaults to global `fetch`, resolved at call time. */
21
+ fetch?: FetchLike;
22
+ /** Per request, milliseconds. */
23
+ timeout?: number;
24
+ };
package/dist/chains.d.ts CHANGED
@@ -31,10 +31,9 @@ export declare const SIGNING_STANDARD_CHAINS: Readonly<Record<string, string>>;
31
31
  * memo guard may be skipped when the origin chain itself is unknown.
32
32
  *
33
33
  * Deliberately the SAFE list rather than the unsafe one, so the default is to
34
- * fail CLOSED: a standard nobody has classified here — a new one, or
35
- * `ton_connect`, whose chain attributes deposits by comment exactly like
36
- * Stellar — must not slip past the guard just because the inference above
37
- * came back empty. `sep53` is absent because it resolves to a chain outright.
34
+ * fail CLOSED: a standard nobody has classified here must not slip past the
35
+ * guard just because the inference above came back empty. `sep53` and
36
+ * `ton_connect` are absent because they resolve to a chain outright.
38
37
  */
39
38
  export declare const MEMO_FREE_SIGNING_STANDARDS: ReadonlySet<string>;
40
39
  /**
@@ -43,7 +42,7 @@ export declare const MEMO_FREE_SIGNING_STANDARDS: ReadonlySet<string>;
43
42
  * (every other ed25519 origin supplies it at `/submit` instead).
44
43
  */
45
44
  export declare const PUBLIC_KEY_REQUIRED_CHAINS: Set<string>;
46
- export type ChainFamily = 'evm' | 'sol' | 'stellar' | 'near';
45
+ export type ChainFamily = 'evm' | 'sol' | 'stellar' | 'near' | 'tron' | 'ton';
47
46
  /**
48
47
  * Decodes the origin chain and token address baked into a bridged asset id:
49
48
  * `nep141:gnosis-0x2a22….omft.near` → `{ chain: 'gnosis', tokenAddress: '0x2a22…' }`,