@sodax/sdk 0.0.1-rc.30 → 0.0.1-rc.32
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 +1 -0
- package/dist/index.cjs +1841 -1019
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +693 -73
- package/dist/index.d.ts +693 -73
- package/dist/index.mjs +1831 -1021
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getAbiItem, encodeAbiParameters, parseAbiParameters, fromHex, createPublicClient, http, toHex, erc20Abi as erc20Abi$1, encodeFunctionData, decodeAbiParameters, encodePacked, parseEventLogs, keccak256, isAddress } from 'viem';
|
|
2
2
|
import { nibiru, polygon, bsc, optimism, base, arbitrum, avalanche, sonic } from 'viem/chains';
|
|
3
|
-
import { SPOKE_CHAIN_IDS, ICON_MAINNET_CHAIN_ID, SUI_MAINNET_CHAIN_ID, STELLAR_MAINNET_CHAIN_ID, INJECTIVE_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, NIBIRU_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, SOLANA_MAINNET_CHAIN_ID
|
|
3
|
+
import { SONIC_MAINNET_CHAIN_ID, SPOKE_CHAIN_IDS, ICON_MAINNET_CHAIN_ID, SUI_MAINNET_CHAIN_ID, STELLAR_MAINNET_CHAIN_ID, INJECTIVE_MAINNET_CHAIN_ID, POLYGON_MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, BASE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, NIBIRU_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, SOLANA_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
4
4
|
export * from '@sodax/types';
|
|
5
|
-
import { ChainGrpcWasmApi, TxGrpcApi, toBase64 } from '@injectivelabs/sdk-ts';
|
|
5
|
+
import { ChainGrpcWasmApi, TxGrpcApi, toBase64, fromBase64 } from '@injectivelabs/sdk-ts';
|
|
6
6
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
7
7
|
import * as IconSdkRaw from 'icon-sdk-js';
|
|
8
8
|
import { SorobanRpc, Horizon, Contract, TransactionBuilder, BASE_FEE, nativeToScVal, TimeoutInfinite, rpc, scValToBigInt, Operation, Address, Account, FeeBumpTransaction } from '@stellar/stellar-sdk';
|
|
@@ -15,7 +15,7 @@ import * as rlp from 'rlp';
|
|
|
15
15
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
16
16
|
import * as anchor from '@coral-xyz/anchor';
|
|
17
17
|
import BN from 'bn.js';
|
|
18
|
-
import
|
|
18
|
+
import invariant12 from 'tiny-invariant';
|
|
19
19
|
import BigNumber4, { BigNumber } from 'bignumber.js';
|
|
20
20
|
|
|
21
21
|
// src/abis/asset-manager.abi.ts
|
|
@@ -6105,7 +6105,7 @@ async function waitForTransactionReceipt(hash, provider) {
|
|
|
6105
6105
|
return provider.waitForTransactionReceipt(hash);
|
|
6106
6106
|
}
|
|
6107
6107
|
var DEFAULT_MAX_RETRY = 3;
|
|
6108
|
-
var DEFAULT_RELAY_TX_TIMEOUT =
|
|
6108
|
+
var DEFAULT_RELAY_TX_TIMEOUT = 12e4;
|
|
6109
6109
|
var DEFAULT_RETRY_DELAY_MS = 2e3;
|
|
6110
6110
|
var ICON_TX_RESULT_WAIT_MAX_RETRY = 10;
|
|
6111
6111
|
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
@@ -6187,6 +6187,155 @@ function getEvmViemChain(id) {
|
|
|
6187
6187
|
throw new Error(`Unsupported EVM chain ID: ${id}`);
|
|
6188
6188
|
}
|
|
6189
6189
|
}
|
|
6190
|
+
var HubVaultSymbols = [
|
|
6191
|
+
"sodaAVAX",
|
|
6192
|
+
"sodaBNB",
|
|
6193
|
+
"sodaETH",
|
|
6194
|
+
"sodaBTC",
|
|
6195
|
+
"sodaSUI",
|
|
6196
|
+
"sodaINJ",
|
|
6197
|
+
"sodaXLM",
|
|
6198
|
+
"sodaSOL",
|
|
6199
|
+
"sodaSODA",
|
|
6200
|
+
"sodaUSDT",
|
|
6201
|
+
"sodaUSDC",
|
|
6202
|
+
"bnUSD",
|
|
6203
|
+
"sodaPOL",
|
|
6204
|
+
"sodaNIBI",
|
|
6205
|
+
"sodaS",
|
|
6206
|
+
"IbnUSD"
|
|
6207
|
+
];
|
|
6208
|
+
var SodaTokens = {
|
|
6209
|
+
sodaBNB: {
|
|
6210
|
+
symbol: "sodaBNB",
|
|
6211
|
+
name: "Soda BNB",
|
|
6212
|
+
decimals: 18,
|
|
6213
|
+
address: "0x40Cd41b35DB9e5109ae7E54b44De8625dB320E6b",
|
|
6214
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6215
|
+
},
|
|
6216
|
+
sodaAVAX: {
|
|
6217
|
+
symbol: "sodaAVAX",
|
|
6218
|
+
name: "Soda AVAX",
|
|
6219
|
+
decimals: 18,
|
|
6220
|
+
address: "0x14238D267557E9d799016ad635B53CD15935d290",
|
|
6221
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6222
|
+
},
|
|
6223
|
+
sodaETH: {
|
|
6224
|
+
symbol: "sodaETH",
|
|
6225
|
+
name: "Soda ETH",
|
|
6226
|
+
decimals: 18,
|
|
6227
|
+
address: "0x4effB5813271699683C25c734F4daBc45B363709",
|
|
6228
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6229
|
+
},
|
|
6230
|
+
sodaBTC: {
|
|
6231
|
+
symbol: "sodaBTC",
|
|
6232
|
+
name: "Soda BTC",
|
|
6233
|
+
decimals: 18,
|
|
6234
|
+
address: "0x7A1A5555842Ad2D0eD274d09b5c4406a95799D5d",
|
|
6235
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6236
|
+
},
|
|
6237
|
+
sodaSOL: {
|
|
6238
|
+
symbol: "sodaSOL",
|
|
6239
|
+
name: "Soda SOL",
|
|
6240
|
+
decimals: 18,
|
|
6241
|
+
address: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87",
|
|
6242
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6243
|
+
},
|
|
6244
|
+
sodaXLM: {
|
|
6245
|
+
symbol: "sodaXLM",
|
|
6246
|
+
name: "Soda XLM",
|
|
6247
|
+
decimals: 18,
|
|
6248
|
+
address: "0x6BC8C37cba91F76E68C9e6d689A9C21E4d32079B",
|
|
6249
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6250
|
+
},
|
|
6251
|
+
sodaINJ: {
|
|
6252
|
+
symbol: "sodaINJ",
|
|
6253
|
+
name: "Soda INJ",
|
|
6254
|
+
decimals: 18,
|
|
6255
|
+
address: "0x1f22279C89B213944b7Ea41daCB0a868DdCDFd13",
|
|
6256
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6257
|
+
},
|
|
6258
|
+
sodaNIBI: {
|
|
6259
|
+
symbol: "sodaNIBI",
|
|
6260
|
+
name: "Soda NIBI",
|
|
6261
|
+
decimals: 18,
|
|
6262
|
+
address: "0xc6c85287a8b173A509C2F198bB719A8a5a2d0C68",
|
|
6263
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6264
|
+
},
|
|
6265
|
+
sodaSUI: {
|
|
6266
|
+
symbol: "sodaSUI",
|
|
6267
|
+
name: "Soda SUI",
|
|
6268
|
+
decimals: 18,
|
|
6269
|
+
address: "0xdc5B4b00F98347E95b9F94911213DAB4C687e1e3",
|
|
6270
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6271
|
+
},
|
|
6272
|
+
bnUSD: {
|
|
6273
|
+
symbol: "bnUSD",
|
|
6274
|
+
name: "Balanced Dollar",
|
|
6275
|
+
decimals: 18,
|
|
6276
|
+
address: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131",
|
|
6277
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6278
|
+
},
|
|
6279
|
+
sodaUSDC: {
|
|
6280
|
+
symbol: "sodaUSDC",
|
|
6281
|
+
name: "Soda USDC",
|
|
6282
|
+
decimals: 18,
|
|
6283
|
+
address: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833",
|
|
6284
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6285
|
+
},
|
|
6286
|
+
sodaUSDT: {
|
|
6287
|
+
symbol: "sodaUSDT",
|
|
6288
|
+
name: "Soda USDT",
|
|
6289
|
+
decimals: 18,
|
|
6290
|
+
address: "0xbDf1F453FCB61424011BBDDCB96cFDB30f3Fe876",
|
|
6291
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6292
|
+
},
|
|
6293
|
+
IbnUSD: {
|
|
6294
|
+
symbol: "IbnUSD",
|
|
6295
|
+
name: "ICON bnUSD (Migration)",
|
|
6296
|
+
decimals: 18,
|
|
6297
|
+
address: "0x9D4b663Eb075d2a1C7B8eaEFB9eCCC0510388B51",
|
|
6298
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6299
|
+
},
|
|
6300
|
+
sodaS: {
|
|
6301
|
+
symbol: "sodaS",
|
|
6302
|
+
name: "Soda S",
|
|
6303
|
+
decimals: 18,
|
|
6304
|
+
address: "0x62ecc3Eeb80a162c57624B3fF80313FE69f5203e",
|
|
6305
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6306
|
+
},
|
|
6307
|
+
sodaPOL: {
|
|
6308
|
+
symbol: "sodaPOL",
|
|
6309
|
+
name: "Soda POL",
|
|
6310
|
+
decimals: 18,
|
|
6311
|
+
address: "0x208ED38f4783328aA9eBFeC360D32e7520A9B779",
|
|
6312
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6313
|
+
},
|
|
6314
|
+
sodaSODA: {
|
|
6315
|
+
symbol: "sodaSODA",
|
|
6316
|
+
name: "Soda SODA",
|
|
6317
|
+
decimals: 18,
|
|
6318
|
+
address: "0x21685E341DE7844135329914Be6Bd8D16982d834",
|
|
6319
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6320
|
+
}
|
|
6321
|
+
};
|
|
6322
|
+
var SodaTokensAsHubAssets = Object.values(SodaTokens).reduce(
|
|
6323
|
+
(acc, token) => {
|
|
6324
|
+
acc[token.address] = {
|
|
6325
|
+
asset: token.address,
|
|
6326
|
+
decimal: token.decimals,
|
|
6327
|
+
symbol: token.symbol,
|
|
6328
|
+
name: token.name,
|
|
6329
|
+
vault: token.address
|
|
6330
|
+
};
|
|
6331
|
+
return acc;
|
|
6332
|
+
},
|
|
6333
|
+
{}
|
|
6334
|
+
);
|
|
6335
|
+
var SodaVaultTokensSet = new Set(Object.values(SodaTokens).map((token) => token.address.toLowerCase()));
|
|
6336
|
+
var isSodaVaultToken = (address) => {
|
|
6337
|
+
return SodaVaultTokensSet.has(address.toLowerCase());
|
|
6338
|
+
};
|
|
6190
6339
|
var hubChainConfig = {
|
|
6191
6340
|
[SONIC_MAINNET_CHAIN_ID]: {
|
|
6192
6341
|
chain: {
|
|
@@ -6226,44 +6375,45 @@ var spokeChainConfig = {
|
|
|
6226
6375
|
symbol: "S",
|
|
6227
6376
|
name: "Sonic",
|
|
6228
6377
|
decimals: 18,
|
|
6229
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6230
|
-
|
|
6231
|
-
bnUSD: {
|
|
6232
|
-
symbol: "bnUSD",
|
|
6233
|
-
name: "bnUSD",
|
|
6234
|
-
decimals: 18,
|
|
6235
|
-
address: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
6378
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6379
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6236
6380
|
},
|
|
6237
6381
|
WETH: {
|
|
6238
6382
|
symbol: "WETH",
|
|
6239
6383
|
name: "Wrapped Ether",
|
|
6240
6384
|
decimals: 18,
|
|
6241
|
-
address: "0x50c42dEAcD8Fc9773493ED674b675bE577f2634b"
|
|
6385
|
+
address: "0x50c42dEAcD8Fc9773493ED674b675bE577f2634b",
|
|
6386
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6242
6387
|
},
|
|
6243
6388
|
USDC: {
|
|
6244
6389
|
symbol: "USDC",
|
|
6245
6390
|
name: "USD Coin",
|
|
6246
6391
|
decimals: 6,
|
|
6247
|
-
address: "0x29219dd400f2Bf60E5a23d13Be72B486D4038894"
|
|
6392
|
+
address: "0x29219dd400f2Bf60E5a23d13Be72B486D4038894",
|
|
6393
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6248
6394
|
},
|
|
6249
6395
|
USDT: {
|
|
6250
6396
|
symbol: "USDT",
|
|
6251
6397
|
name: "Tether USD",
|
|
6252
6398
|
decimals: 6,
|
|
6253
|
-
address: "0x6047828dc181963ba44974801FF68e538dA5eaF9"
|
|
6399
|
+
address: "0x6047828dc181963ba44974801FF68e538dA5eaF9",
|
|
6400
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6254
6401
|
},
|
|
6255
6402
|
wS: {
|
|
6256
6403
|
symbol: "wS",
|
|
6257
6404
|
name: "Wrapped Sonic",
|
|
6258
6405
|
decimals: 18,
|
|
6259
|
-
address: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
6406
|
+
address: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38",
|
|
6407
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6260
6408
|
},
|
|
6261
6409
|
SODA: {
|
|
6262
6410
|
symbol: "SODA",
|
|
6263
6411
|
name: "SODAX",
|
|
6264
6412
|
decimals: 18,
|
|
6265
|
-
address: "0x7c7d53EEcda37a87ce0D5bf8E0b24512A48dC963"
|
|
6266
|
-
|
|
6413
|
+
address: "0x7c7d53EEcda37a87ce0D5bf8E0b24512A48dC963",
|
|
6414
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
6415
|
+
},
|
|
6416
|
+
...SodaTokens
|
|
6267
6417
|
}
|
|
6268
6418
|
},
|
|
6269
6419
|
[SOLANA_MAINNET_CHAIN_ID]: {
|
|
@@ -6282,19 +6432,22 @@ var spokeChainConfig = {
|
|
|
6282
6432
|
symbol: "SOL",
|
|
6283
6433
|
name: "Solana",
|
|
6284
6434
|
decimals: 9,
|
|
6285
|
-
address: "11111111111111111111111111111111"
|
|
6435
|
+
address: "11111111111111111111111111111111",
|
|
6436
|
+
xChainId: SOLANA_MAINNET_CHAIN_ID
|
|
6286
6437
|
},
|
|
6287
6438
|
bnUSD: {
|
|
6288
6439
|
symbol: "bnUSD",
|
|
6289
6440
|
name: "bnUSD",
|
|
6290
6441
|
decimals: 9,
|
|
6291
|
-
address: "3rSPCLNEF7Quw4wX8S1NyKivELoyij8eYA2gJwBgt4V5"
|
|
6442
|
+
address: "3rSPCLNEF7Quw4wX8S1NyKivELoyij8eYA2gJwBgt4V5",
|
|
6443
|
+
xChainId: SOLANA_MAINNET_CHAIN_ID
|
|
6292
6444
|
},
|
|
6293
6445
|
USDC: {
|
|
6294
6446
|
symbol: "USDC",
|
|
6295
6447
|
name: "USD Coin",
|
|
6296
6448
|
decimals: 6,
|
|
6297
|
-
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
6449
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
6450
|
+
xChainId: SOLANA_MAINNET_CHAIN_ID
|
|
6298
6451
|
}
|
|
6299
6452
|
},
|
|
6300
6453
|
gasPrice: "500000",
|
|
@@ -6318,25 +6471,29 @@ var spokeChainConfig = {
|
|
|
6318
6471
|
symbol: "AVAX",
|
|
6319
6472
|
name: "Avalanche",
|
|
6320
6473
|
decimals: 18,
|
|
6321
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6474
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6475
|
+
xChainId: AVALANCHE_MAINNET_CHAIN_ID
|
|
6322
6476
|
},
|
|
6323
6477
|
bnUSD: {
|
|
6324
6478
|
symbol: "bnUSD",
|
|
6325
6479
|
name: "bnUSD",
|
|
6326
6480
|
decimals: 18,
|
|
6327
|
-
address: "0x6958a4CBFe11406E2a1c1d3a71A1971aD8B3b92F"
|
|
6481
|
+
address: "0x6958a4CBFe11406E2a1c1d3a71A1971aD8B3b92F",
|
|
6482
|
+
xChainId: AVALANCHE_MAINNET_CHAIN_ID
|
|
6328
6483
|
},
|
|
6329
6484
|
USDT: {
|
|
6330
6485
|
symbol: "USDT",
|
|
6331
6486
|
name: "Tether USD",
|
|
6332
6487
|
decimals: 6,
|
|
6333
|
-
address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7"
|
|
6488
|
+
address: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
|
|
6489
|
+
xChainId: AVALANCHE_MAINNET_CHAIN_ID
|
|
6334
6490
|
},
|
|
6335
6491
|
USDC: {
|
|
6336
6492
|
symbol: "USDC",
|
|
6337
6493
|
name: "USD Coin",
|
|
6338
6494
|
decimals: 6,
|
|
6339
|
-
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E"
|
|
6495
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
6496
|
+
xChainId: AVALANCHE_MAINNET_CHAIN_ID
|
|
6340
6497
|
}
|
|
6341
6498
|
}
|
|
6342
6499
|
},
|
|
@@ -6357,13 +6514,15 @@ var spokeChainConfig = {
|
|
|
6357
6514
|
symbol: "NIBI",
|
|
6358
6515
|
name: "Nibiru",
|
|
6359
6516
|
decimals: 6,
|
|
6360
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6517
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6518
|
+
xChainId: NIBIRU_MAINNET_CHAIN_ID
|
|
6361
6519
|
},
|
|
6362
6520
|
bnUSD: {
|
|
6363
6521
|
symbol: "bnUSD",
|
|
6364
6522
|
name: "bnUSD",
|
|
6365
6523
|
decimals: 18,
|
|
6366
|
-
address: "0x043fb7e23350Dd5b77dE5E228B528763DEcb9131"
|
|
6524
|
+
address: "0x043fb7e23350Dd5b77dE5E228B528763DEcb9131",
|
|
6525
|
+
xChainId: NIBIRU_MAINNET_CHAIN_ID
|
|
6367
6526
|
}
|
|
6368
6527
|
}
|
|
6369
6528
|
},
|
|
@@ -6384,49 +6543,57 @@ var spokeChainConfig = {
|
|
|
6384
6543
|
symbol: "ETH",
|
|
6385
6544
|
name: "Ethereum",
|
|
6386
6545
|
decimals: 18,
|
|
6387
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6546
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6547
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6388
6548
|
},
|
|
6389
6549
|
bnUSD: {
|
|
6390
6550
|
symbol: "bnUSD",
|
|
6391
6551
|
name: "bnUSD",
|
|
6392
6552
|
decimals: 18,
|
|
6393
|
-
address: "0xA256dd181C3f6E5eC68C6869f5D50a712d47212e"
|
|
6553
|
+
address: "0xA256dd181C3f6E5eC68C6869f5D50a712d47212e",
|
|
6554
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6394
6555
|
},
|
|
6395
6556
|
wstETH: {
|
|
6396
6557
|
symbol: "wstETH",
|
|
6397
6558
|
name: "Wrapped stETH",
|
|
6398
6559
|
decimals: 18,
|
|
6399
|
-
address: "0x5979D7b546E38E414F7E9822514be443A4800529"
|
|
6560
|
+
address: "0x5979D7b546E38E414F7E9822514be443A4800529",
|
|
6561
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6400
6562
|
},
|
|
6401
6563
|
weETH: {
|
|
6402
6564
|
symbol: "weETH",
|
|
6403
6565
|
name: "Wrapped eETH",
|
|
6404
6566
|
decimals: 18,
|
|
6405
|
-
address: "0x35751007a407ca6FEFfE80b3cB397736D2cf4dbe"
|
|
6567
|
+
address: "0x35751007a407ca6FEFfE80b3cB397736D2cf4dbe",
|
|
6568
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6406
6569
|
},
|
|
6407
6570
|
tBTC: {
|
|
6408
6571
|
symbol: "tBTC",
|
|
6409
6572
|
name: "Arbitrum tBTC v2",
|
|
6410
6573
|
decimals: 18,
|
|
6411
|
-
address: "0x6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40"
|
|
6574
|
+
address: "0x6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40",
|
|
6575
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6412
6576
|
},
|
|
6413
6577
|
WBTC: {
|
|
6414
6578
|
symbol: "WBTC",
|
|
6415
6579
|
name: "Wrapped BTC",
|
|
6416
6580
|
decimals: 8,
|
|
6417
|
-
address: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"
|
|
6581
|
+
address: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
6582
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6418
6583
|
},
|
|
6419
6584
|
USDC: {
|
|
6420
6585
|
symbol: "USDC",
|
|
6421
6586
|
name: "USD Coin (USDC)",
|
|
6422
6587
|
decimals: 6,
|
|
6423
|
-
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
|
6588
|
+
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
6589
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6424
6590
|
},
|
|
6425
6591
|
USDT: {
|
|
6426
6592
|
symbol: "USDT",
|
|
6427
6593
|
name: "TetherToken",
|
|
6428
6594
|
decimals: 6,
|
|
6429
|
-
address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
|
|
6595
|
+
address: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
6596
|
+
xChainId: ARBITRUM_MAINNET_CHAIN_ID
|
|
6430
6597
|
}
|
|
6431
6598
|
}
|
|
6432
6599
|
},
|
|
@@ -6447,37 +6614,43 @@ var spokeChainConfig = {
|
|
|
6447
6614
|
symbol: "ETH",
|
|
6448
6615
|
name: "Ethereum",
|
|
6449
6616
|
decimals: 18,
|
|
6450
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6617
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6618
|
+
xChainId: BASE_MAINNET_CHAIN_ID
|
|
6451
6619
|
},
|
|
6452
6620
|
bnUSD: {
|
|
6453
6621
|
symbol: "bnUSD",
|
|
6454
6622
|
name: "bnUSD",
|
|
6455
6623
|
decimals: 18,
|
|
6456
|
-
address: "0xAcfab3F31C0a18559D78556BBf297EC29c6cf8aa"
|
|
6624
|
+
address: "0xAcfab3F31C0a18559D78556BBf297EC29c6cf8aa",
|
|
6625
|
+
xChainId: BASE_MAINNET_CHAIN_ID
|
|
6457
6626
|
},
|
|
6458
6627
|
weETH: {
|
|
6459
6628
|
symbol: "weETH",
|
|
6460
6629
|
name: "Wrapped eETH",
|
|
6461
6630
|
decimals: 18,
|
|
6462
|
-
address: "0x04c0599ae5a44757c0af6f9ec3b93da8976c150a"
|
|
6631
|
+
address: "0x04c0599ae5a44757c0af6f9ec3b93da8976c150a",
|
|
6632
|
+
xChainId: BASE_MAINNET_CHAIN_ID
|
|
6463
6633
|
},
|
|
6464
6634
|
USDC: {
|
|
6465
6635
|
symbol: "USDC",
|
|
6466
6636
|
name: "USD Coin",
|
|
6467
6637
|
decimals: 6,
|
|
6468
|
-
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
|
|
6638
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
6639
|
+
xChainId: BASE_MAINNET_CHAIN_ID
|
|
6469
6640
|
},
|
|
6470
6641
|
wstETH: {
|
|
6471
6642
|
symbol: "wstETH",
|
|
6472
6643
|
name: "Wrapped stETH",
|
|
6473
6644
|
decimals: 18,
|
|
6474
|
-
address: "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452"
|
|
6645
|
+
address: "0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452",
|
|
6646
|
+
xChainId: BASE_MAINNET_CHAIN_ID
|
|
6475
6647
|
},
|
|
6476
6648
|
cbBTC: {
|
|
6477
6649
|
symbol: "cbBTC",
|
|
6478
6650
|
name: "Coinbase Wrapped BTC",
|
|
6479
6651
|
decimals: 8,
|
|
6480
|
-
address: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf"
|
|
6652
|
+
address: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf",
|
|
6653
|
+
xChainId: BASE_MAINNET_CHAIN_ID
|
|
6481
6654
|
}
|
|
6482
6655
|
}
|
|
6483
6656
|
},
|
|
@@ -6498,37 +6671,43 @@ var spokeChainConfig = {
|
|
|
6498
6671
|
symbol: "ETH",
|
|
6499
6672
|
name: "Ethereum",
|
|
6500
6673
|
decimals: 18,
|
|
6501
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6674
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6675
|
+
xChainId: OPTIMISM_MAINNET_CHAIN_ID
|
|
6502
6676
|
},
|
|
6503
6677
|
bnUSD: {
|
|
6504
6678
|
symbol: "bnUSD",
|
|
6505
6679
|
name: "bnUSD",
|
|
6506
6680
|
decimals: 18,
|
|
6507
|
-
address: "0xF4f7dC27c17470a26d0de9039Cf0EA5045F100E8"
|
|
6681
|
+
address: "0xF4f7dC27c17470a26d0de9039Cf0EA5045F100E8",
|
|
6682
|
+
xChainId: OPTIMISM_MAINNET_CHAIN_ID
|
|
6508
6683
|
},
|
|
6509
6684
|
USDC: {
|
|
6510
6685
|
symbol: "USDC",
|
|
6511
6686
|
name: "USD Coin",
|
|
6512
6687
|
decimals: 6,
|
|
6513
|
-
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85"
|
|
6688
|
+
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
6689
|
+
xChainId: OPTIMISM_MAINNET_CHAIN_ID
|
|
6514
6690
|
},
|
|
6515
6691
|
wstETH: {
|
|
6516
6692
|
symbol: "wstETH",
|
|
6517
6693
|
name: "Wrapped stETH",
|
|
6518
6694
|
decimals: 18,
|
|
6519
|
-
address: "0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb"
|
|
6695
|
+
address: "0x1F32b1c2345538c0c6f582fCB022739c4A194Ebb",
|
|
6696
|
+
xChainId: OPTIMISM_MAINNET_CHAIN_ID
|
|
6520
6697
|
},
|
|
6521
6698
|
weETH: {
|
|
6522
6699
|
symbol: "weETH",
|
|
6523
6700
|
name: "Wrapped eETH",
|
|
6524
6701
|
decimals: 18,
|
|
6525
|
-
address: "0x5A7fACB970D094B6C7FF1df0eA68D99E6e73CBFF"
|
|
6702
|
+
address: "0x5A7fACB970D094B6C7FF1df0eA68D99E6e73CBFF",
|
|
6703
|
+
xChainId: OPTIMISM_MAINNET_CHAIN_ID
|
|
6526
6704
|
},
|
|
6527
6705
|
USDT: {
|
|
6528
6706
|
symbol: "USDT",
|
|
6529
6707
|
name: "Tether USD",
|
|
6530
6708
|
decimals: 6,
|
|
6531
|
-
address: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"
|
|
6709
|
+
address: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58",
|
|
6710
|
+
xChainId: OPTIMISM_MAINNET_CHAIN_ID
|
|
6532
6711
|
}
|
|
6533
6712
|
}
|
|
6534
6713
|
},
|
|
@@ -6549,31 +6728,36 @@ var spokeChainConfig = {
|
|
|
6549
6728
|
symbol: "BNB",
|
|
6550
6729
|
name: "BNB",
|
|
6551
6730
|
decimals: 18,
|
|
6552
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6731
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6732
|
+
xChainId: BSC_MAINNET_CHAIN_ID
|
|
6553
6733
|
},
|
|
6554
6734
|
bnUSD: {
|
|
6555
6735
|
symbol: "bnUSD",
|
|
6556
6736
|
name: "bnUSD",
|
|
6557
6737
|
decimals: 18,
|
|
6558
|
-
address: "0x8428FedC020737a5A2291F46cB1B80613eD71638"
|
|
6738
|
+
address: "0x8428FedC020737a5A2291F46cB1B80613eD71638",
|
|
6739
|
+
xChainId: BSC_MAINNET_CHAIN_ID
|
|
6559
6740
|
},
|
|
6560
6741
|
ETHB: {
|
|
6561
6742
|
symbol: "ETHB",
|
|
6562
6743
|
name: "Ethereum BSC",
|
|
6563
6744
|
decimals: 18,
|
|
6564
|
-
address: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8"
|
|
6745
|
+
address: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
|
|
6746
|
+
xChainId: BSC_MAINNET_CHAIN_ID
|
|
6565
6747
|
},
|
|
6566
6748
|
BTCB: {
|
|
6567
6749
|
symbol: "BTCB",
|
|
6568
6750
|
name: "Bitcoin BSC",
|
|
6569
6751
|
decimals: 18,
|
|
6570
|
-
address: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c"
|
|
6752
|
+
address: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c",
|
|
6753
|
+
xChainId: BSC_MAINNET_CHAIN_ID
|
|
6571
6754
|
},
|
|
6572
6755
|
USDC: {
|
|
6573
6756
|
symbol: "USDC",
|
|
6574
6757
|
name: "USD Coin",
|
|
6575
6758
|
decimals: 18,
|
|
6576
|
-
address: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"
|
|
6759
|
+
address: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
6760
|
+
xChainId: BSC_MAINNET_CHAIN_ID
|
|
6577
6761
|
}
|
|
6578
6762
|
}
|
|
6579
6763
|
},
|
|
@@ -6594,19 +6778,22 @@ var spokeChainConfig = {
|
|
|
6594
6778
|
symbol: "POL",
|
|
6595
6779
|
name: "Polygon",
|
|
6596
6780
|
decimals: 18,
|
|
6597
|
-
address: "0x0000000000000000000000000000000000000000"
|
|
6781
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
6782
|
+
xChainId: POLYGON_MAINNET_CHAIN_ID
|
|
6598
6783
|
},
|
|
6599
6784
|
bnUSD: {
|
|
6600
6785
|
symbol: "bnUSD",
|
|
6601
6786
|
name: "bnUSD",
|
|
6602
6787
|
decimals: 18,
|
|
6603
|
-
address: "0x39E77f86C1B1f3fbAb362A82b49D2E86C09659B4"
|
|
6788
|
+
address: "0x39E77f86C1B1f3fbAb362A82b49D2E86C09659B4",
|
|
6789
|
+
xChainId: POLYGON_MAINNET_CHAIN_ID
|
|
6604
6790
|
},
|
|
6605
6791
|
USDC: {
|
|
6606
6792
|
symbol: "USDC",
|
|
6607
6793
|
name: "USD Coin",
|
|
6608
6794
|
decimals: 6,
|
|
6609
|
-
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"
|
|
6795
|
+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
6796
|
+
xChainId: POLYGON_MAINNET_CHAIN_ID
|
|
6610
6797
|
}
|
|
6611
6798
|
}
|
|
6612
6799
|
},
|
|
@@ -6631,19 +6818,22 @@ var spokeChainConfig = {
|
|
|
6631
6818
|
symbol: "INJ",
|
|
6632
6819
|
name: "Injective",
|
|
6633
6820
|
decimals: 18,
|
|
6634
|
-
address: "inj"
|
|
6821
|
+
address: "inj",
|
|
6822
|
+
xChainId: INJECTIVE_MAINNET_CHAIN_ID
|
|
6635
6823
|
},
|
|
6636
6824
|
bnUSD: {
|
|
6637
6825
|
symbol: "bnUSD",
|
|
6638
6826
|
name: "bnUSD",
|
|
6639
6827
|
decimals: 18,
|
|
6640
|
-
address: "factory/inj1d036ftaatxpkqsu9hja8r24rv3v33chz3appxp/bnUSD"
|
|
6828
|
+
address: "factory/inj1d036ftaatxpkqsu9hja8r24rv3v33chz3appxp/bnUSD",
|
|
6829
|
+
xChainId: INJECTIVE_MAINNET_CHAIN_ID
|
|
6641
6830
|
},
|
|
6642
6831
|
USDC: {
|
|
6643
6832
|
symbol: "USDC",
|
|
6644
6833
|
name: "USD Coin",
|
|
6645
6834
|
decimals: 6,
|
|
6646
|
-
address: "ibc/2CBC2EA121AE42563B08028466F37B600F2D7D4282342DE938283CC3FB2BC00E"
|
|
6835
|
+
address: "ibc/2CBC2EA121AE42563B08028466F37B600F2D7D4282342DE938283CC3FB2BC00E",
|
|
6836
|
+
xChainId: INJECTIVE_MAINNET_CHAIN_ID
|
|
6647
6837
|
}
|
|
6648
6838
|
},
|
|
6649
6839
|
gasPrice: "500000000inj",
|
|
@@ -6666,25 +6856,29 @@ var spokeChainConfig = {
|
|
|
6666
6856
|
symbol: "bnUSD",
|
|
6667
6857
|
name: "bnUSD",
|
|
6668
6858
|
decimals: 7,
|
|
6669
|
-
address: "CD6YBFFWMU2UJHX2NGRJ7RN76IJVTCC7MRA46DUBXNB7E6W7H7JRJ2CX"
|
|
6859
|
+
address: "CD6YBFFWMU2UJHX2NGRJ7RN76IJVTCC7MRA46DUBXNB7E6W7H7JRJ2CX",
|
|
6860
|
+
xChainId: STELLAR_MAINNET_CHAIN_ID
|
|
6670
6861
|
},
|
|
6671
6862
|
XLM: {
|
|
6672
6863
|
symbol: "XLM",
|
|
6673
6864
|
name: "Stellar Lumens",
|
|
6674
6865
|
decimals: 7,
|
|
6675
|
-
address: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA"
|
|
6866
|
+
address: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA",
|
|
6867
|
+
xChainId: STELLAR_MAINNET_CHAIN_ID
|
|
6676
6868
|
},
|
|
6677
6869
|
USDC: {
|
|
6678
6870
|
symbol: "USDC",
|
|
6679
6871
|
name: "USD Coin",
|
|
6680
6872
|
decimals: 7,
|
|
6681
|
-
address: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75"
|
|
6873
|
+
address: "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75",
|
|
6874
|
+
xChainId: STELLAR_MAINNET_CHAIN_ID
|
|
6682
6875
|
},
|
|
6683
6876
|
legacybnUSD: {
|
|
6684
|
-
symbol: "bnUSD",
|
|
6877
|
+
symbol: "bnUSD (legacy)",
|
|
6685
6878
|
name: "legacybnUSD",
|
|
6686
6879
|
decimals: 18,
|
|
6687
|
-
address: "CCT4ZYIYZ3TUO2AWQFEOFGBZ6HQP3GW5TA37CK7CRZVFRDXYTHTYX7KP"
|
|
6880
|
+
address: "CCT4ZYIYZ3TUO2AWQFEOFGBZ6HQP3GW5TA37CK7CRZVFRDXYTHTYX7KP",
|
|
6881
|
+
xChainId: STELLAR_MAINNET_CHAIN_ID
|
|
6688
6882
|
}
|
|
6689
6883
|
},
|
|
6690
6884
|
nativeToken: "CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA",
|
|
@@ -6700,8 +6894,8 @@ var spokeChainConfig = {
|
|
|
6700
6894
|
[SUI_MAINNET_CHAIN_ID]: {
|
|
6701
6895
|
addresses: {
|
|
6702
6896
|
connection: "0xf3b1e696a66d02cb776dc15aae73c68bc8f03adcb6ba0ec7f6332d9d90a6a3d2::connectionv3::0x3ee76d13909ac58ae13baab4c9be5a5142818d9a387aed641825e5d4356969bf",
|
|
6703
|
-
|
|
6704
|
-
|
|
6897
|
+
assetManagerConfigId: "0xcb7346339340b7f8dea40fcafb70721dc2fcfa7e8626a89fd954d46c1f928b61",
|
|
6898
|
+
originalAssetManager: "0xa17a409164d1676db71b411ab50813ba2c7dd547d2df538c699049566f1ff922::asset_manager::0xcb7346339340b7f8dea40fcafb70721dc2fcfa7e8626a89fd954d46c1f928b61",
|
|
6705
6899
|
xTokenManager: "",
|
|
6706
6900
|
rateLimit: "",
|
|
6707
6901
|
testToken: ""
|
|
@@ -6711,61 +6905,71 @@ var spokeChainConfig = {
|
|
|
6711
6905
|
symbol: "SUI",
|
|
6712
6906
|
name: "SUI",
|
|
6713
6907
|
decimals: 9,
|
|
6714
|
-
address: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
6908
|
+
address: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
6909
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6715
6910
|
},
|
|
6716
6911
|
bnUSD: {
|
|
6717
6912
|
symbol: "bnUSD",
|
|
6718
6913
|
name: "bnUSD",
|
|
6719
6914
|
decimals: 9,
|
|
6720
|
-
address: "0xff4de2b2b57dd7611d2812d231a467d007b702a101fd5c7ad3b278257cddb507::bnusd::BNUSD"
|
|
6915
|
+
address: "0xff4de2b2b57dd7611d2812d231a467d007b702a101fd5c7ad3b278257cddb507::bnusd::BNUSD",
|
|
6916
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6721
6917
|
},
|
|
6722
6918
|
USDC: {
|
|
6723
6919
|
symbol: "USDC",
|
|
6724
6920
|
name: "USD Coin",
|
|
6725
6921
|
decimals: 6,
|
|
6726
|
-
address: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
6922
|
+
address: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
6923
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6727
6924
|
},
|
|
6728
6925
|
legacybnUSD: {
|
|
6729
|
-
symbol: "bnUSD",
|
|
6926
|
+
symbol: "bnUSD (legacy)",
|
|
6730
6927
|
name: "legacybnUSD",
|
|
6731
6928
|
decimals: 9,
|
|
6732
|
-
address: "0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR"
|
|
6929
|
+
address: "0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR",
|
|
6930
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6733
6931
|
},
|
|
6734
6932
|
afSUI: {
|
|
6735
6933
|
symbol: "afSUI",
|
|
6736
6934
|
name: "Aftermath Staked Sui",
|
|
6737
6935
|
decimals: 9,
|
|
6738
|
-
address: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
6936
|
+
address: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI",
|
|
6937
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6739
6938
|
},
|
|
6740
6939
|
mSUI: {
|
|
6741
6940
|
symbol: "mSUI",
|
|
6742
6941
|
name: "Mirai Staked SUI",
|
|
6743
6942
|
decimals: 9,
|
|
6744
|
-
address: "0x922d15d7f55c13fd790f6e54397470ec592caa2b508df292a2e8553f3d3b274f::msui::MSUI"
|
|
6943
|
+
address: "0x922d15d7f55c13fd790f6e54397470ec592caa2b508df292a2e8553f3d3b274f::msui::MSUI",
|
|
6944
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6745
6945
|
},
|
|
6746
6946
|
haSUI: {
|
|
6747
6947
|
symbol: "haSUI",
|
|
6748
6948
|
name: "haSUI",
|
|
6749
6949
|
decimals: 9,
|
|
6750
|
-
address: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
6950
|
+
address: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",
|
|
6951
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6751
6952
|
},
|
|
6752
6953
|
vSUI: {
|
|
6753
6954
|
symbol: "vSUI",
|
|
6754
6955
|
name: "Volo Staked SUI",
|
|
6755
6956
|
decimals: 9,
|
|
6756
|
-
address: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
6957
|
+
address: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",
|
|
6958
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6757
6959
|
},
|
|
6758
6960
|
yapSUI: {
|
|
6759
6961
|
symbol: "yapSUI",
|
|
6760
6962
|
name: "Yap Staked SUI",
|
|
6761
6963
|
decimals: 9,
|
|
6762
|
-
address: "0x83f1bb8c91ecd1fd313344058b0eed94d63c54e41d8d1ae5bff1353443517d65::yap_sui::YAP_SUI"
|
|
6964
|
+
address: "0x83f1bb8c91ecd1fd313344058b0eed94d63c54e41d8d1ae5bff1353443517d65::yap_sui::YAP_SUI",
|
|
6965
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6763
6966
|
},
|
|
6764
6967
|
trevinSUI: {
|
|
6765
6968
|
symbol: "trevinSUI",
|
|
6766
6969
|
name: "Trevin Staked SUI",
|
|
6767
6970
|
decimals: 9,
|
|
6768
|
-
address: "0x502867b177303bf1bf226245fcdd3403c177e78d175a55a56c0602c7ff51c7fa::trevin_sui::TREVIN_SUI"
|
|
6971
|
+
address: "0x502867b177303bf1bf226245fcdd3403c177e78d175a55a56c0602c7ff51c7fa::trevin_sui::TREVIN_SUI",
|
|
6972
|
+
xChainId: SUI_MAINNET_CHAIN_ID
|
|
6769
6973
|
}
|
|
6770
6974
|
},
|
|
6771
6975
|
nativeToken: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
@@ -6786,7 +6990,7 @@ var spokeChainConfig = {
|
|
|
6786
6990
|
},
|
|
6787
6991
|
chain: {
|
|
6788
6992
|
id: ICON_MAINNET_CHAIN_ID,
|
|
6789
|
-
name: "ICON
|
|
6993
|
+
name: "ICON",
|
|
6790
6994
|
type: "ICON"
|
|
6791
6995
|
},
|
|
6792
6996
|
supportedTokens: {
|
|
@@ -6794,33 +6998,38 @@ var spokeChainConfig = {
|
|
|
6794
6998
|
symbol: "ICX",
|
|
6795
6999
|
name: "ICON",
|
|
6796
7000
|
decimals: 18,
|
|
6797
|
-
address: "cx0000000000000000000000000000000000000000"
|
|
7001
|
+
address: "cx0000000000000000000000000000000000000000",
|
|
7002
|
+
xChainId: ICON_MAINNET_CHAIN_ID
|
|
6798
7003
|
},
|
|
6799
7004
|
wICX: {
|
|
6800
7005
|
symbol: "wICX",
|
|
6801
7006
|
name: "Wrapped ICX",
|
|
6802
7007
|
decimals: 18,
|
|
6803
|
-
address: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
7008
|
+
address: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d",
|
|
7009
|
+
xChainId: ICON_MAINNET_CHAIN_ID
|
|
6804
7010
|
},
|
|
6805
7011
|
bnUSD: {
|
|
6806
7012
|
// same as legacy
|
|
6807
|
-
symbol: "bnUSD",
|
|
7013
|
+
symbol: "bnUSD (legacy)",
|
|
6808
7014
|
name: "bnUSD",
|
|
6809
7015
|
decimals: 18,
|
|
6810
|
-
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb"
|
|
7016
|
+
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb",
|
|
7017
|
+
xChainId: ICON_MAINNET_CHAIN_ID
|
|
6811
7018
|
},
|
|
6812
7019
|
legacybnUSD: {
|
|
6813
7020
|
// duplicate of bnUSD purely for consistency with other legacy tokens chains (sui, stellar)
|
|
6814
|
-
symbol: "bnUSD",
|
|
7021
|
+
symbol: "bnUSD (legacy)",
|
|
6815
7022
|
name: "bnUSD",
|
|
6816
7023
|
decimals: 18,
|
|
6817
|
-
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb"
|
|
7024
|
+
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb",
|
|
7025
|
+
xChainId: ICON_MAINNET_CHAIN_ID
|
|
6818
7026
|
},
|
|
6819
7027
|
BALN: {
|
|
6820
7028
|
symbol: "BALN",
|
|
6821
7029
|
name: "BALN",
|
|
6822
7030
|
decimals: 18,
|
|
6823
|
-
address: "cxf61cd5a45dc9f91c15aa65831a30a90d59a09619"
|
|
7031
|
+
address: "cxf61cd5a45dc9f91c15aa65831a30a90d59a09619",
|
|
7032
|
+
xChainId: ICON_MAINNET_CHAIN_ID
|
|
6824
7033
|
}
|
|
6825
7034
|
},
|
|
6826
7035
|
nativeToken: "cx0000000000000000000000000000000000000000",
|
|
@@ -6828,26 +7037,8 @@ var spokeChainConfig = {
|
|
|
6828
7037
|
nid: "0x1"
|
|
6829
7038
|
}
|
|
6830
7039
|
};
|
|
6831
|
-
var HubVaultSymbols = [
|
|
6832
|
-
"sodaAVAX",
|
|
6833
|
-
"sodaBNB",
|
|
6834
|
-
"sodaETH",
|
|
6835
|
-
"sodaBTC",
|
|
6836
|
-
"sodaSUI",
|
|
6837
|
-
"sodaINJ",
|
|
6838
|
-
"sodaXLM",
|
|
6839
|
-
"sodaSOL",
|
|
6840
|
-
"sodaSODA",
|
|
6841
|
-
"sodaUSDT",
|
|
6842
|
-
"sodaUSDC",
|
|
6843
|
-
"bnUSD",
|
|
6844
|
-
"sodaPOL",
|
|
6845
|
-
"sodaNIBI",
|
|
6846
|
-
"sodaS",
|
|
6847
|
-
"IbnUSD"
|
|
6848
|
-
];
|
|
6849
7040
|
var hubVaults = {
|
|
6850
|
-
IbnUSD: {
|
|
7041
|
+
[SodaTokens.IbnUSD.symbol]: {
|
|
6851
7042
|
// ICON bnUSD (Migration) vault on Sonic contains legacy bnUSD tokens (stellar, sui, icon)
|
|
6852
7043
|
address: "0x9D4b663Eb075d2a1C7B8eaEFB9eCCC0510388B51",
|
|
6853
7044
|
reserves: [
|
|
@@ -6857,28 +7048,28 @@ var hubVaults = {
|
|
|
6857
7048
|
"0x1559B52d2e165da1505a542EA37C543c9137f52a"
|
|
6858
7049
|
]
|
|
6859
7050
|
},
|
|
6860
|
-
sodaS: {
|
|
7051
|
+
[SodaTokens.sodaS.symbol]: {
|
|
6861
7052
|
address: "0x62ecc3eeb80a162c57624b3ff80313fe69f5203e",
|
|
6862
7053
|
reserves: [
|
|
6863
7054
|
// hub asset addresses contained in the vault
|
|
6864
7055
|
"0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38"
|
|
6865
7056
|
]
|
|
6866
7057
|
},
|
|
6867
|
-
sodaNIBI: {
|
|
7058
|
+
[SodaTokens.sodaNIBI.symbol]: {
|
|
6868
7059
|
address: "0xc6c85287a8b173a509c2f198bb719a8a5a2d0c68",
|
|
6869
7060
|
reserves: [
|
|
6870
7061
|
// hub asset addresses contained in the vault
|
|
6871
7062
|
"0xe0064414c2c1a636a9424c7a17d86fbf7fd3f190"
|
|
6872
7063
|
]
|
|
6873
7064
|
},
|
|
6874
|
-
sodaPOL: {
|
|
7065
|
+
[SodaTokens.sodaPOL.symbol]: {
|
|
6875
7066
|
address: "0x208ed38f4783328aa9ebfec360d32e7520a9b779",
|
|
6876
7067
|
reserves: [
|
|
6877
7068
|
// hub asset addresses contained in the vault
|
|
6878
7069
|
"0x9ee17486571917837210824b0d4cadfe3b324d12"
|
|
6879
7070
|
]
|
|
6880
7071
|
},
|
|
6881
|
-
bnUSD: {
|
|
7072
|
+
[SodaTokens.bnUSD.symbol]: {
|
|
6882
7073
|
// new bnUSD vault on Sonic (also contains IbnUSD vault token as part of it)
|
|
6883
7074
|
address: "0xe801ca34e19abcbfea12025378d19c4fbe250131",
|
|
6884
7075
|
reserves: [
|
|
@@ -6897,19 +7088,33 @@ var hubVaults = {
|
|
|
6897
7088
|
"0xdf23097b9aeb917bf8fb70e99b6c528fffa35364",
|
|
6898
7089
|
"0x11b93c162aabffd026539bb3b9f9ec22c8b7ef8a",
|
|
6899
7090
|
"0x69425ffb14704124a58d6f69d510f74a59d9a5bc",
|
|
6900
|
-
"0x9d4b663eb075d2a1c7b8eaefb9eccc0510388b51"
|
|
7091
|
+
"0x9d4b663eb075d2a1c7b8eaefb9eccc0510388b51",
|
|
7092
|
+
"0xD1d14BF3324C901855A1f7d0d5CA4c8458D2a780"
|
|
6901
7093
|
]
|
|
6902
7094
|
},
|
|
6903
|
-
sodaSODA: {
|
|
7095
|
+
[SodaTokens.sodaSODA.symbol]: {
|
|
6904
7096
|
// SODA SODA vault
|
|
6905
7097
|
address: "0x21685e341de7844135329914be6bd8d16982d834",
|
|
6906
7098
|
reserves: [
|
|
6907
7099
|
// hub asset addresses contained in the vault
|
|
6908
|
-
"0x7c7d53eecda37a87ce0d5bf8e0b24512a48dc963"
|
|
7100
|
+
"0x7c7d53eecda37a87ce0d5bf8e0b24512a48dc963",
|
|
6909
7101
|
// SODA SODA hub asset
|
|
7102
|
+
"0xf51d7082375cdca8C19C74e1A0c77dA482aFDa4e",
|
|
7103
|
+
"0x93a367E5B37a1B9E8D04ef25a6Af40d181a3DfFF",
|
|
7104
|
+
"0x17fF8Ad5EBe6CA8B15751067cD0c89f0E580CD17",
|
|
7105
|
+
"0x4d12c72A8633588097D10e57b559ed642588e4C6",
|
|
7106
|
+
"0x26cd76cB5622Dc8638670A16E0Da5a51394A8DB1",
|
|
7107
|
+
"0x0eD0d274dC77ef460DC96b9fBaFF3EDB074e0471",
|
|
7108
|
+
"0x8D78A620E009Ba751Eb40d77A5e9Db48A3F2016b",
|
|
7109
|
+
"0x4Cf5Ce9594AEDdc5D3efe9d4Cdf0b944b4e73A53",
|
|
7110
|
+
"0xD749B5FfFED7cEDaa3239abDd16D677179C29AEc",
|
|
7111
|
+
"0x07Db7b1a96ebE474B20F52fF487cEE415adee79e",
|
|
7112
|
+
"0x20Ce75CdcEe44B1308365447b91B9c26e2b71Ffd",
|
|
7113
|
+
"0x5Db9CEc919f40C50809D9490DC3BbA4F05b0a1D7",
|
|
7114
|
+
"0x655730024B673B3378CD6031B1Cd01eaE9afb138"
|
|
6910
7115
|
]
|
|
6911
7116
|
},
|
|
6912
|
-
sodaAVAX: {
|
|
7117
|
+
[SodaTokens.sodaAVAX.symbol]: {
|
|
6913
7118
|
// SODA AVAX vault
|
|
6914
7119
|
address: "0x14238d267557e9d799016ad635b53cd15935d290",
|
|
6915
7120
|
reserves: [
|
|
@@ -6918,7 +7123,7 @@ var hubVaults = {
|
|
|
6918
7123
|
// AvalancheAVAX hub asset
|
|
6919
7124
|
]
|
|
6920
7125
|
},
|
|
6921
|
-
sodaBNB: {
|
|
7126
|
+
[SodaTokens.sodaBNB.symbol]: {
|
|
6922
7127
|
// SODA BNB vault
|
|
6923
7128
|
address: "0x40cd41b35db9e5109ae7e54b44de8625db320e6b",
|
|
6924
7129
|
reserves: [
|
|
@@ -6927,7 +7132,7 @@ var hubVaults = {
|
|
|
6927
7132
|
// BSC BNB hub asset
|
|
6928
7133
|
]
|
|
6929
7134
|
},
|
|
6930
|
-
sodaETH: {
|
|
7135
|
+
[SodaTokens.sodaETH.symbol]: {
|
|
6931
7136
|
// SODA ETH vault
|
|
6932
7137
|
address: "0x4effb5813271699683c25c734f4dabc45b363709",
|
|
6933
7138
|
reserves: [
|
|
@@ -6944,7 +7149,7 @@ var hubVaults = {
|
|
|
6944
7149
|
// Sonic WETH hub asset
|
|
6945
7150
|
]
|
|
6946
7151
|
},
|
|
6947
|
-
sodaBTC: {
|
|
7152
|
+
[SodaTokens.sodaBTC.symbol]: {
|
|
6948
7153
|
// SODA BTC vault
|
|
6949
7154
|
address: "0x7a1a5555842ad2d0ed274d09b5c4406a95799d5d",
|
|
6950
7155
|
reserves: [
|
|
@@ -6955,11 +7160,12 @@ var hubVaults = {
|
|
|
6955
7160
|
// Arbitrum wBTC hub asset
|
|
6956
7161
|
"0x96fc8540736f1598b7e235e6de8814062b3b5d3b",
|
|
6957
7162
|
// Arbitrum tBTC hub asset,
|
|
6958
|
-
"0xd8a24c71fea5bb81c66c01e532de7d9b11e13905"
|
|
7163
|
+
"0xd8a24c71fea5bb81c66c01e532de7d9b11e13905",
|
|
6959
7164
|
// BSC BTCB hub asset
|
|
7165
|
+
"0x03E99853C6376b13a4c6e4d0A115F1639c9FA14e"
|
|
6960
7166
|
]
|
|
6961
7167
|
},
|
|
6962
|
-
sodaSUI: {
|
|
7168
|
+
[SodaTokens.sodaSUI.symbol]: {
|
|
6963
7169
|
// SODA SUI vault
|
|
6964
7170
|
address: "0xdc5b4b00f98347e95b9f94911213dab4c687e1e3",
|
|
6965
7171
|
reserves: [
|
|
@@ -6968,7 +7174,7 @@ var hubVaults = {
|
|
|
6968
7174
|
// SUI SUI hub asset
|
|
6969
7175
|
]
|
|
6970
7176
|
},
|
|
6971
|
-
sodaINJ: {
|
|
7177
|
+
[SodaTokens.sodaINJ.symbol]: {
|
|
6972
7178
|
// SODA INJ vault
|
|
6973
7179
|
address: "0x1f22279c89b213944b7ea41dacb0a868ddcdfd13",
|
|
6974
7180
|
reserves: [
|
|
@@ -6977,7 +7183,7 @@ var hubVaults = {
|
|
|
6977
7183
|
// Injective INJ hub asset
|
|
6978
7184
|
]
|
|
6979
7185
|
},
|
|
6980
|
-
sodaXLM: {
|
|
7186
|
+
[SodaTokens.sodaXLM.symbol]: {
|
|
6981
7187
|
// SODA XLM vault
|
|
6982
7188
|
address: "0x6bc8c37cba91f76e68c9e6d689a9c21e4d32079b",
|
|
6983
7189
|
reserves: [
|
|
@@ -6986,7 +7192,7 @@ var hubVaults = {
|
|
|
6986
7192
|
// Stellar XLM hub asset
|
|
6987
7193
|
]
|
|
6988
7194
|
},
|
|
6989
|
-
sodaSOL: {
|
|
7195
|
+
[SodaTokens.sodaSOL.symbol]: {
|
|
6990
7196
|
// SODA SOL vault
|
|
6991
7197
|
address: "0xdea692287e2ce8cb08fa52917be0f16b1dacdc87",
|
|
6992
7198
|
reserves: [
|
|
@@ -6995,7 +7201,7 @@ var hubVaults = {
|
|
|
6995
7201
|
// Solana SOL hub asset
|
|
6996
7202
|
]
|
|
6997
7203
|
},
|
|
6998
|
-
sodaUSDT: {
|
|
7204
|
+
[SodaTokens.sodaUSDT.symbol]: {
|
|
6999
7205
|
// SODA USDT vault
|
|
7000
7206
|
address: "0xbdf1f453fcb61424011bbddcb96cfdb30f3fe876",
|
|
7001
7207
|
reserves: [
|
|
@@ -7007,7 +7213,7 @@ var hubVaults = {
|
|
|
7007
7213
|
// Sonic USDT
|
|
7008
7214
|
]
|
|
7009
7215
|
},
|
|
7010
|
-
sodaUSDC: {
|
|
7216
|
+
[SodaTokens.sodaUSDC.symbol]: {
|
|
7011
7217
|
address: "0xabbb91c0617090f0028bdc27597cd0d038f3a833",
|
|
7012
7218
|
reserves: [
|
|
7013
7219
|
"0x41abf4b1559ff709ef8150079bcb26db1fffd117",
|
|
@@ -7021,10 +7227,25 @@ var hubVaults = {
|
|
|
7021
7227
|
"0x4bc1211faa06fb50ff61a70331f56167ae511057",
|
|
7022
7228
|
"0x348007b53f25a9a857ab8ea81ec9e3ccbcf440f2",
|
|
7023
7229
|
"0xc3f020057510ffe10ceb882e1b48238b43d78a5e",
|
|
7024
|
-
"0x9d58508ad10d34048a11640735ca5075bba07b35"
|
|
7230
|
+
"0x9d58508ad10d34048a11640735ca5075bba07b35",
|
|
7231
|
+
"0xC1df02fb7b1b06bE886592C89F6955387998B2f7"
|
|
7025
7232
|
]
|
|
7026
7233
|
}
|
|
7027
7234
|
};
|
|
7235
|
+
var hubVaultTokensMap = new Map(
|
|
7236
|
+
Object.entries(hubVaults).map(([symbol, vault]) => [
|
|
7237
|
+
vault.address.toLowerCase(),
|
|
7238
|
+
{
|
|
7239
|
+
address: vault.address.toLowerCase(),
|
|
7240
|
+
symbol,
|
|
7241
|
+
name: symbol,
|
|
7242
|
+
decimals: 18
|
|
7243
|
+
}
|
|
7244
|
+
])
|
|
7245
|
+
);
|
|
7246
|
+
var getHubVaultTokenByAddress = (address) => {
|
|
7247
|
+
return hubVaultTokensMap.get(address.toLowerCase());
|
|
7248
|
+
};
|
|
7028
7249
|
var bnUSDLegacySpokeChainIds = [
|
|
7029
7250
|
ICON_MAINNET_CHAIN_ID,
|
|
7030
7251
|
SUI_MAINNET_CHAIN_ID,
|
|
@@ -7070,6 +7291,13 @@ var hubAssets = {
|
|
|
7070
7291
|
name: "Sonic",
|
|
7071
7292
|
vault: hubVaults.sodaS.address
|
|
7072
7293
|
},
|
|
7294
|
+
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].bnUSD]: {
|
|
7295
|
+
asset: "0x289cDa1043b4Ce26BDCa3c12E534f56b24308A5B",
|
|
7296
|
+
decimal: 18,
|
|
7297
|
+
symbol: "bnUSD",
|
|
7298
|
+
name: "bnUSD",
|
|
7299
|
+
vault: hubVaults.bnUSD.address
|
|
7300
|
+
},
|
|
7073
7301
|
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address]: {
|
|
7074
7302
|
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address,
|
|
7075
7303
|
decimal: 18,
|
|
@@ -7104,7 +7332,8 @@ var hubAssets = {
|
|
|
7104
7332
|
symbol: "SODA",
|
|
7105
7333
|
name: "SODA",
|
|
7106
7334
|
vault: hubVaults.sodaSODA.address
|
|
7107
|
-
}
|
|
7335
|
+
},
|
|
7336
|
+
...SodaTokensAsHubAssets
|
|
7108
7337
|
},
|
|
7109
7338
|
[AVALANCHE_MAINNET_CHAIN_ID]: {
|
|
7110
7339
|
[spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].nativeToken]: {
|
|
@@ -7565,17 +7794,18 @@ var solverSupportedTokens = {
|
|
|
7565
7794
|
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH,
|
|
7566
7795
|
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7567
7796
|
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
7568
|
-
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS
|
|
7797
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS,
|
|
7798
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.bnUSD
|
|
7569
7799
|
],
|
|
7570
7800
|
[AVALANCHE_MAINNET_CHAIN_ID]: [
|
|
7571
7801
|
spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.AVAX,
|
|
7572
7802
|
spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
7573
|
-
spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
7574
|
-
|
|
7803
|
+
spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7804
|
+
spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.bnUSD
|
|
7575
7805
|
],
|
|
7576
7806
|
[ARBITRUM_MAINNET_CHAIN_ID]: [
|
|
7577
7807
|
spokeChainConfig[ARBITRUM_MAINNET_CHAIN_ID].supportedTokens.ETH,
|
|
7578
|
-
|
|
7808
|
+
spokeChainConfig[ARBITRUM_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7579
7809
|
spokeChainConfig[ARBITRUM_MAINNET_CHAIN_ID].supportedTokens.WBTC,
|
|
7580
7810
|
spokeChainConfig[ARBITRUM_MAINNET_CHAIN_ID].supportedTokens.weETH,
|
|
7581
7811
|
spokeChainConfig[ARBITRUM_MAINNET_CHAIN_ID].supportedTokens.wstETH,
|
|
@@ -7585,7 +7815,7 @@ var solverSupportedTokens = {
|
|
|
7585
7815
|
],
|
|
7586
7816
|
[BASE_MAINNET_CHAIN_ID]: [
|
|
7587
7817
|
spokeChainConfig[BASE_MAINNET_CHAIN_ID].supportedTokens.ETH,
|
|
7588
|
-
|
|
7818
|
+
spokeChainConfig[BASE_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7589
7819
|
spokeChainConfig[BASE_MAINNET_CHAIN_ID].supportedTokens.weETH,
|
|
7590
7820
|
spokeChainConfig[BASE_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7591
7821
|
spokeChainConfig[BASE_MAINNET_CHAIN_ID].supportedTokens.wstETH,
|
|
@@ -7593,7 +7823,7 @@ var solverSupportedTokens = {
|
|
|
7593
7823
|
],
|
|
7594
7824
|
[OPTIMISM_MAINNET_CHAIN_ID]: [
|
|
7595
7825
|
spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.ETH,
|
|
7596
|
-
|
|
7826
|
+
spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7597
7827
|
spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7598
7828
|
spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.wstETH,
|
|
7599
7829
|
// spokeChainConfig[OPTIMISM_MAINNET_CHAIN_ID].supportedTokens.weETH, // NOTE: Not Implemented
|
|
@@ -7601,19 +7831,20 @@ var solverSupportedTokens = {
|
|
|
7601
7831
|
],
|
|
7602
7832
|
[POLYGON_MAINNET_CHAIN_ID]: [
|
|
7603
7833
|
spokeChainConfig[POLYGON_MAINNET_CHAIN_ID].supportedTokens.POL,
|
|
7604
|
-
|
|
7834
|
+
spokeChainConfig[POLYGON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7605
7835
|
spokeChainConfig[POLYGON_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
7606
7836
|
],
|
|
7607
7837
|
[BSC_MAINNET_CHAIN_ID]: [
|
|
7608
7838
|
spokeChainConfig[BSC_MAINNET_CHAIN_ID].supportedTokens.BNB,
|
|
7609
7839
|
spokeChainConfig[BSC_MAINNET_CHAIN_ID].supportedTokens.ETHB,
|
|
7610
7840
|
spokeChainConfig[BSC_MAINNET_CHAIN_ID].supportedTokens.BTCB,
|
|
7611
|
-
|
|
7841
|
+
spokeChainConfig[BSC_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7612
7842
|
spokeChainConfig[BSC_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
7613
7843
|
],
|
|
7614
7844
|
[SOLANA_MAINNET_CHAIN_ID]: [
|
|
7615
7845
|
spokeChainConfig[SOLANA_MAINNET_CHAIN_ID].supportedTokens.SOL,
|
|
7616
|
-
|
|
7846
|
+
spokeChainConfig[SOLANA_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7847
|
+
// NOTE: Not Implemented
|
|
7617
7848
|
spokeChainConfig[SOLANA_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
7618
7849
|
],
|
|
7619
7850
|
[ICON_MAINNET_CHAIN_ID]: [
|
|
@@ -7625,12 +7856,14 @@ var solverSupportedTokens = {
|
|
|
7625
7856
|
],
|
|
7626
7857
|
[STELLAR_MAINNET_CHAIN_ID]: [
|
|
7627
7858
|
spokeChainConfig[STELLAR_MAINNET_CHAIN_ID].supportedTokens.XLM,
|
|
7628
|
-
|
|
7859
|
+
spokeChainConfig[STELLAR_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7860
|
+
// NOTE: Not Implemented
|
|
7629
7861
|
spokeChainConfig[STELLAR_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
7630
7862
|
],
|
|
7631
7863
|
[SUI_MAINNET_CHAIN_ID]: [
|
|
7632
7864
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.SUI,
|
|
7633
|
-
|
|
7865
|
+
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7866
|
+
// NOTE: Not Implemented
|
|
7634
7867
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7635
7868
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.afSUI,
|
|
7636
7869
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.mSUI,
|
|
@@ -7640,9 +7873,9 @@ var solverSupportedTokens = {
|
|
|
7640
7873
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.trevinSUI
|
|
7641
7874
|
],
|
|
7642
7875
|
[INJECTIVE_MAINNET_CHAIN_ID]: [
|
|
7643
|
-
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.INJ,
|
|
7876
|
+
// spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.INJ,
|
|
7644
7877
|
// spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.bnUSD, // NOTE: Not Implemented
|
|
7645
|
-
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
7878
|
+
// spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7646
7879
|
],
|
|
7647
7880
|
[NIBIRU_MAINNET_CHAIN_ID]: [
|
|
7648
7881
|
// spokeChainConfig[NIBIRU_MAINNET_CHAIN_ID].supportedTokens.NIBI, // NOTE: Not Implemented
|
|
@@ -7774,11 +8007,30 @@ var chainIdToHubAssetsMap = new Map(
|
|
|
7774
8007
|
var supportedHubAssets = new Set(
|
|
7775
8008
|
Object.values(hubAssets).flatMap((assets) => Object.values(assets).map((info) => info.asset.toLowerCase()))
|
|
7776
8009
|
);
|
|
8010
|
+
var supportedSodaAssets = new Set(
|
|
8011
|
+
Object.values(hubAssets).flatMap((assets) => Object.values(assets).map((info) => info.vault.toLowerCase()))
|
|
8012
|
+
);
|
|
7777
8013
|
var spokeChainIdsSet = new Set(SPOKE_CHAIN_IDS);
|
|
8014
|
+
var getOriginalAssetInfoFromVault = (chainId, vault) => {
|
|
8015
|
+
const assets = hubAssets[chainId];
|
|
8016
|
+
if (!assets) {
|
|
8017
|
+
return [];
|
|
8018
|
+
}
|
|
8019
|
+
const vaultAddress = vault.toLowerCase();
|
|
8020
|
+
const result = [];
|
|
8021
|
+
for (const [spokeToken, info] of Object.entries(assets)) {
|
|
8022
|
+
if (info.vault.toLowerCase() === vaultAddress) {
|
|
8023
|
+
result.push(spokeToken);
|
|
8024
|
+
}
|
|
8025
|
+
}
|
|
8026
|
+
return result;
|
|
8027
|
+
};
|
|
7778
8028
|
var getHubAssetInfo = (chainId, asset) => originalAssetTohubAssetMap.get(chainId)?.get(asset.toLowerCase());
|
|
7779
8029
|
var isValidOriginalAssetAddress = (chainId, asset) => originalAssetTohubAssetMap.get(chainId)?.has(asset.toLowerCase()) ?? false;
|
|
7780
8030
|
var getOriginalAssetAddress = (chainId, hubAsset) => hubAssetToOriginalAssetMap.get(chainId)?.get(hubAsset.toLowerCase());
|
|
8031
|
+
var getOriginalTokenFromOriginalAssetAddress = (chainId, asset) => Object.values(spokeChainConfig[chainId].supportedTokens).find((t) => t.address.toLowerCase() === asset.toLowerCase()) ?? void 0;
|
|
7781
8032
|
var isValidHubAsset = (hubAsset) => supportedHubAssets.has(hubAsset.toLowerCase());
|
|
8033
|
+
var isValidVault = (vault) => supportedSodaAssets.has(vault.toLowerCase());
|
|
7782
8034
|
var isValidChainHubAsset = (chainId, hubAsset) => chainIdToHubAssetsMap.get(chainId)?.has(hubAsset.toLowerCase()) ?? false;
|
|
7783
8035
|
var isValidSpokeChainId = (chainId) => spokeChainIdsSet.has(chainId);
|
|
7784
8036
|
var isValidIntentRelayChainId = (chainId) => Object.values(INTENT_RELAY_CHAIN_IDS).some((id) => id === chainId);
|
|
@@ -7831,12 +8083,13 @@ var InjectiveSpokeProvider = class {
|
|
|
7831
8083
|
);
|
|
7832
8084
|
}
|
|
7833
8085
|
async getBalance(token) {
|
|
7834
|
-
|
|
8086
|
+
const response = await this.chainGrpcWasmApi.fetchSmartContractState(
|
|
7835
8087
|
this.chainConfig.addresses.assetManager,
|
|
7836
8088
|
toBase64({
|
|
7837
8089
|
get_balance: { denom: token }
|
|
7838
8090
|
})
|
|
7839
8091
|
);
|
|
8092
|
+
return fromBase64(response.data);
|
|
7840
8093
|
}
|
|
7841
8094
|
// Execute Methods (requires SigningCosmWasmClient)
|
|
7842
8095
|
/**
|
|
@@ -8374,341 +8627,66 @@ var StellarSpokeProvider = class {
|
|
|
8374
8627
|
return toHex(Buffer.from(stellaraddress, "hex"));
|
|
8375
8628
|
}
|
|
8376
8629
|
};
|
|
8377
|
-
var
|
|
8378
|
-
|
|
8379
|
-
chainConfig;
|
|
8380
|
-
publicClient;
|
|
8381
|
-
constructor(config, wallet_provider) {
|
|
8382
|
-
this.chainConfig = config;
|
|
8383
|
-
this.walletProvider = wallet_provider;
|
|
8384
|
-
this.publicClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
8385
|
-
}
|
|
8386
|
-
async getBalance(token) {
|
|
8387
|
-
const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
|
|
8388
|
-
const tx = new Transaction();
|
|
8389
|
-
const result = await this.walletProvider.viewContract(
|
|
8390
|
-
tx,
|
|
8391
|
-
assetmanager.packageId,
|
|
8392
|
-
assetmanager.moduleId,
|
|
8393
|
-
"get_token_balance",
|
|
8394
|
-
[tx.object(assetmanager.stateId)],
|
|
8395
|
-
[token]
|
|
8396
|
-
);
|
|
8397
|
-
if (!Array.isArray(result?.returnValues) || !Array.isArray(result.returnValues[0]) || result.returnValues[0][0] === void 0) {
|
|
8398
|
-
throw new Error("Failed to get Balance");
|
|
8399
|
-
}
|
|
8400
|
-
const val = result.returnValues[0][0];
|
|
8401
|
-
const str_u64 = bcs.U64.parse(Uint8Array.from(val));
|
|
8402
|
-
return BigInt(str_u64);
|
|
8630
|
+
var Erc20Service = class {
|
|
8631
|
+
constructor() {
|
|
8403
8632
|
}
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
8409
|
-
|
|
8410
|
-
|
|
8411
|
-
|
|
8412
|
-
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
client: this.publicClient,
|
|
8427
|
-
onlyTransactionKind: true
|
|
8633
|
+
/**
|
|
8634
|
+
* Check if spender has enough ERC20 allowance for given amount
|
|
8635
|
+
* @param token - ERC20 token address
|
|
8636
|
+
* @param amount - Amount to check allowance for
|
|
8637
|
+
* @param owner - User wallet address
|
|
8638
|
+
* @param spender - Spender address
|
|
8639
|
+
* @param spokeProvider - EVM Spoke provider
|
|
8640
|
+
* @return - True if spender is allowed to spend amount on behalf of owner
|
|
8641
|
+
*/
|
|
8642
|
+
static async isAllowanceValid(token, amount, owner, spender, spokeProvider) {
|
|
8643
|
+
try {
|
|
8644
|
+
if (token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
8645
|
+
return {
|
|
8646
|
+
ok: true,
|
|
8647
|
+
value: true
|
|
8648
|
+
};
|
|
8649
|
+
}
|
|
8650
|
+
const allowedAmount = await spokeProvider.publicClient.readContract({
|
|
8651
|
+
address: token,
|
|
8652
|
+
abi: erc20Abi$1,
|
|
8653
|
+
functionName: "allowance",
|
|
8654
|
+
args: [owner, spender]
|
|
8428
8655
|
});
|
|
8429
|
-
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
8430
8656
|
return {
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8657
|
+
ok: true,
|
|
8658
|
+
value: allowedAmount >= amount
|
|
8659
|
+
};
|
|
8660
|
+
} catch (e) {
|
|
8661
|
+
return {
|
|
8662
|
+
ok: false,
|
|
8663
|
+
error: e
|
|
8435
8664
|
};
|
|
8436
8665
|
}
|
|
8437
|
-
return this.walletProvider.signAndExecuteTxn(tx);
|
|
8438
8666
|
}
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8667
|
+
/**
|
|
8668
|
+
* Approve ERC20 amount spending
|
|
8669
|
+
* @param token - ERC20 token address
|
|
8670
|
+
* @param amount - Amount to approve
|
|
8671
|
+
* @param spender - Spender address
|
|
8672
|
+
* @param provider - EVM Provider
|
|
8673
|
+
*/
|
|
8674
|
+
static async approve(token, amount, spender, spokeProvider, raw) {
|
|
8675
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
8676
|
+
const rawTx = {
|
|
8677
|
+
from: walletAddress,
|
|
8678
|
+
to: token,
|
|
8679
|
+
value: 0n,
|
|
8680
|
+
data: encodeFunctionData({
|
|
8681
|
+
abi: erc20Abi$1,
|
|
8682
|
+
functionName: "approve",
|
|
8683
|
+
args: [spender, amount]
|
|
8684
|
+
})
|
|
8685
|
+
};
|
|
8686
|
+
if (raw) {
|
|
8687
|
+
return rawTx;
|
|
8443
8688
|
}
|
|
8444
|
-
return
|
|
8445
|
-
}
|
|
8446
|
-
async getCoin(tx, coin, amount, address) {
|
|
8447
|
-
const coins = await this.walletProvider.getCoins(address, coin);
|
|
8448
|
-
const objects = [];
|
|
8449
|
-
let totalAmount = BigInt(0);
|
|
8450
|
-
for (const coin2 of coins.data) {
|
|
8451
|
-
totalAmount += BigInt(coin2.balance);
|
|
8452
|
-
objects.push(coin2.coinObjectId);
|
|
8453
|
-
if (totalAmount >= amount) {
|
|
8454
|
-
break;
|
|
8455
|
-
}
|
|
8456
|
-
}
|
|
8457
|
-
const firstObject = objects[0];
|
|
8458
|
-
if (!firstObject) {
|
|
8459
|
-
throw new Error(`[SuiIntentService.getCoin] Coin=${coin} not found for address=${address} and amount=${amount}`);
|
|
8460
|
-
}
|
|
8461
|
-
if (objects.length > 1) {
|
|
8462
|
-
tx.mergeCoins(firstObject, objects.slice(1));
|
|
8463
|
-
}
|
|
8464
|
-
if (totalAmount === amount) {
|
|
8465
|
-
return tx.object(firstObject);
|
|
8466
|
-
}
|
|
8467
|
-
return tx.splitCoins(firstObject, [amount]);
|
|
8468
|
-
}
|
|
8469
|
-
splitAddress(address) {
|
|
8470
|
-
const parts = address.split("::");
|
|
8471
|
-
if (parts.length === 3) {
|
|
8472
|
-
if (parts[0] && parts[1] && parts[2]) {
|
|
8473
|
-
return { packageId: parts[0], moduleId: parts[1], stateId: parts[2] };
|
|
8474
|
-
}
|
|
8475
|
-
throw new Error("Invalid package address");
|
|
8476
|
-
}
|
|
8477
|
-
throw new Error("Invalid package address");
|
|
8478
|
-
}
|
|
8479
|
-
async sendMessage(dst_chain_id, dst_address, data, raw) {
|
|
8480
|
-
const txb = new Transaction();
|
|
8481
|
-
const connection = this.splitAddress(this.chainConfig.addresses.connection);
|
|
8482
|
-
txb.moveCall({
|
|
8483
|
-
target: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
|
|
8484
|
-
arguments: [
|
|
8485
|
-
txb.object(connection.stateId),
|
|
8486
|
-
txb.pure.u256(dst_chain_id),
|
|
8487
|
-
txb.pure(bcs.vector(bcs.u8()).serialize(dst_address)),
|
|
8488
|
-
txb.pure(bcs.vector(bcs.u8()).serialize(data))
|
|
8489
|
-
]
|
|
8490
|
-
});
|
|
8491
|
-
const walletAddress = await this.walletProvider.getWalletAddress();
|
|
8492
|
-
if (raw) {
|
|
8493
|
-
txb.setSender(walletAddress);
|
|
8494
|
-
const transactionRaw = await txb.build({
|
|
8495
|
-
client: this.publicClient,
|
|
8496
|
-
onlyTransactionKind: true
|
|
8497
|
-
});
|
|
8498
|
-
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
8499
|
-
return {
|
|
8500
|
-
from: walletAddress,
|
|
8501
|
-
to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
|
|
8502
|
-
value: 0n,
|
|
8503
|
-
data: transactionRawBase64String
|
|
8504
|
-
};
|
|
8505
|
-
}
|
|
8506
|
-
return this.walletProvider.signAndExecuteTxn(txb);
|
|
8507
|
-
}
|
|
8508
|
-
async configureAssetManagerHub(hubNetworkId, hubAssetManager) {
|
|
8509
|
-
const tx = new Transaction();
|
|
8510
|
-
const assetmanager = this.splitAddress(this.chainConfig.addresses.assetManager);
|
|
8511
|
-
tx.moveCall({
|
|
8512
|
-
target: `${assetmanager.packageId}::${assetmanager.moduleId}::set_hub_details`,
|
|
8513
|
-
arguments: [tx.object(assetmanager.stateId), tx.pure.u64(hubNetworkId), tx.pure.vector("u8", hubAssetManager)]
|
|
8514
|
-
});
|
|
8515
|
-
const result = await this.walletProvider.signAndExecuteTxn(tx);
|
|
8516
|
-
return result;
|
|
8517
|
-
}
|
|
8518
|
-
async getWalletAddress() {
|
|
8519
|
-
return this.walletProvider.getWalletAddress();
|
|
8520
|
-
}
|
|
8521
|
-
async getWalletAddressBytes() {
|
|
8522
|
-
const address = await this.getWalletAddress();
|
|
8523
|
-
return _SuiSpokeProvider.getAddressBCSBytes(address);
|
|
8524
|
-
}
|
|
8525
|
-
static getAddressBCSBytes(suiaddress) {
|
|
8526
|
-
return toHex(bcs.Address.serialize(suiaddress).toBytes());
|
|
8527
|
-
}
|
|
8528
|
-
};
|
|
8529
|
-
|
|
8530
|
-
// src/entities/solana/SolanaSpokeProvider.ts
|
|
8531
|
-
var SolanaSpokeProvider = class {
|
|
8532
|
-
walletProvider;
|
|
8533
|
-
chainConfig;
|
|
8534
|
-
constructor(walletProvider, chainConfig) {
|
|
8535
|
-
this.walletProvider = walletProvider;
|
|
8536
|
-
this.chainConfig = chainConfig;
|
|
8537
|
-
}
|
|
8538
|
-
};
|
|
8539
|
-
var solanaSpokeChainConfig = spokeChainConfig[SOLANA_MAINNET_CHAIN_ID];
|
|
8540
|
-
function getSolanaAddressBytes(address) {
|
|
8541
|
-
return `0x${Buffer.from(address.toBytes()).toString("hex")}`;
|
|
8542
|
-
}
|
|
8543
|
-
function isNative(address) {
|
|
8544
|
-
if (address.equals(new PublicKey(solanaSpokeChainConfig.nativeToken))) {
|
|
8545
|
-
return true;
|
|
8546
|
-
}
|
|
8547
|
-
return false;
|
|
8548
|
-
}
|
|
8549
|
-
function convertTransactionInstructionToRaw(instruction) {
|
|
8550
|
-
return {
|
|
8551
|
-
keys: instruction.keys.map((key) => ({
|
|
8552
|
-
pubkey: key.pubkey.toBase58(),
|
|
8553
|
-
isSigner: key.isSigner,
|
|
8554
|
-
isWritable: key.isWritable
|
|
8555
|
-
})),
|
|
8556
|
-
programId: instruction.programId.toBase58(),
|
|
8557
|
-
data: instruction.data
|
|
8558
|
-
};
|
|
8559
|
-
}
|
|
8560
|
-
|
|
8561
|
-
// src/entities/icon/HanaWalletConnector.ts
|
|
8562
|
-
function requestAddress() {
|
|
8563
|
-
return new Promise((resolve) => {
|
|
8564
|
-
const eventHandler = (event) => {
|
|
8565
|
-
const customEvent = event;
|
|
8566
|
-
const response = customEvent.detail;
|
|
8567
|
-
if (isResponseAddressType(response)) {
|
|
8568
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8569
|
-
resolve({
|
|
8570
|
-
ok: true,
|
|
8571
|
-
value: response.payload
|
|
8572
|
-
});
|
|
8573
|
-
}
|
|
8574
|
-
};
|
|
8575
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8576
|
-
window.addEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8577
|
-
window.dispatchEvent(
|
|
8578
|
-
new CustomEvent("ICONEX_RELAY_REQUEST", {
|
|
8579
|
-
detail: {
|
|
8580
|
-
type: "REQUEST_ADDRESS"
|
|
8581
|
-
}
|
|
8582
|
-
})
|
|
8583
|
-
);
|
|
8584
|
-
});
|
|
8585
|
-
}
|
|
8586
|
-
function requestSigning(from, hash) {
|
|
8587
|
-
return new Promise((resolve, reject) => {
|
|
8588
|
-
const signRequest = new CustomEvent("ICONEX_RELAY_REQUEST", {
|
|
8589
|
-
detail: {
|
|
8590
|
-
type: "REQUEST_SIGNING",
|
|
8591
|
-
payload: {
|
|
8592
|
-
from,
|
|
8593
|
-
hash
|
|
8594
|
-
}
|
|
8595
|
-
}
|
|
8596
|
-
});
|
|
8597
|
-
const eventHandler = (event) => {
|
|
8598
|
-
const customEvent = event;
|
|
8599
|
-
const response = customEvent.detail;
|
|
8600
|
-
if (isResponseSigningType(response)) {
|
|
8601
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8602
|
-
resolve({
|
|
8603
|
-
ok: true,
|
|
8604
|
-
value: response.payload
|
|
8605
|
-
});
|
|
8606
|
-
} else if (response.type === "CANCEL_SIGNING") {
|
|
8607
|
-
reject(new Error("CANCEL_SIGNING"));
|
|
8608
|
-
}
|
|
8609
|
-
};
|
|
8610
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8611
|
-
window.addEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8612
|
-
window.dispatchEvent(signRequest);
|
|
8613
|
-
});
|
|
8614
|
-
}
|
|
8615
|
-
function requestJsonRpc(rawTransaction, id = 99999) {
|
|
8616
|
-
return new Promise((resolve, reject) => {
|
|
8617
|
-
const eventHandler = (event) => {
|
|
8618
|
-
const customEvent = event;
|
|
8619
|
-
const { type, payload } = customEvent.detail;
|
|
8620
|
-
if (type === "RESPONSE_JSON-RPC") {
|
|
8621
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8622
|
-
if (isJsonRpcPayloadResponse(payload)) {
|
|
8623
|
-
resolve({
|
|
8624
|
-
ok: true,
|
|
8625
|
-
value: payload
|
|
8626
|
-
});
|
|
8627
|
-
} else {
|
|
8628
|
-
reject(new Error("Invalid payload response type (expected JsonRpcPayloadResponse)"));
|
|
8629
|
-
}
|
|
8630
|
-
} else if (type === "CANCEL_JSON-RPC") {
|
|
8631
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8632
|
-
reject(new Error("CANCEL_JSON-RPC"));
|
|
8633
|
-
}
|
|
8634
|
-
};
|
|
8635
|
-
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8636
|
-
window.addEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
8637
|
-
window.dispatchEvent(
|
|
8638
|
-
new CustomEvent("ICONEX_RELAY_REQUEST", {
|
|
8639
|
-
detail: {
|
|
8640
|
-
type: "REQUEST_JSON-RPC",
|
|
8641
|
-
payload: {
|
|
8642
|
-
jsonrpc: "2.0",
|
|
8643
|
-
method: "icx_sendTransaction",
|
|
8644
|
-
params: rawTransaction,
|
|
8645
|
-
id
|
|
8646
|
-
}
|
|
8647
|
-
}
|
|
8648
|
-
})
|
|
8649
|
-
);
|
|
8650
|
-
});
|
|
8651
|
-
}
|
|
8652
|
-
var Erc20Service = class {
|
|
8653
|
-
constructor() {
|
|
8654
|
-
}
|
|
8655
|
-
/**
|
|
8656
|
-
* Check if spender has enough ERC20 allowance for given amount
|
|
8657
|
-
* @param token - ERC20 token address
|
|
8658
|
-
* @param amount - Amount to check allowance for
|
|
8659
|
-
* @param owner - User wallet address
|
|
8660
|
-
* @param spender - Spender address
|
|
8661
|
-
* @param spokeProvider - EVM Spoke provider
|
|
8662
|
-
* @return - True if spender is allowed to spend amount on behalf of owner
|
|
8663
|
-
*/
|
|
8664
|
-
static async isAllowanceValid(token, amount, owner, spender, spokeProvider) {
|
|
8665
|
-
try {
|
|
8666
|
-
if (token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
8667
|
-
return {
|
|
8668
|
-
ok: true,
|
|
8669
|
-
value: true
|
|
8670
|
-
};
|
|
8671
|
-
}
|
|
8672
|
-
const allowedAmount = await spokeProvider.publicClient.readContract({
|
|
8673
|
-
address: token,
|
|
8674
|
-
abi: erc20Abi$1,
|
|
8675
|
-
functionName: "allowance",
|
|
8676
|
-
args: [owner, spender]
|
|
8677
|
-
});
|
|
8678
|
-
return {
|
|
8679
|
-
ok: true,
|
|
8680
|
-
value: allowedAmount >= amount
|
|
8681
|
-
};
|
|
8682
|
-
} catch (e) {
|
|
8683
|
-
return {
|
|
8684
|
-
ok: false,
|
|
8685
|
-
error: e
|
|
8686
|
-
};
|
|
8687
|
-
}
|
|
8688
|
-
}
|
|
8689
|
-
/**
|
|
8690
|
-
* Approve ERC20 amount spending
|
|
8691
|
-
* @param token - ERC20 token address
|
|
8692
|
-
* @param amount - Amount to approve
|
|
8693
|
-
* @param spender - Spender address
|
|
8694
|
-
* @param provider - EVM Provider
|
|
8695
|
-
*/
|
|
8696
|
-
static async approve(token, amount, spender, spokeProvider, raw) {
|
|
8697
|
-
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
8698
|
-
const rawTx = {
|
|
8699
|
-
from: walletAddress,
|
|
8700
|
-
to: token,
|
|
8701
|
-
value: 0n,
|
|
8702
|
-
data: encodeFunctionData({
|
|
8703
|
-
abi: erc20Abi$1,
|
|
8704
|
-
functionName: "approve",
|
|
8705
|
-
args: [spender, amount]
|
|
8706
|
-
})
|
|
8707
|
-
};
|
|
8708
|
-
if (raw) {
|
|
8709
|
-
return rawTx;
|
|
8710
|
-
}
|
|
8711
|
-
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
8689
|
+
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
8712
8690
|
}
|
|
8713
8691
|
/**
|
|
8714
8692
|
* Encodes a transfer transaction for a token.
|
|
@@ -9052,57 +9030,41 @@ var EvmWalletAbstraction = class {
|
|
|
9052
9030
|
});
|
|
9053
9031
|
}
|
|
9054
9032
|
};
|
|
9055
|
-
var
|
|
9033
|
+
var SuiSpokeService = class _SuiSpokeService {
|
|
9056
9034
|
constructor() {
|
|
9057
9035
|
}
|
|
9058
9036
|
/**
|
|
9059
|
-
*
|
|
9060
|
-
*
|
|
9061
|
-
* -
|
|
9062
|
-
*
|
|
9063
|
-
*
|
|
9064
|
-
* @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9065
|
-
* @param {EvmSpokeProvider} spokeProvider - The EVM spoke provider.
|
|
9066
|
-
* @returns {Promise<bigint>} Estimated gas for the transaction.
|
|
9067
|
-
*
|
|
9068
|
-
* @example
|
|
9069
|
-
*
|
|
9070
|
-
* const rawTx: EvmRawTransaction = {
|
|
9071
|
-
* from: '0x1234...abcd', // sender address
|
|
9072
|
-
* to: '0xabcd...1234', // recipient address
|
|
9073
|
-
* value: 1000000000000000000n, // 1 ETH in wei
|
|
9074
|
-
* data: '0x', // no calldata
|
|
9075
|
-
* };
|
|
9076
|
-
*
|
|
9077
|
-
* // Assume spokeProvider is an initialized EvmSpokeProvider
|
|
9078
|
-
* const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
|
|
9079
|
-
* console.log(`Estimated gas: ${estimatedGas}`);
|
|
9037
|
+
* Estimate the gas for a transaction.
|
|
9038
|
+
* @param {SuiRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9039
|
+
* @param {SuiSpokeProvider} spokeProvider - The spoke provider.
|
|
9040
|
+
* @returns {Promise<bigint>} The estimated computation cost.
|
|
9080
9041
|
*/
|
|
9081
9042
|
static async estimateGas(rawTx, spokeProvider) {
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
data: rawTx.data
|
|
9043
|
+
const txb = Transaction.fromKind(rawTx.data);
|
|
9044
|
+
const result = await spokeProvider.publicClient.devInspectTransactionBlock({
|
|
9045
|
+
sender: rawTx.from,
|
|
9046
|
+
transactionBlock: txb
|
|
9087
9047
|
});
|
|
9048
|
+
return result.effects.gasUsed;
|
|
9088
9049
|
}
|
|
9089
9050
|
/**
|
|
9090
9051
|
* Deposit tokens to the spoke chain.
|
|
9091
|
-
* @param {
|
|
9092
|
-
* @param {
|
|
9052
|
+
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
9053
|
+
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9093
9054
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9094
|
-
* @
|
|
9055
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9056
|
+
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
9095
9057
|
*/
|
|
9096
9058
|
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9097
|
-
const
|
|
9059
|
+
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9098
9060
|
spokeProvider.chainConfig.chain.id,
|
|
9099
9061
|
params.from,
|
|
9100
9062
|
hubProvider
|
|
9101
9063
|
);
|
|
9102
|
-
return
|
|
9064
|
+
return _SuiSpokeService.transfer(
|
|
9103
9065
|
{
|
|
9104
9066
|
token: params.token,
|
|
9105
|
-
recipient:
|
|
9067
|
+
recipient: userWallet,
|
|
9106
9068
|
amount: params.amount,
|
|
9107
9069
|
data: params.data
|
|
9108
9070
|
},
|
|
@@ -9113,21 +9075,16 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
9113
9075
|
/**
|
|
9114
9076
|
* Get the balance of the token in the spoke chain.
|
|
9115
9077
|
* @param {Address} token - The address of the token to get the balance of.
|
|
9116
|
-
* @param {
|
|
9078
|
+
* @param {SuiSpokeProvider} spokeProvider - The spoke provider.
|
|
9117
9079
|
* @returns {Promise<bigint>} The balance of the token.
|
|
9118
9080
|
*/
|
|
9119
9081
|
static async getDeposit(token, spokeProvider) {
|
|
9120
|
-
return spokeProvider.
|
|
9121
|
-
address: token,
|
|
9122
|
-
abi: erc20Abi,
|
|
9123
|
-
functionName: "balanceOf",
|
|
9124
|
-
args: [token]
|
|
9125
|
-
});
|
|
9082
|
+
return spokeProvider.getBalance(token);
|
|
9126
9083
|
}
|
|
9127
9084
|
/**
|
|
9128
|
-
* Generate simulation parameters for deposit from
|
|
9129
|
-
* @param {
|
|
9130
|
-
* @param {
|
|
9085
|
+
* Generate simulation parameters for deposit from SuiSpokeDepositParams.
|
|
9086
|
+
* @param {SuiSpokeDepositParams} params - The deposit parameters.
|
|
9087
|
+
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9131
9088
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9132
9089
|
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9133
9090
|
*/
|
|
@@ -9137,219 +9094,681 @@ var EvmSpokeService = class _EvmSpokeService {
|
|
|
9137
9094
|
params.from,
|
|
9138
9095
|
hubProvider
|
|
9139
9096
|
);
|
|
9097
|
+
const encoder = new TextEncoder();
|
|
9140
9098
|
return {
|
|
9141
9099
|
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9142
|
-
token:
|
|
9100
|
+
token: toHex(encoder.encode(params.token)),
|
|
9143
9101
|
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9144
9102
|
to,
|
|
9145
9103
|
amount: params.amount,
|
|
9146
9104
|
data: params.data,
|
|
9147
|
-
srcAddress:
|
|
9148
|
-
spokeProvider.chainConfig.chain.id,
|
|
9149
|
-
spokeProvider.chainConfig.addresses.assetManager
|
|
9150
|
-
)
|
|
9105
|
+
srcAddress: toHex(encoder.encode(spokeProvider.chainConfig.addresses.originalAssetManager))
|
|
9151
9106
|
};
|
|
9152
9107
|
}
|
|
9153
9108
|
/**
|
|
9154
9109
|
* Calls a contract on the spoke chain using the user's wallet.
|
|
9155
|
-
* @param {HubAddress} from - The address of the user on the
|
|
9110
|
+
* @param {HubAddress} from - The address of the user on the spoke chain.
|
|
9156
9111
|
* @param {Hex} payload - The payload to send to the contract.
|
|
9157
|
-
* @param {
|
|
9112
|
+
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9158
9113
|
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9159
9114
|
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9160
|
-
* @returns {
|
|
9115
|
+
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
9161
9116
|
*/
|
|
9162
9117
|
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
9163
9118
|
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
9164
|
-
|
|
9165
|
-
return result;
|
|
9166
|
-
}
|
|
9167
|
-
/**
|
|
9168
|
-
* Transfers tokens to the hub chain.
|
|
9169
|
-
* @param {EvmTransferToHubParams} params - The parameters for the transfer, including:
|
|
9170
|
-
* - {Address} token: The address of the token to transfer (use address(0) for native token).
|
|
9171
|
-
* - {Address} recipient: The recipient address on the hub chain.
|
|
9172
|
-
* - {bigint} amount: The amount to transfer.
|
|
9173
|
-
* - {Hex} [data="0x"]: Additional data for the transfer.
|
|
9174
|
-
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9175
|
-
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9176
|
-
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9177
|
-
*/
|
|
9178
|
-
static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
|
|
9179
|
-
const txPayload = {
|
|
9180
|
-
address: spokeProvider.chainConfig.addresses.assetManager,
|
|
9181
|
-
value: token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase() ? amount : void 0
|
|
9182
|
-
};
|
|
9183
|
-
const from = await spokeProvider.walletProvider.getWalletAddress();
|
|
9184
|
-
const rawTx = {
|
|
9185
|
-
from,
|
|
9186
|
-
to: txPayload.address,
|
|
9187
|
-
value: txPayload.value ?? 0n,
|
|
9188
|
-
data: encodeFunctionData({
|
|
9189
|
-
abi: spokeAssetManagerAbi,
|
|
9190
|
-
functionName: "transfer",
|
|
9191
|
-
args: [token, recipient, amount, data]
|
|
9192
|
-
})
|
|
9193
|
-
};
|
|
9194
|
-
if (raw) {
|
|
9195
|
-
return rawTx;
|
|
9196
|
-
}
|
|
9197
|
-
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
9119
|
+
return _SuiSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
9198
9120
|
}
|
|
9199
9121
|
/**
|
|
9200
|
-
*
|
|
9201
|
-
* @param {
|
|
9202
|
-
* @
|
|
9203
|
-
* @param {Hex} payload - The payload to send.
|
|
9204
|
-
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9205
|
-
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9206
|
-
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9122
|
+
* Fetch the asset manager config from the spoke chain.
|
|
9123
|
+
* @param {SuiSpokeProvider} suiSpokeProvider - The spoke provider.
|
|
9124
|
+
* @returns {Promise<string>} The asset manager config.
|
|
9207
9125
|
*/
|
|
9208
|
-
static async
|
|
9209
|
-
const
|
|
9210
|
-
|
|
9211
|
-
const from = await spokeProvider.walletProvider.getWalletAddress();
|
|
9212
|
-
const rawTx = {
|
|
9213
|
-
from,
|
|
9214
|
-
to: txPayload.address,
|
|
9215
|
-
value: 0n,
|
|
9216
|
-
data: encodeFunctionData({
|
|
9217
|
-
abi: connectionAbi,
|
|
9218
|
-
functionName: "sendMessage",
|
|
9219
|
-
args: [dstChainId, dstAddress, payload]
|
|
9220
|
-
})
|
|
9221
|
-
};
|
|
9222
|
-
if (raw) {
|
|
9223
|
-
return rawTx;
|
|
9224
|
-
}
|
|
9225
|
-
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
9226
|
-
}
|
|
9227
|
-
};
|
|
9228
|
-
var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
9229
|
-
constructor() {
|
|
9126
|
+
static async fetchAssetManagerAddress(suiSpokeProvider) {
|
|
9127
|
+
const latestPackageId = await _SuiSpokeService.fetchLatestAssetManagerPackageId(suiSpokeProvider);
|
|
9128
|
+
return `${latestPackageId}::asset_manager::${suiSpokeProvider.chainConfig.addresses.assetManagerConfigId}`;
|
|
9230
9129
|
}
|
|
9231
9130
|
/**
|
|
9232
|
-
*
|
|
9233
|
-
* @param {
|
|
9234
|
-
* @
|
|
9235
|
-
* @returns {Promise<InjectiveGasEstimate>} The estimated gas for the transaction.
|
|
9131
|
+
* Fetch the latest asset manager package id from the spoke chain.
|
|
9132
|
+
* @param {SuiSpokeProvider} suiSpokeProvider - The spoke provider.
|
|
9133
|
+
* @returns {Promise<string>} The latest asset manager package id.
|
|
9236
9134
|
*/
|
|
9237
|
-
static async
|
|
9238
|
-
const
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9135
|
+
static async fetchLatestAssetManagerPackageId(suiSpokeProvider) {
|
|
9136
|
+
const configData = await suiSpokeProvider.publicClient.getObject({
|
|
9137
|
+
id: suiSpokeProvider.chainConfig.addresses.assetManagerConfigId,
|
|
9138
|
+
options: {
|
|
9139
|
+
showContent: true
|
|
9140
|
+
}
|
|
9243
9141
|
});
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
);
|
|
9264
|
-
return _InjectiveSpokeService.transfer(
|
|
9265
|
-
{
|
|
9266
|
-
token: params.token,
|
|
9267
|
-
recipient: userWallet,
|
|
9268
|
-
amount: params.amount.toString(),
|
|
9269
|
-
data: params.data
|
|
9270
|
-
},
|
|
9271
|
-
spokeProvider,
|
|
9272
|
-
raw
|
|
9273
|
-
);
|
|
9274
|
-
}
|
|
9275
|
-
/**
|
|
9276
|
-
* Generate simulation parameters for deposit from InjectiveSpokeDepositParams.
|
|
9277
|
-
* @param {InjectiveSpokeDepositParams} params - The deposit parameters.
|
|
9278
|
-
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9279
|
-
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9280
|
-
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9281
|
-
*/
|
|
9282
|
-
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9283
|
-
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9284
|
-
spokeProvider.chainConfig.chain.id,
|
|
9285
|
-
toHex(Buffer.from(params.from, "utf-8")),
|
|
9286
|
-
hubProvider
|
|
9287
|
-
);
|
|
9288
|
-
return {
|
|
9289
|
-
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9290
|
-
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9291
|
-
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9292
|
-
to,
|
|
9293
|
-
amount: params.amount,
|
|
9294
|
-
data: params.data,
|
|
9295
|
-
srcAddress: encodeAddress(
|
|
9296
|
-
spokeProvider.chainConfig.chain.id,
|
|
9297
|
-
spokeProvider.chainConfig.addresses.assetManager
|
|
9298
|
-
)
|
|
9299
|
-
};
|
|
9300
|
-
}
|
|
9301
|
-
/**
|
|
9302
|
-
* Get the balance of the token that deposited in the spoke chain Asset Manager.
|
|
9303
|
-
* @param {Address} token - The address of the token to get the balance of.
|
|
9304
|
-
* @param {InjectiveSpokeProvider} spokeProvider - The spoke provider.
|
|
9305
|
-
* @returns {Promise<bigint>} The balance of the token.
|
|
9306
|
-
*/
|
|
9307
|
-
static async getDeposit(token, spokeProvider) {
|
|
9308
|
-
const bal = await spokeProvider.getBalance(token);
|
|
9309
|
-
return BigInt(bal);
|
|
9310
|
-
}
|
|
9311
|
-
/**
|
|
9312
|
-
* Calls a contract on the spoke chain using the user's wallet.
|
|
9313
|
-
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
9314
|
-
* @param {Hex} payload - The payload to send to the contract.
|
|
9315
|
-
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9316
|
-
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9317
|
-
* @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9318
|
-
*/
|
|
9319
|
-
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
9320
|
-
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
9321
|
-
return _InjectiveSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
9142
|
+
if (configData.error) {
|
|
9143
|
+
throw new Error(`Failed to fetch asset manager id. Details: ${JSON.stringify(configData.error)}`);
|
|
9144
|
+
}
|
|
9145
|
+
if (!configData.data) {
|
|
9146
|
+
throw new Error("Asset manager id not found (no data)");
|
|
9147
|
+
}
|
|
9148
|
+
if (configData.data.content?.dataType !== "moveObject") {
|
|
9149
|
+
throw new Error("Asset manager id not found (not a move object)");
|
|
9150
|
+
}
|
|
9151
|
+
if (!("latest_package_id" in configData.data.content.fields)) {
|
|
9152
|
+
throw new Error("Asset manager id not found (no latest package id)");
|
|
9153
|
+
}
|
|
9154
|
+
const latestPackageId = configData.data.content.fields["latest_package_id"];
|
|
9155
|
+
if (typeof latestPackageId !== "string") {
|
|
9156
|
+
throw new Error("Asset manager id invalid (latest package id is not a string)");
|
|
9157
|
+
}
|
|
9158
|
+
if (!latestPackageId) {
|
|
9159
|
+
throw new Error("Asset manager id not found (no latest package id)");
|
|
9160
|
+
}
|
|
9161
|
+
return latestPackageId.toString();
|
|
9322
9162
|
}
|
|
9323
9163
|
/**
|
|
9324
9164
|
* Transfers tokens to the hub chain.
|
|
9325
|
-
* @param {
|
|
9165
|
+
* @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
|
|
9326
9166
|
* - {string} token: The address of the token to transfer (use address(0) for native token).
|
|
9327
9167
|
* - {Uint8Array} recipient: The recipient address on the hub chain.
|
|
9328
9168
|
* - {string} amount: The amount to transfer.
|
|
9329
9169
|
* - {Uint8Array} [data=new Uint8Array([])]: Additional data for the transfer.
|
|
9330
|
-
* @param {
|
|
9170
|
+
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9331
9171
|
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9332
|
-
* @returns {
|
|
9172
|
+
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
9333
9173
|
*/
|
|
9334
9174
|
static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
|
|
9335
|
-
|
|
9336
|
-
return InjectiveSpokeProvider.deposit(sender, token, recipient, amount, data, spokeProvider, raw);
|
|
9175
|
+
return spokeProvider.transfer(token, amount, fromHex(recipient, "bytes"), fromHex(data, "bytes"), raw);
|
|
9337
9176
|
}
|
|
9338
9177
|
/**
|
|
9339
9178
|
* Sends a message to the hub chain.
|
|
9340
9179
|
* @param {bigint} dstChainId - The chain ID of the hub chain.
|
|
9341
|
-
* @param {
|
|
9180
|
+
* @param {HubAddress} dstAddress - The address on the hub chain.
|
|
9342
9181
|
* @param {Hex} payload - The payload to send.
|
|
9343
|
-
* @param {
|
|
9344
|
-
* @
|
|
9182
|
+
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9183
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9184
|
+
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
9345
9185
|
*/
|
|
9346
9186
|
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
9347
|
-
|
|
9348
|
-
return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
|
|
9187
|
+
return spokeProvider.sendMessage(dstChainId, fromHex(dstAddress, "bytes"), fromHex(payload, "bytes"), raw);
|
|
9349
9188
|
}
|
|
9350
9189
|
};
|
|
9351
9190
|
|
|
9352
|
-
// src/
|
|
9191
|
+
// src/entities/sui/SuiSpokeProvider.ts
|
|
9192
|
+
var SuiSpokeProvider = class _SuiSpokeProvider {
|
|
9193
|
+
walletProvider;
|
|
9194
|
+
chainConfig;
|
|
9195
|
+
publicClient;
|
|
9196
|
+
assetManagerAddress;
|
|
9197
|
+
constructor(config, wallet_provider) {
|
|
9198
|
+
this.chainConfig = config;
|
|
9199
|
+
this.walletProvider = wallet_provider;
|
|
9200
|
+
this.publicClient = new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
9201
|
+
}
|
|
9202
|
+
async getBalance(token) {
|
|
9203
|
+
const assetmanager = this.splitAddress(await this.getAssetManagerAddress());
|
|
9204
|
+
const tx = new Transaction();
|
|
9205
|
+
const result = await this.walletProvider.viewContract(
|
|
9206
|
+
tx,
|
|
9207
|
+
assetmanager.packageId,
|
|
9208
|
+
assetmanager.moduleId,
|
|
9209
|
+
"get_token_balance",
|
|
9210
|
+
[tx.object(assetmanager.stateId)],
|
|
9211
|
+
[token]
|
|
9212
|
+
);
|
|
9213
|
+
if (!Array.isArray(result?.returnValues) || !Array.isArray(result.returnValues[0]) || result.returnValues[0][0] === void 0) {
|
|
9214
|
+
throw new Error("Failed to get Balance");
|
|
9215
|
+
}
|
|
9216
|
+
const val = result.returnValues[0][0];
|
|
9217
|
+
const str_u64 = bcs.U64.parse(Uint8Array.from(val));
|
|
9218
|
+
return BigInt(str_u64);
|
|
9219
|
+
}
|
|
9220
|
+
async transfer(token, amount, to, data, raw) {
|
|
9221
|
+
const isNative2 = token.toLowerCase() === this.chainConfig.nativeToken.toLowerCase();
|
|
9222
|
+
const tx = new Transaction();
|
|
9223
|
+
const walletAddress = await this.walletProvider.getWalletAddressBytes();
|
|
9224
|
+
const coin = isNative2 ? await this.getNativeCoin(tx, amount) : await this.getCoin(tx, token, amount, walletAddress);
|
|
9225
|
+
const connection = this.splitAddress(this.chainConfig.addresses.connection);
|
|
9226
|
+
const assetManager = this.splitAddress(await this.getAssetManagerAddress());
|
|
9227
|
+
tx.moveCall({
|
|
9228
|
+
target: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
9229
|
+
typeArguments: [token],
|
|
9230
|
+
arguments: [
|
|
9231
|
+
tx.object(assetManager.stateId),
|
|
9232
|
+
tx.object(connection.stateId),
|
|
9233
|
+
// Connection state object
|
|
9234
|
+
coin,
|
|
9235
|
+
tx.pure(bcs.vector(bcs.u8()).serialize(to)),
|
|
9236
|
+
tx.pure(bcs.vector(bcs.u8()).serialize(data))
|
|
9237
|
+
]
|
|
9238
|
+
});
|
|
9239
|
+
if (raw) {
|
|
9240
|
+
tx.setSender(walletAddress);
|
|
9241
|
+
const transactionRaw = await tx.build({
|
|
9242
|
+
client: this.publicClient,
|
|
9243
|
+
onlyTransactionKind: true
|
|
9244
|
+
});
|
|
9245
|
+
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
9246
|
+
return {
|
|
9247
|
+
from: walletAddress,
|
|
9248
|
+
to: `${assetManager.packageId}::${assetManager.moduleId}::transfer`,
|
|
9249
|
+
value: amount,
|
|
9250
|
+
data: transactionRawBase64String
|
|
9251
|
+
};
|
|
9252
|
+
}
|
|
9253
|
+
return this.walletProvider.signAndExecuteTxn(tx);
|
|
9254
|
+
}
|
|
9255
|
+
async getNativeCoin(tx, amount) {
|
|
9256
|
+
const coin = tx.splitCoins(tx.gas, [tx.pure.u64(amount)])[0];
|
|
9257
|
+
if (coin === void 0) {
|
|
9258
|
+
return Promise.reject(Error("[SuiIntentService.getNativeCoin] coin undefined"));
|
|
9259
|
+
}
|
|
9260
|
+
return coin;
|
|
9261
|
+
}
|
|
9262
|
+
async getCoin(tx, coin, amount, address) {
|
|
9263
|
+
const coins = await this.walletProvider.getCoins(address, coin);
|
|
9264
|
+
const objects = [];
|
|
9265
|
+
let totalAmount = BigInt(0);
|
|
9266
|
+
for (const coin2 of coins.data) {
|
|
9267
|
+
totalAmount += BigInt(coin2.balance);
|
|
9268
|
+
objects.push(coin2.coinObjectId);
|
|
9269
|
+
if (totalAmount >= amount) {
|
|
9270
|
+
break;
|
|
9271
|
+
}
|
|
9272
|
+
}
|
|
9273
|
+
const firstObject = objects[0];
|
|
9274
|
+
if (!firstObject) {
|
|
9275
|
+
throw new Error(`[SuiIntentService.getCoin] Coin=${coin} not found for address=${address} and amount=${amount}`);
|
|
9276
|
+
}
|
|
9277
|
+
if (objects.length > 1) {
|
|
9278
|
+
tx.mergeCoins(firstObject, objects.slice(1));
|
|
9279
|
+
}
|
|
9280
|
+
if (totalAmount === amount) {
|
|
9281
|
+
return tx.object(firstObject);
|
|
9282
|
+
}
|
|
9283
|
+
return tx.splitCoins(firstObject, [amount]);
|
|
9284
|
+
}
|
|
9285
|
+
splitAddress(address) {
|
|
9286
|
+
const parts = address.split("::");
|
|
9287
|
+
if (parts.length === 3) {
|
|
9288
|
+
if (parts[0] && parts[1] && parts[2]) {
|
|
9289
|
+
return { packageId: parts[0], moduleId: parts[1], stateId: parts[2] };
|
|
9290
|
+
}
|
|
9291
|
+
throw new Error("Invalid package address");
|
|
9292
|
+
}
|
|
9293
|
+
throw new Error("Invalid package address");
|
|
9294
|
+
}
|
|
9295
|
+
async sendMessage(dst_chain_id, dst_address, data, raw) {
|
|
9296
|
+
const txb = new Transaction();
|
|
9297
|
+
const connection = this.splitAddress(this.chainConfig.addresses.connection);
|
|
9298
|
+
txb.moveCall({
|
|
9299
|
+
target: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
|
|
9300
|
+
arguments: [
|
|
9301
|
+
txb.object(connection.stateId),
|
|
9302
|
+
txb.pure.u256(dst_chain_id),
|
|
9303
|
+
txb.pure(bcs.vector(bcs.u8()).serialize(dst_address)),
|
|
9304
|
+
txb.pure(bcs.vector(bcs.u8()).serialize(data))
|
|
9305
|
+
]
|
|
9306
|
+
});
|
|
9307
|
+
const walletAddress = await this.walletProvider.getWalletAddress();
|
|
9308
|
+
if (raw) {
|
|
9309
|
+
txb.setSender(walletAddress);
|
|
9310
|
+
const transactionRaw = await txb.build({
|
|
9311
|
+
client: this.publicClient,
|
|
9312
|
+
onlyTransactionKind: true
|
|
9313
|
+
});
|
|
9314
|
+
const transactionRawBase64String = Buffer.from(transactionRaw).toString("base64");
|
|
9315
|
+
return {
|
|
9316
|
+
from: walletAddress,
|
|
9317
|
+
to: `${connection.packageId}::${connection.moduleId}::send_message_ua`,
|
|
9318
|
+
value: 0n,
|
|
9319
|
+
data: transactionRawBase64String
|
|
9320
|
+
};
|
|
9321
|
+
}
|
|
9322
|
+
return this.walletProvider.signAndExecuteTxn(txb);
|
|
9323
|
+
}
|
|
9324
|
+
async configureAssetManagerHub(hubNetworkId, hubAssetManager) {
|
|
9325
|
+
const tx = new Transaction();
|
|
9326
|
+
const assetmanager = this.splitAddress(await this.getAssetManagerAddress());
|
|
9327
|
+
tx.moveCall({
|
|
9328
|
+
target: `${assetmanager.packageId}::${assetmanager.moduleId}::set_hub_details`,
|
|
9329
|
+
arguments: [tx.object(assetmanager.stateId), tx.pure.u64(hubNetworkId), tx.pure.vector("u8", hubAssetManager)]
|
|
9330
|
+
});
|
|
9331
|
+
const result = await this.walletProvider.signAndExecuteTxn(tx);
|
|
9332
|
+
return result;
|
|
9333
|
+
}
|
|
9334
|
+
async getWalletAddress() {
|
|
9335
|
+
return this.walletProvider.getWalletAddress();
|
|
9336
|
+
}
|
|
9337
|
+
async getWalletAddressBytes() {
|
|
9338
|
+
const address = await this.getWalletAddress();
|
|
9339
|
+
return _SuiSpokeProvider.getAddressBCSBytes(address);
|
|
9340
|
+
}
|
|
9341
|
+
static getAddressBCSBytes(suiaddress) {
|
|
9342
|
+
return toHex(bcs.Address.serialize(suiaddress).toBytes());
|
|
9343
|
+
}
|
|
9344
|
+
async getAssetManagerAddress() {
|
|
9345
|
+
if (!this.assetManagerAddress) {
|
|
9346
|
+
this.assetManagerAddress = await SuiSpokeService.fetchAssetManagerAddress(this);
|
|
9347
|
+
}
|
|
9348
|
+
return this.assetManagerAddress.toString();
|
|
9349
|
+
}
|
|
9350
|
+
};
|
|
9351
|
+
|
|
9352
|
+
// src/entities/solana/SolanaSpokeProvider.ts
|
|
9353
|
+
var SolanaSpokeProvider = class {
|
|
9354
|
+
walletProvider;
|
|
9355
|
+
chainConfig;
|
|
9356
|
+
constructor(walletProvider, chainConfig) {
|
|
9357
|
+
this.walletProvider = walletProvider;
|
|
9358
|
+
this.chainConfig = chainConfig;
|
|
9359
|
+
}
|
|
9360
|
+
};
|
|
9361
|
+
var solanaSpokeChainConfig = spokeChainConfig[SOLANA_MAINNET_CHAIN_ID];
|
|
9362
|
+
function getSolanaAddressBytes(address) {
|
|
9363
|
+
return `0x${Buffer.from(address.toBytes()).toString("hex")}`;
|
|
9364
|
+
}
|
|
9365
|
+
function isNative(address) {
|
|
9366
|
+
if (address.equals(new PublicKey(solanaSpokeChainConfig.nativeToken))) {
|
|
9367
|
+
return true;
|
|
9368
|
+
}
|
|
9369
|
+
return false;
|
|
9370
|
+
}
|
|
9371
|
+
function convertTransactionInstructionToRaw(instruction) {
|
|
9372
|
+
return {
|
|
9373
|
+
keys: instruction.keys.map((key) => ({
|
|
9374
|
+
pubkey: key.pubkey.toBase58(),
|
|
9375
|
+
isSigner: key.isSigner,
|
|
9376
|
+
isWritable: key.isWritable
|
|
9377
|
+
})),
|
|
9378
|
+
programId: instruction.programId.toBase58(),
|
|
9379
|
+
data: instruction.data
|
|
9380
|
+
};
|
|
9381
|
+
}
|
|
9382
|
+
|
|
9383
|
+
// src/entities/icon/HanaWalletConnector.ts
|
|
9384
|
+
function requestAddress() {
|
|
9385
|
+
return new Promise((resolve) => {
|
|
9386
|
+
const eventHandler = (event) => {
|
|
9387
|
+
const customEvent = event;
|
|
9388
|
+
const response = customEvent.detail;
|
|
9389
|
+
if (isResponseAddressType(response)) {
|
|
9390
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9391
|
+
resolve({
|
|
9392
|
+
ok: true,
|
|
9393
|
+
value: response.payload
|
|
9394
|
+
});
|
|
9395
|
+
}
|
|
9396
|
+
};
|
|
9397
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9398
|
+
window.addEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9399
|
+
window.dispatchEvent(
|
|
9400
|
+
new CustomEvent("ICONEX_RELAY_REQUEST", {
|
|
9401
|
+
detail: {
|
|
9402
|
+
type: "REQUEST_ADDRESS"
|
|
9403
|
+
}
|
|
9404
|
+
})
|
|
9405
|
+
);
|
|
9406
|
+
});
|
|
9407
|
+
}
|
|
9408
|
+
function requestSigning(from, hash) {
|
|
9409
|
+
return new Promise((resolve, reject) => {
|
|
9410
|
+
const signRequest = new CustomEvent("ICONEX_RELAY_REQUEST", {
|
|
9411
|
+
detail: {
|
|
9412
|
+
type: "REQUEST_SIGNING",
|
|
9413
|
+
payload: {
|
|
9414
|
+
from,
|
|
9415
|
+
hash
|
|
9416
|
+
}
|
|
9417
|
+
}
|
|
9418
|
+
});
|
|
9419
|
+
const eventHandler = (event) => {
|
|
9420
|
+
const customEvent = event;
|
|
9421
|
+
const response = customEvent.detail;
|
|
9422
|
+
if (isResponseSigningType(response)) {
|
|
9423
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9424
|
+
resolve({
|
|
9425
|
+
ok: true,
|
|
9426
|
+
value: response.payload
|
|
9427
|
+
});
|
|
9428
|
+
} else if (response.type === "CANCEL_SIGNING") {
|
|
9429
|
+
reject(new Error("CANCEL_SIGNING"));
|
|
9430
|
+
}
|
|
9431
|
+
};
|
|
9432
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9433
|
+
window.addEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9434
|
+
window.dispatchEvent(signRequest);
|
|
9435
|
+
});
|
|
9436
|
+
}
|
|
9437
|
+
function requestJsonRpc(rawTransaction, id = 99999) {
|
|
9438
|
+
return new Promise((resolve, reject) => {
|
|
9439
|
+
const eventHandler = (event) => {
|
|
9440
|
+
const customEvent = event;
|
|
9441
|
+
const { type, payload } = customEvent.detail;
|
|
9442
|
+
if (type === "RESPONSE_JSON-RPC") {
|
|
9443
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9444
|
+
if (isJsonRpcPayloadResponse(payload)) {
|
|
9445
|
+
resolve({
|
|
9446
|
+
ok: true,
|
|
9447
|
+
value: payload
|
|
9448
|
+
});
|
|
9449
|
+
} else {
|
|
9450
|
+
reject(new Error("Invalid payload response type (expected JsonRpcPayloadResponse)"));
|
|
9451
|
+
}
|
|
9452
|
+
} else if (type === "CANCEL_JSON-RPC") {
|
|
9453
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9454
|
+
reject(new Error("CANCEL_JSON-RPC"));
|
|
9455
|
+
}
|
|
9456
|
+
};
|
|
9457
|
+
window.removeEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9458
|
+
window.addEventListener("ICONEX_RELAY_RESPONSE", eventHandler, false);
|
|
9459
|
+
window.dispatchEvent(
|
|
9460
|
+
new CustomEvent("ICONEX_RELAY_REQUEST", {
|
|
9461
|
+
detail: {
|
|
9462
|
+
type: "REQUEST_JSON-RPC",
|
|
9463
|
+
payload: {
|
|
9464
|
+
jsonrpc: "2.0",
|
|
9465
|
+
method: "icx_sendTransaction",
|
|
9466
|
+
params: rawTransaction,
|
|
9467
|
+
id
|
|
9468
|
+
}
|
|
9469
|
+
}
|
|
9470
|
+
})
|
|
9471
|
+
);
|
|
9472
|
+
});
|
|
9473
|
+
}
|
|
9474
|
+
var EvmSpokeService = class _EvmSpokeService {
|
|
9475
|
+
constructor() {
|
|
9476
|
+
}
|
|
9477
|
+
/**
|
|
9478
|
+
* Estimates the gas necessary to complete a transaction without submitting it to the network.
|
|
9479
|
+
*
|
|
9480
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateGas
|
|
9481
|
+
* - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
|
|
9482
|
+
*
|
|
9483
|
+
* @param {EvmRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9484
|
+
* @param {EvmSpokeProvider} spokeProvider - The EVM spoke provider.
|
|
9485
|
+
* @returns {Promise<bigint>} Estimated gas for the transaction.
|
|
9486
|
+
*
|
|
9487
|
+
* @example
|
|
9488
|
+
*
|
|
9489
|
+
* const rawTx: EvmRawTransaction = {
|
|
9490
|
+
* from: '0x1234...abcd', // sender address
|
|
9491
|
+
* to: '0xabcd...1234', // recipient address
|
|
9492
|
+
* value: 1000000000000000000n, // 1 ETH in wei
|
|
9493
|
+
* data: '0x', // no calldata
|
|
9494
|
+
* };
|
|
9495
|
+
*
|
|
9496
|
+
* // Assume spokeProvider is an initialized EvmSpokeProvider
|
|
9497
|
+
* const estimatedGas = await EvmSpokeService.estimateGas(rawTx, spokeProvider);
|
|
9498
|
+
* console.log(`Estimated gas: ${estimatedGas}`);
|
|
9499
|
+
*/
|
|
9500
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9501
|
+
return spokeProvider.publicClient.estimateGas({
|
|
9502
|
+
account: rawTx.from,
|
|
9503
|
+
to: rawTx.to,
|
|
9504
|
+
value: rawTx.value,
|
|
9505
|
+
data: rawTx.data
|
|
9506
|
+
});
|
|
9507
|
+
}
|
|
9508
|
+
/**
|
|
9509
|
+
* Deposit tokens to the spoke chain.
|
|
9510
|
+
* @param {EvmSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
9511
|
+
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9512
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9513
|
+
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9514
|
+
*/
|
|
9515
|
+
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9516
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9517
|
+
spokeProvider.chainConfig.chain.id,
|
|
9518
|
+
params.from,
|
|
9519
|
+
hubProvider
|
|
9520
|
+
);
|
|
9521
|
+
return _EvmSpokeService.transfer(
|
|
9522
|
+
{
|
|
9523
|
+
token: params.token,
|
|
9524
|
+
recipient: to,
|
|
9525
|
+
amount: params.amount,
|
|
9526
|
+
data: params.data
|
|
9527
|
+
},
|
|
9528
|
+
spokeProvider,
|
|
9529
|
+
raw
|
|
9530
|
+
);
|
|
9531
|
+
}
|
|
9532
|
+
/**
|
|
9533
|
+
* Get the balance of the token in the spoke chain.
|
|
9534
|
+
* @param {Address} token - The address of the token to get the balance of.
|
|
9535
|
+
* @param {EvmSpokeProvider} spokeProvider - The spoke provider.
|
|
9536
|
+
* @returns {Promise<bigint>} The balance of the token.
|
|
9537
|
+
*/
|
|
9538
|
+
static async getDeposit(token, spokeProvider) {
|
|
9539
|
+
return spokeProvider.publicClient.readContract({
|
|
9540
|
+
address: token,
|
|
9541
|
+
abi: erc20Abi,
|
|
9542
|
+
functionName: "balanceOf",
|
|
9543
|
+
args: [spokeProvider.chainConfig.addresses.assetManager]
|
|
9544
|
+
});
|
|
9545
|
+
}
|
|
9546
|
+
/**
|
|
9547
|
+
* Generate simulation parameters for deposit from EvmSpokeDepositParams.
|
|
9548
|
+
* @param {EvmSpokeDepositParams} params - The deposit parameters.
|
|
9549
|
+
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9550
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9551
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9552
|
+
*/
|
|
9553
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9554
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9555
|
+
spokeProvider.chainConfig.chain.id,
|
|
9556
|
+
params.from,
|
|
9557
|
+
hubProvider
|
|
9558
|
+
);
|
|
9559
|
+
return {
|
|
9560
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9561
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9562
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9563
|
+
to,
|
|
9564
|
+
amount: params.amount,
|
|
9565
|
+
data: params.data,
|
|
9566
|
+
srcAddress: encodeAddress(
|
|
9567
|
+
spokeProvider.chainConfig.chain.id,
|
|
9568
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9569
|
+
)
|
|
9570
|
+
};
|
|
9571
|
+
}
|
|
9572
|
+
/**
|
|
9573
|
+
* Calls a contract on the spoke chain using the user's wallet.
|
|
9574
|
+
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
9575
|
+
* @param {Hex} payload - The payload to send to the contract.
|
|
9576
|
+
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9577
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9578
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9579
|
+
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9580
|
+
*/
|
|
9581
|
+
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
9582
|
+
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
9583
|
+
const result = await _EvmSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
9584
|
+
return result;
|
|
9585
|
+
}
|
|
9586
|
+
/**
|
|
9587
|
+
* Transfers tokens to the hub chain.
|
|
9588
|
+
* @param {EvmTransferToHubParams} params - The parameters for the transfer, including:
|
|
9589
|
+
* - {Address} token: The address of the token to transfer (use address(0) for native token).
|
|
9590
|
+
* - {Address} recipient: The recipient address on the hub chain.
|
|
9591
|
+
* - {bigint} amount: The amount to transfer.
|
|
9592
|
+
* - {Hex} [data="0x"]: Additional data for the transfer.
|
|
9593
|
+
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9594
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9595
|
+
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9596
|
+
*/
|
|
9597
|
+
static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
|
|
9598
|
+
const txPayload = {
|
|
9599
|
+
address: spokeProvider.chainConfig.addresses.assetManager,
|
|
9600
|
+
value: token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase() ? amount : void 0
|
|
9601
|
+
};
|
|
9602
|
+
const from = await spokeProvider.walletProvider.getWalletAddress();
|
|
9603
|
+
const rawTx = {
|
|
9604
|
+
from,
|
|
9605
|
+
to: txPayload.address,
|
|
9606
|
+
value: txPayload.value ?? 0n,
|
|
9607
|
+
data: encodeFunctionData({
|
|
9608
|
+
abi: spokeAssetManagerAbi,
|
|
9609
|
+
functionName: "transfer",
|
|
9610
|
+
args: [token, recipient, amount, data]
|
|
9611
|
+
})
|
|
9612
|
+
};
|
|
9613
|
+
if (raw) {
|
|
9614
|
+
return rawTx;
|
|
9615
|
+
}
|
|
9616
|
+
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
9617
|
+
}
|
|
9618
|
+
/**
|
|
9619
|
+
* Sends a message to the hub chain.
|
|
9620
|
+
* @param {bigint} dstChainId - The chain ID of the hub chain.
|
|
9621
|
+
* @param {Address} dstAddress - The address on the hub chain.
|
|
9622
|
+
* @param {Hex} payload - The payload to send.
|
|
9623
|
+
* @param {EvmSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9624
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9625
|
+
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9626
|
+
*/
|
|
9627
|
+
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
9628
|
+
const txPayload = {
|
|
9629
|
+
address: spokeProvider.chainConfig.addresses.connection};
|
|
9630
|
+
const from = await spokeProvider.walletProvider.getWalletAddress();
|
|
9631
|
+
const rawTx = {
|
|
9632
|
+
from,
|
|
9633
|
+
to: txPayload.address,
|
|
9634
|
+
value: 0n,
|
|
9635
|
+
data: encodeFunctionData({
|
|
9636
|
+
abi: connectionAbi,
|
|
9637
|
+
functionName: "sendMessage",
|
|
9638
|
+
args: [dstChainId, dstAddress, payload]
|
|
9639
|
+
})
|
|
9640
|
+
};
|
|
9641
|
+
if (raw) {
|
|
9642
|
+
return rawTx;
|
|
9643
|
+
}
|
|
9644
|
+
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
9645
|
+
}
|
|
9646
|
+
};
|
|
9647
|
+
var InjectiveSpokeService = class _InjectiveSpokeService {
|
|
9648
|
+
constructor() {
|
|
9649
|
+
}
|
|
9650
|
+
/**
|
|
9651
|
+
* Estimate the gas for a transaction.
|
|
9652
|
+
* @param {InjectiveRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9653
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9654
|
+
* @returns {Promise<InjectiveGasEstimate>} The estimated gas for the transaction.
|
|
9655
|
+
*/
|
|
9656
|
+
static async estimateGas(rawTx, spokeProvider) {
|
|
9657
|
+
const txRaw = CosmosTxV1Beta1Tx.TxRaw.fromPartial({
|
|
9658
|
+
bodyBytes: rawTx.signedDoc.bodyBytes,
|
|
9659
|
+
authInfoBytes: rawTx.signedDoc.authInfoBytes,
|
|
9660
|
+
signatures: []
|
|
9661
|
+
// not required for simulation
|
|
9662
|
+
});
|
|
9663
|
+
const { gasInfo } = await spokeProvider.txClient.simulate(txRaw);
|
|
9664
|
+
return {
|
|
9665
|
+
gasWanted: gasInfo.gasWanted,
|
|
9666
|
+
gasUsed: gasInfo.gasUsed
|
|
9667
|
+
};
|
|
9668
|
+
}
|
|
9669
|
+
/**
|
|
9670
|
+
* Deposit tokens to the spoke chain.
|
|
9671
|
+
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
9672
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9673
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9674
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9675
|
+
* @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9676
|
+
*/
|
|
9677
|
+
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9678
|
+
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9679
|
+
spokeProvider.chainConfig.chain.id,
|
|
9680
|
+
toHex(Buffer.from(params.from, "utf-8")),
|
|
9681
|
+
hubProvider
|
|
9682
|
+
);
|
|
9683
|
+
return _InjectiveSpokeService.transfer(
|
|
9684
|
+
{
|
|
9685
|
+
token: params.token,
|
|
9686
|
+
recipient: userWallet,
|
|
9687
|
+
amount: params.amount.toString(),
|
|
9688
|
+
data: params.data
|
|
9689
|
+
},
|
|
9690
|
+
spokeProvider,
|
|
9691
|
+
raw
|
|
9692
|
+
);
|
|
9693
|
+
}
|
|
9694
|
+
/**
|
|
9695
|
+
* Generate simulation parameters for deposit from InjectiveSpokeDepositParams.
|
|
9696
|
+
* @param {InjectiveSpokeDepositParams} params - The deposit parameters.
|
|
9697
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9698
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9699
|
+
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9700
|
+
*/
|
|
9701
|
+
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9702
|
+
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9703
|
+
spokeProvider.chainConfig.chain.id,
|
|
9704
|
+
toHex(Buffer.from(params.from, "utf-8")),
|
|
9705
|
+
hubProvider
|
|
9706
|
+
);
|
|
9707
|
+
return {
|
|
9708
|
+
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9709
|
+
token: encodeAddress(spokeProvider.chainConfig.chain.id, params.token),
|
|
9710
|
+
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9711
|
+
to,
|
|
9712
|
+
amount: params.amount,
|
|
9713
|
+
data: params.data,
|
|
9714
|
+
srcAddress: encodeAddress(
|
|
9715
|
+
spokeProvider.chainConfig.chain.id,
|
|
9716
|
+
spokeProvider.chainConfig.addresses.assetManager
|
|
9717
|
+
)
|
|
9718
|
+
};
|
|
9719
|
+
}
|
|
9720
|
+
/**
|
|
9721
|
+
* Get the balance of the token that deposited in the spoke chain Asset Manager.
|
|
9722
|
+
* @param {Address} token - The address of the token to get the balance of.
|
|
9723
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The spoke provider.
|
|
9724
|
+
* @returns {Promise<bigint>} The balance of the token.
|
|
9725
|
+
*/
|
|
9726
|
+
static async getDeposit(token, spokeProvider) {
|
|
9727
|
+
const bal = await spokeProvider.getBalance(token);
|
|
9728
|
+
return BigInt(bal);
|
|
9729
|
+
}
|
|
9730
|
+
/**
|
|
9731
|
+
* Calls a contract on the spoke chain using the user's wallet.
|
|
9732
|
+
* @param {HubAddress} from - The address of the user on the hub chain.
|
|
9733
|
+
* @param {Hex} payload - The payload to send to the contract.
|
|
9734
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9735
|
+
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9736
|
+
* @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9737
|
+
*/
|
|
9738
|
+
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
9739
|
+
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
9740
|
+
return _InjectiveSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
9741
|
+
}
|
|
9742
|
+
/**
|
|
9743
|
+
* Transfers tokens to the hub chain.
|
|
9744
|
+
* @param {InjectiveTransferToHubParams} params - The parameters for the transfer, including:
|
|
9745
|
+
* - {string} token: The address of the token to transfer (use address(0) for native token).
|
|
9746
|
+
* - {Uint8Array} recipient: The recipient address on the hub chain.
|
|
9747
|
+
* - {string} amount: The amount to transfer.
|
|
9748
|
+
* - {Uint8Array} [data=new Uint8Array([])]: Additional data for the transfer.
|
|
9749
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9750
|
+
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9751
|
+
* @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9752
|
+
*/
|
|
9753
|
+
static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
|
|
9754
|
+
const sender = await spokeProvider.walletProvider.getWalletAddress();
|
|
9755
|
+
return InjectiveSpokeProvider.deposit(sender, token, recipient, amount, data, spokeProvider, raw);
|
|
9756
|
+
}
|
|
9757
|
+
/**
|
|
9758
|
+
* Sends a message to the hub chain.
|
|
9759
|
+
* @param {bigint} dstChainId - The chain ID of the hub chain.
|
|
9760
|
+
* @param {Address} dstAddress - The address on the hub chain.
|
|
9761
|
+
* @param {Hex} payload - The payload to send.
|
|
9762
|
+
* @param {InjectiveSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9763
|
+
* @returns {PromiseInjectiveTxReturnType<R>} A promise that resolves to the transaction hash.
|
|
9764
|
+
*/
|
|
9765
|
+
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
9766
|
+
const sender = await spokeProvider.walletProvider.getWalletAddress();
|
|
9767
|
+
return spokeProvider.send_message(sender, dstChainId.toString(), dstAddress, payload, raw);
|
|
9768
|
+
}
|
|
9769
|
+
};
|
|
9770
|
+
|
|
9771
|
+
// src/utils/icon-utils.ts
|
|
9353
9772
|
async function estimateStepCost(rawTx, debugRpcUrl) {
|
|
9354
9773
|
try {
|
|
9355
9774
|
const tmpRawTx = { ...rawTx };
|
|
@@ -9634,18 +10053,14 @@ var SolanaSpokeService = class _SolanaSpokeService {
|
|
|
9634
10053
|
);
|
|
9635
10054
|
}
|
|
9636
10055
|
static async getDeposit(token, spokeProvider) {
|
|
9637
|
-
const
|
|
9638
|
-
|
|
9639
|
-
spokeProvider.chainConfig.rpcUrl,
|
|
9640
|
-
spokeProvider.chainConfig.addresses.assetManager
|
|
9641
|
-
);
|
|
9642
|
-
const solToken = new PublicKey(Buffer.from(token, "hex"));
|
|
10056
|
+
const assetManagerProgramId = new PublicKey(spokeProvider.chainConfig.addresses.assetManager);
|
|
10057
|
+
const solToken = new PublicKey(token);
|
|
9643
10058
|
if (isNative(new PublicKey(solToken))) {
|
|
9644
|
-
const vaultNative = AssetManagerPDA.vault_native(
|
|
10059
|
+
const vaultNative = AssetManagerPDA.vault_native(assetManagerProgramId);
|
|
9645
10060
|
const balance = await spokeProvider.walletProvider.getBalance(vaultNative.pda.toBase58());
|
|
9646
10061
|
return BigInt(balance);
|
|
9647
10062
|
}
|
|
9648
|
-
const vaultToken = AssetManagerPDA.vault_token(
|
|
10063
|
+
const vaultToken = AssetManagerPDA.vault_token(assetManagerProgramId, new PublicKey(solToken));
|
|
9649
10064
|
const tokenAccount = await spokeProvider.walletProvider.getTokenAccountBalance(vaultToken.pda.toBase58());
|
|
9650
10065
|
return BigInt(tokenAccount.value.amount);
|
|
9651
10066
|
}
|
|
@@ -9853,6 +10268,12 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
9853
10268
|
raw
|
|
9854
10269
|
);
|
|
9855
10270
|
}
|
|
10271
|
+
/**
|
|
10272
|
+
* Get the balance of the token in the spoke chain asset manager.
|
|
10273
|
+
* @param token - The address of the token to get the balance of.
|
|
10274
|
+
* @param spokeProvider - The spoke provider.
|
|
10275
|
+
* @returns The balance of the token.
|
|
10276
|
+
*/
|
|
9856
10277
|
static async getDeposit(token, spokeProvider) {
|
|
9857
10278
|
return BigInt(await spokeProvider.getBalance(token));
|
|
9858
10279
|
}
|
|
@@ -9901,131 +10322,16 @@ var StellarSpokeService = class _StellarSpokeService {
|
|
|
9901
10322
|
amount.toString(),
|
|
9902
10323
|
fromHex(recipient, "bytes"),
|
|
9903
10324
|
fromHex(data, "bytes"),
|
|
9904
|
-
raw
|
|
9905
|
-
);
|
|
9906
|
-
}
|
|
9907
|
-
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
9908
|
-
return await spokeProvider.sendMessage(
|
|
9909
|
-
dstChainId.toString(),
|
|
9910
|
-
fromHex(dstAddress, "bytes"),
|
|
9911
|
-
fromHex(payload, "bytes"),
|
|
9912
|
-
raw
|
|
9913
|
-
);
|
|
9914
|
-
}
|
|
9915
|
-
};
|
|
9916
|
-
var SuiSpokeService = class _SuiSpokeService {
|
|
9917
|
-
constructor() {
|
|
9918
|
-
}
|
|
9919
|
-
/**
|
|
9920
|
-
* Estimate the gas for a transaction.
|
|
9921
|
-
* @param {SuiRawTransaction} rawTx - The raw transaction to estimate the gas for.
|
|
9922
|
-
* @param {SuiSpokeProvider} spokeProvider - The spoke provider.
|
|
9923
|
-
* @returns {Promise<bigint>} The estimated computation cost.
|
|
9924
|
-
*/
|
|
9925
|
-
static async estimateGas(rawTx, spokeProvider) {
|
|
9926
|
-
const txb = Transaction.fromKind(rawTx.data);
|
|
9927
|
-
const result = await spokeProvider.publicClient.devInspectTransactionBlock({
|
|
9928
|
-
sender: rawTx.from,
|
|
9929
|
-
transactionBlock: txb
|
|
9930
|
-
});
|
|
9931
|
-
return result.effects.gasUsed;
|
|
9932
|
-
}
|
|
9933
|
-
/**
|
|
9934
|
-
* Deposit tokens to the spoke chain.
|
|
9935
|
-
* @param {InjectiveSpokeDepositParams} params - The parameters for the deposit, including the user's address, token address, amount, and additional data.
|
|
9936
|
-
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9937
|
-
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9938
|
-
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9939
|
-
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
9940
|
-
*/
|
|
9941
|
-
static async deposit(params, spokeProvider, hubProvider, raw) {
|
|
9942
|
-
const userWallet = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9943
|
-
spokeProvider.chainConfig.chain.id,
|
|
9944
|
-
params.from,
|
|
9945
|
-
hubProvider
|
|
9946
|
-
);
|
|
9947
|
-
return _SuiSpokeService.transfer(
|
|
9948
|
-
{
|
|
9949
|
-
token: params.token,
|
|
9950
|
-
recipient: userWallet,
|
|
9951
|
-
amount: params.amount,
|
|
9952
|
-
data: params.data
|
|
9953
|
-
},
|
|
9954
|
-
spokeProvider,
|
|
9955
|
-
raw
|
|
9956
|
-
);
|
|
9957
|
-
}
|
|
9958
|
-
/**
|
|
9959
|
-
* Get the balance of the token in the spoke chain.
|
|
9960
|
-
* @param {Address} token - The address of the token to get the balance of.
|
|
9961
|
-
* @param {SuiSpokeProvider} spokeProvider - The spoke provider.
|
|
9962
|
-
* @returns {Promise<bigint>} The balance of the token.
|
|
9963
|
-
*/
|
|
9964
|
-
static async getDeposit(token, spokeProvider) {
|
|
9965
|
-
return spokeProvider.getBalance(token);
|
|
9966
|
-
}
|
|
9967
|
-
/**
|
|
9968
|
-
* Generate simulation parameters for deposit from SuiSpokeDepositParams.
|
|
9969
|
-
* @param {SuiSpokeDepositParams} params - The deposit parameters.
|
|
9970
|
-
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9971
|
-
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9972
|
-
* @returns {Promise<DepositSimulationParams>} The simulation parameters.
|
|
9973
|
-
*/
|
|
9974
|
-
static async getSimulateDepositParams(params, spokeProvider, hubProvider) {
|
|
9975
|
-
const to = params.to ?? await EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9976
|
-
spokeProvider.chainConfig.chain.id,
|
|
9977
|
-
params.from,
|
|
9978
|
-
hubProvider
|
|
9979
|
-
);
|
|
9980
|
-
const encoder = new TextEncoder();
|
|
9981
|
-
return {
|
|
9982
|
-
spokeChainID: spokeProvider.chainConfig.chain.id,
|
|
9983
|
-
token: toHex(encoder.encode(params.token)),
|
|
9984
|
-
from: encodeAddress(spokeProvider.chainConfig.chain.id, params.from),
|
|
9985
|
-
to,
|
|
9986
|
-
amount: params.amount,
|
|
9987
|
-
data: params.data,
|
|
9988
|
-
srcAddress: toHex(encoder.encode(spokeProvider.chainConfig.addresses.assetManagerId))
|
|
9989
|
-
};
|
|
9990
|
-
}
|
|
9991
|
-
/**
|
|
9992
|
-
* Calls a contract on the spoke chain using the user's wallet.
|
|
9993
|
-
* @param {HubAddress} from - The address of the user on the spoke chain.
|
|
9994
|
-
* @param {Hex} payload - The payload to send to the contract.
|
|
9995
|
-
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
9996
|
-
* @param {EvmHubProvider} hubProvider - The provider for the hub chain.
|
|
9997
|
-
* @param {boolean} raw - The return type raw or just transaction hash
|
|
9998
|
-
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
9999
|
-
*/
|
|
10000
|
-
static async callWallet(from, payload, spokeProvider, hubProvider, raw) {
|
|
10001
|
-
const relayId = getIntentRelayChainId(hubProvider.chainConfig.chain.id);
|
|
10002
|
-
return _SuiSpokeService.call(BigInt(relayId), from, payload, spokeProvider, raw);
|
|
10003
|
-
}
|
|
10004
|
-
/**
|
|
10005
|
-
* Transfers tokens to the hub chain.
|
|
10006
|
-
* @param {SuiTransferToHubParams} params - The parameters for the transfer, including:
|
|
10007
|
-
* - {string} token: The address of the token to transfer (use address(0) for native token).
|
|
10008
|
-
* - {Uint8Array} recipient: The recipient address on the hub chain.
|
|
10009
|
-
* - {string} amount: The amount to transfer.
|
|
10010
|
-
* - {Uint8Array} [data=new Uint8Array([])]: Additional data for the transfer.
|
|
10011
|
-
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
10012
|
-
* @param {boolean} raw - The return type raw or just transaction hash
|
|
10013
|
-
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
10014
|
-
*/
|
|
10015
|
-
static async transfer({ token, recipient, amount, data = "0x" }, spokeProvider, raw) {
|
|
10016
|
-
return spokeProvider.transfer(token, amount, fromHex(recipient, "bytes"), fromHex(data, "bytes"), raw);
|
|
10017
|
-
}
|
|
10018
|
-
/**
|
|
10019
|
-
* Sends a message to the hub chain.
|
|
10020
|
-
* @param {bigint} dstChainId - The chain ID of the hub chain.
|
|
10021
|
-
* @param {HubAddress} dstAddress - The address on the hub chain.
|
|
10022
|
-
* @param {Hex} payload - The payload to send.
|
|
10023
|
-
* @param {SuiSpokeProvider} spokeProvider - The provider for the spoke chain.
|
|
10024
|
-
* @param {boolean} raw - The return type raw or just transaction hash
|
|
10025
|
-
* @returns {PromiseSuiTxReturnType<R>} A promise that resolves to the transaction hash or raw transaction base64 string.
|
|
10026
|
-
*/
|
|
10325
|
+
raw
|
|
10326
|
+
);
|
|
10327
|
+
}
|
|
10027
10328
|
static async call(dstChainId, dstAddress, payload, spokeProvider, raw) {
|
|
10028
|
-
return spokeProvider.sendMessage(
|
|
10329
|
+
return await spokeProvider.sendMessage(
|
|
10330
|
+
dstChainId.toString(),
|
|
10331
|
+
fromHex(dstAddress, "bytes"),
|
|
10332
|
+
fromHex(payload, "bytes"),
|
|
10333
|
+
raw
|
|
10334
|
+
);
|
|
10029
10335
|
}
|
|
10030
10336
|
};
|
|
10031
10337
|
var SonicSpokeService = class _SonicSpokeService {
|
|
@@ -10084,7 +10390,7 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10084
10390
|
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash
|
|
10085
10391
|
*/
|
|
10086
10392
|
static async deposit(params, spokeProvider, raw) {
|
|
10087
|
-
|
|
10393
|
+
invariant12(spokeProvider instanceof SonicSpokeProvider, "[SonicSpokeService] invalid spoke provider");
|
|
10088
10394
|
const userHubAddress = params.to ?? await _SonicSpokeService.getUserRouter(params.from, spokeProvider);
|
|
10089
10395
|
const calls = Array.from(
|
|
10090
10396
|
decodeAbiParameters(
|
|
@@ -10149,11 +10455,11 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10149
10455
|
inputToken = hubProvider.chainConfig.nativeToken;
|
|
10150
10456
|
}
|
|
10151
10457
|
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
10152
|
-
|
|
10458
|
+
invariant12(
|
|
10153
10459
|
inputToken,
|
|
10154
10460
|
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
10155
10461
|
);
|
|
10156
|
-
|
|
10462
|
+
invariant12(
|
|
10157
10463
|
outputToken,
|
|
10158
10464
|
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
10159
10465
|
);
|
|
@@ -10216,7 +10522,7 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10216
10522
|
* @returns {PromiseEvmTxReturnType<R>} A promise that resolves to the transaction hash
|
|
10217
10523
|
*/
|
|
10218
10524
|
static async callWallet(payload, spokeProvider, raw) {
|
|
10219
|
-
|
|
10525
|
+
invariant12(spokeProvider instanceof SonicSpokeProvider, "[SonicSpokeService] invalid spoke provider");
|
|
10220
10526
|
const calls = decodeAbiParameters(
|
|
10221
10527
|
[
|
|
10222
10528
|
{
|
|
@@ -10705,11 +11011,8 @@ var SpokeService = class _SpokeService {
|
|
|
10705
11011
|
*/
|
|
10706
11012
|
static async deposit(params, spokeProvider, hubProvider, raw, skipSimulation = false) {
|
|
10707
11013
|
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
10708
|
-
|
|
10709
|
-
|
|
10710
|
-
spokeProvider,
|
|
10711
|
-
raw
|
|
10712
|
-
);
|
|
11014
|
+
const _params = params;
|
|
11015
|
+
return SonicSpokeService.deposit(_params, spokeProvider, raw);
|
|
10713
11016
|
}
|
|
10714
11017
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
10715
11018
|
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
@@ -10734,7 +11037,6 @@ var SpokeService = class _SpokeService {
|
|
|
10734
11037
|
);
|
|
10735
11038
|
}
|
|
10736
11039
|
if (spokeProvider instanceof SuiSpokeProvider) {
|
|
10737
|
-
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10738
11040
|
return SuiSpokeService.deposit(
|
|
10739
11041
|
params,
|
|
10740
11042
|
spokeProvider,
|
|
@@ -10862,6 +11164,20 @@ var SpokeService = class _SpokeService {
|
|
|
10862
11164
|
raw
|
|
10863
11165
|
);
|
|
10864
11166
|
}
|
|
11167
|
+
if (!skipSimulation) {
|
|
11168
|
+
const result = await _SpokeService.simulateRecvMessage(
|
|
11169
|
+
{
|
|
11170
|
+
target: from,
|
|
11171
|
+
srcChainId: getIntentRelayChainId(spokeProvider.chainConfig.chain.id),
|
|
11172
|
+
srcAddress: await spokeProvider.walletProvider.getWalletAddressBytes(),
|
|
11173
|
+
payload
|
|
11174
|
+
},
|
|
11175
|
+
hubProvider
|
|
11176
|
+
);
|
|
11177
|
+
if (!result.success) {
|
|
11178
|
+
throw new Error("Simulation failed", { cause: result });
|
|
11179
|
+
}
|
|
11180
|
+
}
|
|
10865
11181
|
if (isEvmSpokeProvider(spokeProvider)) {
|
|
10866
11182
|
await _SpokeService.verifySimulation(from, payload, spokeProvider, hubProvider, skipSimulation);
|
|
10867
11183
|
return await EvmSpokeService.callWallet(from, payload, spokeProvider, hubProvider);
|
|
@@ -10930,19 +11246,19 @@ async function postRequest(payload, apiUrl) {
|
|
|
10930
11246
|
return response.json();
|
|
10931
11247
|
}
|
|
10932
11248
|
async function submitTransaction(payload, apiUrl) {
|
|
10933
|
-
|
|
10934
|
-
|
|
11249
|
+
invariant12(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11250
|
+
invariant12(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
10935
11251
|
return postRequest(payload, apiUrl);
|
|
10936
11252
|
}
|
|
10937
11253
|
async function getTransactionPackets(payload, apiUrl) {
|
|
10938
|
-
|
|
10939
|
-
|
|
11254
|
+
invariant12(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11255
|
+
invariant12(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
10940
11256
|
return postRequest(payload, apiUrl);
|
|
10941
11257
|
}
|
|
10942
11258
|
async function getPacket(payload, apiUrl) {
|
|
10943
|
-
|
|
10944
|
-
|
|
10945
|
-
|
|
11259
|
+
invariant12(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11260
|
+
invariant12(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
11261
|
+
invariant12(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
|
|
10946
11262
|
return postRequest(payload, apiUrl);
|
|
10947
11263
|
}
|
|
10948
11264
|
async function waitUntilIntentExecuted(payload) {
|
|
@@ -11073,11 +11389,11 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11073
11389
|
inputToken = hubProvider.chainConfig.wrappedNativeToken;
|
|
11074
11390
|
}
|
|
11075
11391
|
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
11076
|
-
|
|
11392
|
+
invariant12(
|
|
11077
11393
|
inputToken,
|
|
11078
11394
|
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
11079
11395
|
);
|
|
11080
|
-
|
|
11396
|
+
invariant12(
|
|
11081
11397
|
outputToken,
|
|
11082
11398
|
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
11083
11399
|
);
|
|
@@ -11109,7 +11425,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11109
11425
|
* @returns A tuple containing [encoded fee data, fee amount]. Fee amount will be 0n if no fee.
|
|
11110
11426
|
*/
|
|
11111
11427
|
static createIntentFeeData(fee, inputAmount) {
|
|
11112
|
-
|
|
11428
|
+
invariant12(inputAmount > 0n, "Input amount must be greater than 0");
|
|
11113
11429
|
if (!fee) {
|
|
11114
11430
|
return ["0x", 0n];
|
|
11115
11431
|
}
|
|
@@ -11117,7 +11433,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11117
11433
|
if (isPartnerFeeAmount(fee)) {
|
|
11118
11434
|
feeAmount = fee.amount;
|
|
11119
11435
|
} else if (isPartnerFeePercentage(fee)) {
|
|
11120
|
-
|
|
11436
|
+
invariant12(
|
|
11121
11437
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
11122
11438
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
11123
11439
|
);
|
|
@@ -11244,23 +11560,23 @@ var SolverApiService = class {
|
|
|
11244
11560
|
* }
|
|
11245
11561
|
*/
|
|
11246
11562
|
static async getQuote(payload, config) {
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11252
|
-
|
|
11563
|
+
invariant12(payload.token_src.length > 0, "Empty token_src");
|
|
11564
|
+
invariant12(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
|
|
11565
|
+
invariant12(payload.token_dst.length > 0, "Empty token_dst");
|
|
11566
|
+
invariant12(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
|
|
11567
|
+
invariant12(payload.amount > 0n, "amount must be greater than 0");
|
|
11568
|
+
invariant12(
|
|
11253
11569
|
isValidOriginalAssetAddress(payload.token_src_blockchain_id, payload.token_src),
|
|
11254
11570
|
"unsupported token_src for src chain"
|
|
11255
11571
|
);
|
|
11256
|
-
|
|
11572
|
+
invariant12(
|
|
11257
11573
|
isValidOriginalAssetAddress(payload.token_dst_blockchain_id, payload.token_dst),
|
|
11258
11574
|
"unsupported token_dst for dst chain"
|
|
11259
11575
|
);
|
|
11260
11576
|
const tokenSrc = getHubAssetInfo(payload.token_src_blockchain_id, payload.token_src)?.asset;
|
|
11261
11577
|
const tokenDst = getHubAssetInfo(payload.token_dst_blockchain_id, payload.token_dst)?.asset;
|
|
11262
|
-
|
|
11263
|
-
|
|
11578
|
+
invariant12(tokenSrc, "hub asset not found for token_src");
|
|
11579
|
+
invariant12(tokenDst, "hub asset not found for token_dst");
|
|
11264
11580
|
try {
|
|
11265
11581
|
const response = await fetch(`${config.solverApiEndpoint}/quote`, {
|
|
11266
11582
|
method: "POST",
|
|
@@ -11355,7 +11671,7 @@ var SolverApiService = class {
|
|
|
11355
11671
|
}
|
|
11356
11672
|
}
|
|
11357
11673
|
static async getStatus(request, config) {
|
|
11358
|
-
|
|
11674
|
+
invariant12(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
|
|
11359
11675
|
try {
|
|
11360
11676
|
const response = await fetch(`${config.solverApiEndpoint}/status`, {
|
|
11361
11677
|
method: "POST",
|
|
@@ -11987,19 +12303,19 @@ var SolverService = class {
|
|
|
11987
12303
|
fee = this.config.partnerFee,
|
|
11988
12304
|
raw
|
|
11989
12305
|
}) {
|
|
11990
|
-
|
|
12306
|
+
invariant12(
|
|
11991
12307
|
isValidOriginalAssetAddress(params.srcChain, params.inputToken),
|
|
11992
12308
|
`Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
|
|
11993
12309
|
);
|
|
11994
|
-
|
|
12310
|
+
invariant12(
|
|
11995
12311
|
isValidOriginalAssetAddress(params.dstChain, params.outputToken),
|
|
11996
12312
|
`Unsupported spoke chain token (params.dstChain): ${params.dstChain}, params.outputToken): ${params.outputToken}`
|
|
11997
12313
|
);
|
|
11998
|
-
|
|
11999
|
-
|
|
12314
|
+
invariant12(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
|
|
12315
|
+
invariant12(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
|
|
12000
12316
|
try {
|
|
12001
12317
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12002
|
-
|
|
12318
|
+
invariant12(
|
|
12003
12319
|
params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
|
|
12004
12320
|
"srcAddress must be the same as wallet address"
|
|
12005
12321
|
);
|
|
@@ -12073,8 +12389,8 @@ var SolverService = class {
|
|
|
12073
12389
|
*/
|
|
12074
12390
|
async cancelIntent(intent, spokeProvider, raw) {
|
|
12075
12391
|
try {
|
|
12076
|
-
|
|
12077
|
-
|
|
12392
|
+
invariant12(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
12393
|
+
invariant12(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
12078
12394
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12079
12395
|
const creatorHubWalletAddress = await deriveUserWalletAddress(spokeProvider, this.hubProvider, walletAddress);
|
|
12080
12396
|
const calls = [];
|
|
@@ -12121,7 +12437,7 @@ var SolverService = class {
|
|
|
12121
12437
|
* @returns {bigint} The deadline for the swap as a sum of hub chain block timestamp and deadline offset
|
|
12122
12438
|
*/
|
|
12123
12439
|
async getSwapDeadline(deadline = DEFAULT_DEADLINE_OFFSET) {
|
|
12124
|
-
|
|
12440
|
+
invariant12(deadline > 0n, "Deadline must be greater than 0");
|
|
12125
12441
|
const block = await this.hubProvider.publicClient.getBlock({
|
|
12126
12442
|
includeTransactions: false,
|
|
12127
12443
|
blockTag: "latest"
|
|
@@ -12599,7 +12915,7 @@ var IcxMigrationService = class {
|
|
|
12599
12915
|
migrateData(params) {
|
|
12600
12916
|
const calls = [];
|
|
12601
12917
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.address);
|
|
12602
|
-
|
|
12918
|
+
invariant12(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
|
|
12603
12919
|
calls.push(
|
|
12604
12920
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
|
|
12605
12921
|
);
|
|
@@ -12615,7 +12931,7 @@ var IcxMigrationService = class {
|
|
|
12615
12931
|
revertMigration(params) {
|
|
12616
12932
|
const calls = [];
|
|
12617
12933
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, params.wICX);
|
|
12618
|
-
|
|
12934
|
+
invariant12(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
|
|
12619
12935
|
calls.push(
|
|
12620
12936
|
Erc20Service.encodeApprove(
|
|
12621
12937
|
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
@@ -12711,9 +13027,9 @@ var MigrationService = class {
|
|
|
12711
13027
|
async isAllowanceValid(params, action, spokeProvider) {
|
|
12712
13028
|
try {
|
|
12713
13029
|
if (action === "migrate") {
|
|
12714
|
-
|
|
12715
|
-
|
|
12716
|
-
|
|
13030
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
13031
|
+
invariant12(isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
13032
|
+
invariant12(
|
|
12717
13033
|
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
12718
13034
|
"Invalid params"
|
|
12719
13035
|
);
|
|
@@ -12739,9 +13055,9 @@ var MigrationService = class {
|
|
|
12739
13055
|
};
|
|
12740
13056
|
}
|
|
12741
13057
|
if (action === "revert") {
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
13058
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
13059
|
+
invariant12(params.to.length > 0, "To address is required");
|
|
13060
|
+
invariant12(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12745
13061
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12746
13062
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12747
13063
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -12797,9 +13113,9 @@ var MigrationService = class {
|
|
|
12797
13113
|
async approve(params, action, spokeProvider, raw) {
|
|
12798
13114
|
try {
|
|
12799
13115
|
if (action === "migrate") {
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
13116
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
13117
|
+
invariant12(params.to.length > 0, "To address is required");
|
|
13118
|
+
invariant12(isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12803
13119
|
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
12804
13120
|
const evmSpokeProvider = spokeProvider;
|
|
12805
13121
|
const result = await Erc20Service.approve(
|
|
@@ -12820,9 +13136,9 @@ var MigrationService = class {
|
|
|
12820
13136
|
};
|
|
12821
13137
|
}
|
|
12822
13138
|
if (action === "revert") {
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
13139
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
13140
|
+
invariant12(params.to.length > 0, "To address is required");
|
|
13141
|
+
invariant12(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12826
13142
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12827
13143
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12828
13144
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -13234,13 +13550,13 @@ var MigrationService = class {
|
|
|
13234
13550
|
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
13235
13551
|
try {
|
|
13236
13552
|
if (!unchecked) {
|
|
13237
|
-
|
|
13238
|
-
|
|
13239
|
-
|
|
13240
|
-
|
|
13241
|
-
|
|
13242
|
-
|
|
13243
|
-
|
|
13553
|
+
invariant12(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
|
|
13554
|
+
invariant12(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
|
|
13555
|
+
invariant12(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
|
|
13556
|
+
invariant12(params.dstbnUSD.length > 0, "New bnUSD token address is required");
|
|
13557
|
+
invariant12(params.amount > 0, "Amount must be greater than 0");
|
|
13558
|
+
invariant12(params.to.length > 0, "Recipient address is required");
|
|
13559
|
+
invariant12(
|
|
13244
13560
|
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
13245
13561
|
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
13246
13562
|
);
|
|
@@ -13248,11 +13564,11 @@ var MigrationService = class {
|
|
|
13248
13564
|
let migrationData;
|
|
13249
13565
|
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
13250
13566
|
if (!unchecked) {
|
|
13251
|
-
|
|
13567
|
+
invariant12(
|
|
13252
13568
|
isLegacybnUSDChainId(params.srcChainId),
|
|
13253
13569
|
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
13254
13570
|
);
|
|
13255
|
-
|
|
13571
|
+
invariant12(
|
|
13256
13572
|
isNewbnUSDChainId(params.dstChainId),
|
|
13257
13573
|
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
13258
13574
|
);
|
|
@@ -13267,15 +13583,15 @@ var MigrationService = class {
|
|
|
13267
13583
|
});
|
|
13268
13584
|
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
13269
13585
|
if (!unchecked) {
|
|
13270
|
-
|
|
13586
|
+
invariant12(
|
|
13271
13587
|
isLegacybnUSDChainId(params.dstChainId),
|
|
13272
13588
|
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
13273
13589
|
);
|
|
13274
|
-
|
|
13590
|
+
invariant12(
|
|
13275
13591
|
isNewbnUSDToken(params.srcbnUSD),
|
|
13276
13592
|
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
13277
13593
|
);
|
|
13278
|
-
|
|
13594
|
+
invariant12(
|
|
13279
13595
|
isNewbnUSDChainId(params.srcChainId),
|
|
13280
13596
|
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
13281
13597
|
);
|
|
@@ -13348,13 +13664,13 @@ var MigrationService = class {
|
|
|
13348
13664
|
*/
|
|
13349
13665
|
async createMigrateIcxToSodaIntent(params, spokeProvider, raw) {
|
|
13350
13666
|
try {
|
|
13351
|
-
|
|
13352
|
-
|
|
13353
|
-
|
|
13667
|
+
invariant12(params.amount > 0, "Amount must be greater than 0");
|
|
13668
|
+
invariant12(isAddress(params.to), "Recipient address is required");
|
|
13669
|
+
invariant12(
|
|
13354
13670
|
params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
13355
13671
|
"Token must be wICX or native ICX token"
|
|
13356
13672
|
);
|
|
13357
|
-
|
|
13673
|
+
invariant12(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
|
|
13358
13674
|
const availableAmount = await this.icxMigration.getAvailableAmount();
|
|
13359
13675
|
if (availableAmount < params.amount) {
|
|
13360
13676
|
throw new Error(
|
|
@@ -13466,7 +13782,7 @@ var BnUSDMigrationService = class {
|
|
|
13466
13782
|
migrateData(params) {
|
|
13467
13783
|
const calls = [];
|
|
13468
13784
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
13469
|
-
|
|
13785
|
+
invariant12(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
13470
13786
|
const bnUSDVault = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
13471
13787
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
13472
13788
|
calls.push(EvmVaultTokenService.encodeDeposit(assetConfig.vault, assetConfig.asset, params.amount));
|
|
@@ -13478,7 +13794,7 @@ var BnUSDMigrationService = class {
|
|
|
13478
13794
|
return encodeContractCalls(calls);
|
|
13479
13795
|
}
|
|
13480
13796
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
13481
|
-
|
|
13797
|
+
invariant12(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13482
13798
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
13483
13799
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
13484
13800
|
dstAssetConfig.decimal,
|
|
@@ -13511,14 +13827,14 @@ var BnUSDMigrationService = class {
|
|
|
13511
13827
|
let decimals = 18;
|
|
13512
13828
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
13513
13829
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
13514
|
-
|
|
13830
|
+
invariant12(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13515
13831
|
decimals = assetConfig.decimal;
|
|
13516
13832
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
13517
13833
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
13518
13834
|
}
|
|
13519
13835
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
13520
13836
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
13521
|
-
|
|
13837
|
+
invariant12(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
13522
13838
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
13523
13839
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
13524
13840
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -13601,7 +13917,7 @@ var BalnSwapService = class {
|
|
|
13601
13917
|
*/
|
|
13602
13918
|
async swapData(balnToken, params) {
|
|
13603
13919
|
const assetConfig = getHubAssetInfo(ICON_MAINNET_CHAIN_ID, balnToken);
|
|
13604
|
-
|
|
13920
|
+
invariant12(assetConfig, `hub asset not found for baln token: ${balnToken}`);
|
|
13605
13921
|
const calls = [];
|
|
13606
13922
|
calls.push(
|
|
13607
13923
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.balnSwap, params.amount)
|
|
@@ -13654,129 +13970,620 @@ var BalnSwapService = class {
|
|
|
13654
13970
|
return await this.call(spokeProvider, unstakeTx, raw);
|
|
13655
13971
|
}
|
|
13656
13972
|
/**
|
|
13657
|
-
* Gets detailed locks for a specific user including unstake requests and staked amounts.
|
|
13973
|
+
* Gets detailed locks for a specific user including unstake requests and staked amounts.
|
|
13974
|
+
*
|
|
13975
|
+
* @param publicClient - The public client for reading contract state
|
|
13976
|
+
* @param user - The user address
|
|
13977
|
+
* @returns Array of detailed lock information for the user
|
|
13978
|
+
*/
|
|
13979
|
+
async getDetailedUserLocks(publicClient, user) {
|
|
13980
|
+
return await publicClient.readContract({
|
|
13981
|
+
address: this.hubProvider.chainConfig.addresses.balnSwap,
|
|
13982
|
+
abi: balnSwapAbi,
|
|
13983
|
+
functionName: "getDetailedUserLocks",
|
|
13984
|
+
args: [user]
|
|
13985
|
+
});
|
|
13986
|
+
}
|
|
13987
|
+
// ===== ENCODING METHODS =====
|
|
13988
|
+
/**
|
|
13989
|
+
* Encodes a swap transaction for the BALN swap contract.
|
|
13990
|
+
*
|
|
13991
|
+
* @param amount - The amount of BALN tokens to swap
|
|
13992
|
+
* @param lockupPeriod - The lockup period for the swap
|
|
13993
|
+
* @param to - The address that will receive the swapped SODA tokens
|
|
13994
|
+
* @param stake - Whether to stake the SODA tokens
|
|
13995
|
+
* @returns The encoded contract call for the swap operation
|
|
13996
|
+
*/
|
|
13997
|
+
encodeSwap(amount, lockupPeriod, to, stake) {
|
|
13998
|
+
return {
|
|
13999
|
+
address: this.hubProvider.chainConfig.addresses.balnSwap,
|
|
14000
|
+
value: 0n,
|
|
14001
|
+
data: encodeFunctionData({
|
|
14002
|
+
abi: balnSwapAbi,
|
|
14003
|
+
functionName: "swap",
|
|
14004
|
+
args: [amount, BigInt(lockupPeriod), to, stake]
|
|
14005
|
+
})
|
|
14006
|
+
};
|
|
14007
|
+
}
|
|
14008
|
+
/**
|
|
14009
|
+
* Encodes a claim transaction for the BALN swap contract.
|
|
14010
|
+
*
|
|
14011
|
+
* @param lockId - The lock ID to claim from
|
|
14012
|
+
* @returns The encoded contract call for the claim operation
|
|
14013
|
+
*/
|
|
14014
|
+
encodeClaim(lockId) {
|
|
14015
|
+
return {
|
|
14016
|
+
address: this.hubProvider.chainConfig.addresses.balnSwap,
|
|
14017
|
+
value: 0n,
|
|
14018
|
+
data: encodeFunctionData({
|
|
14019
|
+
abi: balnSwapAbi,
|
|
14020
|
+
functionName: "claim",
|
|
14021
|
+
args: [lockId]
|
|
14022
|
+
})
|
|
14023
|
+
};
|
|
14024
|
+
}
|
|
14025
|
+
/**
|
|
14026
|
+
* Encodes a claim unstaked transaction for the BALN swap contract.
|
|
14027
|
+
*
|
|
14028
|
+
* @param lockId - The lock ID to claim unstaked tokens from
|
|
14029
|
+
* @returns The encoded contract call for the claim unstaked operation
|
|
14030
|
+
*/
|
|
14031
|
+
encodeClaimUnstaked(lockId) {
|
|
14032
|
+
return {
|
|
14033
|
+
address: this.hubProvider.chainConfig.addresses.balnSwap,
|
|
14034
|
+
value: 0n,
|
|
14035
|
+
data: encodeFunctionData({
|
|
14036
|
+
abi: balnSwapAbi,
|
|
14037
|
+
functionName: "claimUnstaked",
|
|
14038
|
+
args: [lockId]
|
|
14039
|
+
})
|
|
14040
|
+
};
|
|
14041
|
+
}
|
|
14042
|
+
/**
|
|
14043
|
+
* Encodes a stake transaction for the BALN swap contract.
|
|
14044
|
+
*
|
|
14045
|
+
* @param lockId - The lock ID to stake
|
|
14046
|
+
* @returns The encoded contract call for the stake operation
|
|
14047
|
+
*/
|
|
14048
|
+
encodeStake(lockId) {
|
|
14049
|
+
return {
|
|
14050
|
+
address: this.hubProvider.chainConfig.addresses.balnSwap,
|
|
14051
|
+
value: 0n,
|
|
14052
|
+
data: encodeFunctionData({
|
|
14053
|
+
abi: balnSwapAbi,
|
|
14054
|
+
functionName: "stake",
|
|
14055
|
+
args: [lockId]
|
|
14056
|
+
})
|
|
14057
|
+
};
|
|
14058
|
+
}
|
|
14059
|
+
/**
|
|
14060
|
+
* Encodes an unstake transaction for the BALN swap contract.
|
|
14061
|
+
*
|
|
14062
|
+
* @param lockId - The lock ID to unstake
|
|
14063
|
+
* @returns The encoded contract call for the unstake operation
|
|
14064
|
+
*/
|
|
14065
|
+
encodeUnstake(lockId) {
|
|
14066
|
+
return {
|
|
14067
|
+
address: this.hubProvider.chainConfig.addresses.balnSwap,
|
|
14068
|
+
value: 0n,
|
|
14069
|
+
data: encodeFunctionData({
|
|
14070
|
+
abi: balnSwapAbi,
|
|
14071
|
+
functionName: "unstake",
|
|
14072
|
+
args: [lockId]
|
|
14073
|
+
})
|
|
14074
|
+
};
|
|
14075
|
+
}
|
|
14076
|
+
// ===== PRIVATE HELPER METHODS =====
|
|
14077
|
+
/**
|
|
14078
|
+
* Executes a contract call through the Sonic wallet provider.
|
|
14079
|
+
* @param spokeProvider - The Sonic spoke provider
|
|
14080
|
+
* @param rawTx - The raw contract call to execute
|
|
14081
|
+
* @param raw - Whether to return raw transaction data
|
|
14082
|
+
* @returns The transaction hash or raw transaction data
|
|
14083
|
+
*/
|
|
14084
|
+
async call(spokeProvider, rawTx, raw) {
|
|
14085
|
+
const from = await spokeProvider.walletProvider.getWalletAddress();
|
|
14086
|
+
const tx = {
|
|
14087
|
+
from,
|
|
14088
|
+
to: rawTx.address,
|
|
14089
|
+
value: rawTx.value,
|
|
14090
|
+
data: rawTx.data
|
|
14091
|
+
};
|
|
14092
|
+
if (raw) {
|
|
14093
|
+
return tx;
|
|
14094
|
+
}
|
|
14095
|
+
return spokeProvider.walletProvider.sendTransaction(tx);
|
|
14096
|
+
}
|
|
14097
|
+
};
|
|
14098
|
+
var BridgeService = class {
|
|
14099
|
+
hubProvider;
|
|
14100
|
+
relayerApiEndpoint;
|
|
14101
|
+
config;
|
|
14102
|
+
constructor(hubProvider, relayerApiEndpoint, config = void 0) {
|
|
14103
|
+
this.config = config ? config : { partnerFee: void 0 };
|
|
14104
|
+
this.hubProvider = hubProvider;
|
|
14105
|
+
this.relayerApiEndpoint = relayerApiEndpoint;
|
|
14106
|
+
}
|
|
14107
|
+
/**
|
|
14108
|
+
* Get the fee for a given input amount
|
|
14109
|
+
* @param {bigint} inputAmount - The amount of input tokens
|
|
14110
|
+
* @returns {Promise<bigint>} The fee amount (denominated in input tokens)
|
|
14111
|
+
*
|
|
14112
|
+
* @example
|
|
14113
|
+
* const fee: bigint = await sodax.bridge.getFee(1000000000000000n);
|
|
14114
|
+
* console.log('Fee:', fee);
|
|
14115
|
+
*/
|
|
14116
|
+
getFee(inputAmount) {
|
|
14117
|
+
if (!this.config.partnerFee) {
|
|
14118
|
+
return 0n;
|
|
14119
|
+
}
|
|
14120
|
+
return calculateFeeAmount(inputAmount, this.config.partnerFee);
|
|
14121
|
+
}
|
|
14122
|
+
/**
|
|
14123
|
+
* Check if allowance is valid for the bridge transaction
|
|
14124
|
+
* @param params - The bridge parameters
|
|
14125
|
+
* @param spokeProvider - The spoke provider
|
|
14126
|
+
* @returns {Promise<Result<boolean, BridgeError<'ALLOWANCE_CHECK_FAILED'>>>}
|
|
14127
|
+
*/
|
|
14128
|
+
async isAllowanceValid({
|
|
14129
|
+
params,
|
|
14130
|
+
spokeProvider
|
|
14131
|
+
}) {
|
|
14132
|
+
try {
|
|
14133
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
14134
|
+
invariant12(params.srcAsset.length > 0, "Source asset is required");
|
|
14135
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
14136
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
14137
|
+
invariant12(isAddress(params.srcAsset), "Invalid source asset address for EVM chain");
|
|
14138
|
+
const allowanceResult = await Erc20Service.isAllowanceValid(
|
|
14139
|
+
params.srcAsset,
|
|
14140
|
+
params.amount,
|
|
14141
|
+
walletAddress,
|
|
14142
|
+
spokeProvider.chainConfig.addresses.assetManager,
|
|
14143
|
+
spokeProvider
|
|
14144
|
+
);
|
|
14145
|
+
if (!allowanceResult.ok) {
|
|
14146
|
+
return {
|
|
14147
|
+
ok: false,
|
|
14148
|
+
error: {
|
|
14149
|
+
code: "ALLOWANCE_CHECK_FAILED",
|
|
14150
|
+
error: allowanceResult.error
|
|
14151
|
+
}
|
|
14152
|
+
};
|
|
14153
|
+
}
|
|
14154
|
+
return {
|
|
14155
|
+
ok: true,
|
|
14156
|
+
value: allowanceResult.value
|
|
14157
|
+
};
|
|
14158
|
+
}
|
|
14159
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
14160
|
+
invariant12(isAddress(params.srcAsset), "Invalid source asset address for Sonic chain");
|
|
14161
|
+
const userRouter = await SonicSpokeService.getUserRouter(walletAddress, spokeProvider);
|
|
14162
|
+
const allowanceResult = await Erc20Service.isAllowanceValid(
|
|
14163
|
+
params.srcAsset,
|
|
14164
|
+
params.amount,
|
|
14165
|
+
walletAddress,
|
|
14166
|
+
userRouter,
|
|
14167
|
+
spokeProvider
|
|
14168
|
+
);
|
|
14169
|
+
if (!allowanceResult.ok) {
|
|
14170
|
+
return {
|
|
14171
|
+
ok: false,
|
|
14172
|
+
error: {
|
|
14173
|
+
code: "ALLOWANCE_CHECK_FAILED",
|
|
14174
|
+
error: allowanceResult.error
|
|
14175
|
+
}
|
|
14176
|
+
};
|
|
14177
|
+
}
|
|
14178
|
+
return {
|
|
14179
|
+
ok: true,
|
|
14180
|
+
value: allowanceResult.value
|
|
14181
|
+
};
|
|
14182
|
+
}
|
|
14183
|
+
return {
|
|
14184
|
+
ok: true,
|
|
14185
|
+
value: true
|
|
14186
|
+
};
|
|
14187
|
+
} catch (error) {
|
|
14188
|
+
return {
|
|
14189
|
+
ok: false,
|
|
14190
|
+
error: {
|
|
14191
|
+
code: "ALLOWANCE_CHECK_FAILED",
|
|
14192
|
+
error
|
|
14193
|
+
}
|
|
14194
|
+
};
|
|
14195
|
+
}
|
|
14196
|
+
}
|
|
14197
|
+
/**
|
|
14198
|
+
* Approve token spending for the bridge transaction
|
|
14199
|
+
* @param params - The bridge parameters
|
|
14200
|
+
* @param spokeProvider - The spoke provider
|
|
14201
|
+
* @param raw - Whether to return raw transaction data
|
|
14202
|
+
* @returns Promise<Result<TxReturnType<S, R>, BridgeError<'APPROVAL_FAILED'>>>
|
|
14203
|
+
*/
|
|
14204
|
+
async approve({
|
|
14205
|
+
params,
|
|
14206
|
+
spokeProvider,
|
|
14207
|
+
raw
|
|
14208
|
+
}) {
|
|
14209
|
+
try {
|
|
14210
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
14211
|
+
invariant12(params.srcAsset.length > 0, "Source asset is required");
|
|
14212
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
14213
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
14214
|
+
invariant12(isAddress(params.srcAsset), "Invalid source asset address for EVM chain");
|
|
14215
|
+
const result = await Erc20Service.approve(
|
|
14216
|
+
params.srcAsset,
|
|
14217
|
+
params.amount,
|
|
14218
|
+
spokeProvider.chainConfig.addresses.assetManager,
|
|
14219
|
+
spokeProvider,
|
|
14220
|
+
raw
|
|
14221
|
+
);
|
|
14222
|
+
return {
|
|
14223
|
+
ok: true,
|
|
14224
|
+
value: result
|
|
14225
|
+
};
|
|
14226
|
+
}
|
|
14227
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
14228
|
+
invariant12(isAddress(params.srcAsset), "Invalid source asset address for Sonic chain");
|
|
14229
|
+
const userRouter = await SonicSpokeService.getUserRouter(
|
|
14230
|
+
walletAddress,
|
|
14231
|
+
spokeProvider
|
|
14232
|
+
);
|
|
14233
|
+
const result = await Erc20Service.approve(params.srcAsset, params.amount, userRouter, spokeProvider, raw);
|
|
14234
|
+
return {
|
|
14235
|
+
ok: true,
|
|
14236
|
+
value: result
|
|
14237
|
+
};
|
|
14238
|
+
}
|
|
14239
|
+
return {
|
|
14240
|
+
ok: false,
|
|
14241
|
+
error: {
|
|
14242
|
+
code: "APPROVAL_FAILED",
|
|
14243
|
+
error: new Error("Approval only supported for EVM spoke chains")
|
|
14244
|
+
}
|
|
14245
|
+
};
|
|
14246
|
+
} catch (error) {
|
|
14247
|
+
console.error(error);
|
|
14248
|
+
return {
|
|
14249
|
+
ok: false,
|
|
14250
|
+
error: {
|
|
14251
|
+
code: "APPROVAL_FAILED",
|
|
14252
|
+
error
|
|
14253
|
+
}
|
|
14254
|
+
};
|
|
14255
|
+
}
|
|
14256
|
+
}
|
|
14257
|
+
/**
|
|
14258
|
+
* Execute a bridge transaction to transfer tokens from one chain to another
|
|
14259
|
+
* @param params - The bridge parameters including source/destination chains, assets, and recipient
|
|
14260
|
+
* @param spokeProvider - The spoke provider for the source chain
|
|
14261
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
14262
|
+
* @returns {Promise<Result<[SpokeTxHash, HubTxHash], BridgeError<BridgeErrorCode>>>} - Returns the transaction hashes for both spoke and hub chains or error
|
|
13658
14263
|
*
|
|
13659
|
-
* @
|
|
13660
|
-
*
|
|
13661
|
-
*
|
|
13662
|
-
|
|
13663
|
-
|
|
13664
|
-
|
|
13665
|
-
|
|
13666
|
-
|
|
13667
|
-
|
|
13668
|
-
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
* Encodes a swap transaction for the BALN swap contract.
|
|
14264
|
+
* @example
|
|
14265
|
+
* const result = await sodax.bridge.bridge(
|
|
14266
|
+
* {
|
|
14267
|
+
* srcChainId: '0x2105.base',
|
|
14268
|
+
* srcAsset: '0x...', // Address of the source token
|
|
14269
|
+
* amount: 1000n, // Amount to bridge (in token decimals)
|
|
14270
|
+
* dstChainId: '0x89.polygon',
|
|
14271
|
+
* dstAsset: '0x...', // Address of the destination token
|
|
14272
|
+
* recipient: '0x...', // Recipient address on destination chain
|
|
14273
|
+
* partnerFee: { address: '0x...', percentage: 0.1 } // Optional partner fee. Partner fees and denominated in vault token decimals (18)
|
|
14274
|
+
* },
|
|
14275
|
+
* spokeProvider,
|
|
14276
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
14277
|
+
* );
|
|
13674
14278
|
*
|
|
13675
|
-
*
|
|
13676
|
-
*
|
|
13677
|
-
*
|
|
13678
|
-
*
|
|
13679
|
-
*
|
|
14279
|
+
* if (!result.ok) {
|
|
14280
|
+
* // Handle error
|
|
14281
|
+
* }
|
|
14282
|
+
*
|
|
14283
|
+
* const [
|
|
14284
|
+
* spokeTxHash, // transaction hash on the source chain
|
|
14285
|
+
* hubTxHash, // transaction hash on the hub chain
|
|
14286
|
+
* ] = result.value;
|
|
14287
|
+
* console.log('Bridge transaction hashes:', { spokeTxHash, hubTxHash });
|
|
13680
14288
|
*/
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13684
|
-
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
|
|
14289
|
+
async bridge({
|
|
14290
|
+
params,
|
|
14291
|
+
spokeProvider,
|
|
14292
|
+
fee = this.config.partnerFee,
|
|
14293
|
+
timeout = DEFAULT_RELAY_TX_TIMEOUT
|
|
14294
|
+
}) {
|
|
14295
|
+
try {
|
|
14296
|
+
const txResult = await this.createBridgeIntent({ params, spokeProvider, fee, raw: false });
|
|
14297
|
+
if (!txResult.ok) {
|
|
14298
|
+
return txResult;
|
|
14299
|
+
}
|
|
14300
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
14301
|
+
txResult.value,
|
|
14302
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
14303
|
+
spokeProvider,
|
|
14304
|
+
this.relayerApiEndpoint,
|
|
14305
|
+
timeout
|
|
14306
|
+
);
|
|
14307
|
+
if (!packetResult.ok) {
|
|
14308
|
+
return {
|
|
14309
|
+
ok: false,
|
|
14310
|
+
error: {
|
|
14311
|
+
code: packetResult.error.code,
|
|
14312
|
+
error: packetResult.error
|
|
14313
|
+
}
|
|
14314
|
+
};
|
|
14315
|
+
}
|
|
14316
|
+
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
14317
|
+
} catch (error) {
|
|
14318
|
+
return {
|
|
14319
|
+
ok: false,
|
|
14320
|
+
error: {
|
|
14321
|
+
code: "BRIDGE_FAILED",
|
|
14322
|
+
error
|
|
14323
|
+
}
|
|
14324
|
+
};
|
|
14325
|
+
}
|
|
13691
14326
|
}
|
|
13692
14327
|
/**
|
|
13693
|
-
*
|
|
14328
|
+
* Create bridge intent only (without relaying to hub)
|
|
14329
|
+
* NOTE: This method only executes the transaction on the spoke chain and creates the bridge intent
|
|
14330
|
+
* In order to successfully bridge tokens, you need to:
|
|
14331
|
+
* 1. Check if the allowance is sufficient using isAllowanceValid
|
|
14332
|
+
* 2. Approve the appropriate contract to spend the tokens using approve
|
|
14333
|
+
* 3. Create the bridge intent using this method
|
|
14334
|
+
* 4. Relay the transaction to the hub and await completion using the bridge method
|
|
13694
14335
|
*
|
|
13695
|
-
* @param
|
|
13696
|
-
* @
|
|
14336
|
+
* @param params - The bridge parameters including source/destination chains, assets, and recipient
|
|
14337
|
+
* @param spokeProvider - The spoke provider for the source chain
|
|
14338
|
+
* @param raw - Whether to return the raw transaction data
|
|
14339
|
+
* @returns {Promise<Result<TxReturnType<S, R>, BridgeError<BridgeErrorCode>>>} - Returns the transaction result
|
|
14340
|
+
*
|
|
14341
|
+
* @example
|
|
14342
|
+
* const bridgeService = new BridgeService(hubProvider, relayerApiEndpoint);
|
|
14343
|
+
* const result = await sodax.bridge.createBridgeIntent(
|
|
14344
|
+
* {
|
|
14345
|
+
* srcChainId: 'ethereum',
|
|
14346
|
+
* srcAsset: "0x123...", // source token address
|
|
14347
|
+
* amount: 1000000000000000000n, // 1 token in wei
|
|
14348
|
+
* dstChainId: 'polygon',
|
|
14349
|
+
* dstAsset: "0x456...", // destination token address
|
|
14350
|
+
* recipient: "0x789..." // recipient address
|
|
14351
|
+
* },
|
|
14352
|
+
* spokeProvider,
|
|
14353
|
+
* raw // Optional: true = return the raw transaction data, false = execute and return the transaction hash (default: false)
|
|
14354
|
+
* );
|
|
14355
|
+
*
|
|
14356
|
+
* if (result.ok) {
|
|
14357
|
+
* const txHash = result.value;
|
|
14358
|
+
* console.log('Bridge intent transaction hash:', txHash);
|
|
14359
|
+
* } else {
|
|
14360
|
+
* console.error('Bridge intent creation failed:', result.error);
|
|
14361
|
+
* }
|
|
13697
14362
|
*/
|
|
13698
|
-
|
|
13699
|
-
|
|
13700
|
-
|
|
13701
|
-
|
|
13702
|
-
|
|
13703
|
-
|
|
13704
|
-
|
|
13705
|
-
|
|
13706
|
-
|
|
13707
|
-
|
|
14363
|
+
async createBridgeIntent({
|
|
14364
|
+
params,
|
|
14365
|
+
spokeProvider,
|
|
14366
|
+
fee = this.config.partnerFee,
|
|
14367
|
+
raw
|
|
14368
|
+
}) {
|
|
14369
|
+
try {
|
|
14370
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
14371
|
+
const srcAssetInfo = getHubAssetInfo(params.srcChainId, params.srcAsset);
|
|
14372
|
+
const dstAssetInfo = getHubAssetInfo(params.dstChainId, params.dstAsset);
|
|
14373
|
+
invariant12(srcAssetInfo, `Unsupported spoke chain (${params.srcChainId}) token: ${params.srcAsset}`);
|
|
14374
|
+
invariant12(dstAssetInfo, `Unsupported spoke chain (${params.dstChainId}) token: ${params.dstAsset}`);
|
|
14375
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
14376
|
+
const hubWallet = await WalletAbstractionService.getUserAbstractedWalletAddress(
|
|
14377
|
+
walletAddress,
|
|
14378
|
+
spokeProvider,
|
|
14379
|
+
this.hubProvider
|
|
14380
|
+
);
|
|
14381
|
+
const data = this.buildBridgeData(params, srcAssetInfo, dstAssetInfo, fee);
|
|
14382
|
+
const txResult = await SpokeService.deposit(
|
|
14383
|
+
{
|
|
14384
|
+
from: walletAddress,
|
|
14385
|
+
to: hubWallet,
|
|
14386
|
+
token: params.srcAsset,
|
|
14387
|
+
amount: params.amount,
|
|
14388
|
+
data
|
|
14389
|
+
},
|
|
14390
|
+
spokeProvider,
|
|
14391
|
+
this.hubProvider,
|
|
14392
|
+
raw
|
|
14393
|
+
);
|
|
14394
|
+
return {
|
|
14395
|
+
ok: true,
|
|
14396
|
+
value: txResult,
|
|
14397
|
+
data: {
|
|
14398
|
+
address: hubWallet,
|
|
14399
|
+
payload: data
|
|
14400
|
+
}
|
|
14401
|
+
};
|
|
14402
|
+
} catch (error) {
|
|
14403
|
+
console.error(error);
|
|
14404
|
+
return {
|
|
14405
|
+
ok: false,
|
|
14406
|
+
error: {
|
|
14407
|
+
code: "CREATE_BRIDGE_INTENT_FAILED",
|
|
14408
|
+
error
|
|
14409
|
+
}
|
|
14410
|
+
};
|
|
14411
|
+
}
|
|
13708
14412
|
}
|
|
13709
14413
|
/**
|
|
13710
|
-
*
|
|
13711
|
-
*
|
|
13712
|
-
* @param
|
|
13713
|
-
* @
|
|
14414
|
+
* Build the bridge transaction data for executing the bridge operation on the hub
|
|
14415
|
+
* @param params - The create bridge intent parameters
|
|
14416
|
+
* @param srcAssetInfo - The source asset information
|
|
14417
|
+
* @param dstAssetInfo - The destination asset information
|
|
14418
|
+
* @returns Hex - The encoded contract calls for the bridge operation
|
|
13714
14419
|
*/
|
|
13715
|
-
|
|
13716
|
-
|
|
13717
|
-
|
|
13718
|
-
|
|
13719
|
-
|
|
13720
|
-
|
|
13721
|
-
|
|
13722
|
-
|
|
13723
|
-
|
|
13724
|
-
}
|
|
14420
|
+
buildBridgeData(params, srcAssetInfo, dstAssetInfo, partnerFee) {
|
|
14421
|
+
const calls = [];
|
|
14422
|
+
let translatedAmount = params.amount;
|
|
14423
|
+
let srcVault = params.srcAsset;
|
|
14424
|
+
if (!isValidVault(srcAssetInfo.asset)) {
|
|
14425
|
+
calls.push(Erc20Service.encodeApprove(srcAssetInfo.asset, srcAssetInfo.vault, params.amount));
|
|
14426
|
+
calls.push(EvmVaultTokenService.encodeDeposit(srcAssetInfo.vault, srcAssetInfo.asset, params.amount));
|
|
14427
|
+
translatedAmount = EvmVaultTokenService.translateIncomingDecimals(srcAssetInfo.decimal, params.amount);
|
|
14428
|
+
srcVault = srcAssetInfo.vault;
|
|
14429
|
+
}
|
|
14430
|
+
const feeAmount = calculateFeeAmount(translatedAmount, partnerFee);
|
|
14431
|
+
if (partnerFee && feeAmount > 0n) {
|
|
14432
|
+
calls.push(Erc20Service.encodeTransfer(srcVault, partnerFee.address, feeAmount));
|
|
14433
|
+
}
|
|
14434
|
+
const withdrawAmount = translatedAmount - feeAmount;
|
|
14435
|
+
let translatedWithdrawAmount = withdrawAmount;
|
|
14436
|
+
if (!isValidVault(dstAssetInfo.asset)) {
|
|
14437
|
+
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetInfo.vault, dstAssetInfo.asset, withdrawAmount));
|
|
14438
|
+
translatedWithdrawAmount = EvmVaultTokenService.translateOutgoingDecimals(dstAssetInfo.decimal, withdrawAmount);
|
|
14439
|
+
}
|
|
14440
|
+
const encodedRecipientAddress = encodeAddress(params.dstChainId, params.recipient);
|
|
14441
|
+
if (params.dstChainId === this.hubProvider.chainConfig.chain.id) {
|
|
14442
|
+
calls.push(Erc20Service.encodeTransfer(dstAssetInfo.asset, encodedRecipientAddress, translatedWithdrawAmount));
|
|
14443
|
+
} else {
|
|
14444
|
+
invariant12(dstAssetInfo, `Unsupported hub chain (${params.dstChainId}) token: ${params.dstAsset}`);
|
|
14445
|
+
calls.push(
|
|
14446
|
+
EvmAssetManagerService.encodeTransfer(
|
|
14447
|
+
dstAssetInfo.asset,
|
|
14448
|
+
encodedRecipientAddress,
|
|
14449
|
+
translatedWithdrawAmount,
|
|
14450
|
+
this.hubProvider.chainConfig.addresses.assetManager
|
|
14451
|
+
)
|
|
14452
|
+
);
|
|
14453
|
+
}
|
|
14454
|
+
return encodeContractCalls(calls);
|
|
13725
14455
|
}
|
|
13726
14456
|
/**
|
|
13727
|
-
*
|
|
14457
|
+
* Retrieves the deposited token balance held by the asset manager on a spoke chain.
|
|
14458
|
+
* This balance represents the available liquidity for bridging operations and is used to verify
|
|
14459
|
+
* that the target chain has sufficient funds to complete a bridge transaction.
|
|
13728
14460
|
*
|
|
13729
|
-
* @param
|
|
13730
|
-
* @
|
|
14461
|
+
* @param spokeProvider - The spoke provider instance
|
|
14462
|
+
* @param token - The token address to query the balance for
|
|
14463
|
+
* @returns {Promise<bigint>} - The token balance as a bigint value
|
|
13731
14464
|
*/
|
|
13732
|
-
|
|
13733
|
-
|
|
13734
|
-
|
|
13735
|
-
|
|
13736
|
-
|
|
13737
|
-
|
|
13738
|
-
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
14465
|
+
async getBridgeableAmount(from, to) {
|
|
14466
|
+
try {
|
|
14467
|
+
const fromHubAsset = getHubAssetInfo(from.xChainId, from.address);
|
|
14468
|
+
const toHubAsset = getHubAssetInfo(to.xChainId, to.address);
|
|
14469
|
+
invariant12(fromHubAsset, `Hub asset not found for token ${from.address} on chain ${from.xChainId}`);
|
|
14470
|
+
invariant12(toHubAsset, `Hub asset not found for token ${to.address} on chain ${to.xChainId}`);
|
|
14471
|
+
const [depositTokenInfo, reserves] = await Promise.all([
|
|
14472
|
+
EvmVaultTokenService.getTokenInfo(fromHubAsset.vault, fromHubAsset.asset, this.hubProvider.publicClient),
|
|
14473
|
+
EvmVaultTokenService.getVaultReserves(toHubAsset.vault, this.hubProvider.publicClient)
|
|
14474
|
+
]);
|
|
14475
|
+
if (!isValidVault(fromHubAsset.asset) && isValidVault(toHubAsset.asset)) {
|
|
14476
|
+
const fromTokenIndex2 = reserves.tokens.findIndex((t) => t.toLowerCase() === fromHubAsset.asset.toLowerCase());
|
|
14477
|
+
invariant12(
|
|
14478
|
+
fromTokenIndex2 !== -1,
|
|
14479
|
+
`Token ${fromHubAsset.asset} not found in the vault reserves for chain ${from.xChainId}`
|
|
14480
|
+
);
|
|
14481
|
+
const fromTokenDepositedAmount2 = reserves.balances[fromTokenIndex2] ?? 0n;
|
|
14482
|
+
const availableDeposit2 = depositTokenInfo.maxDeposit - fromTokenDepositedAmount2;
|
|
14483
|
+
return {
|
|
14484
|
+
ok: true,
|
|
14485
|
+
value: availableDeposit2
|
|
14486
|
+
};
|
|
14487
|
+
}
|
|
14488
|
+
if (isValidVault(fromHubAsset.asset)) {
|
|
14489
|
+
const tokenIndex2 = reserves.tokens.findIndex((t) => t.toLowerCase() === toHubAsset.asset.toLowerCase());
|
|
14490
|
+
invariant12(
|
|
14491
|
+
tokenIndex2 !== -1,
|
|
14492
|
+
`Token ${toHubAsset.asset} not found in the vault reserves for chain ${to.xChainId}`
|
|
14493
|
+
);
|
|
14494
|
+
const assetManagerBalance2 = reserves.balances[tokenIndex2] ?? 0n;
|
|
14495
|
+
return {
|
|
14496
|
+
ok: true,
|
|
14497
|
+
value: assetManagerBalance2
|
|
14498
|
+
};
|
|
14499
|
+
}
|
|
14500
|
+
const fromTokenIndex = reserves.tokens.findIndex((t) => t.toLowerCase() === fromHubAsset.asset.toLowerCase());
|
|
14501
|
+
invariant12(
|
|
14502
|
+
fromTokenIndex !== -1,
|
|
14503
|
+
`Token ${fromHubAsset.asset} not found in the vault reserves for chain ${from.xChainId}`
|
|
14504
|
+
);
|
|
14505
|
+
const fromTokenDepositedAmount = reserves.balances[fromTokenIndex] ?? 0n;
|
|
14506
|
+
const availableDeposit = depositTokenInfo.maxDeposit - fromTokenDepositedAmount;
|
|
14507
|
+
const tokenIndex = reserves.tokens.findIndex((t) => t.toLowerCase() === toHubAsset.asset.toLowerCase());
|
|
14508
|
+
invariant12(
|
|
14509
|
+
tokenIndex !== -1,
|
|
14510
|
+
`Token ${toHubAsset.asset} not found in the vault reserves for chain ${to.xChainId}`
|
|
14511
|
+
);
|
|
14512
|
+
const assetManagerBalance = reserves.balances[tokenIndex] ?? 0n;
|
|
14513
|
+
return {
|
|
14514
|
+
ok: true,
|
|
14515
|
+
value: availableDeposit < assetManagerBalance ? availableDeposit : assetManagerBalance
|
|
14516
|
+
};
|
|
14517
|
+
} catch (error) {
|
|
14518
|
+
console.error(error);
|
|
14519
|
+
return {
|
|
14520
|
+
ok: false,
|
|
14521
|
+
error
|
|
14522
|
+
};
|
|
14523
|
+
}
|
|
13742
14524
|
}
|
|
13743
14525
|
/**
|
|
13744
|
-
*
|
|
13745
|
-
*
|
|
13746
|
-
* @param
|
|
13747
|
-
* @
|
|
14526
|
+
* Check if two assets on different chains are bridgeable
|
|
14527
|
+
* Two assets are bridgeable if they share the same vault on the hub chain
|
|
14528
|
+
* @param from - The source X token
|
|
14529
|
+
* @param to - The destination X token
|
|
14530
|
+
* @param unchecked - Whether to skip the chain ID validation
|
|
14531
|
+
* @returns boolean - true if assets are bridgeable, false otherwise
|
|
13748
14532
|
*/
|
|
13749
|
-
|
|
13750
|
-
|
|
13751
|
-
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13755
|
-
|
|
13756
|
-
|
|
13757
|
-
|
|
13758
|
-
|
|
14533
|
+
isBridgeable({
|
|
14534
|
+
from,
|
|
14535
|
+
to,
|
|
14536
|
+
unchecked = false
|
|
14537
|
+
}) {
|
|
14538
|
+
try {
|
|
14539
|
+
if (!unchecked) {
|
|
14540
|
+
invariant12(isValidSpokeChainId(from.xChainId), `Invalid spoke chain (${from.xChainId})`);
|
|
14541
|
+
invariant12(isValidSpokeChainId(to.xChainId), `Invalid spoke chain (${to.xChainId})`);
|
|
14542
|
+
}
|
|
14543
|
+
const srcAssetInfo = getHubAssetInfo(from.xChainId, from.address);
|
|
14544
|
+
const dstAssetInfo = getHubAssetInfo(to.xChainId, to.address);
|
|
14545
|
+
invariant12(srcAssetInfo, `Hub asset not found for token ${from.address} on chain ${from.xChainId}`);
|
|
14546
|
+
invariant12(dstAssetInfo, `Hub asset not found for token ${to.address} on chain ${to.xChainId}`);
|
|
14547
|
+
return srcAssetInfo.vault.toLowerCase() === dstAssetInfo.vault.toLowerCase();
|
|
14548
|
+
} catch (error) {
|
|
14549
|
+
console.error(error);
|
|
14550
|
+
return false;
|
|
14551
|
+
}
|
|
13759
14552
|
}
|
|
13760
|
-
// ===== PRIVATE HELPER METHODS =====
|
|
13761
14553
|
/**
|
|
13762
|
-
*
|
|
13763
|
-
* @param
|
|
13764
|
-
* @param
|
|
13765
|
-
* @param
|
|
13766
|
-
* @returns
|
|
14554
|
+
* Get all bridgeable tokens from a source token to a destination chain
|
|
14555
|
+
* @param from - The source chain ID
|
|
14556
|
+
* @param to - The destination chain ID
|
|
14557
|
+
* @param token - The source token address
|
|
14558
|
+
* @returns XToken[] - Array of bridgeable tokens on the destination chain
|
|
13767
14559
|
*/
|
|
13768
|
-
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
-
from
|
|
13772
|
-
|
|
13773
|
-
|
|
13774
|
-
|
|
13775
|
-
|
|
13776
|
-
|
|
13777
|
-
return
|
|
14560
|
+
getBridgeableTokens(from, to, token) {
|
|
14561
|
+
try {
|
|
14562
|
+
const srcAssetInfo = getHubAssetInfo(from, token);
|
|
14563
|
+
invariant12(srcAssetInfo, `Hub asset not found for token ${token} on chain ${from}`);
|
|
14564
|
+
return {
|
|
14565
|
+
ok: true,
|
|
14566
|
+
value: this.filterTokensWithSameVault(spokeChainConfig[to].supportedTokens, to, srcAssetInfo)
|
|
14567
|
+
};
|
|
14568
|
+
} catch (error) {
|
|
14569
|
+
return {
|
|
14570
|
+
ok: false,
|
|
14571
|
+
error
|
|
14572
|
+
};
|
|
13778
14573
|
}
|
|
13779
|
-
|
|
14574
|
+
}
|
|
14575
|
+
filterTokensWithSameVault(tokens, to, srcAssetInfo) {
|
|
14576
|
+
const bridgeableTokens = [];
|
|
14577
|
+
for (const token of Object.values(tokens)) {
|
|
14578
|
+
const dstAssetInfo = getHubAssetInfo(to, token.address);
|
|
14579
|
+
if (dstAssetInfo && srcAssetInfo && dstAssetInfo.vault.toLowerCase() === srcAssetInfo.vault.toLowerCase()) {
|
|
14580
|
+
bridgeableTokens.push({
|
|
14581
|
+
...token,
|
|
14582
|
+
xChainId: to
|
|
14583
|
+
});
|
|
14584
|
+
}
|
|
14585
|
+
}
|
|
14586
|
+
return bridgeableTokens;
|
|
13780
14587
|
}
|
|
13781
14588
|
};
|
|
13782
14589
|
|
|
@@ -13789,6 +14596,8 @@ var Sodax = class {
|
|
|
13789
14596
|
// Money Market service enabling cross-chain lending and borrowing
|
|
13790
14597
|
migration;
|
|
13791
14598
|
// ICX migration service enabling ICX migration to SODA
|
|
14599
|
+
bridge;
|
|
14600
|
+
// Bridge service enabling cross-chain transfers
|
|
13792
14601
|
hubProvider;
|
|
13793
14602
|
// hub provider for the hub chain (e.g. Sonic mainnet)
|
|
13794
14603
|
relayerApiEndpoint;
|
|
@@ -13800,6 +14609,7 @@ var Sodax = class {
|
|
|
13800
14609
|
this.solver = config && config.solver ? new SolverService(config.solver, this.hubProvider, this.relayerApiEndpoint) : new SolverService(void 0, this.hubProvider, this.relayerApiEndpoint);
|
|
13801
14610
|
this.moneyMarket = config && config.moneyMarket ? new MoneyMarketService(config.moneyMarket, this.hubProvider, this.relayerApiEndpoint) : new MoneyMarketService(void 0, this.hubProvider, this.relayerApiEndpoint);
|
|
13802
14611
|
this.migration = config && config.migration ? new MigrationService(this.hubProvider, config.migration) : new MigrationService(this.hubProvider);
|
|
14612
|
+
this.bridge = config && config.bridge ? new BridgeService(this.hubProvider, this.relayerApiEndpoint, config.bridge) : new BridgeService(this.hubProvider, this.relayerApiEndpoint);
|
|
13803
14613
|
}
|
|
13804
14614
|
};
|
|
13805
14615
|
|
|
@@ -13866,16 +14676,16 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
13866
14676
|
if (!fee) {
|
|
13867
14677
|
return 0n;
|
|
13868
14678
|
}
|
|
13869
|
-
|
|
14679
|
+
invariant12(inputAmount > 0n, "Input amount must be greater than 0");
|
|
13870
14680
|
let feeAmount = 0n;
|
|
13871
14681
|
if (isPartnerFeeAmount(fee)) {
|
|
13872
|
-
|
|
14682
|
+
invariant12(
|
|
13873
14683
|
fee.amount >= 0 && fee.amount <= inputAmount,
|
|
13874
14684
|
`Fee amount must be greater than 0 and less than or equal to the input amount: ${fee.amount}`
|
|
13875
14685
|
);
|
|
13876
14686
|
feeAmount = fee.amount;
|
|
13877
14687
|
} else if (isPartnerFeePercentage(fee)) {
|
|
13878
|
-
|
|
14688
|
+
invariant12(
|
|
13879
14689
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
13880
14690
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
13881
14691
|
);
|
|
@@ -13884,8 +14694,8 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
13884
14694
|
return feeAmount;
|
|
13885
14695
|
}
|
|
13886
14696
|
function adjustAmountByFee(amount, fee, quoteType) {
|
|
13887
|
-
|
|
13888
|
-
|
|
14697
|
+
invariant12(amount > 0n, "Amount must be greater than 0");
|
|
14698
|
+
invariant12(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
|
|
13889
14699
|
if (quoteType === "exact_input") {
|
|
13890
14700
|
return amount - calculateFeeAmount(amount, fee);
|
|
13891
14701
|
}
|
|
@@ -15460,9 +16270,9 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15460
16270
|
*/
|
|
15461
16271
|
async isAllowanceValid(params, spokeProvider) {
|
|
15462
16272
|
try {
|
|
15463
|
-
|
|
15464
|
-
|
|
15465
|
-
|
|
16273
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
16274
|
+
invariant12(params.token.length > 0, "Token is required");
|
|
16275
|
+
invariant12(
|
|
15466
16276
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15467
16277
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15468
16278
|
);
|
|
@@ -15557,19 +16367,19 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15557
16367
|
*/
|
|
15558
16368
|
async approve(params, spokeProvider, raw) {
|
|
15559
16369
|
try {
|
|
15560
|
-
|
|
15561
|
-
|
|
15562
|
-
|
|
16370
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
16371
|
+
invariant12(params.token.length > 0, "Token is required");
|
|
16372
|
+
invariant12(
|
|
15563
16373
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15564
16374
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15565
16375
|
);
|
|
15566
16376
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15567
16377
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
15568
|
-
|
|
16378
|
+
invariant12(
|
|
15569
16379
|
params.action === "supply" || params.action === "repay",
|
|
15570
16380
|
"Invalid action (only supply and repay are supported on evm)"
|
|
15571
16381
|
);
|
|
15572
|
-
|
|
16382
|
+
invariant12(isAddress(params.token), "Invalid token address");
|
|
15573
16383
|
const result = await Erc20Service.approve(
|
|
15574
16384
|
params.token,
|
|
15575
16385
|
params.amount,
|
|
@@ -15583,11 +16393,11 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15583
16393
|
};
|
|
15584
16394
|
}
|
|
15585
16395
|
if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
15586
|
-
|
|
16396
|
+
invariant12(
|
|
15587
16397
|
params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
|
|
15588
16398
|
"Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
|
|
15589
16399
|
);
|
|
15590
|
-
|
|
16400
|
+
invariant12(isAddress(params.token), "Invalid token address");
|
|
15591
16401
|
if (params.action === "withdraw") {
|
|
15592
16402
|
const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
|
|
15593
16403
|
params.token,
|
|
@@ -15759,10 +16569,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15759
16569
|
*/
|
|
15760
16570
|
async createSupplyIntent(params, spokeProvider, raw) {
|
|
15761
16571
|
try {
|
|
15762
|
-
|
|
15763
|
-
|
|
15764
|
-
|
|
15765
|
-
|
|
16572
|
+
invariant12(params.action === "supply", "Invalid action");
|
|
16573
|
+
invariant12(params.token.length > 0, "Token is required");
|
|
16574
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
16575
|
+
invariant12(
|
|
15766
16576
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15767
16577
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15768
16578
|
);
|
|
@@ -15924,10 +16734,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15924
16734
|
* }
|
|
15925
16735
|
*/
|
|
15926
16736
|
async createBorrowIntent(params, spokeProvider, raw) {
|
|
15927
|
-
|
|
15928
|
-
|
|
15929
|
-
|
|
15930
|
-
|
|
16737
|
+
invariant12(params.action === "borrow", "Invalid action");
|
|
16738
|
+
invariant12(params.token.length > 0, "Token is required");
|
|
16739
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
16740
|
+
invariant12(
|
|
15931
16741
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15932
16742
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15933
16743
|
);
|
|
@@ -16060,10 +16870,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16060
16870
|
* }
|
|
16061
16871
|
*/
|
|
16062
16872
|
async createWithdrawIntent(params, spokeProvider, raw) {
|
|
16063
|
-
|
|
16064
|
-
|
|
16065
|
-
|
|
16066
|
-
|
|
16873
|
+
invariant12(params.action === "withdraw", "Invalid action");
|
|
16874
|
+
invariant12(params.token.length > 0, "Token is required");
|
|
16875
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
16876
|
+
invariant12(
|
|
16067
16877
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
16068
16878
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
16069
16879
|
);
|
|
@@ -16211,10 +17021,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16211
17021
|
* }
|
|
16212
17022
|
*/
|
|
16213
17023
|
async createRepayIntent(params, spokeProvider, raw) {
|
|
16214
|
-
|
|
16215
|
-
|
|
16216
|
-
|
|
16217
|
-
|
|
17024
|
+
invariant12(params.action === "repay", "Invalid action");
|
|
17025
|
+
invariant12(params.token.length > 0, "Token is required");
|
|
17026
|
+
invariant12(params.amount > 0n, "Amount must be greater than 0");
|
|
17027
|
+
invariant12(
|
|
16218
17028
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
16219
17029
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
16220
17030
|
);
|
|
@@ -16267,7 +17077,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16267
17077
|
buildSupplyData(token, to, amount, spokeChainId) {
|
|
16268
17078
|
const calls = [];
|
|
16269
17079
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
16270
|
-
|
|
17080
|
+
invariant12(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
16271
17081
|
let assetAddress = assetConfig.asset;
|
|
16272
17082
|
const vaultAddress = assetConfig.vault;
|
|
16273
17083
|
const lendingPool = this.config.lendingPool;
|
|
@@ -16298,13 +17108,13 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16298
17108
|
* @returns {Hex} The transaction data.
|
|
16299
17109
|
*/
|
|
16300
17110
|
buildBorrowData(from, to, token, amount, spokeChainId) {
|
|
16301
|
-
|
|
16302
|
-
|
|
17111
|
+
invariant12(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
|
|
17112
|
+
invariant12(
|
|
16303
17113
|
isValidOriginalAssetAddress(spokeChainId, token),
|
|
16304
17114
|
`Unsupported spoke chain (${spokeChainId}) token: ${token}`
|
|
16305
17115
|
);
|
|
16306
17116
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
16307
|
-
|
|
17117
|
+
invariant12(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
16308
17118
|
let assetAddress = assetConfig.asset;
|
|
16309
17119
|
const vaultAddress = assetConfig.vault;
|
|
16310
17120
|
const bnUSDVault = this.config.bnUSDVault;
|
|
@@ -16628,6 +17438,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
|
|
|
16628
17438
|
return SolverIntentErrorCode2;
|
|
16629
17439
|
})(SolverIntentErrorCode || {});
|
|
16630
17440
|
|
|
16631
|
-
export { BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, ChainIdToIntentRelayChainId, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, SupportedMigrationTokens, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isUnifiedBnUSDMigrateParams, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, moneyMarketSupportedTokens, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, originalAssetTohubAssetMap, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
17441
|
+
export { BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, BridgeService, ChainIdToIntentRelayChainId, DEFAULT_DEADLINE_OFFSET, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, SodaTokens, SodaTokensAsHubAssets, SodaVaultTokensSet, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, SuiSpokeService, SupportedMigrationTokens, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, deriveUserWalletAddress, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getHubVaultTokenByAddress, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getMoneyMarketConfig, getOriginalAssetAddress, getOriginalAssetInfoFromVault, getOriginalTokenFromOriginalAssetAddress, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hubAssetToOriginalAssetMap, hubAssets, hubVaultTokensMap, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSodaVaultToken, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isUnifiedBnUSDMigrateParams, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isValidVault, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, moneyMarketSupportedTokens, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, originalAssetTohubAssetMap, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSodaAssets, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
16632
17442
|
//# sourceMappingURL=index.mjs.map
|
|
16633
17443
|
//# sourceMappingURL=index.mjs.map
|