@sodax/sdk 0.0.1-rc.22 → 0.0.1-rc.24
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 +79 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +79 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6186,6 +6186,17 @@ function calculateFeeAmount(inputAmount, fee) {
|
|
|
6186
6186
|
}
|
|
6187
6187
|
return feeAmount;
|
|
6188
6188
|
}
|
|
6189
|
+
function adjustAmountByFee(amount, fee, quoteType) {
|
|
6190
|
+
invariant10__default.default(amount > 0n, "Amount must be greater than 0");
|
|
6191
|
+
invariant10__default.default(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
|
|
6192
|
+
if (quoteType === "exact_input") {
|
|
6193
|
+
return amount - calculateFeeAmount(amount, fee);
|
|
6194
|
+
}
|
|
6195
|
+
if (quoteType === "exact_output") {
|
|
6196
|
+
return amount + calculateFeeAmount(amount, fee);
|
|
6197
|
+
}
|
|
6198
|
+
throw new Error("Invalid quote type");
|
|
6199
|
+
}
|
|
6189
6200
|
function BigIntToHex(value) {
|
|
6190
6201
|
return `0x${value.toString(16)}`;
|
|
6191
6202
|
}
|
|
@@ -7179,7 +7190,7 @@ var getAllLegacybnUSDTokens = () => {
|
|
|
7179
7190
|
var hubAssets = {
|
|
7180
7191
|
[types.SONIC_MAINNET_CHAIN_ID]: {
|
|
7181
7192
|
[spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].nativeToken]: {
|
|
7182
|
-
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.
|
|
7193
|
+
asset: spokeChainConfig[types.SONIC_MAINNET_CHAIN_ID].supportedTokens.S.address,
|
|
7183
7194
|
decimal: 18,
|
|
7184
7195
|
symbol: "S",
|
|
7185
7196
|
name: "Sonic",
|
|
@@ -10061,7 +10072,7 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10061
10072
|
params.data
|
|
10062
10073
|
)[0]
|
|
10063
10074
|
);
|
|
10064
|
-
if (params.token === spokeProvider.chainConfig.nativeToken) {
|
|
10075
|
+
if (params.token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
10065
10076
|
const wrapCall = {
|
|
10066
10077
|
address: spokeProvider.chainConfig.addresses.wrappedSonic,
|
|
10067
10078
|
value: params.amount,
|
|
@@ -10095,7 +10106,7 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10095
10106
|
from: params.from,
|
|
10096
10107
|
to: spokeProvider.chainConfig.addresses.walletRouter,
|
|
10097
10108
|
data: txData,
|
|
10098
|
-
value: params.token === spokeProvider.chainConfig.nativeToken ? params.amount : 0n
|
|
10109
|
+
value: params.token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase() ? params.amount : 0n
|
|
10099
10110
|
};
|
|
10100
10111
|
if (raw) {
|
|
10101
10112
|
return rawTx;
|
|
@@ -10310,12 +10321,16 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10310
10321
|
}
|
|
10311
10322
|
return spokeProvider.walletProvider.sendTransaction(rawTx);
|
|
10312
10323
|
}
|
|
10313
|
-
static async buildWithdrawData(from, withdrawInfo, amount, spokeProvider, moneyMarketService) {
|
|
10314
|
-
const userRouter = await _SonicSpokeService.getUserRouter(from, spokeProvider);
|
|
10324
|
+
static async buildWithdrawData(from, withdrawInfo, amount, spokeProvider, moneyMarketService, userRouterAddress) {
|
|
10325
|
+
const userRouter = userRouterAddress ?? await _SonicSpokeService.getUserRouter(from, spokeProvider);
|
|
10326
|
+
let token = withdrawInfo.token;
|
|
10327
|
+
if (withdrawInfo.token.toLowerCase() === spokeProvider.chainConfig.nativeToken.toLowerCase()) {
|
|
10328
|
+
token = spokeProvider.chainConfig.addresses.wrappedSonic;
|
|
10329
|
+
}
|
|
10315
10330
|
const withdrawCall = moneyMarketService.buildWithdrawData(
|
|
10316
10331
|
userRouter,
|
|
10317
10332
|
from,
|
|
10318
|
-
|
|
10333
|
+
token,
|
|
10319
10334
|
amount,
|
|
10320
10335
|
spokeProvider.chainConfig.chain.id
|
|
10321
10336
|
);
|
|
@@ -10333,17 +10348,6 @@ var SonicSpokeService = class _SonicSpokeService {
|
|
|
10333
10348
|
],
|
|
10334
10349
|
withdrawCall
|
|
10335
10350
|
)[0];
|
|
10336
|
-
const transferFromCall = Erc20Service.encodeTransferFrom(
|
|
10337
|
-
withdrawInfo.aTokenAddress,
|
|
10338
|
-
from,
|
|
10339
|
-
userRouter,
|
|
10340
|
-
withdrawInfo.aTokenAmount
|
|
10341
|
-
);
|
|
10342
|
-
calls.unshift({
|
|
10343
|
-
address: transferFromCall.address,
|
|
10344
|
-
value: transferFromCall.value,
|
|
10345
|
-
data: transferFromCall.data
|
|
10346
|
-
});
|
|
10347
10351
|
return encodeContractCalls(calls);
|
|
10348
10352
|
}
|
|
10349
10353
|
};
|
|
@@ -11201,7 +11205,7 @@ var SolverService = class {
|
|
|
11201
11205
|
async getQuote(payload) {
|
|
11202
11206
|
payload = {
|
|
11203
11207
|
...payload,
|
|
11204
|
-
amount: payload.amount
|
|
11208
|
+
amount: adjustAmountByFee(payload.amount, this.config.partnerFee, payload.quote_type)
|
|
11205
11209
|
};
|
|
11206
11210
|
return SolverApiService.getQuote(payload, this.config);
|
|
11207
11211
|
}
|
|
@@ -11711,8 +11715,7 @@ var SolverService = class {
|
|
|
11711
11715
|
params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
|
|
11712
11716
|
"srcAddress must be the same as wallet address"
|
|
11713
11717
|
);
|
|
11714
|
-
const
|
|
11715
|
-
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
11718
|
+
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
11716
11719
|
const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
|
|
11717
11720
|
{
|
|
11718
11721
|
...params,
|
|
@@ -11763,8 +11766,7 @@ var SolverService = class {
|
|
|
11763
11766
|
invariant10__default.default(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
|
|
11764
11767
|
invariant10__default.default(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
|
|
11765
11768
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
11766
|
-
const
|
|
11767
|
-
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
11769
|
+
const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
|
|
11768
11770
|
const calls = [];
|
|
11769
11771
|
const intentsContract = this.config.intentsContract;
|
|
11770
11772
|
calls.push(EvmSolverService.encodeCancelIntent(intent, intentsContract));
|
|
@@ -13851,7 +13853,7 @@ function calculateAllUserIncentives({
|
|
|
13851
13853
|
(reserve2) => reserve2.underlyingAsset === userIncentive.underlyingAsset
|
|
13852
13854
|
);
|
|
13853
13855
|
const userReserve = userReserves.find(
|
|
13854
|
-
(userReserve2) => userReserve2.reserve.underlyingAsset === userIncentive.underlyingAsset
|
|
13856
|
+
(userReserve2) => userReserve2.reserve.underlyingAsset.toLowerCase() === userIncentive.underlyingAsset.toLowerCase()
|
|
13855
13857
|
);
|
|
13856
13858
|
if (reserve) {
|
|
13857
13859
|
const reserveRewards = calculateUserReserveIncentives({
|
|
@@ -14866,7 +14868,11 @@ var MoneyMarketDataService = class {
|
|
|
14866
14868
|
*/
|
|
14867
14869
|
async getUserReservesData(spokeProvider) {
|
|
14868
14870
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
14869
|
-
const hubWalletAddress =
|
|
14871
|
+
const hubWalletAddress = await WalletAbstractionService.getUserHubWalletAddress(
|
|
14872
|
+
walletAddress,
|
|
14873
|
+
spokeProvider,
|
|
14874
|
+
this.hubProvider
|
|
14875
|
+
);
|
|
14870
14876
|
return this.uiPoolDataProviderService.getUserReservesData(hubWalletAddress);
|
|
14871
14877
|
}
|
|
14872
14878
|
/**
|
|
@@ -14897,7 +14903,11 @@ var MoneyMarketDataService = class {
|
|
|
14897
14903
|
*/
|
|
14898
14904
|
async getUserReservesHumanized(spokeProvider) {
|
|
14899
14905
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
14900
|
-
const hubWalletAddress =
|
|
14906
|
+
const hubWalletAddress = await WalletAbstractionService.getUserHubWalletAddress(
|
|
14907
|
+
walletAddress,
|
|
14908
|
+
spokeProvider,
|
|
14909
|
+
this.hubProvider
|
|
14910
|
+
);
|
|
14901
14911
|
return this.uiPoolDataProviderService.getUserReservesHumanized(hubWalletAddress);
|
|
14902
14912
|
}
|
|
14903
14913
|
/**
|
|
@@ -15635,13 +15645,31 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15635
15645
|
spokeProvider,
|
|
15636
15646
|
this.hubProvider
|
|
15637
15647
|
);
|
|
15638
|
-
|
|
15639
|
-
|
|
15640
|
-
|
|
15641
|
-
|
|
15642
|
-
|
|
15643
|
-
|
|
15644
|
-
|
|
15648
|
+
let data;
|
|
15649
|
+
if (spokeProvider instanceof SonicSpokeProvider) {
|
|
15650
|
+
const withdrawInfo = await SonicSpokeService.getWithdrawInfo(
|
|
15651
|
+
params.token,
|
|
15652
|
+
params.amount,
|
|
15653
|
+
spokeProvider,
|
|
15654
|
+
this.data
|
|
15655
|
+
);
|
|
15656
|
+
data = await SonicSpokeService.buildWithdrawData(
|
|
15657
|
+
walletAddress,
|
|
15658
|
+
withdrawInfo,
|
|
15659
|
+
params.amount,
|
|
15660
|
+
spokeProvider,
|
|
15661
|
+
this,
|
|
15662
|
+
hubWallet
|
|
15663
|
+
);
|
|
15664
|
+
} else {
|
|
15665
|
+
data = this.buildWithdrawData(
|
|
15666
|
+
hubWallet,
|
|
15667
|
+
encodedAddress,
|
|
15668
|
+
params.token,
|
|
15669
|
+
params.amount,
|
|
15670
|
+
spokeProvider.chainConfig.chain.id
|
|
15671
|
+
);
|
|
15672
|
+
}
|
|
15645
15673
|
const txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
15646
15674
|
return {
|
|
15647
15675
|
ok: true,
|
|
@@ -15805,9 +15833,14 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15805
15833
|
const calls = [];
|
|
15806
15834
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
15807
15835
|
invariant10__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
15808
|
-
|
|
15836
|
+
let assetAddress = assetConfig.asset;
|
|
15809
15837
|
const vaultAddress = assetConfig.vault;
|
|
15810
15838
|
const lendingPool = this.config.lendingPool;
|
|
15839
|
+
if (spokeChainId === this.hubProvider.chainConfig.chain.id) {
|
|
15840
|
+
if (token.toLowerCase() === spokeChainConfig[this.hubProvider.chainConfig.chain.id].nativeToken.toLowerCase()) {
|
|
15841
|
+
assetAddress = spokeChainConfig[this.hubProvider.chainConfig.chain.id].supportedTokens.wS.address;
|
|
15842
|
+
}
|
|
15843
|
+
}
|
|
15811
15844
|
calls.push(Erc20Service.encodeApprove(assetAddress, vaultAddress, amount));
|
|
15812
15845
|
calls.push(EvmVaultTokenService.encodeDeposit(vaultAddress, assetAddress, amount));
|
|
15813
15846
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(assetConfig.decimal, amount);
|
|
@@ -15837,10 +15870,15 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15837
15870
|
);
|
|
15838
15871
|
const assetConfig = getHubAssetInfo(spokeChainId, token);
|
|
15839
15872
|
invariant10__default.default(assetConfig, `hub asset not found for spoke chain token (token): ${token}`);
|
|
15840
|
-
|
|
15873
|
+
let assetAddress = assetConfig.asset;
|
|
15841
15874
|
const vaultAddress = assetConfig.vault;
|
|
15842
15875
|
const bnUSDVault = this.config.bnUSDVault;
|
|
15843
15876
|
const bnUSD = this.config.bnUSD;
|
|
15877
|
+
if (spokeChainId === this.hubProvider.chainConfig.chain.id) {
|
|
15878
|
+
if (token.toLowerCase() === spokeChainConfig[this.hubProvider.chainConfig.chain.id].nativeToken.toLowerCase()) {
|
|
15879
|
+
assetAddress = spokeChainConfig[this.hubProvider.chainConfig.chain.id].supportedTokens.wS.address;
|
|
15880
|
+
}
|
|
15881
|
+
}
|
|
15844
15882
|
const feeAmount = calculateFeeAmount(amount, this.config.partnerFee);
|
|
15845
15883
|
const calls = [];
|
|
15846
15884
|
if (bnUSDVault && bnUSD && bnUSDVault.toLowerCase() === vaultAddress.toLowerCase()) {
|
|
@@ -15961,10 +15999,15 @@ var MoneyMarketService = class _MoneyMarketService {
|
|
|
15961
15999
|
if (!assetConfig) {
|
|
15962
16000
|
throw new Error("[buildRepayData] Hub asset not found");
|
|
15963
16001
|
}
|
|
15964
|
-
|
|
16002
|
+
let assetAddress = assetConfig.asset;
|
|
15965
16003
|
const vaultAddress = assetConfig.vault;
|
|
15966
16004
|
const bnUSDVault = this.config.bnUSDVault;
|
|
15967
16005
|
const bnUSD = this.config.bnUSD;
|
|
16006
|
+
if (spokeChainId === this.hubProvider.chainConfig.chain.id) {
|
|
16007
|
+
if (token.toLowerCase() === spokeChainConfig[this.hubProvider.chainConfig.chain.id].nativeToken.toLowerCase()) {
|
|
16008
|
+
assetAddress = spokeChainConfig[this.hubProvider.chainConfig.chain.id].supportedTokens.wS.address;
|
|
16009
|
+
}
|
|
16010
|
+
}
|
|
15968
16011
|
calls.push(Erc20Service.encodeApprove(assetAddress, vaultAddress, amount));
|
|
15969
16012
|
calls.push(EvmVaultTokenService.encodeDeposit(vaultAddress, assetAddress, amount));
|
|
15970
16013
|
const translatedAmount = EvmVaultTokenService.translateIncomingDecimals(assetConfig.decimal, amount);
|
|
@@ -16212,6 +16255,7 @@ exports.WAD = WAD;
|
|
|
16212
16255
|
exports.WAD_RAY_RATIO = WAD_RAY_RATIO;
|
|
16213
16256
|
exports.WEI_DECIMALS = WEI_DECIMALS;
|
|
16214
16257
|
exports.WalletAbstractionService = WalletAbstractionService;
|
|
16258
|
+
exports.adjustAmountByFee = adjustAmountByFee;
|
|
16215
16259
|
exports.assetManagerAbi = assetManagerAbi;
|
|
16216
16260
|
exports.balnSwapAbi = balnSwapAbi;
|
|
16217
16261
|
exports.binomialApproximatedRayPow = binomialApproximatedRayPow;
|