@wireio/stake 0.2.1 → 0.2.3
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 +295 -73
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +157 -66
- package/lib/stake.js +398 -127
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +295 -73
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/assets/solana/idl/liqsol_core.json +3 -53
- package/src/assets/solana/idl/liqsol_token.json +1 -1
- package/src/assets/solana/idl/validator_leaderboard.json +1 -1
- package/src/assets/solana/types/liqsol_core.ts +3 -53
- package/src/assets/solana/types/liqsol_token.ts +1 -1
- package/src/assets/solana/types/validator_leaderboard.ts +1 -1
- package/src/index.ts +4 -3
- package/src/networks/ethereum/contract.ts +9 -12
- package/src/networks/ethereum/ethereum.ts +25 -1
- package/src/networks/ethereum/types.ts +1 -1
- package/src/networks/solana/clients/token.client.ts +251 -0
- package/src/networks/solana/constants.ts +9 -0
- package/src/networks/solana/solana.ts +205 -7
- package/src/networks/solana/types.ts +11 -1
- package/src/networks/solana/utils.ts +17 -3
- package/src/{staker/staker.ts → staker.ts} +2 -2
- package/src/types.ts +105 -0
- package/src/staker/types.ts +0 -51
package/lib/stake.browser.js
CHANGED
|
@@ -4,7 +4,16 @@ 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';
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var PurchaseAsset = ((PurchaseAsset2) => {
|
|
8
|
+
PurchaseAsset2["SOL"] = "SOL";
|
|
9
|
+
PurchaseAsset2["LIQSOL"] = "LIQSOL";
|
|
10
|
+
PurchaseAsset2["ETH"] = "ETH";
|
|
11
|
+
PurchaseAsset2["LIQETH"] = "LIQETH";
|
|
12
|
+
PurchaseAsset2["YIELD"] = "YIELD";
|
|
13
|
+
return PurchaseAsset2;
|
|
14
|
+
})(PurchaseAsset || {});
|
|
15
|
+
|
|
16
|
+
var address$2 = "BBkVcNWNQz1vZ6esv5US4QnNFWPRqxWbdpJHur9GVXSu";
|
|
8
17
|
var metadata$2 = {
|
|
9
18
|
name: "liqsol_core",
|
|
10
19
|
version: "0.1.0",
|
|
@@ -3184,58 +3193,8 @@ var events = [
|
|
|
3184
3193
|
var errors$2 = [
|
|
3185
3194
|
{
|
|
3186
3195
|
code: 6000,
|
|
3187
|
-
name: "
|
|
3188
|
-
msg: "
|
|
3189
|
-
},
|
|
3190
|
-
{
|
|
3191
|
-
code: 6001,
|
|
3192
|
-
name: "InsufficientBalance",
|
|
3193
|
-
msg: "Insufficient balance"
|
|
3194
|
-
},
|
|
3195
|
-
{
|
|
3196
|
-
code: 6002,
|
|
3197
|
-
name: "InsufficientFunds",
|
|
3198
|
-
msg: "Insufficient funds"
|
|
3199
|
-
},
|
|
3200
|
-
{
|
|
3201
|
-
code: 6003,
|
|
3202
|
-
name: "Unauthorized",
|
|
3203
|
-
msg: "Unauthorized - caller is not the distribution authority"
|
|
3204
|
-
},
|
|
3205
|
-
{
|
|
3206
|
-
code: 6004,
|
|
3207
|
-
name: "InvalidMint",
|
|
3208
|
-
msg: "Invalid mint"
|
|
3209
|
-
},
|
|
3210
|
-
{
|
|
3211
|
-
code: 6005,
|
|
3212
|
-
name: "InvalidOwner",
|
|
3213
|
-
msg: "Invalid owner"
|
|
3214
|
-
},
|
|
3215
|
-
{
|
|
3216
|
-
code: 6006,
|
|
3217
|
-
name: "InvalidUserRecord",
|
|
3218
|
-
msg: "Invalid user record"
|
|
3219
|
-
},
|
|
3220
|
-
{
|
|
3221
|
-
code: 6007,
|
|
3222
|
-
name: "InvalidWithdrawal",
|
|
3223
|
-
msg: "Invalid withdrawal - balance increased instead of decreased"
|
|
3224
|
-
},
|
|
3225
|
-
{
|
|
3226
|
-
code: 6008,
|
|
3227
|
-
name: "InvalidProgramId",
|
|
3228
|
-
msg: "Invalid program ID"
|
|
3229
|
-
},
|
|
3230
|
-
{
|
|
3231
|
-
code: 6009,
|
|
3232
|
-
name: "InstructionIntrospectionFailed",
|
|
3233
|
-
msg: "Instruction introspection failed"
|
|
3234
|
-
},
|
|
3235
|
-
{
|
|
3236
|
-
code: 6010,
|
|
3237
|
-
name: "ReceiptFulfilled",
|
|
3238
|
-
msg: "Receipt already fulfilled"
|
|
3196
|
+
name: "AccountBorrowFailed",
|
|
3197
|
+
msg: "Util Acc borrow Failed"
|
|
3239
3198
|
}
|
|
3240
3199
|
];
|
|
3241
3200
|
var types$4 = [
|
|
@@ -4519,7 +4478,7 @@ var liqsolCoreIDL = {
|
|
|
4519
4478
|
types: types$4
|
|
4520
4479
|
};
|
|
4521
4480
|
|
|
4522
|
-
var address$1 = "
|
|
4481
|
+
var address$1 = "6cDoerqdV6UQDsGvUEq5Qj5HRxxyDxSuUaB2J6iK8cio";
|
|
4523
4482
|
var metadata$1 = {
|
|
4524
4483
|
name: "liqsol_token",
|
|
4525
4484
|
version: "0.1.0",
|
|
@@ -4708,7 +4667,7 @@ var liqsolTokenJson = {
|
|
|
4708
4667
|
types: types$3
|
|
4709
4668
|
};
|
|
4710
4669
|
|
|
4711
|
-
var address = "
|
|
4670
|
+
var address = "C4ddPrB1ALYpW4G1Qz4ffvETBA8YGUL7TVZaLiE6bb1q";
|
|
4712
4671
|
var metadata = {
|
|
4713
4672
|
name: "validator_leaderboard",
|
|
4714
4673
|
version: "0.1.0",
|
|
@@ -5326,7 +5285,8 @@ const PDA_SEEDS = {
|
|
|
5326
5285
|
USER_WARRANT_RECORD: "user_warrant_record",
|
|
5327
5286
|
BAR_STATE_SEED: "bar_state",
|
|
5328
5287
|
BONDED_ACTOR_SEED: "bonded_actor",
|
|
5329
|
-
BOND_LEVEL_SEED: "bond_level"
|
|
5288
|
+
BOND_LEVEL_SEED: "bond_level",
|
|
5289
|
+
PRICE_HISTORY: "price_history"
|
|
5330
5290
|
};
|
|
5331
5291
|
const deriveLiqsolMintPda = () => PublicKey.findProgramAddressSync(
|
|
5332
5292
|
[Buffer.from(PDA_SEEDS.LIQSOL_MINT)],
|
|
@@ -5428,6 +5388,10 @@ const deriveBondedActorPda = (actor) => PublicKey.findProgramAddressSync(
|
|
|
5428
5388
|
[Buffer.from(PDA_SEEDS.BONDED_ACTOR_SEED), actor.toBuffer()],
|
|
5429
5389
|
LIQSOL_CORE
|
|
5430
5390
|
)[0];
|
|
5391
|
+
const derivePriceHistoryPda = () => PublicKey.findProgramAddressSync(
|
|
5392
|
+
[Buffer.from(PDA_SEEDS.PRICE_HISTORY)],
|
|
5393
|
+
LIQSOL_CORE
|
|
5394
|
+
)[0];
|
|
5431
5395
|
const deriveEphemeralStakeAddress = async (user, seed) => {
|
|
5432
5396
|
const seedStr = `ephemeral_${seed}`;
|
|
5433
5397
|
return await PublicKey.createWithSeed(user, seedStr, StakeProgram.programId);
|
|
@@ -5948,8 +5912,17 @@ async function buildOutpostAccounts(connection, user) {
|
|
|
5948
5912
|
false,
|
|
5949
5913
|
TOKEN_2022_PROGRAM_ID
|
|
5950
5914
|
);
|
|
5951
|
-
|
|
5952
|
-
|
|
5915
|
+
let chainLinkFeed = CHAINLINK_FEED;
|
|
5916
|
+
let chainLinkProgram = CHAINLINK_PROGRAM;
|
|
5917
|
+
try {
|
|
5918
|
+
const program = getLiqsolCoreProgram(connection);
|
|
5919
|
+
const ts = await program.account.trancheState.fetch(trancheState);
|
|
5920
|
+
if (ts.chainlinkFeed && ts.chainlinkProgram) {
|
|
5921
|
+
chainLinkFeed = ts.chainlinkFeed;
|
|
5922
|
+
chainLinkProgram = ts.chainlinkProgram;
|
|
5923
|
+
}
|
|
5924
|
+
} catch {
|
|
5925
|
+
}
|
|
5953
5926
|
return {
|
|
5954
5927
|
user,
|
|
5955
5928
|
globalState,
|
|
@@ -6354,6 +6327,127 @@ const _OutpostClient = class _OutpostClient {
|
|
|
6354
6327
|
_OutpostClient.INDEX_SCALE = new BN("1000000000000");
|
|
6355
6328
|
let OutpostClient = _OutpostClient;
|
|
6356
6329
|
|
|
6330
|
+
class TokenClient {
|
|
6331
|
+
constructor(provider) {
|
|
6332
|
+
this.provider = provider;
|
|
6333
|
+
const svc = new SolanaProgramService(provider);
|
|
6334
|
+
this.program = svc.getProgram("liqsolCore");
|
|
6335
|
+
}
|
|
6336
|
+
get wallet() {
|
|
6337
|
+
return this.provider.wallet;
|
|
6338
|
+
}
|
|
6339
|
+
async getAccounts(user) {
|
|
6340
|
+
return buildOutpostAccounts(this.provider.connection, user);
|
|
6341
|
+
}
|
|
6342
|
+
async fetchGlobalState() {
|
|
6343
|
+
const { globalState } = await this.getAccounts(this.provider.wallet.publicKey);
|
|
6344
|
+
return this.program.account.globalState.fetch(globalState);
|
|
6345
|
+
}
|
|
6346
|
+
async fetchTrancheState() {
|
|
6347
|
+
const { trancheState } = await this.getAccounts(this.provider.wallet.publicKey);
|
|
6348
|
+
return this.program.account.trancheState.fetch(trancheState);
|
|
6349
|
+
}
|
|
6350
|
+
async fetchWireReceipt(user) {
|
|
6351
|
+
const { wireReceipt } = await this.getAccounts(user);
|
|
6352
|
+
return this.program.account.wireReceipt.fetch(wireReceipt);
|
|
6353
|
+
}
|
|
6354
|
+
async fetchUserWarrantRecord(user) {
|
|
6355
|
+
const { userWarrantRecord } = await this.getAccounts(user);
|
|
6356
|
+
return this.program.account.userWarrantRecord.fetch(userWarrantRecord);
|
|
6357
|
+
}
|
|
6358
|
+
async buildPurchaseWithSolIx(amountLamports, user = this.wallet.publicKey) {
|
|
6359
|
+
const a = await this.getAccounts(user);
|
|
6360
|
+
return this.program.methods.purchaseWithSol(new BN(amountLamports.toString())).accounts({
|
|
6361
|
+
user: a.user,
|
|
6362
|
+
liqsolMint: a.liqsolMint,
|
|
6363
|
+
globalState: a.globalState,
|
|
6364
|
+
poolAuthority: a.poolAuthority,
|
|
6365
|
+
liqsolPoolAta: a.liqsolPoolAta,
|
|
6366
|
+
liqsolPoolUserRecord: a.poolUserRecord,
|
|
6367
|
+
distributionState: a.distributionState,
|
|
6368
|
+
payRateHistory: a.payRateHistory,
|
|
6369
|
+
bucketAuthority: a.bucketAuthority,
|
|
6370
|
+
bucketTokenAccount: a.bucketTokenAccount,
|
|
6371
|
+
solBucket: a.solBucket,
|
|
6372
|
+
warrantDepositRecord: a.wireReceipt,
|
|
6373
|
+
trancheState: a.trancheState,
|
|
6374
|
+
userWarrantRecord: a.userWarrantRecord,
|
|
6375
|
+
chainlinkFeed: a.chainLinkFeed,
|
|
6376
|
+
chainlinkProgram: a.chainLinkProgram,
|
|
6377
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
6378
|
+
systemProgram: SystemProgram.programId
|
|
6379
|
+
}).instruction();
|
|
6380
|
+
}
|
|
6381
|
+
async buildPurchaseWithLiqsolIx(amountLamports, user = this.wallet.publicKey) {
|
|
6382
|
+
const a = await this.getAccounts(user);
|
|
6383
|
+
return this.program.methods.purchaseWithLiqsol(new BN(amountLamports.toString())).accounts({
|
|
6384
|
+
user: a.user,
|
|
6385
|
+
liqsolMint: a.liqsolMint,
|
|
6386
|
+
globalState: a.globalState,
|
|
6387
|
+
buyerAta: a.userAta,
|
|
6388
|
+
poolAuthority: a.poolAuthority,
|
|
6389
|
+
liqsolPoolAta: a.liqsolPoolAta,
|
|
6390
|
+
warrantDepositRecord: a.wireReceipt,
|
|
6391
|
+
liqsolPoolUserRecord: a.poolUserRecord,
|
|
6392
|
+
distributionState: a.distributionState,
|
|
6393
|
+
payRateHistory: a.payRateHistory,
|
|
6394
|
+
bucketAuthority: a.bucketAuthority,
|
|
6395
|
+
bucketTokenAccount: a.bucketTokenAccount,
|
|
6396
|
+
solBucket: a.solBucket,
|
|
6397
|
+
trancheState: a.trancheState,
|
|
6398
|
+
userWarrantRecord: a.userWarrantRecord,
|
|
6399
|
+
chainlinkFeed: a.chainLinkFeed,
|
|
6400
|
+
chainlinkProgram: a.chainLinkProgram,
|
|
6401
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
6402
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
6403
|
+
systemProgram: SystemProgram.programId
|
|
6404
|
+
}).instruction();
|
|
6405
|
+
}
|
|
6406
|
+
async buildPurchaseFromYieldIx(user = this.wallet.publicKey) {
|
|
6407
|
+
const a = await this.getAccounts(user);
|
|
6408
|
+
return this.program.methods.purchaseWarrantsFromYield().accounts({
|
|
6409
|
+
user: a.user,
|
|
6410
|
+
globalState: a.globalState,
|
|
6411
|
+
liqsolMint: a.liqsolMint,
|
|
6412
|
+
poolAuthority: a.poolAuthority,
|
|
6413
|
+
liqsolPoolAta: a.liqsolPoolAta,
|
|
6414
|
+
solBucket: a.solBucket,
|
|
6415
|
+
liqsolPoolUserRecord: a.poolUserRecord,
|
|
6416
|
+
distributionState: a.distributionState,
|
|
6417
|
+
payRateHistory: a.payRateHistory,
|
|
6418
|
+
bucketAuthority: a.bucketAuthority,
|
|
6419
|
+
bucketTokenAccount: a.bucketTokenAccount,
|
|
6420
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
6421
|
+
systemProgram: SystemProgram.programId,
|
|
6422
|
+
trancheState: a.trancheState,
|
|
6423
|
+
userWarrantRecord: a.userWarrantRecord,
|
|
6424
|
+
chainlinkFeed: a.chainLinkFeed,
|
|
6425
|
+
chainlinkProgram: a.chainLinkProgram
|
|
6426
|
+
}).instruction();
|
|
6427
|
+
}
|
|
6428
|
+
async getSolPriceUsd() {
|
|
6429
|
+
const priceHistoryPda = derivePriceHistoryPda();
|
|
6430
|
+
const history = await this.program.account.priceHistory.fetch(
|
|
6431
|
+
priceHistoryPda
|
|
6432
|
+
);
|
|
6433
|
+
console.log("PRICE HISTORY", history);
|
|
6434
|
+
const { windowSize, prices, nextIndex, count } = history;
|
|
6435
|
+
if (!prices || prices.length === 0 || count === 0) {
|
|
6436
|
+
throw new Error("Price history is empty \u2013 no SOL price available");
|
|
6437
|
+
}
|
|
6438
|
+
const capacity = prices.length || windowSize;
|
|
6439
|
+
if (capacity === 0) {
|
|
6440
|
+
throw new Error("Price history capacity is zero \u2013 check account layout");
|
|
6441
|
+
}
|
|
6442
|
+
const lastIndex = nextIndex === 0 ? capacity - 1 : nextIndex - 1;
|
|
6443
|
+
const priceUsd = prices[lastIndex];
|
|
6444
|
+
if (!BN.isBN(priceUsd)) {
|
|
6445
|
+
throw new Error("Latest price entry is not a BN \u2013 check IDL/decoder");
|
|
6446
|
+
}
|
|
6447
|
+
return priceUsd;
|
|
6448
|
+
}
|
|
6449
|
+
}
|
|
6450
|
+
|
|
6357
6451
|
const commitment = "confirmed";
|
|
6358
6452
|
class SolanaStakingClient {
|
|
6359
6453
|
constructor(config) {
|
|
@@ -6386,6 +6480,7 @@ class SolanaStakingClient {
|
|
|
6386
6480
|
this.distributionClient = new DistributionClient(this.anchor);
|
|
6387
6481
|
this.leaderboardClient = new LeaderboardClient(this.anchor);
|
|
6388
6482
|
this.outpostClient = new OutpostClient(this.anchor);
|
|
6483
|
+
this.tokenClient = new TokenClient(this.anchor);
|
|
6389
6484
|
}
|
|
6390
6485
|
get solPubKey() {
|
|
6391
6486
|
return new PublicKey(this.pubKey.data.array);
|
|
@@ -6425,6 +6520,41 @@ class SolanaStakingClient {
|
|
|
6425
6520
|
const result = await this.sendAndConfirmHttp(signed, prepared);
|
|
6426
6521
|
return result.signature;
|
|
6427
6522
|
}
|
|
6523
|
+
async buy(amountLamports, purchaseAsset) {
|
|
6524
|
+
const user = this.solPubKey;
|
|
6525
|
+
let ix;
|
|
6526
|
+
let preIxs = [];
|
|
6527
|
+
switch (purchaseAsset) {
|
|
6528
|
+
case PurchaseAsset.SOL: {
|
|
6529
|
+
if (!amountLamports || amountLamports <= BigInt(0))
|
|
6530
|
+
throw new Error("SOL pretoken purchase requires a positive amount.");
|
|
6531
|
+
ix = await this.tokenClient.buildPurchaseWithSolIx(amountLamports, user);
|
|
6532
|
+
break;
|
|
6533
|
+
}
|
|
6534
|
+
case PurchaseAsset.LIQSOL: {
|
|
6535
|
+
if (!amountLamports || amountLamports <= BigInt(0))
|
|
6536
|
+
throw new Error("liqSOL pretoken purchase requires a positive amount.");
|
|
6537
|
+
preIxs = await this.outpostClient.maybeBuildCreateUserAtaIx(user);
|
|
6538
|
+
ix = await this.tokenClient.buildPurchaseWithLiqsolIx(amountLamports, user);
|
|
6539
|
+
break;
|
|
6540
|
+
}
|
|
6541
|
+
case PurchaseAsset.YIELD: {
|
|
6542
|
+
ix = await this.tokenClient.buildPurchaseFromYieldIx(user);
|
|
6543
|
+
break;
|
|
6544
|
+
}
|
|
6545
|
+
case PurchaseAsset.ETH:
|
|
6546
|
+
case PurchaseAsset.LIQETH: {
|
|
6547
|
+
throw new Error("ETH / LIQETH pretoken purchases are not supported on Solana.");
|
|
6548
|
+
}
|
|
6549
|
+
default:
|
|
6550
|
+
throw new Error(`Unsupported pretoken purchase asset: ${String(purchaseAsset)}`);
|
|
6551
|
+
}
|
|
6552
|
+
const tx = new Transaction().add(...preIxs, ix);
|
|
6553
|
+
const prepared = await this.prepareTx(tx);
|
|
6554
|
+
const signed = await this.signTransaction(prepared.tx);
|
|
6555
|
+
const res = await this.sendAndConfirmHttp(signed, prepared);
|
|
6556
|
+
return res.signature;
|
|
6557
|
+
}
|
|
6428
6558
|
async getPortfolio() {
|
|
6429
6559
|
const user = this.solPubKey;
|
|
6430
6560
|
const reservePoolPDA = deriveReservePoolPda();
|
|
@@ -6447,7 +6577,11 @@ class SolanaStakingClient {
|
|
|
6447
6577
|
const actualAmountStr = actualBalResp?.value?.amount ?? "0";
|
|
6448
6578
|
const trackedAmountStr = userRecord?.trackedBalance ? userRecord.trackedBalance.toString() : "0";
|
|
6449
6579
|
const wireReceipt = snapshot?.wireReceipt ?? null;
|
|
6580
|
+
const userWarrantRecord = snapshot?.userWarrantRecord ?? null;
|
|
6581
|
+
const trancheState = snapshot?.trancheState ?? null;
|
|
6582
|
+
const globalState = snapshot?.globalState ?? null;
|
|
6450
6583
|
const stakedAmountStr = wireReceipt?.stakedLiqsol ? wireReceipt.stakedLiqsol.toString() : "0";
|
|
6584
|
+
const wireSharesStr = userWarrantRecord?.totalWarrantsPurchased ? userWarrantRecord.totalWarrantsPurchased.toString() : "0";
|
|
6451
6585
|
return {
|
|
6452
6586
|
native: {
|
|
6453
6587
|
amount: BigInt(nativeLamports),
|
|
@@ -6465,6 +6599,11 @@ class SolanaStakingClient {
|
|
|
6465
6599
|
symbol: "LiqSOL",
|
|
6466
6600
|
decimals: LIQSOL_DECIMALS
|
|
6467
6601
|
},
|
|
6602
|
+
wire: {
|
|
6603
|
+
amount: BigInt(wireSharesStr),
|
|
6604
|
+
symbol: "$WIRE",
|
|
6605
|
+
decimals: 8
|
|
6606
|
+
},
|
|
6468
6607
|
tracked: {
|
|
6469
6608
|
amount: BigInt(trackedAmountStr),
|
|
6470
6609
|
symbol: "LiqSOL",
|
|
@@ -6474,16 +6613,85 @@ class SolanaStakingClient {
|
|
|
6474
6613
|
userLiqsolAta: userLiqsolAta.toBase58(),
|
|
6475
6614
|
reservePoolPDA: reservePoolPDA.toBase58(),
|
|
6476
6615
|
vaultPDA: vaultPDA.toBase58(),
|
|
6477
|
-
wireReceipt
|
|
6616
|
+
wireReceipt,
|
|
6617
|
+
userWarrantRecord,
|
|
6618
|
+
globalIndex: globalState?.currentIndex?.toString(),
|
|
6619
|
+
totalShares: globalState?.totalShares?.toString(),
|
|
6620
|
+
currentTrancheNumber: trancheState?.currentTrancheNumber?.toString(),
|
|
6621
|
+
currentTranchePriceUsd: trancheState?.currentTranchePriceUsd?.toString()
|
|
6478
6622
|
},
|
|
6479
6623
|
chainID: this.network.chainId
|
|
6480
6624
|
};
|
|
6481
6625
|
}
|
|
6626
|
+
async getTrancheSnapshot() {
|
|
6627
|
+
const snapshot = await this.outpostClient.getWireStateSnapshot(this.solPubKey);
|
|
6628
|
+
const global = snapshot.globalState;
|
|
6629
|
+
const tranche = snapshot.trancheState;
|
|
6630
|
+
if (!global || !tranche) return null;
|
|
6631
|
+
return {
|
|
6632
|
+
chainID: this.network.chainId,
|
|
6633
|
+
totalShares: BigInt(global.totalShares.toString()),
|
|
6634
|
+
currentIndex: BigInt(global.currentIndex.toString()),
|
|
6635
|
+
currentTrancheNumber: BigInt(tranche.currentTrancheNumber.toString()),
|
|
6636
|
+
currentTrancheSupply: BigInt(tranche.currentTrancheSupply.toString()),
|
|
6637
|
+
totalWarrantsSold: BigInt(tranche.totalWarrantsSold.toString()),
|
|
6638
|
+
currentTranchePriceUsd: BigInt(tranche.currentTranchePriceUsd.toString())
|
|
6639
|
+
};
|
|
6640
|
+
}
|
|
6641
|
+
async getBuyQuote(amount, purchaseAsset) {
|
|
6642
|
+
if (amount <= BigInt(0) && purchaseAsset !== PurchaseAsset.YIELD)
|
|
6643
|
+
throw new Error("Buy amount must be greater than zero for non-YIELD purchases.");
|
|
6644
|
+
const user = this.solPubKey;
|
|
6645
|
+
const snapshot = await this.outpostClient.getWireStateSnapshot(user);
|
|
6646
|
+
const tranche = snapshot.trancheState;
|
|
6647
|
+
if (!tranche) {
|
|
6648
|
+
throw new Error("TrancheState not initialized; cannot quote WIRE purchase.");
|
|
6649
|
+
}
|
|
6650
|
+
const wirePriceUsd = tranche.currentTranchePriceUsd;
|
|
6651
|
+
const wireDecimals = 8;
|
|
6652
|
+
let notionalUsd;
|
|
6653
|
+
let wireSharesBn;
|
|
6654
|
+
switch (purchaseAsset) {
|
|
6655
|
+
case PurchaseAsset.SOL: {
|
|
6656
|
+
const solPriceUsd = await this.tokenClient.getSolPriceUsd();
|
|
6657
|
+
notionalUsd = new BN(amount).mul(solPriceUsd).div(new BN(1e9));
|
|
6658
|
+
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
6659
|
+
break;
|
|
6660
|
+
}
|
|
6661
|
+
case PurchaseAsset.LIQSOL: {
|
|
6662
|
+
const liqsolPriceUsd = await this.tokenClient.getSolPriceUsd();
|
|
6663
|
+
notionalUsd = new BN(amount).mul(liqsolPriceUsd).div(new BN(1e9));
|
|
6664
|
+
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
6665
|
+
break;
|
|
6666
|
+
}
|
|
6667
|
+
case PurchaseAsset.YIELD: {
|
|
6668
|
+
const solPriceUsd = await this.tokenClient.getSolPriceUsd();
|
|
6669
|
+
notionalUsd = new BN(amount).mul(solPriceUsd).div(new BN(1e9));
|
|
6670
|
+
wireSharesBn = this.calculateExpectedWarrants(notionalUsd, wirePriceUsd);
|
|
6671
|
+
break;
|
|
6672
|
+
}
|
|
6673
|
+
case PurchaseAsset.ETH:
|
|
6674
|
+
case PurchaseAsset.LIQETH:
|
|
6675
|
+
throw new Error("getBuyQuote for ETH/LIQETH is not supported on Solana.");
|
|
6676
|
+
default:
|
|
6677
|
+
throw new Error(`Unsupported purchase asset: ${String(purchaseAsset)}`);
|
|
6678
|
+
}
|
|
6679
|
+
return {
|
|
6680
|
+
purchaseAsset,
|
|
6681
|
+
amountIn: amount,
|
|
6682
|
+
wireShares: BigInt(wireSharesBn.toString()),
|
|
6683
|
+
wireDecimals,
|
|
6684
|
+
wirePriceUsd: BigInt(wirePriceUsd.toString()),
|
|
6685
|
+
notionalUsd: BigInt(notionalUsd.toString())
|
|
6686
|
+
};
|
|
6687
|
+
}
|
|
6688
|
+
calculateExpectedWarrants(notionalUsd, wirePriceUsd) {
|
|
6689
|
+
const SCALE = new BN("100000000");
|
|
6690
|
+
return notionalUsd.mul(SCALE).div(wirePriceUsd);
|
|
6691
|
+
}
|
|
6482
6692
|
async getUserRecord() {
|
|
6483
6693
|
return this.distributionClient.getUserRecord(this.solPubKey);
|
|
6484
6694
|
}
|
|
6485
|
-
getProtocolFee() {
|
|
6486
|
-
}
|
|
6487
6695
|
async correctBalance(amount) {
|
|
6488
6696
|
const build = await this.distributionClient.buildCorrectRegisterTx({ amount });
|
|
6489
6697
|
if (!build.canSucceed || !build.transaction) {
|
|
@@ -23936,14 +24144,14 @@ const ADDRESSES = {
|
|
|
23936
24144
|
StakingModule: "0xBd13C85fdefBBc63904e7301aCdeFE87c9C93234",
|
|
23937
24145
|
WithdrawalQueue: "0xD9A1D38ae4A636DEf20B02F35387a6b126D73fAe",
|
|
23938
24146
|
WithdrawalVault: "0x150334D09a1d3d30EE93d5e6009EB897B5dDF5b2",
|
|
23939
|
-
Depositor: "
|
|
23940
|
-
ReceiptNFT: "
|
|
23941
|
-
OutpostManager: "
|
|
23942
|
-
BAR: "
|
|
23943
|
-
OPP: "
|
|
23944
|
-
OPPCommon: "
|
|
23945
|
-
OPPInbound: "
|
|
23946
|
-
Warrant: "
|
|
24147
|
+
Depositor: "0x6aE1D7095B81970654Bd51bCAD42825C6E579088",
|
|
24148
|
+
ReceiptNFT: "0x38eAEa05cB1FFD0c8426A3f9e77815a251DdC197",
|
|
24149
|
+
OutpostManager: "0x6512bB8E7f8418A8e3bB73c49E33EcC30F53f221",
|
|
24150
|
+
BAR: "0x00c128A37598d018Eb8ca4f516688695D83bD413",
|
|
24151
|
+
OPP: "0x8C5710103Ec6a7608dAC539DC232d3822bA3d14C",
|
|
24152
|
+
OPPCommon: "0x52C1d7F02B35176F79b03F6eF7E5b74b27d1dB8c",
|
|
24153
|
+
OPPInbound: "0x39feC7536BaEd4E376b1B5cf2f2e8182ab203418",
|
|
24154
|
+
Warrant: "0x9190bBcaB5cfeb4b7b6DE5Ae21105F3114753F10"
|
|
23947
24155
|
};
|
|
23948
24156
|
const CONTRACTS = {
|
|
23949
24157
|
Accounting: {
|
|
@@ -24317,6 +24525,12 @@ class EthereumStakingClient {
|
|
|
24317
24525
|
rewardCooldown
|
|
24318
24526
|
};
|
|
24319
24527
|
}
|
|
24528
|
+
buy(amount, purchaseAsset) {
|
|
24529
|
+
throw new Error("Method not yet implemented.");
|
|
24530
|
+
}
|
|
24531
|
+
getBuyQuote(amount, purchaseAsset) {
|
|
24532
|
+
throw new Error("Method not yet implemented.");
|
|
24533
|
+
}
|
|
24320
24534
|
async getPortfolio() {
|
|
24321
24535
|
const walletAddress = await this.signer.getAddress();
|
|
24322
24536
|
const nativeBalance = await this.provider.getBalance(walletAddress);
|
|
@@ -24346,10 +24560,18 @@ class EthereumStakingClient {
|
|
|
24346
24560
|
decimals: nativeDecimals,
|
|
24347
24561
|
symbol: liqSymbol
|
|
24348
24562
|
},
|
|
24563
|
+
wire: {
|
|
24564
|
+
amount: BigInt(0),
|
|
24565
|
+
decimals: 0,
|
|
24566
|
+
symbol: "$WIRE"
|
|
24567
|
+
},
|
|
24349
24568
|
chainID: this.network.chainId
|
|
24350
24569
|
};
|
|
24351
24570
|
return portfolio;
|
|
24352
24571
|
}
|
|
24572
|
+
async getTrancheSnapshot() {
|
|
24573
|
+
return null;
|
|
24574
|
+
}
|
|
24353
24575
|
async requestWithdraw(amountWei) {
|
|
24354
24576
|
const deadline = Math.floor(Date.now() / 1e3) + 3600;
|
|
24355
24577
|
const liqEth = this.contract.LiqEth;
|
|
@@ -24461,13 +24683,13 @@ const CONTRACT_NAMES = [
|
|
|
24461
24683
|
];
|
|
24462
24684
|
|
|
24463
24685
|
var types$1 = /*#__PURE__*/Object.freeze({
|
|
24464
|
-
|
|
24465
|
-
|
|
24686
|
+
__proto__: null,
|
|
24687
|
+
CONTRACT_NAMES: CONTRACT_NAMES
|
|
24466
24688
|
});
|
|
24467
24689
|
|
|
24468
24690
|
var types = /*#__PURE__*/Object.freeze({
|
|
24469
|
-
|
|
24691
|
+
__proto__: null
|
|
24470
24692
|
});
|
|
24471
24693
|
|
|
24472
|
-
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, types as SOL, SolanaStakingClient, Staker, VALIDATOR_LEADERBOARD, airdropSol, buildOutpostAccounts, calculateExpectedFee, deriveBarConfigPda, deriveBondLevelPda, deriveBondedActorPda, deriveBucketAuthorityPda, deriveDepositAuthorityPda, deriveDistributionStatePda, deriveEphemeralStakeAddress, deriveLeaderboardStatePda, deriveLiqsolMintAuthorityPda, deriveLiqsolMintPda, deriveOutpostGlobalStatePda, deriveOutpostPoolAuthorityPda, derivePayRateHistoryPda, derivePayoutStatePda, derivePoolUserRecordPda, 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 };
|
|
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 };
|
|
24473
24695
|
//# sourceMappingURL=stake.browser.js.map
|