@sodax/sdk 0.0.1-rc.16 → 0.0.1-rc.18
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 +8 -10
- package/dist/index.cjs +499 -388
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1422 -1364
- package/dist/index.d.ts +1422 -1364
- package/dist/index.mjs +487 -389
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -9
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAbiItem, fromHex, createPublicClient, http, toHex, encodeAbiParameters, parseAbiParameters, erc20Abi as erc20Abi$1, encodeFunctionData, isAddress, decodeAbiParameters, encodePacked, parseEventLogs, keccak256 } from 'viem';
|
|
2
2
|
import { nibiru, polygon, bsc, optimism, base, arbitrum, avalanche, sonic } from 'viem/chains';
|
|
3
|
-
import { 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, SONIC_MAINNET_CHAIN_ID
|
|
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, SONIC_MAINNET_CHAIN_ID } from '@sodax/types';
|
|
4
4
|
export * from '@sodax/types';
|
|
5
5
|
import { ChainGrpcWasmApi, TxGrpcApi, toBase64 } from '@injectivelabs/sdk-ts';
|
|
6
6
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
@@ -6212,14 +6212,20 @@ var spokeChainConfig = {
|
|
|
6212
6212
|
wrappedSonic: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
6213
6213
|
},
|
|
6214
6214
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
6215
|
-
bnUSD: "
|
|
6215
|
+
bnUSD: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131",
|
|
6216
6216
|
supportedTokens: {
|
|
6217
|
-
|
|
6218
|
-
symbol: "
|
|
6217
|
+
S: {
|
|
6218
|
+
symbol: "S",
|
|
6219
6219
|
name: "Sonic",
|
|
6220
6220
|
decimals: 18,
|
|
6221
6221
|
address: "0x0000000000000000000000000000000000000000"
|
|
6222
6222
|
},
|
|
6223
|
+
bnUSD: {
|
|
6224
|
+
symbol: "bnUSD",
|
|
6225
|
+
name: "bnUSD",
|
|
6226
|
+
decimals: 18,
|
|
6227
|
+
address: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
6228
|
+
},
|
|
6223
6229
|
WETH: {
|
|
6224
6230
|
symbol: "WETH",
|
|
6225
6231
|
name: "Wrapped Ether",
|
|
@@ -6238,8 +6244,8 @@ var spokeChainConfig = {
|
|
|
6238
6244
|
decimals: 6,
|
|
6239
6245
|
address: "0x6047828dc181963ba44974801FF68e538dA5eaF9"
|
|
6240
6246
|
},
|
|
6241
|
-
|
|
6242
|
-
symbol: "
|
|
6247
|
+
wS: {
|
|
6248
|
+
symbol: "wS",
|
|
6243
6249
|
name: "Wrapped Sonic",
|
|
6244
6250
|
decimals: 18,
|
|
6245
6251
|
address: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
@@ -6788,6 +6794,14 @@ var spokeChainConfig = {
|
|
|
6788
6794
|
address: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
6789
6795
|
},
|
|
6790
6796
|
bnUSD: {
|
|
6797
|
+
// same as legacy
|
|
6798
|
+
symbol: "bnUSD",
|
|
6799
|
+
name: "bnUSD",
|
|
6800
|
+
decimals: 18,
|
|
6801
|
+
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb"
|
|
6802
|
+
},
|
|
6803
|
+
legacybnUSD: {
|
|
6804
|
+
// duplicate of bnUSD purely for consistency with other legacy tokens chains (sui, stellar)
|
|
6791
6805
|
symbol: "bnUSD",
|
|
6792
6806
|
name: "bnUSD",
|
|
6793
6807
|
decimals: 18,
|
|
@@ -6825,6 +6839,7 @@ var HubVaultSymbols = [
|
|
|
6825
6839
|
];
|
|
6826
6840
|
var hubVaults = {
|
|
6827
6841
|
IbnUSD: {
|
|
6842
|
+
// ICON bnUSD (Migration) vault on Sonic contains legacy bnUSD tokens (stellar, sui, icon)
|
|
6828
6843
|
address: "0x9D4b663Eb075d2a1C7B8eaEFB9eCCC0510388B51",
|
|
6829
6844
|
reserves: [
|
|
6830
6845
|
// hub asset addresses contained in the vault
|
|
@@ -6855,6 +6870,7 @@ var hubVaults = {
|
|
|
6855
6870
|
]
|
|
6856
6871
|
},
|
|
6857
6872
|
bnUSD: {
|
|
6873
|
+
// new bnUSD vault on Sonic (also contains IbnUSD vault token as part of it)
|
|
6858
6874
|
address: "0xe801ca34e19abcbfea12025378d19c4fbe250131",
|
|
6859
6875
|
reserves: [
|
|
6860
6876
|
// hub asset addresses contained in the vault
|
|
@@ -7000,45 +7016,81 @@ var hubVaults = {
|
|
|
7000
7016
|
]
|
|
7001
7017
|
}
|
|
7002
7018
|
};
|
|
7019
|
+
var bnUSDLegacySpokeChainIds = [
|
|
7020
|
+
ICON_MAINNET_CHAIN_ID,
|
|
7021
|
+
SUI_MAINNET_CHAIN_ID,
|
|
7022
|
+
STELLAR_MAINNET_CHAIN_ID
|
|
7023
|
+
];
|
|
7024
|
+
var newbnUSDSpokeChainIds = SPOKE_CHAIN_IDS.filter((chainId) => chainId !== ICON_MAINNET_CHAIN_ID);
|
|
7025
|
+
var bnUSDLegacyTokens = [
|
|
7026
|
+
spokeChainConfig[ICON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7027
|
+
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7028
|
+
spokeChainConfig[STELLAR_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD
|
|
7029
|
+
];
|
|
7030
|
+
var bnUSDNewTokens = newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD);
|
|
7031
|
+
var isLegacybnUSDChainId = (chainId) => {
|
|
7032
|
+
return bnUSDLegacySpokeChainIds.includes(chainId);
|
|
7033
|
+
};
|
|
7034
|
+
var isNewbnUSDChainId = (chainId) => {
|
|
7035
|
+
return newbnUSDSpokeChainIds.includes(chainId);
|
|
7036
|
+
};
|
|
7037
|
+
var isLegacybnUSDToken = (token) => {
|
|
7038
|
+
if (typeof token === "string") {
|
|
7039
|
+
return bnUSDLegacyTokens.some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7040
|
+
}
|
|
7041
|
+
return bnUSDLegacyTokens.some((t) => t.address.toLowerCase() === token.address.toLowerCase());
|
|
7042
|
+
};
|
|
7043
|
+
var isNewbnUSDToken = (token) => {
|
|
7044
|
+
if (typeof token === "string") {
|
|
7045
|
+
return newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD).some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7046
|
+
}
|
|
7047
|
+
return newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD).some((t) => t.address.toLowerCase() === token.address.toLowerCase());
|
|
7048
|
+
};
|
|
7049
|
+
var getAllLegacybnUSDTokens = () => {
|
|
7050
|
+
return bnUSDLegacySpokeChainIds.map((chainId) => ({
|
|
7051
|
+
token: spokeChainConfig[chainId].supportedTokens.legacybnUSD,
|
|
7052
|
+
chainId
|
|
7053
|
+
}));
|
|
7054
|
+
};
|
|
7003
7055
|
var hubAssets = {
|
|
7004
7056
|
[SONIC_MAINNET_CHAIN_ID]: {
|
|
7005
7057
|
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].nativeToken]: {
|
|
7006
|
-
asset:
|
|
7058
|
+
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address,
|
|
7007
7059
|
decimal: 18,
|
|
7008
7060
|
symbol: "S",
|
|
7009
7061
|
name: "Sonic",
|
|
7010
7062
|
vault: hubVaults.sodaS.address
|
|
7011
7063
|
},
|
|
7012
|
-
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7013
|
-
asset:
|
|
7064
|
+
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address]: {
|
|
7065
|
+
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address,
|
|
7014
7066
|
decimal: 18,
|
|
7015
|
-
symbol: "
|
|
7067
|
+
symbol: "wS",
|
|
7016
7068
|
name: "Sonic",
|
|
7017
7069
|
vault: hubVaults.sodaS.address
|
|
7018
7070
|
},
|
|
7019
7071
|
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH.address]: {
|
|
7020
|
-
asset:
|
|
7072
|
+
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH.address,
|
|
7021
7073
|
decimal: 18,
|
|
7022
7074
|
symbol: "WETH",
|
|
7023
7075
|
name: "Wrapped Ethereum",
|
|
7024
7076
|
vault: hubVaults.sodaETH.address
|
|
7025
7077
|
},
|
|
7026
7078
|
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC.address]: {
|
|
7027
|
-
asset:
|
|
7079
|
+
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC.address,
|
|
7028
7080
|
decimal: 6,
|
|
7029
7081
|
symbol: "USDC ",
|
|
7030
7082
|
name: "USD Coin",
|
|
7031
7083
|
vault: hubVaults.sodaUSDC.address
|
|
7032
7084
|
},
|
|
7033
7085
|
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT.address]: {
|
|
7034
|
-
asset:
|
|
7086
|
+
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT.address,
|
|
7035
7087
|
decimal: 6,
|
|
7036
7088
|
symbol: "USDT",
|
|
7037
7089
|
name: "Tether USD",
|
|
7038
7090
|
vault: hubVaults.sodaUSDT.address
|
|
7039
7091
|
},
|
|
7040
7092
|
[spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.SODA.address]: {
|
|
7041
|
-
asset:
|
|
7093
|
+
asset: spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.SODA.address,
|
|
7042
7094
|
decimal: 18,
|
|
7043
7095
|
symbol: "SODA",
|
|
7044
7096
|
name: "SODA",
|
|
@@ -7353,7 +7405,7 @@ var hubAssets = {
|
|
|
7353
7405
|
decimal: 18,
|
|
7354
7406
|
symbol: "legacybnUSD",
|
|
7355
7407
|
name: "legacybnUSD",
|
|
7356
|
-
vault:
|
|
7408
|
+
vault: hubVaults.IbnUSD.address
|
|
7357
7409
|
}
|
|
7358
7410
|
},
|
|
7359
7411
|
[SUI_MAINNET_CHAIN_ID]: {
|
|
@@ -7431,7 +7483,7 @@ var hubAssets = {
|
|
|
7431
7483
|
decimal: 9,
|
|
7432
7484
|
symbol: "bnUSD",
|
|
7433
7485
|
name: "legacybnUSD",
|
|
7434
|
-
vault:
|
|
7486
|
+
vault: hubVaults.IbnUSD.address
|
|
7435
7487
|
}
|
|
7436
7488
|
},
|
|
7437
7489
|
[SOLANA_MAINNET_CHAIN_ID]: {
|
|
@@ -7478,7 +7530,7 @@ var hubAssets = {
|
|
|
7478
7530
|
decimal: 18,
|
|
7479
7531
|
symbol: "bnUSD",
|
|
7480
7532
|
name: "bnUSD",
|
|
7481
|
-
vault: hubVaults.
|
|
7533
|
+
vault: hubVaults.IbnUSD.address
|
|
7482
7534
|
},
|
|
7483
7535
|
[spokeChainConfig[ICON_MAINNET_CHAIN_ID].supportedTokens.BALN.address]: {
|
|
7484
7536
|
asset: "0xde8e19a099fedf9d617599f62c5f7f020d92b572",
|
|
@@ -7500,10 +7552,11 @@ var solverConfig = {
|
|
|
7500
7552
|
var getSolverConfig = (chainId) => solverConfig[chainId];
|
|
7501
7553
|
var solverSupportedTokens = {
|
|
7502
7554
|
[SONIC_MAINNET_CHAIN_ID]: [
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7555
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.S,
|
|
7556
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH,
|
|
7557
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7558
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
7559
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS
|
|
7507
7560
|
],
|
|
7508
7561
|
[AVALANCHE_MAINNET_CHAIN_ID]: [
|
|
7509
7562
|
spokeChainConfig[AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.AVAX,
|
|
@@ -7670,35 +7723,13 @@ var moneyMarketSupportedTokens = {
|
|
|
7670
7723
|
],
|
|
7671
7724
|
[NIBIRU_MAINNET_CHAIN_ID]: [],
|
|
7672
7725
|
[SONIC_MAINNET_CHAIN_ID]: [
|
|
7673
|
-
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7726
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.S,
|
|
7674
7727
|
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH,
|
|
7675
7728
|
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7676
7729
|
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
7677
|
-
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7730
|
+
spokeChainConfig[SONIC_MAINNET_CHAIN_ID].supportedTokens.wS
|
|
7678
7731
|
]
|
|
7679
7732
|
};
|
|
7680
|
-
var migrationConfig = {
|
|
7681
|
-
bnUSD: {
|
|
7682
|
-
[ICON_MAINNET_CHAIN_ID]: {
|
|
7683
|
-
legacybnUSD: spokeChainConfig[ICON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7684
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7685
|
-
},
|
|
7686
|
-
[SUI_MAINNET_CHAIN_ID]: {
|
|
7687
|
-
legacybnUSD: spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7688
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7689
|
-
},
|
|
7690
|
-
[STELLAR_MAINNET_CHAIN_ID]: {
|
|
7691
|
-
legacybnUSD: spokeChainConfig[STELLAR_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7692
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7693
|
-
}
|
|
7694
|
-
},
|
|
7695
|
-
ICX: {
|
|
7696
|
-
[ICON_MAINNET_CHAIN_ID]: {
|
|
7697
|
-
icx: spokeChainConfig[ICON_MAINNET_CHAIN_ID]["nativeToken"],
|
|
7698
|
-
wICX: spokeChainConfig[ICON_MAINNET_CHAIN_ID]["addresses"]["wICX"]
|
|
7699
|
-
}
|
|
7700
|
-
}
|
|
7701
|
-
};
|
|
7702
7733
|
var isMoneyMarketSupportedToken = (chainId, token) => moneyMarketSupportedTokens[chainId].some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7703
7734
|
var getSupportedMoneyMarketTokens = (chainId) => moneyMarketSupportedTokens[chainId];
|
|
7704
7735
|
var hubVaultsAddressSet = new Set(
|
|
@@ -9025,16 +9056,28 @@ var EvmWalletAbstraction = class {
|
|
|
9025
9056
|
var WalletAbstractionService = class {
|
|
9026
9057
|
constructor() {
|
|
9027
9058
|
}
|
|
9028
|
-
|
|
9029
|
-
|
|
9059
|
+
/**
|
|
9060
|
+
* Gets the hub wallet address for a user based on their spoke chain address.
|
|
9061
|
+
* @param address - The user's address on the spoke chain
|
|
9062
|
+
* @param spokeProvider - The provider for interacting with the spoke chain
|
|
9063
|
+
* @param hubProvider - The provider for interacting with the hub chain
|
|
9064
|
+
* @returns The user's hub wallet address
|
|
9065
|
+
*/
|
|
9066
|
+
static async getUserHubWalletAddress(address, spokeProvider, hubProvider) {
|
|
9067
|
+
const encodedAddress = encodeAddress(spokeProvider.chainConfig.chain.id, address);
|
|
9068
|
+
if (spokeProvider.chainConfig.chain.id === hubProvider.chainConfig.chain.id) {
|
|
9030
9069
|
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
9031
|
-
return SonicSpokeService.getUserRouter(
|
|
9070
|
+
return SonicSpokeService.getUserRouter(encodedAddress, spokeProvider);
|
|
9032
9071
|
}
|
|
9033
9072
|
throw new Error(
|
|
9034
9073
|
"[WalletAbstractionService.getUserHubWalletAddress] Invalid spoke provider. Sonic spoke provider is required."
|
|
9035
9074
|
);
|
|
9036
9075
|
}
|
|
9037
|
-
return EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9076
|
+
return EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9077
|
+
spokeProvider.chainConfig.chain.id,
|
|
9078
|
+
encodedAddress,
|
|
9079
|
+
hubProvider
|
|
9080
|
+
);
|
|
9038
9081
|
}
|
|
9039
9082
|
};
|
|
9040
9083
|
async function retry(action, retryCount = DEFAULT_MAX_RETRY, delayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
@@ -9412,26 +9455,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9412
9455
|
if (!txResult.ok) {
|
|
9413
9456
|
return txResult;
|
|
9414
9457
|
}
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9458
|
+
let intentTxHash = null;
|
|
9459
|
+
if (spokeProvider.chainConfig.chain.id !== SONIC_MAINNET_CHAIN_ID) {
|
|
9460
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9461
|
+
txResult.value,
|
|
9462
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9463
|
+
spokeProvider,
|
|
9464
|
+
this.config.relayerApiEndpoint,
|
|
9465
|
+
timeout
|
|
9466
|
+
);
|
|
9467
|
+
if (!packetResult.ok) {
|
|
9468
|
+
return {
|
|
9469
|
+
ok: false,
|
|
9470
|
+
error: {
|
|
9471
|
+
code: packetResult.error.code,
|
|
9472
|
+
data: {
|
|
9473
|
+
error: packetResult.error,
|
|
9474
|
+
payload: txResult.value
|
|
9475
|
+
}
|
|
9430
9476
|
}
|
|
9431
|
-
}
|
|
9432
|
-
}
|
|
9477
|
+
};
|
|
9478
|
+
}
|
|
9479
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9480
|
+
} else {
|
|
9481
|
+
intentTxHash = txResult.value;
|
|
9433
9482
|
}
|
|
9434
|
-
return { ok: true, value: [txResult.value,
|
|
9483
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9435
9484
|
} catch (error) {
|
|
9436
9485
|
return {
|
|
9437
9486
|
ok: false,
|
|
@@ -9486,12 +9535,11 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9486
9535
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9487
9536
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9488
9537
|
);
|
|
9489
|
-
const
|
|
9538
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9490
9539
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
this.hubProvider
|
|
9494
|
-
spokeProvider
|
|
9540
|
+
walletAddress,
|
|
9541
|
+
spokeProvider,
|
|
9542
|
+
this.hubProvider
|
|
9495
9543
|
);
|
|
9496
9544
|
const data = this.buildSupplyData(
|
|
9497
9545
|
params.token,
|
|
@@ -9499,7 +9547,6 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9499
9547
|
params.amount,
|
|
9500
9548
|
spokeProvider.chainConfig.chain.id
|
|
9501
9549
|
);
|
|
9502
|
-
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9503
9550
|
const txResult = await SpokeService.deposit(
|
|
9504
9551
|
{
|
|
9505
9552
|
from: walletAddress,
|
|
@@ -9566,26 +9613,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9566
9613
|
if (!txResult.ok) {
|
|
9567
9614
|
return txResult;
|
|
9568
9615
|
}
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
|
|
9616
|
+
let intentTxHash = null;
|
|
9617
|
+
if (spokeProvider.chainConfig.chain.id !== SONIC_MAINNET_CHAIN_ID) {
|
|
9618
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9619
|
+
txResult.value,
|
|
9620
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9621
|
+
spokeProvider,
|
|
9622
|
+
this.config.relayerApiEndpoint,
|
|
9623
|
+
timeout
|
|
9624
|
+
);
|
|
9625
|
+
if (!packetResult.ok) {
|
|
9626
|
+
return {
|
|
9627
|
+
ok: false,
|
|
9628
|
+
error: {
|
|
9629
|
+
code: packetResult.error.code,
|
|
9630
|
+
data: {
|
|
9631
|
+
error: packetResult.error,
|
|
9632
|
+
payload: txResult.value
|
|
9633
|
+
}
|
|
9584
9634
|
}
|
|
9585
|
-
}
|
|
9586
|
-
}
|
|
9635
|
+
};
|
|
9636
|
+
}
|
|
9637
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9638
|
+
} else {
|
|
9639
|
+
intentTxHash = txResult.value;
|
|
9587
9640
|
}
|
|
9588
|
-
return { ok: true, value: [txResult.value,
|
|
9641
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9589
9642
|
} catch (error) {
|
|
9590
9643
|
return {
|
|
9591
9644
|
ok: false,
|
|
@@ -9637,16 +9690,16 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9637
9690
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9638
9691
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9639
9692
|
);
|
|
9640
|
-
const
|
|
9693
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9694
|
+
const encodedAddress = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
|
|
9641
9695
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
this.hubProvider
|
|
9645
|
-
spokeProvider
|
|
9696
|
+
walletAddress,
|
|
9697
|
+
spokeProvider,
|
|
9698
|
+
this.hubProvider
|
|
9646
9699
|
);
|
|
9647
9700
|
const data = this.buildBorrowData(
|
|
9648
9701
|
hubWallet,
|
|
9649
|
-
|
|
9702
|
+
encodedAddress,
|
|
9650
9703
|
params.token,
|
|
9651
9704
|
params.amount,
|
|
9652
9705
|
spokeProvider.chainConfig.chain.id
|
|
@@ -9695,26 +9748,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9695
9748
|
if (!txResult.ok) {
|
|
9696
9749
|
return txResult;
|
|
9697
9750
|
}
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9751
|
+
let intentTxHash = null;
|
|
9752
|
+
if (spokeProvider.chainConfig.chain.id !== SONIC_MAINNET_CHAIN_ID) {
|
|
9753
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9754
|
+
txResult.value,
|
|
9755
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9756
|
+
spokeProvider,
|
|
9757
|
+
this.config.relayerApiEndpoint,
|
|
9758
|
+
timeout
|
|
9759
|
+
);
|
|
9760
|
+
if (!packetResult.ok) {
|
|
9761
|
+
return {
|
|
9762
|
+
ok: false,
|
|
9763
|
+
error: {
|
|
9764
|
+
code: packetResult.error.code,
|
|
9765
|
+
data: {
|
|
9766
|
+
error: packetResult.error,
|
|
9767
|
+
payload: txResult.value
|
|
9768
|
+
}
|
|
9713
9769
|
}
|
|
9714
|
-
}
|
|
9715
|
-
}
|
|
9770
|
+
};
|
|
9771
|
+
}
|
|
9772
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9773
|
+
} else {
|
|
9774
|
+
intentTxHash = txResult.value;
|
|
9716
9775
|
}
|
|
9717
|
-
return { ok: true, value: [txResult.value,
|
|
9776
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9718
9777
|
} catch (error) {
|
|
9719
9778
|
return {
|
|
9720
9779
|
ok: false,
|
|
@@ -9766,16 +9825,16 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9766
9825
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9767
9826
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9768
9827
|
);
|
|
9769
|
-
const
|
|
9828
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9829
|
+
const encodedAddress = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
|
|
9770
9830
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
this.hubProvider
|
|
9774
|
-
spokeProvider
|
|
9831
|
+
walletAddress,
|
|
9832
|
+
spokeProvider,
|
|
9833
|
+
this.hubProvider
|
|
9775
9834
|
);
|
|
9776
9835
|
const data = this.buildWithdrawData(
|
|
9777
9836
|
hubWallet,
|
|
9778
|
-
|
|
9837
|
+
encodedAddress,
|
|
9779
9838
|
params.token,
|
|
9780
9839
|
params.amount,
|
|
9781
9840
|
spokeProvider.chainConfig.chain.id
|
|
@@ -9824,26 +9883,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9824
9883
|
if (!txResult.ok) {
|
|
9825
9884
|
return txResult;
|
|
9826
9885
|
}
|
|
9827
|
-
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
|
|
9831
|
-
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
|
|
9838
|
-
|
|
9839
|
-
|
|
9840
|
-
|
|
9841
|
-
|
|
9886
|
+
let intentTxHash = null;
|
|
9887
|
+
if (spokeProvider.chainConfig.chain.id !== SONIC_MAINNET_CHAIN_ID) {
|
|
9888
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9889
|
+
txResult.value,
|
|
9890
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9891
|
+
spokeProvider,
|
|
9892
|
+
this.config.relayerApiEndpoint,
|
|
9893
|
+
timeout
|
|
9894
|
+
);
|
|
9895
|
+
if (!packetResult.ok) {
|
|
9896
|
+
return {
|
|
9897
|
+
ok: false,
|
|
9898
|
+
error: {
|
|
9899
|
+
code: packetResult.error.code,
|
|
9900
|
+
data: {
|
|
9901
|
+
error: packetResult.error,
|
|
9902
|
+
payload: txResult.value
|
|
9903
|
+
}
|
|
9842
9904
|
}
|
|
9843
|
-
}
|
|
9844
|
-
}
|
|
9905
|
+
};
|
|
9906
|
+
}
|
|
9907
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9908
|
+
} else {
|
|
9909
|
+
intentTxHash = txResult.value;
|
|
9845
9910
|
}
|
|
9846
|
-
return { ok: true, value: [txResult.value,
|
|
9911
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9847
9912
|
} catch (error) {
|
|
9848
9913
|
return {
|
|
9849
9914
|
ok: false,
|
|
@@ -9897,15 +9962,13 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9897
9962
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9898
9963
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9899
9964
|
);
|
|
9900
|
-
const
|
|
9965
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9901
9966
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
this.hubProvider
|
|
9905
|
-
spokeProvider
|
|
9967
|
+
walletAddress,
|
|
9968
|
+
spokeProvider,
|
|
9969
|
+
this.hubProvider
|
|
9906
9970
|
);
|
|
9907
9971
|
const data = this.buildRepayData(params.token, hubWallet, params.amount, spokeProvider.chainConfig.chain.id);
|
|
9908
|
-
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9909
9972
|
const txResult = await SpokeService.deposit(
|
|
9910
9973
|
{
|
|
9911
9974
|
from: walletAddress,
|
|
@@ -11614,6 +11677,18 @@ function isMoneyMarketWithdrawUnknownError(error) {
|
|
|
11614
11677
|
function isMoneyMarketRepayUnknownError(error) {
|
|
11615
11678
|
return typeof error === "object" && error !== null && "code" in error && error.code === "REPAY_UNKNOWN_ERROR";
|
|
11616
11679
|
}
|
|
11680
|
+
function isIcxMigrateParams(value) {
|
|
11681
|
+
return typeof value === "object" && value !== null && "address" in value && "amount" in value && "to" in value;
|
|
11682
|
+
}
|
|
11683
|
+
function isUnifiedBnUSDMigrateParams(value) {
|
|
11684
|
+
return typeof value === "object" && value !== null && "srcChainId" in value && "srcbnUSD" in value && "dstChainId" in value && "dstbnUSD" in value && "amount" in value && "to" in value;
|
|
11685
|
+
}
|
|
11686
|
+
function isBalnMigrateParams(value) {
|
|
11687
|
+
return typeof value === "object" && value !== null && "amount" in value && "lockupPeriod" in value && "to" in value && "stake" in value;
|
|
11688
|
+
}
|
|
11689
|
+
function isIcxCreateRevertMigrationParams(value) {
|
|
11690
|
+
return typeof value === "object" && value !== null && "amount" in value && "to" in value;
|
|
11691
|
+
}
|
|
11617
11692
|
|
|
11618
11693
|
// src/services/spoke/SpokeService.ts
|
|
11619
11694
|
var SpokeService = class {
|
|
@@ -12496,15 +12571,15 @@ var SolverService = class {
|
|
|
12496
12571
|
* // handle error
|
|
12497
12572
|
* }
|
|
12498
12573
|
*/
|
|
12499
|
-
async swap(payload, spokeProvider,
|
|
12500
|
-
return this.createAndSubmitIntent(payload, spokeProvider,
|
|
12574
|
+
async swap(payload, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12575
|
+
return this.createAndSubmitIntent(payload, spokeProvider, this.config.partnerFee, timeout);
|
|
12501
12576
|
}
|
|
12502
12577
|
/**
|
|
12503
12578
|
* Creates an intent and submits it to the Solver API and Relayer API
|
|
12504
12579
|
* @param {CreateIntentParams} payload - The intent to create
|
|
12505
12580
|
* @param {ISpokeProvider} spokeProvider - The spoke provider
|
|
12506
12581
|
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
12507
|
-
* @returns {Promise<Result<[SolverExecutionResponse, Intent,
|
|
12582
|
+
* @returns {Promise<Result<[SolverExecutionResponse, Intent, Hex], IntentError<IntentErrorCode>>>} The solver execution response, intent, and packet data
|
|
12508
12583
|
*
|
|
12509
12584
|
* @example
|
|
12510
12585
|
* const payload = {
|
|
@@ -12533,49 +12608,55 @@ var SolverService = class {
|
|
|
12533
12608
|
* // handle error
|
|
12534
12609
|
* }
|
|
12535
12610
|
*/
|
|
12536
|
-
async createAndSubmitIntent(payload, spokeProvider, fee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12611
|
+
async createAndSubmitIntent(payload, spokeProvider, fee = this.config.partnerFee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12537
12612
|
try {
|
|
12538
12613
|
const createIntentResult = await this.createIntent(payload, spokeProvider, fee, false);
|
|
12539
12614
|
if (!createIntentResult.ok) {
|
|
12540
12615
|
return createIntentResult;
|
|
12541
12616
|
}
|
|
12542
12617
|
const [spokeTxHash, intent, data] = createIntentResult.value;
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12618
|
+
let intentTxHash = null;
|
|
12619
|
+
if (spokeProvider.chainConfig.chain.id !== SONIC_MAINNET_CHAIN_ID) {
|
|
12620
|
+
const intentRelayChainId = getIntentRelayChainId(payload.srcChain).toString();
|
|
12621
|
+
const submitPayload = payload.srcChain === SOLANA_MAINNET_CHAIN_ID && data ? {
|
|
12622
|
+
action: "submit",
|
|
12623
|
+
params: {
|
|
12624
|
+
chain_id: intentRelayChainId,
|
|
12625
|
+
tx_hash: spokeTxHash,
|
|
12626
|
+
data: {
|
|
12627
|
+
address: intent.creator,
|
|
12628
|
+
payload: data
|
|
12629
|
+
}
|
|
12630
|
+
}
|
|
12631
|
+
} : {
|
|
12632
|
+
action: "submit",
|
|
12633
|
+
params: {
|
|
12634
|
+
chain_id: intentRelayChainId,
|
|
12635
|
+
tx_hash: spokeTxHash
|
|
12552
12636
|
}
|
|
12637
|
+
};
|
|
12638
|
+
const submitResult = await this.submitIntent(submitPayload);
|
|
12639
|
+
if (!submitResult.ok) {
|
|
12640
|
+
return submitResult;
|
|
12553
12641
|
}
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
|
|
12557
|
-
|
|
12558
|
-
|
|
12642
|
+
const packet = await waitUntilIntentExecuted({
|
|
12643
|
+
intentRelayChainId,
|
|
12644
|
+
spokeTxHash,
|
|
12645
|
+
timeout,
|
|
12646
|
+
apiUrl: this.config.relayerApiEndpoint
|
|
12647
|
+
});
|
|
12648
|
+
if (!packet.ok) {
|
|
12649
|
+
return {
|
|
12650
|
+
ok: false,
|
|
12651
|
+
error: packet.error
|
|
12652
|
+
};
|
|
12559
12653
|
}
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
return submitResult;
|
|
12564
|
-
}
|
|
12565
|
-
const packet = await waitUntilIntentExecuted({
|
|
12566
|
-
intentRelayChainId,
|
|
12567
|
-
spokeTxHash,
|
|
12568
|
-
timeout,
|
|
12569
|
-
apiUrl: this.config.relayerApiEndpoint
|
|
12570
|
-
});
|
|
12571
|
-
if (!packet.ok) {
|
|
12572
|
-
return {
|
|
12573
|
-
ok: false,
|
|
12574
|
-
error: packet.error
|
|
12575
|
-
};
|
|
12654
|
+
intentTxHash = packet.value.dst_tx_hash;
|
|
12655
|
+
} else {
|
|
12656
|
+
intentTxHash = spokeTxHash;
|
|
12576
12657
|
}
|
|
12577
12658
|
const result = await this.postExecution({
|
|
12578
|
-
intent_tx_hash:
|
|
12659
|
+
intent_tx_hash: intentTxHash
|
|
12579
12660
|
});
|
|
12580
12661
|
if (!result.ok) {
|
|
12581
12662
|
return {
|
|
@@ -12588,7 +12669,7 @@ var SolverService = class {
|
|
|
12588
12669
|
}
|
|
12589
12670
|
return {
|
|
12590
12671
|
ok: true,
|
|
12591
|
-
value: [result.value, intent,
|
|
12672
|
+
value: [result.value, intent, intentTxHash]
|
|
12592
12673
|
};
|
|
12593
12674
|
} catch (error) {
|
|
12594
12675
|
return {
|
|
@@ -12758,12 +12839,7 @@ var SolverService = class {
|
|
|
12758
12839
|
"srcAddress must be the same as wallet address"
|
|
12759
12840
|
);
|
|
12760
12841
|
const walletAddressBytes = encodeAddress(params.srcChain, walletAddress);
|
|
12761
|
-
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(
|
|
12762
|
-
params.srcChain,
|
|
12763
|
-
walletAddressBytes,
|
|
12764
|
-
this.hubProvider,
|
|
12765
|
-
spokeProvider
|
|
12766
|
-
);
|
|
12842
|
+
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12767
12843
|
const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
|
|
12768
12844
|
{
|
|
12769
12845
|
...params,
|
|
@@ -12813,13 +12889,9 @@ var SolverService = class {
|
|
|
12813
12889
|
try {
|
|
12814
12890
|
invariant2(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
12815
12891
|
invariant2(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
12816
|
-
const
|
|
12817
|
-
const
|
|
12818
|
-
|
|
12819
|
-
walletAddressBytes,
|
|
12820
|
-
this.hubProvider,
|
|
12821
|
-
spokeProvider
|
|
12822
|
-
);
|
|
12892
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12893
|
+
const walletAddressBytes = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
|
|
12894
|
+
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12823
12895
|
const calls = [];
|
|
12824
12896
|
const intentsContract = this.config.intentsContract;
|
|
12825
12897
|
calls.push(EvmSolverService.encodeCancelIntent(intent, intentsContract));
|
|
@@ -13444,9 +13516,25 @@ var MigrationService = class {
|
|
|
13444
13516
|
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
13445
13517
|
invariant2(isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
13446
13518
|
invariant2(
|
|
13447
|
-
|
|
13448
|
-
"
|
|
13519
|
+
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
13520
|
+
"Invalid params"
|
|
13449
13521
|
);
|
|
13522
|
+
if (spokeProvider instanceof IconSpokeProvider && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
|
|
13523
|
+
return {
|
|
13524
|
+
ok: true,
|
|
13525
|
+
value: true
|
|
13526
|
+
};
|
|
13527
|
+
}
|
|
13528
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13529
|
+
const evmSpokeProvider = spokeProvider;
|
|
13530
|
+
return await Erc20Service.isAllowanceValid(
|
|
13531
|
+
params.srcbnUSD,
|
|
13532
|
+
params.amount,
|
|
13533
|
+
await evmSpokeProvider.walletProvider.getWalletAddress(),
|
|
13534
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13535
|
+
evmSpokeProvider
|
|
13536
|
+
);
|
|
13537
|
+
}
|
|
13450
13538
|
return {
|
|
13451
13539
|
ok: true,
|
|
13452
13540
|
value: true
|
|
@@ -13455,19 +13543,28 @@ var MigrationService = class {
|
|
|
13455
13543
|
if (action === "revert") {
|
|
13456
13544
|
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
13457
13545
|
invariant2(params.to.length > 0, "To address is required");
|
|
13458
|
-
invariant2(
|
|
13459
|
-
|
|
13460
|
-
|
|
13461
|
-
|
|
13462
|
-
|
|
13463
|
-
|
|
13464
|
-
|
|
13465
|
-
|
|
13466
|
-
|
|
13467
|
-
|
|
13468
|
-
|
|
13469
|
-
|
|
13470
|
-
)
|
|
13546
|
+
invariant2(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13547
|
+
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
13548
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
13549
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
13550
|
+
return await Erc20Service.isAllowanceValid(
|
|
13551
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
13552
|
+
params.amount,
|
|
13553
|
+
wallet,
|
|
13554
|
+
userRouter,
|
|
13555
|
+
spokeProvider
|
|
13556
|
+
);
|
|
13557
|
+
}
|
|
13558
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13559
|
+
const evmSpokeProvider = spokeProvider;
|
|
13560
|
+
return await Erc20Service.isAllowanceValid(
|
|
13561
|
+
params.srcbnUSD,
|
|
13562
|
+
params.amount,
|
|
13563
|
+
await evmSpokeProvider.walletProvider.getWalletAddress(),
|
|
13564
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13565
|
+
evmSpokeProvider
|
|
13566
|
+
);
|
|
13567
|
+
}
|
|
13471
13568
|
}
|
|
13472
13569
|
return {
|
|
13473
13570
|
ok: false,
|
|
@@ -13501,25 +13598,65 @@ var MigrationService = class {
|
|
|
13501
13598
|
*/
|
|
13502
13599
|
async approve(params, action, spokeProvider, raw) {
|
|
13503
13600
|
try {
|
|
13601
|
+
if (action === "migrate") {
|
|
13602
|
+
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
13603
|
+
invariant2(params.to.length > 0, "To address is required");
|
|
13604
|
+
invariant2(isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13605
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13606
|
+
const evmSpokeProvider = spokeProvider;
|
|
13607
|
+
const result = await Erc20Service.approve(
|
|
13608
|
+
params.srcbnUSD,
|
|
13609
|
+
params.amount,
|
|
13610
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13611
|
+
evmSpokeProvider,
|
|
13612
|
+
raw
|
|
13613
|
+
);
|
|
13614
|
+
return {
|
|
13615
|
+
ok: true,
|
|
13616
|
+
value: result
|
|
13617
|
+
};
|
|
13618
|
+
}
|
|
13619
|
+
return {
|
|
13620
|
+
ok: false,
|
|
13621
|
+
error: new Error("Invalid params for migrate action")
|
|
13622
|
+
};
|
|
13623
|
+
}
|
|
13504
13624
|
if (action === "revert") {
|
|
13505
13625
|
invariant2(params.amount > 0n, "Amount must be greater than 0");
|
|
13506
13626
|
invariant2(params.to.length > 0, "To address is required");
|
|
13507
|
-
invariant2(
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
13512
|
-
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13627
|
+
invariant2(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13628
|
+
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
13629
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
13630
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
13631
|
+
const result = await Erc20Service.approve(
|
|
13632
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
13633
|
+
params.amount,
|
|
13634
|
+
userRouter,
|
|
13635
|
+
spokeProvider,
|
|
13636
|
+
raw
|
|
13637
|
+
);
|
|
13638
|
+
return {
|
|
13639
|
+
ok: true,
|
|
13640
|
+
value: result
|
|
13641
|
+
};
|
|
13642
|
+
}
|
|
13643
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13644
|
+
const evmSpokeProvider = spokeProvider;
|
|
13645
|
+
const result = await Erc20Service.approve(
|
|
13646
|
+
params.srcbnUSD,
|
|
13647
|
+
params.amount,
|
|
13648
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13649
|
+
evmSpokeProvider,
|
|
13650
|
+
raw
|
|
13651
|
+
);
|
|
13652
|
+
return {
|
|
13653
|
+
ok: true,
|
|
13654
|
+
value: result
|
|
13655
|
+
};
|
|
13656
|
+
}
|
|
13520
13657
|
return {
|
|
13521
|
-
ok:
|
|
13522
|
-
|
|
13658
|
+
ok: false,
|
|
13659
|
+
error: new Error("Invalid params or chain type for revert action")
|
|
13523
13660
|
};
|
|
13524
13661
|
}
|
|
13525
13662
|
return {
|
|
@@ -13534,27 +13671,37 @@ var MigrationService = class {
|
|
|
13534
13671
|
}
|
|
13535
13672
|
}
|
|
13536
13673
|
/**
|
|
13537
|
-
* Migrates
|
|
13538
|
-
*
|
|
13674
|
+
* Migrates bnUSD tokens between legacy and new formats across supported spoke chains via the hub chain (sonic).
|
|
13675
|
+
* Handles both legacy-to-new and new-to-legacy bnUSD migrations, enforcing validation and relaying the transaction.
|
|
13539
13676
|
*
|
|
13540
|
-
* @param params -
|
|
13541
|
-
* @param spokeProvider - The
|
|
13542
|
-
* @param timeout -
|
|
13677
|
+
* @param params - Migration parameters, including source/destination chain IDs, token addresses, amount, and recipient.
|
|
13678
|
+
* @param spokeProvider - The SpokeProvider instance for the source chain.
|
|
13679
|
+
* @param timeout - Optional timeout in milliseconds for the relay operation (default: 60 seconds).
|
|
13680
|
+
* @param unchecked - Optional flag to skip validation checks (default: false).
|
|
13543
13681
|
* @returns {Promise<Result<[string, Hex], MigrationError<'MIGRATION_FAILED'> | MigrationError<'CREATE_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
13544
|
-
*
|
|
13545
|
-
* or an error describing why the migration or relay failed.
|
|
13546
|
-
*
|
|
13682
|
+
* Result containing a tuple: [spokeTxHash, hubTxHash] if successful, or an error describing the failure.
|
|
13547
13683
|
*
|
|
13548
13684
|
* @example
|
|
13549
|
-
* //
|
|
13685
|
+
* // Migrate legacy bnUSD to new bnUSD
|
|
13550
13686
|
* const result = await sodax.migration.migratebnUSD({
|
|
13551
|
-
*
|
|
13552
|
-
*
|
|
13553
|
-
*
|
|
13554
|
-
*
|
|
13555
|
-
*
|
|
13687
|
+
* srcChainId: '0x1.icon', // Source chain ID (legacy)
|
|
13688
|
+
* dstChainId: 'sonic', // Destination chain ID (new)
|
|
13689
|
+
* srcbnUSD: 'cx...', // Legacy bnUSD token address
|
|
13690
|
+
* dstbnUSD: '0x...', // New bnUSD token address
|
|
13691
|
+
* amount: 1000n, // Amount to migrate
|
|
13692
|
+
* to: '0x...', // Recipient address on destination chain
|
|
13556
13693
|
* }, iconSpokeProvider);
|
|
13557
13694
|
*
|
|
13695
|
+
* // Reverse migration: new bnUSD to legacy bnUSD
|
|
13696
|
+
* const result = await sodax.migration.migratebnUSD({
|
|
13697
|
+
* srcChainId: 'sonic', // Source chain ID (new)
|
|
13698
|
+
* dstChainId: '0x1.icon', // Destination chain ID (legacy)
|
|
13699
|
+
* srcbnUSD: '0x...', // New bnUSD token address
|
|
13700
|
+
* dstbnUSD: 'cx...', // Legacy bnUSD token address
|
|
13701
|
+
* amount: 1000n, // Amount to migrate
|
|
13702
|
+
* to: 'hx...', // Recipient address on destination chain
|
|
13703
|
+
* }, sonicSpokeProvider);
|
|
13704
|
+
*
|
|
13558
13705
|
* if (result.ok) {
|
|
13559
13706
|
* // result.value is a tuple: [spokeTxHash, hubTxHash]
|
|
13560
13707
|
* const [spokeTxHash, hubTxHash] = result.value;
|
|
@@ -13565,9 +13712,9 @@ var MigrationService = class {
|
|
|
13565
13712
|
* console.error('[migrateBnUSD] error', result.error);
|
|
13566
13713
|
* }
|
|
13567
13714
|
*/
|
|
13568
|
-
async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
13715
|
+
async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT, unchecked = false) {
|
|
13569
13716
|
try {
|
|
13570
|
-
const txResult = await this.createMigratebnUSDIntent(params, spokeProvider);
|
|
13717
|
+
const txResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked);
|
|
13571
13718
|
if (!txResult.ok) {
|
|
13572
13719
|
return {
|
|
13573
13720
|
ok: false,
|
|
@@ -13598,70 +13745,6 @@ var MigrationService = class {
|
|
|
13598
13745
|
};
|
|
13599
13746
|
}
|
|
13600
13747
|
}
|
|
13601
|
-
/**
|
|
13602
|
-
* Reverses the migration of legacy bnUSD tokens to new bnUSD tokens on the hub chain (sonic).
|
|
13603
|
-
* This function handles the reversal of the migration of legacy bnUSD tokens to new bnUSD tokens.
|
|
13604
|
-
*
|
|
13605
|
-
* @param params - The parameters for the migration transaction.
|
|
13606
|
-
* @param spokeProvider - The spoke provider.
|
|
13607
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
13608
|
-
* @returns {Promise<Result<[string, Hex], MigrationError<'REVERT_MIGRATION_FAILED'> | MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
13609
|
-
* Returns a Result containing a tuple of [spokeTxHash, hubTxHash] if successful,
|
|
13610
|
-
* or an error describing why the revert migration or relay failed.
|
|
13611
|
-
*
|
|
13612
|
-
*
|
|
13613
|
-
* @example
|
|
13614
|
-
* // Example: Reverse the migration of legacy bnUSD tokens to new bnUSD tokens on the hub chain (sonic)
|
|
13615
|
-
* const result = await sodax.migration.reverseMigratebnUSD({
|
|
13616
|
-
* srcChainID: 'sonic', // source chain ID (e.g., SONIC_MAINNET_CHAIN_ID)
|
|
13617
|
-
* amount: 1000000000000000000n,
|
|
13618
|
-
* to: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd', // The spoke chain address that will receive the migrated legacy bnUSD tokens
|
|
13619
|
-
* dstChainID: '0x1.icon', // destination chain ID of type bnUSDLegacySpokeChainId (e.g., ICON_MAINNET_CHAIN_ID)
|
|
13620
|
-
* }, iconSpokeProvider);
|
|
13621
|
-
*
|
|
13622
|
-
* if (result.ok) {
|
|
13623
|
-
* // result.value is a tuple: [spokeTxHash, hubTxHash]
|
|
13624
|
-
* const [spokeTxHash, hubTxHash] = result.value;
|
|
13625
|
-
* console.log('[reverseMigrateBnUSD] hubTxHash', hubTxHash);
|
|
13626
|
-
* console.log('[reverseMigrateBnUSD] spokeTxHash', spokeTxHash);
|
|
13627
|
-
* } else {
|
|
13628
|
-
* // Handle revert migration error
|
|
13629
|
-
* console.error('[reverseMigrateBnUSD] error', result.error);
|
|
13630
|
-
* }
|
|
13631
|
-
*/
|
|
13632
|
-
async reverseMigratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
13633
|
-
try {
|
|
13634
|
-
const txResult = await this.createRevertMigratebnUSDIntent(params, spokeProvider);
|
|
13635
|
-
if (!txResult.ok) {
|
|
13636
|
-
return {
|
|
13637
|
-
ok: false,
|
|
13638
|
-
error: txResult.error
|
|
13639
|
-
};
|
|
13640
|
-
}
|
|
13641
|
-
const packetResult = await relayTxAndWaitPacket(
|
|
13642
|
-
txResult.value,
|
|
13643
|
-
void 0,
|
|
13644
|
-
spokeProvider,
|
|
13645
|
-
this.config.relayerApiEndpoint,
|
|
13646
|
-
timeout
|
|
13647
|
-
);
|
|
13648
|
-
if (!packetResult.ok) {
|
|
13649
|
-
return packetResult;
|
|
13650
|
-
}
|
|
13651
|
-
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
13652
|
-
} catch (error) {
|
|
13653
|
-
return {
|
|
13654
|
-
ok: false,
|
|
13655
|
-
error: {
|
|
13656
|
-
code: "REVERT_MIGRATION_FAILED",
|
|
13657
|
-
data: {
|
|
13658
|
-
payload: params,
|
|
13659
|
-
error
|
|
13660
|
-
}
|
|
13661
|
-
}
|
|
13662
|
-
};
|
|
13663
|
-
}
|
|
13664
|
-
}
|
|
13665
13748
|
/**
|
|
13666
13749
|
* Migrates ICX tokens to SODA tokens on the hub chain (sonic).
|
|
13667
13750
|
* This function handles the migration of ICX tokens to SODA tokens.
|
|
@@ -13854,62 +13937,6 @@ var MigrationService = class {
|
|
|
13854
13937
|
};
|
|
13855
13938
|
}
|
|
13856
13939
|
}
|
|
13857
|
-
/**
|
|
13858
|
-
* Creates a revert migration intent and submits (relays) it to the spoke chain.
|
|
13859
|
-
* @param params - The parameters for the revert migration transaction.
|
|
13860
|
-
* @param spokeProvider - The spoke provider.
|
|
13861
|
-
* @param raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
13862
|
-
* @returns {Promise<Result<TxReturnType<bnUSDLegacyMigrationProviders, R>>>} - Returns the raw transaction payload or transaction hash
|
|
13863
|
-
*
|
|
13864
|
-
* @example
|
|
13865
|
-
* const result = await migrationService.createRevertMigratebnUSDIntent(
|
|
13866
|
-
* {
|
|
13867
|
-
* srcChainID: 'sonic', // The source chain ID where the new bnUSD token exists (hub chain)
|
|
13868
|
-
* amount: 1000n, // The amount of new bnUSD tokens to migrate back
|
|
13869
|
-
* to: '0x...', // The spoke chain address that will receive the migrated legacy bnUSD tokens
|
|
13870
|
-
* dstChainID: '0x1.icon', // The destination chain ID for the migration (spoke chain)
|
|
13871
|
-
* },
|
|
13872
|
-
* spokeProvider, // IconSpokeProvider instance
|
|
13873
|
-
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
13874
|
-
* );
|
|
13875
|
-
*
|
|
13876
|
-
*/
|
|
13877
|
-
async createRevertMigratebnUSDIntent(params, spokeProvider, raw) {
|
|
13878
|
-
try {
|
|
13879
|
-
const { legacybnUSD, newbnUSD } = migrationConfig.bnUSD[params.dstChainID];
|
|
13880
|
-
const migrationData = this.bnUSDMigrationService.revertMigrationData({
|
|
13881
|
-
...params,
|
|
13882
|
-
legacybnUSD: legacybnUSD.address,
|
|
13883
|
-
newbnUSD
|
|
13884
|
-
});
|
|
13885
|
-
const txResult = await SpokeService.deposit(
|
|
13886
|
-
{
|
|
13887
|
-
from: await spokeProvider.walletProvider.getWalletAddressBytes(),
|
|
13888
|
-
token: newbnUSD,
|
|
13889
|
-
amount: params.amount,
|
|
13890
|
-
data: migrationData
|
|
13891
|
-
},
|
|
13892
|
-
spokeProvider,
|
|
13893
|
-
this.hubProvider,
|
|
13894
|
-
raw
|
|
13895
|
-
);
|
|
13896
|
-
return {
|
|
13897
|
-
ok: true,
|
|
13898
|
-
value: txResult
|
|
13899
|
-
};
|
|
13900
|
-
} catch (error) {
|
|
13901
|
-
return {
|
|
13902
|
-
ok: false,
|
|
13903
|
-
error: {
|
|
13904
|
-
code: "CREATE_REVERT_MIGRATION_INTENT_FAILED",
|
|
13905
|
-
data: {
|
|
13906
|
-
payload: params,
|
|
13907
|
-
error
|
|
13908
|
-
}
|
|
13909
|
-
}
|
|
13910
|
-
};
|
|
13911
|
-
}
|
|
13912
|
-
}
|
|
13913
13940
|
/**
|
|
13914
13941
|
* Creates a BALN migration intent on spoke chain (icon).
|
|
13915
13942
|
*
|
|
@@ -13964,39 +13991,112 @@ var MigrationService = class {
|
|
|
13964
13991
|
}
|
|
13965
13992
|
}
|
|
13966
13993
|
/**
|
|
13967
|
-
* Creates a bnUSD migration intent on spoke chain
|
|
13994
|
+
* Creates a bnUSD migration or reverse migration (legacy bnUSD to new bnUSD or vice versa) intent on a spoke chain.
|
|
13968
13995
|
*
|
|
13969
|
-
*
|
|
13970
|
-
*
|
|
13971
|
-
*
|
|
13972
|
-
*
|
|
13996
|
+
* This function prepares the transaction data for migrating legacy bnUSD to new bnUSD,
|
|
13997
|
+
* or for reverting (migrating new bnUSD back to legacy bnUSD), depending on the provided parameters.
|
|
13998
|
+
* It performs validation on chain IDs and token addresses unless `unchecked` is set to true.
|
|
13999
|
+
*
|
|
14000
|
+
* @param params - The parameters for the bnUSD migration or reverse migration transaction.
|
|
14001
|
+
* @param spokeProvider - The spoke provider instance for the source chain.
|
|
14002
|
+
* @param unchecked - If true, skips input validation (use with caution).
|
|
14003
|
+
* @param raw - If true, returns the raw transaction hash instead of the transaction receipt.
|
|
14004
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MigrationError<'CREATE_MIGRATION_INTENT_FAILED'>>>}
|
|
14005
|
+
* Returns a Result containing the transaction payload or hash, or an error if creation failed.
|
|
13973
14006
|
*
|
|
13974
14007
|
* @example
|
|
14008
|
+
* // Migrate legacy bnUSD to new bnUSD
|
|
13975
14009
|
* const result = await migrationService.createMigratebnUSDIntent(
|
|
13976
14010
|
* {
|
|
13977
|
-
*
|
|
13978
|
-
*
|
|
13979
|
-
*
|
|
13980
|
-
*
|
|
13981
|
-
*
|
|
13982
|
-
*
|
|
13983
|
-
*
|
|
14011
|
+
* srcChainId: '0x1.icon', // Source chain ID (legacy bnUSD chain)
|
|
14012
|
+
* dstChainId: 'sonic', // Destination chain ID (new bnUSD chain)
|
|
14013
|
+
* srcbnUSD: 'cx...', // Legacy bnUSD token address
|
|
14014
|
+
* dstbnUSD: '0x...', // New bnUSD token address
|
|
14015
|
+
* amount: 1000n, // Amount to migrate
|
|
14016
|
+
* to: '0x...', // Recipient address on destination chain
|
|
14017
|
+
* } satisfies UnifiedBnUSDMigrateParams,
|
|
14018
|
+
* spokeProvider, // SpokeProvider instance
|
|
14019
|
+
* false, // Optional unchecked flag (validation is skipped)
|
|
14020
|
+
* true // Optional raw flag
|
|
13984
14021
|
* );
|
|
13985
14022
|
*
|
|
14023
|
+
* // Reverse migration: new bnUSD to legacy bnUSD
|
|
14024
|
+
* const result = await migrationService.createMigratebnUSDIntent(
|
|
14025
|
+
* {
|
|
14026
|
+
* srcChainId: 'sonic', // Source chain ID (new bnUSD chain)
|
|
14027
|
+
* dstChainId: '0x1.icon', // Destination chain ID (legacy bnUSD chain)
|
|
14028
|
+
* srcbnUSD: '0x...', // New bnUSD token address
|
|
14029
|
+
* dstbnUSD: 'cx...', // Legacy bnUSD token address
|
|
14030
|
+
* amount: 1000n, // Amount to migrate
|
|
14031
|
+
* to: 'hx...', // Recipient address on destination chain
|
|
14032
|
+
* } satisfies UnifiedBnUSDMigrateParams,
|
|
14033
|
+
* spokeProvider
|
|
14034
|
+
* );
|
|
13986
14035
|
*/
|
|
13987
|
-
async createMigratebnUSDIntent(params, spokeProvider, raw) {
|
|
14036
|
+
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
13988
14037
|
try {
|
|
13989
|
-
|
|
13990
|
-
|
|
13991
|
-
|
|
13992
|
-
|
|
13993
|
-
|
|
13994
|
-
|
|
13995
|
-
|
|
14038
|
+
if (!unchecked) {
|
|
14039
|
+
invariant2(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
|
|
14040
|
+
invariant2(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
|
|
14041
|
+
invariant2(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
|
|
14042
|
+
invariant2(params.dstbnUSD.length > 0, "New bnUSD token address is required");
|
|
14043
|
+
invariant2(params.amount > 0, "Amount must be greater than 0");
|
|
14044
|
+
invariant2(params.to.length > 0, "Recipient address is required");
|
|
14045
|
+
invariant2(
|
|
14046
|
+
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
14047
|
+
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
14048
|
+
);
|
|
14049
|
+
}
|
|
14050
|
+
let migrationData;
|
|
14051
|
+
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
14052
|
+
if (!unchecked) {
|
|
14053
|
+
invariant2(
|
|
14054
|
+
isLegacybnUSDChainId(params.srcChainId),
|
|
14055
|
+
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
14056
|
+
);
|
|
14057
|
+
invariant2(
|
|
14058
|
+
isNewbnUSDChainId(params.dstChainId),
|
|
14059
|
+
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
14060
|
+
);
|
|
14061
|
+
}
|
|
14062
|
+
migrationData = this.bnUSDMigrationService.migrateData({
|
|
14063
|
+
srcChainId: params.srcChainId,
|
|
14064
|
+
legacybnUSD: params.srcbnUSD,
|
|
14065
|
+
newbnUSD: params.dstbnUSD,
|
|
14066
|
+
dstChainId: params.dstChainId,
|
|
14067
|
+
amount: params.amount,
|
|
14068
|
+
to: encodeAddress(params.dstChainId, params.to)
|
|
14069
|
+
});
|
|
14070
|
+
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
14071
|
+
if (!unchecked) {
|
|
14072
|
+
invariant2(
|
|
14073
|
+
isLegacybnUSDChainId(params.dstChainId),
|
|
14074
|
+
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
14075
|
+
);
|
|
14076
|
+
invariant2(
|
|
14077
|
+
isNewbnUSDToken(params.srcbnUSD),
|
|
14078
|
+
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
14079
|
+
);
|
|
14080
|
+
invariant2(
|
|
14081
|
+
isNewbnUSDChainId(params.srcChainId),
|
|
14082
|
+
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
14083
|
+
);
|
|
14084
|
+
}
|
|
14085
|
+
migrationData = this.bnUSDMigrationService.revertMigrationData({
|
|
14086
|
+
srcChainId: params.srcChainId,
|
|
14087
|
+
legacybnUSD: params.dstbnUSD,
|
|
14088
|
+
newbnUSD: params.srcbnUSD,
|
|
14089
|
+
dstChainId: params.dstChainId,
|
|
14090
|
+
amount: params.amount,
|
|
14091
|
+
to: encodeAddress(params.dstChainId, params.to)
|
|
14092
|
+
});
|
|
14093
|
+
} else {
|
|
14094
|
+
throw new Error("srcbnUSD or dstbnUSD must be a legacy bnUSD token");
|
|
14095
|
+
}
|
|
13996
14096
|
const txResult = await SpokeService.deposit(
|
|
13997
14097
|
{
|
|
13998
14098
|
from: await spokeProvider.walletProvider.getWalletAddress(),
|
|
13999
|
-
token:
|
|
14099
|
+
token: params.srcbnUSD,
|
|
14000
14100
|
amount: params.amount,
|
|
14001
14101
|
data: migrationData
|
|
14002
14102
|
},
|
|
@@ -14167,7 +14267,7 @@ var BnUSDMigrationService = class {
|
|
|
14167
14267
|
*/
|
|
14168
14268
|
migrateData(params) {
|
|
14169
14269
|
const calls = [];
|
|
14170
|
-
const assetConfig = getHubAssetInfo(params.
|
|
14270
|
+
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
14171
14271
|
invariant2(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
14172
14272
|
const bnUSDVault = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
14173
14273
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
@@ -14179,7 +14279,7 @@ var BnUSDMigrationService = class {
|
|
|
14179
14279
|
calls.push(Erc20Service.encodeTransfer(bnUSDVault, params.to, translatedAmount));
|
|
14180
14280
|
return encodeContractCalls(calls);
|
|
14181
14281
|
}
|
|
14182
|
-
const dstAssetConfig = getHubAssetInfo(
|
|
14282
|
+
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
14183
14283
|
invariant2(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
14184
14284
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
14185
14285
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -14210,19 +14310,17 @@ var BnUSDMigrationService = class {
|
|
|
14210
14310
|
revertMigrationData(params) {
|
|
14211
14311
|
const calls = [];
|
|
14212
14312
|
const bnUSDVault = getMoneyMarketConfig(SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
14213
|
-
console.log("params.newbnUSD", params.newbnUSD);
|
|
14214
|
-
console.log("bnUSDVault", bnUSDVault);
|
|
14215
14313
|
let decimals = 18;
|
|
14216
14314
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
14217
|
-
const assetConfig = getHubAssetInfo(params.
|
|
14315
|
+
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
14218
14316
|
invariant2(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
14219
14317
|
decimals = assetConfig.decimal;
|
|
14220
14318
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
14221
14319
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
14222
14320
|
}
|
|
14223
14321
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
14224
|
-
const dstAssetConfig = getHubAssetInfo(params.
|
|
14225
|
-
invariant2(dstAssetConfig, `hub asset not found for
|
|
14322
|
+
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
14323
|
+
invariant2(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
14226
14324
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
14227
14325
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
14228
14326
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -14538,6 +14636,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
|
|
|
14538
14636
|
return SolverIntentErrorCode2;
|
|
14539
14637
|
})(SolverIntentErrorCode || {});
|
|
14540
14638
|
|
|
14541
|
-
export { BalnSwapService, BigIntToHex, BnUSDMigrationService, 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, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketService, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, SupportedMigrationTokens, VAULT_TOKEN_DECIMALS, WalletAbstractionService, assetManagerAbi, balnSwapAbi, calculateFeeAmount, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isWaitUntilIntentExecutedFailed,
|
|
14639
|
+
export { BalnSwapService, BigIntToHex, BnUSDMigrationService, ChainIdToIntentRelayChainId, 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, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketService, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, SupportedMigrationTokens, VAULT_TOKEN_DECIMALS, WalletAbstractionService, assetManagerAbi, balnSwapAbi, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateFeeAmount, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, getAllLegacybnUSDTokens, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, 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, newbnUSDSpokeChainIds, originalAssetTohubAssetMap, poolAbi, randomUint256, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, variableDebtTokenAbi, vaultTokenAbi, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
|
|
14542
14640
|
//# sourceMappingURL=index.mjs.map
|
|
14543
14641
|
//# sourceMappingURL=index.mjs.map
|