@wireio/stake 0.2.3 → 0.2.4
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 +270 -96
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +176 -84
- package/lib/stake.js +282 -102
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +270 -96
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/networks/solana/clients/token.client.ts +72 -98
- package/src/networks/solana/solana.ts +284 -184
- package/src/networks/solana/utils.ts +209 -5
- package/src/types.ts +68 -30
package/lib/stake.m.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PublicKey as PublicKey$1, KeyType,
|
|
2
|
-
import { PublicKey, StakeProgram, SystemProgram, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_CLOCK_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, SYSVAR_RENT_PUBKEY, Transaction, Keypair, Connection } from '@solana/web3.js';
|
|
1
|
+
import { PublicKey as PublicKey$1, KeyType, SolChainID, EvmChainID } from '@wireio/core';
|
|
2
|
+
import { PublicKey, StakeProgram, SystemProgram, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_CLOCK_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, SYSVAR_RENT_PUBKEY, Transaction, Keypair, Connection, LAMPORTS_PER_SOL as LAMPORTS_PER_SOL$1 } from '@solana/web3.js';
|
|
3
3
|
import { Program, BN, AnchorProvider } from '@coral-xyz/anchor';
|
|
4
4
|
import { getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddress, createAssociatedTokenAccountInstruction } from '@solana/spl-token';
|
|
5
5
|
import { ethers, Contract, BigNumber } from 'ethers';
|
|
@@ -5739,6 +5739,129 @@ class LeaderboardClient {
|
|
|
5739
5739
|
}
|
|
5740
5740
|
}
|
|
5741
5741
|
|
|
5742
|
+
const INDEX_SCALE = BigInt(1e12);
|
|
5743
|
+
BigInt(1e8);
|
|
5744
|
+
const BPS = BigInt(1e4);
|
|
5745
|
+
function toBigint(x) {
|
|
5746
|
+
if (typeof x === "bigint") return x;
|
|
5747
|
+
if (typeof x === "number") return BigInt(x);
|
|
5748
|
+
return BigInt(x.toString());
|
|
5749
|
+
}
|
|
5750
|
+
function tokensToShares(amount, currentIndex) {
|
|
5751
|
+
if (amount === BigInt(0)) return BigInt(0);
|
|
5752
|
+
const num = amount * INDEX_SCALE;
|
|
5753
|
+
const q = num / currentIndex;
|
|
5754
|
+
const r = num % currentIndex;
|
|
5755
|
+
return r === BigInt(0) ? q : q + BigInt(1);
|
|
5756
|
+
}
|
|
5757
|
+
function growOnce(value, growthBps) {
|
|
5758
|
+
const g = BigInt(growthBps);
|
|
5759
|
+
return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
|
|
5760
|
+
}
|
|
5761
|
+
function shrinkOnce(value, growthBps) {
|
|
5762
|
+
const g = BigInt(growthBps);
|
|
5763
|
+
return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
|
|
5764
|
+
}
|
|
5765
|
+
function buildSolanaTrancheLadder(options) {
|
|
5766
|
+
const {
|
|
5767
|
+
currentTranche,
|
|
5768
|
+
initialTrancheSupply,
|
|
5769
|
+
currentTrancheSupply,
|
|
5770
|
+
currentPriceUsd,
|
|
5771
|
+
supplyGrowthBps,
|
|
5772
|
+
priceGrowthBps,
|
|
5773
|
+
windowBefore = 5,
|
|
5774
|
+
windowAfter = 5
|
|
5775
|
+
} = options;
|
|
5776
|
+
const startId = Math.max(0, currentTranche - windowBefore);
|
|
5777
|
+
const endId = currentTranche + windowAfter;
|
|
5778
|
+
const capacity = new Map();
|
|
5779
|
+
const price = new Map();
|
|
5780
|
+
capacity.set(currentTranche, initialTrancheSupply);
|
|
5781
|
+
price.set(currentTranche, currentPriceUsd);
|
|
5782
|
+
for (let id = currentTranche + 1; id <= endId; id++) {
|
|
5783
|
+
const prevCap = capacity.get(id - 1);
|
|
5784
|
+
const prevPrice = price.get(id - 1);
|
|
5785
|
+
capacity.set(id, growOnce(prevCap, supplyGrowthBps));
|
|
5786
|
+
price.set(id, growOnce(prevPrice, priceGrowthBps));
|
|
5787
|
+
}
|
|
5788
|
+
for (let id = currentTranche - 1; id >= startId; id--) {
|
|
5789
|
+
const nextCap = capacity.get(id + 1);
|
|
5790
|
+
const nextPrice = price.get(id + 1);
|
|
5791
|
+
capacity.set(id, shrinkOnce(nextCap, supplyGrowthBps));
|
|
5792
|
+
price.set(id, shrinkOnce(nextPrice, priceGrowthBps));
|
|
5793
|
+
}
|
|
5794
|
+
const ladder = [];
|
|
5795
|
+
for (let id = startId; id <= endId; id++) {
|
|
5796
|
+
const cap = capacity.get(id);
|
|
5797
|
+
let sold;
|
|
5798
|
+
if (id < currentTranche) {
|
|
5799
|
+
sold = cap;
|
|
5800
|
+
} else if (id === currentTranche) {
|
|
5801
|
+
sold = cap - currentTrancheSupply;
|
|
5802
|
+
} else {
|
|
5803
|
+
sold = BigInt(0);
|
|
5804
|
+
}
|
|
5805
|
+
ladder.push({
|
|
5806
|
+
id,
|
|
5807
|
+
capacity: cap,
|
|
5808
|
+
sold,
|
|
5809
|
+
remaining: cap - sold,
|
|
5810
|
+
priceUsd: price.get(id)
|
|
5811
|
+
});
|
|
5812
|
+
}
|
|
5813
|
+
return ladder;
|
|
5814
|
+
}
|
|
5815
|
+
function buildSolanaTrancheSnapshot(options) {
|
|
5816
|
+
const {
|
|
5817
|
+
chainID,
|
|
5818
|
+
globalState,
|
|
5819
|
+
trancheState,
|
|
5820
|
+
solPriceUsd,
|
|
5821
|
+
nativePriceTimestamp,
|
|
5822
|
+
ladderWindowBefore,
|
|
5823
|
+
ladderWindowAfter
|
|
5824
|
+
} = options;
|
|
5825
|
+
const currentIndex = toBigint(globalState.currentIndex);
|
|
5826
|
+
const totalShares = toBigint(globalState.totalShares);
|
|
5827
|
+
const currentTranche = trancheState.currentTrancheNumber.toNumber();
|
|
5828
|
+
const currentTrancheSupply = toBigint(trancheState.currentTrancheSupply);
|
|
5829
|
+
const initialTrancheSupply = toBigint(trancheState.initialTrancheSupply);
|
|
5830
|
+
const totalWarrantsSold = toBigint(trancheState.totalWarrantsSold);
|
|
5831
|
+
const currentPriceUsd = toBigint(trancheState.currentTranchePriceUsd);
|
|
5832
|
+
const supplyGrowthBps = trancheState.supplyGrowthBps;
|
|
5833
|
+
const priceGrowthBps = trancheState.priceGrowthBps;
|
|
5834
|
+
const minPriceUsd = trancheState.minPriceUsd ? toBigint(trancheState.minPriceUsd) : void 0;
|
|
5835
|
+
const maxPriceUsd = trancheState.maxPriceUsd ? toBigint(trancheState.maxPriceUsd) : void 0;
|
|
5836
|
+
const ladder = buildSolanaTrancheLadder({
|
|
5837
|
+
currentTranche,
|
|
5838
|
+
initialTrancheSupply,
|
|
5839
|
+
currentTrancheSupply,
|
|
5840
|
+
totalWarrantsSold,
|
|
5841
|
+
currentPriceUsd,
|
|
5842
|
+
supplyGrowthBps,
|
|
5843
|
+
priceGrowthBps,
|
|
5844
|
+
windowBefore: ladderWindowBefore,
|
|
5845
|
+
windowAfter: ladderWindowAfter
|
|
5846
|
+
});
|
|
5847
|
+
return {
|
|
5848
|
+
chainID,
|
|
5849
|
+
currentIndex,
|
|
5850
|
+
totalShares,
|
|
5851
|
+
currentTranche,
|
|
5852
|
+
currentPriceUsd,
|
|
5853
|
+
minPriceUsd,
|
|
5854
|
+
maxPriceUsd,
|
|
5855
|
+
supplyGrowthBps,
|
|
5856
|
+
priceGrowthBps,
|
|
5857
|
+
currentTrancheSupply,
|
|
5858
|
+
initialTrancheSupply,
|
|
5859
|
+
totalWarrantsSold,
|
|
5860
|
+
nativePriceUsd: solPriceUsd,
|
|
5861
|
+
nativePriceTimestamp,
|
|
5862
|
+
ladder
|
|
5863
|
+
};
|
|
5864
|
+
}
|
|
5742
5865
|
let _liqsolCoreProgram = null;
|
|
5743
5866
|
function getLiqsolCoreProgram(connection) {
|
|
5744
5867
|
if (_liqsolCoreProgram && _liqsolCoreProgram.provider.connection === connection) {
|
|
@@ -6340,11 +6463,11 @@ class TokenClient {
|
|
|
6340
6463
|
return buildOutpostAccounts(this.provider.connection, user);
|
|
6341
6464
|
}
|
|
6342
6465
|
async fetchGlobalState() {
|
|
6343
|
-
const { globalState } = await this.getAccounts(this.
|
|
6466
|
+
const { globalState } = await this.getAccounts(this.wallet.publicKey);
|
|
6344
6467
|
return this.program.account.globalState.fetch(globalState);
|
|
6345
6468
|
}
|
|
6346
6469
|
async fetchTrancheState() {
|
|
6347
|
-
const { trancheState } = await this.getAccounts(this.
|
|
6470
|
+
const { trancheState } = await this.getAccounts(this.wallet.publicKey);
|
|
6348
6471
|
return this.program.account.trancheState.fetch(trancheState);
|
|
6349
6472
|
}
|
|
6350
6473
|
async fetchWireReceipt(user) {
|
|
@@ -6417,34 +6540,41 @@ class TokenClient {
|
|
|
6417
6540
|
payRateHistory: a.payRateHistory,
|
|
6418
6541
|
bucketAuthority: a.bucketAuthority,
|
|
6419
6542
|
bucketTokenAccount: a.bucketTokenAccount,
|
|
6420
|
-
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
6421
|
-
systemProgram: SystemProgram.programId,
|
|
6422
6543
|
trancheState: a.trancheState,
|
|
6423
6544
|
userWarrantRecord: a.userWarrantRecord,
|
|
6424
6545
|
chainlinkFeed: a.chainLinkFeed,
|
|
6425
|
-
chainlinkProgram: a.chainLinkProgram
|
|
6546
|
+
chainlinkProgram: a.chainLinkProgram,
|
|
6547
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
6548
|
+
systemProgram: SystemProgram.programId
|
|
6426
6549
|
}).instruction();
|
|
6427
6550
|
}
|
|
6551
|
+
async getSolPriceUsdSafe() {
|
|
6552
|
+
try {
|
|
6553
|
+
const price = await this.getSolPriceUsd();
|
|
6554
|
+
return { price, timestamp: void 0 };
|
|
6555
|
+
} catch {
|
|
6556
|
+
return { price: void 0, timestamp: void 0 };
|
|
6557
|
+
}
|
|
6558
|
+
}
|
|
6428
6559
|
async getSolPriceUsd() {
|
|
6429
6560
|
const priceHistoryPda = derivePriceHistoryPda();
|
|
6430
6561
|
const history = await this.program.account.priceHistory.fetch(
|
|
6431
6562
|
priceHistoryPda
|
|
6432
6563
|
);
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
if (!prices || prices.length === 0 || count === 0) {
|
|
6564
|
+
const { prices, nextIndex, count, windowSize } = history;
|
|
6565
|
+
if (!prices || prices.length === 0 || !count) {
|
|
6436
6566
|
throw new Error("Price history is empty \u2013 no SOL price available");
|
|
6437
6567
|
}
|
|
6438
6568
|
const capacity = prices.length || windowSize;
|
|
6439
|
-
if (capacity
|
|
6569
|
+
if (!capacity) {
|
|
6440
6570
|
throw new Error("Price history capacity is zero \u2013 check account layout");
|
|
6441
6571
|
}
|
|
6442
6572
|
const lastIndex = nextIndex === 0 ? capacity - 1 : nextIndex - 1;
|
|
6443
|
-
const
|
|
6444
|
-
if (!BN.isBN(
|
|
6573
|
+
const latest = prices[lastIndex];
|
|
6574
|
+
if (!BN.isBN(latest)) {
|
|
6445
6575
|
throw new Error("Latest price entry is not a BN \u2013 check IDL/decoder");
|
|
6446
6576
|
}
|
|
6447
|
-
return
|
|
6577
|
+
return BigInt(latest.toString());
|
|
6448
6578
|
}
|
|
6449
6579
|
}
|
|
6450
6580
|
|
|
@@ -6481,6 +6611,7 @@ class SolanaStakingClient {
|
|
|
6481
6611
|
this.leaderboardClient = new LeaderboardClient(this.anchor);
|
|
6482
6612
|
this.outpostClient = new OutpostClient(this.anchor);
|
|
6483
6613
|
this.tokenClient = new TokenClient(this.anchor);
|
|
6614
|
+
this.tokenClient = new TokenClient(this.anchor);
|
|
6484
6615
|
}
|
|
6485
6616
|
get solPubKey() {
|
|
6486
6617
|
return new PublicKey(this.pubKey.data.array);
|
|
@@ -6489,36 +6620,46 @@ class SolanaStakingClient {
|
|
|
6489
6620
|
return this.config.network;
|
|
6490
6621
|
}
|
|
6491
6622
|
async deposit(amountLamports) {
|
|
6492
|
-
if (amountLamports <= BigInt(0))
|
|
6623
|
+
if (amountLamports <= BigInt(0)) {
|
|
6624
|
+
throw new Error("Deposit amount must be greater than zero.");
|
|
6625
|
+
}
|
|
6493
6626
|
const tx = await this.depositClient.buildDepositTx(amountLamports);
|
|
6494
|
-
const { tx: prepared, blockhash, lastValidBlockHeight } = await this.prepareTx(
|
|
6627
|
+
const { tx: prepared, blockhash, lastValidBlockHeight } = await this.prepareTx(
|
|
6628
|
+
tx
|
|
6629
|
+
);
|
|
6495
6630
|
const signed = await this.signTransaction(prepared);
|
|
6496
|
-
|
|
6497
|
-
|
|
6631
|
+
return await this.sendAndConfirmHttp(signed, {
|
|
6632
|
+
blockhash,
|
|
6633
|
+
lastValidBlockHeight
|
|
6634
|
+
});
|
|
6498
6635
|
}
|
|
6499
|
-
async withdraw(
|
|
6636
|
+
async withdraw(_amountLamports) {
|
|
6500
6637
|
throw new Error("Withdraw method not yet implemented.");
|
|
6501
6638
|
}
|
|
6502
6639
|
async stake(amountLamports) {
|
|
6503
|
-
if (amountLamports <= BigInt(0))
|
|
6504
|
-
|
|
6640
|
+
if (amountLamports <= BigInt(0)) {
|
|
6641
|
+
throw new Error("Stake amount must be greater than zero.");
|
|
6642
|
+
}
|
|
6643
|
+
const preIxs = await this.outpostClient.maybeBuildCreateUserAtaIx(
|
|
6644
|
+
this.solPubKey
|
|
6645
|
+
);
|
|
6505
6646
|
const stakeIx = await this.outpostClient.buildStakeLiqsolIx(amountLamports);
|
|
6506
6647
|
const tx = new Transaction().add(...preIxs, stakeIx);
|
|
6507
6648
|
const prepared = await this.prepareTx(tx);
|
|
6508
6649
|
const signed = await this.signTransaction(prepared.tx);
|
|
6509
|
-
|
|
6510
|
-
return result.signature;
|
|
6650
|
+
return await this.sendAndConfirmHttp(signed, prepared);
|
|
6511
6651
|
}
|
|
6512
6652
|
async unstake(amountLamports) {
|
|
6513
|
-
if (amountLamports <= BigInt(0))
|
|
6653
|
+
if (amountLamports <= BigInt(0)) {
|
|
6654
|
+
throw new Error("Unstake amount must be greater than zero.");
|
|
6655
|
+
}
|
|
6514
6656
|
const user = this.solPubKey;
|
|
6515
6657
|
const preIxs = await this.outpostClient.maybeBuildCreateUserAtaIx(user);
|
|
6516
6658
|
const withdrawIx = await this.outpostClient.buildWithdrawStakeIx(amountLamports);
|
|
6517
6659
|
const tx = new Transaction().add(...preIxs, withdrawIx);
|
|
6518
6660
|
const prepared = await this.prepareTx(tx);
|
|
6519
6661
|
const signed = await this.signTransaction(prepared.tx);
|
|
6520
|
-
|
|
6521
|
-
return result.signature;
|
|
6662
|
+
return await this.sendAndConfirmHttp(signed, prepared);
|
|
6522
6663
|
}
|
|
6523
6664
|
async buy(amountLamports, purchaseAsset) {
|
|
6524
6665
|
const user = this.solPubKey;
|
|
@@ -6526,16 +6667,26 @@ class SolanaStakingClient {
|
|
|
6526
6667
|
let preIxs = [];
|
|
6527
6668
|
switch (purchaseAsset) {
|
|
6528
6669
|
case PurchaseAsset.SOL: {
|
|
6529
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
6670
|
+
if (!amountLamports || amountLamports <= BigInt(0)) {
|
|
6530
6671
|
throw new Error("SOL pretoken purchase requires a positive amount.");
|
|
6531
|
-
|
|
6672
|
+
}
|
|
6673
|
+
ix = await this.tokenClient.buildPurchaseWithSolIx(
|
|
6674
|
+
amountLamports,
|
|
6675
|
+
user
|
|
6676
|
+
);
|
|
6532
6677
|
break;
|
|
6533
6678
|
}
|
|
6534
6679
|
case PurchaseAsset.LIQSOL: {
|
|
6535
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
6536
|
-
throw new Error(
|
|
6680
|
+
if (!amountLamports || amountLamports <= BigInt(0)) {
|
|
6681
|
+
throw new Error(
|
|
6682
|
+
"liqSOL pretoken purchase requires a positive amount."
|
|
6683
|
+
);
|
|
6684
|
+
}
|
|
6537
6685
|
preIxs = await this.outpostClient.maybeBuildCreateUserAtaIx(user);
|
|
6538
|
-
ix = await this.tokenClient.buildPurchaseWithLiqsolIx(
|
|
6686
|
+
ix = await this.tokenClient.buildPurchaseWithLiqsolIx(
|
|
6687
|
+
amountLamports,
|
|
6688
|
+
user
|
|
6689
|
+
);
|
|
6539
6690
|
break;
|
|
6540
6691
|
}
|
|
6541
6692
|
case PurchaseAsset.YIELD: {
|
|
@@ -6544,16 +6695,19 @@ class SolanaStakingClient {
|
|
|
6544
6695
|
}
|
|
6545
6696
|
case PurchaseAsset.ETH:
|
|
6546
6697
|
case PurchaseAsset.LIQETH: {
|
|
6547
|
-
throw new Error(
|
|
6698
|
+
throw new Error(
|
|
6699
|
+
"ETH / LIQETH pretoken purchases are not supported on Solana."
|
|
6700
|
+
);
|
|
6548
6701
|
}
|
|
6549
6702
|
default:
|
|
6550
|
-
throw new Error(`Unsupported pretoken purchase asset: ${String(
|
|
6703
|
+
throw new Error(`Unsupported pretoken purchase asset: ${String(
|
|
6704
|
+
purchaseAsset
|
|
6705
|
+
)}`);
|
|
6551
6706
|
}
|
|
6552
6707
|
const tx = new Transaction().add(...preIxs, ix);
|
|
6553
6708
|
const prepared = await this.prepareTx(tx);
|
|
6554
6709
|
const signed = await this.signTransaction(prepared.tx);
|
|
6555
|
-
|
|
6556
|
-
return res.signature;
|
|
6710
|
+
return await this.sendAndConfirmHttp(signed, prepared);
|
|
6557
6711
|
}
|
|
6558
6712
|
async getPortfolio() {
|
|
6559
6713
|
const user = this.solPubKey;
|
|
@@ -6567,7 +6721,12 @@ class SolanaStakingClient {
|
|
|
6567
6721
|
TOKEN_2022_PROGRAM_ID,
|
|
6568
6722
|
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
6569
6723
|
);
|
|
6570
|
-
const [
|
|
6724
|
+
const [
|
|
6725
|
+
nativeLamports,
|
|
6726
|
+
actualBalResp,
|
|
6727
|
+
userRecord,
|
|
6728
|
+
snapshot
|
|
6729
|
+
] = await Promise.all([
|
|
6571
6730
|
this.connection.getBalance(user, "confirmed"),
|
|
6572
6731
|
this.connection.getTokenAccountBalance(userLiqsolAta, "confirmed").catch(() => null),
|
|
6573
6732
|
this.distributionClient.getUserRecord(user).catch(() => null),
|
|
@@ -6575,13 +6734,13 @@ class SolanaStakingClient {
|
|
|
6575
6734
|
]);
|
|
6576
6735
|
const LIQSOL_DECIMALS = 9;
|
|
6577
6736
|
const actualAmountStr = actualBalResp?.value?.amount ?? "0";
|
|
6578
|
-
const trackedAmountStr = userRecord?.trackedBalance
|
|
6737
|
+
const trackedAmountStr = userRecord?.trackedBalance?.toString() ?? "0";
|
|
6579
6738
|
const wireReceipt = snapshot?.wireReceipt ?? null;
|
|
6580
6739
|
const userWarrantRecord = snapshot?.userWarrantRecord ?? null;
|
|
6581
6740
|
const trancheState = snapshot?.trancheState ?? null;
|
|
6582
6741
|
const globalState = snapshot?.globalState ?? null;
|
|
6583
|
-
const stakedAmountStr = wireReceipt?.stakedLiqsol
|
|
6584
|
-
const wireSharesStr = userWarrantRecord?.totalWarrantsPurchased
|
|
6742
|
+
const stakedAmountStr = wireReceipt?.stakedLiqsol?.toString() ?? "0";
|
|
6743
|
+
const wireSharesStr = userWarrantRecord?.totalWarrantsPurchased?.toString() ?? "0";
|
|
6585
6744
|
return {
|
|
6586
6745
|
native: {
|
|
6587
6746
|
amount: BigInt(nativeLamports),
|
|
@@ -6623,72 +6782,75 @@ class SolanaStakingClient {
|
|
|
6623
6782
|
chainID: this.network.chainId
|
|
6624
6783
|
};
|
|
6625
6784
|
}
|
|
6626
|
-
async getTrancheSnapshot() {
|
|
6627
|
-
const
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6785
|
+
async getTrancheSnapshot(options) {
|
|
6786
|
+
const {
|
|
6787
|
+
chainID = SolChainID.WireTestnet,
|
|
6788
|
+
windowBefore,
|
|
6789
|
+
windowAfter
|
|
6790
|
+
} = options ?? {};
|
|
6791
|
+
const [globalState, trancheState] = await Promise.all([
|
|
6792
|
+
this.tokenClient.fetchGlobalState(),
|
|
6793
|
+
this.tokenClient.fetchTrancheState()
|
|
6794
|
+
]);
|
|
6795
|
+
const { price: solPriceUsd, timestamp } = await this.tokenClient.getSolPriceUsdSafe();
|
|
6796
|
+
return buildSolanaTrancheSnapshot({
|
|
6797
|
+
chainID,
|
|
6798
|
+
globalState,
|
|
6799
|
+
trancheState,
|
|
6800
|
+
solPriceUsd,
|
|
6801
|
+
nativePriceTimestamp: timestamp,
|
|
6802
|
+
ladderWindowBefore: windowBefore,
|
|
6803
|
+
ladderWindowAfter: windowAfter
|
|
6804
|
+
});
|
|
6640
6805
|
}
|
|
6641
|
-
async getBuyQuote(amount,
|
|
6642
|
-
if (amount <= BigInt(0)
|
|
6643
|
-
throw new Error("
|
|
6644
|
-
|
|
6645
|
-
const snapshot = await this.
|
|
6646
|
-
|
|
6647
|
-
|
|
6648
|
-
|
|
6806
|
+
async getBuyQuote(amount, asset, opts) {
|
|
6807
|
+
if (asset !== PurchaseAsset.YIELD && amount <= BigInt(0)) {
|
|
6808
|
+
throw new Error("amount must be > 0 for non-YIELD purchases");
|
|
6809
|
+
}
|
|
6810
|
+
const snapshot = await this.getTrancheSnapshot({
|
|
6811
|
+
chainID: opts?.chainID
|
|
6812
|
+
});
|
|
6813
|
+
const wirePriceUsd = snapshot.currentPriceUsd;
|
|
6814
|
+
const solPriceUsd = snapshot.nativePriceUsd;
|
|
6815
|
+
if (!wirePriceUsd || wirePriceUsd <= BigInt(0)) {
|
|
6816
|
+
throw new Error("Invalid WIRE price in tranche snapshot");
|
|
6649
6817
|
}
|
|
6650
|
-
|
|
6651
|
-
|
|
6818
|
+
if (!solPriceUsd || solPriceUsd <= BigInt(0)) {
|
|
6819
|
+
throw new Error("No SOL/USD price available");
|
|
6820
|
+
}
|
|
6821
|
+
const ONE_E9 = BigInt(LAMPORTS_PER_SOL$1);
|
|
6822
|
+
const ONE_E8 = BigInt(1e8);
|
|
6652
6823
|
let notionalUsd;
|
|
6653
|
-
|
|
6654
|
-
switch (purchaseAsset) {
|
|
6824
|
+
switch (asset) {
|
|
6655
6825
|
case PurchaseAsset.SOL: {
|
|
6656
|
-
|
|
6657
|
-
notionalUsd = new BN(amount).mul(solPriceUsd).div(new BN(1e9));
|
|
6658
|
-
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
6826
|
+
notionalUsd = amount * solPriceUsd / ONE_E9;
|
|
6659
6827
|
break;
|
|
6660
6828
|
}
|
|
6661
6829
|
case PurchaseAsset.LIQSOL: {
|
|
6662
|
-
|
|
6663
|
-
notionalUsd = new BN(amount).mul(liqsolPriceUsd).div(new BN(1e9));
|
|
6664
|
-
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
6830
|
+
notionalUsd = amount * solPriceUsd / ONE_E9;
|
|
6665
6831
|
break;
|
|
6666
6832
|
}
|
|
6667
6833
|
case PurchaseAsset.YIELD: {
|
|
6668
|
-
|
|
6669
|
-
notionalUsd = new BN(amount).mul(solPriceUsd).div(new BN(1e9));
|
|
6670
|
-
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
6834
|
+
notionalUsd = amount * solPriceUsd / ONE_E9;
|
|
6671
6835
|
break;
|
|
6672
6836
|
}
|
|
6673
6837
|
case PurchaseAsset.ETH:
|
|
6674
6838
|
case PurchaseAsset.LIQETH:
|
|
6675
|
-
throw new Error("getBuyQuote for ETH/LIQETH is not supported on Solana
|
|
6839
|
+
throw new Error("getBuyQuote for ETH/LIQETH is not supported on Solana");
|
|
6676
6840
|
default:
|
|
6677
|
-
throw new Error(`Unsupported purchase asset: ${String(
|
|
6841
|
+
throw new Error(`Unsupported purchase asset: ${String(asset)}`);
|
|
6678
6842
|
}
|
|
6843
|
+
const numerator = notionalUsd * ONE_E8;
|
|
6844
|
+
const wireShares = numerator === BigInt(0) ? BigInt(0) : (numerator + wirePriceUsd - BigInt(1)) / wirePriceUsd;
|
|
6679
6845
|
return {
|
|
6680
|
-
purchaseAsset,
|
|
6846
|
+
purchaseAsset: asset,
|
|
6681
6847
|
amountIn: amount,
|
|
6682
|
-
wireShares
|
|
6683
|
-
wireDecimals,
|
|
6684
|
-
wirePriceUsd
|
|
6685
|
-
notionalUsd
|
|
6848
|
+
wireShares,
|
|
6849
|
+
wireDecimals: 8,
|
|
6850
|
+
wirePriceUsd,
|
|
6851
|
+
notionalUsd
|
|
6686
6852
|
};
|
|
6687
6853
|
}
|
|
6688
|
-
calculateExpectedWarrants(notionalUsd, wirePriceUsd) {
|
|
6689
|
-
const SCALE = new BN("100000000");
|
|
6690
|
-
return notionalUsd.mul(SCALE).div(wirePriceUsd);
|
|
6691
|
-
}
|
|
6692
6854
|
async getUserRecord() {
|
|
6693
6855
|
return this.distributionClient.getUserRecord(this.solPubKey);
|
|
6694
6856
|
}
|
|
@@ -6697,25 +6859,37 @@ class SolanaStakingClient {
|
|
|
6697
6859
|
if (!build.canSucceed || !build.transaction) {
|
|
6698
6860
|
throw new Error(build.reason ?? "Unable to build Correct&Register transaction");
|
|
6699
6861
|
}
|
|
6700
|
-
const { tx, blockhash, lastValidBlockHeight } = await this.prepareTx(
|
|
6862
|
+
const { tx, blockhash, lastValidBlockHeight } = await this.prepareTx(
|
|
6863
|
+
build.transaction
|
|
6864
|
+
);
|
|
6701
6865
|
const signed = await this.signTransaction(tx);
|
|
6702
|
-
const
|
|
6703
|
-
|
|
6866
|
+
const signature = await this.sendAndConfirmHttp(signed, {
|
|
6867
|
+
blockhash,
|
|
6868
|
+
lastValidBlockHeight
|
|
6869
|
+
});
|
|
6870
|
+
return signature;
|
|
6704
6871
|
}
|
|
6705
6872
|
async sendAndConfirmHttp(signed, ctx) {
|
|
6706
|
-
const signature = await this.connection.sendRawTransaction(
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6873
|
+
const signature = await this.connection.sendRawTransaction(
|
|
6874
|
+
signed.serialize(),
|
|
6875
|
+
{
|
|
6876
|
+
skipPreflight: false,
|
|
6877
|
+
preflightCommitment: commitment,
|
|
6878
|
+
maxRetries: 3
|
|
6879
|
+
}
|
|
6880
|
+
);
|
|
6711
6881
|
const conf = await this.connection.confirmTransaction(
|
|
6712
|
-
{
|
|
6882
|
+
{
|
|
6883
|
+
signature,
|
|
6884
|
+
blockhash: ctx.blockhash,
|
|
6885
|
+
lastValidBlockHeight: ctx.lastValidBlockHeight
|
|
6886
|
+
},
|
|
6713
6887
|
commitment
|
|
6714
6888
|
);
|
|
6715
6889
|
if (conf.value.err) {
|
|
6716
6890
|
throw new Error(`Transaction failed: ${JSON.stringify(conf.value.err)}`);
|
|
6717
6891
|
}
|
|
6718
|
-
return
|
|
6892
|
+
return signature;
|
|
6719
6893
|
}
|
|
6720
6894
|
async signTransaction(tx) {
|
|
6721
6895
|
return this.anchor.wallet.signTransaction(tx);
|
|
@@ -24691,5 +24865,5 @@ var types = /*#__PURE__*/Object.freeze({
|
|
|
24691
24865
|
__proto__: null
|
|
24692
24866
|
});
|
|
24693
24867
|
|
|
24694
|
-
export { ADDRESSES, CHAINLINK_FEED, CHAINLINK_PROGRAM, CONTRACTS, DEFAULT_AVERAGE_PAY_RATE, DEFAULT_PAY_RATE_LOOKBACK, DepositClient$1 as DepositClient, DistributionClient, EPHEMERAL_RENT_EXEMPTION, ERC1155Abi, ERC20Abi, ERC721Abi, types$1 as ETH, EthereumContractService, EthereumStakingClient, LAMPORTS_PER_SOL, LIQSOL_CORE, LIQSOL_TOKEN, LeaderboardClient, OutpostClient, PAY_RATE_SCALE_FACTOR, PDA_SEEDS, PROGRAM_IDS, PurchaseAsset, types as SOL, SolanaStakingClient, Staker, TokenClient, VALIDATOR_LEADERBOARD, airdropSol, buildOutpostAccounts, calculateExpectedFee, deriveBarConfigPda, deriveBondLevelPda, deriveBondedActorPda, deriveBucketAuthorityPda, deriveDepositAuthorityPda, deriveDistributionStatePda, deriveEphemeralStakeAddress, deriveLeaderboardStatePda, deriveLiqsolMintAuthorityPda, deriveLiqsolMintPda, deriveOutpostGlobalStatePda, deriveOutpostPoolAuthorityPda, derivePayRateHistoryPda, derivePayoutStatePda, derivePoolUserRecordPda, derivePriceHistoryPda, deriveReservePoolPda, deriveSolBucketPda, deriveStakeControllerStatePda, deriveStakeControllerVaultPda, deriveTrancheStatePda, deriveUserRecordPda, deriveUserUserRecordPda, deriveUserWarrantRecordPda, deriveValidatorRecordPda, deriveVaultPda, deriveWireReceiptPda, generateRandomDepositAmount, generateTestKeypair, getAveragePayRate, getBucketLiqSolBalance, getEpochSnapshot, getErrorMessage, getLiqsolCoreProgram, getPayoutStateRaw, getReservePoolBalance, getStakeControllerStateRaw, getUserLiqSolBalance, getUserRecordRaw, lamportsToSol, msToEpochEnd, previewDepositEffects, scheduledInstruction, sleep, solToLamports, waitForConfirmation, waitUntilSafeToExecuteFunction };
|
|
24868
|
+
export { ADDRESSES, CHAINLINK_FEED, CHAINLINK_PROGRAM, CONTRACTS, DEFAULT_AVERAGE_PAY_RATE, DEFAULT_PAY_RATE_LOOKBACK, DepositClient$1 as DepositClient, DistributionClient, EPHEMERAL_RENT_EXEMPTION, ERC1155Abi, ERC20Abi, ERC721Abi, types$1 as ETH, EthereumContractService, EthereumStakingClient, LAMPORTS_PER_SOL, LIQSOL_CORE, LIQSOL_TOKEN, LeaderboardClient, OutpostClient, PAY_RATE_SCALE_FACTOR, PDA_SEEDS, PROGRAM_IDS, PurchaseAsset, types as SOL, SolanaStakingClient, Staker, TokenClient, VALIDATOR_LEADERBOARD, airdropSol, buildOutpostAccounts, buildSolanaTrancheLadder, buildSolanaTrancheSnapshot, calculateExpectedFee, deriveBarConfigPda, deriveBondLevelPda, deriveBondedActorPda, deriveBucketAuthorityPda, deriveDepositAuthorityPda, deriveDistributionStatePda, deriveEphemeralStakeAddress, deriveLeaderboardStatePda, deriveLiqsolMintAuthorityPda, deriveLiqsolMintPda, deriveOutpostGlobalStatePda, deriveOutpostPoolAuthorityPda, derivePayRateHistoryPda, derivePayoutStatePda, derivePoolUserRecordPda, derivePriceHistoryPda, deriveReservePoolPda, deriveSolBucketPda, deriveStakeControllerStatePda, deriveStakeControllerVaultPda, deriveTrancheStatePda, deriveUserRecordPda, deriveUserUserRecordPda, deriveUserWarrantRecordPda, deriveValidatorRecordPda, deriveVaultPda, deriveWireReceiptPda, generateRandomDepositAmount, generateTestKeypair, getAveragePayRate, getBucketLiqSolBalance, getEpochSnapshot, getErrorMessage, getLiqsolCoreProgram, getPayoutStateRaw, getReservePoolBalance, getStakeControllerStateRaw, getUserLiqSolBalance, getUserRecordRaw, lamportsToSol, msToEpochEnd, previewDepositEffects, scheduledInstruction, sleep, solToLamports, toBigint, tokensToShares, waitForConfirmation, waitUntilSafeToExecuteFunction };
|
|
24695
24869
|
//# sourceMappingURL=stake.m.js.map
|