@sodax/sdk 0.0.1-rc.10 → 0.0.1-rc.11
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 +9 -9
- package/dist/index.cjs +969 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +267 -4
- package/dist/index.d.ts +267 -4
- package/dist/index.mjs +968 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5187,7 +5187,9 @@ var hubChainConfig = {
|
|
|
5187
5187
|
addresses: {
|
|
5188
5188
|
assetManager: "0x60c5681bD1DB4e50735c4cA3386005A4BA4937C0",
|
|
5189
5189
|
hubWallet: "0xA0ed3047D358648F2C0583B415CffCA571FDB544",
|
|
5190
|
-
xTokenManager: "0x5bD2843de9D6b0e6A05d0FB742072274EA3C6CA3"
|
|
5190
|
+
xTokenManager: "0x5bD2843de9D6b0e6A05d0FB742072274EA3C6CA3",
|
|
5191
|
+
icxMigration: "0x8Af7cae2c8377BEDD8820A5ad096AaFA29D839cc",
|
|
5192
|
+
sodaToken: "0x8515352CB9832D1d379D52366D1E995ADd358420"
|
|
5191
5193
|
},
|
|
5192
5194
|
nativeToken: "0x0000000000000000000000000000000000000000",
|
|
5193
5195
|
supportedTokens: []
|
|
@@ -5712,7 +5714,8 @@ var spokeChainConfig = {
|
|
|
5712
5714
|
addresses: {
|
|
5713
5715
|
assetManager: "cx1be33c283c7dc7617181d1b21a6a2309e71b1ee7",
|
|
5714
5716
|
connection: "cxe5cdf3b0f26967b0efc72d470d57bbf534268f94",
|
|
5715
|
-
rateLimit: "cxbbdcea9e6757023a046067ba8daa3c4c50304358"
|
|
5717
|
+
rateLimit: "cxbbdcea9e6757023a046067ba8daa3c4c50304358",
|
|
5718
|
+
wICX: "cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
5716
5719
|
},
|
|
5717
5720
|
chain: {
|
|
5718
5721
|
id: types.ICON_MAINNET_CHAIN_ID,
|
|
@@ -6100,15 +6103,15 @@ var hubAssets = {
|
|
|
6100
6103
|
decimal: 6,
|
|
6101
6104
|
symbol: "USDC",
|
|
6102
6105
|
name: "USD Coin",
|
|
6103
|
-
vault: "
|
|
6106
|
+
vault: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833"
|
|
6104
6107
|
}
|
|
6105
6108
|
},
|
|
6106
6109
|
[types.SOLANA_MAINNET_CHAIN_ID]: {
|
|
6107
6110
|
[spokeChainConfig[types.SOLANA_MAINNET_CHAIN_ID].supportedTokens.SOL.address]: {
|
|
6108
6111
|
asset: "0x0c09e69a4528945de6d16c7e469dea6996fdf636",
|
|
6109
6112
|
decimal: 9,
|
|
6110
|
-
symbol: "
|
|
6111
|
-
name: "
|
|
6113
|
+
symbol: "SOL",
|
|
6114
|
+
name: "Solana",
|
|
6112
6115
|
vault: "0xdEa692287E2cE8Cb08FA52917Be0F16b1DACDC87"
|
|
6113
6116
|
},
|
|
6114
6117
|
[spokeChainConfig[types.SOLANA_MAINNET_CHAIN_ID].bnUSD]: {
|
|
@@ -6119,11 +6122,11 @@ var hubAssets = {
|
|
|
6119
6122
|
vault: "0xE801CA34E19aBCbFeA12025378D19c4FBE250131"
|
|
6120
6123
|
},
|
|
6121
6124
|
[spokeChainConfig[types.SOLANA_MAINNET_CHAIN_ID].supportedTokens.USDC.address]: {
|
|
6122
|
-
asset: "
|
|
6125
|
+
asset: "0xC3f020057510ffE10Ceb882e1B48238b43d78a5e",
|
|
6123
6126
|
decimal: 6,
|
|
6124
6127
|
symbol: "USDC",
|
|
6125
6128
|
name: "USD Coin",
|
|
6126
|
-
vault: "
|
|
6129
|
+
vault: "0xAbbb91c0617090F0028BDC27597Cd0D038F3A833"
|
|
6127
6130
|
}
|
|
6128
6131
|
},
|
|
6129
6132
|
[types.ICON_MAINNET_CHAIN_ID]: {
|
|
@@ -6134,6 +6137,13 @@ var hubAssets = {
|
|
|
6134
6137
|
name: "ICON",
|
|
6135
6138
|
vault: "0x0000000000000000000000000000000000000000"
|
|
6136
6139
|
},
|
|
6140
|
+
[spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].addresses.wICX]: {
|
|
6141
|
+
asset: "0xb66cB7D841272AF6BaA8b8119007EdEE35d2C24F",
|
|
6142
|
+
decimal: 18,
|
|
6143
|
+
symbol: "wICX",
|
|
6144
|
+
name: "ICON",
|
|
6145
|
+
vault: "0x0000000000000000000000000000000000000000"
|
|
6146
|
+
},
|
|
6137
6147
|
[spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].bnUSD]: {
|
|
6138
6148
|
asset: "0x654dddf32a9a2ac53f5fb54bf1e93f66791f8047",
|
|
6139
6149
|
decimal: 18,
|
|
@@ -6147,8 +6157,7 @@ var DEFAULT_RELAYER_API_ENDPOINT = "https://xcall-relay.nw.iconblockchain.xyz";
|
|
|
6147
6157
|
var solverConfig = {
|
|
6148
6158
|
[types.SONIC_MAINNET_CHAIN_ID]: {
|
|
6149
6159
|
intentsContract: "0x6382D6ccD780758C5e8A6123c33ee8F4472F96ef",
|
|
6150
|
-
solverApiEndpoint: "https://
|
|
6151
|
-
// TODO replace with mainnet
|
|
6160
|
+
solverApiEndpoint: "https://sodax-solver.iconblockchain.xyz"
|
|
6152
6161
|
}
|
|
6153
6162
|
};
|
|
6154
6163
|
var getSolverConfig = (chainId) => solverConfig[chainId];
|
|
@@ -6291,11 +6300,13 @@ var moneyMarketSupportedTokens = {
|
|
|
6291
6300
|
],
|
|
6292
6301
|
[types.SUI_MAINNET_CHAIN_ID]: [
|
|
6293
6302
|
spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.SUI,
|
|
6294
|
-
spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.bnUSD
|
|
6303
|
+
spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
6304
|
+
spokeChainConfig[types.SUI_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
6295
6305
|
],
|
|
6296
6306
|
[types.INJECTIVE_MAINNET_CHAIN_ID]: [
|
|
6297
6307
|
spokeChainConfig[types.INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.INJ,
|
|
6298
|
-
spokeChainConfig[types.INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.bnUSD
|
|
6308
|
+
spokeChainConfig[types.INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
6309
|
+
spokeChainConfig[types.INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
6299
6310
|
],
|
|
6300
6311
|
[types.NIBIRU_MAINNET_CHAIN_ID]: [],
|
|
6301
6312
|
[types.SONIC_MAINNET_CHAIN_ID]: [
|
|
@@ -9064,10 +9075,7 @@ var IconSpokeService = class _IconSpokeService {
|
|
|
9064
9075
|
}
|
|
9065
9076
|
return spokeProvider.walletProvider.sendTransaction({
|
|
9066
9077
|
from: walletAddress,
|
|
9067
|
-
to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ?
|
|
9068
|
-
// wICX address
|
|
9069
|
-
"cx3975b43d260fb8ec802cef6e60c2f4d07486f11d"
|
|
9070
|
-
) : token,
|
|
9078
|
+
to: isNativeToken(spokeProvider.chainConfig.chain.id, token) ? spokeProvider.chainConfig.addresses.wICX : token,
|
|
9071
9079
|
value,
|
|
9072
9080
|
nid: spokeProvider.chainConfig.nid,
|
|
9073
9081
|
method: "transfer",
|
|
@@ -10560,12 +10568,13 @@ var SolverService = class {
|
|
|
10560
10568
|
}
|
|
10561
10569
|
/**
|
|
10562
10570
|
* Get the status of an intent from Solver API
|
|
10571
|
+
* NOTE: intentHash should be retrieved from relay packet dst_tx_hash property (see createAndSubmitIntent)
|
|
10563
10572
|
* @param {IntentStatusRequest} intentStatusRequest - The intent status request
|
|
10564
10573
|
* @returns {Promise<Result<IntentStatusResponse, IntentErrorResponse>>} The intent status response
|
|
10565
10574
|
*
|
|
10566
10575
|
* @example
|
|
10567
10576
|
* const intentStatusRequest = {
|
|
10568
|
-
* "intentHash": "a0dd7652-b360-4123-ab2d-78cfbcd20c6b"
|
|
10577
|
+
* "intentHash": "a0dd7652-b360-4123-ab2d-78cfbcd20c6b" // destination tx hash from relay packet
|
|
10569
10578
|
* } satisfies IntentStatusRequest
|
|
10570
10579
|
*
|
|
10571
10580
|
* const response = await solverService.getStatus(intentStatusRequest);
|
|
@@ -10789,10 +10798,16 @@ var SolverService = class {
|
|
|
10789
10798
|
*
|
|
10790
10799
|
* const txReceipt = approveResult.value;
|
|
10791
10800
|
*/
|
|
10792
|
-
async approve(token, amount,
|
|
10801
|
+
async approve(token, amount, spokeProvider, raw) {
|
|
10793
10802
|
try {
|
|
10794
10803
|
if (spokeProvider instanceof EvmSpokeProvider || spokeProvider instanceof SonicSpokeProvider) {
|
|
10795
|
-
const result = await Erc20Service.approve(
|
|
10804
|
+
const result = await Erc20Service.approve(
|
|
10805
|
+
token,
|
|
10806
|
+
amount,
|
|
10807
|
+
spokeProvider.chainConfig.addresses.assetManager,
|
|
10808
|
+
spokeProvider,
|
|
10809
|
+
raw
|
|
10810
|
+
);
|
|
10796
10811
|
return {
|
|
10797
10812
|
ok: true,
|
|
10798
10813
|
value: result
|
|
@@ -10937,6 +10952,937 @@ var SolverService = class {
|
|
|
10937
10952
|
}
|
|
10938
10953
|
};
|
|
10939
10954
|
|
|
10955
|
+
// src/abis/icxSwap.abi.ts
|
|
10956
|
+
var icxSwapAbi = [
|
|
10957
|
+
{
|
|
10958
|
+
type: "constructor",
|
|
10959
|
+
inputs: [],
|
|
10960
|
+
stateMutability: "nonpayable"
|
|
10961
|
+
},
|
|
10962
|
+
{
|
|
10963
|
+
type: "function",
|
|
10964
|
+
name: "ICX",
|
|
10965
|
+
inputs: [],
|
|
10966
|
+
outputs: [
|
|
10967
|
+
{
|
|
10968
|
+
name: "",
|
|
10969
|
+
type: "address",
|
|
10970
|
+
internalType: "contract IERC20"
|
|
10971
|
+
}
|
|
10972
|
+
],
|
|
10973
|
+
stateMutability: "view"
|
|
10974
|
+
},
|
|
10975
|
+
{
|
|
10976
|
+
type: "function",
|
|
10977
|
+
name: "UPGRADE_INTERFACE_VERSION",
|
|
10978
|
+
inputs: [],
|
|
10979
|
+
outputs: [
|
|
10980
|
+
{
|
|
10981
|
+
name: "",
|
|
10982
|
+
type: "string",
|
|
10983
|
+
internalType: "string"
|
|
10984
|
+
}
|
|
10985
|
+
],
|
|
10986
|
+
stateMutability: "view"
|
|
10987
|
+
},
|
|
10988
|
+
{
|
|
10989
|
+
type: "function",
|
|
10990
|
+
name: "getImplementation",
|
|
10991
|
+
inputs: [],
|
|
10992
|
+
outputs: [
|
|
10993
|
+
{
|
|
10994
|
+
name: "",
|
|
10995
|
+
type: "address",
|
|
10996
|
+
internalType: "address"
|
|
10997
|
+
}
|
|
10998
|
+
],
|
|
10999
|
+
stateMutability: "view"
|
|
11000
|
+
},
|
|
11001
|
+
{
|
|
11002
|
+
type: "function",
|
|
11003
|
+
name: "initialize",
|
|
11004
|
+
inputs: [],
|
|
11005
|
+
outputs: [],
|
|
11006
|
+
stateMutability: "nonpayable"
|
|
11007
|
+
},
|
|
11008
|
+
{
|
|
11009
|
+
type: "function",
|
|
11010
|
+
name: "owner",
|
|
11011
|
+
inputs: [],
|
|
11012
|
+
outputs: [
|
|
11013
|
+
{
|
|
11014
|
+
name: "",
|
|
11015
|
+
type: "address",
|
|
11016
|
+
internalType: "address"
|
|
11017
|
+
}
|
|
11018
|
+
],
|
|
11019
|
+
stateMutability: "view"
|
|
11020
|
+
},
|
|
11021
|
+
{
|
|
11022
|
+
type: "function",
|
|
11023
|
+
name: "pendingMigrations",
|
|
11024
|
+
inputs: [
|
|
11025
|
+
{
|
|
11026
|
+
name: "",
|
|
11027
|
+
type: "uint256",
|
|
11028
|
+
internalType: "uint256"
|
|
11029
|
+
}
|
|
11030
|
+
],
|
|
11031
|
+
outputs: [
|
|
11032
|
+
{
|
|
11033
|
+
name: "user",
|
|
11034
|
+
type: "address",
|
|
11035
|
+
internalType: "address"
|
|
11036
|
+
},
|
|
11037
|
+
{
|
|
11038
|
+
name: "to",
|
|
11039
|
+
type: "address",
|
|
11040
|
+
internalType: "address"
|
|
11041
|
+
},
|
|
11042
|
+
{
|
|
11043
|
+
name: "amount",
|
|
11044
|
+
type: "uint256",
|
|
11045
|
+
internalType: "uint256"
|
|
11046
|
+
},
|
|
11047
|
+
{
|
|
11048
|
+
name: "timestamp",
|
|
11049
|
+
type: "uint256",
|
|
11050
|
+
internalType: "uint256"
|
|
11051
|
+
}
|
|
11052
|
+
],
|
|
11053
|
+
stateMutability: "view"
|
|
11054
|
+
},
|
|
11055
|
+
{
|
|
11056
|
+
type: "function",
|
|
11057
|
+
name: "reverseSwap",
|
|
11058
|
+
inputs: [
|
|
11059
|
+
{
|
|
11060
|
+
name: "amount",
|
|
11061
|
+
type: "uint256",
|
|
11062
|
+
internalType: "uint256"
|
|
11063
|
+
},
|
|
11064
|
+
{
|
|
11065
|
+
name: "to",
|
|
11066
|
+
type: "address",
|
|
11067
|
+
internalType: "address"
|
|
11068
|
+
}
|
|
11069
|
+
],
|
|
11070
|
+
outputs: [],
|
|
11071
|
+
stateMutability: "nonpayable"
|
|
11072
|
+
},
|
|
11073
|
+
{
|
|
11074
|
+
type: "function",
|
|
11075
|
+
name: "reverseSwapEnabled",
|
|
11076
|
+
inputs: [],
|
|
11077
|
+
outputs: [
|
|
11078
|
+
{
|
|
11079
|
+
name: "",
|
|
11080
|
+
type: "bool",
|
|
11081
|
+
internalType: "bool"
|
|
11082
|
+
}
|
|
11083
|
+
],
|
|
11084
|
+
stateMutability: "view"
|
|
11085
|
+
},
|
|
11086
|
+
{
|
|
11087
|
+
type: "function",
|
|
11088
|
+
name: "sodax",
|
|
11089
|
+
inputs: [],
|
|
11090
|
+
outputs: [
|
|
11091
|
+
{
|
|
11092
|
+
name: "",
|
|
11093
|
+
type: "address",
|
|
11094
|
+
internalType: "contract IERC20"
|
|
11095
|
+
}
|
|
11096
|
+
],
|
|
11097
|
+
stateMutability: "view"
|
|
11098
|
+
},
|
|
11099
|
+
{
|
|
11100
|
+
type: "function",
|
|
11101
|
+
name: "swap",
|
|
11102
|
+
inputs: [
|
|
11103
|
+
{
|
|
11104
|
+
name: "amount",
|
|
11105
|
+
type: "uint256",
|
|
11106
|
+
internalType: "uint256"
|
|
11107
|
+
},
|
|
11108
|
+
{
|
|
11109
|
+
name: "to",
|
|
11110
|
+
type: "address",
|
|
11111
|
+
internalType: "address"
|
|
11112
|
+
}
|
|
11113
|
+
],
|
|
11114
|
+
outputs: [],
|
|
11115
|
+
stateMutability: "nonpayable"
|
|
11116
|
+
},
|
|
11117
|
+
{
|
|
11118
|
+
type: "event",
|
|
11119
|
+
name: "Initialized",
|
|
11120
|
+
inputs: [
|
|
11121
|
+
{
|
|
11122
|
+
name: "version",
|
|
11123
|
+
type: "uint64",
|
|
11124
|
+
indexed: false,
|
|
11125
|
+
internalType: "uint64"
|
|
11126
|
+
}
|
|
11127
|
+
],
|
|
11128
|
+
anonymous: false
|
|
11129
|
+
},
|
|
11130
|
+
{
|
|
11131
|
+
type: "event",
|
|
11132
|
+
name: "OwnershipTransferStarted",
|
|
11133
|
+
inputs: [
|
|
11134
|
+
{
|
|
11135
|
+
name: "previousOwner",
|
|
11136
|
+
type: "address",
|
|
11137
|
+
indexed: true,
|
|
11138
|
+
internalType: "address"
|
|
11139
|
+
},
|
|
11140
|
+
{
|
|
11141
|
+
name: "newOwner",
|
|
11142
|
+
type: "address",
|
|
11143
|
+
indexed: true,
|
|
11144
|
+
internalType: "address"
|
|
11145
|
+
}
|
|
11146
|
+
],
|
|
11147
|
+
anonymous: false
|
|
11148
|
+
},
|
|
11149
|
+
{
|
|
11150
|
+
type: "event",
|
|
11151
|
+
name: "OwnershipTransferred",
|
|
11152
|
+
inputs: [
|
|
11153
|
+
{
|
|
11154
|
+
name: "previousOwner",
|
|
11155
|
+
type: "address",
|
|
11156
|
+
indexed: true,
|
|
11157
|
+
internalType: "address"
|
|
11158
|
+
},
|
|
11159
|
+
{
|
|
11160
|
+
name: "newOwner",
|
|
11161
|
+
type: "address",
|
|
11162
|
+
indexed: true,
|
|
11163
|
+
internalType: "address"
|
|
11164
|
+
}
|
|
11165
|
+
],
|
|
11166
|
+
anonymous: false
|
|
11167
|
+
},
|
|
11168
|
+
{
|
|
11169
|
+
type: "event",
|
|
11170
|
+
name: "PendingMigrationApproved",
|
|
11171
|
+
inputs: [
|
|
11172
|
+
{
|
|
11173
|
+
name: "index",
|
|
11174
|
+
type: "uint256",
|
|
11175
|
+
indexed: false,
|
|
11176
|
+
internalType: "uint256"
|
|
11177
|
+
},
|
|
11178
|
+
{
|
|
11179
|
+
name: "user",
|
|
11180
|
+
type: "address",
|
|
11181
|
+
indexed: true,
|
|
11182
|
+
internalType: "address"
|
|
11183
|
+
},
|
|
11184
|
+
{
|
|
11185
|
+
name: "amount",
|
|
11186
|
+
type: "uint256",
|
|
11187
|
+
indexed: false,
|
|
11188
|
+
internalType: "uint256"
|
|
11189
|
+
}
|
|
11190
|
+
],
|
|
11191
|
+
anonymous: false
|
|
11192
|
+
},
|
|
11193
|
+
{
|
|
11194
|
+
type: "event",
|
|
11195
|
+
name: "PendingMigrationCreated",
|
|
11196
|
+
inputs: [
|
|
11197
|
+
{
|
|
11198
|
+
name: "user",
|
|
11199
|
+
type: "address",
|
|
11200
|
+
indexed: true,
|
|
11201
|
+
internalType: "address"
|
|
11202
|
+
},
|
|
11203
|
+
{
|
|
11204
|
+
name: "amount",
|
|
11205
|
+
type: "uint256",
|
|
11206
|
+
indexed: false,
|
|
11207
|
+
internalType: "uint256"
|
|
11208
|
+
},
|
|
11209
|
+
{
|
|
11210
|
+
name: "index",
|
|
11211
|
+
type: "uint256",
|
|
11212
|
+
indexed: false,
|
|
11213
|
+
internalType: "uint256"
|
|
11214
|
+
}
|
|
11215
|
+
],
|
|
11216
|
+
anonymous: false
|
|
11217
|
+
},
|
|
11218
|
+
{
|
|
11219
|
+
type: "event",
|
|
11220
|
+
name: "ReverseSwap",
|
|
11221
|
+
inputs: [
|
|
11222
|
+
{
|
|
11223
|
+
name: "user",
|
|
11224
|
+
type: "address",
|
|
11225
|
+
indexed: true,
|
|
11226
|
+
internalType: "address"
|
|
11227
|
+
},
|
|
11228
|
+
{
|
|
11229
|
+
name: "sodaxAmount",
|
|
11230
|
+
type: "uint256",
|
|
11231
|
+
indexed: false,
|
|
11232
|
+
internalType: "uint256"
|
|
11233
|
+
},
|
|
11234
|
+
{
|
|
11235
|
+
name: "ICXAmount",
|
|
11236
|
+
type: "uint256",
|
|
11237
|
+
indexed: false,
|
|
11238
|
+
internalType: "uint256"
|
|
11239
|
+
}
|
|
11240
|
+
],
|
|
11241
|
+
anonymous: false
|
|
11242
|
+
},
|
|
11243
|
+
{
|
|
11244
|
+
type: "event",
|
|
11245
|
+
name: "ReverseSwapToggled",
|
|
11246
|
+
inputs: [
|
|
11247
|
+
{
|
|
11248
|
+
name: "enabled",
|
|
11249
|
+
type: "bool",
|
|
11250
|
+
indexed: false,
|
|
11251
|
+
internalType: "bool"
|
|
11252
|
+
}
|
|
11253
|
+
],
|
|
11254
|
+
anonymous: false
|
|
11255
|
+
},
|
|
11256
|
+
{
|
|
11257
|
+
type: "event",
|
|
11258
|
+
name: "Swap",
|
|
11259
|
+
inputs: [
|
|
11260
|
+
{
|
|
11261
|
+
name: "user",
|
|
11262
|
+
type: "address",
|
|
11263
|
+
indexed: true,
|
|
11264
|
+
internalType: "address"
|
|
11265
|
+
},
|
|
11266
|
+
{
|
|
11267
|
+
name: "ICXAmount",
|
|
11268
|
+
type: "uint256",
|
|
11269
|
+
indexed: false,
|
|
11270
|
+
internalType: "uint256"
|
|
11271
|
+
},
|
|
11272
|
+
{
|
|
11273
|
+
name: "sodaxAmount",
|
|
11274
|
+
type: "uint256",
|
|
11275
|
+
indexed: false,
|
|
11276
|
+
internalType: "uint256"
|
|
11277
|
+
}
|
|
11278
|
+
],
|
|
11279
|
+
anonymous: false
|
|
11280
|
+
},
|
|
11281
|
+
{
|
|
11282
|
+
type: "event",
|
|
11283
|
+
name: "Upgraded",
|
|
11284
|
+
inputs: [
|
|
11285
|
+
{
|
|
11286
|
+
name: "implementation",
|
|
11287
|
+
type: "address",
|
|
11288
|
+
indexed: true,
|
|
11289
|
+
internalType: "address"
|
|
11290
|
+
}
|
|
11291
|
+
],
|
|
11292
|
+
anonymous: false
|
|
11293
|
+
},
|
|
11294
|
+
{
|
|
11295
|
+
type: "error",
|
|
11296
|
+
name: "AddressEmptyCode",
|
|
11297
|
+
inputs: [
|
|
11298
|
+
{
|
|
11299
|
+
name: "target",
|
|
11300
|
+
type: "address",
|
|
11301
|
+
internalType: "address"
|
|
11302
|
+
}
|
|
11303
|
+
]
|
|
11304
|
+
},
|
|
11305
|
+
{
|
|
11306
|
+
type: "error",
|
|
11307
|
+
name: "ERC1967InvalidImplementation",
|
|
11308
|
+
inputs: [
|
|
11309
|
+
{
|
|
11310
|
+
name: "implementation",
|
|
11311
|
+
type: "address",
|
|
11312
|
+
internalType: "address"
|
|
11313
|
+
}
|
|
11314
|
+
]
|
|
11315
|
+
},
|
|
11316
|
+
{
|
|
11317
|
+
type: "error",
|
|
11318
|
+
name: "ERC1967NonPayable",
|
|
11319
|
+
inputs: []
|
|
11320
|
+
},
|
|
11321
|
+
{
|
|
11322
|
+
type: "error",
|
|
11323
|
+
name: "FailedCall",
|
|
11324
|
+
inputs: []
|
|
11325
|
+
},
|
|
11326
|
+
{
|
|
11327
|
+
type: "error",
|
|
11328
|
+
name: "InvalidInitialization",
|
|
11329
|
+
inputs: []
|
|
11330
|
+
},
|
|
11331
|
+
{
|
|
11332
|
+
type: "error",
|
|
11333
|
+
name: "NotInitializing",
|
|
11334
|
+
inputs: []
|
|
11335
|
+
},
|
|
11336
|
+
{
|
|
11337
|
+
type: "error",
|
|
11338
|
+
name: "OwnableInvalidOwner",
|
|
11339
|
+
inputs: [
|
|
11340
|
+
{
|
|
11341
|
+
name: "owner",
|
|
11342
|
+
type: "address",
|
|
11343
|
+
internalType: "address"
|
|
11344
|
+
}
|
|
11345
|
+
]
|
|
11346
|
+
},
|
|
11347
|
+
{
|
|
11348
|
+
type: "error",
|
|
11349
|
+
name: "OwnableUnauthorizedAccount",
|
|
11350
|
+
inputs: [
|
|
11351
|
+
{
|
|
11352
|
+
name: "account",
|
|
11353
|
+
type: "address",
|
|
11354
|
+
internalType: "address"
|
|
11355
|
+
}
|
|
11356
|
+
]
|
|
11357
|
+
},
|
|
11358
|
+
{
|
|
11359
|
+
type: "error",
|
|
11360
|
+
name: "ReentrancyGuardReentrantCall",
|
|
11361
|
+
inputs: []
|
|
11362
|
+
},
|
|
11363
|
+
{
|
|
11364
|
+
type: "error",
|
|
11365
|
+
name: "SafeERC20FailedOperation",
|
|
11366
|
+
inputs: [
|
|
11367
|
+
{
|
|
11368
|
+
name: "token",
|
|
11369
|
+
type: "address",
|
|
11370
|
+
internalType: "address"
|
|
11371
|
+
}
|
|
11372
|
+
]
|
|
11373
|
+
},
|
|
11374
|
+
{
|
|
11375
|
+
type: "error",
|
|
11376
|
+
name: "UUPSUnauthorizedCallContext",
|
|
11377
|
+
inputs: []
|
|
11378
|
+
},
|
|
11379
|
+
{
|
|
11380
|
+
type: "error",
|
|
11381
|
+
name: "UUPSUnsupportedProxiableUUID",
|
|
11382
|
+
inputs: [
|
|
11383
|
+
{
|
|
11384
|
+
name: "slot",
|
|
11385
|
+
type: "bytes32",
|
|
11386
|
+
internalType: "bytes32"
|
|
11387
|
+
}
|
|
11388
|
+
]
|
|
11389
|
+
}
|
|
11390
|
+
];
|
|
11391
|
+
var IcxMigrationService = class {
|
|
11392
|
+
hubProvider;
|
|
11393
|
+
constructor(hubProvider) {
|
|
11394
|
+
this.hubProvider = hubProvider;
|
|
11395
|
+
}
|
|
11396
|
+
/**
|
|
11397
|
+
* Retrieves the available amount of SODA tokens in the ICX migration contract.
|
|
11398
|
+
* This represents the amount of tokens available for migration.
|
|
11399
|
+
*
|
|
11400
|
+
* @returns The available balance of SODA tokens in the migration contract
|
|
11401
|
+
*/
|
|
11402
|
+
async getAvailableAmount() {
|
|
11403
|
+
const balance = await this.hubProvider.publicClient.readContract({
|
|
11404
|
+
address: this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11405
|
+
abi: erc20Abi,
|
|
11406
|
+
functionName: "balanceOf",
|
|
11407
|
+
args: [this.hubProvider.chainConfig.addresses.icxMigration]
|
|
11408
|
+
});
|
|
11409
|
+
return balance;
|
|
11410
|
+
}
|
|
11411
|
+
/**
|
|
11412
|
+
* Generates transaction data for migrating wICX tokens from ICON to the hub chain.
|
|
11413
|
+
* This method creates the necessary contract calls to:
|
|
11414
|
+
* 1. Approve the migration contract to spend the wICX tokens
|
|
11415
|
+
* 2. Execute the migration swap
|
|
11416
|
+
*
|
|
11417
|
+
* @param params - The migration parameters including token address, amount, and recipient
|
|
11418
|
+
* @returns Encoded transaction data for the migration operation
|
|
11419
|
+
* @throws Will throw an error if the hub asset configuration is not found
|
|
11420
|
+
*/
|
|
11421
|
+
migrateData(params) {
|
|
11422
|
+
const calls = [];
|
|
11423
|
+
const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, params.icx);
|
|
11424
|
+
invariant2__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.icx}`);
|
|
11425
|
+
calls.push(
|
|
11426
|
+
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
|
|
11427
|
+
);
|
|
11428
|
+
calls.push(this.encodeMigrate(params.amount, params.to));
|
|
11429
|
+
return encodeContractCalls(calls);
|
|
11430
|
+
}
|
|
11431
|
+
/**
|
|
11432
|
+
* Generates transaction data for migrating back tokens to the ICON chain.
|
|
11433
|
+
* @param params - The migration parameters including token address, amount, and recipient
|
|
11434
|
+
* @returns Encoded transaction data for the migration operation
|
|
11435
|
+
* @throws Will throw an error if the hub asset configuration is not found
|
|
11436
|
+
*/
|
|
11437
|
+
revertMigration(params) {
|
|
11438
|
+
const calls = [];
|
|
11439
|
+
const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, params.wICX);
|
|
11440
|
+
invariant2__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
|
|
11441
|
+
calls.push(
|
|
11442
|
+
Erc20Service.encodeApprove(
|
|
11443
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11444
|
+
this.hubProvider.chainConfig.addresses.icxMigration,
|
|
11445
|
+
params.amount
|
|
11446
|
+
)
|
|
11447
|
+
);
|
|
11448
|
+
calls.push(this.encodeRevertMigration(params.amount, params.userWallet));
|
|
11449
|
+
calls.push(
|
|
11450
|
+
EvmAssetManagerService.encodeTransfer(
|
|
11451
|
+
assetConfig.asset,
|
|
11452
|
+
params.to,
|
|
11453
|
+
params.amount,
|
|
11454
|
+
this.hubProvider.chainConfig.addresses.assetManager
|
|
11455
|
+
)
|
|
11456
|
+
);
|
|
11457
|
+
return encodeContractCalls(calls);
|
|
11458
|
+
}
|
|
11459
|
+
/**
|
|
11460
|
+
* Encodes a migration transaction for the ICX swap contract.
|
|
11461
|
+
* This creates the contract call data for swapping wICX tokens to SODA tokens.
|
|
11462
|
+
*
|
|
11463
|
+
* @param amount - The amount of wICX tokens to migrate
|
|
11464
|
+
* @param to - The address that will receive the migrated SODA tokens
|
|
11465
|
+
* @returns The encoded contract call for the migration operation
|
|
11466
|
+
*/
|
|
11467
|
+
encodeMigrate(amount, to) {
|
|
11468
|
+
return {
|
|
11469
|
+
address: this.hubProvider.chainConfig.addresses.icxMigration,
|
|
11470
|
+
value: 0n,
|
|
11471
|
+
data: viem.encodeFunctionData({
|
|
11472
|
+
abi: icxSwapAbi,
|
|
11473
|
+
functionName: "swap",
|
|
11474
|
+
args: [amount, to]
|
|
11475
|
+
})
|
|
11476
|
+
};
|
|
11477
|
+
}
|
|
11478
|
+
/**
|
|
11479
|
+
* Encodes a revert migration transaction for the ICX swap contract.
|
|
11480
|
+
* This creates the contract call data for swapping SODA tokens to wICX tokens.
|
|
11481
|
+
*
|
|
11482
|
+
* @param amount - The amount of wICX tokens to migrate
|
|
11483
|
+
* @param to - The address that will receive the migrated SODA tokens
|
|
11484
|
+
* @returns The encoded contract call for the migration operation
|
|
11485
|
+
*/
|
|
11486
|
+
encodeRevertMigration(amount, to) {
|
|
11487
|
+
return {
|
|
11488
|
+
address: this.hubProvider.chainConfig.addresses.icxMigration,
|
|
11489
|
+
value: 0n,
|
|
11490
|
+
data: viem.encodeFunctionData({
|
|
11491
|
+
abi: icxSwapAbi,
|
|
11492
|
+
functionName: "reverseSwap",
|
|
11493
|
+
args: [amount, to]
|
|
11494
|
+
})
|
|
11495
|
+
};
|
|
11496
|
+
}
|
|
11497
|
+
};
|
|
11498
|
+
var MigrationService = class {
|
|
11499
|
+
icxMigration;
|
|
11500
|
+
hubProvider;
|
|
11501
|
+
config;
|
|
11502
|
+
constructor(hubProvider, config) {
|
|
11503
|
+
this.hubProvider = hubProvider;
|
|
11504
|
+
this.icxMigration = new IcxMigrationService(hubProvider);
|
|
11505
|
+
this.config = config ?? {
|
|
11506
|
+
relayerApiEndpoint: DEFAULT_RELAYER_API_ENDPOINT
|
|
11507
|
+
};
|
|
11508
|
+
}
|
|
11509
|
+
async migrateData(params) {
|
|
11510
|
+
return this.icxMigration.migrateData(params);
|
|
11511
|
+
}
|
|
11512
|
+
/**
|
|
11513
|
+
* Checks if the allowance is valid for the migration transaction.
|
|
11514
|
+
* @param params - The parameters for the migration transaction.
|
|
11515
|
+
* @param spokeProvider - The spoke provider.
|
|
11516
|
+
* @returns {Promise<Result<boolean>>} - Returns the result of the allowance check or error
|
|
11517
|
+
*
|
|
11518
|
+
* @example
|
|
11519
|
+
* const result = await migrationService.isAllowanceValid(
|
|
11520
|
+
* {
|
|
11521
|
+
* token: 'ICX', // Token to migrate
|
|
11522
|
+
* icx: 'cx...', // Address of the ICX or wICX token to migrate
|
|
11523
|
+
* amount: 1000n, // Amount to migrate (in ICX decimals, usually 18)
|
|
11524
|
+
* to: '0x...', // Address to receive the migrated SODA tokens
|
|
11525
|
+
* action: 'migrate', // Action to perform (migrate or revert)
|
|
11526
|
+
* },
|
|
11527
|
+
* spokeProvider, // IconSpokeProvider instance
|
|
11528
|
+
* );
|
|
11529
|
+
*
|
|
11530
|
+
*/
|
|
11531
|
+
async isAllowanceValid(params, spokeProvider) {
|
|
11532
|
+
try {
|
|
11533
|
+
if (params.action === "migrate") {
|
|
11534
|
+
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
11535
|
+
invariant2__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
11536
|
+
invariant2__default.default(
|
|
11537
|
+
spokeProvider instanceof IconSpokeProvider,
|
|
11538
|
+
"Spoke provider must be an instance of IconSpokeProvider"
|
|
11539
|
+
);
|
|
11540
|
+
invariant2__default.default(
|
|
11541
|
+
params.icx.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.icx.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
11542
|
+
"Token must be wICX or native ICX token"
|
|
11543
|
+
);
|
|
11544
|
+
invariant2__default.default(params.token === "ICX", "Token must be ICX");
|
|
11545
|
+
return {
|
|
11546
|
+
ok: true,
|
|
11547
|
+
value: true
|
|
11548
|
+
};
|
|
11549
|
+
}
|
|
11550
|
+
if (params.action === "revert") {
|
|
11551
|
+
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
11552
|
+
invariant2__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
11553
|
+
invariant2__default.default(
|
|
11554
|
+
spokeProvider instanceof SonicSpokeProvider,
|
|
11555
|
+
"Spoke provider must be an instance of SonicSpokeProvider"
|
|
11556
|
+
);
|
|
11557
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
11558
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
11559
|
+
return await Erc20Service.isAllowanceValid(
|
|
11560
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11561
|
+
params.amount,
|
|
11562
|
+
wallet,
|
|
11563
|
+
userRouter,
|
|
11564
|
+
spokeProvider
|
|
11565
|
+
);
|
|
11566
|
+
}
|
|
11567
|
+
return {
|
|
11568
|
+
ok: false,
|
|
11569
|
+
error: new Error("Invalid action")
|
|
11570
|
+
};
|
|
11571
|
+
} catch (error) {
|
|
11572
|
+
return {
|
|
11573
|
+
ok: false,
|
|
11574
|
+
error
|
|
11575
|
+
};
|
|
11576
|
+
}
|
|
11577
|
+
}
|
|
11578
|
+
/**
|
|
11579
|
+
* Approves the amount spending for the revert migration transaction.
|
|
11580
|
+
* @param params - The parameters for the revert migration transaction.
|
|
11581
|
+
* @param spokeProvider - The spoke provider.
|
|
11582
|
+
* @param raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
11583
|
+
* @returns {Promise<Result<TxReturnType<S, R>>>} - Returns the raw transaction payload or transaction hash
|
|
11584
|
+
*
|
|
11585
|
+
* @example
|
|
11586
|
+
* const result = await migrationService.approve(
|
|
11587
|
+
* {
|
|
11588
|
+
* amount: 1000n, // Amount of SODA tokens to revert
|
|
11589
|
+
* to: 'hx...', // Icon Address to receive the reverted SODA tokens as ICX
|
|
11590
|
+
* action: 'revert',
|
|
11591
|
+
* },
|
|
11592
|
+
* spokeProvider, // SonicSpokeProvider instance
|
|
11593
|
+
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
11594
|
+
* );
|
|
11595
|
+
*
|
|
11596
|
+
*/
|
|
11597
|
+
async approve(params, spokeProvider, raw) {
|
|
11598
|
+
try {
|
|
11599
|
+
if (params.action === "revert") {
|
|
11600
|
+
invariant2__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
11601
|
+
invariant2__default.default(params.to.length > 0, "To address is required");
|
|
11602
|
+
invariant2__default.default(
|
|
11603
|
+
spokeProvider instanceof SonicSpokeProvider,
|
|
11604
|
+
"Spoke provider must be an instance of SonicSpokeProvider"
|
|
11605
|
+
);
|
|
11606
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
11607
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
11608
|
+
const result = await Erc20Service.approve(
|
|
11609
|
+
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11610
|
+
params.amount,
|
|
11611
|
+
userRouter,
|
|
11612
|
+
spokeProvider,
|
|
11613
|
+
raw
|
|
11614
|
+
);
|
|
11615
|
+
return {
|
|
11616
|
+
ok: true,
|
|
11617
|
+
value: result
|
|
11618
|
+
};
|
|
11619
|
+
}
|
|
11620
|
+
return {
|
|
11621
|
+
ok: false,
|
|
11622
|
+
error: new Error("Invalid action")
|
|
11623
|
+
};
|
|
11624
|
+
} catch (error) {
|
|
11625
|
+
return {
|
|
11626
|
+
ok: false,
|
|
11627
|
+
error
|
|
11628
|
+
};
|
|
11629
|
+
}
|
|
11630
|
+
}
|
|
11631
|
+
/**
|
|
11632
|
+
* Creates a migration intent and submits (relays) it to the hub chain.
|
|
11633
|
+
* @param params - The parameters for the migration transaction.
|
|
11634
|
+
* @param spokeProvider - The spoke provider.
|
|
11635
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
11636
|
+
* @returns {Promise<Result<[Hex, Hex], MigrationError<'MIGRATION_FAILED'> | MigrationError<'CREATE_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
11637
|
+
* Returns a Result containing a tuple of [spokeTxHash, hubTxHash] if successful,
|
|
11638
|
+
* or an error describing why the migration or relay failed.
|
|
11639
|
+
*
|
|
11640
|
+
* @example
|
|
11641
|
+
* const result = await migrationService.createAndSubmitMigrateIntent(
|
|
11642
|
+
* {
|
|
11643
|
+
* token: 'ICX', // Token to migrate
|
|
11644
|
+
* icx: 'cx...', // Address of the ICX or wICX token to migrate
|
|
11645
|
+
* amount: 1000n, // Amount to migrate (in ICX decimals, usually 18)
|
|
11646
|
+
* to: '0x...', // Address to receive the migrated SODA tokens
|
|
11647
|
+
* action: 'migrate',
|
|
11648
|
+
* },
|
|
11649
|
+
* spokeProvider, // IconSpokeProvider instance
|
|
11650
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
11651
|
+
* );
|
|
11652
|
+
*
|
|
11653
|
+
* if (!result.ok) {
|
|
11654
|
+
* // Handle error
|
|
11655
|
+
* }
|
|
11656
|
+
*
|
|
11657
|
+
* const [
|
|
11658
|
+
* spokeTxHash, // transaction hash on the spoke chain
|
|
11659
|
+
* hubTxHash, // transaction hash on the hub chain (i.e. the transaction that was relayed to the hub)
|
|
11660
|
+
* ] = result.value;
|
|
11661
|
+
* console.log('Migration transaction hashes:', { spokeTxHash, hubTxHash });
|
|
11662
|
+
*/
|
|
11663
|
+
async createAndSubmitMigrateIntent(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
11664
|
+
try {
|
|
11665
|
+
const txResult = await this.createMigrateIntent(params, spokeProvider);
|
|
11666
|
+
if (!txResult.ok) {
|
|
11667
|
+
return {
|
|
11668
|
+
ok: false,
|
|
11669
|
+
error: txResult.error
|
|
11670
|
+
};
|
|
11671
|
+
}
|
|
11672
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
11673
|
+
txResult.value,
|
|
11674
|
+
spokeProvider,
|
|
11675
|
+
this.config.relayerApiEndpoint,
|
|
11676
|
+
timeout
|
|
11677
|
+
);
|
|
11678
|
+
if (!packetResult.ok) {
|
|
11679
|
+
return packetResult;
|
|
11680
|
+
}
|
|
11681
|
+
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
11682
|
+
} catch (error) {
|
|
11683
|
+
return {
|
|
11684
|
+
ok: false,
|
|
11685
|
+
error: {
|
|
11686
|
+
code: "MIGRATION_FAILED",
|
|
11687
|
+
data: {
|
|
11688
|
+
payload: params,
|
|
11689
|
+
error
|
|
11690
|
+
}
|
|
11691
|
+
}
|
|
11692
|
+
};
|
|
11693
|
+
}
|
|
11694
|
+
}
|
|
11695
|
+
/**
|
|
11696
|
+
* Creates a revert migration (SODA to ICX) intent and submits (relays) it to the spoke chain.
|
|
11697
|
+
* @param params - The parameters for the revert migration transaction.
|
|
11698
|
+
* @param spokeProvider - The SonicSpokeProvider instance.
|
|
11699
|
+
* @param timeout - The timeout in milliseconds for the transaction. Default is 60 seconds.
|
|
11700
|
+
*
|
|
11701
|
+
* @returns {Promise<Result<[Hex, Hex], MigrationError<'REVERT_MIGRATION_FAILED'> | MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'> | RelayError>>}
|
|
11702
|
+
* Returns a Result containing a tuple of [hubTxHash, spokeTxHash] if successful,
|
|
11703
|
+
* or an error describing why the revert migration or relay failed.
|
|
11704
|
+
*
|
|
11705
|
+
*
|
|
11706
|
+
* @example
|
|
11707
|
+
* const result = await migrationService.createAndSubmitRevertMigrationIntent(
|
|
11708
|
+
* {
|
|
11709
|
+
* amount: 1000n, // Amount of SODA tokens to revert
|
|
11710
|
+
* to: 'hx...', // Icon Address to receive the reverted SODA tokens as ICX
|
|
11711
|
+
* action: 'revert',
|
|
11712
|
+
* },
|
|
11713
|
+
* spokeProvider, // SonicSpokeProvider instance
|
|
11714
|
+
* 30000 // Optional timeout in milliseconds (default: 60000, i.e. 60 seconds)
|
|
11715
|
+
* );
|
|
11716
|
+
*
|
|
11717
|
+
* if (!result.ok) {
|
|
11718
|
+
* // Handle error
|
|
11719
|
+
* }
|
|
11720
|
+
*
|
|
11721
|
+
* const [
|
|
11722
|
+
* hubTxHash, // transaction hash on the hub chain
|
|
11723
|
+
* spokeTxHash, // transaction hash on the spoke chain (i.e. the transaction that was relayed to the spoke)
|
|
11724
|
+
* ] = result.value;
|
|
11725
|
+
* console.log('Revert migration transaction hashes:', { hubTxHash, spokeTxHash });
|
|
11726
|
+
*/
|
|
11727
|
+
async createAndSubmitRevertMigrationIntent(params, spokeProvider, timeout = DEFAULT_RELAY_TX_TIMEOUT) {
|
|
11728
|
+
try {
|
|
11729
|
+
const txResult = await this.createRevertMigrationIntent(params, spokeProvider);
|
|
11730
|
+
if (!txResult.ok) {
|
|
11731
|
+
return txResult;
|
|
11732
|
+
}
|
|
11733
|
+
const packetResult = await relayTxAndWaitPacket(
|
|
11734
|
+
txResult.value,
|
|
11735
|
+
spokeProvider,
|
|
11736
|
+
this.config.relayerApiEndpoint,
|
|
11737
|
+
timeout
|
|
11738
|
+
);
|
|
11739
|
+
if (!packetResult.ok) {
|
|
11740
|
+
return packetResult;
|
|
11741
|
+
}
|
|
11742
|
+
return { ok: true, value: [txResult.value, packetResult.value.dst_tx_hash] };
|
|
11743
|
+
} catch (error) {
|
|
11744
|
+
return {
|
|
11745
|
+
ok: false,
|
|
11746
|
+
error: {
|
|
11747
|
+
code: "REVERT_MIGRATION_FAILED",
|
|
11748
|
+
data: {
|
|
11749
|
+
payload: params,
|
|
11750
|
+
error
|
|
11751
|
+
}
|
|
11752
|
+
}
|
|
11753
|
+
};
|
|
11754
|
+
}
|
|
11755
|
+
}
|
|
11756
|
+
/**
|
|
11757
|
+
* Migrates ICX or wICX tokens from ICON to the hub chain.
|
|
11758
|
+
* This function handles the migration of ICX or wICX tokens to SODA tokens on the hub chain.
|
|
11759
|
+
* Note: This function does not relay the transaction to the spoke chain.
|
|
11760
|
+
* You should call the `isAllowanceValid` function before calling this function to check if the allowance is valid.
|
|
11761
|
+
* You should call the `relayTxAndWaitPacket` function after calling this function to relay the transaction to the spoke chain.
|
|
11762
|
+
*
|
|
11763
|
+
* @param {MigrationParams} params - The parameters for the migration transaction.
|
|
11764
|
+
* @param {IconSpokeProvider} spokeProvider - The spoke provider.
|
|
11765
|
+
* @param {boolean} raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
11766
|
+
* @returns {Promise<Result<TxReturnType<IconSpokeProvider, R>, MigrationError<'CREATE_MIGRATION_INTENT_FAILED'>>>} - Returns the raw transaction payload or transaction hash
|
|
11767
|
+
*
|
|
11768
|
+
* @example
|
|
11769
|
+
* const result = await migrationService.createMigrateIntent(
|
|
11770
|
+
* {
|
|
11771
|
+
* icx: 'cx...', // Address of the ICX or wICX token to migrate
|
|
11772
|
+
* amount: 1000n, // Amount to migrate (in ICX decimals, usually 18)
|
|
11773
|
+
* to: '0x...', // Address to receive the migrated SODA tokens
|
|
11774
|
+
* },
|
|
11775
|
+
* spokeProvider, // IconSpokeProvider instance
|
|
11776
|
+
* true // Optional raw flag to return the raw transaction hash instead of the transaction receipt
|
|
11777
|
+
* );
|
|
11778
|
+
*
|
|
11779
|
+
* if (!result.ok) {
|
|
11780
|
+
* // Handle error
|
|
11781
|
+
* }
|
|
11782
|
+
*/
|
|
11783
|
+
async createMigrateIntent(params, spokeProvider, raw) {
|
|
11784
|
+
try {
|
|
11785
|
+
invariant2__default.default(params.amount > 0, "Amount must be greater than 0");
|
|
11786
|
+
invariant2__default.default(viem.isAddress(params.to), "Recipient address is required");
|
|
11787
|
+
invariant2__default.default(
|
|
11788
|
+
params.icx.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.icx.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
11789
|
+
"Token must be wICX or native ICX token"
|
|
11790
|
+
);
|
|
11791
|
+
invariant2__default.default(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
|
|
11792
|
+
invariant2__default.default(params.token === "ICX", "Token must be ICX");
|
|
11793
|
+
const availableAmount = await this.icxMigration.getAvailableAmount();
|
|
11794
|
+
if (availableAmount < params.amount) {
|
|
11795
|
+
throw new Error(
|
|
11796
|
+
`Insufficient liquidity. Available: ${availableAmount.toString()}, Requested: ${params.amount.toString()}`
|
|
11797
|
+
);
|
|
11798
|
+
}
|
|
11799
|
+
const migrationData = this.icxMigration.migrateData(params);
|
|
11800
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11801
|
+
const txResult = await SpokeService.deposit(
|
|
11802
|
+
{
|
|
11803
|
+
from: walletAddress,
|
|
11804
|
+
token: params.icx,
|
|
11805
|
+
amount: params.amount,
|
|
11806
|
+
data: migrationData
|
|
11807
|
+
},
|
|
11808
|
+
spokeProvider,
|
|
11809
|
+
this.hubProvider,
|
|
11810
|
+
raw
|
|
11811
|
+
);
|
|
11812
|
+
return {
|
|
11813
|
+
ok: true,
|
|
11814
|
+
value: txResult
|
|
11815
|
+
};
|
|
11816
|
+
} catch (error) {
|
|
11817
|
+
return {
|
|
11818
|
+
ok: false,
|
|
11819
|
+
error: {
|
|
11820
|
+
code: "CREATE_MIGRATION_INTENT_FAILED",
|
|
11821
|
+
data: {
|
|
11822
|
+
payload: params,
|
|
11823
|
+
error
|
|
11824
|
+
}
|
|
11825
|
+
}
|
|
11826
|
+
};
|
|
11827
|
+
}
|
|
11828
|
+
}
|
|
11829
|
+
/**
|
|
11830
|
+
* Creates a revert migration intent transaction on the hub chain.
|
|
11831
|
+
* Note: This function does not relay the transaction to the spoke chain.
|
|
11832
|
+
* You should call the `isAllowanceValid` function before calling this function to check if the allowance is valid.
|
|
11833
|
+
* You should call the `relayTxAndWaitPacket` function after calling this function to relay the transaction to the spoke chain.
|
|
11834
|
+
* @param {IcxCreateRevertMigrationParams} - The parameters for the revert migration transaction.
|
|
11835
|
+
* @param {SonicSpokeProvider} spokeProvider - The spoke provider.
|
|
11836
|
+
* @param {boolean} raw - Whether to return the raw transaction hash instead of the transaction receipt
|
|
11837
|
+
* @returns {Promise<Result<TxReturnType<SonicSpokeProvider, R>, MigrationError<'CREATE_REVERT_MIGRATION_INTENT_FAILED'>>>} - Returns the transaction hash or error
|
|
11838
|
+
*
|
|
11839
|
+
* @example
|
|
11840
|
+
* const result = await migrationService.createRevertMigrationIntent(
|
|
11841
|
+
* {
|
|
11842
|
+
* amount: 1000n, // Amount of SODA tokens to revert
|
|
11843
|
+
* to: 'hx...', // Icon Address to receive the reverted SODA tokens as ICX
|
|
11844
|
+
* action: 'revert',
|
|
11845
|
+
* },
|
|
11846
|
+
*/
|
|
11847
|
+
async createRevertMigrationIntent(params, spokeProvider, raw) {
|
|
11848
|
+
try {
|
|
11849
|
+
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
11850
|
+
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
11851
|
+
const data = this.icxMigration.revertMigration({
|
|
11852
|
+
wICX: spokeChainConfig[types.ICON_MAINNET_CHAIN_ID].addresses.wICX,
|
|
11853
|
+
amount: params.amount,
|
|
11854
|
+
to: encodeAddress(types.ICON_MAINNET_CHAIN_ID, params.to),
|
|
11855
|
+
userWallet: userRouter
|
|
11856
|
+
});
|
|
11857
|
+
const txResult = await SonicSpokeService.deposit(
|
|
11858
|
+
{
|
|
11859
|
+
from: wallet,
|
|
11860
|
+
token: this.hubProvider.chainConfig.addresses.sodaToken,
|
|
11861
|
+
amount: params.amount,
|
|
11862
|
+
data
|
|
11863
|
+
},
|
|
11864
|
+
spokeProvider,
|
|
11865
|
+
raw
|
|
11866
|
+
);
|
|
11867
|
+
return {
|
|
11868
|
+
ok: true,
|
|
11869
|
+
value: txResult
|
|
11870
|
+
};
|
|
11871
|
+
} catch (error) {
|
|
11872
|
+
return {
|
|
11873
|
+
ok: false,
|
|
11874
|
+
error: {
|
|
11875
|
+
code: "CREATE_REVERT_MIGRATION_INTENT_FAILED",
|
|
11876
|
+
data: {
|
|
11877
|
+
payload: params,
|
|
11878
|
+
error
|
|
11879
|
+
}
|
|
11880
|
+
}
|
|
11881
|
+
};
|
|
11882
|
+
}
|
|
11883
|
+
}
|
|
11884
|
+
};
|
|
11885
|
+
|
|
10940
11886
|
// src/entities/Sodax.ts
|
|
10941
11887
|
var Sodax = class {
|
|
10942
11888
|
config;
|
|
@@ -10944,6 +11890,8 @@ var Sodax = class {
|
|
|
10944
11890
|
// Solver service enabling intent based swaps
|
|
10945
11891
|
moneyMarket;
|
|
10946
11892
|
// Money Market service enabling cross-chain lending and borrowing
|
|
11893
|
+
migration;
|
|
11894
|
+
// ICX migration service enabling ICX migration to SODA
|
|
10947
11895
|
hubProvider;
|
|
10948
11896
|
// hub provider for the hub chain (e.g. Sonic mainnet)
|
|
10949
11897
|
relayerApiEndpoint;
|
|
@@ -10954,6 +11902,7 @@ var Sodax = class {
|
|
|
10954
11902
|
this.hubProvider = new EvmHubProvider(config?.hubProviderConfig);
|
|
10955
11903
|
this.solver = config && config.solver ? new SolverService(config.solver, this.hubProvider, this.relayerApiEndpoint) : new SolverService(void 0, this.hubProvider, this.relayerApiEndpoint);
|
|
10956
11904
|
this.moneyMarket = config && config.moneyMarket ? new MoneyMarketService(config.moneyMarket, this.hubProvider, this.relayerApiEndpoint) : new MoneyMarketService(void 0, this.hubProvider, this.relayerApiEndpoint);
|
|
11905
|
+
this.migration = config && config.migration ? new MigrationService(this.hubProvider, config.migration) : new MigrationService(this.hubProvider);
|
|
10957
11906
|
}
|
|
10958
11907
|
};
|
|
10959
11908
|
|
|
@@ -11009,12 +11958,14 @@ exports.HubVaultSymbols = HubVaultSymbols;
|
|
|
11009
11958
|
exports.ICON_TX_RESULT_WAIT_MAX_RETRY = ICON_TX_RESULT_WAIT_MAX_RETRY;
|
|
11010
11959
|
exports.INTENT_RELAY_CHAIN_IDS = INTENT_RELAY_CHAIN_IDS;
|
|
11011
11960
|
exports.IconSpokeProvider = IconSpokeProvider;
|
|
11961
|
+
exports.IcxMigrationService = IcxMigrationService;
|
|
11012
11962
|
exports.IntentCreatedEventAbi = IntentCreatedEventAbi;
|
|
11013
11963
|
exports.IntentDataType = IntentDataType;
|
|
11014
11964
|
exports.IntentErrorCode = IntentErrorCode;
|
|
11015
11965
|
exports.IntentStatusCode = IntentStatusCode;
|
|
11016
11966
|
exports.IntentsAbi = IntentsAbi;
|
|
11017
11967
|
exports.MAX_UINT256 = MAX_UINT256;
|
|
11968
|
+
exports.MigrationService = MigrationService;
|
|
11018
11969
|
exports.MoneyMarketService = MoneyMarketService;
|
|
11019
11970
|
exports.Sodax = Sodax;
|
|
11020
11971
|
exports.SolanaSpokeProvider = SolanaSpokeProvider;
|