@fastxyz/allset-sdk 0.1.11 → 1.0.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 (44) hide show
  1. package/README.md +339 -266
  2. package/dist/index.d.ts +658 -5
  3. package/dist/index.js +927 -7
  4. package/package.json +21 -47
  5. package/dist/browser/index.d.ts +0 -2
  6. package/dist/browser/index.d.ts.map +0 -1
  7. package/dist/browser/index.js +0 -1
  8. package/dist/core/address.d.ts +0 -5
  9. package/dist/core/address.d.ts.map +0 -1
  10. package/dist/core/address.js +0 -29
  11. package/dist/core/deposit.d.ts +0 -59
  12. package/dist/core/deposit.d.ts.map +0 -1
  13. package/dist/core/deposit.js +0 -92
  14. package/dist/core/index.d.ts +0 -6
  15. package/dist/core/index.d.ts.map +0 -1
  16. package/dist/core/index.js +0 -3
  17. package/dist/default-config.d.ts +0 -78
  18. package/dist/default-config.d.ts.map +0 -1
  19. package/dist/default-config.js +0 -78
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/intents.d.ts +0 -94
  22. package/dist/intents.d.ts.map +0 -1
  23. package/dist/intents.js +0 -119
  24. package/dist/node/bridge.d.ts +0 -38
  25. package/dist/node/bridge.d.ts.map +0 -1
  26. package/dist/node/bridge.js +0 -519
  27. package/dist/node/config.d.ts +0 -45
  28. package/dist/node/config.d.ts.map +0 -1
  29. package/dist/node/config.js +0 -48
  30. package/dist/node/eip7702.d.ts +0 -47
  31. package/dist/node/eip7702.d.ts.map +0 -1
  32. package/dist/node/eip7702.js +0 -189
  33. package/dist/node/evm-executor.d.ts +0 -130
  34. package/dist/node/evm-executor.d.ts.map +0 -1
  35. package/dist/node/evm-executor.js +0 -160
  36. package/dist/node/index.d.ts +0 -15
  37. package/dist/node/index.d.ts.map +0 -1
  38. package/dist/node/index.js +0 -17
  39. package/dist/node/provider.d.ts +0 -162
  40. package/dist/node/provider.d.ts.map +0 -1
  41. package/dist/node/provider.js +0 -272
  42. package/dist/node/types.d.ts +0 -110
  43. package/dist/node/types.d.ts.map +0 -1
  44. package/dist/node/types.js +0 -4
package/README.md CHANGED
@@ -1,384 +1,457 @@
1
- # AllSet SDK
1
+ ---
2
+ name: allset-sdk
3
+ description: >
4
+ AllSet SDK for bridging tokens between Fast network and EVM chains. Use executeDeposit
5
+ for EVM → Fast deposits and executeIntent for Fast → EVM withdrawals or custom operations.
6
+ All functions are pure — no embedded config, no file system access. Caller provides all
7
+ chain/contract addresses.
8
+ metadata:
9
+ short-description: Bridge tokens between Fast and EVM chains (pure functions, no config).
10
+ compatibility: Node.js 20+; browser-safe pure helpers (address, deposit, intents).
11
+ ---
2
12
 
3
- Bridge tokens between Fast network and EVM chains.
13
+ # @fastxyz/allset-sdk
4
14
 
