@sodax/sdk 0.0.1-rc.17 → 0.0.1-rc.19
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 +6 -5
- package/dist/index.cjs +311 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1636 -1586
- package/dist/index.d.ts +1636 -1586
- package/dist/index.mjs +300 -235
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -9
package/dist/index.cjs
CHANGED
|
@@ -6215,12 +6215,9 @@ var hubChainConfig = {
|
|
|
6215
6215
|
assetManager: "0x60c5681bD1DB4e50735c4cA3386005A4BA4937C0",
|
|
6216
6216
|
hubWallet: "0xA0ed3047D358648F2C0583B415CffCA571FDB544",
|
|
6217
6217
|
xTokenManager: "0x5bD2843de9D6b0e6A05d0FB742072274EA3C6CA3",
|
|
6218
|
-
icxMigration: "
|
|
6219
|
-
// TODO update with "final" address before migration
|
|
6218
|
+
icxMigration: "0x8294DE9fc60F5ABCc19245E5857071d7C42B9875",
|
|
6220
6219
|
balnSwap: "0x610a90B61b89a98b954d5750E94834Aa45d08d10",
|
|
6221
|
-
|
|
6222
|
-
sodaToken: "0x8515352CB9832D1d379D52366D1E995ADd358420"
|
|
6223
|
-
// TODO update with "final" address before migration
|
|
6220
|
+
sodaToken: "0x7c7d53eecda37a87ce0d5bf8e0b24512a48dc963"
|
|
6224
6221
|
},
|
|
6225
6222
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
6226
6223
|
supportedTokens: []
|
|
@@ -6239,7 +6236,7 @@ var spokeChainConfig = {
|
|
|
6239
6236
|
wrappedSonic: "0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38"
|
|
6240
6237
|
},
|
|
6241
6238
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
6242
|
-
bnUSD: "
|
|
6239
|
+
bnUSD: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131",
|
|
6243
6240
|
supportedTokens: {
|
|
6244
6241
|
S: {
|
|
6245
6242
|
symbol: "S",
|
|
@@ -6247,6 +6244,12 @@ var spokeChainConfig = {
|
|
|
6247
6244
|
decimals: 18,
|
|
6248
6245
|
address: "0x0000000000000000000000000000000000000000"
|
|
6249
6246
|
},
|
|
6247
|
+
bnUSD: {
|
|
6248
|
+
symbol: "bnUSD",
|
|
6249
|
+
name: "bnUSD",
|
|
6250
|
+
decimals: 18,
|
|
6251
|
+
address: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
6252
|
+
},
|
|
6250
6253
|
WETH: {
|
|
6251
6254
|
symbol: "WETH",
|
|
6252
6255
|
name: "Wrapped Ether",
|
|
@@ -6815,6 +6818,14 @@ var spokeChainConfig = {
|
|
|
6815
6818
|
address: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
6816
6819
|
},
|
|
6817
6820
|
bnUSD: {
|
|
6821
|
+
// same as legacy
|
|
6822
|
+
symbol: "bnUSD",
|
|
6823
|
+
name: "bnUSD",
|
|
6824
|
+
decimals: 18,
|
|
6825
|
+
address: "cx88fd7df7ddff82f7cc735c871dc519838cb235bb"
|
|
6826
|
+
},
|
|
6827
|
+
legacybnUSD: {
|
|
6828
|
+
// duplicate of bnUSD purely for consistency with other legacy tokens chains (sui, stellar)
|
|
6818
6829
|
symbol: "bnUSD",
|
|
6819
6830
|
name: "bnUSD",
|
|
6820
6831
|
decimals: 18,
|
|
@@ -6852,6 +6863,7 @@ var HubVaultSymbols = [
|
|
|
6852
6863
|
];
|
|
6853
6864
|
var hubVaults = {
|
|
6854
6865
|
IbnUSD: {
|
|
6866
|
+
// ICON bnUSD (Migration) vault on Sonic contains legacy bnUSD tokens (stellar, sui, icon)
|
|
6855
6867
|
address: "0x9D4b663Eb075d2a1C7B8eaEFB9eCCC0510388B51",
|
|
6856
6868
|
reserves: [
|
|
6857
6869
|
// hub asset addresses contained in the vault
|
|
@@ -6882,6 +6894,7 @@ var hubVaults = {
|
|
|
6882
6894
|
]
|
|
6883
6895
|
},
|
|
6884
6896
|
bnUSD: {
|
|
6897
|
+
// new bnUSD vault on Sonic (also contains IbnUSD vault token as part of it)
|
|
6885
6898
|
address: "0xe801ca34e19abcbfea12025378d19c4fbe250131",
|
|
6886
6899
|
reserves: [
|
|
6887
6900
|
// hub asset addresses contained in the vault
|
|
@@ -7027,6 +7040,42 @@ var hubVaults = {
|
|
|
7027
7040
|
]
|
|
7028
7041
|
}
|
|
7029
7042
|
};
|
|
7043
|
+
var bnUSDLegacySpokeChainIds = [
|
|
7044
|
+
types.ICON_MAINNET_CHAIN_ID,
|
|
7045
|
+
types.SUI_MAINNET_CHAIN_ID,
|
|
7046
|
+
types.STELLAR_MAINNET_CHAIN_ID
|
|
7047
|
+
];
|
|
7048
|
+
var newbnUSDSpokeChainIds = types.SPOKE_CHAIN_IDS.filter((chainId) => chainId !== types.ICON_MAINNET_CHAIN_ID);
|
|
7049
|
+
var bnUSDLegacyTokens = [
|
|
7050
|
+
spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7051
|
+
spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7052
|
+
spokeChainConfig[types.STELLAR_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD
|
|
7053
|
+
];
|
|
7054
|
+
var bnUSDNewTokens = newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD);
|
|
7055
|
+
var isLegacybnUSDChainId = (chainId) => {
|
|
7056
|
+
return bnUSDLegacySpokeChainIds.includes(chainId);
|
|
7057
|
+
};
|
|
7058
|
+
var isNewbnUSDChainId = (chainId) => {
|
|
7059
|
+
return newbnUSDSpokeChainIds.includes(chainId);
|
|
7060
|
+
};
|
|
7061
|
+
var isLegacybnUSDToken = (token) => {
|
|
7062
|
+
if (typeof token === "string") {
|
|
7063
|
+
return bnUSDLegacyTokens.some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7064
|
+
}
|
|
7065
|
+
return bnUSDLegacyTokens.some((t) => t.address.toLowerCase() === token.address.toLowerCase());
|
|
7066
|
+
};
|
|
7067
|
+
var isNewbnUSDToken = (token) => {
|
|
7068
|
+
if (typeof token === "string") {
|
|
7069
|
+
return newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD).some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7070
|
+
}
|
|
7071
|
+
return newbnUSDSpokeChainIds.map((chainId) => spokeChainConfig[chainId].supportedTokens.bnUSD).some((t) => t.address.toLowerCase() === token.address.toLowerCase());
|
|
7072
|
+
};
|
|
7073
|
+
var getAllLegacybnUSDTokens = () => {
|
|
7074
|
+
return bnUSDLegacySpokeChainIds.map((chainId) => ({
|
|
7075
|
+
token: spokeChainConfig[chainId].supportedTokens.legacybnUSD,
|
|
7076
|
+
chainId
|
|
7077
|
+
}));
|
|
7078
|
+
};
|
|
7030
7079
|
var hubAssets = {
|
|
7031
7080
|
[types.SONIC_MAINNET_CHAIN_ID]: {
|
|
7032
7081
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].nativeToken]: {
|
|
@@ -7380,7 +7429,7 @@ var hubAssets = {
|
|
|
7380
7429
|
decimal: 18,
|
|
7381
7430
|
symbol: "legacybnUSD",
|
|
7382
7431
|
name: "legacybnUSD",
|
|
7383
|
-
vault:
|
|
7432
|
+
vault: hubVaults.IbnUSD.address
|
|
7384
7433
|
}
|
|
7385
7434
|
},
|
|
7386
7435
|
[types.SUI_MAINNET_CHAIN_ID]: {
|
|
@@ -7458,7 +7507,7 @@ var hubAssets = {
|
|
|
7458
7507
|
decimal: 9,
|
|
7459
7508
|
symbol: "bnUSD",
|
|
7460
7509
|
name: "legacybnUSD",
|
|
7461
|
-
vault:
|
|
7510
|
+
vault: hubVaults.IbnUSD.address
|
|
7462
7511
|
}
|
|
7463
7512
|
},
|
|
7464
7513
|
[types.SOLANA_MAINNET_CHAIN_ID]: {
|
|
@@ -7505,7 +7554,7 @@ var hubAssets = {
|
|
|
7505
7554
|
decimal: 18,
|
|
7506
7555
|
symbol: "bnUSD",
|
|
7507
7556
|
name: "bnUSD",
|
|
7508
|
-
vault: hubVaults.
|
|
7557
|
+
vault: hubVaults.IbnUSD.address
|
|
7509
7558
|
},
|
|
7510
7559
|
[spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].supportedTokens.BALN.address]: {
|
|
7511
7560
|
asset: "0xde8e19a099fedf9d617599f62c5f7f020d92b572",
|
|
@@ -7705,28 +7754,6 @@ var moneyMarketSupportedTokens = {
|
|
|
7705
7754
|
spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.wS
|
|
7706
7755
|
]
|
|
7707
7756
|
};
|
|
7708
|
-
var migrationConfig = {
|
|
7709
|
-
bnUSD: {
|
|
7710
|
-
[types.ICON_MAINNET_CHAIN_ID]: {
|
|
7711
|
-
legacybnUSD: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
7712
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7713
|
-
},
|
|
7714
|
-
[types.SUI_MAINNET_CHAIN_ID]: {
|
|
7715
|
-
legacybnUSD: spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7716
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7717
|
-
},
|
|
7718
|
-
[types.STELLAR_MAINNET_CHAIN_ID]: {
|
|
7719
|
-
legacybnUSD: spokeChainConfig[types.STELLAR_MAINNET_CHAIN_ID].supportedTokens.legacybnUSD,
|
|
7720
|
-
newbnUSD: hubVaults.bnUSD.address
|
|
7721
|
-
}
|
|
7722
|
-
},
|
|
7723
|
-
ICX: {
|
|
7724
|
-
[types.ICON_MAINNET_CHAIN_ID]: {
|
|
7725
|
-
icx: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID]["nativeToken"],
|
|
7726
|
-
wICX: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID]["addresses"]["wICX"]
|
|
7727
|
-
}
|
|
7728
|
-
}
|
|
7729
|
-
};
|
|
7730
7757
|
var isMoneyMarketSupportedToken = (chainId, token) => moneyMarketSupportedTokens[chainId].some((t) => t.address.toLowerCase() === token.toLowerCase());
|
|
7731
7758
|
var getSupportedMoneyMarketTokens = (chainId) => moneyMarketSupportedTokens[chainId];
|
|
7732
7759
|
var hubVaultsAddressSet = new Set(
|
|
@@ -9492,7 +9519,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9492
9519
|
}
|
|
9493
9520
|
}
|
|
9494
9521
|
/**
|
|
9495
|
-
* Create supply intent only (without
|
|
9522
|
+
* Create supply intent only (without relay submit to Solver API)
|
|
9496
9523
|
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
9497
9524
|
* In order to successfully supply tokens, you need to:
|
|
9498
9525
|
* 1. Check if the allowance is sufficient
|
|
@@ -9650,7 +9677,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9650
9677
|
}
|
|
9651
9678
|
}
|
|
9652
9679
|
/**
|
|
9653
|
-
* Create borrow intent only (without
|
|
9680
|
+
* Create borrow intent only (without relay and submit to Solver API)
|
|
9654
9681
|
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
9655
9682
|
* In order to successfully borrow tokens, you need to:
|
|
9656
9683
|
* 1. Execute the borrow transaction on the spoke chain
|
|
@@ -9785,7 +9812,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9785
9812
|
}
|
|
9786
9813
|
}
|
|
9787
9814
|
/**
|
|
9788
|
-
* Create withdraw intent only (without
|
|
9815
|
+
* Create withdraw intent only (without relay and submit to Solver API)
|
|
9789
9816
|
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
9790
9817
|
* In order to successfully withdraw tokens, you need to:
|
|
9791
9818
|
* 1. Execute the withdraw transaction on the spoke chain
|
|
@@ -9920,7 +9947,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
9920
9947
|
}
|
|
9921
9948
|
}
|
|
9922
9949
|
/**
|
|
9923
|
-
* Create repay intent only (without
|
|
9950
|
+
* Create repay intent only (without relay and submit to Solver API)
|
|
9924
9951
|
* NOTE: This method does not submit the intent to the Solver API, it only executes the transaction on the spoke chain
|
|
9925
9952
|
* In order to successfully repay tokens, you need to:
|
|
9926
9953
|
* 1. Check if the allowance is sufficient
|
|
@@ -11624,7 +11651,7 @@ function isSuiSpokeProvider(value) {
|
|
|
11624
11651
|
return typeof value === "object" && value !== null && value instanceof SuiSpokeProvider && value.chainConfig.chain.type === "SUI";
|
|
11625
11652
|
}
|
|
11626
11653
|
function isConfiguredSolverConfig(value) {
|
|
11627
|
-
return typeof value === "object" && value !== null && "intentsContract" in value && "solverApiEndpoint" in value
|
|
11654
|
+
return typeof value === "object" && value !== null && "intentsContract" in value && "solverApiEndpoint" in value;
|
|
11628
11655
|
}
|
|
11629
11656
|
function isConfiguredMoneyMarketConfig(value) {
|
|
11630
11657
|
return typeof value === "object" && value !== null && "lendingPool" in value && "uiPoolDataProvider" in value && "poolAddressesProvider" in value && "bnUSD" in value && "bnUSDVault" in value;
|
|
@@ -11674,6 +11701,18 @@ function isMoneyMarketWithdrawUnknownError(error) {
|
|
|
11674
11701
|
function isMoneyMarketRepayUnknownError(error) {
|
|
11675
11702
|
return typeof error === "object" && error !== null && "code" in error && error.code === "REPAY_UNKNOWN_ERROR";
|
|
11676
11703
|
}
|
|
11704
|
+
function isIcxMigrateParams(value) {
|
|
11705
|
+
return typeof value === "object" && value !== null && "address" in value && "amount" in value && "to" in value;
|
|
11706
|
+
}
|
|
11707
|
+
function isUnifiedBnUSDMigrateParams(value) {
|
|
11708
|
+
return typeof value === "object" && value !== null && "srcChainId" in value && "srcbnUSD" in value && "dstChainId" in value && "dstbnUSD" in value && "amount" in value && "to" in value;
|
|
11709
|
+
}
|
|
11710
|
+
function isBalnMigrateParams(value) {
|
|
11711
|
+
return typeof value === "object" && value !== null && "amount" in value && "lockupPeriod" in value && "to" in value && "stake" in value;
|
|
11712
|
+
}
|
|
11713
|
+
function isIcxCreateRevertMigrationParams(value) {
|
|
11714
|
+
return typeof value === "object" && value !== null && "amount" in value && "to" in value;
|
|
11715
|
+
}
|
|
11677
11716
|
|
|
11678
11717
|
// src/services/spoke/SpokeService.ts
|
|
11679
11718
|
var SpokeService = class {
|
|
@@ -12556,8 +12595,8 @@ var SolverService = class {
|
|
|
12556
12595
|
* // handle error
|
|
12557
12596
|
* }
|
|
12558
12597
|
*/
|
|
12559
|
-
async swap(payload, spokeProvider,
|
|
12560
|
-
return this.createAndSubmitIntent(payload, spokeProvider,
|
|
12598
|
+
async swap(payload, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12599
|
+
return this.createAndSubmitIntent(payload, spokeProvider, this.config.partnerFee, timeout);
|
|
12561
12600
|
}
|
|
12562
12601
|
/**
|
|
12563
12602
|
* Creates an intent and submits it to the Solver API and Relayer API
|
|
@@ -12593,7 +12632,7 @@ var SolverService = class {
|
|
|
12593
12632
|
* // handle error
|
|
12594
12633
|
* }
|
|
12595
12634
|
*/
|
|
12596
|
-
async createAndSubmitIntent(payload, spokeProvider, fee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12635
|
+
async createAndSubmitIntent(payload, spokeProvider, fee = this.config.partnerFee, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
12597
12636
|
try {
|
|
12598
12637
|
const createIntentResult = await this.createIntent(payload, spokeProvider, fee, false);
|
|
12599
12638
|
if (!createIntentResult.ok) {
|
|
@@ -13501,9 +13540,25 @@ var MigrationService = class {
|
|
|
13501
13540
|
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13502
13541
|
invariant2__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
13503
13542
|
invariant2__default.default(
|
|
13504
|
-
|
|
13505
|
-
"
|
|
13543
|
+
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
13544
|
+
"Invalid params"
|
|
13506
13545
|
);
|
|
13546
|
+
if (spokeProvider instanceof IconSpokeProvider && (isIcxMigrateParams(params) || isBalnMigrateParams(params))) {
|
|
13547
|
+
return {
|
|
13548
|
+
ok: true,
|
|
13549
|
+
value: true
|
|
13550
|
+
};
|
|
13551
|
+
}
|
|
13552
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13553
|
+
const evmSpokeProvider = spokeProvider;
|
|
13554
|
+
return await Erc20Service.isAllowanceValid(
|
|
13555
|
+
params.srcbnUSD,
|
|
13556
|
+
params.amount,
|
|
13557
|
+
await evmSpokeProvider.walletProvider.getWalletAddress(),
|
|
13558
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13559
|
+
evmSpokeProvider
|
|
13560
|
+
);
|
|
13561
|
+
}
|
|
13507
13562
|
return {
|
|
13508
13563
|
ok: true,
|
|
13509
13564
|
value: true
|
|
@@ -13512,19 +13567,28 @@ var MigrationService = class {
|
|
|
13512
13567
|
if (action === "revert") {
|
|
13513
13568
|
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13514
13569
|
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
13515
|
-
invariant2__default.default(
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
|
|
13522
|
-
|
|
13523
|
-
|
|
13524
|
-
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
)
|
|
13570
|
+
invariant2__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13571
|
+
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
13572
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
13573
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
13574
|
+
return await Erc20Service.isAllowanceValid(
|
|
13575
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
13576
|
+
params.amount,
|
|
13577
|
+
wallet,
|
|
13578
|
+
userRouter,
|
|
13579
|
+
spokeProvider
|
|
13580
|
+
);
|
|
13581
|
+
}
|
|
13582
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13583
|
+
const evmSpokeProvider = spokeProvider;
|
|
13584
|
+
return await Erc20Service.isAllowanceValid(
|
|
13585
|
+
params.srcbnUSD,
|
|
13586
|
+
params.amount,
|
|
13587
|
+
await evmSpokeProvider.walletProvider.getWalletAddress(),
|
|
13588
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13589
|
+
evmSpokeProvider
|
|
13590
|
+
);
|
|
13591
|
+
}
|
|
13528
13592
|
}
|
|
13529
13593
|
return {
|
|
13530
13594
|
ok: false,
|
|
@@ -13558,25 +13622,65 @@ var MigrationService = class {
|
|
|
13558
13622
|
*/
|
|
13559
13623
|
async approve(params, action, spokeProvider, raw) {
|
|
13560
13624
|
try {
|
|
13625
|
+
if (action === "migrate") {
|
|
13626
|
+
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13627
|
+
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
13628
|
+
invariant2__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13629
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13630
|
+
const evmSpokeProvider = spokeProvider;
|
|
13631
|
+
const result = await Erc20Service.approve(
|
|
13632
|
+
params.srcbnUSD,
|
|
13633
|
+
params.amount,
|
|
13634
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13635
|
+
evmSpokeProvider,
|
|
13636
|
+
raw
|
|
13637
|
+
);
|
|
13638
|
+
return {
|
|
13639
|
+
ok: true,
|
|
13640
|
+
value: result
|
|
13641
|
+
};
|
|
13642
|
+
}
|
|
13643
|
+
return {
|
|
13644
|
+
ok: false,
|
|
13645
|
+
error: new Error("Invalid params for migrate action")
|
|
13646
|
+
};
|
|
13647
|
+
}
|
|
13561
13648
|
if (action === "revert") {
|
|
13562
13649
|
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
13563
13650
|
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
13564
|
-
invariant2__default.default(
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13651
|
+
invariant2__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
13652
|
+
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
13653
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
13654
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
13655
|
+
const result = await Erc20Service.approve(
|
|
13656
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
13657
|
+
params.amount,
|
|
13658
|
+
userRouter,
|
|
13659
|
+
spokeProvider,
|
|
13660
|
+
raw
|
|
13661
|
+
);
|
|
13662
|
+
return {
|
|
13663
|
+
ok: true,
|
|
13664
|
+
value: result
|
|
13665
|
+
};
|
|
13666
|
+
}
|
|
13667
|
+
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
13668
|
+
const evmSpokeProvider = spokeProvider;
|
|
13669
|
+
const result = await Erc20Service.approve(
|
|
13670
|
+
params.srcbnUSD,
|
|
13671
|
+
params.amount,
|
|
13672
|
+
evmSpokeProvider instanceof EvmSpokeProvider ? evmSpokeProvider.chainConfig.addresses.assetManager : evmSpokeProvider.chainConfig.bnUSD,
|
|
13673
|
+
evmSpokeProvider,
|
|
13674
|
+
raw
|
|
13675
|
+
);
|
|
13676
|
+
return {
|
|
13677
|
+
ok: true,
|
|
13678
|
+
value: result
|
|
13679
|
+
};
|
|
13680
|
+
}
|
|
13577
13681
|
return {
|
|
13578
|
-
ok:
|
|
13579
|
-
|
|
13682
|
+
ok: false,
|
|
13683
|
+
error: new Error("Invalid params or chain type for revert action")
|
|
13580
13684
|
};
|
|
13581
13685
|
}
|
|
13582
13686
|
return {
|
|
@@ -13591,27 +13695,37 @@ var MigrationService = class {
|
|
|
13591
13695
|
}
|
|
13592
13696
|
}
|
|
13593
13697
|
/**
|
|
13594
|
-
* Migrates
|
|
13595
|
-
*
|
|
13698
|
+
* Migrates bnUSD tokens between legacy and new formats across supported spoke chains via the hub chain (sonic).
|
|
13699
|
+
* Handles both legacy-to-new and new-to-legacy bnUSD migrations, enforcing validation and relaying the transaction.
|
|
13596
13700
|
*
|
|
13597
|
-
* @param params -
|
|
13598
|
-
* @param spokeProvider - The
|
|
13599
|
-
* @param timeout -
|
|
13701
|
+
* @param params - Migration parameters, including source/destination chain IDs, token addresses, amount, and recipient.
|
|
13702
|
+
* @param spokeProvider - The SpokeProvider instance for the source chain.
|
|
13703
|
+
* @param timeout - Optional timeout in milliseconds for the relay operation (default: 60 seconds).
|
|
13704
|
+
* @param unchecked - Optional flag to skip validation checks (default: false).
|
|
13600
13705
|
* @returns {Promise<Result<[string, Hex], MigrationError<'MIGRATION_FAILED'> | MigrationError<'CREATE_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
13601
|
-
*
|
|
13602
|
-
* or an error describing why the migration or relay failed.
|
|
13603
|
-
*
|
|
13706
|
+
* Result containing a tuple: [spokeTxHash, hubTxHash] if successful, or an error describing the failure.
|
|
13604
13707
|
*
|
|
13605
13708
|
* @example
|
|
13606
|
-
* //
|
|
13709
|
+
* // Migrate legacy bnUSD to new bnUSD
|
|
13607
13710
|
* const result = await sodax.migration.migratebnUSD({
|
|
13608
|
-
*
|
|
13609
|
-
*
|
|
13610
|
-
*
|
|
13611
|
-
*
|
|
13612
|
-
*
|
|
13711
|
+
* srcChainId: '0x1.icon', // Source chain ID (legacy)
|
|
13712
|
+
* dstChainId: 'sonic', // Destination chain ID (new)
|
|
13713
|
+
* srcbnUSD: 'cx...', // Legacy bnUSD token address
|
|
13714
|
+
* dstbnUSD: '0x...', // New bnUSD token address
|
|
13715
|
+
* amount: 1000n, // Amount to migrate
|
|
13716
|
+
* to: '0x...', // Recipient address on destination chain
|
|
13613
13717
|
* }, iconSpokeProvider);
|
|
13614
13718
|
*
|
|
13719
|
+
* // Reverse migration: new bnUSD to legacy bnUSD
|
|
13720
|
+
* const result = await sodax.migration.migratebnUSD({
|
|
13721
|
+
* srcChainId: 'sonic', // Source chain ID (new)
|
|
13722
|
+
* dstChainId: '0x1.icon', // Destination chain ID (legacy)
|
|
13723
|
+
* srcbnUSD: '0x...', // New bnUSD token address
|
|
13724
|
+
* dstbnUSD: 'cx...', // Legacy bnUSD token address
|
|
13725
|
+
* amount: 1000n, // Amount to migrate
|
|
13726
|
+
* to: 'hx...', // Recipient address on destination chain
|
|
13727
|
+
* }, sonicSpokeProvider);
|
|
13728
|
+
*
|
|
13615
13729
|
* if (result.ok) {
|
|
13616
13730
|
* // result.value is a tuple: [spokeTxHash, hubTxHash]
|
|
13617
13731
|
* const [spokeTxHash, hubTxHash] = result.value;
|
|
@@ -13622,9 +13736,9 @@ var MigrationService = class {
|
|
|
13622
13736
|
* console.error('[migrateBnUSD] error', result.error);
|
|
13623
13737
|
* }
|
|
13624
13738
|
*/
|
|
13625
|
-
async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
13739
|
+
async migratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT, unchecked = false) {
|
|
13626
13740
|
try {
|
|
13627
|
-
const txResult = await this.createMigratebnUSDIntent(params, spokeProvider);
|
|
13741
|
+
const txResult = await this.createMigratebnUSDIntent(params, spokeProvider, unchecked);
|
|
13628
13742
|
if (!txResult.ok) {
|
|
13629
13743
|
return {
|
|
13630
13744
|
ok: false,
|
|
@@ -13655,70 +13769,6 @@ var MigrationService = class {
|
|
|
13655
13769
|
};
|
|
13656
13770
|
}
|
|
13657
13771
|
}
|
|
13658
|
-
/**
|
|
13659
|
-
* Reverses the migration of legacy bnUSD tokens to new bnUSD tokens on the hub chain (sonic).
|
|
13660
|
-
* This function handles the reversal of the migration of legacy bnUSD tokens to new bnUSD tokens.
|
|
13661
|
-
*
|
|
13662
|
-
* @param params - The parameters for the migration transaction.
|
|
13663
|
-
* @param spokeProvider - The spoke provider.
|
|
13664
|
-
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
13665
|
-
* @returns {Promise<Result<[string, Hex], MigrationError<'REVERT_MIGRATION_FAILED'> | MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
13666
|
-
* Returns a Result containing a tuple of [spokeTxHash, hubTxHash] if successful,
|
|
13667
|
-
* or an error describing why the revert migration or relay failed.
|
|
13668
|
-
*
|
|
13669
|
-
*
|
|
13670
|
-
* @example
|
|
13671
|
-
* // Example: Reverse the migration of legacy bnUSD tokens to new bnUSD tokens on the hub chain (sonic)
|
|
13672
|
-
* const result = await sodax.migration.reverseMigratebnUSD({
|
|
13673
|
-
* srcChainID: 'sonic', // source chain ID (e.g., SONIC_MAINNET_CHAIN_ID)
|
|
13674
|
-
* amount: 1000000000000000000n,
|
|
13675
|
-
* to: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd', // The spoke chain address that will receive the migrated legacy bnUSD tokens
|
|
13676
|
-
* dstChainID: '0x1.icon', // destination chain ID of type bnUSDLegacySpokeChainId (e.g., ICON_MAINNET_CHAIN_ID)
|
|
13677
|
-
* }, iconSpokeProvider);
|
|
13678
|
-
*
|
|
13679
|
-
* if (result.ok) {
|
|
13680
|
-
* // result.value is a tuple: [spokeTxHash, hubTxHash]
|
|
13681
|
-
* const [spokeTxHash, hubTxHash] = result.value;
|
|
13682
|
-
* console.log('[reverseMigrateBnUSD] hubTxHash', hubTxHash);
|
|
13683
|
-
* console.log('[reverseMigrateBnUSD] spokeTxHash', spokeTxHash);
|
|
13684
|
-
* } else {
|
|
13685
|
-
* // Handle revert migration error
|
|
13686
|
-
* console.error('[reverseMigrateBnUSD] error', result.error);
|
|
13687
|
-
* }
|
|
13688
|
-
*/
|
|
13689
|
-
async reverseMigratebnUSD(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
13690
|
-
try {
|
|
13691
|
-
const txResult = await this.createRevertMigratebnUSDIntent(params, spokeProvider);
|
|
13692
|
-
if (!txResult.ok) {
|
|
13693
|
-
return {
|
|
13694
|
-
ok: false,
|
|
13695
|
-
error: txResult.error
|
|
13696
|
-
};
|
|
13697
|
-
}
|
|
13698
|
-
const packetResult = await relayTxAndWaitPacket(
|
|
13699
|
-
txResult.value,
|
|
13700
|
-
void 0,
|
|
13701
|
-
spokeProvider,
|
|
13702
|
-
this.config.relayerApiEndpoint,
|
|
13703
|
-
timeout
|
|
13704
|
-
);
|
|
13705
|
-
if (!packetResult.ok) {
|
|
13706
|
-
return packetResult;
|
|
13707
|
-
}
|
|
13708
|
-
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
13709
|
-
} catch (error) {
|
|
13710
|
-
return {
|
|
13711
|
-
ok: false,
|
|
13712
|
-
error: {
|
|
13713
|
-
code: "REVERT_MIGRATION_FAILED",
|
|
13714
|
-
data: {
|
|
13715
|
-
payload: params,
|
|
13716
|
-
error
|
|
13717
|
-
}
|
|
13718
|
-
}
|
|
13719
|
-
};
|
|
13720
|
-
}
|
|
13721
|
-
}
|
|
13722
13772
|
/**
|
|
13723
13773
|
* Migrates ICX tokens to SODA tokens on the hub chain (sonic).
|
|
13724
13774
|
* This function handles the migration of ICX tokens to SODA tokens.
|
|
@@ -13911,62 +13961,6 @@ var MigrationService = class {
|
|
|
13911
13961
|
};
|
|
13912
13962
|
}
|
|
13913
13963
|
}
|
|
13914
|
-
/**
|
|
13915
|
-
* Creates a revert migration intent and submits (relays) it to the spoke chain.
|
|
13916
|
-
* @param params - The parameters for the revert migration transaction.
|
|
13917
|
-
* @param spokeProvider - The spoke provider.
|
|
13918
|
-
* @param raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
13919
|
-
* @returns {Promise<Result<TxReturnType<bnUSDLegacyMigrationProviders, R>>>} - Returns the raw transaction payload or transaction hash
|
|
13920
|
-
*
|
|
13921
|
-
* @example
|
|
13922
|
-
* const result = await migrationService.createRevertMigratebnUSDIntent(
|
|
13923
|
-
* {
|
|
13924
|
-
* srcChainID: 'sonic', // The source chain ID where the new bnUSD token exists (hub chain)
|
|
13925
|
-
* amount: 1000n, // The amount of new bnUSD tokens to migrate back
|
|
13926
|
-
* to: '0x...', // The spoke chain address that will receive the migrated legacy bnUSD tokens
|
|
13927
|
-
* dstChainID: '0x1.icon', // The destination chain ID for the migration (spoke chain)
|
|
13928
|
-
* },
|
|
13929
|
-
* spokeProvider, // IconSpokeProvider instance
|
|
13930
|
-
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
13931
|
-
* );
|
|
13932
|
-
*
|
|
13933
|
-
*/
|
|
13934
|
-
async createRevertMigratebnUSDIntent(params, spokeProvider, raw) {
|
|
13935
|
-
try {
|
|
13936
|
-
const { legacybnUSD, newbnUSD } = migrationConfig.bnUSD[params.dstChainID];
|
|
13937
|
-
const migrationData = this.bnUSDMigrationService.revertMigrationData({
|
|
13938
|
-
...params,
|
|
13939
|
-
legacybnUSD: legacybnUSD.address,
|
|
13940
|
-
newbnUSD
|
|
13941
|
-
});
|
|
13942
|
-
const txResult = await SpokeService.deposit(
|
|
13943
|
-
{
|
|
13944
|
-
from: await spokeProvider.walletProvider.getWalletAddressBytes(),
|
|
13945
|
-
token: newbnUSD,
|
|
13946
|
-
amount: params.amount,
|
|
13947
|
-
data: migrationData
|
|
13948
|
-
},
|
|
13949
|
-
spokeProvider,
|
|
13950
|
-
this.hubProvider,
|
|
13951
|
-
raw
|
|
13952
|
-
);
|
|
13953
|
-
return {
|
|
13954
|
-
ok: true,
|
|
13955
|
-
value: txResult
|
|
13956
|
-
};
|
|
13957
|
-
} catch (error) {
|
|
13958
|
-
return {
|
|
13959
|
-
ok: false,
|
|
13960
|
-
error: {
|
|
13961
|
-
code: "CREATE_REVERT_MIGRATION_INTENT_FAILED",
|
|
13962
|
-
data: {
|
|
13963
|
-
payload: params,
|
|
13964
|
-
error
|
|
13965
|
-
}
|
|
13966
|
-
}
|
|
13967
|
-
};
|
|
13968
|
-
}
|
|
13969
|
-
}
|
|
13970
13964
|
/**
|
|
13971
13965
|
* Creates a BALN migration intent on spoke chain (icon).
|
|
13972
13966
|
*
|
|
@@ -14021,39 +14015,112 @@ var MigrationService = class {
|
|
|
14021
14015
|
}
|
|
14022
14016
|
}
|
|
14023
14017
|
/**
|
|
14024
|
-
* Creates a bnUSD migration intent on spoke chain
|
|
14018
|
+
* Creates a bnUSD migration or reverse migration (legacy bnUSD to new bnUSD or vice versa) intent on a spoke chain.
|
|
14025
14019
|
*
|
|
14026
|
-
*
|
|
14027
|
-
*
|
|
14028
|
-
*
|
|
14029
|
-
*
|
|
14020
|
+
* This function prepares the transaction data for migrating legacy bnUSD to new bnUSD,
|
|
14021
|
+
* or for reverting (migrating new bnUSD back to legacy bnUSD), depending on the provided parameters.
|
|
14022
|
+
* It performs validation on chain IDs and token addresses unless `unchecked` is set to true.
|
|
14023
|
+
*
|
|
14024
|
+
* @param params - The parameters for the bnUSD migration or reverse migration transaction.
|
|
14025
|
+
* @param spokeProvider - The spoke provider instance for the source chain.
|
|
14026
|
+
* @param unchecked - If true, skips input validation (use with caution).
|
|
14027
|
+
* @param raw - If true, returns the raw transaction hash instead of the transaction receipt.
|
|
14028
|
+
* @returns {Promise<Result<TxReturnType<S, R>, MigrationError<'CREATE_MIGRATION_INTENT_FAILED'>>>}
|
|
14029
|
+
* Returns a Result containing the transaction payload or hash, or an error if creation failed.
|
|
14030
14030
|
*
|
|
14031
14031
|
* @example
|
|
14032
|
+
* // Migrate legacy bnUSD to new bnUSD
|
|
14032
14033
|
* const result = await migrationService.createMigratebnUSDIntent(
|
|
14033
14034
|
* {
|
|
14034
|
-
*
|
|
14035
|
-
*
|
|
14036
|
-
*
|
|
14037
|
-
*
|
|
14038
|
-
*
|
|
14039
|
-
*
|
|
14040
|
-
*
|
|
14035
|
+
* srcChainId: '0x1.icon', // Source chain ID (legacy bnUSD chain)
|
|
14036
|
+
* dstChainId: 'sonic', // Destination chain ID (new bnUSD chain)
|
|
14037
|
+
* srcbnUSD: 'cx...', // Legacy bnUSD token address
|
|
14038
|
+
* dstbnUSD: '0x...', // New bnUSD token address
|
|
14039
|
+
* amount: 1000n, // Amount to migrate
|
|
14040
|
+
* to: '0x...', // Recipient address on destination chain
|
|
14041
|
+
* } satisfies UnifiedBnUSDMigrateParams,
|
|
14042
|
+
* spokeProvider, // SpokeProvider instance
|
|
14043
|
+
* false, // Optional unchecked flag (validation is skipped)
|
|
14044
|
+
* true // Optional raw flag
|
|
14041
14045
|
* );
|
|
14042
14046
|
*
|
|
14047
|
+
* // Reverse migration: new bnUSD to legacy bnUSD
|
|
14048
|
+
* const result = await migrationService.createMigratebnUSDIntent(
|
|
14049
|
+
* {
|
|
14050
|
+
* srcChainId: 'sonic', // Source chain ID (new bnUSD chain)
|
|
14051
|
+
* dstChainId: '0x1.icon', // Destination chain ID (legacy bnUSD chain)
|
|
14052
|
+
* srcbnUSD: '0x...', // New bnUSD token address
|
|
14053
|
+
* dstbnUSD: 'cx...', // Legacy bnUSD token address
|
|
14054
|
+
* amount: 1000n, // Amount to migrate
|
|
14055
|
+
* to: 'hx...', // Recipient address on destination chain
|
|
14056
|
+
* } satisfies UnifiedBnUSDMigrateParams,
|
|
14057
|
+
* spokeProvider
|
|
14058
|
+
* );
|
|
14043
14059
|
*/
|
|
14044
|
-
async createMigratebnUSDIntent(params, spokeProvider, raw) {
|
|
14060
|
+
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
14045
14061
|
try {
|
|
14046
|
-
|
|
14047
|
-
|
|
14048
|
-
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
|
|
14052
|
-
|
|
14062
|
+
if (!unchecked) {
|
|
14063
|
+
invariant2__default.default(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
|
|
14064
|
+
invariant2__default.default(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
|
|
14065
|
+
invariant2__default.default(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
|
|
14066
|
+
invariant2__default.default(params.dstbnUSD.length > 0, "New bnUSD token address is required");
|
|
14067
|
+
invariant2__default.default(params.amount > 0, "Amount must be greater than 0");
|
|
14068
|
+
invariant2__default.default(params.to.length > 0, "Recipient address is required");
|
|
14069
|
+
invariant2__default.default(
|
|
14070
|
+
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
14071
|
+
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
14072
|
+
);
|
|
14073
|
+
}
|
|
14074
|
+
let migrationData;
|
|
14075
|
+
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
14076
|
+
if (!unchecked) {
|
|
14077
|
+
invariant2__default.default(
|
|
14078
|
+
isLegacybnUSDChainId(params.srcChainId),
|
|
14079
|
+
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
14080
|
+
);
|
|
14081
|
+
invariant2__default.default(
|
|
14082
|
+
isNewbnUSDChainId(params.dstChainId),
|
|
14083
|
+
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
14084
|
+
);
|
|
14085
|
+
}
|
|
14086
|
+
migrationData = this.bnUSDMigrationService.migrateData({
|
|
14087
|
+
srcChainId: params.srcChainId,
|
|
14088
|
+
legacybnUSD: params.srcbnUSD,
|
|
14089
|
+
newbnUSD: params.dstbnUSD,
|
|
14090
|
+
dstChainId: params.dstChainId,
|
|
14091
|
+
amount: params.amount,
|
|
14092
|
+
to: encodeAddress(params.dstChainId, params.to)
|
|
14093
|
+
});
|
|
14094
|
+
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
14095
|
+
if (!unchecked) {
|
|
14096
|
+
invariant2__default.default(
|
|
14097
|
+
isLegacybnUSDChainId(params.dstChainId),
|
|
14098
|
+
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
14099
|
+
);
|
|
14100
|
+
invariant2__default.default(
|
|
14101
|
+
isNewbnUSDToken(params.srcbnUSD),
|
|
14102
|
+
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
14103
|
+
);
|
|
14104
|
+
invariant2__default.default(
|
|
14105
|
+
isNewbnUSDChainId(params.srcChainId),
|
|
14106
|
+
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
14107
|
+
);
|
|
14108
|
+
}
|
|
14109
|
+
migrationData = this.bnUSDMigrationService.revertMigrationData({
|
|
14110
|
+
srcChainId: params.srcChainId,
|
|
14111
|
+
legacybnUSD: params.dstbnUSD,
|
|
14112
|
+
newbnUSD: params.srcbnUSD,
|
|
14113
|
+
dstChainId: params.dstChainId,
|
|
14114
|
+
amount: params.amount,
|
|
14115
|
+
to: encodeAddress(params.dstChainId, params.to)
|
|
14116
|
+
});
|
|
14117
|
+
} else {
|
|
14118
|
+
throw new Error("srcbnUSD or dstbnUSD must be a legacy bnUSD token");
|
|
14119
|
+
}
|
|
14053
14120
|
const txResult = await SpokeService.deposit(
|
|
14054
14121
|
{
|
|
14055
14122
|
from: await spokeProvider.walletProvider.getWalletAddress(),
|
|
14056
|
-
token:
|
|
14123
|
+
token: params.srcbnUSD,
|
|
14057
14124
|
amount: params.amount,
|
|
14058
14125
|
data: migrationData
|
|
14059
14126
|
},
|
|
@@ -14224,7 +14291,7 @@ var BnUSDMigrationService = class {
|
|
|
14224
14291
|
*/
|
|
14225
14292
|
migrateData(params) {
|
|
14226
14293
|
const calls = [];
|
|
14227
|
-
const assetConfig = getHubAssetInfo(params.
|
|
14294
|
+
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
14228
14295
|
invariant2__default.default(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
14229
14296
|
const bnUSDVault = getMoneyMarketConfig(types.SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
14230
14297
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
@@ -14236,7 +14303,7 @@ var BnUSDMigrationService = class {
|
|
|
14236
14303
|
calls.push(Erc20Service.encodeTransfer(bnUSDVault, params.to, translatedAmount));
|
|
14237
14304
|
return encodeContractCalls(calls);
|
|
14238
14305
|
}
|
|
14239
|
-
const dstAssetConfig = getHubAssetInfo(
|
|
14306
|
+
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
14240
14307
|
invariant2__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
14241
14308
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
14242
14309
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -14267,19 +14334,17 @@ var BnUSDMigrationService = class {
|
|
|
14267
14334
|
revertMigrationData(params) {
|
|
14268
14335
|
const calls = [];
|
|
14269
14336
|
const bnUSDVault = getMoneyMarketConfig(types.SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
14270
|
-
console.log("params.newbnUSD", params.newbnUSD);
|
|
14271
|
-
console.log("bnUSDVault", bnUSDVault);
|
|
14272
14337
|
let decimals = 18;
|
|
14273
14338
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
14274
|
-
const assetConfig = getHubAssetInfo(params.
|
|
14339
|
+
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
14275
14340
|
invariant2__default.default(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
14276
14341
|
decimals = assetConfig.decimal;
|
|
14277
14342
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
14278
14343
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
14279
14344
|
}
|
|
14280
14345
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
14281
|
-
const dstAssetConfig = getHubAssetInfo(params.
|
|
14282
|
-
invariant2__default.default(dstAssetConfig, `hub asset not found for
|
|
14346
|
+
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
14347
|
+
invariant2__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
14283
14348
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
14284
14349
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
14285
14350
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -14645,6 +14710,9 @@ exports.VAULT_TOKEN_DECIMALS = VAULT_TOKEN_DECIMALS;
|
|
|
14645
14710
|
exports.WalletAbstractionService = WalletAbstractionService;
|
|
14646
14711
|
exports.assetManagerAbi = assetManagerAbi;
|
|
14647
14712
|
exports.balnSwapAbi = balnSwapAbi;
|
|
14713
|
+
exports.bnUSDLegacySpokeChainIds = bnUSDLegacySpokeChainIds;
|
|
14714
|
+
exports.bnUSDLegacyTokens = bnUSDLegacyTokens;
|
|
14715
|
+
exports.bnUSDNewTokens = bnUSDNewTokens;
|
|
14648
14716
|
exports.calculateFeeAmount = calculateFeeAmount;
|
|
14649
14717
|
exports.calculatePercentageFeeAmount = calculatePercentageFeeAmount;
|
|
14650
14718
|
exports.chainIdToHubAssetsMap = chainIdToHubAssetsMap;
|
|
@@ -14652,6 +14720,7 @@ exports.connectionAbi = connectionAbi;
|
|
|
14652
14720
|
exports.encodeAddress = encodeAddress;
|
|
14653
14721
|
exports.encodeContractCalls = encodeContractCalls;
|
|
14654
14722
|
exports.erc20Abi = erc20Abi;
|
|
14723
|
+
exports.getAllLegacybnUSDTokens = getAllLegacybnUSDTokens;
|
|
14655
14724
|
exports.getEvmViemChain = getEvmViemChain;
|
|
14656
14725
|
exports.getHubAssetInfo = getHubAssetInfo;
|
|
14657
14726
|
exports.getHubChainConfig = getHubChainConfig;
|
|
@@ -14673,6 +14742,7 @@ exports.hubAssets = hubAssets;
|
|
|
14673
14742
|
exports.hubVaults = hubVaults;
|
|
14674
14743
|
exports.hubVaultsAddressSet = hubVaultsAddressSet;
|
|
14675
14744
|
exports.intentRelayChainIdToSpokeChainIdMap = intentRelayChainIdToSpokeChainIdMap;
|
|
14745
|
+
exports.isBalnMigrateParams = isBalnMigrateParams;
|
|
14676
14746
|
exports.isConfiguredMoneyMarketConfig = isConfiguredMoneyMarketConfig;
|
|
14677
14747
|
exports.isConfiguredSolverConfig = isConfiguredSolverConfig;
|
|
14678
14748
|
exports.isEvmHubChainConfig = isEvmHubChainConfig;
|
|
@@ -14684,6 +14754,8 @@ exports.isEvmUninitializedConfig = isEvmUninitializedConfig;
|
|
|
14684
14754
|
exports.isEvmUninitializedPrivateKeyConfig = isEvmUninitializedPrivateKeyConfig;
|
|
14685
14755
|
exports.isIconAddress = isIconAddress;
|
|
14686
14756
|
exports.isIconSpokeProvider = isIconSpokeProvider;
|
|
14757
|
+
exports.isIcxCreateRevertMigrationParams = isIcxCreateRevertMigrationParams;
|
|
14758
|
+
exports.isIcxMigrateParams = isIcxMigrateParams;
|
|
14687
14759
|
exports.isInjectiveSpokeProvider = isInjectiveSpokeProvider;
|
|
14688
14760
|
exports.isIntentCreationFailedError = isIntentCreationFailedError;
|
|
14689
14761
|
exports.isIntentCreationUnknownError = isIntentCreationUnknownError;
|
|
@@ -14691,6 +14763,8 @@ exports.isIntentPostExecutionFailedError = isIntentPostExecutionFailedError;
|
|
|
14691
14763
|
exports.isIntentRelayChainId = isIntentRelayChainId;
|
|
14692
14764
|
exports.isIntentSubmitTxFailedError = isIntentSubmitTxFailedError;
|
|
14693
14765
|
exports.isJsonRpcPayloadResponse = isJsonRpcPayloadResponse;
|
|
14766
|
+
exports.isLegacybnUSDChainId = isLegacybnUSDChainId;
|
|
14767
|
+
exports.isLegacybnUSDToken = isLegacybnUSDToken;
|
|
14694
14768
|
exports.isMoneyMarketBorrowUnknownError = isMoneyMarketBorrowUnknownError;
|
|
14695
14769
|
exports.isMoneyMarketCreateBorrowIntentFailedError = isMoneyMarketCreateBorrowIntentFailedError;
|
|
14696
14770
|
exports.isMoneyMarketCreateRepayIntentFailedError = isMoneyMarketCreateRepayIntentFailedError;
|
|
@@ -14705,6 +14779,8 @@ exports.isMoneyMarketSupplyUnknownError = isMoneyMarketSupplyUnknownError;
|
|
|
14705
14779
|
exports.isMoneyMarketSupportedToken = isMoneyMarketSupportedToken;
|
|
14706
14780
|
exports.isMoneyMarketWithdrawUnknownError = isMoneyMarketWithdrawUnknownError;
|
|
14707
14781
|
exports.isNativeToken = isNativeToken;
|
|
14782
|
+
exports.isNewbnUSDChainId = isNewbnUSDChainId;
|
|
14783
|
+
exports.isNewbnUSDToken = isNewbnUSDToken;
|
|
14708
14784
|
exports.isPartnerFeeAmount = isPartnerFeeAmount;
|
|
14709
14785
|
exports.isPartnerFeePercentage = isPartnerFeePercentage;
|
|
14710
14786
|
exports.isResponseAddressType = isResponseAddressType;
|
|
@@ -14714,16 +14790,17 @@ exports.isSolverSupportedToken = isSolverSupportedToken;
|
|
|
14714
14790
|
exports.isSonicSpokeProvider = isSonicSpokeProvider;
|
|
14715
14791
|
exports.isStellarSpokeProvider = isStellarSpokeProvider;
|
|
14716
14792
|
exports.isSuiSpokeProvider = isSuiSpokeProvider;
|
|
14793
|
+
exports.isUnifiedBnUSDMigrateParams = isUnifiedBnUSDMigrateParams;
|
|
14717
14794
|
exports.isValidChainHubAsset = isValidChainHubAsset;
|
|
14718
14795
|
exports.isValidHubAsset = isValidHubAsset;
|
|
14719
14796
|
exports.isValidIntentRelayChainId = isValidIntentRelayChainId;
|
|
14720
14797
|
exports.isValidOriginalAssetAddress = isValidOriginalAssetAddress;
|
|
14721
14798
|
exports.isValidSpokeChainId = isValidSpokeChainId;
|
|
14722
14799
|
exports.isWaitUntilIntentExecutedFailed = isWaitUntilIntentExecutedFailed;
|
|
14723
|
-
exports.migrationConfig = migrationConfig;
|
|
14724
14800
|
exports.moneyMarketReserveAssets = moneyMarketReserveAssets;
|
|
14725
14801
|
exports.moneyMarketReserveHubAssetsSet = moneyMarketReserveHubAssetsSet;
|
|
14726
14802
|
exports.moneyMarketSupportedTokens = moneyMarketSupportedTokens;
|
|
14803
|
+
exports.newbnUSDSpokeChainIds = newbnUSDSpokeChainIds;
|
|
14727
14804
|
exports.originalAssetTohubAssetMap = originalAssetTohubAssetMap;
|
|
14728
14805
|
exports.poolAbi = poolAbi;
|
|
14729
14806
|
exports.randomUint256 = randomUint256;
|