@fastxyz/allset-sdk 0.1.0 → 0.1.2

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.
@@ -0,0 +1,128 @@
1
+ /**
2
+ * intents.ts — Intent builders for AllSet external execution
3
+ *
4
+ * Intents define what actions to perform on EVM chains after
5
+ * transferring tokens from Fast network.
6
+ */
7
+ import { encodeAbiParameters } from 'viem';
8
+ import { bech32m } from 'bech32';
9
+ // ---------------------------------------------------------------------------
10
+ // Types
11
+ // ---------------------------------------------------------------------------
12
+ /**
13
+ * Intent action types supported by AllSet bridge.
14
+ */
15
+ export var IntentAction;
16
+ (function (IntentAction) {
17
+ /** Generic contract call */
18
+ IntentAction[IntentAction["Execute"] = 0] = "Execute";
19
+ /** ERC-20 transfer to address */
20
+ IntentAction[IntentAction["DynamicTransfer"] = 1] = "DynamicTransfer";
21
+ /** Deposit tokens back to Fast network */
22
+ IntentAction[IntentAction["DynamicDeposit"] = 2] = "DynamicDeposit";
23
+ /** Cancel/revoke pending intent */
24
+ IntentAction[IntentAction["Revoke"] = 3] = "Revoke";
25
+ })(IntentAction || (IntentAction = {}));
26
+ // ---------------------------------------------------------------------------
27
+ // Helper Functions
28
+ // ---------------------------------------------------------------------------
29
+ function fastAddressToBytes32(address) {
30
+ const { words } = bech32m.decode(address, 90);
31
+ const bytes = new Uint8Array(bech32m.fromWords(words));
32
+ return `0x${Buffer.from(bytes).toString('hex')}`;
33
+ }
34
+ // ---------------------------------------------------------------------------
35
+ // Intent Builders
36
+ // ---------------------------------------------------------------------------
37
+ /**
38
+ * Build a transfer intent to send ERC-20 tokens to an address.
39
+ *
40
+ * @param token - ERC-20 token contract address
41
+ * @param receiver - Recipient EVM address
42
+ * @returns Intent for DynamicTransfer action
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const intent = buildTransferIntent(
47
+ * '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d', // USDC
48
+ * '0xRecipientAddress'
49
+ * );
50
+ * ```
51
+ */
52
+ export function buildTransferIntent(token, receiver) {
53
+ const payload = encodeAbiParameters([{ type: 'address' }, { type: 'address' }], [token, receiver]);
54
+ return {
55
+ action: IntentAction.DynamicTransfer,
56
+ payload,
57
+ value: 0n,
58
+ };
59
+ }
60
+ /**
61
+ * Build a generic execute intent for arbitrary contract calls.
62
+ *
63
+ * @param target - Target contract address
64
+ * @param calldata - ABI-encoded function call data
65
+ * @param value - Native token value to send (default: 0)
66
+ * @returns Intent for Execute action
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * // Call a contract function
71
+ * const calldata = encodeFunctionData({
72
+ * abi: contractAbi,
73
+ * functionName: 'someFunction',
74
+ * args: [arg1, arg2],
75
+ * });
76
+ * const intent = buildExecuteIntent('0xContractAddress', calldata);
77
+ * ```
78
+ */
79
+ export function buildExecuteIntent(target, calldata, value = 0n) {
80
+ const payload = encodeAbiParameters([{ type: 'address' }, { type: 'bytes' }], [target, calldata]);
81
+ return {
82
+ action: IntentAction.Execute,
83
+ payload,
84
+ value,
85
+ };
86
+ }
87
+ /**
88
+ * Build an intent to deposit tokens back to Fast network.
89
+ *
90
+ * @param token - ERC-20 token contract address on EVM
91
+ * @param fastReceiver - Fast network recipient address (fast1...)
92
+ * @returns Intent for DynamicDeposit action
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const intent = buildDepositBackIntent(
97
+ * '0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d', // USDC
98
+ * 'fast1recipientaddress...'
99
+ * );
100
+ * ```
101
+ */
102
+ export function buildDepositBackIntent(token, fastReceiver) {
103
+ const receiverBytes = fastAddressToBytes32(fastReceiver);
104
+ const payload = encodeAbiParameters([{ type: 'address' }, { type: 'bytes32' }], [token, receiverBytes]);
105
+ return {
106
+ action: IntentAction.DynamicDeposit,
107
+ payload,
108
+ value: 0n,
109
+ };
110
+ }
111
+ /**
112
+ * Build a revoke intent to cancel pending operations.
113
+ *
114
+ * @returns Intent for Revoke action
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const intent = buildRevokeIntent();
119
+ * ```
120
+ */
121
+ export function buildRevokeIntent() {
122
+ return {
123
+ action: IntentAction.Revoke,
124
+ payload: '0x',
125
+ value: 0n,
126
+ };
127
+ }
128
+ //# sourceMappingURL=intents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intents.js","sourceRoot":"","sources":["../src/intents.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,8EAA8E;AAC9E,QAAQ;AACR,8EAA8E;AAE9E;;GAEG;AACH,MAAM,CAAN,IAAY,YASX;AATD,WAAY,YAAY;IACtB,4BAA4B;IAC5B,qDAAW,CAAA;IACX,iCAAiC;IACjC,qEAAmB,CAAA;IACnB,0CAA0C;IAC1C,mEAAkB,CAAA;IAClB,mCAAmC;IACnC,mDAAU,CAAA;AACZ,CAAC,EATW,YAAY,KAAZ,YAAY,QASvB;AAcD,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,SAAS,oBAAoB,CAAC,OAAe;IAC3C,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IACvD,OAAO,KAAK,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAmB,CAAC;AACpE,CAAC;AAED,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,QAAgB;IACjE,MAAM,OAAO,GAAG,mBAAmB,CACjC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAC1C,CAAC,KAAsB,EAAE,QAAyB,CAAC,CACpD,CAAC;IACF,OAAO;QACL,MAAM,EAAE,YAAY,CAAC,eAAe;QACpC,OAAO;QACP,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,QAAgB,EAChB,QAAgB,EAAE;IAElB,MAAM,OAAO,GAAG,mBAAmB,CACjC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EACxC,CAAC,MAAuB,EAAE,QAAyB,CAAC,CACrD,CAAC;IACF,OAAO;QACL,MAAM,EAAE,YAAY,CAAC,OAAO;QAC5B,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAa,EACb,YAAoB;IAEpB,MAAM,aAAa,GAAG,oBAAoB,CAAC,YAAY,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,mBAAmB,CACjC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAC1C,CAAC,KAAsB,EAAE,aAAa,CAAC,CACxC,CAAC;IACF,OAAO;QACL,MAAM,EAAE,YAAY,CAAC,cAAc;QACnC,OAAO;QACP,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO;QACL,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * provider.ts — AllSetProvider for bridge configuration and operations
3
+ *
4
+ * Similar to FastProvider, AllSetProvider manages network configuration
5
+ * and provides the bridge() method for bridging tokens.
6
+ */
7
+ import type { NetworkConfig, ChainConfig, TokenConfig, AllNetworksConfig } from './config.js';
8
+ import type { BridgeResult, SendToFastParams, SendToExternalParams, ExecuteIntentParams } from './types.js';
9
+ export interface AllSetProviderOptions {
10
+ /**
11
+ * Network to use: 'testnet' or 'mainnet'
12
+ * @default 'testnet'
13
+ */
14
+ network?: 'testnet' | 'mainnet';
15
+ /**
16
+ * Custom path to networks.json config file.
17
+ * If not provided, loads from:
18
+ * 1. ~/.allset/networks.json (user override)
19
+ * 2. Bundled data/networks.json (package default)
20
+ */
21
+ configPath?: string;
22
+ /**
23
+ * Custom cross-sign URL (overrides config)
24
+ */
25
+ crossSignUrl?: string;
26
+ }
27
+ /**
28
+ * AllSetProvider manages AllSet bridge configuration.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // Default testnet configuration
33
+ * const provider = new AllSetProvider();
34
+ *
35
+ * // Mainnet configuration
36
+ * const provider = new AllSetProvider({ network: 'mainnet' });
37
+ *
38
+ * // Custom config file
39
+ * const provider = new AllSetProvider({ configPath: './my-config.json' });
40
+ *
41
+ * // Access configuration
42
+ * const chainConfig = provider.getChainConfig('arbitrum');
43
+ * const tokenConfig = provider.getTokenConfig('arbitrum', 'USDC');
44
+ * ```
45
+ */
46
+ export declare class AllSetProvider {
47
+ private readonly _network;
48
+ private readonly _config;
49
+ private readonly _networkConfig;
50
+ private readonly _crossSignUrl;
51
+ constructor(options?: AllSetProviderOptions);
52
+ /**
53
+ * Get the current network name.
54
+ */
55
+ get network(): 'testnet' | 'mainnet';
56
+ /**
57
+ * Get the cross-sign service URL.
58
+ */
59
+ get crossSignUrl(): string;
60
+ /**
61
+ * Get list of supported chain names.
62
+ */
63
+ get chains(): string[];
64
+ /**
65
+ * Get configuration for a specific chain.
66
+ */
67
+ getChainConfig(chain: string): ChainConfig | null;
68
+ /**
69
+ * Get token configuration for a chain.
70
+ * Handles fastUSDC -> USDC normalization.
71
+ */
72
+ getTokenConfig(chain: string, token: string): TokenConfig | null;
73
+ /**
74
+ * Get the full network configuration.
75
+ */
76
+ getNetworkConfig(): NetworkConfig;
77
+ /**
78
+ * Get the raw config (both testnet and mainnet).
79
+ */
80
+ getRawConfig(): AllNetworksConfig;
81
+ /**
82
+ * Deposit tokens from EVM chain to Fast network.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const result = await allset.sendToFast({
87
+ * chain: 'arbitrum',
88
+ * token: 'USDC',
89
+ * amount: '1000000',
90
+ * from: '0xYourEvmAddress',
91
+ * to: 'fast1receiveraddress',
92
+ * evmExecutor,
93
+ * });
94
+ * ```
95
+ */
96
+ sendToFast(params: SendToFastParams): Promise<BridgeResult>;
97
+ /**
98
+ * Withdraw tokens from Fast network to EVM chain.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const result = await allset.sendToExternal({
103
+ * chain: 'arbitrum',
104
+ * token: 'fastUSDC',
105
+ * amount: '1000000',
106
+ * from: fastWallet.address,
107
+ * to: '0xReceiverEvmAddress',
108
+ * fastWallet,
109
+ * });
110
+ * ```
111
+ */
112
+ sendToExternal(params: SendToExternalParams): Promise<BridgeResult>;
113
+ /**
114
+ * Execute custom intents on an EVM chain.
115
+ *
116
+ * This is the advanced API for composing custom operations like swaps,
117
+ * multi-step transactions, or protocol integrations.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * import { buildTransferIntent, buildExecuteIntent } from '@fastxyz/allset-sdk';
122
+ *
123
+ * // Simple transfer
124
+ * const result = await allset.executeIntent({
125
+ * chain: 'arbitrum',
126
+ * fastWallet,
127
+ * token: 'fastUSDC',
128
+ * amount: '1000000',
129
+ * intents: [buildTransferIntent(USDC_ADDRESS, '0xRecipient')],
130
+ * });
131
+ *
132
+ * // Custom contract call
133
+ * const result = await allset.executeIntent({
134
+ * chain: 'arbitrum',
135
+ * fastWallet,
136
+ * token: 'fastUSDC',
137
+ * amount: '1000000',
138
+ * intents: [buildExecuteIntent(CONTRACT, calldata)],
139
+ * externalAddress: CONTRACT,
140
+ * });
141
+ * ```
142
+ */
143
+ executeIntent(params: ExecuteIntentParams): Promise<BridgeResult>;
144
+ }
145
+ /**
146
+ * Get the AllSet home directory (~/.allset).
147
+ */
148
+ export declare function getAllSetDir(): string;
149
+ /**
150
+ * Get the EVM keys directory (~/.allset/.evm/keys).
151
+ */
152
+ export declare function getEvmKeysDir(): string;
153
+ /**
154
+ * Ensure the AllSet directory structure exists.
155
+ */
156
+ export declare function ensureAllSetDirs(): void;
157
+ /**
158
+ * Initialize user config by copying bundled networks.json to ~/.allset/.
159
+ * Does nothing if user config already exists.
160
+ */
161
+ export declare function initUserConfig(): string;
162
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAa5G,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAEhC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAqDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,OAAO,GAAE,qBAA0B;IAY/C;;OAEG;IACH,IAAI,OAAO,IAAI,SAAS,GAAG,SAAS,CAEnC;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAIjD;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAchE;;OAEG;IACH,gBAAgB,IAAI,aAAa;IAIjC;;OAEG;IACH,YAAY,IAAI,iBAAiB;IAIjC;;;;;;;;;;;;;;OAcG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC;IAejE;;;;;;;;;;;;;;OAcG;IACG,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,YAAY,CAAC;IAezE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;CAKxE;AAMD;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAOvC;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAevC"}
@@ -0,0 +1,276 @@
1
+ /**
2
+ * provider.ts — AllSetProvider for bridge configuration and operations
3
+ *
4
+ * Similar to FastProvider, AllSetProvider manages network configuration
5
+ * and provides the bridge() method for bridging tokens.
6
+ */
7
+ import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
8
+ import { dirname, join } from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ // ---------------------------------------------------------------------------
11
+ // Constants
12
+ // ---------------------------------------------------------------------------
13
+ const ALLSET_DIR = join(process.env.HOME || process.env.USERPROFILE || '', '.allset');
14
+ const EVM_KEYS_DIR = join(ALLSET_DIR, '.evm', 'keys');
15
+ // ---------------------------------------------------------------------------
16
+ // Helper Functions
17
+ // ---------------------------------------------------------------------------
18
+ function expandHome(path) {
19
+ if (path.startsWith('~/')) {
20
+ const home = process.env.HOME || process.env.USERPROFILE || '';
21
+ return path.replace('~', home);
22
+ }
23
+ return path;
24
+ }
25
+ function getPackageDataDir() {
26
+ const __filename = fileURLToPath(import.meta.url);
27
+ const __dirname = dirname(__filename);
28
+ return join(__dirname, '..', 'data');
29
+ }
30
+ function getUserConfigPath() {
31
+ return join(ALLSET_DIR, 'networks.json');
32
+ }
33
+ function loadConfig(customPath) {
34
+ // Priority: customPath > ~/.allset/networks.json > bundled data/networks.json
35
+ const paths = [
36
+ customPath,
37
+ getUserConfigPath(),
38
+ join(getPackageDataDir(), 'networks.json'),
39
+ ].filter((p) => !!p);
40
+ for (const configPath of paths) {
41
+ const resolved = expandHome(configPath);
42
+ if (existsSync(resolved)) {
43
+ try {
44
+ const raw = readFileSync(resolved, 'utf-8');
45
+ return JSON.parse(raw);
46
+ }
47
+ catch {
48
+ // Continue to next path
49
+ }
50
+ }
51
+ }
52
+ throw new Error('Failed to load AllSet networks config. Ensure data/networks.json exists in the package.');
53
+ }
54
+ // ---------------------------------------------------------------------------
55
+ // AllSetProvider Class
56
+ // ---------------------------------------------------------------------------
57
+ /**
58
+ * AllSetProvider manages AllSet bridge configuration.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * // Default testnet configuration
63
+ * const provider = new AllSetProvider();
64
+ *
65
+ * // Mainnet configuration
66
+ * const provider = new AllSetProvider({ network: 'mainnet' });
67
+ *
68
+ * // Custom config file
69
+ * const provider = new AllSetProvider({ configPath: './my-config.json' });
70
+ *
71
+ * // Access configuration
72
+ * const chainConfig = provider.getChainConfig('arbitrum');
73
+ * const tokenConfig = provider.getTokenConfig('arbitrum', 'USDC');
74
+ * ```
75
+ */
76
+ export class AllSetProvider {
77
+ _network;
78
+ _config;
79
+ _networkConfig;
80
+ _crossSignUrl;
81
+ constructor(options = {}) {
82
+ this._network = options.network ?? 'testnet';
83
+ this._config = loadConfig(options.configPath);
84
+ this._networkConfig = this._config[this._network];
85
+ if (!this._networkConfig) {
86
+ throw new Error(`Network "${this._network}" not found in config`);
87
+ }
88
+ this._crossSignUrl = options.crossSignUrl ?? this._networkConfig.crossSignUrl;
89
+ }
90
+ /**
91
+ * Get the current network name.
92
+ */
93
+ get network() {
94
+ return this._network;
95
+ }
96
+ /**
97
+ * Get the cross-sign service URL.
98
+ */
99
+ get crossSignUrl() {
100
+ return this._crossSignUrl;
101
+ }
102
+ /**
103
+ * Get list of supported chain names.
104
+ */
105
+ get chains() {
106
+ return Object.keys(this._networkConfig.chains);
107
+ }
108
+ /**
109
+ * Get configuration for a specific chain.
110
+ */
111
+ getChainConfig(chain) {
112
+ return this._networkConfig.chains[chain] ?? null;
113
+ }
114
+ /**
115
+ * Get token configuration for a chain.
116
+ * Handles fastUSDC -> USDC normalization.
117
+ */
118
+ getTokenConfig(chain, token) {
119
+ const chainConfig = this.getChainConfig(chain);
120
+ if (!chainConfig)
121
+ return null;
122
+ // Normalize: fastUSDC on Fast maps to USDC on EVM
123
+ const normalizedToken = token.toLowerCase() === 'fastusdc' ? 'USDC' : token;
124
+ return (chainConfig.tokens[normalizedToken] ??
125
+ chainConfig.tokens[normalizedToken.toUpperCase()] ??
126
+ null);
127
+ }
128
+ /**
129
+ * Get the full network configuration.
130
+ */
131
+ getNetworkConfig() {
132
+ return this._networkConfig;
133
+ }
134
+ /**
135
+ * Get the raw config (both testnet and mainnet).
136
+ */
137
+ getRawConfig() {
138
+ return this._config;
139
+ }
140
+ /**
141
+ * Deposit tokens from EVM chain to Fast network.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const result = await allset.sendToFast({
146
+ * chain: 'arbitrum',
147
+ * token: 'USDC',
148
+ * amount: '1000000',
149
+ * from: '0xYourEvmAddress',
150
+ * to: 'fast1receiveraddress',
151
+ * evmExecutor,
152
+ * });
153
+ * ```
154
+ */
155
+ async sendToFast(params) {
156
+ const { executeBridge } = await import('./bridge.js');
157
+ return executeBridge({
158
+ fromChain: params.chain,
159
+ toChain: 'fast',
160
+ fromToken: params.token,
161
+ toToken: params.token === 'USDC' ? 'fastUSDC' : params.token,
162
+ fromDecimals: 6,
163
+ amount: params.amount,
164
+ senderAddress: params.from,
165
+ receiverAddress: params.to,
166
+ evmExecutor: params.evmExecutor,
167
+ }, this);
168
+ }
169
+ /**
170
+ * Withdraw tokens from Fast network to EVM chain.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * const result = await allset.sendToExternal({
175
+ * chain: 'arbitrum',
176
+ * token: 'fastUSDC',
177
+ * amount: '1000000',
178
+ * from: fastWallet.address,
179
+ * to: '0xReceiverEvmAddress',
180
+ * fastWallet,
181
+ * });
182
+ * ```
183
+ */
184
+ async sendToExternal(params) {
185
+ const { executeBridge } = await import('./bridge.js');
186
+ return executeBridge({
187
+ fromChain: 'fast',
188
+ toChain: params.chain,
189
+ fromToken: params.token,
190
+ toToken: params.token === 'fastUSDC' ? 'USDC' : params.token,
191
+ fromDecimals: 6,
192
+ amount: params.amount,
193
+ senderAddress: params.from,
194
+ receiverAddress: params.to,
195
+ fastWallet: params.fastWallet,
196
+ }, this);
197
+ }
198
+ /**
199
+ * Execute custom intents on an EVM chain.
200
+ *
201
+ * This is the advanced API for composing custom operations like swaps,
202
+ * multi-step transactions, or protocol integrations.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * import { buildTransferIntent, buildExecuteIntent } from '@fastxyz/allset-sdk';
207
+ *
208
+ * // Simple transfer
209
+ * const result = await allset.executeIntent({
210
+ * chain: 'arbitrum',
211
+ * fastWallet,
212
+ * token: 'fastUSDC',
213
+ * amount: '1000000',
214
+ * intents: [buildTransferIntent(USDC_ADDRESS, '0xRecipient')],
215
+ * });
216
+ *
217
+ * // Custom contract call
218
+ * const result = await allset.executeIntent({
219
+ * chain: 'arbitrum',
220
+ * fastWallet,
221
+ * token: 'fastUSDC',
222
+ * amount: '1000000',
223
+ * intents: [buildExecuteIntent(CONTRACT, calldata)],
224
+ * externalAddress: CONTRACT,
225
+ * });
226
+ * ```
227
+ */
228
+ async executeIntent(params) {
229
+ const { executeIntent: execIntent } = await import('./bridge.js');
230
+ return execIntent(params, this);
231
+ }
232
+ }
233
+ // ---------------------------------------------------------------------------
234
+ // Directory Utilities
235
+ // ---------------------------------------------------------------------------
236
+ /**
237
+ * Get the AllSet home directory (~/.allset).
238
+ */
239
+ export function getAllSetDir() {
240
+ return ALLSET_DIR;
241
+ }
242
+ /**
243
+ * Get the EVM keys directory (~/.allset/.evm/keys).
244
+ */
245
+ export function getEvmKeysDir() {
246
+ return EVM_KEYS_DIR;
247
+ }
248
+ /**
249
+ * Ensure the AllSet directory structure exists.
250
+ */
251
+ export function ensureAllSetDirs() {
252
+ if (!existsSync(ALLSET_DIR)) {
253
+ mkdirSync(ALLSET_DIR, { recursive: true, mode: 0o700 });
254
+ }
255
+ if (!existsSync(EVM_KEYS_DIR)) {
256
+ mkdirSync(EVM_KEYS_DIR, { recursive: true, mode: 0o700 });
257
+ }
258
+ }
259
+ /**
260
+ * Initialize user config by copying bundled networks.json to ~/.allset/.
261
+ * Does nothing if user config already exists.
262
+ */
263
+ export function initUserConfig() {
264
+ ensureAllSetDirs();
265
+ const userConfigPath = getUserConfigPath();
266
+ if (existsSync(userConfigPath)) {
267
+ return userConfigPath;
268
+ }
269
+ const bundledPath = join(getPackageDataDir(), 'networks.json');
270
+ if (existsSync(bundledPath)) {
271
+ const content = readFileSync(bundledPath, 'utf-8');
272
+ writeFileSync(userConfigPath, content, { mode: 0o600 });
273
+ }
274
+ return userConfigPath;
275
+ }
276
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,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