@wireio/stake 2.2.2 → 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/README.md +185 -243
- package/lib/stake.browser.js +417 -212
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +119 -24
- package/lib/stake.js +489 -260
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +417 -212
- package/lib/stake.m.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -2
- package/src/networks/ethereum/clients/receipt.client.ts +54 -69
- package/src/networks/ethereum/ethereum.ts +10 -10
- package/src/networks/ethereum/types.ts +14 -17
- package/src/networks/solana/clients/convert.client.ts +339 -0
- package/src/networks/solana/clients/distribution.client.ts +114 -2
- package/src/networks/solana/solana.ts +61 -7
- package/src/networks/solana/types.ts +22 -0
- package/src/networks/solana/utils.ts +8 -1
- package/src/types.ts +49 -4
- package/src/networks/solana/clients/deposit.client.ts +0 -291
package/lib/stake.js
CHANGED
|
@@ -9,213 +9,24 @@ var bs58 = require('bs58');
|
|
|
9
9
|
var ethers = require('ethers');
|
|
10
10
|
|
|
11
11
|
function _interopNamespaceDefault(e) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
}
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
22
20
|
});
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var multisig__namespace = /*#__PURE__*/_interopNamespaceDefault(multisig);
|
|
29
|
-
|
|
30
|
-
var __pow = Math.pow;
|
|
31
|
-
var __async$h = (__this, __arguments, generator) => {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
var fulfilled = (value) => {
|
|
34
|
-
try {
|
|
35
|
-
step(generator.next(value));
|
|
36
|
-
} catch (e) {
|
|
37
|
-
reject(e);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var rejected = (value) => {
|
|
41
|
-
try {
|
|
42
|
-
step(generator.throw(value));
|
|
43
|
-
} catch (e) {
|
|
44
|
-
reject(e);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
48
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
class DepositClient {
|
|
52
|
-
constructor(provider, pgs) {
|
|
53
|
-
this.provider = provider;
|
|
54
|
-
this.pgs = pgs;
|
|
55
|
-
this.program = pgs.getProgram("liqsolCore");
|
|
56
|
-
}
|
|
57
|
-
get connection() {
|
|
58
|
-
return this.provider.connection;
|
|
59
|
-
}
|
|
60
|
-
get wallet() {
|
|
61
|
-
return this.provider.wallet;
|
|
62
|
-
}
|
|
63
|
-
buildDepositTx(_0) {
|
|
64
|
-
return __async$h(this, arguments, function* (amount, user = this.wallet.publicKey) {
|
|
65
|
-
if (!user) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
"DepositClient.buildDepositTx: wallet not connected"
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
if (!amount || amount <= BigInt(0)) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
"DepositClient.buildDepositTx: amount must be greater than zero."
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const depositAuthority = this.pgs.deriveDepositAuthorityPda();
|
|
76
|
-
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
77
|
-
const liqsolMintAuthority = this.pgs.deriveLiqsolMintAuthorityPda();
|
|
78
|
-
const reservePool = this.pgs.deriveReservePoolPda();
|
|
79
|
-
const vault = this.pgs.deriveVaultPda();
|
|
80
|
-
const controllerState = this.pgs.deriveStakeControllerStatePda();
|
|
81
|
-
const payoutState = this.pgs.derivePayoutStatePda();
|
|
82
|
-
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
83
|
-
const payRateHistory = this.pgs.derivePayRateHistoryPda();
|
|
84
|
-
const globalConfig = this.pgs.deriveGlobalConfigPda();
|
|
85
|
-
const userAta = splToken.getAssociatedTokenAddressSync(
|
|
86
|
-
liqsolMint,
|
|
87
|
-
user,
|
|
88
|
-
true,
|
|
89
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
90
|
-
);
|
|
91
|
-
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
92
|
-
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
93
|
-
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
94
|
-
liqsolMint,
|
|
95
|
-
bucketAuthority,
|
|
96
|
-
true,
|
|
97
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
98
|
-
);
|
|
99
|
-
const seed = Math.floor(Math.random() * __pow(2, 32));
|
|
100
|
-
const ephemeralStake = yield this.pgs.deriveEphemeralStakeAddress(user, seed);
|
|
101
|
-
return yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
|
|
102
|
-
user,
|
|
103
|
-
depositAuthority,
|
|
104
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
105
|
-
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
106
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
107
|
-
liqsolProgram: this.pgs.PROGRAM_IDS.LIQSOL_TOKEN,
|
|
108
|
-
stakeProgram: web3_js.StakeProgram.programId,
|
|
109
|
-
liqsolMint,
|
|
110
|
-
userAta,
|
|
111
|
-
liqsolMintAuthority,
|
|
112
|
-
reservePool,
|
|
113
|
-
vault,
|
|
114
|
-
ephemeralStake,
|
|
115
|
-
controllerState,
|
|
116
|
-
payoutState,
|
|
117
|
-
bucketAuthority,
|
|
118
|
-
bucketTokenAccount,
|
|
119
|
-
userRecord,
|
|
120
|
-
distributionState,
|
|
121
|
-
payRateHistory,
|
|
122
|
-
instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
123
|
-
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
124
|
-
stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
125
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
126
|
-
globalConfig
|
|
127
|
-
}).instruction();
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
buildWithdrawTx(_0) {
|
|
131
|
-
return __async$h(this, arguments, function* (amount, user = this.wallet.publicKey) {
|
|
132
|
-
if (!user) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
"DepositClient.buildWithdrawTx: wallet not connected"
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (!amount || amount <= BigInt(0)) {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"DepositClient.buildWithdrawTx: amount must be greater than zero."
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
143
|
-
const userAta = splToken.getAssociatedTokenAddressSync(
|
|
144
|
-
liqsolMint,
|
|
145
|
-
user,
|
|
146
|
-
true,
|
|
147
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
148
|
-
);
|
|
149
|
-
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
150
|
-
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
151
|
-
const global = this.pgs.deriveWithdrawGlobalPda();
|
|
152
|
-
const reservePool = this.pgs.deriveReservePoolPda();
|
|
153
|
-
const stakeAllocationState = this.pgs.deriveStakeAllocationStatePda();
|
|
154
|
-
const stakeMetrics = this.pgs.deriveStakeMetricsPda();
|
|
155
|
-
const maintenanceLedger = this.pgs.deriveMaintenanceLedgerPda();
|
|
156
|
-
const globalConfig = this.pgs.deriveGlobalConfigPda();
|
|
157
|
-
const globalAcct = yield this.program.account.global.fetch(global);
|
|
158
|
-
const rawId = globalAcct.nextReceiptId;
|
|
159
|
-
let receiptId;
|
|
160
|
-
if (typeof rawId === "bigint") {
|
|
161
|
-
receiptId = rawId;
|
|
162
|
-
} else if (rawId != null && typeof rawId === "object" && "toString" in rawId) {
|
|
163
|
-
receiptId = BigInt(rawId.toString());
|
|
164
|
-
} else if (typeof rawId === "number") {
|
|
165
|
-
receiptId = BigInt(rawId);
|
|
166
|
-
} else {
|
|
167
|
-
throw new Error(
|
|
168
|
-
`DepositClient.buildWithdrawTx: unexpected nextReceiptId type (${typeof rawId})`
|
|
169
|
-
);
|
|
170
21
|
}
|
|
171
|
-
const mintAuthority = this.pgs.deriveWithdrawMintAuthorityPda();
|
|
172
|
-
const metadata = this.pgs.deriveWithdrawMintMetadataPda();
|
|
173
|
-
const nftMint = this.pgs.deriveWithdrawNftMintPda(receiptId);
|
|
174
|
-
const receiptData = this.pgs.deriveLiqReceiptDataPda(nftMint);
|
|
175
|
-
const owner = user;
|
|
176
|
-
const nftAta = splToken.getAssociatedTokenAddressSync(
|
|
177
|
-
nftMint,
|
|
178
|
-
owner,
|
|
179
|
-
true,
|
|
180
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
181
|
-
);
|
|
182
|
-
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
183
|
-
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
184
|
-
liqsolMint,
|
|
185
|
-
bucketAuthority,
|
|
186
|
-
true,
|
|
187
|
-
splToken.TOKEN_2022_PROGRAM_ID
|
|
188
|
-
);
|
|
189
|
-
return yield this.program.methods.requestWithdraw(new anchor.BN(amount.toString())).accounts({
|
|
190
|
-
user,
|
|
191
|
-
owner,
|
|
192
|
-
global,
|
|
193
|
-
liqsolMint,
|
|
194
|
-
userAta,
|
|
195
|
-
userRecord,
|
|
196
|
-
reservePool,
|
|
197
|
-
stakeAllocationState,
|
|
198
|
-
stakeMetrics,
|
|
199
|
-
maintenanceLedger,
|
|
200
|
-
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
201
|
-
mintAuthority,
|
|
202
|
-
receiptData,
|
|
203
|
-
metadata,
|
|
204
|
-
nftMint,
|
|
205
|
-
nftAta,
|
|
206
|
-
distributionState,
|
|
207
|
-
bucketTokenAccount,
|
|
208
|
-
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
209
|
-
tokenInterface: splToken.TOKEN_2022_PROGRAM_ID,
|
|
210
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
211
|
-
systemProgram: web3_js.SystemProgram.programId,
|
|
212
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
213
|
-
globalConfig
|
|
214
|
-
}).instruction();
|
|
215
22
|
});
|
|
216
23
|
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
217
26
|
}
|
|
218
27
|
|
|
28
|
+
var multisig__namespace = /*#__PURE__*/_interopNamespaceDefault(multisig);
|
|
29
|
+
|
|
219
30
|
var address$7 = "5nBtmutQLrRKBUxNfHJPDjiW5u8id6QM9Hhjg1D1g1XH";
|
|
220
31
|
var metadata$7 = {
|
|
221
32
|
name: "liqsol_core",
|
|
@@ -14638,7 +14449,7 @@ var devnetTransferHookIDL = {
|
|
|
14638
14449
|
types: types$2
|
|
14639
14450
|
};
|
|
14640
14451
|
|
|
14641
|
-
var __async$
|
|
14452
|
+
var __async$h = (__this, __arguments, generator) => {
|
|
14642
14453
|
return new Promise((resolve, reject) => {
|
|
14643
14454
|
var fulfilled = (value) => {
|
|
14644
14455
|
try {
|
|
@@ -14716,7 +14527,7 @@ const PDA_SEEDS = {
|
|
|
14716
14527
|
LIQ_RECEIPT_DATA: "liq_receipt_data",
|
|
14717
14528
|
WITHDRAW_MINT: "mint"
|
|
14718
14529
|
};
|
|
14719
|
-
const deriveEphemeralStakeAddress = (user, seed) => __async$
|
|
14530
|
+
const deriveEphemeralStakeAddress = (user, seed) => __async$h(null, null, function* () {
|
|
14720
14531
|
const seedStr = `ephemeral_${seed}`;
|
|
14721
14532
|
return web3_js.PublicKey.createWithSeed(user, seedStr, web3_js.StakeProgram.programId);
|
|
14722
14533
|
});
|
|
@@ -14735,7 +14546,7 @@ const INDEX_SCALE$1 = BigInt(1e12);
|
|
|
14735
14546
|
const lamportsToSol = (lamports) => Number(lamports) / LAMPORTS_PER_SOL;
|
|
14736
14547
|
const solToLamports = (sol) => BigInt(Math.round(sol * LAMPORTS_PER_SOL));
|
|
14737
14548
|
|
|
14738
|
-
var __async$
|
|
14549
|
+
var __async$g = (__this, __arguments, generator) => {
|
|
14739
14550
|
return new Promise((resolve, reject) => {
|
|
14740
14551
|
var fulfilled = (value) => {
|
|
14741
14552
|
try {
|
|
@@ -14889,7 +14700,7 @@ function buildSolanaTrancheSnapshot(options) {
|
|
|
14889
14700
|
};
|
|
14890
14701
|
}
|
|
14891
14702
|
function buildOutpostAccounts(connection, user, pgs) {
|
|
14892
|
-
return __async$
|
|
14703
|
+
return __async$g(this, null, function* () {
|
|
14893
14704
|
const globalState = pgs.deriveOutpostGlobalStatePda();
|
|
14894
14705
|
const poolAuthority = pgs.deriveOutpostPoolAuthorityPda();
|
|
14895
14706
|
const liqsolMint = pgs.deriveLiqsolMintPda();
|
|
@@ -14954,7 +14765,7 @@ function buildOutpostAccounts(connection, user, pgs) {
|
|
|
14954
14765
|
});
|
|
14955
14766
|
}
|
|
14956
14767
|
function getEpochSnapshot(connection) {
|
|
14957
|
-
return __async$
|
|
14768
|
+
return __async$g(this, null, function* () {
|
|
14958
14769
|
var _a;
|
|
14959
14770
|
const info = yield connection.getEpochInfo();
|
|
14960
14771
|
let slotTimeMs = Number((_a = process.env.SLOT_TIME_MS_FALLBACK) != null ? _a : 400);
|
|
@@ -14985,7 +14796,7 @@ function msToEpochEnd(snapshot) {
|
|
|
14985
14796
|
return remainingSlots * snapshot.slotMs;
|
|
14986
14797
|
}
|
|
14987
14798
|
function scheduledInstruction(connection, config, instruction) {
|
|
14988
|
-
return __async$
|
|
14799
|
+
return __async$g(this, null, function* () {
|
|
14989
14800
|
var _a, _b;
|
|
14990
14801
|
const early = (_a = config.early) != null ? _a : 0.1;
|
|
14991
14802
|
const late = (_b = config.late) != null ? _b : 0.9;
|
|
@@ -15032,14 +14843,14 @@ function generateTestKeypair() {
|
|
|
15032
14843
|
return web3_js.Keypair.generate();
|
|
15033
14844
|
}
|
|
15034
14845
|
function airdropSol(connection, publicKey, amountSol) {
|
|
15035
|
-
return __async$
|
|
14846
|
+
return __async$g(this, null, function* () {
|
|
15036
14847
|
const lamports = solToLamports(amountSol);
|
|
15037
14848
|
const sig = yield connection.requestAirdrop(publicKey, Number(lamports));
|
|
15038
14849
|
yield connection.confirmTransaction(sig, "confirmed");
|
|
15039
14850
|
});
|
|
15040
14851
|
}
|
|
15041
14852
|
function waitForConfirmation(connection, signature) {
|
|
15042
|
-
return __async$
|
|
14853
|
+
return __async$g(this, null, function* () {
|
|
15043
14854
|
yield connection.confirmTransaction(signature, "confirmed");
|
|
15044
14855
|
});
|
|
15045
14856
|
}
|
|
@@ -15047,8 +14858,8 @@ function sleep(ms) {
|
|
|
15047
14858
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
15048
14859
|
}
|
|
15049
14860
|
function waitUntilSafeToExecuteFunction(_0) {
|
|
15050
|
-
return __async$
|
|
15051
|
-
yield scheduledInstruction(connection, config, () => __async$
|
|
14861
|
+
return __async$g(this, arguments, function* (connection, config = {}) {
|
|
14862
|
+
yield scheduledInstruction(connection, config, () => __async$g(null, null, function* () {
|
|
15052
14863
|
return;
|
|
15053
14864
|
}));
|
|
15054
14865
|
});
|
|
@@ -15059,6 +14870,283 @@ function ceilDiv(n, d) {
|
|
|
15059
14870
|
}
|
|
15060
14871
|
return n.add(d.subn(1)).div(d);
|
|
15061
14872
|
}
|
|
14873
|
+
function normalizeToBigInt(x) {
|
|
14874
|
+
if (typeof x === "bigint") return x;
|
|
14875
|
+
if (x != null && typeof x === "object" && "toString" in x) return BigInt(x.toString());
|
|
14876
|
+
if (typeof x === "number") return BigInt(x);
|
|
14877
|
+
throw new Error(`normalizeToBigInt: unsupported type ${typeof x}`);
|
|
14878
|
+
}
|
|
14879
|
+
|
|
14880
|
+
var __pow = Math.pow;
|
|
14881
|
+
var __async$f = (__this, __arguments, generator) => {
|
|
14882
|
+
return new Promise((resolve, reject) => {
|
|
14883
|
+
var fulfilled = (value) => {
|
|
14884
|
+
try {
|
|
14885
|
+
step(generator.next(value));
|
|
14886
|
+
} catch (e) {
|
|
14887
|
+
reject(e);
|
|
14888
|
+
}
|
|
14889
|
+
};
|
|
14890
|
+
var rejected = (value) => {
|
|
14891
|
+
try {
|
|
14892
|
+
step(generator.throw(value));
|
|
14893
|
+
} catch (e) {
|
|
14894
|
+
reject(e);
|
|
14895
|
+
}
|
|
14896
|
+
};
|
|
14897
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
14898
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
14899
|
+
});
|
|
14900
|
+
};
|
|
14901
|
+
let ConvertClient$1 = class ConvertClient {
|
|
14902
|
+
constructor(provider, pgs) {
|
|
14903
|
+
this.provider = provider;
|
|
14904
|
+
this.pgs = pgs;
|
|
14905
|
+
this.program = pgs.getProgram("liqsolCore");
|
|
14906
|
+
}
|
|
14907
|
+
get connection() {
|
|
14908
|
+
return this.provider.connection;
|
|
14909
|
+
}
|
|
14910
|
+
get wallet() {
|
|
14911
|
+
return this.provider.wallet;
|
|
14912
|
+
}
|
|
14913
|
+
buildDepositTx(_0) {
|
|
14914
|
+
return __async$f(this, arguments, function* (amount, user = this.wallet.publicKey) {
|
|
14915
|
+
if (!user) throw new Error("ConvertClient.buildDepositTx: wallet not connected");
|
|
14916
|
+
if (!amount || amount <= BigInt(0))
|
|
14917
|
+
throw new Error("ConvertClient.buildDepositTx: amount must be greater than zero.");
|
|
14918
|
+
const depositAuthority = this.pgs.deriveDepositAuthorityPda();
|
|
14919
|
+
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
14920
|
+
const liqsolMintAuthority = this.pgs.deriveLiqsolMintAuthorityPda();
|
|
14921
|
+
const reservePool = this.pgs.deriveReservePoolPda();
|
|
14922
|
+
const vault = this.pgs.deriveVaultPda();
|
|
14923
|
+
const controllerState = this.pgs.deriveStakeControllerStatePda();
|
|
14924
|
+
const payoutState = this.pgs.derivePayoutStatePda();
|
|
14925
|
+
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
14926
|
+
const payRateHistory = this.pgs.derivePayRateHistoryPda();
|
|
14927
|
+
const globalConfig = this.pgs.deriveGlobalConfigPda();
|
|
14928
|
+
const userAta = splToken.getAssociatedTokenAddressSync(liqsolMint, user, true, splToken.TOKEN_2022_PROGRAM_ID);
|
|
14929
|
+
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
14930
|
+
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
14931
|
+
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
14932
|
+
liqsolMint,
|
|
14933
|
+
bucketAuthority,
|
|
14934
|
+
true,
|
|
14935
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
14936
|
+
);
|
|
14937
|
+
const seed = Math.floor(Math.random() * __pow(2, 32));
|
|
14938
|
+
const ephemeralStake = yield this.pgs.deriveEphemeralStakeAddress(user, seed);
|
|
14939
|
+
return yield this.program.methods.deposit(new anchor.BN(amount.toString()), seed).accounts({
|
|
14940
|
+
user,
|
|
14941
|
+
depositAuthority,
|
|
14942
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
14943
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
14944
|
+
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
14945
|
+
liqsolProgram: this.pgs.PROGRAM_IDS.LIQSOL_TOKEN,
|
|
14946
|
+
stakeProgram: web3_js.StakeProgram.programId,
|
|
14947
|
+
liqsolMint,
|
|
14948
|
+
userAta,
|
|
14949
|
+
liqsolMintAuthority,
|
|
14950
|
+
reservePool,
|
|
14951
|
+
vault,
|
|
14952
|
+
ephemeralStake,
|
|
14953
|
+
controllerState,
|
|
14954
|
+
payoutState,
|
|
14955
|
+
bucketAuthority,
|
|
14956
|
+
bucketTokenAccount,
|
|
14957
|
+
userRecord,
|
|
14958
|
+
distributionState,
|
|
14959
|
+
payRateHistory,
|
|
14960
|
+
instructionsSysvar: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
14961
|
+
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
14962
|
+
stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
14963
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
14964
|
+
globalConfig
|
|
14965
|
+
}).instruction();
|
|
14966
|
+
});
|
|
14967
|
+
}
|
|
14968
|
+
buildWithdrawTx(_0) {
|
|
14969
|
+
return __async$f(this, arguments, function* (amount, user = this.wallet.publicKey) {
|
|
14970
|
+
if (!user) throw new Error("ConvertClient.buildWithdrawTx: wallet not connected");
|
|
14971
|
+
if (!amount || amount <= BigInt(0))
|
|
14972
|
+
throw new Error("ConvertClient.buildWithdrawTx: amount must be greater than zero.");
|
|
14973
|
+
const liqsolMint = this.pgs.deriveLiqsolMintPda();
|
|
14974
|
+
const userAta = splToken.getAssociatedTokenAddressSync(liqsolMint, user, true, splToken.TOKEN_2022_PROGRAM_ID);
|
|
14975
|
+
const userRecord = this.pgs.deriveUserRecordPda(userAta);
|
|
14976
|
+
const distributionState = this.pgs.deriveDistributionStatePda();
|
|
14977
|
+
const global = this.pgs.deriveWithdrawGlobalPda();
|
|
14978
|
+
const reservePool = this.pgs.deriveReservePoolPda();
|
|
14979
|
+
const stakeAllocationState = this.pgs.deriveStakeAllocationStatePda();
|
|
14980
|
+
const stakeMetrics = this.pgs.deriveStakeMetricsPda();
|
|
14981
|
+
const maintenanceLedger = this.pgs.deriveMaintenanceLedgerPda();
|
|
14982
|
+
const globalConfig = this.pgs.deriveGlobalConfigPda();
|
|
14983
|
+
const globalAcct = yield this.program.account.global.fetch(global);
|
|
14984
|
+
const rawId = globalAcct.nextReceiptId;
|
|
14985
|
+
const receiptId = normalizeToBigInt(rawId);
|
|
14986
|
+
const mintAuthority = this.pgs.deriveWithdrawMintAuthorityPda();
|
|
14987
|
+
const metadata = this.pgs.deriveWithdrawMintMetadataPda();
|
|
14988
|
+
const nftMint = this.pgs.deriveWithdrawNftMintPda(receiptId);
|
|
14989
|
+
const receiptData = this.pgs.deriveLiqReceiptDataPda(nftMint);
|
|
14990
|
+
const owner = user;
|
|
14991
|
+
const nftAta = splToken.getAssociatedTokenAddressSync(nftMint, owner, true, splToken.TOKEN_2022_PROGRAM_ID);
|
|
14992
|
+
const bucketAuthority = this.pgs.deriveBucketAuthorityPda();
|
|
14993
|
+
const bucketTokenAccount = splToken.getAssociatedTokenAddressSync(
|
|
14994
|
+
liqsolMint,
|
|
14995
|
+
bucketAuthority,
|
|
14996
|
+
true,
|
|
14997
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
14998
|
+
);
|
|
14999
|
+
return yield this.program.methods.requestWithdraw(new anchor.BN(amount.toString())).accounts({
|
|
15000
|
+
user,
|
|
15001
|
+
owner,
|
|
15002
|
+
global,
|
|
15003
|
+
liqsolMint,
|
|
15004
|
+
userAta,
|
|
15005
|
+
userRecord,
|
|
15006
|
+
reservePool,
|
|
15007
|
+
stakeAllocationState,
|
|
15008
|
+
stakeMetrics,
|
|
15009
|
+
maintenanceLedger,
|
|
15010
|
+
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
15011
|
+
mintAuthority,
|
|
15012
|
+
receiptData,
|
|
15013
|
+
metadata,
|
|
15014
|
+
nftMint,
|
|
15015
|
+
nftAta,
|
|
15016
|
+
distributionState,
|
|
15017
|
+
bucketTokenAccount,
|
|
15018
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
15019
|
+
tokenInterface: splToken.TOKEN_2022_PROGRAM_ID,
|
|
15020
|
+
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
15021
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
15022
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
|
15023
|
+
globalConfig
|
|
15024
|
+
}).instruction();
|
|
15025
|
+
});
|
|
15026
|
+
}
|
|
15027
|
+
fetchWithdrawReceipts(owner) {
|
|
15028
|
+
return __async$f(this, null, function* () {
|
|
15029
|
+
var _a, _b, _c, _d;
|
|
15030
|
+
const globalPda = this.pgs.deriveWithdrawGlobalPda();
|
|
15031
|
+
const globalAcct = yield this.program.account.global.fetch(globalPda);
|
|
15032
|
+
const nextId = normalizeToBigInt(globalAcct.nextReceiptId);
|
|
15033
|
+
const mintToId = new Map();
|
|
15034
|
+
for (let i = BigInt(0); i < nextId; i++) {
|
|
15035
|
+
const mint = this.pgs.deriveWithdrawNftMintPda(i);
|
|
15036
|
+
mintToId.set(mint.toBase58(), i);
|
|
15037
|
+
}
|
|
15038
|
+
const tokenAccounts = yield this.connection.getParsedTokenAccountsByOwner(owner, {
|
|
15039
|
+
programId: splToken.TOKEN_2022_PROGRAM_ID
|
|
15040
|
+
});
|
|
15041
|
+
const receipts = [];
|
|
15042
|
+
for (const { pubkey, account } of tokenAccounts.value) {
|
|
15043
|
+
const info = (_b = (_a = account.data) == null ? void 0 : _a["parsed"]) == null ? void 0 : _b.info;
|
|
15044
|
+
if (!info) continue;
|
|
15045
|
+
const amount = info.tokenAmount;
|
|
15046
|
+
const decimals = Number((_c = amount == null ? void 0 : amount.decimals) != null ? _c : 0);
|
|
15047
|
+
const uiAmount = Number((_d = amount == null ? void 0 : amount.uiAmount) != null ? _d : 0);
|
|
15048
|
+
if (decimals !== 0 || uiAmount !== 1) continue;
|
|
15049
|
+
const mintStr = info.mint;
|
|
15050
|
+
if (!mintStr) continue;
|
|
15051
|
+
const receiptId = mintToId.get(mintStr);
|
|
15052
|
+
if (receiptId === void 0) continue;
|
|
15053
|
+
const mintKey = new web3_js.PublicKey(mintStr);
|
|
15054
|
+
const receiptDataPda = this.pgs.deriveLiqReceiptDataPda(mintKey);
|
|
15055
|
+
let receiptData;
|
|
15056
|
+
try {
|
|
15057
|
+
const raw = yield this.program.account.liqReceiptData.fetch(receiptDataPda);
|
|
15058
|
+
receiptData = {
|
|
15059
|
+
receiptId: normalizeToBigInt(raw.receiptId),
|
|
15060
|
+
liqports: normalizeToBigInt(raw.liqports),
|
|
15061
|
+
epoch: normalizeToBigInt(raw.epoch),
|
|
15062
|
+
fulfilled: Boolean(raw.fulfilled)
|
|
15063
|
+
};
|
|
15064
|
+
} catch (err) {
|
|
15065
|
+
console.warn(`ConvertClient: failed to fetch receipt data for mint ${mintStr}`, err);
|
|
15066
|
+
continue;
|
|
15067
|
+
}
|
|
15068
|
+
const { etaMs, readyAtMs } = yield this.estimateEpochEta(receiptData.epoch);
|
|
15069
|
+
const status = receiptData.fulfilled ? "claimed" : etaMs <= 0 ? "ready" : "queued";
|
|
15070
|
+
const amountView = {
|
|
15071
|
+
amount: receiptData.liqports,
|
|
15072
|
+
decimals: 9,
|
|
15073
|
+
symbol: "SOL"
|
|
15074
|
+
};
|
|
15075
|
+
receipts.push({
|
|
15076
|
+
tokenId: receiptData.receiptId,
|
|
15077
|
+
receipt: {
|
|
15078
|
+
amount: amountView,
|
|
15079
|
+
readyAt: readyAtMs,
|
|
15080
|
+
chain: "SOL",
|
|
15081
|
+
epoch: receiptData.epoch,
|
|
15082
|
+
status,
|
|
15083
|
+
mint: mintKey.toBase58(),
|
|
15084
|
+
ownerAta: pubkey.toBase58()
|
|
15085
|
+
}
|
|
15086
|
+
});
|
|
15087
|
+
}
|
|
15088
|
+
return receipts;
|
|
15089
|
+
});
|
|
15090
|
+
}
|
|
15091
|
+
buildClaimWithdrawTx(receiptId, user) {
|
|
15092
|
+
return __async$f(this, null, function* () {
|
|
15093
|
+
const mintAccount = this.pgs.deriveWithdrawNftMintPda(receiptId);
|
|
15094
|
+
const receiptData = this.pgs.deriveLiqReceiptDataPda(mintAccount);
|
|
15095
|
+
const ownerAta = splToken.getAssociatedTokenAddressSync(
|
|
15096
|
+
mintAccount,
|
|
15097
|
+
user,
|
|
15098
|
+
true,
|
|
15099
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
15100
|
+
);
|
|
15101
|
+
const accounts = {
|
|
15102
|
+
user,
|
|
15103
|
+
global: this.pgs.deriveWithdrawGlobalPda(),
|
|
15104
|
+
mintAuthority: this.pgs.deriveWithdrawMintAuthorityPda(),
|
|
15105
|
+
receiptData,
|
|
15106
|
+
mintAccount,
|
|
15107
|
+
ownerAta,
|
|
15108
|
+
reservePool: this.pgs.deriveReservePoolPda(),
|
|
15109
|
+
vault: this.pgs.deriveVaultPda(),
|
|
15110
|
+
clock: web3_js.SYSVAR_CLOCK_PUBKEY,
|
|
15111
|
+
stakeHistory: web3_js.SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
15112
|
+
globalConfig: this.pgs.deriveGlobalConfigPda(),
|
|
15113
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
|
|
15114
|
+
stakeProgram: web3_js.StakeProgram.programId,
|
|
15115
|
+
systemProgram: web3_js.SystemProgram.programId,
|
|
15116
|
+
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
15117
|
+
};
|
|
15118
|
+
return this.program.methods.claimWithdraw().accounts(accounts).instruction();
|
|
15119
|
+
});
|
|
15120
|
+
}
|
|
15121
|
+
estimateEpochEta(targetEpoch) {
|
|
15122
|
+
return __async$f(this, null, function* () {
|
|
15123
|
+
const conn = this.connection;
|
|
15124
|
+
const epochInfo = yield conn.getEpochInfo();
|
|
15125
|
+
const schedule = yield conn.getEpochSchedule();
|
|
15126
|
+
const currentEpoch = BigInt(epochInfo.epoch);
|
|
15127
|
+
if (targetEpoch <= currentEpoch) {
|
|
15128
|
+
const now = Date.now();
|
|
15129
|
+
return { etaMs: 0, readyAtMs: now };
|
|
15130
|
+
}
|
|
15131
|
+
let slotTimeSec = 0.4;
|
|
15132
|
+
try {
|
|
15133
|
+
const samples = yield conn.getRecentPerformanceSamples(1);
|
|
15134
|
+
if (samples == null ? void 0 : samples.length) {
|
|
15135
|
+
const s = samples[0];
|
|
15136
|
+
slotTimeSec = s.numSlots > 0 ? s.samplePeriodSecs / s.numSlots : slotTimeSec;
|
|
15137
|
+
}
|
|
15138
|
+
} catch (_) {
|
|
15139
|
+
}
|
|
15140
|
+
const slotsPerEpoch = BigInt(schedule.slotsPerEpoch);
|
|
15141
|
+
const slotsRemainingInCurrent = slotsPerEpoch - BigInt(epochInfo.slotIndex);
|
|
15142
|
+
const epochsRemaining = targetEpoch - currentEpoch - BigInt(1);
|
|
15143
|
+
const slotsRemaining = (epochsRemaining > 0 ? epochsRemaining * slotsPerEpoch : BigInt(0)) + slotsRemainingInCurrent;
|
|
15144
|
+
const etaSeconds = Number(slotsRemaining) * slotTimeSec;
|
|
15145
|
+
const etaMs = Math.max(0, Math.round(etaSeconds * 1e3));
|
|
15146
|
+
return { etaMs, readyAtMs: Date.now() + etaMs };
|
|
15147
|
+
});
|
|
15148
|
+
}
|
|
15149
|
+
};
|
|
15062
15150
|
|
|
15063
15151
|
var __async$e = (__this, __arguments, generator) => {
|
|
15064
15152
|
return new Promise((resolve, reject) => {
|
|
@@ -15080,6 +15168,7 @@ var __async$e = (__this, __arguments, generator) => {
|
|
|
15080
15168
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
15081
15169
|
});
|
|
15082
15170
|
};
|
|
15171
|
+
const INDEX_SCALE_BN = new anchor.BN("1000000000000");
|
|
15083
15172
|
class DistributionClient {
|
|
15084
15173
|
constructor(provider, pgs) {
|
|
15085
15174
|
this.provider = provider;
|
|
@@ -15089,6 +15178,16 @@ class DistributionClient {
|
|
|
15089
15178
|
get connection() {
|
|
15090
15179
|
return this.provider.connection;
|
|
15091
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
|
+
}
|
|
15092
15191
|
getDistributionState() {
|
|
15093
15192
|
return __async$e(this, null, function* () {
|
|
15094
15193
|
const pda = this.pgs.deriveDistributionStatePda();
|
|
@@ -15168,6 +15267,85 @@ class DistributionClient {
|
|
|
15168
15267
|
return { shares: userShares, totalShares, ratio };
|
|
15169
15268
|
});
|
|
15170
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
|
+
}
|
|
15171
15349
|
getAverageScaledPayRate(windowSize = 5) {
|
|
15172
15350
|
return __async$e(this, null, function* () {
|
|
15173
15351
|
var _a, _b, _c, _d, _e;
|
|
@@ -16027,7 +16205,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16027
16205
|
commitment
|
|
16028
16206
|
});
|
|
16029
16207
|
this.program = new SolanaProgramService(this.anchor, config.network.chainId);
|
|
16030
|
-
this.
|
|
16208
|
+
this.convertClient = new ConvertClient$1(this.anchor, this.program);
|
|
16031
16209
|
this.distributionClient = new DistributionClient(this.anchor, this.program);
|
|
16032
16210
|
this.leaderboardClient = new LeaderboardClient(this.anchor, this.program);
|
|
16033
16211
|
this.outpostClient = new OutpostClient(this.anchor, this.program);
|
|
@@ -16056,7 +16234,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16056
16234
|
if (amountLamports <= BigInt(0))
|
|
16057
16235
|
throw new Error("Deposit amount must be greater than zero.");
|
|
16058
16236
|
try {
|
|
16059
|
-
const ix = yield this.
|
|
16237
|
+
const ix = yield this.convertClient.buildDepositTx(amountLamports, this.squadsVaultPDA);
|
|
16060
16238
|
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16061
16239
|
} catch (err) {
|
|
16062
16240
|
console.log(`Failed to deposit Solana: ${err}`);
|
|
@@ -16070,7 +16248,7 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16070
16248
|
if (amountLamports <= BigInt(0))
|
|
16071
16249
|
throw new Error("Withdraw amount must be greater than zero.");
|
|
16072
16250
|
try {
|
|
16073
|
-
const ix = yield this.
|
|
16251
|
+
const ix = yield this.convertClient.buildWithdrawTx(amountLamports, this.squadsVaultPDA);
|
|
16074
16252
|
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16075
16253
|
} catch (err) {
|
|
16076
16254
|
console.log(`Failed to withdraw Solana: ${err}`);
|
|
@@ -16078,6 +16256,42 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16078
16256
|
}
|
|
16079
16257
|
});
|
|
16080
16258
|
}
|
|
16259
|
+
getPendingWithdraws() {
|
|
16260
|
+
return __async$9(this, null, function* () {
|
|
16261
|
+
var _a;
|
|
16262
|
+
this.ensureUser();
|
|
16263
|
+
const owner = (_a = this.squadsVaultPDA) != null ? _a : this.anchor.wallet.publicKey;
|
|
16264
|
+
return yield this.convertClient.fetchWithdrawReceipts(owner);
|
|
16265
|
+
});
|
|
16266
|
+
}
|
|
16267
|
+
claimWithdraw(tokenId) {
|
|
16268
|
+
return __async$9(this, null, function* () {
|
|
16269
|
+
var _a;
|
|
16270
|
+
this.ensureUser();
|
|
16271
|
+
const owner = (_a = this.squadsVaultPDA) != null ? _a : this.anchor.wallet.publicKey;
|
|
16272
|
+
try {
|
|
16273
|
+
const ix = yield this.convertClient.buildClaimWithdrawTx(tokenId, owner);
|
|
16274
|
+
return !!this.squadsX ? yield this.sendSquadsIxs(ix) : yield this.buildAndSendIx(ix);
|
|
16275
|
+
} catch (err) {
|
|
16276
|
+
console.log(`Failed to claim withdraw on Solana: ${err}`);
|
|
16277
|
+
throw err;
|
|
16278
|
+
}
|
|
16279
|
+
});
|
|
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
|
+
}
|
|
16081
16295
|
stake(amountLamports) {
|
|
16082
16296
|
return __async$9(this, null, function* () {
|
|
16083
16297
|
this.ensureUser();
|
|
@@ -16135,10 +16349,11 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16135
16349
|
splToken.TOKEN_2022_PROGRAM_ID,
|
|
16136
16350
|
splToken.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
16137
16351
|
);
|
|
16138
|
-
const [nativeLamports, actualBalResp, snapshot] = yield Promise.all([
|
|
16352
|
+
const [nativeLamports, actualBalResp, snapshot, claimableLamports] = yield Promise.all([
|
|
16139
16353
|
this.connection.getBalance(user, "confirmed"),
|
|
16140
16354
|
this.connection.getTokenAccountBalance(userLiqsolAta, "confirmed").catch(() => null),
|
|
16141
|
-
this.outpostClient.fetchWireState(user).catch(() => null)
|
|
16355
|
+
this.outpostClient.fetchWireState(user).catch(() => null),
|
|
16356
|
+
this.distributionClient.getClaimableLiqsol(user).catch(() => new anchor.BN(0))
|
|
16142
16357
|
]);
|
|
16143
16358
|
const LIQSOL_DECIMALS = 9;
|
|
16144
16359
|
const actualAmountStr = (_b = (_a = actualBalResp == null ? void 0 : actualBalResp.value) == null ? void 0 : _a.amount) != null ? _b : "0";
|
|
@@ -16175,6 +16390,12 @@ const _SolanaStakingClient = class _SolanaStakingClient {
|
|
|
16175
16390
|
decimals: LIQSOL_DECIMALS,
|
|
16176
16391
|
ata: userLiqsolAta
|
|
16177
16392
|
},
|
|
16393
|
+
claimable: {
|
|
16394
|
+
amount: BigInt(claimableLamports.toString()),
|
|
16395
|
+
symbol: "LiqSOL",
|
|
16396
|
+
decimals: LIQSOL_DECIMALS,
|
|
16397
|
+
ata: userLiqsolAta
|
|
16398
|
+
},
|
|
16178
16399
|
staked: {
|
|
16179
16400
|
amount: stakedLiqsol,
|
|
16180
16401
|
symbol: "LiqSOL",
|
|
@@ -41823,34 +42044,6 @@ class ReceiptClient {
|
|
|
41823
42044
|
return results;
|
|
41824
42045
|
});
|
|
41825
42046
|
}
|
|
41826
|
-
getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
|
|
41827
|
-
return __async$2(this, null, function* () {
|
|
41828
|
-
var _a, _b;
|
|
41829
|
-
const receiptContract = this.contract.ReceiptNFT;
|
|
41830
|
-
const toLogs = yield receiptContract.queryFilter(
|
|
41831
|
-
receiptContract.filters.Transfer(null, owner),
|
|
41832
|
-
fromBlock,
|
|
41833
|
-
toBlock
|
|
41834
|
-
);
|
|
41835
|
-
const fromLogs = yield receiptContract.queryFilter(
|
|
41836
|
-
receiptContract.filters.Transfer(owner, null),
|
|
41837
|
-
fromBlock,
|
|
41838
|
-
toBlock
|
|
41839
|
-
);
|
|
41840
|
-
const owned = new Set();
|
|
41841
|
-
for (const e of toLogs) {
|
|
41842
|
-
const tokenId = (_a = e.args) == null ? void 0 : _a.tokenId;
|
|
41843
|
-
if (!tokenId) continue;
|
|
41844
|
-
owned.add(tokenId.toString());
|
|
41845
|
-
}
|
|
41846
|
-
for (const e of fromLogs) {
|
|
41847
|
-
const tokenId = (_b = e.args) == null ? void 0 : _b.tokenId;
|
|
41848
|
-
if (!tokenId) continue;
|
|
41849
|
-
owned.delete(tokenId.toString());
|
|
41850
|
-
}
|
|
41851
|
-
return Array.from(owned).map((id) => ethers.BigNumber.from(id));
|
|
41852
|
-
});
|
|
41853
|
-
}
|
|
41854
42047
|
fetchWithdrawReceipts(address) {
|
|
41855
42048
|
return __async$2(this, null, function* () {
|
|
41856
42049
|
const tokenIds = yield this.getOwnedWithdrawReceiptsFor(address);
|
|
@@ -41858,16 +42051,19 @@ class ReceiptClient {
|
|
|
41858
42051
|
for (const idBN of tokenIds) {
|
|
41859
42052
|
try {
|
|
41860
42053
|
const receiptData = yield this.contract.WithdrawalQueue.info(idBN);
|
|
42054
|
+
const readyAtMs = Number(receiptData.readyAt) * 1e3;
|
|
42055
|
+
const status = readyAtMs <= Date.now() ? "ready" : "queued";
|
|
41861
42056
|
results.push({
|
|
41862
42057
|
tokenId: idBN.toBigInt(),
|
|
41863
42058
|
receipt: {
|
|
41864
|
-
|
|
41865
|
-
ethBalance: {
|
|
42059
|
+
amount: {
|
|
41866
42060
|
amount: receiptData.ethAmount.toBigInt(),
|
|
41867
42061
|
decimals: 18,
|
|
41868
42062
|
symbol: "ETH"
|
|
41869
42063
|
},
|
|
41870
|
-
readyAt:
|
|
42064
|
+
readyAt: readyAtMs,
|
|
42065
|
+
chain: "ETH",
|
|
42066
|
+
status
|
|
41871
42067
|
}
|
|
41872
42068
|
});
|
|
41873
42069
|
} catch (err) {
|
|
@@ -41906,6 +42102,34 @@ class ReceiptClient {
|
|
|
41906
42102
|
return Array.from(owned).map((id) => ethers.BigNumber.from(id));
|
|
41907
42103
|
});
|
|
41908
42104
|
}
|
|
42105
|
+
getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
|
|
42106
|
+
return __async$2(this, null, function* () {
|
|
42107
|
+
var _a, _b;
|
|
42108
|
+
const receiptContract = this.contract.ReceiptNFT;
|
|
42109
|
+
const toLogs = yield receiptContract.queryFilter(
|
|
42110
|
+
receiptContract.filters.Transfer(null, owner),
|
|
42111
|
+
fromBlock,
|
|
42112
|
+
toBlock
|
|
42113
|
+
);
|
|
42114
|
+
const fromLogs = yield receiptContract.queryFilter(
|
|
42115
|
+
receiptContract.filters.Transfer(owner, null),
|
|
42116
|
+
fromBlock,
|
|
42117
|
+
toBlock
|
|
42118
|
+
);
|
|
42119
|
+
const owned = new Set();
|
|
42120
|
+
for (const e of toLogs) {
|
|
42121
|
+
const tokenId = (_a = e.args) == null ? void 0 : _a.tokenId;
|
|
42122
|
+
if (!tokenId) continue;
|
|
42123
|
+
owned.add(tokenId.toString());
|
|
42124
|
+
}
|
|
42125
|
+
for (const e of fromLogs) {
|
|
42126
|
+
const tokenId = (_b = e.args) == null ? void 0 : _b.tokenId;
|
|
42127
|
+
if (!tokenId) continue;
|
|
42128
|
+
owned.delete(tokenId.toString());
|
|
42129
|
+
}
|
|
42130
|
+
return Array.from(owned).map((id) => ethers.BigNumber.from(id));
|
|
42131
|
+
});
|
|
42132
|
+
}
|
|
41909
42133
|
}
|
|
41910
42134
|
|
|
41911
42135
|
var __async$1 = (__this, __arguments, generator) => {
|
|
@@ -42019,6 +42243,10 @@ class EthereumStakingClient {
|
|
|
42019
42243
|
get network() {
|
|
42020
42244
|
return this.config.network;
|
|
42021
42245
|
}
|
|
42246
|
+
get address() {
|
|
42247
|
+
var _a;
|
|
42248
|
+
return (_a = this.signer) == null ? void 0 : _a.getAddress();
|
|
42249
|
+
}
|
|
42022
42250
|
deposit(amount) {
|
|
42023
42251
|
return __async(this, null, function* () {
|
|
42024
42252
|
this.ensureUser();
|
|
@@ -42030,16 +42258,16 @@ class EthereumStakingClient {
|
|
|
42030
42258
|
withdraw(amount) {
|
|
42031
42259
|
return __async(this, null, function* () {
|
|
42032
42260
|
this.ensureUser();
|
|
42033
|
-
const address = yield this.
|
|
42261
|
+
const address = yield this.address;
|
|
42034
42262
|
const amountWei = ethers.BigNumber.from(amount);
|
|
42035
42263
|
const result = yield this.convertClient.performWithdraw(address, amountWei);
|
|
42036
42264
|
return result.txHash;
|
|
42037
42265
|
});
|
|
42038
42266
|
}
|
|
42039
|
-
|
|
42267
|
+
getPendingWithdraws() {
|
|
42040
42268
|
return __async(this, null, function* () {
|
|
42041
42269
|
this.ensureUser();
|
|
42042
|
-
const address = yield this.
|
|
42270
|
+
const address = yield this.address;
|
|
42043
42271
|
return yield this.receiptClient.fetchWithdrawReceipts(address);
|
|
42044
42272
|
});
|
|
42045
42273
|
}
|
|
@@ -42054,7 +42282,7 @@ class EthereumStakingClient {
|
|
|
42054
42282
|
stake(amount) {
|
|
42055
42283
|
return __async(this, null, function* () {
|
|
42056
42284
|
this.ensureUser();
|
|
42057
|
-
const walletAddress = yield this.
|
|
42285
|
+
const walletAddress = yield this.address;
|
|
42058
42286
|
const amountWei = ethers.BigNumber.from(amount);
|
|
42059
42287
|
const result = yield this.stakeClient.performStake(amountWei, walletAddress);
|
|
42060
42288
|
return result.txHash;
|
|
@@ -42076,7 +42304,7 @@ class EthereumStakingClient {
|
|
|
42076
42304
|
buy(amount) {
|
|
42077
42305
|
return __async(this, null, function* () {
|
|
42078
42306
|
this.ensureUser();
|
|
42079
|
-
const buyer = yield this.
|
|
42307
|
+
const buyer = yield this.address;
|
|
42080
42308
|
let result = yield this.pretokenClient.purchasePretokensWithLiqETH(amount, buyer);
|
|
42081
42309
|
return result && result.txHash ? result.txHash : "Error - no resulting txHash";
|
|
42082
42310
|
});
|
|
@@ -42093,7 +42321,7 @@ class EthereumStakingClient {
|
|
|
42093
42321
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
42094
42322
|
try {
|
|
42095
42323
|
if (!this.signer) return Promise.resolve(null);
|
|
42096
|
-
const walletAddress = yield this.
|
|
42324
|
+
const walletAddress = yield this.address;
|
|
42097
42325
|
const nativeBalance = yield this.provider.getBalance(walletAddress);
|
|
42098
42326
|
const nativeDecimals = (_c = (_b = (_a = this.network) == null ? void 0 : _a.nativeCurrency) == null ? void 0 : _b.decimals) != null ? _c : 18;
|
|
42099
42327
|
const nativeSymbol = (_f = (_e = (_d = this.network) == null ? void 0 : _d.nativeCurrency) == null ? void 0 : _e.symbol) != null ? _f : "ETH";
|
|
@@ -42173,14 +42401,14 @@ class EthereumStakingClient {
|
|
|
42173
42401
|
fetchPrelaunchReceipts(address) {
|
|
42174
42402
|
return __async(this, null, function* () {
|
|
42175
42403
|
this.ensureUser();
|
|
42176
|
-
if (address === void 0) address = yield this.
|
|
42404
|
+
if (address === void 0) address = yield this.address;
|
|
42177
42405
|
return yield this.receiptClient.stakeReceipts(address);
|
|
42178
42406
|
});
|
|
42179
42407
|
}
|
|
42180
42408
|
getOPPMessages(address) {
|
|
42181
42409
|
return __async(this, null, function* () {
|
|
42182
42410
|
this.ensureUser();
|
|
42183
|
-
if (!address) address = yield this.
|
|
42411
|
+
if (!address) address = yield this.address;
|
|
42184
42412
|
return yield this.oppClient.getMessages(address);
|
|
42185
42413
|
});
|
|
42186
42414
|
}
|
|
@@ -42268,7 +42496,7 @@ class EthereumStakingClient {
|
|
|
42268
42496
|
return __async(this, null, function* () {
|
|
42269
42497
|
var _a, _b, _c, _d, _e;
|
|
42270
42498
|
this.ensureUser();
|
|
42271
|
-
const walletAddress = yield this.
|
|
42499
|
+
const walletAddress = yield this.address;
|
|
42272
42500
|
const baseGas = yield this.provider.estimateGas({
|
|
42273
42501
|
from: walletAddress,
|
|
42274
42502
|
to: walletAddress,
|
|
@@ -42364,12 +42592,12 @@ const CONTRACT_NAMES = [
|
|
|
42364
42592
|
];
|
|
42365
42593
|
|
|
42366
42594
|
var types$1 = /*#__PURE__*/Object.freeze({
|
|
42367
|
-
|
|
42368
|
-
|
|
42595
|
+
__proto__: null,
|
|
42596
|
+
CONTRACT_NAMES: CONTRACT_NAMES
|
|
42369
42597
|
});
|
|
42370
42598
|
|
|
42371
42599
|
var types = /*#__PURE__*/Object.freeze({
|
|
42372
|
-
|
|
42600
|
+
__proto__: null
|
|
42373
42601
|
});
|
|
42374
42602
|
|
|
42375
42603
|
exports.ADDRESSES = ADDRESSES;
|
|
@@ -42377,9 +42605,9 @@ exports.ADDRESS_BOOK_BY_CHAIN = ADDRESS_BOOK_BY_CHAIN;
|
|
|
42377
42605
|
exports.CHAINLINK_FEED = CHAINLINK_FEED;
|
|
42378
42606
|
exports.CHAINLINK_PROGRAM = CHAINLINK_PROGRAM;
|
|
42379
42607
|
exports.CONTRACTS_BY_CHAIN = CONTRACTS_BY_CHAIN;
|
|
42608
|
+
exports.ConvertClient = ConvertClient$1;
|
|
42380
42609
|
exports.DEFAULT_AVERAGE_PAY_RATE = DEFAULT_AVERAGE_PAY_RATE;
|
|
42381
42610
|
exports.DEFAULT_PAY_RATE_LOOKBACK = DEFAULT_PAY_RATE_LOOKBACK;
|
|
42382
|
-
exports.DepositClient = DepositClient;
|
|
42383
42611
|
exports.DistributionClient = DistributionClient;
|
|
42384
42612
|
exports.EPHEMERAL_RENT_EXEMPTION = EPHEMERAL_RENT_EXEMPTION;
|
|
42385
42613
|
exports.ERC1155Abi = ERC1155Abi;
|
|
@@ -42420,6 +42648,7 @@ exports.getErrorMessage = getErrorMessage;
|
|
|
42420
42648
|
exports.getProgramIds = getProgramIds;
|
|
42421
42649
|
exports.lamportsToSol = lamportsToSol;
|
|
42422
42650
|
exports.msToEpochEnd = msToEpochEnd;
|
|
42651
|
+
exports.normalizeToBigInt = normalizeToBigInt;
|
|
42423
42652
|
exports.scheduledInstruction = scheduledInstruction;
|
|
42424
42653
|
exports.sleep = sleep;
|
|
42425
42654
|
exports.solToLamports = solToLamports;
|