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