@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.cjs
CHANGED
|
@@ -6239,14 +6239,20 @@ var spokeChainConfig = {
|
|
|
6239
6239
|
wrappedSonic: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
6240
6240
|
},
|
|
6241
6241
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
6242
|
-
bnUSD: "
|
|
6242
|
+
bnUSD: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131",
|
|
6243
6243
|
supportedTokens: {
|
|
6244
|
-
|
|
6245
|
-
symbol: "
|
|
6244
|
+
S: {
|
|
6245
|
+
symbol: "S",
|
|
6246
6246
|
name: "Sonic",
|
|
6247
6247
|
decimals: 18,
|
|
6248
6248
|
address: "0x0000000000000000000000000000000000000000"
|
|
6249
6249
|
},
|
|
6250
|
+
bnUSD: {
|
|
6251
|
+
symbol: "bnUSD",
|
|
6252
|
+
name: "bnUSD",
|
|
6253
|
+
decimals: 18,
|
|
6254
|
+
address: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
6255
|
+
},
|
|
6250
6256
|
WETH: {
|
|
6251
6257
|
symbol: "WETH",
|
|
6252
6258
|
name: "Wrapped Ether",
|
|
@@ -6265,8 +6271,8 @@ var spokeChainConfig = {
|
|
|
6265
6271
|
decimals: 6,
|
|
6266
6272
|
address: "0x6047828dc181963ba44974801FF68e538dA5eaF9"
|
|
6267
6273
|
},
|
|
6268
|
-
|
|
6269
|
-
symbol: "
|
|
6274
|
+
wS: {
|
|
6275
|
+
symbol: "wS",
|
|
6270
6276
|
name: "Wrapped Sonic",
|
|
6271
6277
|
decimals: 18,
|
|
6272
6278
|
address: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
@@ -6815,6 +6821,14 @@ var spokeChainConfig = {
|
|
|
6815
6821
|
address: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
6816
6822
|
},
|
|
6817
6823
|
bnUSD: {
|
|
6824
|
+
// same as legacy
|
|
6825
|
+
symbol: "bnUSD",
|
|
6826
|
+
name: "bnUSD",
|
|
6827
|
+
decimals: 18,
|
|
6828
|
+
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb"
|
|
6829
|
+
},
|
|
6830
|
+
legacybnUSD: {
|
|
6831
|
+
// duplicate of bnUSD purely for consistency with other legacy tokens chains (sui, stellar)
|
|
6818
6832
|
symbol: "bnUSD",
|
|
6819
6833
|
name: "bnUSD",
|
|
6820
6834
|
decimals: 18,
|
|
@@ -6852,6 +6866,7 @@ var HubVaultSymbols = [
|
|
|
6852
6866
|
];
|
|
6853
6867
|
var hubVaults = {
|
|
6854
6868
|
IbnUSD: {
|
|
6869
|
+
// ICON bnUSD (Migration) vault on Sonic contains legacy bnUSD tokens (stellar, sui, icon)
|
|
6855
6870
|
address: "0x9D4b663Eb075d2a1C7B8eaEFB9eCCC0510388B51",
|
|
6856
6871
|
reserves: [
|
|
6857
6872
|
// hub asset addresses contained in the vault
|
|
@@ -6882,6 +6897,7 @@ var hubVaults = {
|
|
|
6882
6897
|
]
|
|
6883
6898
|
},
|
|
6884
6899
|
bnUSD: {
|
|
6900
|
+
// new bnUSD vault on Sonic (also contains IbnUSD vault token as part of it)
|
|
6885
6901
|
address: "0xe801ca34e19abcbfea12025378d19c4fbe250131",
|
|
6886
6902
|
reserves: [
|
|
6887
6903
|
// hub asset addresses contained in the vault
|
|
@@ -7027,45 +7043,81 @@ var hubVaults = {
|
|
|
7027
7043
|
]
|
|
7028
7044
|
}
|
|
7029
7045
|
};
|
|
7046
|
+
var bnUSDLegacySpokeChainIds = [
|
|
7047
|
+
types.ICON_MAINNET_CHAIN_ID,
|
|
7048
|
+
types.SUI_MAINNET_CHAIN_ID,
|
|
7049
|
+
types.STELLAR_MAINNET_CHAIN_ID
|
|
7050
|
+
];
|
|
7051
|
+
var newbnUSDSpokeChainIds = types.SPOKE_CHAIN_IDS.filter((chainId) => chainId !== types.ICON_MAINNET_CHAIN_ID);
|
|
7052
|
+
var bnUSDLegacyTokens = [
|
|
7053
|
+
spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7054
|
+
spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7055
|
+
spokeChainConfig[types.STELLAR_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD
|
|
7056
|
+
];
|
|
7057
|
+
var bnUSDNewTokens = newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD);
|
|
7058
|
+
var isLegacybnUSDChainId = (chainId) => {
|
|
7059
|
+
return bnUSDLegacySpokeChainIds.includes(chainId);
|
|
7060
|
+
};
|
|
7061
|
+
var isNewbnUSDChainId = (chainId) => {
|
|
7062
|
+
return newbnUSDSpokeChainIds.includes(chainId);
|
|
7063
|
+
};
|
|
7064
|
+
var isLegacybnUSDToken = (token) => {
|
|
7065
|
+
if (typeof token === "string") {
|
|
7066
|
+
return bnUSDLegacyTokens.some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7067
|
+
}
|
|
7068
|
+
return bnUSDLegacyTokens.some((t) => t.address.toLowerCase() === token.address.toLowerCase());
|
|
7069
|
+
};
|
|
7070
|
+
var isNewbnUSDToken = (token) => {
|
|
7071
|
+
if (typeof token === "string") {
|
|
7072
|
+
return newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD).some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7073
|
+
}
|
|
7074
|
+
return newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD).some((t) => t.address.toLowerCase() === token.address.toLowerCase());
|
|
7075
|
+
};
|
|
7076
|
+
var getAllLegacybnUSDTokens = () => {
|
|
7077
|
+
return bnUSDLegacySpokeChainIds.map((chainId) => ({
|
|
7078
|
+
token: spokeChainConfig[chainId].supportedTokens.legacybnUSD,
|
|
7079
|
+
chainId
|
|
7080
|
+
}));
|
|
7081
|
+
};
|
|
7030
7082
|
var hubAssets = {
|
|
7031
7083
|
[types.SONIC_MAINNET_CHAIN_ID]: {
|
|
7032
7084
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].nativeToken]: {
|
|
7033
|
-
asset:
|
|
7085
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address,
|
|
7034
7086
|
decimal: 18,
|
|
7035
7087
|
symbol: "S",
|
|
7036
7088
|
name: "Sonic",
|
|
7037
7089
|
vault: hubVaults.sodaS.address
|
|
7038
7090
|
},
|
|
7039
|
-
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7040
|
-
asset:
|
|
7091
|
+
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address]: {
|
|
7092
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.wS.address,
|
|
7041
7093
|
decimal: 18,
|
|
7042
|
-
symbol: "
|
|
7094
|
+
symbol: "wS",
|
|
7043
7095
|
name: "Sonic",
|
|
7044
7096
|
vault: hubVaults.sodaS.address
|
|
7045
7097
|
},
|
|
7046
7098
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH.address]: {
|
|
7047
|
-
asset:
|
|
7099
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH.address,
|
|
7048
7100
|
decimal: 18,
|
|
7049
7101
|
symbol: "WETH",
|
|
7050
7102
|
name: "Wrapped Ethereum",
|
|
7051
7103
|
vault: hubVaults.sodaETH.address
|
|
7052
7104
|
},
|
|
7053
7105
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC.address]: {
|
|
7054
|
-
asset:
|
|
7106
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC.address,
|
|
7055
7107
|
decimal: 6,
|
|
7056
7108
|
symbol: "USDC ",
|
|
7057
7109
|
name: "USD Coin",
|
|
7058
7110
|
vault: hubVaults.sodaUSDC.address
|
|
7059
7111
|
},
|
|
7060
7112
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT.address]: {
|
|
7061
|
-
asset:
|
|
7113
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT.address,
|
|
7062
7114
|
decimal: 6,
|
|
7063
7115
|
symbol: "USDT",
|
|
7064
7116
|
name: "Tether USD",
|
|
7065
7117
|
vault: hubVaults.sodaUSDT.address
|
|
7066
7118
|
},
|
|
7067
7119
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.SODA.address]: {
|
|
7068
|
-
asset:
|
|
7120
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.SODA.address,
|
|
7069
7121
|
decimal: 18,
|
|
7070
7122
|
symbol: "SODA",
|
|
7071
7123
|
name: "SODA",
|
|
@@ -7380,7 +7432,7 @@ var hubAssets = {
|
|
|
7380
7432
|
decimal: 18,
|
|
7381
7433
|
symbol: "legacybnUSD",
|
|
7382
7434
|
name: "legacybnUSD",
|
|
7383
|
-
vault:
|
|
7435
|
+
vault: hubVaults.IbnUSD.address
|
|
7384
7436
|
}
|
|
7385
7437
|
},
|
|
7386
7438
|
[types.SUI_MAINNET_CHAIN_ID]: {
|
|
@@ -7458,7 +7510,7 @@ var hubAssets = {
|
|
|
7458
7510
|
decimal: 9,
|
|
7459
7511
|
symbol: "bnUSD",
|
|
7460
7512
|
name: "legacybnUSD",
|
|
7461
|
-
vault:
|
|
7513
|
+
vault: hubVaults.IbnUSD.address
|
|
7462
7514
|
}
|
|
7463
7515
|
},
|
|
7464
7516
|
[types.SOLANA_MAINNET_CHAIN_ID]: {
|
|
@@ -7505,7 +7557,7 @@ var hubAssets = {
|
|
|
7505
7557
|
decimal: 18,
|
|
7506
7558
|
symbol: "bnUSD",
|
|
7507
7559
|
name: "bnUSD",
|
|
7508
|
-
vault: hubVaults.
|
|
7560
|
+
vault: hubVaults.IbnUSD.address
|
|
7509
7561
|
},
|
|
7510
7562
|
[spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].supportedTokens.BALN.address]: {
|
|
7511
7563
|
asset: "0xde8e19a099fedf9d617599f62c5f7f020d92b572",
|
|
@@ -7527,10 +7579,11 @@ var solverConfig = {
|
|
|
7527
7579
|
var getSolverConfig = (chainId) => solverConfig[chainId];
|
|
7528
7580
|
var solverSupportedTokens = {
|
|
7529
7581
|
[types.SONIC_MAINNET_CHAIN_ID]: [
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7582
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.S,
|
|
7583
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH,
|
|
7584
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7585
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
7586
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.wS
|
|
7534
7587
|
],
|
|
7535
7588
|
[types.AVALANCHE_MAINNET_CHAIN_ID]: [
|
|
7536
7589
|
spokeChainConfig[types.AVALANCHE_MAINNET_CHAIN_ID].supportedTokens.AVAX,
|
|
@@ -7697,35 +7750,13 @@ var moneyMarketSupportedTokens = {
|
|
|
7697
7750
|
],
|
|
7698
7751
|
[types.NIBIRU_MAINNET_CHAIN_ID]: [],
|
|
7699
7752
|
[types.SONIC_MAINNET_CHAIN_ID]: [
|
|
7700
|
-
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7753
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.S,
|
|
7701
7754
|
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.WETH,
|
|
7702
7755
|
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
7703
7756
|
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
7704
|
-
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7757
|
+
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.wS
|
|
7705
7758
|
]
|
|
7706
7759
|
};
|
|
7707
|
-
var migrationConfig = {
|
|
7708
|
-
bnUSD: {
|
|
7709
|
-
[types.ICON_MAINNET_CHAIN_ID]: {
|
|
7710
|
-
legacybnUSD: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7711
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7712
|
-
},
|
|
7713
|
-
[types.SUI_MAINNET_CHAIN_ID]: {
|
|
7714
|
-
legacybnUSD: spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7715
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7716
|
-
},
|
|
7717
|
-
[types.STELLAR_MAINNET_CHAIN_ID]: {
|
|
7718
|
-
legacybnUSD: spokeChainConfig[types.STELLAR_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7719
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7720
|
-
}
|
|
7721
|
-
},
|
|
7722
|
-
ICX: {
|
|
7723
|
-
[types.ICON_MAINNET_CHAIN_ID]: {
|
|
7724
|
-
icx: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID]["nativeToken"],
|
|
7725
|
-
wICX: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID]["addresses"]["wICX"]
|
|
7726
|
-
}
|
|
7727
|
-
}
|
|
7728
|
-
};
|
|
7729
7760
|
var isMoneyMarketSupportedToken = (chainId, token) => moneyMarketSupportedTokens[chainId].some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7730
7761
|
var getSupportedMoneyMarketTokens = (chainId) => moneyMarketSupportedTokens[chainId];
|
|
7731
7762
|
var hubVaultsAddressSet = new Set(
|
|
@@ -9052,16 +9083,28 @@ var EvmWalletAbstraction = class {
|
|
|
9052
9083
|
var WalletAbstractionService = class {
|
|
9053
9084
|
constructor() {
|
|
9054
9085
|
}
|
|
9055
|
-
|
|
9056
|
-
|
|
9086
|
+
/**
|
|
9087
|
+
* Gets the hub wallet address for a user based on their spoke chain address.
|
|
9088
|
+
* @param address - The user's address on the spoke chain
|
|
9089
|
+
* @param spokeProvider - The provider for interacting with the spoke chain
|
|
9090
|
+
* @param hubProvider - The provider for interacting with the hub chain
|
|
9091
|
+
* @returns The user's hub wallet address
|
|
9092
|
+
*/
|
|
9093
|
+
static async getUserHubWalletAddress(address, spokeProvider, hubProvider) {
|
|
9094
|
+
const encodedAddress = encodeAddress(spokeProvider.chainConfig.chain.id, address);
|
|
9095
|
+
if (spokeProvider.chainConfig.chain.id === hubProvider.chainConfig.chain.id) {
|
|
9057
9096
|
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
9058
|
-
return SonicSpokeService.getUserRouter(
|
|
9097
|
+
return SonicSpokeService.getUserRouter(encodedAddress, spokeProvider);
|
|
9059
9098
|
}
|
|
9060
9099
|
throw new Error(
|
|
9061
9100
|
"[WalletAbstractionService.getUserHubWalletAddress] Invalid spoke provider. Sonic spoke provider is required."
|
|
9062
9101
|
);
|
|
9063
9102
|
}
|
|
9064
|
-
return EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9103
|
+
return EvmWalletAbstraction.getUserHubWalletAddress(
|
|
9104
|
+
spokeProvider.chainConfig.chain.id,
|
|
9105
|
+
encodedAddress,
|
|
9106
|
+
hubProvider
|
|
9107
|
+
);
|
|
9065
9108
|
}
|
|
9066
9109
|
};
|
|
9067
9110
|
async function retry(action, retryCount = DEFAULT_MAX_RETRY, delayMs = DEFAULT_RETRY_DELAY_MS) {
|
|
@@ -9439,26 +9482,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9439
9482
|
if (!txResult.ok) {
|
|
9440
9483
|
return txResult;
|
|
9441
9484
|
}
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9485
|
+
let intentTxHash = null;
|
|
9486
|
+
if (spokeProvider.chainConfig.chain.id !== types.SONIC_MAINNET_CHAIN_ID) {
|
|
9487
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9488
|
+
txResult.value,
|
|
9489
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9490
|
+
spokeProvider,
|
|
9491
|
+
this.config.relayerApiEndpoint,
|
|
9492
|
+
timeout
|
|
9493
|
+
);
|
|
9494
|
+
if (!packetResult.ok) {
|
|
9495
|
+
return {
|
|
9496
|
+
ok: false,
|
|
9497
|
+
error: {
|
|
9498
|
+
code: packetResult.error.code,
|
|
9499
|
+
data: {
|
|
9500
|
+
error: packetResult.error,
|
|
9501
|
+
payload: txResult.value
|
|
9502
|
+
}
|
|
9457
9503
|
}
|
|
9458
|
-
}
|
|
9459
|
-
}
|
|
9504
|
+
};
|
|
9505
|
+
}
|
|
9506
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9507
|
+
} else {
|
|
9508
|
+
intentTxHash = txResult.value;
|
|
9460
9509
|
}
|
|
9461
|
-
return { ok: true, value: [txResult.value,
|
|
9510
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9462
9511
|
} catch (error) {
|
|
9463
9512
|
return {
|
|
9464
9513
|
ok: false,
|
|
@@ -9513,12 +9562,11 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9513
9562
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9514
9563
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9515
9564
|
);
|
|
9516
|
-
const
|
|
9565
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9517
9566
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
this.hubProvider
|
|
9521
|
-
spokeProvider
|
|
9567
|
+
walletAddress,
|
|
9568
|
+
spokeProvider,
|
|
9569
|
+
this.hubProvider
|
|
9522
9570
|
);
|
|
9523
9571
|
const data = this.buildSupplyData(
|
|
9524
9572
|
params.token,
|
|
@@ -9526,7 +9574,6 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9526
9574
|
params.amount,
|
|
9527
9575
|
spokeProvider.chainConfig.chain.id
|
|
9528
9576
|
);
|
|
9529
|
-
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9530
9577
|
const txResult = await SpokeService.deposit(
|
|
9531
9578
|
{
|
|
9532
9579
|
from: walletAddress,
|
|
@@ -9593,26 +9640,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9593
9640
|
if (!txResult.ok) {
|
|
9594
9641
|
return txResult;
|
|
9595
9642
|
}
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9643
|
+
let intentTxHash = null;
|
|
9644
|
+
if (spokeProvider.chainConfig.chain.id !== types.SONIC_MAINNET_CHAIN_ID) {
|
|
9645
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9646
|
+
txResult.value,
|
|
9647
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9648
|
+
spokeProvider,
|
|
9649
|
+
this.config.relayerApiEndpoint,
|
|
9650
|
+
timeout
|
|
9651
|
+
);
|
|
9652
|
+
if (!packetResult.ok) {
|
|
9653
|
+
return {
|
|
9654
|
+
ok: false,
|
|
9655
|
+
error: {
|
|
9656
|
+
code: packetResult.error.code,
|
|
9657
|
+
data: {
|
|
9658
|
+
error: packetResult.error,
|
|
9659
|
+
payload: txResult.value
|
|
9660
|
+
}
|
|
9611
9661
|
}
|
|
9612
|
-
}
|
|
9613
|
-
}
|
|
9662
|
+
};
|
|
9663
|
+
}
|
|
9664
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9665
|
+
} else {
|
|
9666
|
+
intentTxHash = txResult.value;
|
|
9614
9667
|
}
|
|
9615
|
-
return { ok: true, value: [txResult.value,
|
|
9668
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9616
9669
|
} catch (error) {
|
|
9617
9670
|
return {
|
|
9618
9671
|
ok: false,
|
|
@@ -9664,16 +9717,16 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9664
9717
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9665
9718
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9666
9719
|
);
|
|
9667
|
-
const
|
|
9720
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9721
|
+
const encodedAddress = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
|
|
9668
9722
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
this.hubProvider
|
|
9672
|
-
spokeProvider
|
|
9723
|
+
walletAddress,
|
|
9724
|
+
spokeProvider,
|
|
9725
|
+
this.hubProvider
|
|
9673
9726
|
);
|
|
9674
9727
|
const data = this.buildBorrowData(
|
|
9675
9728
|
hubWallet,
|
|
9676
|
-
|
|
9729
|
+
encodedAddress,
|
|
9677
9730
|
params.token,
|
|
9678
9731
|
params.amount,
|
|
9679
9732
|
spokeProvider.chainConfig.chain.id
|
|
@@ -9722,26 +9775,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9722
9775
|
if (!txResult.ok) {
|
|
9723
9776
|
return txResult;
|
|
9724
9777
|
}
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9778
|
+
let intentTxHash = null;
|
|
9779
|
+
if (spokeProvider.chainConfig.chain.id !== types.SONIC_MAINNET_CHAIN_ID) {
|
|
9780
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9781
|
+
txResult.value,
|
|
9782
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9783
|
+
spokeProvider,
|
|
9784
|
+
this.config.relayerApiEndpoint,
|
|
9785
|
+
timeout
|
|
9786
|
+
);
|
|
9787
|
+
if (!packetResult.ok) {
|
|
9788
|
+
return {
|
|
9789
|
+
ok: false,
|
|
9790
|
+
error: {
|
|
9791
|
+
code: packetResult.error.code,
|
|
9792
|
+
data: {
|
|
9793
|
+
error: packetResult.error,
|
|
9794
|
+
payload: txResult.value
|
|
9795
|
+
}
|
|
9740
9796
|
}
|
|
9741
|
-
}
|
|
9742
|
-
}
|
|
9797
|
+
};
|
|
9798
|
+
}
|
|
9799
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9800
|
+
} else {
|
|
9801
|
+
intentTxHash = txResult.value;
|
|
9743
9802
|
}
|
|
9744
|
-
return { ok: true, value: [txResult.value,
|
|
9803
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9745
9804
|
} catch (error) {
|
|
9746
9805
|
return {
|
|
9747
9806
|
ok: false,
|
|
@@ -9793,16 +9852,16 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9793
9852
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9794
9853
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9795
9854
|
);
|
|
9796
|
-
const
|
|
9855
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9856
|
+
const encodedAddress = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
|
|
9797
9857
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
this.hubProvider
|
|
9801
|
-
spokeProvider
|
|
9858
|
+
walletAddress,
|
|
9859
|
+
spokeProvider,
|
|
9860
|
+
this.hubProvider
|
|
9802
9861
|
);
|
|
9803
9862
|
const data = this.buildWithdrawData(
|
|
9804
9863
|
hubWallet,
|
|
9805
|
-
|
|
9864
|
+
encodedAddress,
|
|
9806
9865
|
params.token,
|
|
9807
9866
|
params.amount,
|
|
9808
9867
|
spokeProvider.chainConfig.chain.id
|
|
@@ -9851,26 +9910,32 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9851
9910
|
if (!txResult.ok) {
|
|
9852
9911
|
return txResult;
|
|
9853
9912
|
}
|
|
9854
|
-
|
|
9855
|
-
|
|
9856
|
-
|
|
9857
|
-
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
-
|
|
9865
|
-
|
|
9866
|
-
|
|
9867
|
-
|
|
9868
|
-
|
|
9913
|
+
let intentTxHash = null;
|
|
9914
|
+
if (spokeProvider.chainConfig.chain.id !== types.SONIC_MAINNET_CHAIN_ID) {
|
|
9915
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
9916
|
+
txResult.value,
|
|
9917
|
+
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
9918
|
+
spokeProvider,
|
|
9919
|
+
this.config.relayerApiEndpoint,
|
|
9920
|
+
timeout
|
|
9921
|
+
);
|
|
9922
|
+
if (!packetResult.ok) {
|
|
9923
|
+
return {
|
|
9924
|
+
ok: false,
|
|
9925
|
+
error: {
|
|
9926
|
+
code: packetResult.error.code,
|
|
9927
|
+
data: {
|
|
9928
|
+
error: packetResult.error,
|
|
9929
|
+
payload: txResult.value
|
|
9930
|
+
}
|
|
9869
9931
|
}
|
|
9870
|
-
}
|
|
9871
|
-
}
|
|
9932
|
+
};
|
|
9933
|
+
}
|
|
9934
|
+
intentTxHash = packetResult.value.dst_tx_hash;
|
|
9935
|
+
} else {
|
|
9936
|
+
intentTxHash = txResult.value;
|
|
9872
9937
|
}
|
|
9873
|
-
return { ok: true, value: [txResult.value,
|
|
9938
|
+
return { ok: true, value: [txResult.value, intentTxHash] };
|
|
9874
9939
|
} catch (error) {
|
|
9875
9940
|
return {
|
|
9876
9941
|
ok: false,
|
|
@@ -9924,15 +9989,13 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9924
9989
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
9925
9990
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
9926
9991
|
);
|
|
9927
|
-
const
|
|
9992
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9928
9993
|
const hubWallet = await WalletAbstractionService.getUserHubWalletAddress(
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
this.hubProvider
|
|
9932
|
-
spokeProvider
|
|
9994
|
+
walletAddress,
|
|
9995
|
+
spokeProvider,
|
|
9996
|
+
this.hubProvider
|
|
9933
9997
|
);
|
|
9934
9998
|
const data = this.buildRepayData(params.token, hubWallet, params.amount, spokeProvider.chainConfig.chain.id);
|
|
9935
|
-
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
9936
9999
|
const txResult = await SpokeService.deposit(
|
|
9937
10000
|
{
|
|
9938
10001
|
from: walletAddress,
|
|
@@ -11641,6 +11704,18 @@ function isMoneyMarketWithdrawUnknownError(error) {
|
|
|
11641
11704
|
function isMoneyMarketRepayUnknownError(error) {
|
|
11642
11705
|
return typeof error === "object" && error !== null && "code" in error && error.code === "REPAY_UNKNOWN_ERROR";
|
|
11643
11706
|
}
|
|
11707
|
+
function isIcxMigrateParams(value) {
|
|
11708
|
+
return typeof value === "object" && value !== null && "address" in value && "amount" in value && "to" in value;
|
|
11709
|
+
}
|
|
11710
|
+
function isUnifiedBnUSDMigrateParams(value) {
|
|
11711
|
+
return typeof value === "object" && value !== null && "srcChainId" in value && "srcbnUSD" in value && "dstChainId" in value && "dstbnUSD" in value && "amount" in value && "to" in value;
|
|
11712
|
+
}
|
|
11713
|
+
function isBalnMigrateParams(value) {
|
|
11714
|
+
return typeof value === "object" && value !== null && "amount" in value && "lockupPeriod" in value && "to" in value && "stake" in value;
|
|
11715
|
+
}
|
|
11716
|
+
function isIcxCreateRevertMigrationParams(value) {
|
|
11717
|
+
return typeof value === "object" && value !== null && "amount" in value && "to" in value;
|
|
11718
|
+
}
|
|
11644
11719
|
|
|
11645
11720
|
// src/services/spoke/SpokeService.ts
|
|
11646
11721
|
var SpokeService = class {
|
|
@@ -12523,15 +12598,15 @@ var SolverService = class {
|
|
|
12523
12598
|
* // handle error
|
|
12524
12599
|
* }
|
|
12525
12600
|
*/
|
|
12526
|
-
async swap(payload, spokeProvider,
|
|
12527
|
-
return this.createAndSubmitIntent(payload, spokeProvider,
|
|
12601
|
+
async swap(payload, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12602
|
+
return this.createAndSubmitIntent(payload, spokeProvider, this.config.partnerFee, timeout);
|
|
12528
12603
|
}
|
|
12529
12604
|
/**
|
|
12530
12605
|
* Creates an intent and submits it to the Solver API and Relayer API
|
|
12531
12606
|
* @param {CreateIntentParams} payload - The intent to create
|
|
12532
12607
|
* @param {ISpokeProvider} spokeProvider - The spoke provider
|
|
12533
12608
|
* @param {number} timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
12534
|
-
* @returns {Promise<Result<[SolverExecutionResponse, Intent,
|
|
12609
|
+
* @returns {Promise<Result<[SolverExecutionResponse, Intent, Hex], IntentError<IntentErrorCode>>>} The solver execution response, intent, and packet data
|
|
12535
12610
|
*
|
|
12536
12611
|
* @example
|
|
12537
12612
|
* const payload = {
|
|
@@ -12560,49 +12635,55 @@ var SolverService = class {
|
|
|
12560
12635
|
* // handle error
|
|
12561
12636
|
* }
|
|
12562
12637
|
*/
|
|
12563
|
-
async createAndSubmitIntent(payload, spokeProvider, fee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12638
|
+
async createAndSubmitIntent(payload, spokeProvider, fee = this.config.partnerFee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12564
12639
|
try {
|
|
12565
12640
|
const createIntentResult = await this.createIntent(payload, spokeProvider, fee, false);
|
|
12566
12641
|
if (!createIntentResult.ok) {
|
|
12567
12642
|
return createIntentResult;
|
|
12568
12643
|
}
|
|
12569
12644
|
const [spokeTxHash, intent, data] = createIntentResult.value;
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12645
|
+
let intentTxHash = null;
|
|
12646
|
+
if (spokeProvider.chainConfig.chain.id !== types.SONIC_MAINNET_CHAIN_ID) {
|
|
12647
|
+
const intentRelayChainId = getIntentRelayChainId(payload.srcChain).toString();
|
|
12648
|
+
const submitPayload = payload.srcChain === types.SOLANA_MAINNET_CHAIN_ID && data ? {
|
|
12649
|
+
action: "submit",
|
|
12650
|
+
params: {
|
|
12651
|
+
chain_id: intentRelayChainId,
|
|
12652
|
+
tx_hash: spokeTxHash,
|
|
12653
|
+
data: {
|
|
12654
|
+
address: intent.creator,
|
|
12655
|
+
payload: data
|
|
12656
|
+
}
|
|
12657
|
+
}
|
|
12658
|
+
} : {
|
|
12659
|
+
action: "submit",
|
|
12660
|
+
params: {
|
|
12661
|
+
chain_id: intentRelayChainId,
|
|
12662
|
+
tx_hash: spokeTxHash
|
|
12579
12663
|
}
|
|
12664
|
+
};
|
|
12665
|
+
const submitResult = await this.submitIntent(submitPayload);
|
|
12666
|
+
if (!submitResult.ok) {
|
|
12667
|
+
return submitResult;
|
|
12580
12668
|
}
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12669
|
+
const packet = await waitUntilIntentExecuted({
|
|
12670
|
+
intentRelayChainId,
|
|
12671
|
+
spokeTxHash,
|
|
12672
|
+
timeout,
|
|
12673
|
+
apiUrl: this.config.relayerApiEndpoint
|
|
12674
|
+
});
|
|
12675
|
+
if (!packet.ok) {
|
|
12676
|
+
return {
|
|
12677
|
+
ok: false,
|
|
12678
|
+
error: packet.error
|
|
12679
|
+
};
|
|
12586
12680
|
}
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
return submitResult;
|
|
12591
|
-
}
|
|
12592
|
-
const packet = await waitUntilIntentExecuted({
|
|
12593
|
-
intentRelayChainId,
|
|
12594
|
-
spokeTxHash,
|
|
12595
|
-
timeout,
|
|
12596
|
-
apiUrl: this.config.relayerApiEndpoint
|
|
12597
|
-
});
|
|
12598
|
-
if (!packet.ok) {
|
|
12599
|
-
return {
|
|
12600
|
-
ok: false,
|
|
12601
|
-
error: packet.error
|
|
12602
|
-
};
|
|
12681
|
+
intentTxHash = packet.value.dst_tx_hash;
|
|
12682
|
+
} else {
|
|
12683
|
+
intentTxHash = spokeTxHash;
|
|
12603
12684
|
}
|
|
12604
12685
|
const result = await this.postExecution({
|
|
12605
|
-
intent_tx_hash:
|
|
12686
|
+
intent_tx_hash: intentTxHash
|
|
12606
12687
|
});
|
|
12607
12688
|
if (!result.ok) {
|
|
12608
12689
|
return {
|
|
@@ -12615,7 +12696,7 @@ var SolverService = class {
|
|
|
12615
12696
|
}
|
|
12616
12697
|
return {
|
|
12617
12698
|
ok: true,
|
|
12618
|
-
value: [result.value, intent,
|
|
12699
|
+
value: [result.value, intent, intentTxHash]
|
|
12619
12700
|
};
|
|
12620
12701
|
} catch (error) {
|
|
12621
12702
|
return {
|
|
@@ -12785,12 +12866,7 @@ var SolverService = class {
|
|
|
12785
12866
|
"srcAddress must be the same as wallet address"
|
|
12786
12867
|
);
|
|
12787
12868
|
const walletAddressBytes = encodeAddress(params.srcChain, walletAddress);
|
|
12788
|
-
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(
|
|
12789
|
-
params.srcChain,
|
|
12790
|
-
walletAddressBytes,
|
|
12791
|
-
this.hubProvider,
|
|
12792
|
-
spokeProvider
|
|
12793
|
-
);
|
|
12869
|
+
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12794
12870
|
const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
|
|
12795
12871
|
{
|
|
12796
12872
|
...params,
|
|
@@ -12840,13 +12916,9 @@ var SolverService = class {
|
|
|
12840
12916
|
try {
|
|
12841
12917
|
invariant2__default.default(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
12842
12918
|
invariant2__default.default(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
12843
|
-
const
|
|
12844
|
-
const
|
|
12845
|
-
|
|
12846
|
-
walletAddressBytes,
|
|
12847
|
-
this.hubProvider,
|
|
12848
|
-
spokeProvider
|
|
12849
|
-
);
|
|
12919
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12920
|
+
const walletAddressBytes = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
|
|
12921
|
+
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12850
12922
|
const calls = [];
|
|
12851
12923
|
const intentsContract = this.config.intentsContract;
|
|
12852
12924
|
calls.push(EvmSolverService.encodeCancelIntent(intent, intentsContract));
|
|
@@ -13471,9 +13543,25 @@ var MigrationService = class {
|
|
|
13471
13543
|
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13472
13544
|
invariant2__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
13473
13545
|
invariant2__default.default(
|
|
13474
|
-
|
|
13475
|
-
"
|
|
13546
|
+
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
13547
|
+
"Invalid params"
|
|
13476
13548
|
);
|
|
13549
|
+
if (spokeProvider instanceof IconSpokeProvider && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
|
|
13550
|
+
return {
|
|
13551
|
+
ok: true,
|
|
13552
|
+
value: true
|
|
13553
|
+
};
|
|
13554
|
+
}
|
|
13555
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13556
|
+
const evmSpokeProvider = spokeProvider;
|
|
13557
|
+
return await Erc20Service.isAllowanceValid(
|
|
13558
|
+
params.srcbnUSD,
|
|
13559
|
+
params.amount,
|
|
13560
|
+
await evmSpokeProvider.walletProvider.getWalletAddress(),
|
|
13561
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13562
|
+
evmSpokeProvider
|
|
13563
|
+
);
|
|
13564
|
+
}
|
|
13477
13565
|
return {
|
|
13478
13566
|
ok: true,
|
|
13479
13567
|
value: true
|
|
@@ -13482,19 +13570,28 @@ var MigrationService = class {
|
|
|
13482
13570
|
if (action === "revert") {
|
|
13483
13571
|
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13484
13572
|
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
13485
|
-
invariant2__default.default(
|
|
13486
|
-
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13497
|
-
)
|
|
13573
|
+
invariant2__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13574
|
+
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
13575
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
13576
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
13577
|
+
return await Erc20Service.isAllowanceValid(
|
|
13578
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
13579
|
+
params.amount,
|
|
13580
|
+
wallet,
|
|
13581
|
+
userRouter,
|
|
13582
|
+
spokeProvider
|
|
13583
|
+
);
|
|
13584
|
+
}
|
|
13585
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13586
|
+
const evmSpokeProvider = spokeProvider;
|
|
13587
|
+
return await Erc20Service.isAllowanceValid(
|
|
13588
|
+
params.srcbnUSD,
|
|
13589
|
+
params.amount,
|
|
13590
|
+
await evmSpokeProvider.walletProvider.getWalletAddress(),
|
|
13591
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13592
|
+
evmSpokeProvider
|
|
13593
|
+
);
|
|
13594
|
+
}
|
|
13498
13595
|
}
|
|
13499
13596
|
return {
|
|
13500
13597
|
ok: false,
|
|
@@ -13528,25 +13625,65 @@ var MigrationService = class {
|
|
|
13528
13625
|
*/
|
|
13529
13626
|
async approve(params, action, spokeProvider, raw) {
|
|
13530
13627
|
try {
|
|
13628
|
+
if (action === "migrate") {
|
|
13629
|
+
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13630
|
+
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
13631
|
+
invariant2__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13632
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13633
|
+
const evmSpokeProvider = spokeProvider;
|
|
13634
|
+
const result = await Erc20Service.approve(
|
|
13635
|
+
params.srcbnUSD,
|
|
13636
|
+
params.amount,
|
|
13637
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13638
|
+
evmSpokeProvider,
|
|
13639
|
+
raw
|
|
13640
|
+
);
|
|
13641
|
+
return {
|
|
13642
|
+
ok: true,
|
|
13643
|
+
value: result
|
|
13644
|
+
};
|
|
13645
|
+
}
|
|
13646
|
+
return {
|
|
13647
|
+
ok: false,
|
|
13648
|
+
error: new Error("Invalid params for migrate action")
|
|
13649
|
+
};
|
|
13650
|
+
}
|
|
13531
13651
|
if (action === "revert") {
|
|
13532
13652
|
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13533
13653
|
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
13534
|
-
invariant2__default.default(
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
13546
|
-
|
|
13654
|
+
invariant2__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13655
|
+
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
13656
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
13657
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
13658
|
+
const result = await Erc20Service.approve(
|
|
13659
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
13660
|
+
params.amount,
|
|
13661
|
+
userRouter,
|
|
13662
|
+
spokeProvider,
|
|
13663
|
+
raw
|
|
13664
|
+
);
|
|
13665
|
+
return {
|
|
13666
|
+
ok: true,
|
|
13667
|
+
value: result
|
|
13668
|
+
};
|
|
13669
|
+
}
|
|
13670
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13671
|
+
const evmSpokeProvider = spokeProvider;
|
|
13672
|
+
const result = await Erc20Service.approve(
|
|
13673
|
+
params.srcbnUSD,
|
|
13674
|
+
params.amount,
|
|
13675
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13676
|
+
evmSpokeProvider,
|
|
13677
|
+
raw
|
|
13678
|
+
);
|
|
13679
|
+
return {
|
|
13680
|
+
ok: true,
|
|
13681
|
+
value: result
|
|
13682
|
+
};
|
|
13683
|
+
}
|
|
13547
13684
|
return {
|
|
13548
|
-
ok:
|
|
13549
|
-
|
|
13685
|
+
ok: false,
|
|
13686
|
+
error: new Error("Invalid params or chain type for revert action")
|
|
13550
13687
|
};
|
|
13551
13688
|
}
|
|
13552
13689
|
return {
|
|
@@ -13561,27 +13698,37 @@ var MigrationService = class {
|
|
|
13561
13698
|
}
|
|
13562
13699
|
}
|
|
13563
13700
|
/**
|
|
13564
|
-
* Migrates
|
|
13565
|
-
*
|
|
13701
|
+
* Migrates bnUSD tokens between legacy and new formats across supported spoke chains via the hub chain (sonic).
|
|
13702
|
+
* Handles both legacy-to-new and new-to-legacy bnUSD migrations, enforcing validation and relaying the transaction.
|
|
13566
13703
|
*
|
|
13567
|
-
* @param params -
|
|
13568
|
-
* @param spokeProvider - The
|
|
13569
|
-
* @param timeout -
|
|
13704
|
+
* @param params - Migration parameters, including source/destination chain IDs, token addresses, amount, and recipient.
|
|
13705
|
+
* @param spokeProvider - The SpokeProvider instance for the source chain.
|
|
13706
|
+
* @param timeout - Optional timeout in milliseconds for the relay operation (default: 60 seconds).
|
|
13707
|
+
* @param unchecked - Optional flag to skip validation checks (default: false).
|
|
13570
13708
|
* @returns {Promise<Result<[string, Hex], MigrationError<'MIGRATION_FAILED'> | MigrationError<'CREATE_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
13571
|
-
*
|
|
13572
|
-
* or an error describing why the migration or relay failed.
|
|
13573
|
-
*
|
|
13709
|
+
* Result containing a tuple: [spokeTxHash, hubTxHash] if successful, or an error describing the failure.
|
|
13574
13710
|
*
|
|
13575
13711
|
* @example
|
|
13576
|
-
* //
|
|
13712
|
+
* // Migrate legacy bnUSD to new bnUSD
|
|
13577
13713
|
* const result = await sodax.migration.migratebnUSD({
|
|
13578
|
-
*
|
|
13579
|
-
*
|
|
13580
|
-
*
|
|
13581
|
-
*
|
|
13582
|
-
*
|
|
13714
|
+
* srcChainId: '0x1.icon', // Source chain ID (legacy)
|
|
13715
|
+
* dstChainId: 'sonic', // Destination chain ID (new)
|
|
13716
|
+
* srcbnUSD: 'cx...', // Legacy bnUSD token address
|
|
13717
|
+
* dstbnUSD: '0x...', // New bnUSD token address
|
|
13718
|
+
* amount: 1000n, // Amount to migrate
|
|
13719
|
+
* to: '0x...', // Recipient address on destination chain
|
|
13583
13720
|
* }, iconSpokeProvider);
|
|
13584
13721
|
*
|
|
13722
|
+
* // Reverse migration: new bnUSD to legacy bnUSD
|
|
13723
|
+
* const result = await sodax.migration.migratebnUSD({
|
|
13724
|
+
* srcChainId: 'sonic', // Source chain ID (new)
|
|
13725
|
+
* dstChainId: '0x1.icon', // Destination chain ID (legacy)
|
|
13726
|
+
* srcbnUSD: '0x...', // New bnUSD token address
|
|
13727
|
+
* dstbnUSD: 'cx...', // Legacy bnUSD token address
|
|
13728
|
+
* amount: 1000n, // Amount to migrate
|
|
13729
|
+
* to: 'hx...', // Recipient address on destination chain
|
|
13730
|
+
* }, sonicSpokeProvider);
|
|
13731
|
+
*
|
|
13585
13732
|
* if (result.ok) {
|
|
13586
13733
|
* // result.value is a tuple: [spokeTxHash, hubTxHash]
|
|
13587
13734
|
* const [spokeTxHash, hubTxHash] = result.value;
|
|
@@ -13592,9 +13739,9 @@ var MigrationService = class {
|
|
|
13592
13739
|
* console.error('[migrateBnUSD] error', result.error);
|
|
13593
13740
|
* }
|
|
13594
13741
|
*/
|
|
13595
|
-
async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
13742
|
+
async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT, unchecked = false) {
|
|
13596
13743
|
try {
|
|
13597
|
-
const txResult = await this.createMigratebnUSDIntent(params, spokeProvider);
|
|
13744
|
+
const txResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked);
|
|
13598
13745
|
if (!txResult.ok) {
|
|
13599
13746
|
return {
|
|
13600
13747
|
ok: false,
|
|
@@ -13625,70 +13772,6 @@ var MigrationService = class {
|
|
|
13625
13772
|
};
|
|
13626
13773
|
}
|
|
13627
13774
|
}
|
|
13628
|
-
/**
|
|
13629
|
-
* Reverses the migration of legacy bnUSD tokens to new bnUSD tokens on the hub chain (sonic).
|
|
13630
|
-
* This function handles the reversal of the migration of legacy bnUSD tokens to new bnUSD tokens.
|
|
13631
|
-
*
|
|
13632
|
-
* @param params - The parameters for the migration transaction.
|
|
13633
|
-
* @param spokeProvider - The spoke provider.
|
|
13634
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
13635
|
-
* @returns {Promise<Result<[string, Hex], MigrationError<'REVERT_MIGRATION_FAILED'> | MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
13636
|
-
* Returns a Result containing a tuple of [spokeTxHash, hubTxHash] if successful,
|
|
13637
|
-
* or an error describing why the revert migration or relay failed.
|
|
13638
|
-
*
|
|
13639
|
-
*
|
|
13640
|
-
* @example
|
|
13641
|
-
* // Example: Reverse the migration of legacy bnUSD tokens to new bnUSD tokens on the hub chain (sonic)
|
|
13642
|
-
* const result = await sodax.migration.reverseMigratebnUSD({
|
|
13643
|
-
* srcChainID: 'sonic', // source chain ID (e.g., SONIC_MAINNET_CHAIN_ID)
|
|
13644
|
-
* amount: 1000000000000000000n,
|
|
13645
|
-
* to: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd', // The spoke chain address that will receive the migrated legacy bnUSD tokens
|
|
13646
|
-
* dstChainID: '0x1.icon', // destination chain ID of type bnUSDLegacySpokeChainId (e.g., ICON_MAINNET_CHAIN_ID)
|
|
13647
|
-
* }, iconSpokeProvider);
|
|
13648
|
-
*
|
|
13649
|
-
* if (result.ok) {
|
|
13650
|
-
* // result.value is a tuple: [spokeTxHash, hubTxHash]
|
|
13651
|
-
* const [spokeTxHash, hubTxHash] = result.value;
|
|
13652
|
-
* console.log('[reverseMigrateBnUSD] hubTxHash', hubTxHash);
|
|
13653
|
-
* console.log('[reverseMigrateBnUSD] spokeTxHash', spokeTxHash);
|
|
13654
|
-
* } else {
|
|
13655
|
-
* // Handle revert migration error
|
|
13656
|
-
* console.error('[reverseMigrateBnUSD] error', result.error);
|
|
13657
|
-
* }
|
|
13658
|
-
*/
|
|
13659
|
-
async reverseMigratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
13660
|
-
try {
|
|
13661
|
-
const txResult = await this.createRevertMigratebnUSDIntent(params, spokeProvider);
|
|
13662
|
-
if (!txResult.ok) {
|
|
13663
|
-
return {
|
|
13664
|
-
ok: false,
|
|
13665
|
-
error: txResult.error
|
|
13666
|
-
};
|
|
13667
|
-
}
|
|
13668
|
-
const packetResult = await relayTxAndWaitPacket(
|
|
13669
|
-
txResult.value,
|
|
13670
|
-
void 0,
|
|
13671
|
-
spokeProvider,
|
|
13672
|
-
this.config.relayerApiEndpoint,
|
|
13673
|
-
timeout
|
|
13674
|
-
);
|
|
13675
|
-
if (!packetResult.ok) {
|
|
13676
|
-
return packetResult;
|
|
13677
|
-
}
|
|
13678
|
-
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
13679
|
-
} catch (error) {
|
|
13680
|
-
return {
|
|
13681
|
-
ok: false,
|
|
13682
|
-
error: {
|
|
13683
|
-
code: "REVERT_MIGRATION_FAILED",
|
|
13684
|
-
data: {
|
|
13685
|
-
payload: params,
|
|
13686
|
-
error
|
|
13687
|
-
}
|
|
13688
|
-
}
|
|
13689
|
-
};
|
|
13690
|
-
}
|
|
13691
|
-
}
|
|
13692
13775
|
/**
|
|
13693
13776
|
* Migrates ICX tokens to SODA tokens on the hub chain (sonic).
|
|
13694
13777
|
* This function handles the migration of ICX tokens to SODA tokens.
|
|
@@ -13881,62 +13964,6 @@ var MigrationService = class {
|
|
|
13881
13964
|
};
|
|
13882
13965
|
}
|
|
13883
13966
|
}
|
|
13884
|
-
/**
|
|
13885
|
-
* Creates a revert migration intent and submits (relays) it to the spoke chain.
|
|
13886
|
-
* @param params - The parameters for the revert migration transaction.
|
|
13887
|
-
* @param spokeProvider - The spoke provider.
|
|
13888
|
-
* @param raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
13889
|
-
* @returns {Promise<Result<TxReturnType<bnUSDLegacyMigrationProviders, R>>>} - Returns the raw transaction payload or transaction hash
|
|
13890
|
-
*
|
|
13891
|
-
* @example
|
|
13892
|
-
* const result = await migrationService.createRevertMigratebnUSDIntent(
|
|
13893
|
-
* {
|
|
13894
|
-
* srcChainID: 'sonic', // The source chain ID where the new bnUSD token exists (hub chain)
|
|
13895
|
-
* amount: 1000n, // The amount of new bnUSD tokens to migrate back
|
|
13896
|
-
* to: '0x...', // The spoke chain address that will receive the migrated legacy bnUSD tokens
|
|
13897
|
-
* dstChainID: '0x1.icon', // The destination chain ID for the migration (spoke chain)
|
|
13898
|
-
* },
|
|
13899
|
-
* spokeProvider, // IconSpokeProvider instance
|
|
13900
|
-
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
13901
|
-
* );
|
|
13902
|
-
*
|
|
13903
|
-
*/
|
|
13904
|
-
async createRevertMigratebnUSDIntent(params, spokeProvider, raw) {
|
|
13905
|
-
try {
|
|
13906
|
-
const { legacybnUSD, newbnUSD } = migrationConfig.bnUSD[params.dstChainID];
|
|
13907
|
-
const migrationData = this.bnUSDMigrationService.revertMigrationData({
|
|
13908
|
-
...params,
|
|
13909
|
-
legacybnUSD: legacybnUSD.address,
|
|
13910
|
-
newbnUSD
|
|
13911
|
-
});
|
|
13912
|
-
const txResult = await SpokeService.deposit(
|
|
13913
|
-
{
|
|
13914
|
-
from: await spokeProvider.walletProvider.getWalletAddressBytes(),
|
|
13915
|
-
token: newbnUSD,
|
|
13916
|
-
amount: params.amount,
|
|
13917
|
-
data: migrationData
|
|
13918
|
-
},
|
|
13919
|
-
spokeProvider,
|
|
13920
|
-
this.hubProvider,
|
|
13921
|
-
raw
|
|
13922
|
-
);
|
|
13923
|
-
return {
|
|
13924
|
-
ok: true,
|
|
13925
|
-
value: txResult
|
|
13926
|
-
};
|
|
13927
|
-
} catch (error) {
|
|
13928
|
-
return {
|
|
13929
|
-
ok: false,
|
|
13930
|
-
error: {
|
|
13931
|
-
code: "CREATE_REVERT_MIGRATION_INTENT_FAILED",
|
|
13932
|
-
data: {
|
|
13933
|
-
payload: params,
|
|
13934
|
-
error
|
|
13935
|
-
}
|
|
13936
|
-
}
|
|
13937
|
-
};
|
|
13938
|
-
}
|
|
13939
|
-
}
|
|
13940
13967
|
/**
|
|
13941
13968
|
* Creates a BALN migration intent on spoke chain (icon).
|
|
13942
13969
|
*
|
|
@@ -13991,39 +14018,112 @@ var MigrationService = class {
|
|
|
13991
14018
|
}
|
|
13992
14019
|
}
|
|
13993
14020
|
/**
|
|
13994
|
-
* Creates a bnUSD migration intent on spoke chain
|
|
14021
|
+
* Creates a bnUSD migration or reverse migration (legacy bnUSD to new bnUSD or vice versa) intent on a spoke chain.
|
|
13995
14022
|
*
|
|
13996
|
-
*
|
|
13997
|
-
*
|
|
13998
|
-
*
|
|
13999
|
-
*
|
|
14023
|
+
* This function prepares the transaction data for migrating legacy bnUSD to new bnUSD,
|
|
14024
|
+
* or for reverting (migrating new bnUSD back to legacy bnUSD), depending on the provided parameters.
|
|
14025
|
+
* It performs validation on chain IDs and token addresses unless `unchecked` is set to true.
|
|
14026
|
+
*
|
|
14027
|
+
* @param params - The parameters for the bnUSD migration or reverse migration transaction.
|
|
14028
|
+
* @param spokeProvider - The spoke provider instance for the source chain.
|
|
14029
|
+
* @param unchecked - If true, skips input validation (use with caution).
|
|
14030
|
+
* @param raw - If true, returns the raw transaction hash instead of the transaction receipt.
|
|
14031
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MigrationError<'CREATE_MIGRATION_INTENT_FAILED'>>>}
|
|
14032
|
+
* Returns a Result containing the transaction payload or hash, or an error if creation failed.
|
|
14000
14033
|
*
|
|
14001
14034
|
* @example
|
|
14035
|
+
* // Migrate legacy bnUSD to new bnUSD
|
|
14002
14036
|
* const result = await migrationService.createMigratebnUSDIntent(
|
|
14003
14037
|
* {
|
|
14004
|
-
*
|
|
14005
|
-
*
|
|
14006
|
-
*
|
|
14007
|
-
*
|
|
14008
|
-
*
|
|
14009
|
-
*
|
|
14010
|
-
*
|
|
14038
|
+
* srcChainId: '0x1.icon', // Source chain ID (legacy bnUSD chain)
|
|
14039
|
+
* dstChainId: 'sonic', // Destination chain ID (new bnUSD chain)
|
|
14040
|
+
* srcbnUSD: 'cx...', // Legacy bnUSD token address
|
|
14041
|
+
* dstbnUSD: '0x...', // New bnUSD token address
|
|
14042
|
+
* amount: 1000n, // Amount to migrate
|
|
14043
|
+
* to: '0x...', // Recipient address on destination chain
|
|
14044
|
+
* } satisfies UnifiedBnUSDMigrateParams,
|
|
14045
|
+
* spokeProvider, // SpokeProvider instance
|
|
14046
|
+
* false, // Optional unchecked flag (validation is skipped)
|
|
14047
|
+
* true // Optional raw flag
|
|
14011
14048
|
* );
|
|
14012
14049
|
*
|
|
14050
|
+
* // Reverse migration: new bnUSD to legacy bnUSD
|
|
14051
|
+
* const result = await migrationService.createMigratebnUSDIntent(
|
|
14052
|
+
* {
|
|
14053
|
+
* srcChainId: 'sonic', // Source chain ID (new bnUSD chain)
|
|
14054
|
+
* dstChainId: '0x1.icon', // Destination chain ID (legacy bnUSD chain)
|
|
14055
|
+
* srcbnUSD: '0x...', // New bnUSD token address
|
|
14056
|
+
* dstbnUSD: 'cx...', // Legacy bnUSD token address
|
|
14057
|
+
* amount: 1000n, // Amount to migrate
|
|
14058
|
+
* to: 'hx...', // Recipient address on destination chain
|
|
14059
|
+
* } satisfies UnifiedBnUSDMigrateParams,
|
|
14060
|
+
* spokeProvider
|
|
14061
|
+
* );
|
|
14013
14062
|
*/
|
|
14014
|
-
async createMigratebnUSDIntent(params, spokeProvider, raw) {
|
|
14063
|
+
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
14015
14064
|
try {
|
|
14016
|
-
|
|
14017
|
-
|
|
14018
|
-
|
|
14019
|
-
|
|
14020
|
-
|
|
14021
|
-
|
|
14022
|
-
|
|
14065
|
+
if (!unchecked) {
|
|
14066
|
+
invariant2__default.default(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
|
|
14067
|
+
invariant2__default.default(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
|
|
14068
|
+
invariant2__default.default(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
|
|
14069
|
+
invariant2__default.default(params.dstbnUSD.length > 0, "New bnUSD token address is required");
|
|
14070
|
+
invariant2__default.default(params.amount > 0, "Amount must be greater than 0");
|
|
14071
|
+
invariant2__default.default(params.to.length > 0, "Recipient address is required");
|
|
14072
|
+
invariant2__default.default(
|
|
14073
|
+
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
14074
|
+
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
14075
|
+
);
|
|
14076
|
+
}
|
|
14077
|
+
let migrationData;
|
|
14078
|
+
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
14079
|
+
if (!unchecked) {
|
|
14080
|
+
invariant2__default.default(
|
|
14081
|
+
isLegacybnUSDChainId(params.srcChainId),
|
|
14082
|
+
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
14083
|
+
);
|
|
14084
|
+
invariant2__default.default(
|
|
14085
|
+
isNewbnUSDChainId(params.dstChainId),
|
|
14086
|
+
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
14087
|
+
);
|
|
14088
|
+
}
|
|
14089
|
+
migrationData = this.bnUSDMigrationService.migrateData({
|
|
14090
|
+
srcChainId: params.srcChainId,
|
|
14091
|
+
legacybnUSD: params.srcbnUSD,
|
|
14092
|
+
newbnUSD: params.dstbnUSD,
|
|
14093
|
+
dstChainId: params.dstChainId,
|
|
14094
|
+
amount: params.amount,
|
|
14095
|
+
to: encodeAddress(params.dstChainId, params.to)
|
|
14096
|
+
});
|
|
14097
|
+
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
14098
|
+
if (!unchecked) {
|
|
14099
|
+
invariant2__default.default(
|
|
14100
|
+
isLegacybnUSDChainId(params.dstChainId),
|
|
14101
|
+
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
14102
|
+
);
|
|
14103
|
+
invariant2__default.default(
|
|
14104
|
+
isNewbnUSDToken(params.srcbnUSD),
|
|
14105
|
+
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
14106
|
+
);
|
|
14107
|
+
invariant2__default.default(
|
|
14108
|
+
isNewbnUSDChainId(params.srcChainId),
|
|
14109
|
+
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
14110
|
+
);
|
|
14111
|
+
}
|
|
14112
|
+
migrationData = this.bnUSDMigrationService.revertMigrationData({
|
|
14113
|
+
srcChainId: params.srcChainId,
|
|
14114
|
+
legacybnUSD: params.dstbnUSD,
|
|
14115
|
+
newbnUSD: params.srcbnUSD,
|
|
14116
|
+
dstChainId: params.dstChainId,
|
|
14117
|
+
amount: params.amount,
|
|
14118
|
+
to: encodeAddress(params.dstChainId, params.to)
|
|
14119
|
+
});
|
|
14120
|
+
} else {
|
|
14121
|
+
throw new Error("srcbnUSD or dstbnUSD must be a legacy bnUSD token");
|
|
14122
|
+
}
|
|
14023
14123
|
const txResult = await SpokeService.deposit(
|
|
14024
14124
|
{
|
|
14025
14125
|
from: await spokeProvider.walletProvider.getWalletAddress(),
|
|
14026
|
-
token:
|
|
14126
|
+
token: params.srcbnUSD,
|
|
14027
14127
|
amount: params.amount,
|
|
14028
14128
|
data: migrationData
|
|
14029
14129
|
},
|
|
@@ -14194,7 +14294,7 @@ var BnUSDMigrationService = class {
|
|
|
14194
14294
|
*/
|
|
14195
14295
|
migrateData(params) {
|
|
14196
14296
|
const calls = [];
|
|
14197
|
-
const assetConfig = getHubAssetInfo(params.
|
|
14297
|
+
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
14198
14298
|
invariant2__default.default(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
14199
14299
|
const bnUSDVault = getMoneyMarketConfig(types.SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
14200
14300
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
@@ -14206,7 +14306,7 @@ var BnUSDMigrationService = class {
|
|
|
14206
14306
|
calls.push(Erc20Service.encodeTransfer(bnUSDVault, params.to, translatedAmount));
|
|
14207
14307
|
return encodeContractCalls(calls);
|
|
14208
14308
|
}
|
|
14209
|
-
const dstAssetConfig = getHubAssetInfo(
|
|
14309
|
+
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
14210
14310
|
invariant2__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
14211
14311
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
14212
14312
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -14237,19 +14337,17 @@ var BnUSDMigrationService = class {
|
|
|
14237
14337
|
revertMigrationData(params) {
|
|
14238
14338
|
const calls = [];
|
|
14239
14339
|
const bnUSDVault = getMoneyMarketConfig(types.SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
14240
|
-
console.log("params.newbnUSD", params.newbnUSD);
|
|
14241
|
-
console.log("bnUSDVault", bnUSDVault);
|
|
14242
14340
|
let decimals = 18;
|
|
14243
14341
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
14244
|
-
const assetConfig = getHubAssetInfo(params.
|
|
14342
|
+
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
14245
14343
|
invariant2__default.default(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
14246
14344
|
decimals = assetConfig.decimal;
|
|
14247
14345
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
14248
14346
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
14249
14347
|
}
|
|
14250
14348
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
14251
|
-
const dstAssetConfig = getHubAssetInfo(params.
|
|
14252
|
-
invariant2__default.default(dstAssetConfig, `hub asset not found for
|
|
14349
|
+
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
14350
|
+
invariant2__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
14253
14351
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
14254
14352
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
14255
14353
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -14568,6 +14666,7 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
|
|
|
14568
14666
|
exports.BalnSwapService = BalnSwapService;
|
|
14569
14667
|
exports.BigIntToHex = BigIntToHex;
|
|
14570
14668
|
exports.BnUSDMigrationService = BnUSDMigrationService;
|
|
14669
|
+
exports.ChainIdToIntentRelayChainId = ChainIdToIntentRelayChainId;
|
|
14571
14670
|
exports.DEFAULT_MAX_RETRY = DEFAULT_MAX_RETRY;
|
|
14572
14671
|
exports.DEFAULT_RELAYER_API_ENDPOINT = DEFAULT_RELAYER_API_ENDPOINT;
|
|
14573
14672
|
exports.DEFAULT_RELAY_TX_TIMEOUT = DEFAULT_RELAY_TX_TIMEOUT;
|
|
@@ -14614,6 +14713,9 @@ exports.VAULT_TOKEN_DECIMALS = VAULT_TOKEN_DECIMALS;
|
|
|
14614
14713
|
exports.WalletAbstractionService = WalletAbstractionService;
|
|
14615
14714
|
exports.assetManagerAbi = assetManagerAbi;
|
|
14616
14715
|
exports.balnSwapAbi = balnSwapAbi;
|
|
14716
|
+
exports.bnUSDLegacySpokeChainIds = bnUSDLegacySpokeChainIds;
|
|
14717
|
+
exports.bnUSDLegacyTokens = bnUSDLegacyTokens;
|
|
14718
|
+
exports.bnUSDNewTokens = bnUSDNewTokens;
|
|
14617
14719
|
exports.calculateFeeAmount = calculateFeeAmount;
|
|
14618
14720
|
exports.calculatePercentageFeeAmount = calculatePercentageFeeAmount;
|
|
14619
14721
|
exports.chainIdToHubAssetsMap = chainIdToHubAssetsMap;
|
|
@@ -14621,6 +14723,7 @@ exports.connectionAbi = connectionAbi;
|
|
|
14621
14723
|
exports.encodeAddress = encodeAddress;
|
|
14622
14724
|
exports.encodeContractCalls = encodeContractCalls;
|
|
14623
14725
|
exports.erc20Abi = erc20Abi;
|
|
14726
|
+
exports.getAllLegacybnUSDTokens = getAllLegacybnUSDTokens;
|
|
14624
14727
|
exports.getEvmViemChain = getEvmViemChain;
|
|
14625
14728
|
exports.getHubAssetInfo = getHubAssetInfo;
|
|
14626
14729
|
exports.getHubChainConfig = getHubChainConfig;
|
|
@@ -14642,6 +14745,7 @@ exports.hubAssets = hubAssets;
|
|
|
14642
14745
|
exports.hubVaults = hubVaults;
|
|
14643
14746
|
exports.hubVaultsAddressSet = hubVaultsAddressSet;
|
|
14644
14747
|
exports.intentRelayChainIdToSpokeChainIdMap = intentRelayChainIdToSpokeChainIdMap;
|
|
14748
|
+
exports.isBalnMigrateParams = isBalnMigrateParams;
|
|
14645
14749
|
exports.isConfiguredMoneyMarketConfig = isConfiguredMoneyMarketConfig;
|
|
14646
14750
|
exports.isConfiguredSolverConfig = isConfiguredSolverConfig;
|
|
14647
14751
|
exports.isEvmHubChainConfig = isEvmHubChainConfig;
|
|
@@ -14653,6 +14757,8 @@ exports.isEvmUninitializedConfig = isEvmUninitializedConfig;
|
|
|
14653
14757
|
exports.isEvmUninitializedPrivateKeyConfig = isEvmUninitializedPrivateKeyConfig;
|
|
14654
14758
|
exports.isIconAddress = isIconAddress;
|
|
14655
14759
|
exports.isIconSpokeProvider = isIconSpokeProvider;
|
|
14760
|
+
exports.isIcxCreateRevertMigrationParams = isIcxCreateRevertMigrationParams;
|
|
14761
|
+
exports.isIcxMigrateParams = isIcxMigrateParams;
|
|
14656
14762
|
exports.isInjectiveSpokeProvider = isInjectiveSpokeProvider;
|
|
14657
14763
|
exports.isIntentCreationFailedError = isIntentCreationFailedError;
|
|
14658
14764
|
exports.isIntentCreationUnknownError = isIntentCreationUnknownError;
|
|
@@ -14660,6 +14766,8 @@ exports.isIntentPostExecutionFailedError = isIntentPostExecutionFailedError;
|
|
|
14660
14766
|
exports.isIntentRelayChainId = isIntentRelayChainId;
|
|
14661
14767
|
exports.isIntentSubmitTxFailedError = isIntentSubmitTxFailedError;
|
|
14662
14768
|
exports.isJsonRpcPayloadResponse = isJsonRpcPayloadResponse;
|
|
14769
|
+
exports.isLegacybnUSDChainId = isLegacybnUSDChainId;
|
|
14770
|
+
exports.isLegacybnUSDToken = isLegacybnUSDToken;
|
|
14663
14771
|
exports.isMoneyMarketBorrowUnknownError = isMoneyMarketBorrowUnknownError;
|
|
14664
14772
|
exports.isMoneyMarketCreateBorrowIntentFailedError = isMoneyMarketCreateBorrowIntentFailedError;
|
|
14665
14773
|
exports.isMoneyMarketCreateRepayIntentFailedError = isMoneyMarketCreateRepayIntentFailedError;
|
|
@@ -14674,6 +14782,8 @@ exports.isMoneyMarketSupplyUnknownError = isMoneyMarketSupplyUnknownError;
|
|
|
14674
14782
|
exports.isMoneyMarketSupportedToken = isMoneyMarketSupportedToken;
|
|
14675
14783
|
exports.isMoneyMarketWithdrawUnknownError = isMoneyMarketWithdrawUnknownError;
|
|
14676
14784
|
exports.isNativeToken = isNativeToken;
|
|
14785
|
+
exports.isNewbnUSDChainId = isNewbnUSDChainId;
|
|
14786
|
+
exports.isNewbnUSDToken = isNewbnUSDToken;
|
|
14677
14787
|
exports.isPartnerFeeAmount = isPartnerFeeAmount;
|
|
14678
14788
|
exports.isPartnerFeePercentage = isPartnerFeePercentage;
|
|
14679
14789
|
exports.isResponseAddressType = isResponseAddressType;
|
|
@@ -14683,16 +14793,17 @@ exports.isSolverSupportedToken = isSolverSupportedToken;
|
|
|
14683
14793
|
exports.isSonicSpokeProvider = isSonicSpokeProvider;
|
|
14684
14794
|
exports.isStellarSpokeProvider = isStellarSpokeProvider;
|
|
14685
14795
|
exports.isSuiSpokeProvider = isSuiSpokeProvider;
|
|
14796
|
+
exports.isUnifiedBnUSDMigrateParams = isUnifiedBnUSDMigrateParams;
|
|
14686
14797
|
exports.isValidChainHubAsset = isValidChainHubAsset;
|
|
14687
14798
|
exports.isValidHubAsset = isValidHubAsset;
|
|
14688
14799
|
exports.isValidIntentRelayChainId = isValidIntentRelayChainId;
|
|
14689
14800
|
exports.isValidOriginalAssetAddress = isValidOriginalAssetAddress;
|
|
14690
14801
|
exports.isValidSpokeChainId = isValidSpokeChainId;
|
|
14691
14802
|
exports.isWaitUntilIntentExecutedFailed = isWaitUntilIntentExecutedFailed;
|
|
14692
|
-
exports.migrationConfig = migrationConfig;
|
|
14693
14803
|
exports.moneyMarketReserveAssets = moneyMarketReserveAssets;
|
|
14694
14804
|
exports.moneyMarketReserveHubAssetsSet = moneyMarketReserveHubAssetsSet;
|
|
14695
14805
|
exports.moneyMarketSupportedTokens = moneyMarketSupportedTokens;
|
|
14806
|
+
exports.newbnUSDSpokeChainIds = newbnUSDSpokeChainIds;
|
|
14696
14807
|
exports.originalAssetTohubAssetMap = originalAssetTohubAssetMap;
|
|
14697
14808
|
exports.poolAbi = poolAbi;
|
|
14698
14809
|
exports.randomUint256 = randomUint256;
|