5
- | Entrypoint | Use Case |
6
- |------------|----------|
7
- | `@fastxyz/allset-sdk` | Pure helpers (deposit planning, intent builders) |
8
- | `@fastxyz/allset-sdk/node` | Full bridge execution (deposits, withdrawals) |
9
- | `@fastxyz/allset-sdk/browser` | Browser-safe pure helpers |
15
+ AllSet SDK for bridging tokens between [Fast network](https://fast.xyz) and EVM chains.
10
16
 
11
- ## Install
17
+ - **EVM → Fast (deposit):** `executeDeposit()`
18
+ - **Fast → EVM (withdrawal):** `executeWithdraw()` or `executeIntent()` + intent builders
19
+ - **Pure helpers:** `buildDepositTransaction()`, intent builders, address utils — browser-safe
12
20
 
13
- For node bridge execution and pure helpers only:
21
+ **Design:** All functions are pure no embedded chain config, no file system access, no environment variable reads. The caller provides all addresses, URLs, and credentials.
14
22
 
15
- ```bash
16
- npm install @fastxyz/allset-sdk
17
- ```
23
+ ---
18
24
 
19
- Install [`@fastxyz/sdk`](https://github.com/fastxyz/fast-sdk) only for FastWallet-backed flows such as `sendToExternal(...)` and `executeIntent(...)`:
25
+ ## Use Cases
20
26
 
21
- ```bash
22
- npm install @fastxyz/allset-sdk @fastxyz/sdk
23
- ```
27
+ - Bridge tokens from EVM to Fast network (deposit / EVM → Fast)
28
+ - Bridge tokens from Fast to EVM (withdrawal / Fast → EVM)
29
+ - Execute custom intents on EVM via AllSet bridge
30
+ - Build or plan deposit transactions (pure, browser-safe helpers)
31
+ - Set up EVM wallets for bridging
24
32
 
25
- ## Quick Start
33
+ **Out of scope:** Fast-only operations (balance, send, sign) → [`@fastxyz/sdk`](../fast-sdk) · EVM-only operations without bridging · Swaps, lending, or staking
26
34
 
27
- ```ts
28
- import { FastProvider, FastWallet } from '@fastxyz/sdk';
29
- import { AllSetProvider, createEvmWallet, createEvmExecutor } from '@fastxyz/allset-sdk/node';
30
-
31
- // 1. Setup providers and wallets
32
- const fastProvider = new FastProvider({ network: 'testnet' });
33
- const allset = new AllSetProvider({ network: 'testnet' });
34
- const fastWallet = await FastWallet.fromKeyfile('~/.fast/keys/default.json', fastProvider);
35
- const evmAccount = createEvmWallet('~/.evm/keys/default.json');
36
- const evmClients = createEvmExecutor(evmAccount, 'https://sepolia-rollup.arbitrum.io/rpc', 421614);
37
-
38
- // 2. Deposit: EVM → Fast
39
- await allset.sendToFast({
40
- chain: 'arbitrum-sepolia',
41
- token: 'USDC',
42
- amount: '1000000',
43
- from: evmAccount.address,
44
- to: fastWallet.address,
45
- evmClients,
46
- });
35
+ All functions are exported from a single root entrypoint — no sub-paths:
47
36
 
48
- // 3. Withdraw: Fast → EVM
49
- await allset.sendToExternal({
50
- chain: 'arbitrum-sepolia',
51
- token: 'USDC',
52
- amount: '1000000',
53
- from: fastWallet.address,
54
- to: evmAccount.address,
55
- fastWallet,
56
- });
37
+ ```ts
38
+ import { ... } from '@fastxyz/allset-sdk';
57
39
  ```
58
40
 
59
41
  ---
60
42
 
61
- ## AllSetProvider Setup
43
+ ## Installation
62
44
 
63
- AllSetProvider connects to AllSet bridge infrastructure.
45
+ ```bash
46
+ npm install @fastxyz/allset-sdk
47
+ # or
48
+ pnpm add @fastxyz/allset-sdk
49
+ ```
64
50
 
65
- ### Default (testnet)
51
+ `viem` is installed as a package dependency and is also useful directly in consumer code when you need chain objects or wallet helpers.
66
52
 
67
- ```ts
68
- import { AllSetProvider } from '@fastxyz/allset-sdk/node';
53
+ ---
69
54
 
70
- const allset = new AllSetProvider();
71
- ```
55
+ ## Workflows
72
56
 
73
- ### Specify Network
57
+ ### Deposit (EVM → Fast)
74
58
 
75
59
  ```ts
76
- const allset = new AllSetProvider({ network: 'testnet' });
77
- // or when available:
78
- const allset = new AllSetProvider({ network: 'mainnet' });
60
+ import { createEvmWallet, createEvmExecutor, executeDeposit } from '@fastxyz/allset-sdk';
61
+
62
+ const account = createEvmWallet('0xYourPrivateKey');
63
+ const evmClients = createEvmExecutor(account, 'https://your-evm-rpc...', 421614);
64
+
65
+ const result = await executeDeposit({
66
+ chainId: 421614,
67
+ bridgeContract: '0xb536...', // AllSet bridge contract on Arbitrum Sepolia
68
+ tokenAddress: '0x75fa...', // USDC on Arbitrum Sepolia
69
+ amount: '1000000', // 1 USDC (6 decimals)
70
+ senderAddress: account.address,
71
+ receiverAddress: 'fast1abc...', // your Fast address
72
+ evmClients,
73
+ });
74
+
75
+ console.log(result.txHash); // EVM transaction hash
79
76
  ```
80
77
 
81
- ### Custom Config
78
+ ### Smart Deposit via EIP-7702 (EVM → Fast, gasless)
79
+
80
+ Gas is paid in the deposit token (USDC) — no ETH required.
82
81
 
83
82
  ```ts
84
- const allset = new AllSetProvider({
85
- configPath: './my-networks.json',
86
- crossSignUrl: 'https://custom.cross-sign.example.com',
83
+ import {
84
+ smartDeposit,
85
+ encodeDepositCalldata,
86
+ fastAddressToBytes32,
87
+ InsufficientBalanceError,
88
+ } from '@fastxyz/allset-sdk';
89
+
90
+ const receiverBytes32 = fastAddressToBytes32('fast1abc...');
91
+ const depositCalldata = encodeDepositCalldata({
92
+ tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
93
+ amount: 1_000n, // 0.001 USDC
94
+ receiverBytes32,
87
95
  });
88
- ```
89
96
 
90
- ### Provider Options
91
-
92
- ```ts
93
- interface AllSetProviderOptions {
94
- network?: 'testnet' | 'mainnet';
95
- configPath?: string; // Custom config file path
96
- crossSignUrl?: string; // Override cross-sign endpoint
97
+ try {
98
+ const result = await smartDeposit({
99
+ privateKey: '0xYourPrivateKey',
100
+ rpcUrl: 'https://base-rpc...',
101
+ allsetApiUrl: 'https://allset.fast.xyz/api',
102
+ tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
103
+ amount: 1_000n,
104
+ bridgeAddress: '0x8677EdAA374b7A47ff0093947AABE4aCbB2D4538',
105
+ depositCalldata,
106
+ });
107
+
108
+ console.log(result.txHash); // on-chain transaction hash
109
+ console.log(result.userOpHash); // ERC-4337 UserOperation hash
110
+ } catch (err) {
111
+ if (err instanceof InsufficientBalanceError) {
112
+ console.error(`Need ${err.required}, have ${err.balance}`);
113
+ }
97
114
  }
98
115
  ```
99
116
 
100
- ### Network Config Resolution Order
117
+ ### Withdrawal (Fast EVM)
101
118
 
102
- 1. Custom `configPath` (if provided, highest priority)
103
- 2. `~/.allset/networks.json` (user override)
104
- 3. Bundled defaults from `src/default-config.ts`
105
-
106
- ---
119
+ ```ts
120
+ import { Signer, FastProvider } from '@fastxyz/sdk';
121
+ import { executeWithdraw } from '@fastxyz/allset-sdk';
122
+
123
+ const signer = new Signer('0xYourPrivateKey');
124
+ const provider = new FastProvider({ rpcUrl: 'https://your-fast-rpc...' });
125
+
126
+ const result = await executeWithdraw({
127
+ fastBridgeAddress: 'fast1bridge...',
128
+ relayerUrl: 'https://relayer.allset...',
129
+ crossSignUrl: 'https://cross-sign.allset...',
130
+ tokenEvmAddress: '0x75fa...',
131
+ tokenFastTokenId: 'abc123...', // hex token ID on Fast network (no 0x)
132
+ amount: '1000000',
133
+ receiverEvmAddress: '0xReceiverEVM...',
134
+ networkId: 'fast:testnet', // or 'fast:mainnet'
135
+ signer,
136
+ provider,
137
+ });
107
138
 
108
- ## Fast Wallet Setup
139
+ console.log(result.txHash);
140
+ ```
109
141
 
110
- Fast wallet is required for withdrawals (Fast → EVM).
142
+ ### Withdrawal with custom intents
111
143
 
112
144
  ```ts
113
- import { FastProvider, FastWallet } from '@fastxyz/sdk';
114
-
115
- const fastProvider = new FastProvider({ network: 'testnet' });
116
- const fastWallet = await FastWallet.fromKeyfile('~/.fast/keys/default.json', fastProvider);
145
+ import { Signer, FastProvider } from '@fastxyz/sdk';
146
+ import { executeIntent, buildTransferIntent } from '@fastxyz/allset-sdk';
147
+
148
+ const signer = new Signer('0xYourPrivateKey');
149
+ const provider = new FastProvider({ rpcUrl: 'https://...' });
150
+
151
+ const result = await executeIntent({
152
+ fastBridgeAddress: 'fast1bridge...',
153
+ relayerUrl: 'https://relayer.allset...',
154
+ crossSignUrl: 'https://cross-sign.allset...',
155
+ tokenEvmAddress: '0x75fa...',
156
+ tokenFastTokenId: 'abc123...',
157
+ amount: '1000000',
158
+ intents: [buildTransferIntent('0x75fa...', '0xReceiverEVM...')],
159
+ networkId: 'fast:testnet',
160
+ signer,
161
+ provider,
162
+ });
117
163
  ```
118
164
 
119
- See [`@fastxyz/sdk` documentation](https://github.com/fastxyz/fast-sdk) for wallet setup details.
120
-
121
165
  ---
122
166
 
123
- ## EVM Wallet Setup
167
+ ## API Reference
168
+
169
+ ### Wallet & Clients
124
170
 
125
- EVM wallet is required for deposits (EVM → Fast).
171
+ #### `createEvmWallet(privateKey?): EvmAccount`
126
172
 
127
- ### Generate New Wallet
173
+ Creates an EVM wallet. Generates a new random wallet if `privateKey` is omitted.
128
174
 
129
175
  ```ts
130
- import { createEvmWallet } from '@fastxyz/allset-sdk/node';
131
-
132
- const account = createEvmWallet();
133
- console.log('Address:', account.address);
134
- console.log('Private Key:', account.privateKey); // Save this!
176
+ const account = createEvmWallet(); // random
177
+ const account = createEvmWallet('0xabc123...'); // from existing key
178
+ // account.privateKey hex key (persist to reuse)
179
+ // account.address — 0x address
135
180
  ```
136
181
 
137
- ### From Private Key
182
+ #### `createEvmExecutor(account, rpcUrl, chainId): EvmClients`
183
+
184
+ Creates viem `walletClient` and `publicClient` for the given chain.
138
185
 
139
186
  ```ts
140
- const account = createEvmWallet('0x1234...64hexchars');
141
- // or without 0x prefix
142
- const account = createEvmWallet('1234...64hexchars');
187
+ const { walletClient, publicClient } = createEvmExecutor(account, rpcUrl, 421614);
143
188
  ```
144
189
 
145
- ### From Keyfile
190
+ Supported chain IDs: `1` (Ethereum), `11155111` (Sepolia), `421614` (Arbitrum Sepolia), `42161` (Arbitrum), `8453` (Base).
146
191
 
147
- ```ts
148
- const account = createEvmWallet('~/.evm/keys/default.json');
149
- ```
192
+ ---
150
193
 
151
- **Keyfile format:**
152
- ```json
153
- {
154
- "privateKey": "abc123...64hexchars",
155
- "address": "0x..."
156
- }
157
- ```
194
+ ### Bridge Execution
195
+
196
+ #### `executeDeposit(params): Promise<BridgeResult>`
158
197
 
159
- ### Create EVM Executor
198
+ Executes an EVM → Fast deposit. For ERC-20 tokens, automatically submits an `approve` transaction if the current allowance is insufficient.
160
199
 
161
- EVM executor provides viem clients for blockchain operations:
200
+ > **Note:** `isNative` is only for native EVM assets (ETH). All ERC-20 tokens (including USDC, USDT, etc.) use `tokenAddress` and `isNative: false` (the default). Do not set `isNative: true` for ERC-20 tokens.
162
201
 
163
202
  ```ts
164
- import { createEvmExecutor } from '@fastxyz/allset-sdk/node';
165
-
166
- const evmClients = createEvmExecutor(
167
- account, // From createEvmWallet()
168
- 'https://sepolia-rollup.arbitrum.io/rpc', // RPC URL
169
- 421614 // Chain ID
170
- );
171
- // Returns { walletClient, publicClient }
203
+ interface ExecuteDepositParams {
204
+ chainId: number;
205
+ bridgeContract: `0x${string}`;
206
+ tokenAddress: `0x${string}`; // ERC-20 contract address (or zero address for native ETH when isNative=true)
207
+ isNative?: boolean; // true only for native ETH deposits; false (default) for all ERC-20 tokens
208
+ amount: string; // smallest units as string
209
+ senderAddress: string;
210
+ receiverAddress: string; // Fast bech32m address (fast1...)
211
+ evmClients: EvmClients;
212
+ }
172
213
  ```
173
214
 
174
- ### EVM Wallet Resolution
215
+ #### `executeWithdraw(params): Promise<BridgeResult>`
175
216
 
176
- `createEvmWallet(keyOrPath?)` resolves the parameter as:
177
- 1. Omitted → Generate new random wallet
178
- 2. Starts with `0x` or 64 hex chars → Derive from private key
179
- 3. Contains `/`, `~`, or ends with `.json` → Load from keyfile
180
-
181
- ### viem Interoperability
182
-
183
- `createEvmWallet()` returns a standard viem account (from `privateKeyToAccount`), so it's **fully interoperable**:
217
+ Executes a simple Fast → EVM token withdrawal. Automatically builds a `DynamicTransfer` intent for the given receiver address.
184
218
 
185
219
  ```ts
186
- import { privateKeyToAccount } from 'viem/accounts';
187
-
188
- // These are equivalent:
189
- const account1 = createEvmWallet('0xabc123...');
190
- const account2 = privateKeyToAccount('0xabc123...');
191
-
192
- // Both work with createEvmExecutor:
193
- createEvmExecutor(account1, rpcUrl, chainId);
194
- createEvmExecutor(account2, rpcUrl, chainId);
220
+ interface ExecuteWithdrawParams {
221
+ fastBridgeAddress: string;
222
+ relayerUrl: string;
223
+ crossSignUrl: string;
224
+ tokenEvmAddress: string;
225
+ tokenFastTokenId: string; // hex, no 0x prefix
226
+ amount: string;
227
+ receiverEvmAddress: string; // EVM address to receive tokens
228
+ deadlineSeconds?: number; // default: 3600
229
+ networkId: string; // 'fast:testnet' | 'fast:mainnet' | ...
230
+ signer: Signer; // from @fastxyz/sdk
231
+ provider: FastProvider; // from @fastxyz/sdk
232
+ }
195
233
  ```
196
234
 
197
- You can use existing viem accounts directly — no need to re-wrap them.
198
-
199
- ---
235
+ #### `executeIntent(params): Promise<BridgeResult>`
200
236
 
201
- ## Common Operations
237
+ Executes Fast → EVM bridge with custom intents. Internally:
202
238
 
203
- ### Deposit: EVM Fast
204
-
205
- Send tokens from an EVM chain to Fast network:
239
+ 1. Transfers tokens to the bridge on Fast network
240
+ 2. Cross-signs the transfer certificate
241
+ 3. Submits intent claim on Fast network
242
+ 4. Cross-signs the intent certificate
243
+ 5. Submits to the relayer for EVM execution
206
244
 
207
245
  ```ts
208
- await allset.sendToFast({
209
- chain: 'arbitrum-sepolia', // EVM chain
210
- token: 'USDC', // Token symbol
211
- amount: '1000000', // Amount in smallest units (6 decimals for USDC)
212
- from: evmAccount.address, // Sender EVM address
213
- to: fastWallet.address, // Receiver Fast address
214
- evmClients, // From createEvmExecutor()
215
- });
246
+ interface ExecuteIntentParams {
247
+ fastBridgeAddress: string;
248
+ relayerUrl: string;
249
+ crossSignUrl: string;
250
+ tokenEvmAddress: string;
251
+ tokenFastTokenId: string; // hex, no 0x prefix
252
+ amount: string;
253
+ intents: Intent[];
254
+ externalAddress?: string; // override EVM target (required for depositBack/revoke flows)
255
+ deadlineSeconds?: number; // default: 3600
256
+ networkId: string; // 'fast:testnet' | 'fast:mainnet' | ...
257
+ signer: Signer; // from @fastxyz/sdk
258
+ provider: FastProvider; // from @fastxyz/sdk
259
+ }
216
260
  ```
217
261
 
218
- ### Withdraw: Fast → EVM
262
+ #### `evmSign(certificate, crossSignUrl): Promise<EvmSignResult>`
219
263
 
220
- Send tokens from Fast network to an EVM chain:
264
+ Cross-signs a Fast network certificate with the AllSet cross-sign service.
265
+
266
+ ---
267
+
268
+ ### Intent Builders (Pure)
221
269
 
222
270
  ```ts
223
- await allset.sendToExternal({
224
- chain: 'arbitrum-sepolia', // Target EVM chain
225
- token: 'USDC', // Token symbol
226
- amount: '1000000', // Amount in smallest units
227
- from: fastWallet.address, // Sender Fast address
228
- to: evmAccount.address, // Receiver EVM address
229
- fastWallet, // From @fastxyz/sdk
230
- });
271
+ buildTransferIntent(tokenAddress, receiverEvmAddress): Intent
272
+ buildExecuteIntent(targetAddress, calldata, value?): Intent
273
+ buildDepositBackIntent(tokenAddress, fastReceiverAddress): Intent
274
+ buildRevokeIntent(): Intent
231
275
  ```
232
276
 
233
277
  ---
234
278
 
235
- ## Advanced: Custom Intents
279
+ ### Deposit Planning (Pure, Browser-Safe)
236
280
 
237
- Execute custom operations on EVM via intents:
281
+ #### `buildDepositTransaction(params): DepositTransactionPlan`
238
282
 
239
- ```ts
240
- import { buildTransferIntent, buildExecuteIntent } from '@fastxyz/allset-sdk';
283
+ Builds a deposit transaction without executing it. Useful for displaying, signing externally, or constructing in a browser.
241
284
 
242
- await allset.executeIntent({
243
- chain: 'arbitrum-sepolia',
244
- fastWallet,
245
- token: 'USDC',
246
- amount: '1000000',
247
- intents: [
248
- buildTransferIntent(USDC_ADDRESS, '0xRecipient'),
249
- buildExecuteIntent(CONTRACT_ADDRESS, calldata),
250
- ],
285
+ ```ts
286
+ const plan = buildDepositTransaction({
287
+ chainId: 421614,
288
+ bridgeContract: '0xb536...',
289
+ tokenAddress: '0x75fa...',
290
+ amount: 1000000n, // bigint
291
+ receiver: 'fast1abc...',
251
292
  });
293
+ // plan.to, plan.data, plan.value — pass to walletClient.sendTransaction()
252
294
  ```
253
295
 
254
- ### Intent Builders
296
+ #### `encodeDepositCalldata(params): Hex`
255
297
 
256
- | Builder | Purpose |
257
- |---------|---------|
258
- | `buildTransferIntent(token, receiver)` | ERC-20 transfer |
259
- | `buildExecuteIntent(target, calldata, value?)` | Generic contract call |
260
- | `buildDepositBackIntent(token, fastReceiver)` | Deposit back to Fast |
261
- | `buildRevokeIntent()` | Cancel pending intent |
298
+ Encodes only the calldata for a deposit call.
262
299
 
263
300
  ---
264
301
 
265
- ## Pure Helpers (Browser-Safe)
266
-
267
- Use for deposit planning without execution:
302
+ ### Address Utilities (Pure, Browser-Safe)
268
303
 
269
304
  ```ts
270
- import { buildDepositTransaction } from '@fastxyz/allset-sdk';
271
-
272
- const plan = buildDepositTransaction({
273
- network: 'testnet',
274
- chain: 'arbitrum-sepolia',
275
- token: 'USDC',
276
- amount: 1_000_000n,
277
- receiver: 'fast1receiveraddress...',
278
- });
279
-
280
- console.log(plan.to); // Bridge contract
281
- console.log(plan.data); // Calldata
282
- console.log(plan.value); // ETH value (usually 0n)
305
+ fastAddressToBytes32(address: string): Hex // bech32m 0x bytes32
306
+ fastAddressToBytes(address: string): Uint8Array // bech32m → Uint8Array
283
307
  ```
284
308
 
285
309
  ---
286
310
 
287
- ## Configuration
311
+ ### Error Handling
288
312
 
289
- ### Token Parameter
290
-
291
- The `token` field in `sendToFast`/`sendToExternal` accepts:
292
-
293
- | Format | Example |
294
- |--------|---------|
295
- | Symbol | `'USDC'` (mainnet), `'testUSDC'` (testnet) |
296
- | EVM Address | `'0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d'` |
297
-
298
- **Symbol aliases:** `testUSDC` normalizes to `USDC` for testnet chains.
313
+ ```ts
314
+ import { FastError, type FastErrorCode } from '@fastxyz/allset-sdk';
315
+
316
+ try {
317
+ await executeWithdraw({ ... });
318
+ } catch (err) {
319
+ if (err instanceof FastError) {
320
+ console.error(err.code); // 'TX_FAILED' | 'INVALID_ADDRESS' | 'INVALID_PARAMS'
321
+ console.error(err.message);
322
+ console.error(err.context);
323
+ }
324
+ }
325
+ ```
299
326
 
300
- ### Finding Supported Assets
327
+ ### Claims Encoding (Low-Level)
301
328
 
302
- Supported tokens are configured in [`src/default-config.ts`](./src/default-config.ts).
329
+ `claims.ts` provides standalone functions for encoding AllSet bridge claims. These are used internally by `executeIntent()` but can also be used directly for custom flows:
303
330
 
304
- **Testnet tokens:**
331
+ ```ts
332
+ import {
333
+ encodeTransferClaim,
334
+ hashTransferClaim,
335
+ encodeIntentClaim,
336
+ buildIntentClaimBytes,
337
+ extractClaimId,
338
+ type TransferClaimParams,
339
+ type IntentClaimParams,
340
+ } from '@fastxyz/allset-sdk';
341
+
342
+ // Encode a transfer claim for cross-signing
343
+ const claimBytes = encodeTransferClaim({
344
+ fastAddress: 'fast1sender...',
345
+ tokenFastTokenId: 'abc123...',
346
+ amount: '1000000',
347
+ recipientEvmAddress: '0xReceiver...',
348
+ bridgeAddress: 'fast1bridge...',
349
+ nonce: 0n,
350
+ timestamp: BigInt(Math.floor(Date.now() / 1000)),
351
+ });
305
352
 
306
- | Chain | Token | EVM Address |
307
- |-------|-------|-------------|
308
- | `arbitrum-sepolia` | USDC | `0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d` |
309
- | `ethereum-sepolia` | USDC | `0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238` |
353
+ // Hash a transfer claim
354
+ const claimHash = hashTransferClaim({ ... });
310
355
 
311
- **Mainnet tokens:**
356
+ // Encode an intent claim
357
+ const intentBytes = encodeIntentClaim({
358
+ externalAddress: '0xTarget...',
359
+ tokenEvmAddress: '0xUSDC...',
360
+ amount: '1000000',
361
+ fastAddress: 'fast1sender...',
362
+ transferClaimId: '0xabc...',
363
+ externalCallDeadline: BigInt(Math.floor(Date.now() / 1000) + 3600),
364
+ });
312
365
 
313
- | Chain | Token | EVM Address |
314
- |-------|-------|-------------|
315
- | `base` | USDC | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` |
316
- | `arbitrum` | USDC | `0xaf88d065e77c8cC2239327C5EDb3A432268e5831` |
366
+ // Extract the claim ID from cross-sign transaction output
367
+ const claimId = extractClaimId(crossSignTransaction); // Uint8Array
368
+ ```
317
369
 
318
- To add custom tokens, create `~/.allset/networks.json` with your token config.
370
+ ### Relay Submission (Low-Level)
319
371
 
320
- ### Config Files
372
+ `relay.ts` provides a standalone function for submitting to the AllSet relayer. Use this for step-by-step flows, retry logic, or when you want to separate relay submission from the rest of the bridge flow:
321
373
 
322
- ```
323
- ~/.allset/
324
- └── networks.json # Custom network config (overrides defaults)
374
+ ```ts
375
+ import { relayExecute, type RelayParams } from '@fastxyz/allset-sdk';
376
+
377
+ const result = await relayExecute({
378
+ relayerUrl: 'https://relayer.allset...',
379
+ encodedTransferClaim: [...], // from evmSign result
380
+ transferProof: '0x...', // EVM signature over the transfer claim
381
+ transferFastTxId: '0x...', // Fast network tx ID for the transfer
382
+ fastsetAddress: 'fast1bridge...',
383
+ externalAddress: '0xTarget...',
384
+ encodedIntentClaim: [...], // from evmSign result
385
+ intentProof: '0x...', // EVM signature over the intent claim
386
+ intentClaimId: '0xabc...',
387
+ });
325
388
 
326
- ~/.evm/
327
- └── keys/
328
- └── default.json # EVM wallet keyfiles
389
+ console.log(result.relayTxHash); // EVM transaction hash from the relayer
329
390
  ```
330
391
 
331
- ### Custom Network Config
332
-
333
- Create `~/.allset/networks.json` to override bundled defaults.
334
-
335
392
  ---
336
393
 
337
- ## API Reference
394
+ ## Types
338
395
 
339
- ### AllSetProvider Methods
396
+ ```ts
397
+ interface BridgeResult {
398
+ txHash: string;
399
+ orderId: string;
400
+ estimatedTime?: string;
401
+ }
340
402
 
341
- | Method | Description |
342
- |--------|-------------|
343
- | `sendToFast(params)` | Deposit EVM → Fast |
344
- | `sendToExternal(params)` | Withdraw Fast → EVM |
345
- | `executeIntent(params)` | Execute custom intents |
346
- | `getChainConfig(chain)` | Get chain configuration |
347
- | `getTokenConfig(chain, token)` | Get token configuration |
403
+ type FastErrorCode = 'TX_FAILED' | 'INVALID_ADDRESS' | 'INVALID_PARAMS' | 'CROSS_SIGN_FAILED' | 'RELAY_FAILED';
348
404
 
349
- ### Error Codes
405
+ class FastError extends Error {
406
+ readonly code: FastErrorCode;
407
+ readonly context?: Record<string, unknown>;
408
+ }
350
409
 
351
- | Code | Meaning |
352
- |------|---------|
353
- | `INVALID_PARAMS` | Missing required parameter |
354
- | `INVALID_ADDRESS` | Bad address format |
355
- | `TOKEN_NOT_FOUND` | Unknown token symbol |
356
- | `UNSUPPORTED_OPERATION` | Chain not supported |
357
- | `TX_FAILED` | Transaction rejected |
410
+ interface TransferClaimParams {
411
+ fastAddress: string;
412
+ tokenFastTokenId: string;
413
+ amount: string;
414
+ recipientEvmAddress: string;
415
+ bridgeAddress: string;
416
+ nonce: bigint;
417
+ timestamp: bigint;
418
+ }
358
419
 
359
- ---
420
+ interface IntentClaimParams {
421
+ externalAddress: string;
422
+ tokenEvmAddress: string;
423
+ amount: string;
424
+ fastAddress: string;
425
+ transferClaimId: string;
426
+ externalCallDeadline: bigint;
427
+ }
360
428
 
361
- ## Supported Networks
429
+ interface RelayParams {
430
+ relayerUrl: string;
431
+ encodedTransferClaim: number[];
432
+ transferProof: string;
433
+ transferFastTxId: string;
434
+ fastsetAddress: string;
435
+ externalAddress: string;
436
+ encodedIntentClaim: number[];
437
+ intentProof: string;
438
+ intentClaimId: string;
439
+ }
362
440
 
363
- | Network | Chain | Chain ID | Status |
364
- |---------|-------|----------|--------|
365
- | Testnet | Arbitrum Sepolia | 421614 | ✅ |
366
- | Testnet | Ethereum Sepolia | 11155111 | ✅ |
367
- | Testnet | Base | 8453 | ✅ |
368
- | Mainnet | Coming soon | — | 🔜 |
441
+ interface RelayResult {
442
+ relayTxHash: string;
443
+ }
444
+ ```
369
445
 
370
446
  ---
371
447
 
372
- ## Development
373
-
374
- ```bash
375
- npm install
376
- npm run build
377
- npm test
378
- ```
379
-
380
- See [SKILL.md](./SKILL.md) for detailed workflows.
448
+ ## Changelog
381
449
 
382
- ## License
450
+ **v0.x (current)**
383
451
 
384
- MIT
452
+ - `executeWithdraw()` — new convenience function for simple Fast → EVM withdrawals
453
+ - `executeIntent()` / `executeWithdraw()` now accept `signer`, `provider`, `networkId` from `@fastxyz/sdk` (replaces `FastWalletLike`)
454
+ - Added Ethereum mainnet (chainId 1) support
455
+ - Pure-function API — no `AllSetProvider`, no embedded config, no keyfile loading
456
+ - Single entrypoint `@fastxyz/allset-sdk` (no sub-path exports)
457
+ - All config values passed as explicit function parameters