@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.js
CHANGED
|
@@ -5888,6 +5888,129 @@ var __async$7 = (__this, __arguments, generator) => {
|
|
|
5888
5888
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
5889
5889
|
});
|
|
5890
5890
|
};
|
|
5891
|
+
const INDEX_SCALE = BigInt(1e12);
|
|
5892
|
+
BigInt(1e8);
|
|
5893
|
+
const BPS = BigInt(1e4);
|
|
5894
|
+
function toBigint(x) {
|
|
5895
|
+
if (typeof x === "bigint") return x;
|
|
5896
|
+
if (typeof x === "number") return BigInt(x);
|
|
5897
|
+
return BigInt(x.toString());
|
|
5898
|
+
}
|
|
5899
|
+
function tokensToShares(amount, currentIndex) {
|
|
5900
|
+
if (amount === BigInt(0)) return BigInt(0);
|
|
5901
|
+
const num = amount * INDEX_SCALE;
|
|
5902
|
+
const q = num / currentIndex;
|
|
5903
|
+
const r = num % currentIndex;
|
|
5904
|
+
return r === BigInt(0) ? q : q + BigInt(1);
|
|
5905
|
+
}
|
|
5906
|
+
function growOnce(value, growthBps) {
|
|
5907
|
+
const g = BigInt(growthBps);
|
|
5908
|
+
return (value * (BPS + g) + BPS / BigInt(2)) / BPS;
|
|
5909
|
+
}
|
|
5910
|
+
function shrinkOnce(value, growthBps) {
|
|
5911
|
+
const g = BigInt(growthBps);
|
|
5912
|
+
return (value * BPS + (BPS + g) / BigInt(2)) / (BPS + g);
|
|
5913
|
+
}
|
|
5914
|
+
function buildSolanaTrancheLadder(options) {
|
|
5915
|
+
const {
|
|
5916
|
+
currentTranche,
|
|
5917
|
+
initialTrancheSupply,
|
|
5918
|
+
currentTrancheSupply,
|
|
5919
|
+
currentPriceUsd,
|
|
5920
|
+
supplyGrowthBps,
|
|
5921
|
+
priceGrowthBps,
|
|
5922
|
+
windowBefore = 5,
|
|
5923
|
+
windowAfter = 5
|
|
5924
|
+
} = options;
|
|
5925
|
+
const startId = Math.max(0, currentTranche - windowBefore);
|
|
5926
|
+
const endId = currentTranche + windowAfter;
|
|
5927
|
+
const capacity = new Map();
|
|
5928
|
+
const price = new Map();
|
|
5929
|
+
capacity.set(currentTranche, initialTrancheSupply);
|
|
5930
|
+
price.set(currentTranche, currentPriceUsd);
|
|
5931
|
+
for (let id = currentTranche + 1; id <= endId; id++) {
|
|
5932
|
+
const prevCap = capacity.get(id - 1);
|
|
5933
|
+
const prevPrice = price.get(id - 1);
|
|
5934
|
+
capacity.set(id, growOnce(prevCap, supplyGrowthBps));
|
|
5935
|
+
price.set(id, growOnce(prevPrice, priceGrowthBps));
|
|
5936
|
+
}
|
|
5937
|
+
for (let id = currentTranche - 1; id >= startId; id--) {
|
|
5938
|
+
const nextCap = capacity.get(id + 1);
|
|
5939
|
+
const nextPrice = price.get(id + 1);
|
|
5940
|
+
capacity.set(id, shrinkOnce(nextCap, supplyGrowthBps));
|
|
5941
|
+
price.set(id, shrinkOnce(nextPrice, priceGrowthBps));
|
|
5942
|
+
}
|
|
5943
|
+
const ladder = [];
|
|
5944
|
+
for (let id = startId; id <= endId; id++) {
|
|
5945
|
+
const cap = capacity.get(id);
|
|
5946
|
+
let sold;
|
|
5947
|
+
if (id < currentTranche) {
|
|
5948
|
+
sold = cap;
|
|
5949
|
+
} else if (id === currentTranche) {
|
|
5950
|
+
sold = cap - currentTrancheSupply;
|
|
5951
|
+
} else {
|
|
5952
|
+
sold = BigInt(0);
|
|
5953
|
+
}
|
|
5954
|
+
ladder.push({
|
|
5955
|
+
id,
|
|
5956
|
+
capacity: cap,
|
|
5957
|
+
sold,
|
|
5958
|
+
remaining: cap - sold,
|
|
5959
|
+
priceUsd: price.get(id)
|
|
5960
|
+
});
|
|
5961
|
+
}
|
|
5962
|
+
return ladder;
|
|
5963
|
+
}
|
|
5964
|
+
function buildSolanaTrancheSnapshot(options) {
|
|
5965
|
+
const {
|
|
5966
|
+
chainID,
|
|
5967
|
+
globalState,
|
|
5968
|
+
trancheState,
|
|
5969
|
+
solPriceUsd,
|
|
5970
|
+
nativePriceTimestamp,
|
|
5971
|
+
ladderWindowBefore,
|
|
5972
|
+
ladderWindowAfter
|
|
5973
|
+
} = options;
|
|
5974
|
+
const currentIndex = toBigint(globalState.currentIndex);
|
|
5975
|
+
const totalShares = toBigint(globalState.totalShares);
|
|
5976
|
+
const currentTranche = trancheState.currentTrancheNumber.toNumber();
|
|
5977
|
+
const currentTrancheSupply = toBigint(trancheState.currentTrancheSupply);
|
|
5978
|
+
const initialTrancheSupply = toBigint(trancheState.initialTrancheSupply);
|
|
5979
|
+
const totalWarrantsSold = toBigint(trancheState.totalWarrantsSold);
|
|
5980
|
+
const currentPriceUsd = toBigint(trancheState.currentTranchePriceUsd);
|
|
5981
|
+
const supplyGrowthBps = trancheState.supplyGrowthBps;
|
|
5982
|
+
const priceGrowthBps = trancheState.priceGrowthBps;
|
|
5983
|
+
const minPriceUsd = trancheState.minPriceUsd ? toBigint(trancheState.minPriceUsd) : void 0;
|
|
5984
|
+
const maxPriceUsd = trancheState.maxPriceUsd ? toBigint(trancheState.maxPriceUsd) : void 0;
|
|
5985
|
+
const ladder = buildSolanaTrancheLadder({
|
|
5986
|
+
currentTranche,
|
|
5987
|
+
initialTrancheSupply,
|
|
5988
|
+
currentTrancheSupply,
|
|
5989
|
+
totalWarrantsSold,
|
|
5990
|
+
currentPriceUsd,
|
|
5991
|
+
supplyGrowthBps,
|
|
5992
|
+
priceGrowthBps,
|
|
5993
|
+
windowBefore: ladderWindowBefore,
|
|
5994
|
+
windowAfter: ladderWindowAfter
|
|
5995
|
+
});
|
|
5996
|
+
return {
|
|
5997
|
+
chainID,
|
|
5998
|
+
currentIndex,
|
|
5999
|
+
totalShares,
|
|
6000
|
+
currentTranche,
|
|
6001
|
+
currentPriceUsd,
|
|
6002
|
+
minPriceUsd,
|
|
6003
|
+
maxPriceUsd,
|
|
6004
|
+
supplyGrowthBps,
|
|
6005
|
+
priceGrowthBps,
|
|
6006
|
+
currentTrancheSupply,
|
|
6007
|
+
initialTrancheSupply,
|
|
6008
|
+
totalWarrantsSold,
|
|
6009
|
+
nativePriceUsd: solPriceUsd,
|
|
6010
|
+
nativePriceTimestamp,
|
|
6011
|
+
ladder
|
|
6012
|
+
};
|
|
6013
|
+
}
|
|
5891
6014
|
let _liqsolCoreProgram = null;
|
|
5892
6015
|
function getLiqsolCoreProgram(connection) {
|
|
5893
6016
|
if (_liqsolCoreProgram && _liqsolCoreProgram.provider.connection === connection) {
|
|
@@ -6617,13 +6740,13 @@ class TokenClient {
|
|
|
6617
6740
|
}
|
|
6618
6741
|
fetchGlobalState() {
|
|
6619
6742
|
return __async$5(this, null, function* () {
|
|
6620
|
-
const { globalState } = yield this.getAccounts(this.
|
|
6743
|
+
const { globalState } = yield this.getAccounts(this.wallet.publicKey);
|
|
6621
6744
|
return this.program.account.globalState.fetch(globalState);
|
|
6622
6745
|
});
|
|
6623
6746
|
}
|
|
6624
6747
|
fetchTrancheState() {
|
|
6625
6748
|
return __async$5(this, null, function* () {
|
|
6626
|
-
const { trancheState } = yield this.getAccounts(this.
|
|
6749
|
+
const { trancheState } = yield this.getAccounts(this.wallet.publicKey);
|
|
6627
6750
|
return this.program.account.trancheState.fetch(trancheState);
|
|
6628
6751
|
});
|
|
6629
6752
|
}
|
|
@@ -6706,36 +6829,45 @@ class TokenClient {
|
|
|
6706
6829
|
payRateHistory: a.payRateHistory,
|
|
6707
6830
|
bucketAuthority: a.bucketAuthority,
|
|
6708
6831
|
bucketTokenAccount: a.bucketTokenAccount,
|
|
6709
|
-
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
6710
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
6711
6832
|
trancheState: a.trancheState,
|
|
6712
6833
|
userWarrantRecord: a.userWarrantRecord,
|
|
6713
6834
|
chainlinkFeed: a.chainLinkFeed,
|
|
6714
|
-
chainlinkProgram: a.chainLinkProgram
|
|
6835
|
+
chainlinkProgram: a.chainLinkProgram,
|
|
6836
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
6837
|
+
systemProgram: web3_js.SystemProgram.programId
|
|
6715
6838
|
}).instruction();
|
|
6716
6839
|
});
|
|
6717
6840
|
}
|
|
6841
|
+
getSolPriceUsdSafe() {
|
|
6842
|
+
return __async$5(this, null, function* () {
|
|
6843
|
+
try {
|
|
6844
|
+
const price = yield this.getSolPriceUsd();
|
|
6845
|
+
return { price, timestamp: void 0 };
|
|
6846
|
+
} catch (e) {
|
|
6847
|
+
return { price: void 0, timestamp: void 0 };
|
|
6848
|
+
}
|
|
6849
|
+
});
|
|
6850
|
+
}
|
|
6718
6851
|
getSolPriceUsd() {
|
|
6719
6852
|
return __async$5(this, null, function* () {
|
|
6720
6853
|
const priceHistoryPda = derivePriceHistoryPda();
|
|
6721
6854
|
const history = yield this.program.account.priceHistory.fetch(
|
|
6722
6855
|
priceHistoryPda
|
|
6723
6856
|
);
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
if (!prices || prices.length === 0 || count === 0) {
|
|
6857
|
+
const { prices, nextIndex, count, windowSize } = history;
|
|
6858
|
+
if (!prices || prices.length === 0 || !count) {
|
|
6727
6859
|
throw new Error("Price history is empty \u2013 no SOL price available");
|
|
6728
6860
|
}
|
|
6729
6861
|
const capacity = prices.length || windowSize;
|
|
6730
|
-
if (capacity
|
|
6862
|
+
if (!capacity) {
|
|
6731
6863
|
throw new Error("Price history capacity is zero \u2013 check account layout");
|
|
6732
6864
|
}
|
|
6733
6865
|
const lastIndex = nextIndex === 0 ? capacity - 1 : nextIndex - 1;
|
|
6734
|
-
const
|
|
6735
|
-
if (!anchor.BN.isBN(
|
|
6866
|
+
const latest = prices[lastIndex];
|
|
6867
|
+
if (!anchor.BN.isBN(latest)) {
|
|
6736
6868
|
throw new Error("Latest price entry is not a BN \u2013 check IDL/decoder");
|
|
6737
6869
|
}
|
|
6738
|
-
return
|
|
6870
|
+
return BigInt(latest.toString());
|
|
6739
6871
|
});
|
|
6740
6872
|
}
|
|
6741
6873
|
}
|
|
@@ -6797,6 +6929,7 @@ class SolanaStakingClient {
|
|
|
6797
6929
|
this.leaderboardClient = new LeaderboardClient(this.anchor);
|
|
6798
6930
|
this.outpostClient = new OutpostClient(this.anchor);
|
|
6799
6931
|
this.tokenClient = new TokenClient(this.anchor);
|
|
6932
|
+
this.tokenClient = new TokenClient(this.anchor);
|
|
6800
6933
|
}
|
|
6801
6934
|
get solPubKey() {
|
|
6802
6935
|
return new web3_js.PublicKey(this.pubKey.data.array);
|
|
@@ -6806,42 +6939,52 @@ class SolanaStakingClient {
|
|
|
6806
6939
|
}
|
|
6807
6940
|
deposit(amountLamports) {
|
|
6808
6941
|
return __async$4(this, null, function* () {
|
|
6809
|
-
if (amountLamports <= BigInt(0))
|
|
6942
|
+
if (amountLamports <= BigInt(0)) {
|
|
6943
|
+
throw new Error("Deposit amount must be greater than zero.");
|
|
6944
|
+
}
|
|
6810
6945
|
const tx = yield this.depositClient.buildDepositTx(amountLamports);
|
|
6811
|
-
const { tx: prepared, blockhash, lastValidBlockHeight } = yield this.prepareTx(
|
|
6946
|
+
const { tx: prepared, blockhash, lastValidBlockHeight } = yield this.prepareTx(
|
|
6947
|
+
tx
|
|
6948
|
+
);
|
|
6812
6949
|
const signed = yield this.signTransaction(prepared);
|
|
6813
|
-
|
|
6814
|
-
|
|
6950
|
+
return yield this.sendAndConfirmHttp(signed, {
|
|
6951
|
+
blockhash,
|
|
6952
|
+
lastValidBlockHeight
|
|
6953
|
+
});
|
|
6815
6954
|
});
|
|
6816
6955
|
}
|
|
6817
|
-
withdraw(
|
|
6956
|
+
withdraw(_amountLamports) {
|
|
6818
6957
|
return __async$4(this, null, function* () {
|
|
6819
6958
|
throw new Error("Withdraw method not yet implemented.");
|
|
6820
6959
|
});
|
|
6821
6960
|
}
|
|
6822
6961
|
stake(amountLamports) {
|
|
6823
6962
|
return __async$4(this, null, function* () {
|
|
6824
|
-
if (amountLamports <= BigInt(0))
|
|
6825
|
-
|
|
6963
|
+
if (amountLamports <= BigInt(0)) {
|
|
6964
|
+
throw new Error("Stake amount must be greater than zero.");
|
|
6965
|
+
}
|
|
6966
|
+
const preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(
|
|
6967
|
+
this.solPubKey
|
|
6968
|
+
);
|
|
6826
6969
|
const stakeIx = yield this.outpostClient.buildStakeLiqsolIx(amountLamports);
|
|
6827
6970
|
const tx = new web3_js.Transaction().add(...preIxs, stakeIx);
|
|
6828
6971
|
const prepared = yield this.prepareTx(tx);
|
|
6829
6972
|
const signed = yield this.signTransaction(prepared.tx);
|
|
6830
|
-
|
|
6831
|
-
return result.signature;
|
|
6973
|
+
return yield this.sendAndConfirmHttp(signed, prepared);
|
|
6832
6974
|
});
|
|
6833
6975
|
}
|
|
6834
6976
|
unstake(amountLamports) {
|
|
6835
6977
|
return __async$4(this, null, function* () {
|
|
6836
|
-
if (amountLamports <= BigInt(0))
|
|
6978
|
+
if (amountLamports <= BigInt(0)) {
|
|
6979
|
+
throw new Error("Unstake amount must be greater than zero.");
|
|
6980
|
+
}
|
|
6837
6981
|
const user = this.solPubKey;
|
|
6838
6982
|
const preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(user);
|
|
6839
6983
|
const withdrawIx = yield this.outpostClient.buildWithdrawStakeIx(amountLamports);
|
|
6840
6984
|
const tx = new web3_js.Transaction().add(...preIxs, withdrawIx);
|
|
6841
6985
|
const prepared = yield this.prepareTx(tx);
|
|
6842
6986
|
const signed = yield this.signTransaction(prepared.tx);
|
|
6843
|
-
|
|
6844
|
-
return result.signature;
|
|
6987
|
+
return yield this.sendAndConfirmHttp(signed, prepared);
|
|
6845
6988
|
});
|
|
6846
6989
|
}
|
|
6847
6990
|
buy(amountLamports, purchaseAsset) {
|
|
@@ -6851,16 +6994,26 @@ class SolanaStakingClient {
|
|
|
6851
6994
|
let preIxs = [];
|
|
6852
6995
|
switch (purchaseAsset) {
|
|
6853
6996
|
case PurchaseAsset.SOL: {
|
|
6854
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
6997
|
+
if (!amountLamports || amountLamports <= BigInt(0)) {
|
|
6855
6998
|
throw new Error("SOL pretoken purchase requires a positive amount.");
|
|
6856
|
-
|
|
6999
|
+
}
|
|
7000
|
+
ix = yield this.tokenClient.buildPurchaseWithSolIx(
|
|
7001
|
+
amountLamports,
|
|
7002
|
+
user
|
|
7003
|
+
);
|
|
6857
7004
|
break;
|
|
6858
7005
|
}
|
|
6859
7006
|
case PurchaseAsset.LIQSOL: {
|
|
6860
|
-
if (!amountLamports || amountLamports <= BigInt(0))
|
|
6861
|
-
throw new Error(
|
|
7007
|
+
if (!amountLamports || amountLamports <= BigInt(0)) {
|
|
7008
|
+
throw new Error(
|
|
7009
|
+
"liqSOL pretoken purchase requires a positive amount."
|
|
7010
|
+
);
|
|
7011
|
+
}
|
|
6862
7012
|
preIxs = yield this.outpostClient.maybeBuildCreateUserAtaIx(user);
|
|
6863
|
-
ix = yield this.tokenClient.buildPurchaseWithLiqsolIx(
|
|
7013
|
+
ix = yield this.tokenClient.buildPurchaseWithLiqsolIx(
|
|
7014
|
+
amountLamports,
|
|
7015
|
+
user
|
|
7016
|
+
);
|
|
6864
7017
|
break;
|
|
6865
7018
|
}
|
|
6866
7019
|
case PurchaseAsset.YIELD: {
|
|
@@ -6869,21 +7022,24 @@ class SolanaStakingClient {
|
|
|
6869
7022
|
}
|
|
6870
7023
|
case PurchaseAsset.ETH:
|
|
6871
7024
|
case PurchaseAsset.LIQETH: {
|
|
6872
|
-
throw new Error(
|
|
7025
|
+
throw new Error(
|
|
7026
|
+
"ETH / LIQETH pretoken purchases are not supported on Solana."
|
|
7027
|
+
);
|
|
6873
7028
|
}
|
|
6874
7029
|
default:
|
|
6875
|
-
throw new Error(`Unsupported pretoken purchase asset: ${String(
|
|
7030
|
+
throw new Error(`Unsupported pretoken purchase asset: ${String(
|
|
7031
|
+
purchaseAsset
|
|
7032
|
+
)}`);
|
|
6876
7033
|
}
|
|
6877
7034
|
const tx = new web3_js.Transaction().add(...preIxs, ix);
|
|
6878
7035
|
const prepared = yield this.prepareTx(tx);
|
|
6879
7036
|
const signed = yield this.signTransaction(prepared.tx);
|
|
6880
|
-
|
|
6881
|
-
return res.signature;
|
|
7037
|
+
return yield this.sendAndConfirmHttp(signed, prepared);
|
|
6882
7038
|
});
|
|
6883
7039
|
}
|
|
6884
7040
|
getPortfolio() {
|
|
6885
7041
|
return __async$4(this, null, function* () {
|
|
6886
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
7042
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
6887
7043
|
const user = this.solPubKey;
|
|
6888
7044
|
const reservePoolPDA = deriveReservePoolPda();
|
|
6889
7045
|
const vaultPDA = deriveVaultPda();
|
|
@@ -6895,7 +7051,12 @@ class SolanaStakingClient {
|
|
|
6895
7051
|
splToken.TOKEN_2022_PROGRAM_ID,
|
|
6896
7052
|
splToken.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
6897
7053
|
);
|
|
6898
|
-
const [
|
|
7054
|
+
const [
|
|
7055
|
+
nativeLamports,
|
|
7056
|
+
actualBalResp,
|
|
7057
|
+
userRecord,
|
|
7058
|
+
snapshot
|
|
7059
|
+
] = yield Promise.all([
|
|
6899
7060
|
this.connection.getBalance(user, "confirmed"),
|
|
6900
7061
|
this.connection.getTokenAccountBalance(userLiqsolAta, "confirmed").catch(() => null),
|
|
6901
7062
|
this.distributionClient.getUserRecord(user).catch(() => null),
|
|
@@ -6903,13 +7064,13 @@ class SolanaStakingClient {
|
|
|
6903
7064
|
]);
|
|
6904
7065
|
const LIQSOL_DECIMALS = 9;
|
|
6905
7066
|
const actualAmountStr = (_b = (_a = actualBalResp == null ? void 0 : actualBalResp.value) == null ? void 0 : _a.amount) != null ? _b : "0";
|
|
6906
|
-
const trackedAmountStr = (userRecord == null ? void 0 : userRecord.trackedBalance) ?
|
|
6907
|
-
const wireReceipt = (
|
|
6908
|
-
const userWarrantRecord = (
|
|
6909
|
-
const trancheState = (
|
|
6910
|
-
const globalState = (
|
|
6911
|
-
const stakedAmountStr = (wireReceipt == null ? void 0 : wireReceipt.stakedLiqsol) ?
|
|
6912
|
-
const wireSharesStr = (userWarrantRecord == null ? void 0 : userWarrantRecord.totalWarrantsPurchased) ?
|
|
7067
|
+
const trackedAmountStr = (_d = (_c = userRecord == null ? void 0 : userRecord.trackedBalance) == null ? void 0 : _c.toString()) != null ? _d : "0";
|
|
7068
|
+
const wireReceipt = (_e = snapshot == null ? void 0 : snapshot.wireReceipt) != null ? _e : null;
|
|
7069
|
+
const userWarrantRecord = (_f = snapshot == null ? void 0 : snapshot.userWarrantRecord) != null ? _f : null;
|
|
7070
|
+
const trancheState = (_g = snapshot == null ? void 0 : snapshot.trancheState) != null ? _g : null;
|
|
7071
|
+
const globalState = (_h = snapshot == null ? void 0 : snapshot.globalState) != null ? _h : null;
|
|
7072
|
+
const stakedAmountStr = (_j = (_i = wireReceipt == null ? void 0 : wireReceipt.stakedLiqsol) == null ? void 0 : _i.toString()) != null ? _j : "0";
|
|
7073
|
+
const wireSharesStr = (_l = (_k = userWarrantRecord == null ? void 0 : userWarrantRecord.totalWarrantsPurchased) == null ? void 0 : _k.toString()) != null ? _l : "0";
|
|
6913
7074
|
return {
|
|
6914
7075
|
native: {
|
|
6915
7076
|
amount: BigInt(nativeLamports),
|
|
@@ -6943,85 +7104,88 @@ class SolanaStakingClient {
|
|
|
6943
7104
|
vaultPDA: vaultPDA.toBase58(),
|
|
6944
7105
|
wireReceipt,
|
|
6945
7106
|
userWarrantRecord,
|
|
6946
|
-
globalIndex: (
|
|
6947
|
-
totalShares: (
|
|
6948
|
-
currentTrancheNumber: (
|
|
6949
|
-
currentTranchePriceUsd: (
|
|
7107
|
+
globalIndex: (_m = globalState == null ? void 0 : globalState.currentIndex) == null ? void 0 : _m.toString(),
|
|
7108
|
+
totalShares: (_n = globalState == null ? void 0 : globalState.totalShares) == null ? void 0 : _n.toString(),
|
|
7109
|
+
currentTrancheNumber: (_o = trancheState == null ? void 0 : trancheState.currentTrancheNumber) == null ? void 0 : _o.toString(),
|
|
7110
|
+
currentTranchePriceUsd: (_p = trancheState == null ? void 0 : trancheState.currentTranchePriceUsd) == null ? void 0 : _p.toString()
|
|
6950
7111
|
},
|
|
6951
7112
|
chainID: this.network.chainId
|
|
6952
7113
|
};
|
|
6953
7114
|
});
|
|
6954
7115
|
}
|
|
6955
|
-
getTrancheSnapshot() {
|
|
7116
|
+
getTrancheSnapshot(options) {
|
|
6956
7117
|
return __async$4(this, null, function* () {
|
|
6957
|
-
const
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
7118
|
+
const {
|
|
7119
|
+
chainID = core.SolChainID.WireTestnet,
|
|
7120
|
+
windowBefore,
|
|
7121
|
+
windowAfter
|
|
7122
|
+
} = options != null ? options : {};
|
|
7123
|
+
const [globalState, trancheState] = yield Promise.all([
|
|
7124
|
+
this.tokenClient.fetchGlobalState(),
|
|
7125
|
+
this.tokenClient.fetchTrancheState()
|
|
7126
|
+
]);
|
|
7127
|
+
const { price: solPriceUsd, timestamp } = yield this.tokenClient.getSolPriceUsdSafe();
|
|
7128
|
+
return buildSolanaTrancheSnapshot({
|
|
7129
|
+
chainID,
|
|
7130
|
+
globalState,
|
|
7131
|
+
trancheState,
|
|
7132
|
+
solPriceUsd,
|
|
7133
|
+
nativePriceTimestamp: timestamp,
|
|
7134
|
+
ladderWindowBefore: windowBefore,
|
|
7135
|
+
ladderWindowAfter: windowAfter
|
|
7136
|
+
});
|
|
6970
7137
|
});
|
|
6971
7138
|
}
|
|
6972
|
-
getBuyQuote(amount,
|
|
7139
|
+
getBuyQuote(amount, asset, opts) {
|
|
6973
7140
|
return __async$4(this, null, function* () {
|
|
6974
|
-
if (amount <= BigInt(0)
|
|
6975
|
-
throw new Error("
|
|
6976
|
-
|
|
6977
|
-
const snapshot = yield this.
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
7141
|
+
if (asset !== PurchaseAsset.YIELD && amount <= BigInt(0)) {
|
|
7142
|
+
throw new Error("amount must be > 0 for non-YIELD purchases");
|
|
7143
|
+
}
|
|
7144
|
+
const snapshot = yield this.getTrancheSnapshot({
|
|
7145
|
+
chainID: opts == null ? void 0 : opts.chainID
|
|
7146
|
+
});
|
|
7147
|
+
const wirePriceUsd = snapshot.currentPriceUsd;
|
|
7148
|
+
const solPriceUsd = snapshot.nativePriceUsd;
|
|
7149
|
+
if (!wirePriceUsd || wirePriceUsd <= BigInt(0)) {
|
|
7150
|
+
throw new Error("Invalid WIRE price in tranche snapshot");
|
|
6981
7151
|
}
|
|
6982
|
-
|
|
6983
|
-
|
|
7152
|
+
if (!solPriceUsd || solPriceUsd <= BigInt(0)) {
|
|
7153
|
+
throw new Error("No SOL/USD price available");
|
|
7154
|
+
}
|
|
7155
|
+
const ONE_E9 = BigInt(web3_js.LAMPORTS_PER_SOL);
|
|
7156
|
+
const ONE_E8 = BigInt(1e8);
|
|
6984
7157
|
let notionalUsd;
|
|
6985
|
-
|
|
6986
|
-
switch (purchaseAsset) {
|
|
7158
|
+
switch (asset) {
|
|
6987
7159
|
case PurchaseAsset.SOL: {
|
|
6988
|
-
|
|
6989
|
-
notionalUsd = new anchor.BN(amount).mul(solPriceUsd).div(new anchor.BN(1e9));
|
|
6990
|
-
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
7160
|
+
notionalUsd = amount * solPriceUsd / ONE_E9;
|
|
6991
7161
|
break;
|
|
6992
7162
|
}
|
|
6993
7163
|
case PurchaseAsset.LIQSOL: {
|
|
6994
|
-
|
|
6995
|
-
notionalUsd = new anchor.BN(amount).mul(liqsolPriceUsd).div(new anchor.BN(1e9));
|
|
6996
|
-
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
7164
|
+
notionalUsd = amount * solPriceUsd / ONE_E9;
|
|
6997
7165
|
break;
|
|
6998
7166
|
}
|
|
6999
7167
|
case PurchaseAsset.YIELD: {
|
|
7000
|
-
|
|
7001
|
-
notionalUsd = new anchor.BN(amount).mul(solPriceUsd).div(new anchor.BN(1e9));
|
|
7002
|
-
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
7168
|
+
notionalUsd = amount * solPriceUsd / ONE_E9;
|
|
7003
7169
|
break;
|
|
7004
7170
|
}
|
|
7005
7171
|
case PurchaseAsset.ETH:
|
|
7006
7172
|
case PurchaseAsset.LIQETH:
|
|
7007
|
-
throw new Error("getBuyQuote for ETH/LIQETH is not supported on Solana
|
|
7173
|
+
throw new Error("getBuyQuote for ETH/LIQETH is not supported on Solana");
|
|
7008
7174
|
default:
|
|
7009
|
-
throw new Error(`Unsupported purchase asset: ${String(
|
|
7175
|
+
throw new Error(`Unsupported purchase asset: ${String(asset)}`);
|
|
7010
7176
|
}
|
|
7177
|
+
const numerator = notionalUsd * ONE_E8;
|
|
7178
|
+
const wireShares = numerator === BigInt(0) ? BigInt(0) : (numerator + wirePriceUsd - BigInt(1)) / wirePriceUsd;
|
|
7011
7179
|
return {
|
|
7012
|
-
purchaseAsset,
|
|
7180
|
+
purchaseAsset: asset,
|
|
7013
7181
|
amountIn: amount,
|
|
7014
|
-
wireShares
|
|
7015
|
-
wireDecimals,
|
|
7016
|
-
wirePriceUsd
|
|
7017
|
-
notionalUsd
|
|
7182
|
+
wireShares,
|
|
7183
|
+
wireDecimals: 8,
|
|
7184
|
+
wirePriceUsd,
|
|
7185
|
+
notionalUsd
|
|
7018
7186
|
};
|
|
7019
7187
|
});
|
|
7020
7188
|
}
|
|
7021
|
-
calculateExpectedWarrants(notionalUsd, wirePriceUsd) {
|
|
7022
|
-
const SCALE = new anchor.BN("100000000");
|
|
7023
|
-
return notionalUsd.mul(SCALE).div(wirePriceUsd);
|
|
7024
|
-
}
|
|
7025
7189
|
getUserRecord() {
|
|
7026
7190
|
return __async$4(this, null, function* () {
|
|
7027
7191
|
return this.distributionClient.getUserRecord(this.solPubKey);
|
|
@@ -7034,27 +7198,39 @@ class SolanaStakingClient {
|
|
|
7034
7198
|
if (!build.canSucceed || !build.transaction) {
|
|
7035
7199
|
throw new Error((_a = build.reason) != null ? _a : "Unable to build Correct&Register transaction");
|
|
7036
7200
|
}
|
|
7037
|
-
const { tx, blockhash, lastValidBlockHeight } = yield this.prepareTx(
|
|
7201
|
+
const { tx, blockhash, lastValidBlockHeight } = yield this.prepareTx(
|
|
7202
|
+
build.transaction
|
|
7203
|
+
);
|
|
7038
7204
|
const signed = yield this.signTransaction(tx);
|
|
7039
|
-
const
|
|
7040
|
-
|
|
7205
|
+
const signature = yield this.sendAndConfirmHttp(signed, {
|
|
7206
|
+
blockhash,
|
|
7207
|
+
lastValidBlockHeight
|
|
7208
|
+
});
|
|
7209
|
+
return signature;
|
|
7041
7210
|
});
|
|
7042
7211
|
}
|
|
7043
7212
|
sendAndConfirmHttp(signed, ctx) {
|
|
7044
7213
|
return __async$4(this, null, function* () {
|
|
7045
|
-
const signature = yield this.connection.sendRawTransaction(
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7214
|
+
const signature = yield this.connection.sendRawTransaction(
|
|
7215
|
+
signed.serialize(),
|
|
7216
|
+
{
|
|
7217
|
+
skipPreflight: false,
|
|
7218
|
+
preflightCommitment: commitment,
|
|
7219
|
+
maxRetries: 3
|
|
7220
|
+
}
|
|
7221
|
+
);
|
|
7050
7222
|
const conf = yield this.connection.confirmTransaction(
|
|
7051
|
-
{
|
|
7223
|
+
{
|
|
7224
|
+
signature,
|
|
7225
|
+
blockhash: ctx.blockhash,
|
|
7226
|
+
lastValidBlockHeight: ctx.lastValidBlockHeight
|
|
7227
|
+
},
|
|
7052
7228
|
commitment
|
|
7053
7229
|
);
|
|
7054
7230
|
if (conf.value.err) {
|
|
7055
7231
|
throw new Error(`Transaction failed: ${JSON.stringify(conf.value.err)}`);
|
|
7056
7232
|
}
|
|
7057
|
-
return
|
|
7233
|
+
return signature;
|
|
7058
7234
|
});
|
|
7059
7235
|
}
|
|
7060
7236
|
signTransaction(tx) {
|
|
@@ -25192,6 +25368,8 @@ exports.TokenClient = TokenClient;
|
|
|
25192
25368
|
exports.VALIDATOR_LEADERBOARD = VALIDATOR_LEADERBOARD;
|
|
25193
25369
|
exports.airdropSol = airdropSol;
|
|
25194
25370
|
exports.buildOutpostAccounts = buildOutpostAccounts;
|
|
25371
|
+
exports.buildSolanaTrancheLadder = buildSolanaTrancheLadder;
|
|
25372
|
+
exports.buildSolanaTrancheSnapshot = buildSolanaTrancheSnapshot;
|
|
25195
25373
|
exports.calculateExpectedFee = calculateExpectedFee;
|
|
25196
25374
|
exports.deriveBarConfigPda = deriveBarConfigPda;
|
|
25197
25375
|
exports.deriveBondLevelPda = deriveBondLevelPda;
|
|
@@ -25238,6 +25416,8 @@ exports.previewDepositEffects = previewDepositEffects;
|
|
|
25238
25416
|
exports.scheduledInstruction = scheduledInstruction;
|
|
25239
25417
|
exports.sleep = sleep;
|
|
25240
25418
|
exports.solToLamports = solToLamports;
|
|
25419
|
+
exports.toBigint = toBigint;
|
|
25420
|
+
exports.tokensToShares = tokensToShares;
|
|
25241
25421
|
exports.waitForConfirmation = waitForConfirmation;
|
|
25242
25422
|
exports.waitUntilSafeToExecuteFunction = waitUntilSafeToExecuteFunction;
|
|
25243
25423
|
//# sourceMappingURL=stake.js.map
|