@sodax/sdk 1.2.1-beta → 1.2.3-beta
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 +46 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +46 -114
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -17684,37 +17684,18 @@ var StakingService = class {
|
|
|
17684
17684
|
if (params.action === "stake" || params.action === "unstake" || params.action === "instantUnstake") {
|
|
17685
17685
|
invariant6(params.amount > 0n, "Amount must be greater than 0");
|
|
17686
17686
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
17687
|
-
const targetToken = params.action === "stake" || spokeProvider
|
|
17687
|
+
const targetToken = params.action === "stake" || !isHubSpokeProvider(spokeProvider, this.hubProvider) ? spokeProvider.chainConfig.supportedTokens.SODA?.address : this.hubProvider.chainConfig.addresses.xSoda;
|
|
17688
17688
|
invariant6(targetToken, "Target token not found");
|
|
17689
|
-
if (isEvmSpokeProviderType(spokeProvider)) {
|
|
17690
|
-
const
|
|
17691
|
-
targetToken,
|
|
17692
|
-
params.amount,
|
|
17689
|
+
if (isEvmSpokeProviderType(spokeProvider) || isSonicSpokeProviderType(spokeProvider)) {
|
|
17690
|
+
const spender = isHubSpokeProvider(spokeProvider, this.hubProvider) ? await HubService.getUserRouter(
|
|
17693
17691
|
walletAddress,
|
|
17694
|
-
|
|
17695
|
-
|
|
17696
|
-
);
|
|
17697
|
-
if (!allowanceResult.ok) {
|
|
17698
|
-
return {
|
|
17699
|
-
ok: false,
|
|
17700
|
-
error: {
|
|
17701
|
-
code: "ALLOWANCE_CHECK_FAILED",
|
|
17702
|
-
error: allowanceResult.error
|
|
17703
|
-
}
|
|
17704
|
-
};
|
|
17705
|
-
}
|
|
17706
|
-
return {
|
|
17707
|
-
ok: true,
|
|
17708
|
-
value: allowanceResult.value
|
|
17709
|
-
};
|
|
17710
|
-
}
|
|
17711
|
-
if (isSonicSpokeProviderType(spokeProvider)) {
|
|
17712
|
-
const userRouter = await SonicSpokeService.getUserRouter(walletAddress, spokeProvider);
|
|
17692
|
+
this.hubProvider
|
|
17693
|
+
) : spokeProvider.chainConfig.addresses.assetManager;
|
|
17713
17694
|
const allowanceResult = await Erc20Service.isAllowanceValid(
|
|
17714
17695
|
targetToken,
|
|
17715
17696
|
params.amount,
|
|
17716
17697
|
walletAddress,
|
|
17717
|
-
|
|
17698
|
+
spender,
|
|
17718
17699
|
spokeProvider
|
|
17719
17700
|
);
|
|
17720
17701
|
if (!allowanceResult.ok) {
|
|
@@ -17775,13 +17756,17 @@ var StakingService = class {
|
|
|
17775
17756
|
if (params.action === "stake" || params.action === "unstake" || params.action === "instantUnstake") {
|
|
17776
17757
|
invariant6(params.amount > 0n, "Amount must be greater than 0");
|
|
17777
17758
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
17778
|
-
const targetToken = params.action === "stake" || spokeProvider
|
|
17759
|
+
const targetToken = params.action === "stake" || !isHubSpokeProvider(spokeProvider, this.hubProvider) ? spokeProvider.chainConfig.supportedTokens.SODA?.address : this.hubProvider.chainConfig.addresses.xSoda;
|
|
17779
17760
|
invariant6(targetToken, "Target token not found");
|
|
17780
|
-
if (isEvmSpokeProviderType(spokeProvider)) {
|
|
17761
|
+
if (isEvmSpokeProviderType(spokeProvider) || isSonicSpokeProviderType(spokeProvider)) {
|
|
17762
|
+
const spender = isHubSpokeProvider(spokeProvider, this.hubProvider) ? await HubService.getUserRouter(
|
|
17763
|
+
walletAddress,
|
|
17764
|
+
this.hubProvider
|
|
17765
|
+
) : spokeProvider.chainConfig.addresses.assetManager;
|
|
17781
17766
|
const result = await Erc20Service.approve(
|
|
17782
17767
|
targetToken,
|
|
17783
17768
|
params.amount,
|
|
17784
|
-
|
|
17769
|
+
spender,
|
|
17785
17770
|
spokeProvider,
|
|
17786
17771
|
raw
|
|
17787
17772
|
);
|
|
@@ -17790,17 +17775,6 @@ var StakingService = class {
|
|
|
17790
17775
|
value: result
|
|
17791
17776
|
};
|
|
17792
17777
|
}
|
|
17793
|
-
if (isSonicSpokeProviderType(spokeProvider)) {
|
|
17794
|
-
const userRouter = await SonicSpokeService.getUserRouter(
|
|
17795
|
-
walletAddress,
|
|
17796
|
-
spokeProvider
|
|
17797
|
-
);
|
|
17798
|
-
const result = await Erc20Service.approve(targetToken, params.amount, userRouter, spokeProvider, raw);
|
|
17799
|
-
return {
|
|
17800
|
-
ok: true,
|
|
17801
|
-
value: result
|
|
17802
|
-
};
|
|
17803
|
-
}
|
|
17804
17778
|
if (isStellarSpokeProviderType(spokeProvider)) {
|
|
17805
17779
|
const result = await StellarSpokeService.requestTrustline(targetToken, params.amount, spokeProvider, raw);
|
|
17806
17780
|
return {
|
|
@@ -17860,7 +17834,7 @@ var StakingService = class {
|
|
|
17860
17834
|
};
|
|
17861
17835
|
}
|
|
17862
17836
|
let hubTxHash = null;
|
|
17863
|
-
if (spokeProvider
|
|
17837
|
+
if (!isHubSpokeProvider(spokeProvider, this.hubProvider)) {
|
|
17864
17838
|
const packetResult = await relayTxAndWaitPacket(
|
|
17865
17839
|
txResult.value,
|
|
17866
17840
|
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
@@ -17917,16 +17891,12 @@ var StakingService = class {
|
|
|
17917
17891
|
invariant6(sodaToken, "SODA token not found");
|
|
17918
17892
|
const sodaAsset = this.configService.getHubAssetInfo(spokeProvider.chainConfig.chain.id, sodaToken.address);
|
|
17919
17893
|
invariant6(sodaAsset, "SODA asset not found");
|
|
17920
|
-
const hubWallet = await
|
|
17894
|
+
const hubWallet = await HubService.getUserHubWalletAddress(
|
|
17921
17895
|
walletAddress,
|
|
17922
|
-
spokeProvider,
|
|
17896
|
+
spokeProvider.chainConfig.chain.id,
|
|
17923
17897
|
this.hubProvider
|
|
17924
17898
|
);
|
|
17925
|
-
|
|
17926
|
-
if (spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id) {
|
|
17927
|
-
to = walletAddress;
|
|
17928
|
-
}
|
|
17929
|
-
const data = this.buildStakeData(sodaAsset, to, params);
|
|
17899
|
+
const data = this.buildStakeData(sodaAsset, hubWallet, params);
|
|
17930
17900
|
const txResult = await SpokeService.deposit(
|
|
17931
17901
|
{
|
|
17932
17902
|
from: walletAddress,
|
|
@@ -17997,7 +17967,7 @@ var StakingService = class {
|
|
|
17997
17967
|
};
|
|
17998
17968
|
}
|
|
17999
17969
|
let hubTxHash = null;
|
|
18000
|
-
if (spokeProvider
|
|
17970
|
+
if (!isHubSpokeProvider(spokeProvider, this.hubProvider)) {
|
|
18001
17971
|
const packetResult = await relayTxAndWaitPacket(
|
|
18002
17972
|
txResult.value,
|
|
18003
17973
|
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
@@ -18049,11 +18019,10 @@ var StakingService = class {
|
|
|
18049
18019
|
raw
|
|
18050
18020
|
}) {
|
|
18051
18021
|
try {
|
|
18052
|
-
const isHub = this.hubProvider.chainConfig.chain.id === spokeProvider.chainConfig.chain.id;
|
|
18053
18022
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
18054
|
-
const hubWallet = await
|
|
18023
|
+
const hubWallet = await HubService.getUserHubWalletAddress(
|
|
18055
18024
|
walletAddress,
|
|
18056
|
-
spokeProvider,
|
|
18025
|
+
spokeProvider.chainConfig.chain.id,
|
|
18057
18026
|
this.hubProvider
|
|
18058
18027
|
);
|
|
18059
18028
|
const xSoda = this.hubProvider.chainConfig.addresses.xSoda;
|
|
@@ -18063,23 +18032,7 @@ var StakingService = class {
|
|
|
18063
18032
|
this.hubProvider.publicClient
|
|
18064
18033
|
);
|
|
18065
18034
|
const data = this.buildUnstakeData(hubWallet, params, xSoda, underlyingSodaAmount);
|
|
18066
|
-
|
|
18067
|
-
if (isHub) {
|
|
18068
|
-
txResult = await SpokeService.deposit(
|
|
18069
|
-
{
|
|
18070
|
-
from: walletAddress,
|
|
18071
|
-
to: hubWallet,
|
|
18072
|
-
token: this.hubProvider.chainConfig.addresses.xSoda,
|
|
18073
|
-
amount: params.amount,
|
|
18074
|
-
data
|
|
18075
|
-
},
|
|
18076
|
-
spokeProvider,
|
|
18077
|
-
this.hubProvider,
|
|
18078
|
-
raw
|
|
18079
|
-
);
|
|
18080
|
-
} else {
|
|
18081
|
-
txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
18082
|
-
}
|
|
18035
|
+
const txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
18083
18036
|
return {
|
|
18084
18037
|
ok: true,
|
|
18085
18038
|
value: txResult,
|
|
@@ -18133,7 +18086,7 @@ var StakingService = class {
|
|
|
18133
18086
|
};
|
|
18134
18087
|
}
|
|
18135
18088
|
let hubTxHash = null;
|
|
18136
|
-
if (spokeProvider
|
|
18089
|
+
if (!isHubSpokeProvider(spokeProvider, this.hubProvider)) {
|
|
18137
18090
|
const packetResult = await relayTxAndWaitPacket(
|
|
18138
18091
|
txResult.value,
|
|
18139
18092
|
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
@@ -18183,11 +18136,10 @@ var StakingService = class {
|
|
|
18183
18136
|
raw
|
|
18184
18137
|
}) {
|
|
18185
18138
|
try {
|
|
18186
|
-
const isHub = this.hubProvider.chainConfig.chain.id === spokeProvider.chainConfig.chain.id;
|
|
18187
18139
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
18188
|
-
const hubWallet = await
|
|
18140
|
+
const hubWallet = await HubService.getUserHubWalletAddress(
|
|
18189
18141
|
walletAddress,
|
|
18190
|
-
spokeProvider,
|
|
18142
|
+
spokeProvider.chainConfig.chain.id,
|
|
18191
18143
|
this.hubProvider
|
|
18192
18144
|
);
|
|
18193
18145
|
const sodaToken = spokeProvider.chainConfig.supportedTokens.SODA;
|
|
@@ -18200,23 +18152,7 @@ var StakingService = class {
|
|
|
18200
18152
|
encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress),
|
|
18201
18153
|
params
|
|
18202
18154
|
);
|
|
18203
|
-
|
|
18204
|
-
if (isHub) {
|
|
18205
|
-
txResult = await SpokeService.deposit(
|
|
18206
|
-
{
|
|
18207
|
-
from: walletAddress,
|
|
18208
|
-
to: hubWallet,
|
|
18209
|
-
token: this.hubProvider.chainConfig.addresses.xSoda,
|
|
18210
|
-
amount: params.amount,
|
|
18211
|
-
data
|
|
18212
|
-
},
|
|
18213
|
-
spokeProvider,
|
|
18214
|
-
this.hubProvider,
|
|
18215
|
-
raw
|
|
18216
|
-
);
|
|
18217
|
-
} else {
|
|
18218
|
-
txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
18219
|
-
}
|
|
18155
|
+
const txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
18220
18156
|
return {
|
|
18221
18157
|
ok: true,
|
|
18222
18158
|
value: txResult,
|
|
@@ -18282,7 +18218,7 @@ var StakingService = class {
|
|
|
18282
18218
|
};
|
|
18283
18219
|
}
|
|
18284
18220
|
let hubTxHash = null;
|
|
18285
|
-
if (spokeProvider
|
|
18221
|
+
if (!isHubSpokeProvider(spokeProvider, this.hubProvider)) {
|
|
18286
18222
|
const packetResult = await relayTxAndWaitPacket(
|
|
18287
18223
|
txResult.value,
|
|
18288
18224
|
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
@@ -18333,9 +18269,9 @@ var StakingService = class {
|
|
|
18333
18269
|
}) {
|
|
18334
18270
|
try {
|
|
18335
18271
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
18336
|
-
const hubWallet = await
|
|
18272
|
+
const hubWallet = await HubService.getUserHubWalletAddress(
|
|
18337
18273
|
walletAddress,
|
|
18338
|
-
spokeProvider,
|
|
18274
|
+
spokeProvider.chainConfig.chain.id,
|
|
18339
18275
|
this.hubProvider
|
|
18340
18276
|
);
|
|
18341
18277
|
const sodaToken = spokeProvider.chainConfig.supportedTokens.SODA;
|
|
@@ -18418,7 +18354,7 @@ var StakingService = class {
|
|
|
18418
18354
|
};
|
|
18419
18355
|
}
|
|
18420
18356
|
let hubTxHash = null;
|
|
18421
|
-
if (spokeProvider
|
|
18357
|
+
if (!isHubSpokeProvider(spokeProvider, this.hubProvider)) {
|
|
18422
18358
|
const packetResult = await relayTxAndWaitPacket(
|
|
18423
18359
|
txResult.value,
|
|
18424
18360
|
spokeProvider instanceof SolanaSpokeProvider ? txResult.data : void 0,
|
|
@@ -18469,16 +18405,11 @@ var StakingService = class {
|
|
|
18469
18405
|
}) {
|
|
18470
18406
|
try {
|
|
18471
18407
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
18472
|
-
|
|
18473
|
-
|
|
18474
|
-
|
|
18475
|
-
|
|
18476
|
-
|
|
18477
|
-
walletAddress,
|
|
18478
|
-
spokeProvider,
|
|
18479
|
-
this.hubProvider
|
|
18480
|
-
);
|
|
18481
|
-
}
|
|
18408
|
+
const hubWallet = await HubService.getUserHubWalletAddress(
|
|
18409
|
+
walletAddress,
|
|
18410
|
+
spokeProvider.chainConfig.chain.id,
|
|
18411
|
+
this.hubProvider
|
|
18412
|
+
);
|
|
18482
18413
|
const data = await this.buildCancelUnstakeData(params, hubWallet);
|
|
18483
18414
|
const txResult = await SpokeService.callWallet(hubWallet, data, spokeProvider, this.hubProvider, raw);
|
|
18484
18415
|
return {
|
|
@@ -18534,12 +18465,9 @@ var StakingService = class {
|
|
|
18534
18465
|
async getStakingInfoFromSpoke(spokeProvider) {
|
|
18535
18466
|
try {
|
|
18536
18467
|
const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
|
|
18537
|
-
|
|
18538
|
-
return this.getStakingInfo(walletAddress);
|
|
18539
|
-
}
|
|
18540
|
-
const hubWallet = await WalletAbstractionService.getUserAbstractedWalletAddress(
|
|
18468
|
+
const hubWallet = await HubService.getUserHubWalletAddress(
|
|
18541
18469
|
walletAddress,
|
|
18542
|
-
spokeProvider,
|
|
18470
|
+
spokeProvider.chainConfig.chain.id,
|
|
18543
18471
|
this.hubProvider
|
|
18544
18472
|
);
|
|
18545
18473
|
return this.getStakingInfo(hubWallet);
|
|
@@ -18563,8 +18491,12 @@ var StakingService = class {
|
|
|
18563
18491
|
invariant6(userAddress, "User address is required");
|
|
18564
18492
|
const hubConfig = getHubChainConfig();
|
|
18565
18493
|
const xSoda = hubConfig.addresses.xSoda;
|
|
18566
|
-
const totalUnderlying = await
|
|
18567
|
-
|
|
18494
|
+
const [totalUnderlying, userXSodaShares] = await Promise.all([
|
|
18495
|
+
StakingLogic.getXSodaTotalAssets(xSoda, this.hubProvider.publicClient),
|
|
18496
|
+
// Get total assets in xSoda vault (total underlying SODA)
|
|
18497
|
+
this.getXSodaBalance(xSoda, userAddress)
|
|
18498
|
+
// Get user's raw xSODA shares
|
|
18499
|
+
]);
|
|
18568
18500
|
const userXSodaValue = await StakingLogic.convertXSodaSharesToSoda(
|
|
18569
18501
|
xSoda,
|
|
18570
18502
|
userXSodaShares,
|
|
@@ -18607,9 +18539,9 @@ var StakingService = class {
|
|
|
18607
18539
|
userAddress = param;
|
|
18608
18540
|
} else {
|
|
18609
18541
|
const walletAddress = await param.walletProvider.getWalletAddress();
|
|
18610
|
-
userAddress = await
|
|
18542
|
+
userAddress = await HubService.getUserHubWalletAddress(
|
|
18611
18543
|
walletAddress,
|
|
18612
|
-
param,
|
|
18544
|
+
param.chainConfig.chain.id,
|
|
18613
18545
|
this.hubProvider
|
|
18614
18546
|
);
|
|
18615
18547
|
}
|
|
@@ -18712,9 +18644,9 @@ var StakingService = class {
|
|
|
18712
18644
|
userAddress = param;
|
|
18713
18645
|
} else {
|
|
18714
18646
|
const walletAddress = await param.walletProvider.getWalletAddress();
|
|
18715
|
-
userAddress = await
|
|
18647
|
+
userAddress = await HubService.getUserHubWalletAddress(
|
|
18716
18648
|
walletAddress,
|
|
18717
|
-
param,
|
|
18649
|
+
param.chainConfig.chain.id,
|
|
18718
18650
|
this.hubProvider
|
|
18719
18651
|
);
|
|
18720
18652
|
}
|