@sodax/sdk 0.0.1-rc.25 → 0.0.1-rc.27
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/dist/index.cjs +225 -131
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +224 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var viem = require('viem');
|
|
4
|
-
var
|
|
4
|
+
var invariant11 = require('tiny-invariant');
|
|
5
5
|
var bcs = require('@mysten/sui/bcs');
|
|
6
6
|
var web3_js = require('@solana/web3.js');
|
|
7
7
|
var stellarSdk = require('@stellar/stellar-sdk');
|
|
@@ -39,7 +39,7 @@ function _interopNamespace(e) {
|
|
|
39
39
|
return Object.freeze(n);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
var
|
|
42
|
+
var invariant11__default = /*#__PURE__*/_interopDefault(invariant11);
|
|
43
43
|
var IconSdkRaw__namespace = /*#__PURE__*/_interopNamespace(IconSdkRaw);
|
|
44
44
|
var rlp__namespace = /*#__PURE__*/_interopNamespace(rlp);
|
|
45
45
|
var anchor__namespace = /*#__PURE__*/_interopNamespace(anchor);
|
|
@@ -6169,16 +6169,16 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
6169
6169
|
if (!fee) {
|
|
6170
6170
|
return 0n;
|
|
6171
6171
|
}
|
|
6172
|
-
|
|
6172
|
+
invariant11__default.default(inputAmount > 0n, "Input amount must be greater than 0");
|
|
6173
6173
|
let feeAmount = 0n;
|
|
6174
6174
|
if (isPartnerFeeAmount(fee)) {
|
|
6175
|
-
|
|
6175
|
+
invariant11__default.default(
|
|
6176
6176
|
fee.amount >= 0 && fee.amount <= inputAmount,
|
|
6177
6177
|
`Fee amount must be greater than 0 and less than or equal to the input amount: ${fee.amount}`
|
|
6178
6178
|
);
|
|
6179
6179
|
feeAmount = fee.amount;
|
|
6180
6180
|
} else if (isPartnerFeePercentage(fee)) {
|
|
6181
|
-
|
|
6181
|
+
invariant11__default.default(
|
|
6182
6182
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
6183
6183
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
6184
6184
|
);
|
|
@@ -6187,8 +6187,8 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
6187
6187
|
return feeAmount;
|
|
6188
6188
|
}
|
|
6189
6189
|
function adjustAmountByFee(amount, fee, quoteType) {
|
|
6190
|
-
|
|
6191
|
-
|
|
6190
|
+
invariant11__default.default(amount > 0n, "Amount must be greater than 0");
|
|
6191
|
+
invariant11__default.default(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
|
|
6192
6192
|
if (quoteType === "exact_input") {
|
|
6193
6193
|
return amount - calculateFeeAmount(amount, fee);
|
|
6194
6194
|
}
|
|
@@ -10269,6 +10269,58 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10269
10269
|
}
|
|
10270
10270
|
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
10271
10271
|
}
|
|
10272
|
+
static async createSwapIntent(createIntentParams, creatorHubWalletAddress, solverConfig2, fee, spokeProvider, hubProvider, raw) {
|
|
10273
|
+
let inputToken = getHubAssetInfo(createIntentParams.srcChain, createIntentParams.inputToken)?.asset;
|
|
10274
|
+
if (createIntentParams.srcChain === hubProvider.chainConfig.chain.id && createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
10275
|
+
inputToken = hubProvider.chainConfig.nativeToken;
|
|
10276
|
+
}
|
|
10277
|
+
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
10278
|
+
invariant11__default.default(
|
|
10279
|
+
inputToken,
|
|
10280
|
+
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
10281
|
+
);
|
|
10282
|
+
invariant11__default.default(
|
|
10283
|
+
outputToken,
|
|
10284
|
+
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
10285
|
+
);
|
|
10286
|
+
const [feeData, feeAmount] = EvmSolverService.createIntentFeeData(fee, createIntentParams.inputAmount);
|
|
10287
|
+
const intentsContract = solverConfig2.intentsContract;
|
|
10288
|
+
const intent = {
|
|
10289
|
+
...createIntentParams,
|
|
10290
|
+
inputToken,
|
|
10291
|
+
outputToken,
|
|
10292
|
+
inputAmount: createIntentParams.inputAmount - feeAmount,
|
|
10293
|
+
srcChain: getIntentRelayChainId(createIntentParams.srcChain),
|
|
10294
|
+
dstChain: getIntentRelayChainId(createIntentParams.dstChain),
|
|
10295
|
+
srcAddress: encodeAddress(createIntentParams.srcChain, createIntentParams.srcAddress),
|
|
10296
|
+
dstAddress: encodeAddress(createIntentParams.dstChain, createIntentParams.dstAddress),
|
|
10297
|
+
intentId: randomUint256(),
|
|
10298
|
+
creator: creatorHubWalletAddress,
|
|
10299
|
+
data: feeData
|
|
10300
|
+
// fee amount will be deducted from the input amount
|
|
10301
|
+
};
|
|
10302
|
+
const txData = EvmSolverService.encodeCreateIntent(intent, intentsContract);
|
|
10303
|
+
const rawTx = {
|
|
10304
|
+
from: await spokeProvider.walletProvider.getWalletAddress(),
|
|
10305
|
+
to: txData.address,
|
|
10306
|
+
data: txData.data,
|
|
10307
|
+
value: createIntentParams.inputToken.toLowerCase() === hubProvider.chainConfig.nativeToken.toLowerCase() ? createIntentParams.inputAmount : 0n
|
|
10308
|
+
};
|
|
10309
|
+
if (raw) {
|
|
10310
|
+
return [
|
|
10311
|
+
rawTx,
|
|
10312
|
+
intent,
|
|
10313
|
+
feeAmount,
|
|
10314
|
+
txData.data
|
|
10315
|
+
];
|
|
10316
|
+
}
|
|
10317
|
+
return [
|
|
10318
|
+
await spokeProvider.walletProvider.sendTransaction(rawTx),
|
|
10319
|
+
intent,
|
|
10320
|
+
feeAmount,
|
|
10321
|
+
txData.data
|
|
10322
|
+
];
|
|
10323
|
+
}
|
|
10272
10324
|
/**
|
|
10273
10325
|
* Get the balance of the token in the spoke chain.
|
|
10274
10326
|
* @param {Address} token - The address of the token to get the balance of.
|
|
@@ -10798,7 +10850,6 @@ var SpokeService = class _SpokeService {
|
|
|
10798
10850
|
return InjectiveSpokeService.deposit(params, spokeProvider, hubProvider, raw);
|
|
10799
10851
|
}
|
|
10800
10852
|
if (spokeProvider instanceof IconSpokeProvider) {
|
|
10801
|
-
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10802
10853
|
return IconSpokeService.deposit(
|
|
10803
10854
|
params,
|
|
10804
10855
|
spokeProvider,
|
|
@@ -10825,7 +10876,6 @@ var SpokeService = class _SpokeService {
|
|
|
10825
10876
|
);
|
|
10826
10877
|
}
|
|
10827
10878
|
if (spokeProvider instanceof StellarSpokeProvider) {
|
|
10828
|
-
await _SpokeService.verifyDepositSimulation(params, spokeProvider, hubProvider, skipSimulation);
|
|
10829
10879
|
return StellarSpokeService.deposit(
|
|
10830
10880
|
params,
|
|
10831
10881
|
spokeProvider,
|
|
@@ -10999,19 +11049,19 @@ async function postRequest(payload, apiUrl) {
|
|
|
10999
11049
|
return response.json();
|
|
11000
11050
|
}
|
|
11001
11051
|
async function submitTransaction(payload, apiUrl) {
|
|
11002
|
-
|
|
11003
|
-
|
|
11052
|
+
invariant11__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11053
|
+
invariant11__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
11004
11054
|
return postRequest(payload, apiUrl);
|
|
11005
11055
|
}
|
|
11006
11056
|
async function getTransactionPackets(payload, apiUrl) {
|
|
11007
|
-
|
|
11008
|
-
|
|
11057
|
+
invariant11__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11058
|
+
invariant11__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
11009
11059
|
return postRequest(payload, apiUrl);
|
|
11010
11060
|
}
|
|
11011
11061
|
async function getPacket(payload, apiUrl) {
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11062
|
+
invariant11__default.default(payload.params.chain_id.length > 0, "Invalid input parameters. source_chain_id empty");
|
|
11063
|
+
invariant11__default.default(payload.params.tx_hash.length > 0, "Invalid input parameters. tx_hash empty");
|
|
11064
|
+
invariant11__default.default(payload.params.conn_sn.length > 0, "Invalid input parameters. conn_sn empty");
|
|
11015
11065
|
return postRequest(payload, apiUrl);
|
|
11016
11066
|
}
|
|
11017
11067
|
async function waitUntilIntentExecuted(payload) {
|
|
@@ -11142,11 +11192,11 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11142
11192
|
inputToken = hubProvider.chainConfig.wrappedNativeToken;
|
|
11143
11193
|
}
|
|
11144
11194
|
const outputToken = getHubAssetInfo(createIntentParams.dstChain, createIntentParams.outputToken)?.asset;
|
|
11145
|
-
|
|
11195
|
+
invariant11__default.default(
|
|
11146
11196
|
inputToken,
|
|
11147
11197
|
`hub asset not found for spoke chain token (intent.inputToken): ${createIntentParams.inputToken}`
|
|
11148
11198
|
);
|
|
11149
|
-
|
|
11199
|
+
invariant11__default.default(
|
|
11150
11200
|
outputToken,
|
|
11151
11201
|
`hub asset not found for spoke chain token (intent.outputToken): ${createIntentParams.outputToken}`
|
|
11152
11202
|
);
|
|
@@ -11178,7 +11228,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11178
11228
|
* @returns A tuple containing [encoded fee data, fee amount]. Fee amount will be 0n if no fee.
|
|
11179
11229
|
*/
|
|
11180
11230
|
static createIntentFeeData(fee, inputAmount) {
|
|
11181
|
-
|
|
11231
|
+
invariant11__default.default(inputAmount > 0n, "Input amount must be greater than 0");
|
|
11182
11232
|
if (!fee) {
|
|
11183
11233
|
return ["0x", 0n];
|
|
11184
11234
|
}
|
|
@@ -11186,7 +11236,7 @@ var EvmSolverService = class _EvmSolverService {
|
|
|
11186
11236
|
if (isPartnerFeeAmount(fee)) {
|
|
11187
11237
|
feeAmount = fee.amount;
|
|
11188
11238
|
} else if (isPartnerFeePercentage(fee)) {
|
|
11189
|
-
|
|
11239
|
+
invariant11__default.default(
|
|
11190
11240
|
fee.percentage >= 0 && fee.percentage <= FEE_PERCENTAGE_SCALE,
|
|
11191
11241
|
`Fee percentage must be between 0 and ${FEE_PERCENTAGE_SCALE}}`
|
|
11192
11242
|
);
|
|
@@ -11313,23 +11363,23 @@ var SolverApiService = class {
|
|
|
11313
11363
|
* }
|
|
11314
11364
|
*/
|
|
11315
11365
|
static async getQuote(payload, config) {
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11366
|
+
invariant11__default.default(payload.token_src.length > 0, "Empty token_src");
|
|
11367
|
+
invariant11__default.default(payload.token_src_blockchain_id.length > 0, "Empty token_src_blockchain_id");
|
|
11368
|
+
invariant11__default.default(payload.token_dst.length > 0, "Empty token_dst");
|
|
11369
|
+
invariant11__default.default(payload.token_dst_blockchain_id.length > 0, "Empty token_dst_blockchain_id");
|
|
11370
|
+
invariant11__default.default(payload.amount > 0n, "amount must be greater than 0");
|
|
11371
|
+
invariant11__default.default(
|
|
11322
11372
|
isValidOriginalAssetAddress(payload.token_src_blockchain_id, payload.token_src),
|
|
11323
11373
|
"unsupported token_src for src chain"
|
|
11324
11374
|
);
|
|
11325
|
-
|
|
11375
|
+
invariant11__default.default(
|
|
11326
11376
|
isValidOriginalAssetAddress(payload.token_dst_blockchain_id, payload.token_dst),
|
|
11327
11377
|
"unsupported token_dst for dst chain"
|
|
11328
11378
|
);
|
|
11329
11379
|
const tokenSrc = getHubAssetInfo(payload.token_src_blockchain_id, payload.token_src)?.asset;
|
|
11330
11380
|
const tokenDst = getHubAssetInfo(payload.token_dst_blockchain_id, payload.token_dst)?.asset;
|
|
11331
|
-
|
|
11332
|
-
|
|
11381
|
+
invariant11__default.default(tokenSrc, "hub asset not found for token_src");
|
|
11382
|
+
invariant11__default.default(tokenDst, "hub asset not found for token_dst");
|
|
11333
11383
|
try {
|
|
11334
11384
|
const response = await fetch(`${config.solverApiEndpoint}/quote`, {
|
|
11335
11385
|
method: "POST",
|
|
@@ -11424,7 +11474,7 @@ var SolverApiService = class {
|
|
|
11424
11474
|
}
|
|
11425
11475
|
}
|
|
11426
11476
|
static async getStatus(request, config) {
|
|
11427
|
-
|
|
11477
|
+
invariant11__default.default(request.intent_tx_hash.length > 0, "Empty intent_tx_hash");
|
|
11428
11478
|
try {
|
|
11429
11479
|
const response = await fetch(`${config.solverApiEndpoint}/status`, {
|
|
11430
11480
|
method: "POST",
|
|
@@ -11885,13 +11935,23 @@ var SolverService = class {
|
|
|
11885
11935
|
spokeProvider
|
|
11886
11936
|
}) {
|
|
11887
11937
|
try {
|
|
11888
|
-
if (spokeProvider instanceof EvmSpokeProvider
|
|
11938
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
11939
|
+
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11940
|
+
return await Erc20Service.isAllowanceValid(
|
|
11941
|
+
params.inputToken,
|
|
11942
|
+
params.inputAmount,
|
|
11943
|
+
walletAddress,
|
|
11944
|
+
spokeProvider.chainConfig.addresses.assetManager,
|
|
11945
|
+
spokeProvider
|
|
11946
|
+
);
|
|
11947
|
+
}
|
|
11948
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
11889
11949
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11890
11950
|
return await Erc20Service.isAllowanceValid(
|
|
11891
11951
|
params.inputToken,
|
|
11892
11952
|
params.inputAmount,
|
|
11893
11953
|
walletAddress,
|
|
11894
|
-
|
|
11954
|
+
getSolverConfig(types.SONIC_MAINNET_CHAIN_ID).intentsContract,
|
|
11895
11955
|
spokeProvider
|
|
11896
11956
|
);
|
|
11897
11957
|
}
|
|
@@ -11950,7 +12010,7 @@ var SolverService = class {
|
|
|
11950
12010
|
raw
|
|
11951
12011
|
}) {
|
|
11952
12012
|
try {
|
|
11953
|
-
if (spokeProvider instanceof EvmSpokeProvider
|
|
12013
|
+
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
11954
12014
|
const result = await Erc20Service.approve(
|
|
11955
12015
|
params.inputToken,
|
|
11956
12016
|
params.inputAmount,
|
|
@@ -11963,6 +12023,19 @@ var SolverService = class {
|
|
|
11963
12023
|
value: result
|
|
11964
12024
|
};
|
|
11965
12025
|
}
|
|
12026
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
12027
|
+
const result = await Erc20Service.approve(
|
|
12028
|
+
params.inputToken,
|
|
12029
|
+
params.inputAmount,
|
|
12030
|
+
getSolverConfig(types.SONIC_MAINNET_CHAIN_ID).intentsContract,
|
|
12031
|
+
spokeProvider,
|
|
12032
|
+
raw
|
|
12033
|
+
);
|
|
12034
|
+
return {
|
|
12035
|
+
ok: true,
|
|
12036
|
+
value: result
|
|
12037
|
+
};
|
|
12038
|
+
}
|
|
11966
12039
|
return {
|
|
11967
12040
|
ok: false,
|
|
11968
12041
|
error: new Error("Approve only supported for EVM spoke chains")
|
|
@@ -12022,49 +12095,70 @@ var SolverService = class {
|
|
|
12022
12095
|
fee = this.config.partnerFee,
|
|
12023
12096
|
raw
|
|
12024
12097
|
}) {
|
|
12025
|
-
|
|
12098
|
+
invariant11__default.default(
|
|
12026
12099
|
isValidOriginalAssetAddress(params.srcChain, params.inputToken),
|
|
12027
12100
|
`Unsupported spoke chain token (params.srcChain): ${params.srcChain}, params.inputToken): ${params.inputToken}`
|
|
12028
12101
|
);
|
|
12029
|
-
|
|
12102
|
+
invariant11__default.default(
|
|
12030
12103
|
isValidOriginalAssetAddress(params.dstChain, params.outputToken),
|
|
12031
12104
|
`Unsupported spoke chain token (params.dstChain): ${params.dstChain}, params.outputToken): ${params.outputToken}`
|
|
12032
12105
|
);
|
|
12033
|
-
|
|
12034
|
-
|
|
12106
|
+
invariant11__default.default(isValidSpokeChainId(params.srcChain), `Invalid spoke chain (params.srcChain): ${params.srcChain}`);
|
|
12107
|
+
invariant11__default.default(isValidSpokeChainId(params.dstChain), `Invalid spoke chain (params.dstChain): ${params.dstChain}`);
|
|
12035
12108
|
try {
|
|
12036
12109
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12037
|
-
|
|
12110
|
+
invariant11__default.default(
|
|
12038
12111
|
params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
|
|
12039
12112
|
"srcAddress must be the same as wallet address"
|
|
12040
12113
|
);
|
|
12041
12114
|
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12042
|
-
|
|
12043
|
-
|
|
12044
|
-
|
|
12045
|
-
|
|
12046
|
-
|
|
12047
|
-
|
|
12048
|
-
|
|
12049
|
-
|
|
12050
|
-
|
|
12051
|
-
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12056
|
-
|
|
12057
|
-
|
|
12058
|
-
|
|
12059
|
-
}
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
12115
|
+
if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
12116
|
+
const [txResult, intent, feeAmount, data] = await SonicSpokeService.createSwapIntent(
|
|
12117
|
+
params,
|
|
12118
|
+
creatorHubWalletAddress,
|
|
12119
|
+
this.config,
|
|
12120
|
+
fee,
|
|
12121
|
+
spokeProvider,
|
|
12122
|
+
this.hubProvider,
|
|
12123
|
+
raw
|
|
12124
|
+
);
|
|
12125
|
+
return {
|
|
12126
|
+
ok: true,
|
|
12127
|
+
value: [
|
|
12128
|
+
txResult,
|
|
12129
|
+
{ ...intent, feeAmount },
|
|
12130
|
+
data
|
|
12131
|
+
]
|
|
12132
|
+
};
|
|
12133
|
+
}
|
|
12134
|
+
{
|
|
12135
|
+
const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
|
|
12136
|
+
{
|
|
12137
|
+
...params,
|
|
12138
|
+
srcAddress: walletAddress
|
|
12139
|
+
},
|
|
12140
|
+
creatorHubWalletAddress,
|
|
12141
|
+
this.config,
|
|
12142
|
+
fee,
|
|
12143
|
+
this.hubProvider
|
|
12144
|
+
);
|
|
12145
|
+
const txResult = await SpokeService.deposit(
|
|
12146
|
+
{
|
|
12147
|
+
from: walletAddress,
|
|
12148
|
+
to: creatorHubWalletAddress,
|
|
12149
|
+
token: params.inputToken,
|
|
12150
|
+
amount: params.inputAmount,
|
|
12151
|
+
data
|
|
12152
|
+
},
|
|
12153
|
+
spokeProvider,
|
|
12154
|
+
this.hubProvider,
|
|
12155
|
+
raw
|
|
12156
|
+
);
|
|
12157
|
+
return {
|
|
12158
|
+
ok: true,
|
|
12159
|
+
value: [txResult, { ...intent, feeAmount }, data]
|
|
12160
|
+
};
|
|
12161
|
+
}
|
|
12068
12162
|
} catch (error) {
|
|
12069
12163
|
return {
|
|
12070
12164
|
ok: false,
|
|
@@ -12087,8 +12181,8 @@ var SolverService = class {
|
|
|
12087
12181
|
*/
|
|
12088
12182
|
async cancelIntent(intent, spokeProvider, raw) {
|
|
12089
12183
|
try {
|
|
12090
|
-
|
|
12091
|
-
|
|
12184
|
+
invariant11__default.default(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
12185
|
+
invariant11__default.default(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
12092
12186
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
12093
12187
|
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
12094
12188
|
const calls = [];
|
|
@@ -12600,7 +12694,7 @@ var IcxMigrationService = class {
|
|
|
12600
12694
|
migrateData(params) {
|
|
12601
12695
|
const calls = [];
|
|
12602
12696
|
const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, params.address);
|
|
12603
|
-
|
|
12697
|
+
invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.address}`);
|
|
12604
12698
|
calls.push(
|
|
12605
12699
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.icxMigration, params.amount)
|
|
12606
12700
|
);
|
|
@@ -12616,7 +12710,7 @@ var IcxMigrationService = class {
|
|
|
12616
12710
|
revertMigration(params) {
|
|
12617
12711
|
const calls = [];
|
|
12618
12712
|
const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, params.wICX);
|
|
12619
|
-
|
|
12713
|
+
invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${params.wICX}`);
|
|
12620
12714
|
calls.push(
|
|
12621
12715
|
Erc20Service.encodeApprove(
|
|
12622
12716
|
this.hubProvider.chainConfig.addresses.sodaToken,
|
|
@@ -12712,9 +12806,9 @@ var MigrationService = class {
|
|
|
12712
12806
|
async isAllowanceValid(params, action, spokeProvider) {
|
|
12713
12807
|
try {
|
|
12714
12808
|
if (action === "migrate") {
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
|
|
12809
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
12810
|
+
invariant11__default.default(viem.isAddress(params.to) || isIconAddress(params.to), "To address is required");
|
|
12811
|
+
invariant11__default.default(
|
|
12718
12812
|
isIcxMigrateParams(params) || isBalnMigrateParams(params) || isUnifiedBnUSDMigrateParams(params),
|
|
12719
12813
|
"Invalid params"
|
|
12720
12814
|
);
|
|
@@ -12740,9 +12834,9 @@ var MigrationService = class {
|
|
|
12740
12834
|
};
|
|
12741
12835
|
}
|
|
12742
12836
|
if (action === "revert") {
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12837
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
12838
|
+
invariant11__default.default(params.to.length > 0, "To address is required");
|
|
12839
|
+
invariant11__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12746
12840
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12747
12841
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12748
12842
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -12798,9 +12892,9 @@ var MigrationService = class {
|
|
|
12798
12892
|
async approve(params, action, spokeProvider, raw) {
|
|
12799
12893
|
try {
|
|
12800
12894
|
if (action === "migrate") {
|
|
12801
|
-
|
|
12802
|
-
|
|
12803
|
-
|
|
12895
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
12896
|
+
invariant11__default.default(params.to.length > 0, "To address is required");
|
|
12897
|
+
invariant11__default.default(isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12804
12898
|
if (isUnifiedBnUSDMigrateParams(params) && spokeProvider.chainConfig.chain.type === "EVM") {
|
|
12805
12899
|
const evmSpokeProvider = spokeProvider;
|
|
12806
12900
|
const result = await Erc20Service.approve(
|
|
@@ -12821,9 +12915,9 @@ var MigrationService = class {
|
|
|
12821
12915
|
};
|
|
12822
12916
|
}
|
|
12823
12917
|
if (action === "revert") {
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12918
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
12919
|
+
invariant11__default.default(params.to.length > 0, "To address is required");
|
|
12920
|
+
invariant11__default.default(isIcxCreateRevertMigrationParams(params) || isUnifiedBnUSDMigrateParams(params), "Invalid params");
|
|
12827
12921
|
if (spokeProvider instanceof SonicSpokeProvider && isIcxCreateRevertMigrationParams(params)) {
|
|
12828
12922
|
const wallet = await spokeProvider.walletProvider.getWalletAddress();
|
|
12829
12923
|
const userRouter = await SonicSpokeService.getUserRouter(wallet, spokeProvider);
|
|
@@ -13235,13 +13329,13 @@ var MigrationService = class {
|
|
|
13235
13329
|
async createMigratebnUSDIntent(params, spokeProvider, unchecked = false, raw) {
|
|
13236
13330
|
try {
|
|
13237
13331
|
if (!unchecked) {
|
|
13238
|
-
|
|
13239
|
-
|
|
13240
|
-
|
|
13241
|
-
|
|
13242
|
-
|
|
13243
|
-
|
|
13244
|
-
|
|
13332
|
+
invariant11__default.default(isValidSpokeChainId(params.srcChainId), "Invalid spoke source chain ID");
|
|
13333
|
+
invariant11__default.default(isValidSpokeChainId(params.dstChainId), "Invalid spoke destination chain ID");
|
|
13334
|
+
invariant11__default.default(params.srcbnUSD.length > 0, "Legacy bnUSD token address is required");
|
|
13335
|
+
invariant11__default.default(params.dstbnUSD.length > 0, "New bnUSD token address is required");
|
|
13336
|
+
invariant11__default.default(params.amount > 0, "Amount must be greater than 0");
|
|
13337
|
+
invariant11__default.default(params.to.length > 0, "Recipient address is required");
|
|
13338
|
+
invariant11__default.default(
|
|
13245
13339
|
!(isLegacybnUSDToken(params.srcbnUSD) && isLegacybnUSDToken(params.dstbnUSD)),
|
|
13246
13340
|
"srcbnUSD and dstbnUSD cannot both be legacy bnUSD tokens"
|
|
13247
13341
|
);
|
|
@@ -13249,11 +13343,11 @@ var MigrationService = class {
|
|
|
13249
13343
|
let migrationData;
|
|
13250
13344
|
if (isLegacybnUSDToken(params.srcbnUSD)) {
|
|
13251
13345
|
if (!unchecked) {
|
|
13252
|
-
|
|
13346
|
+
invariant11__default.default(
|
|
13253
13347
|
isLegacybnUSDChainId(params.srcChainId),
|
|
13254
13348
|
"srcChainId must be a legacy bnUSD chain (icon, sui, stellar) if srcbnUSD is a legacy bnUSD token"
|
|
13255
13349
|
);
|
|
13256
|
-
|
|
13350
|
+
invariant11__default.default(
|
|
13257
13351
|
isNewbnUSDChainId(params.dstChainId),
|
|
13258
13352
|
"dstChainId must be a new bnUSD chain (all spoke chains besides Icon) if dstbnUSD is a legacy bnUSD token"
|
|
13259
13353
|
);
|
|
@@ -13268,15 +13362,15 @@ var MigrationService = class {
|
|
|
13268
13362
|
});
|
|
13269
13363
|
} else if (isLegacybnUSDToken(params.dstbnUSD)) {
|
|
13270
13364
|
if (!unchecked) {
|
|
13271
|
-
|
|
13365
|
+
invariant11__default.default(
|
|
13272
13366
|
isLegacybnUSDChainId(params.dstChainId),
|
|
13273
13367
|
"dstChainId must be a legacy bnUSD chain (sui, stellar, icon) if dstbnUSD is a legacy bnUSD token"
|
|
13274
13368
|
);
|
|
13275
|
-
|
|
13369
|
+
invariant11__default.default(
|
|
13276
13370
|
isNewbnUSDToken(params.srcbnUSD),
|
|
13277
13371
|
"srcbnUSD must be a new bnUSD token if dstbnUSD is a legacy bnUSD token"
|
|
13278
13372
|
);
|
|
13279
|
-
|
|
13373
|
+
invariant11__default.default(
|
|
13280
13374
|
isNewbnUSDChainId(params.srcChainId),
|
|
13281
13375
|
"srcChainId must be a new bnUSD chain (all spoke chains besides Icon) if srcbnUSD is a new bnUSD token"
|
|
13282
13376
|
);
|
|
@@ -13349,13 +13443,13 @@ var MigrationService = class {
|
|
|
13349
13443
|
*/
|
|
13350
13444
|
async createMigrateIcxToSodaIntent(params, spokeProvider, raw) {
|
|
13351
13445
|
try {
|
|
13352
|
-
|
|
13353
|
-
|
|
13354
|
-
|
|
13446
|
+
invariant11__default.default(params.amount > 0, "Amount must be greater than 0");
|
|
13447
|
+
invariant11__default.default(viem.isAddress(params.to), "Recipient address is required");
|
|
13448
|
+
invariant11__default.default(
|
|
13355
13449
|
params.address.toLowerCase() === spokeProvider.chainConfig.addresses.wICX.toLowerCase() || params.address.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase(),
|
|
13356
13450
|
"Token must be wICX or native ICX token"
|
|
13357
13451
|
);
|
|
13358
|
-
|
|
13452
|
+
invariant11__default.default(spokeProvider instanceof IconSpokeProvider, "Spoke provider must be an instance of IconSpokeProvider");
|
|
13359
13453
|
const availableAmount = await this.icxMigration.getAvailableAmount();
|
|
13360
13454
|
if (availableAmount < params.amount) {
|
|
13361
13455
|
throw new Error(
|
|
@@ -13467,7 +13561,7 @@ var BnUSDMigrationService = class {
|
|
|
13467
13561
|
migrateData(params) {
|
|
13468
13562
|
const calls = [];
|
|
13469
13563
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.legacybnUSD);
|
|
13470
|
-
|
|
13564
|
+
invariant11__default.default(assetConfig, `hub asset not found for legacy bnUSD token: ${params.legacybnUSD}`);
|
|
13471
13565
|
const bnUSDVault = getMoneyMarketConfig(types.SONIC_MAINNET_CHAIN_ID).bnUSDVault;
|
|
13472
13566
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, assetConfig.vault, params.amount));
|
|
13473
13567
|
calls.push(EvmVaultTokenService.encodeDeposit(assetConfig.vault, assetConfig.asset, params.amount));
|
|
@@ -13479,7 +13573,7 @@ var BnUSDMigrationService = class {
|
|
|
13479
13573
|
return encodeContractCalls(calls);
|
|
13480
13574
|
}
|
|
13481
13575
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.newbnUSD);
|
|
13482
|
-
|
|
13576
|
+
invariant11__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13483
13577
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.asset, translatedAmount));
|
|
13484
13578
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
13485
13579
|
dstAssetConfig.decimal,
|
|
@@ -13512,14 +13606,14 @@ var BnUSDMigrationService = class {
|
|
|
13512
13606
|
let decimals = 18;
|
|
13513
13607
|
if (params.newbnUSD.toLowerCase() !== bnUSDVault.toLowerCase()) {
|
|
13514
13608
|
const assetConfig = getHubAssetInfo(params.srcChainId, params.newbnUSD);
|
|
13515
|
-
|
|
13609
|
+
invariant11__default.default(assetConfig, `hub asset not found for new bnUSD token: ${params.newbnUSD}`);
|
|
13516
13610
|
decimals = assetConfig.decimal;
|
|
13517
13611
|
calls.push(Erc20Service.encodeApprove(assetConfig.asset, bnUSDVault, params.amount));
|
|
13518
13612
|
calls.push(EvmVaultTokenService.encodeDeposit(bnUSDVault, assetConfig.asset, params.amount));
|
|
13519
13613
|
}
|
|
13520
13614
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(decimals, params.amount);
|
|
13521
13615
|
const dstAssetConfig = getHubAssetInfo(params.dstChainId, params.legacybnUSD);
|
|
13522
|
-
|
|
13616
|
+
invariant11__default.default(dstAssetConfig, `hub asset not found for new bnUSD token: ${params.legacybnUSD}`);
|
|
13523
13617
|
calls.push(EvmVaultTokenService.encodeWithdraw(bnUSDVault, dstAssetConfig.vault, translatedAmount));
|
|
13524
13618
|
calls.push(EvmVaultTokenService.encodeWithdraw(dstAssetConfig.vault, dstAssetConfig.asset, translatedAmount));
|
|
13525
13619
|
const translatedAmountOut = EvmVaultTokenService.translateOutgoingDecimals(
|
|
@@ -13602,7 +13696,7 @@ var BalnSwapService = class {
|
|
|
13602
13696
|
*/
|
|
13603
13697
|
async swapData(balnToken, params) {
|
|
13604
13698
|
const assetConfig = getHubAssetInfo(types.ICON_MAINNET_CHAIN_ID, balnToken);
|
|
13605
|
-
|
|
13699
|
+
invariant11__default.default(assetConfig, `hub asset not found for baln token: ${balnToken}`);
|
|
13606
13700
|
const calls = [];
|
|
13607
13701
|
calls.push(
|
|
13608
13702
|
Erc20Service.encodeApprove(assetConfig.asset, this.hubProvider.chainConfig.addresses.balnSwap, params.amount)
|
|
@@ -15366,9 +15460,9 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15366
15460
|
*/
|
|
15367
15461
|
async isAllowanceValid(params, spokeProvider) {
|
|
15368
15462
|
try {
|
|
15369
|
-
|
|
15370
|
-
|
|
15371
|
-
|
|
15463
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
15464
|
+
invariant11__default.default(params.token.length > 0, "Token is required");
|
|
15465
|
+
invariant11__default.default(
|
|
15372
15466
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15373
15467
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15374
15468
|
);
|
|
@@ -15463,19 +15557,19 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15463
15557
|
*/
|
|
15464
15558
|
async approve(params, spokeProvider, raw) {
|
|
15465
15559
|
try {
|
|
15466
|
-
|
|
15467
|
-
|
|
15468
|
-
|
|
15560
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
15561
|
+
invariant11__default.default(params.token.length > 0, "Token is required");
|
|
15562
|
+
invariant11__default.default(
|
|
15469
15563
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15470
15564
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15471
15565
|
);
|
|
15472
15566
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
15473
15567
|
if (spokeProvider instanceof EvmSpokeProvider) {
|
|
15474
|
-
|
|
15568
|
+
invariant11__default.default(
|
|
15475
15569
|
params.action === "supply" || params.action === "repay",
|
|
15476
15570
|
"Invalid action (only supply and repay are supported on evm)"
|
|
15477
15571
|
);
|
|
15478
|
-
|
|
15572
|
+
invariant11__default.default(viem.isAddress(params.token), "Invalid token address");
|
|
15479
15573
|
const result = await Erc20Service.approve(
|
|
15480
15574
|
params.token,
|
|
15481
15575
|
params.amount,
|
|
@@ -15489,11 +15583,11 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15489
15583
|
};
|
|
15490
15584
|
}
|
|
15491
15585
|
if (spokeProvider instanceof SonicSpokeProvider && spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
15492
|
-
|
|
15586
|
+
invariant11__default.default(
|
|
15493
15587
|
params.action === "withdraw" || params.action === "borrow" || params.action === "supply" || params.action === "repay",
|
|
15494
15588
|
"Invalid action (only withdraw, borrow, supply and repay are supported on sonic)"
|
|
15495
15589
|
);
|
|
15496
|
-
|
|
15590
|
+
invariant11__default.default(viem.isAddress(params.token), "Invalid token address");
|
|
15497
15591
|
if (params.action === "withdraw") {
|
|
15498
15592
|
const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
|
|
15499
15593
|
params.token,
|
|
@@ -15665,10 +15759,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15665
15759
|
*/
|
|
15666
15760
|
async createSupplyIntent(params, spokeProvider, raw) {
|
|
15667
15761
|
try {
|
|
15668
|
-
|
|
15669
|
-
|
|
15670
|
-
|
|
15671
|
-
|
|
15762
|
+
invariant11__default.default(params.action === "supply", "Invalid action");
|
|
15763
|
+
invariant11__default.default(params.token.length > 0, "Token is required");
|
|
15764
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
15765
|
+
invariant11__default.default(
|
|
15672
15766
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15673
15767
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15674
15768
|
);
|
|
@@ -15820,10 +15914,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15820
15914
|
* }
|
|
15821
15915
|
*/
|
|
15822
15916
|
async createBorrowIntent(params, spokeProvider, raw) {
|
|
15823
|
-
|
|
15824
|
-
|
|
15825
|
-
|
|
15826
|
-
|
|
15917
|
+
invariant11__default.default(params.action === "borrow", "Invalid action");
|
|
15918
|
+
invariant11__default.default(params.token.length > 0, "Token is required");
|
|
15919
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
15920
|
+
invariant11__default.default(
|
|
15827
15921
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15828
15922
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15829
15923
|
);
|
|
@@ -15955,10 +16049,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15955
16049
|
* }
|
|
15956
16050
|
*/
|
|
15957
16051
|
async createWithdrawIntent(params, spokeProvider, raw) {
|
|
15958
|
-
|
|
15959
|
-
|
|
15960
|
-
|
|
15961
|
-
|
|
16052
|
+
invariant11__default.default(params.action === "withdraw", "Invalid action");
|
|
16053
|
+
invariant11__default.default(params.token.length > 0, "Token is required");
|
|
16054
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
16055
|
+
invariant11__default.default(
|
|
15962
16056
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
15963
16057
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
15964
16058
|
);
|
|
@@ -16110,10 +16204,10 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16110
16204
|
* }
|
|
16111
16205
|
*/
|
|
16112
16206
|
async createRepayIntent(params, spokeProvider, raw) {
|
|
16113
|
-
|
|
16114
|
-
|
|
16115
|
-
|
|
16116
|
-
|
|
16207
|
+
invariant11__default.default(params.action === "repay", "Invalid action");
|
|
16208
|
+
invariant11__default.default(params.token.length > 0, "Token is required");
|
|
16209
|
+
invariant11__default.default(params.amount > 0n, "Amount must be greater than 0");
|
|
16210
|
+
invariant11__default.default(
|
|
16117
16211
|
isMoneyMarketSupportedToken(spokeProvider.chainConfig.chain.id, params.token),
|
|
16118
16212
|
`Unsupported spoke chain (${spokeProvider.chainConfig.chain.id}) token: ${params.token}`
|
|
16119
16213
|
);
|
|
@@ -16156,7 +16250,7 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16156
16250
|
buildSupplyData(token, to, amount, spokeChainId) {
|
|
16157
16251
|
const calls = [];
|
|
16158
16252
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
16159
|
-
|
|
16253
|
+
invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
16160
16254
|
let assetAddress = assetConfig.asset;
|
|
16161
16255
|
const vaultAddress = assetConfig.vault;
|
|
16162
16256
|
const lendingPool = this.config.lendingPool;
|
|
@@ -16187,13 +16281,13 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
16187
16281
|
* @returns {Hex} The transaction data.
|
|
16188
16282
|
*/
|
|
16189
16283
|
buildBorrowData(from, to, token, amount, spokeChainId) {
|
|
16190
|
-
|
|
16191
|
-
|
|
16284
|
+
invariant11__default.default(isValidSpokeChainId(spokeChainId), `Invalid spokeChainId: ${spokeChainId}`);
|
|
16285
|
+
invariant11__default.default(
|
|
16192
16286
|
isValidOriginalAssetAddress(spokeChainId, token),
|
|
16193
16287
|
`Unsupported spoke chain (${spokeChainId}) token: ${token}`
|
|
16194
16288
|
);
|
|
16195
16289
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
16196
|
-
|
|
16290
|
+
invariant11__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
16197
16291
|
let assetAddress = assetConfig.asset;
|
|
16198
16292
|
const vaultAddress = assetConfig.vault;
|
|
16199
16293
|
const bnUSDVault = this.config.bnUSDVault;
|