@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.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ interface IStakingClient {
|
|
|
41
41
|
buy(amount: bigint): Promise<string>;
|
|
42
42
|
/** Claim a withdrawal receipt (burn NFT + receive ETH/SOL) via claim_withdraw. */
|
|
43
43
|
claimWithdraw(tokenId: bigint): Promise<string>;
|
|
44
|
+
/** Solana only: claim accrued liqSOL distribution rewards. */
|
|
45
|
+
claimLiqsolRewards?(): Promise<string>;
|
|
44
46
|
/** Enumerate withdrawal receipt NFTs held by the user (queued/ready/claimed). */
|
|
45
47
|
getPendingWithdraws(): Promise<WithdrawReceipt$1[]>;
|
|
46
48
|
/** Fetch the complete user portfolio */
|
|
@@ -91,6 +93,11 @@ interface Portfolio {
|
|
|
91
93
|
native: BalanceView;
|
|
92
94
|
/** Liquid staking token balance (LiqETH, LiqSOL, etc.). */
|
|
93
95
|
liq: BalanceView;
|
|
96
|
+
/**
|
|
97
|
+
* Solana-only liqSOL rewards currently claimable from the distribution bucket.
|
|
98
|
+
* Not populated on Ethereum.
|
|
99
|
+
*/
|
|
100
|
+
claimable?: BalanceView;
|
|
94
101
|
/**
|
|
95
102
|
* Outpost-staked balance:
|
|
96
103
|
* - On Solana: liqSOL staked via `synd` (stakedLiqsol, in lamports).
|
|
@@ -445,6 +452,7 @@ declare class EthereumStakingClient implements IStakingClient {
|
|
|
445
452
|
MockAggregator: ethers.Contract;
|
|
446
453
|
};
|
|
447
454
|
get network(): _wireio_core.ExternalNetwork;
|
|
455
|
+
get address(): Promise<string> | undefined;
|
|
448
456
|
constructor(config: StakerConfig);
|
|
449
457
|
/**
|
|
450
458
|
* Deposit native ETH into the liqETH protocol via DepositManager.
|
|
@@ -15494,6 +15502,7 @@ declare class DistributionClient {
|
|
|
15494
15502
|
private program;
|
|
15495
15503
|
constructor(provider: AnchorProvider, pgs: SolanaProgramService);
|
|
15496
15504
|
get connection(): _solana_web3_js.Connection;
|
|
15505
|
+
private getTokenBalance;
|
|
15497
15506
|
/**
|
|
15498
15507
|
* Fetch the global distribution state account.
|
|
15499
15508
|
*
|
|
@@ -15536,6 +15545,19 @@ declare class DistributionClient {
|
|
|
15536
15545
|
totalShares: BN;
|
|
15537
15546
|
ratio: number;
|
|
15538
15547
|
}>;
|
|
15548
|
+
/**
|
|
15549
|
+
* Compute claimable liqSOL for a wallet:
|
|
15550
|
+
* claimable = max(0, entitled - actual)
|
|
15551
|
+
* entitled = floor(shares * syncedIndex / 1e12)
|
|
15552
|
+
*
|
|
15553
|
+
* `syncedIndex` mirrors on-chain `sync_index` behavior by incorporating any
|
|
15554
|
+
* unsynced bucket delta (bucket_balance - last_bucket_balance).
|
|
15555
|
+
*/
|
|
15556
|
+
getClaimableLiqsol(user: PublicKey$1): Promise<BN>;
|
|
15557
|
+
/**
|
|
15558
|
+
* Build claim_rewards instruction for a wallet.
|
|
15559
|
+
*/
|
|
15560
|
+
buildClaimRewardsIx(user: PublicKey$1): Promise<TransactionInstruction>;
|
|
15539
15561
|
/**
|
|
15540
15562
|
* Compute an average scaled pay rate over the most recent `windowSize`
|
|
15541
15563
|
* valid entries in the pay-rate history circular buffer.
|
|
@@ -15857,6 +15879,10 @@ declare class SolanaStakingClient implements IStakingClient {
|
|
|
15857
15879
|
* Claim a withdrawal receipt (burn NFT + receive SOL) via claim_withdraw.
|
|
15858
15880
|
*/
|
|
15859
15881
|
claimWithdraw(tokenId: bigint): Promise<string>;
|
|
15882
|
+
/**
|
|
15883
|
+
* Claim accrued liqSOL distribution rewards (liqsol_core::claim_rewards).
|
|
15884
|
+
*/
|
|
15885
|
+
claimLiqsolRewards(): Promise<string>;
|
|
15860
15886
|
/**
|
|
15861
15887
|
* Stake liqSOL into Outpost (liqSOL → pool) via liqsol_core::synd.
|
|
15862
15888
|
*/
|
package/lib/stake.js
CHANGED
|
@@ -15168,6 +15168,7 @@ var __async$e = (__this, __arguments, generator) => {
|
|
|
15168
15168
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
15169
15169
|
});
|
|
15170
15170
|
};
|
|
15171
|
+
const INDEX_SCALE_BN = new anchor.BN("1000000000000");
|
|
15171
15172
|
class DistributionClient {
|
|
15172
15173
|
constructor(provider, pgs) {
|
|
15173
15174
|
this.provider = provider;
|
|
@@ -15177,6 +15178,16 @@ class DistributionClient {
|
|
|
15177
15178
|
get connection() {
|
|
15178
15179
|
return this.provider.connection;
|
|
15179
15180
|
}
|
|
15181
|
+
getTokenBalance(ata) {
|
|
15182
|
+
return __async$e(this, null, function* () {
|
|
15183
|
+
try {
|
|
15184
|
+
const bal = yield this.connection.getTokenAccountBalance(ata);
|
|
15185
|
+
return new anchor.BN(bal.value.amount);
|
|
15186
|
+
} catch (e) {
|
|
15187
|
+
return new anchor.BN(0);
|
|
15188
|
+
}
|
|
15189
|
+
});
|
|
15190
|
+
}
|
|
15180
15191
|
getDistributionState() {
|
|
15181
15192
|
return __async$e(this, null, function* () {
|
|
15182
15193
|
const pda = this.pgs.deriveDistributionStatePda();
|
|
@@ -15256,6 +15267,85 @@ class DistributionClient {
|
|
|
15256
15267
|
return { shares: userShares, totalShares, ratio };
|
|
15257
15268
|
});
|
|
15258
15269
|
}
|
|
15270
|
+
getClaimableLiqsol(user) {
|
|
15271
|
+
return __async$e(this, null, function* () {
|
|
15272
|
+
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
15273
|
+
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
15274
|
+
const userAta = splToken.getAssociatedTokenAddressSync(
|
|
15275
|
+
liqsolMint,
|
|
15276
|
+
user,
|
|
15277
|
+
true,
|
|
15278
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
15279
|
+
);
|
|
15280
|
+
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
15281
|
+
liqsolMint,
|
|
15282
|
+
bucketAuthority,
|
|
15283
|
+
true,
|
|
15284
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
15285
|
+
);
|
|
15286
|
+
const [distributionState, userRecord, actualBalance, bucketBalance] = yield Promise.all([
|
|
15287
|
+
this.getDistributionState(),
|
|
15288
|
+
this.getUserRecord(user),
|
|
15289
|
+
this.getTokenBalance(userAta),
|
|
15290
|
+
this.getTokenBalance(bucketTokenAccount)
|
|
15291
|
+
]);
|
|
15292
|
+
if (!distributionState || !userRecord) {
|
|
15293
|
+
return new anchor.BN(0);
|
|
15294
|
+
}
|
|
15295
|
+
let syncedIndex = new anchor.BN(distributionState.currentIndex.toString());
|
|
15296
|
+
const totalShares = new anchor.BN(distributionState.totalShares.toString());
|
|
15297
|
+
const lastBucketBalance = new anchor.BN(distributionState.lastBucketBalance.toString());
|
|
15298
|
+
if (totalShares.gt(new anchor.BN(0)) && bucketBalance.gt(lastBucketBalance)) {
|
|
15299
|
+
const delta = bucketBalance.sub(lastBucketBalance);
|
|
15300
|
+
const indexDelta = delta.mul(INDEX_SCALE_BN).div(totalShares);
|
|
15301
|
+
if (indexDelta.gt(new anchor.BN(0))) {
|
|
15302
|
+
syncedIndex = syncedIndex.add(indexDelta);
|
|
15303
|
+
}
|
|
15304
|
+
}
|
|
15305
|
+
const shares = new anchor.BN(userRecord.shares.toString());
|
|
15306
|
+
const entitled = shares.mul(syncedIndex).div(INDEX_SCALE_BN);
|
|
15307
|
+
if (entitled.lte(actualBalance)) {
|
|
15308
|
+
return new anchor.BN(0);
|
|
15309
|
+
}
|
|
15310
|
+
return entitled.sub(actualBalance);
|
|
15311
|
+
});
|
|
15312
|
+
}
|
|
15313
|
+
buildClaimRewardsIx(user) {
|
|
15314
|
+
return __async$e(this, null, function* () {
|
|
15315
|
+
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
15316
|
+
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
15317
|
+
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
15318
|
+
const userAta = splToken.getAssociatedTokenAddressSync(
|
|
15319
|
+
liqsolMint,
|
|
15320
|
+
user,
|
|
15321
|
+
true,
|
|
15322
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
15323
|
+
);
|
|
15324
|
+
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
15325
|
+
liqsolMint,
|
|
15326
|
+
bucketAuthority,
|
|
15327
|
+
true,
|
|
15328
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
15329
|
+
);
|
|
15330
|
+
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
15331
|
+
const bucketUserRecord = this.pgs.deriveUserRecordPda(bucketTokenAccount);
|
|
15332
|
+
const extraAccountMetaList = this.pgs.deriveExtraAccountMetaListPda(liqsolMint);
|
|
15333
|
+
return this.program.methods.claimRewards().accounts({
|
|
15334
|
+
user,
|
|
15335
|
+
userAta,
|
|
15336
|
+
userRecord,
|
|
15337
|
+
bucketUserRecord,
|
|
15338
|
+
distributionState,
|
|
15339
|
+
extraAccountMetaList,
|
|
15340
|
+
liqsolCoreProgram: this.pgs.PROGRAM_IDS.LIQSOL_CORE,
|
|
15341
|
+
transferHookProgram: this.pgs.PROGRAM_IDS.TRANSFER_HOOK,
|
|
15342
|
+
liqsolMint,
|
|
15343
|
+
bucketAuthority,
|
|
15344
|
+
bucketTokenAccount,
|
|
15345
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
15346
|
+
}).instruction();
|
|
15347
|
+
});
|
|
15348
|
+
}
|
|
15259
15349
|
getAverageScaledPayRate(windowSize = 5) {
|
|
15260
15350
|
return __async$e(this, null, function* () {
|
|
15261
15351
|
var _a, _b, _c, _d, _e;
|
|
@@ -16188,6 +16278,20 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16188
16278
|
}
|
|
16189
16279
|
});
|
|
16190
16280
|
}
|
|
16281
|
+
claimLiqsolRewards() {
|
|
16282
|
+
return __async$9(this, null, function* () {
|
|
16283
|
+
var _a;
|
|
16284
|
+
this.ensureUser();
|
|
16285
|
+
const owner = (_a = this.squadsVaultPDA) != null ? _a : this.anchor.wallet.publicKey;
|
|
16286
|
+
try {
|
|
16287
|
+
const ix = yield this.distributionClient.buildClaimRewardsIx(owner);
|
|
16288
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16289
|
+
} catch (err) {
|
|
16290
|
+
console.log(`Failed to claim liqSOL rewards on Solana: ${err}`);
|
|
16291
|
+
throw err;
|
|
16292
|
+
}
|
|
16293
|
+
});
|
|
16294
|
+
}
|
|
16191
16295
|
stake(amountLamports) {
|
|
16192
16296
|
return __async$9(this, null, function* () {
|
|
16193
16297
|
this.ensureUser();
|
|
@@ -16245,10 +16349,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16245
16349
|
splToken.TOKEN_2022_PROGRAM_ID,
|
|
16246
16350
|
splToken.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
16247
16351
|
);
|
|
16248
|
-
const [nativeLamports, actualBalResp, snapshot] = yield Promise.all([
|
|
16352
|
+
const [nativeLamports, actualBalResp, snapshot, claimableLamports] = yield Promise.all([
|
|
16249
16353
|
this.connection.getBalance(user, "confirmed"),
|
|
16250
16354
|
this.connection.getTokenAccountBalance(userLiqsolAta, "confirmed").catch(() => null),
|
|
16251
|
-
this.outpostClient.fetchWireState(user).catch(() => null)
|
|
16355
|
+
this.outpostClient.fetchWireState(user).catch(() => null),
|
|
16356
|
+
this.distributionClient.getClaimableLiqsol(user).catch(() => new anchor.BN(0))
|
|
16252
16357
|
]);
|
|
16253
16358
|
const LIQSOL_DECIMALS = 9;
|
|
16254
16359
|
const actualAmountStr = (_b = (_a = actualBalResp == null ? void 0 : actualBalResp.value) == null ? void 0 : _a.amount) != null ? _b : "0";
|
|
@@ -16285,6 +16390,12 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16285
16390
|
decimals: LIQSOL_DECIMALS,
|
|
16286
16391
|
ata: userLiqsolAta
|
|
16287
16392
|
},
|
|
16393
|
+
claimable: {
|
|
16394
|
+
amount: BigInt(claimableLamports.toString()),
|
|
16395
|
+
symbol: "LiqSOL",
|
|
16396
|
+
decimals: LIQSOL_DECIMALS,
|
|
16397
|
+
ata: userLiqsolAta
|
|
16398
|
+
},
|
|
16288
16399
|
staked: {
|
|
16289
16400
|
amount: stakedLiqsol,
|
|
16290
16401
|
symbol: "LiqSOL",
|
|
@@ -42132,6 +42243,10 @@ class EthereumStakingClient {
|
|
|
42132
42243
|
get network() {
|
|
42133
42244
|
return this.config.network;
|
|
42134
42245
|
}
|
|
42246
|
+
get address() {
|
|
42247
|
+
var _a;
|
|
42248
|
+
return (_a = this.signer) == null ? void 0 : _a.getAddress();
|
|
42249
|
+
}
|
|
42135
42250
|
deposit(amount) {
|
|
42136
42251
|
return __async(this, null, function* () {
|
|
42137
42252
|
this.ensureUser();
|
|
@@ -42143,7 +42258,7 @@ class EthereumStakingClient {
|
|
|
42143
42258
|
withdraw(amount) {
|
|
42144
42259
|
return __async(this, null, function* () {
|
|
42145
42260
|
this.ensureUser();
|
|
42146
|
-
const address = yield this.
|
|
42261
|
+
const address = yield this.address;
|
|
42147
42262
|
const amountWei = ethers.BigNumber.from(amount);
|
|
42148
42263
|
const result = yield this.convertClient.performWithdraw(address, amountWei);
|
|
42149
42264
|
return result.txHash;
|
|
@@ -42152,7 +42267,7 @@ class EthereumStakingClient {
|
|
|
42152
42267
|
getPendingWithdraws() {
|
|
42153
42268
|
return __async(this, null, function* () {
|
|
42154
42269
|
this.ensureUser();
|
|
42155
|
-
const address = yield this.
|
|
42270
|
+
const address = yield this.address;
|
|
42156
42271
|
return yield this.receiptClient.fetchWithdrawReceipts(address);
|
|
42157
42272
|
});
|
|
42158
42273
|
}
|
|
@@ -42167,7 +42282,7 @@ class EthereumStakingClient {
|
|
|
42167
42282
|
stake(amount) {
|
|
42168
42283
|
return __async(this, null, function* () {
|
|
42169
42284
|
this.ensureUser();
|
|
42170
|
-
const walletAddress = yield this.
|
|
42285
|
+
const walletAddress = yield this.address;
|
|
42171
42286
|
const amountWei = ethers.BigNumber.from(amount);
|
|
42172
42287
|
const result = yield this.stakeClient.performStake(amountWei, walletAddress);
|
|
42173
42288
|
return result.txHash;
|
|
@@ -42189,7 +42304,7 @@ class EthereumStakingClient {
|
|
|
42189
42304
|
buy(amount) {
|
|
42190
42305
|
return __async(this, null, function* () {
|
|
42191
42306
|
this.ensureUser();
|
|
42192
|
-
const buyer = yield this.
|
|
42307
|
+
const buyer = yield this.address;
|
|
42193
42308
|
let result = yield this.pretokenClient.purchasePretokensWithLiqETH(amount, buyer);
|
|
42194
42309
|
return result && result.txHash ? result.txHash : "Error - no resulting txHash";
|
|
42195
42310
|
});
|
|
@@ -42206,7 +42321,7 @@ class EthereumStakingClient {
|
|
|
42206
42321
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
42207
42322
|
try {
|
|
42208
42323
|
if (!this.signer) return Promise.resolve(null);
|
|
42209
|
-
const walletAddress = yield this.
|
|
42324
|
+
const walletAddress = yield this.address;
|
|
42210
42325
|
const nativeBalance = yield this.provider.getBalance(walletAddress);
|
|
42211
42326
|
const nativeDecimals = (_c = (_b = (_a = this.network) == null ? void 0 : _a.nativeCurrency) == null ? void 0 : _b.decimals) != null ? _c : 18;
|
|
42212
42327
|
const nativeSymbol = (_f = (_e = (_d = this.network) == null ? void 0 : _d.nativeCurrency) == null ? void 0 : _e.symbol) != null ? _f : "ETH";
|
|
@@ -42286,14 +42401,14 @@ class EthereumStakingClient {
|
|
|
42286
42401
|
fetchPrelaunchReceipts(address) {
|
|
42287
42402
|
return __async(this, null, function* () {
|
|
42288
42403
|
this.ensureUser();
|
|
42289
|
-
if (address === void 0) address = yield this.
|
|
42404
|
+
if (address === void 0) address = yield this.address;
|
|
42290
42405
|
return yield this.receiptClient.stakeReceipts(address);
|
|
42291
42406
|
});
|
|
42292
42407
|
}
|
|
42293
42408
|
getOPPMessages(address) {
|
|
42294
42409
|
return __async(this, null, function* () {
|
|
42295
42410
|
this.ensureUser();
|
|
42296
|
-
if (!address) address = yield this.
|
|
42411
|
+
if (!address) address = yield this.address;
|
|
42297
42412
|
return yield this.oppClient.getMessages(address);
|
|
42298
42413
|
});
|
|
42299
42414
|
}
|
|
@@ -42381,7 +42496,7 @@ class EthereumStakingClient {
|
|
|
42381
42496
|
return __async(this, null, function* () {
|
|
42382
42497
|
var _a, _b, _c, _d, _e;
|
|
42383
42498
|
this.ensureUser();
|
|
42384
|
-
const walletAddress = yield this.
|
|
42499
|
+
const walletAddress = yield this.address;
|
|
42385
42500
|
const baseGas = yield this.provider.estimateGas({
|
|
42386
42501
|
from: walletAddress,
|
|
42387
42502
|
to: walletAddress,
|