@wireio/stake 2.3.0 → 2.3.1
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/lib/stake.browser.js +115 -10
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +26 -0
- package/lib/stake.js +125 -10
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +115 -10
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/ethereum/ethereum.ts +9 -9
- package/src/networks/solana/clients/distribution.client.ts +114 -2
- package/src/networks/solana/solana.ts +26 -1
- package/src/types.ts +10 -1
package/lib/stake.m.js
CHANGED
|
@@ -15040,6 +15040,7 @@ let ConvertClient$1 = class ConvertClient {
|
|
|
15040
15040
|
}
|
|
15041
15041
|
};
|
|
15042
15042
|
|
|
15043
|
+
const INDEX_SCALE_BN = new BN("1000000000000");
|
|
15043
15044
|
class DistributionClient {
|
|
15044
15045
|
constructor(provider, pgs) {
|
|
15045
15046
|
this.provider = provider;
|
|
@@ -15049,6 +15050,14 @@ class DistributionClient {
|
|
|
15049
15050
|
get connection() {
|
|
15050
15051
|
return this.provider.connection;
|
|
15051
15052
|
}
|
|
15053
|
+
async getTokenBalance(ata) {
|
|
15054
|
+
try {
|
|
15055
|
+
const bal = await this.connection.getTokenAccountBalance(ata);
|
|
15056
|
+
return new BN(bal.value.amount);
|
|
15057
|
+
} catch {
|
|
15058
|
+
return new BN(0);
|
|
15059
|
+
}
|
|
15060
|
+
}
|
|
15052
15061
|
async getDistributionState() {
|
|
15053
15062
|
const pda = this.pgs.deriveDistributionStatePda();
|
|
15054
15063
|
try {
|
|
@@ -15116,6 +15125,81 @@ class DistributionClient {
|
|
|
15116
15125
|
}
|
|
15117
15126
|
return { shares: userShares, totalShares, ratio };
|
|
15118
15127
|
}
|
|
15128
|
+
async getClaimableLiqsol(user) {
|
|
15129
|
+
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
15130
|
+
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
15131
|
+
const userAta = getAssociatedTokenAddressSync(
|
|
15132
|
+
liqsolMint,
|
|
15133
|
+
user,
|
|
15134
|
+
true,
|
|
15135
|
+
TOKEN_2022_PROGRAM_ID
|
|
15136
|
+
);
|
|
15137
|
+
const bucketTokenAccount = getAssociatedTokenAddressSync(
|
|
15138
|
+
liqsolMint,
|
|
15139
|
+
bucketAuthority,
|
|
15140
|
+
true,
|
|
15141
|
+
TOKEN_2022_PROGRAM_ID
|
|
15142
|
+
);
|
|
15143
|
+
const [distributionState, userRecord, actualBalance, bucketBalance] = await Promise.all([
|
|
15144
|
+
this.getDistributionState(),
|
|
15145
|
+
this.getUserRecord(user),
|
|
15146
|
+
this.getTokenBalance(userAta),
|
|
15147
|
+
this.getTokenBalance(bucketTokenAccount)
|
|
15148
|
+
]);
|
|
15149
|
+
if (!distributionState || !userRecord) {
|
|
15150
|
+
return new BN(0);
|
|
15151
|
+
}
|
|
15152
|
+
let syncedIndex = new BN(distributionState.currentIndex.toString());
|
|
15153
|
+
const totalShares = new BN(distributionState.totalShares.toString());
|
|
15154
|
+
const lastBucketBalance = new BN(distributionState.lastBucketBalance.toString());
|
|
15155
|
+
if (totalShares.gt(new BN(0)) && bucketBalance.gt(lastBucketBalance)) {
|
|
15156
|
+
const delta = bucketBalance.sub(lastBucketBalance);
|
|
15157
|
+
const indexDelta = delta.mul(INDEX_SCALE_BN).div(totalShares);
|
|
15158
|
+
if (indexDelta.gt(new BN(0))) {
|
|
15159
|
+
syncedIndex = syncedIndex.add(indexDelta);
|
|
15160
|
+
}
|
|
15161
|
+
}
|
|
15162
|
+
const shares = new BN(userRecord.shares.toString());
|
|
15163
|
+
const entitled = shares.mul(syncedIndex).div(INDEX_SCALE_BN);
|
|
15164
|
+
if (entitled.lte(actualBalance)) {
|
|
15165
|
+
return new BN(0);
|
|
15166
|
+
}
|
|
15167
|
+
return entitled.sub(actualBalance);
|
|
15168
|
+
}
|
|
15169
|
+
async buildClaimRewardsIx(user) {
|
|
15170
|
+
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
15171
|
+
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
15172
|
+
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
15173
|
+
const userAta = getAssociatedTokenAddressSync(
|
|
15174
|
+
liqsolMint,
|
|
15175
|
+
user,
|
|
15176
|
+
true,
|
|
15177
|
+
TOKEN_2022_PROGRAM_ID
|
|
15178
|
+
);
|
|
15179
|
+
const bucketTokenAccount = getAssociatedTokenAddressSync(
|
|
15180
|
+
liqsolMint,
|
|
15181
|
+
bucketAuthority,
|
|
15182
|
+
true,
|
|
15183
|
+
TOKEN_2022_PROGRAM_ID
|
|
15184
|
+
);
|
|
15185
|
+
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
15186
|
+
const bucketUserRecord = this.pgs.deriveUserRecordPda(bucketTokenAccount);
|
|
15187
|
+
const extraAccountMetaList = this.pgs.deriveExtraAccountMetaListPda(liqsolMint);
|
|
15188
|
+
return this.program.methods.claimRewards().accounts({
|
|
15189
|
+
user,
|
|
15190
|
+
userAta,
|
|
15191
|
+
userRecord,
|
|
15192
|
+
bucketUserRecord,
|
|
15193
|
+
distributionState,
|
|
15194
|
+
extraAccountMetaList,
|
|
15195
|
+
liqsolCoreProgram: this.pgs.PROGRAM_IDS.LIQSOL_CORE,
|
|
15196
|
+
transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
|
|
15197
|
+
liqsolMint,
|
|
15198
|
+
bucketAuthority,
|
|
15199
|
+
bucketTokenAccount,
|
|
15200
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID
|
|
15201
|
+
}).instruction();
|
|
15202
|
+
}
|
|
15119
15203
|
async getAverageScaledPayRate(windowSize = 5) {
|
|
15120
15204
|
const history = await this.getPayRateHistory();
|
|
15121
15205
|
if (!history) {
|
|
@@ -15872,6 +15956,17 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
15872
15956
|
throw err;
|
|
15873
15957
|
}
|
|
15874
15958
|
}
|
|
15959
|
+
async claimLiqsolRewards() {
|
|
15960
|
+
this.ensureUser();
|
|
15961
|
+
const owner = this.squadsVaultPDA ?? this.anchor.wallet.publicKey;
|
|
15962
|
+
try {
|
|
15963
|
+
const ix = await this.distributionClient.buildClaimRewardsIx(owner);
|
|
15964
|
+
return !!this.squadsX ? await this.sendSquadsIxs(ix) : await this.buildAndSendIx(ix);
|
|
15965
|
+
} catch (err) {
|
|
15966
|
+
console.log(`Failed to claim liqSOL rewards on Solana: ${err}`);
|
|
15967
|
+
throw err;
|
|
15968
|
+
}
|
|
15969
|
+
}
|
|
15875
15970
|
async stake(amountLamports) {
|
|
15876
15971
|
this.ensureUser();
|
|
15877
15972
|
if (!amountLamports || amountLamports <= BigInt(0))
|
|
@@ -15921,10 +16016,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
15921
16016
|
TOKEN_2022_PROGRAM_ID,
|
|
15922
16017
|
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
15923
16018
|
);
|
|
15924
|
-
const [nativeLamports, actualBalResp, snapshot] = await Promise.all([
|
|
16019
|
+
const [nativeLamports, actualBalResp, snapshot, claimableLamports] = await Promise.all([
|
|
15925
16020
|
this.connection.getBalance(user, "confirmed"),
|
|
15926
16021
|
this.connection.getTokenAccountBalance(userLiqsolAta, "confirmed").catch(() => null),
|
|
15927
|
-
this.outpostClient.fetchWireState(user).catch(() => null)
|
|
16022
|
+
this.outpostClient.fetchWireState(user).catch(() => null),
|
|
16023
|
+
this.distributionClient.getClaimableLiqsol(user).catch(() => new BN(0))
|
|
15928
16024
|
]);
|
|
15929
16025
|
const LIQSOL_DECIMALS = 9;
|
|
15930
16026
|
const actualAmountStr = actualBalResp?.value?.amount ?? "0";
|
|
@@ -15961,6 +16057,12 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
15961
16057
|
decimals: LIQSOL_DECIMALS,
|
|
15962
16058
|
ata: userLiqsolAta
|
|
15963
16059
|
},
|
|
16060
|
+
claimable: {
|
|
16061
|
+
amount: BigInt(claimableLamports.toString()),
|
|
16062
|
+
symbol: "LiqSOL",
|
|
16063
|
+
decimals: LIQSOL_DECIMALS,
|
|
16064
|
+
ata: userLiqsolAta
|
|
16065
|
+
},
|
|
15964
16066
|
staked: {
|
|
15965
16067
|
amount: stakedLiqsol,
|
|
15966
16068
|
symbol: "LiqSOL",
|
|
@@ -41534,6 +41636,9 @@ class EthereumStakingClient {
|
|
|
41534
41636
|
get network() {
|
|
41535
41637
|
return this.config.network;
|
|
41536
41638
|
}
|
|
41639
|
+
get address() {
|
|
41640
|
+
return this.signer?.getAddress();
|
|
41641
|
+
}
|
|
41537
41642
|
async deposit(amount) {
|
|
41538
41643
|
this.ensureUser();
|
|
41539
41644
|
const amountWei = BigNumber.isBigNumber(amount) ? amount : BigNumber.from(amount);
|
|
@@ -41542,14 +41647,14 @@ class EthereumStakingClient {
|
|
|
41542
41647
|
}
|
|
41543
41648
|
async withdraw(amount) {
|
|
41544
41649
|
this.ensureUser();
|
|
41545
|
-
const address = await this.
|
|
41650
|
+
const address = await this.address;
|
|
41546
41651
|
const amountWei = BigNumber.from(amount);
|
|
41547
41652
|
const result = await this.convertClient.performWithdraw(address, amountWei);
|
|
41548
41653
|
return result.txHash;
|
|
41549
41654
|
}
|
|
41550
41655
|
async getPendingWithdraws() {
|
|
41551
41656
|
this.ensureUser();
|
|
41552
|
-
const address = await this.
|
|
41657
|
+
const address = await this.address;
|
|
41553
41658
|
return await this.receiptClient.fetchWithdrawReceipts(address);
|
|
41554
41659
|
}
|
|
41555
41660
|
async claimWithdraw(tokenId) {
|
|
@@ -41560,7 +41665,7 @@ class EthereumStakingClient {
|
|
|
41560
41665
|
}
|
|
41561
41666
|
async stake(amount) {
|
|
41562
41667
|
this.ensureUser();
|
|
41563
|
-
const walletAddress = await this.
|
|
41668
|
+
const walletAddress = await this.address;
|
|
41564
41669
|
const amountWei = BigNumber.from(amount);
|
|
41565
41670
|
const result = await this.stakeClient.performStake(amountWei, walletAddress);
|
|
41566
41671
|
return result.txHash;
|
|
@@ -41576,7 +41681,7 @@ class EthereumStakingClient {
|
|
|
41576
41681
|
}
|
|
41577
41682
|
async buy(amount) {
|
|
41578
41683
|
this.ensureUser();
|
|
41579
|
-
const buyer = await this.
|
|
41684
|
+
const buyer = await this.address;
|
|
41580
41685
|
let result = await this.pretokenClient.purchasePretokensWithLiqETH(amount, buyer);
|
|
41581
41686
|
return result && result.txHash ? result.txHash : "Error - no resulting txHash";
|
|
41582
41687
|
}
|
|
@@ -41588,7 +41693,7 @@ class EthereumStakingClient {
|
|
|
41588
41693
|
async getPortfolio() {
|
|
41589
41694
|
try {
|
|
41590
41695
|
if (!this.signer) return Promise.resolve(null);
|
|
41591
|
-
const walletAddress = await this.
|
|
41696
|
+
const walletAddress = await this.address;
|
|
41592
41697
|
const nativeBalance = await this.provider.getBalance(walletAddress);
|
|
41593
41698
|
const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
|
|
41594
41699
|
const nativeSymbol = this.network?.nativeCurrency?.symbol ?? "ETH";
|
|
@@ -41666,12 +41771,12 @@ class EthereumStakingClient {
|
|
|
41666
41771
|
}
|
|
41667
41772
|
async fetchPrelaunchReceipts(address) {
|
|
41668
41773
|
this.ensureUser();
|
|
41669
|
-
if (address === void 0) address = await this.
|
|
41774
|
+
if (address === void 0) address = await this.address;
|
|
41670
41775
|
return await this.receiptClient.stakeReceipts(address);
|
|
41671
41776
|
}
|
|
41672
41777
|
async getOPPMessages(address) {
|
|
41673
41778
|
this.ensureUser();
|
|
41674
|
-
if (!address) address = await this.
|
|
41779
|
+
if (!address) address = await this.address;
|
|
41675
41780
|
return await this.oppClient.getMessages(address);
|
|
41676
41781
|
}
|
|
41677
41782
|
ensureUser() {
|
|
@@ -41746,7 +41851,7 @@ class EthereumStakingClient {
|
|
|
41746
41851
|
}
|
|
41747
41852
|
async getDepositBuffer(options) {
|
|
41748
41853
|
this.ensureUser();
|
|
41749
|
-
const walletAddress = await this.
|
|
41854
|
+
const walletAddress = await this.address;
|
|
41750
41855
|
const baseGas = await this.provider.estimateGas({
|
|
41751
41856
|
from: walletAddress,
|
|
41752
41857
|
to: walletAddress,
|