@wireio/stake 0.9.1 → 0.9.2
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 +95 -3
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +27 -1
- package/lib/stake.js +107 -3
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +95 -3
- package/lib/stake.m.js.map +1 -1
- package/package.json +3 -3
- package/src/networks/ethereum/clients/convert.client.ts +29 -1
- package/src/networks/ethereum/clients/receipt.client.ts +81 -3
- package/src/networks/ethereum/clients/stake.client.ts +1 -0
- package/src/networks/ethereum/ethereum.ts +33 -11
- package/src/networks/ethereum/types.ts +15 -0
package/lib/stake.d.ts
CHANGED
|
@@ -333,15 +333,29 @@ interface preLaunchReceipt {
|
|
|
333
333
|
timestamp: string;
|
|
334
334
|
};
|
|
335
335
|
}
|
|
336
|
+
interface ClaimedEvent {
|
|
337
|
+
sender: string;
|
|
338
|
+
ethAmount: BigNumber;
|
|
339
|
+
}
|
|
340
|
+
interface WithdrawReceipt {
|
|
341
|
+
tokenId: bigint;
|
|
342
|
+
receipt: {
|
|
343
|
+
ethAmount: BigNumber;
|
|
344
|
+
ethBalance: BalanceView;
|
|
345
|
+
readyAt: number;
|
|
346
|
+
};
|
|
347
|
+
}
|
|
336
348
|
|
|
337
349
|
type types$1_AddressBook = AddressBook;
|
|
338
350
|
declare const types$1_CONTRACT_NAMES: typeof CONTRACT_NAMES;
|
|
351
|
+
type types$1_ClaimedEvent = ClaimedEvent;
|
|
339
352
|
type types$1_ContractName = ContractName;
|
|
340
353
|
type types$1_DepositEvent = DepositEvent;
|
|
341
354
|
type types$1_DepositResult = DepositResult;
|
|
342
355
|
type types$1_SharesBurnedEvent = SharesBurnedEvent;
|
|
343
356
|
type types$1_StakedEvent = StakedEvent;
|
|
344
357
|
type types$1_StakedResult = StakedResult;
|
|
358
|
+
type types$1_WithdrawReceipt = WithdrawReceipt;
|
|
345
359
|
type types$1_WithdrawRequestedEvent = WithdrawRequestedEvent;
|
|
346
360
|
type types$1_WithdrawResult = WithdrawResult;
|
|
347
361
|
type types$1_WithdrawnStakeEvent = WithdrawnStakeEvent;
|
|
@@ -349,7 +363,7 @@ type types$1_WithdrawnStakeResult = WithdrawnStakeResult;
|
|
|
349
363
|
type types$1_preLaunchReceipt = preLaunchReceipt;
|
|
350
364
|
declare namespace types$1 {
|
|
351
365
|
export { types$1_CONTRACT_NAMES as CONTRACT_NAMES };
|
|
352
|
-
export type { types$1_AddressBook as AddressBook, types$1_ContractName as ContractName, types$1_DepositEvent as DepositEvent, types$1_DepositResult as DepositResult, types$1_SharesBurnedEvent as SharesBurnedEvent, types$1_StakedEvent as StakedEvent, types$1_StakedResult as StakedResult, types$1_WithdrawRequestedEvent as WithdrawRequestedEvent, types$1_WithdrawResult as WithdrawResult, types$1_WithdrawnStakeEvent as WithdrawnStakeEvent, types$1_WithdrawnStakeResult as WithdrawnStakeResult, types$1_preLaunchReceipt as preLaunchReceipt };
|
|
366
|
+
export type { types$1_AddressBook as AddressBook, types$1_ClaimedEvent as ClaimedEvent, types$1_ContractName as ContractName, types$1_DepositEvent as DepositEvent, types$1_DepositResult as DepositResult, types$1_SharesBurnedEvent as SharesBurnedEvent, types$1_StakedEvent as StakedEvent, types$1_StakedResult as StakedResult, types$1_WithdrawReceipt as WithdrawReceipt, types$1_WithdrawRequestedEvent as WithdrawRequestedEvent, types$1_WithdrawResult as WithdrawResult, types$1_WithdrawnStakeEvent as WithdrawnStakeEvent, types$1_WithdrawnStakeResult as WithdrawnStakeResult, types$1_preLaunchReceipt as preLaunchReceipt };
|
|
353
367
|
}
|
|
354
368
|
|
|
355
369
|
declare const INITIAL_TRANCHE_SUPPLY = 35000;
|
|
@@ -406,6 +420,18 @@ declare class EthereumStakingClient implements IStakingClient {
|
|
|
406
420
|
* @returns transaction hash
|
|
407
421
|
*/
|
|
408
422
|
withdraw(amount: bigint): Promise<string>;
|
|
423
|
+
/**
|
|
424
|
+
* Withdraw native ETH from the liqETH protocol via the liqeth safeBurn function, which burns the LiqETH and adds the user to the withdrawal queue.
|
|
425
|
+
* @param amount Amount in wei (or something convertible to BigNumber).
|
|
426
|
+
* @returns transaction hash
|
|
427
|
+
*/
|
|
428
|
+
loadPendingWithdraws(): Promise<WithdrawReceipt[]>;
|
|
429
|
+
/**
|
|
430
|
+
* Withdraw native ETH from the liqETH protocol via the liqeth safeBurn function, which burns the LiqETH and adds the user to the withdrawal queue.
|
|
431
|
+
* @param amount Amount in wei (or something convertible to BigNumber).
|
|
432
|
+
* @returns transaction hash
|
|
433
|
+
*/
|
|
434
|
+
claimWithdraw(tokenId: bigint): Promise<string>;
|
|
409
435
|
/**
|
|
410
436
|
* Stake liqETH via DepositManager.
|
|
411
437
|
* @param amount Amount in wei - Keep this as a bigint / string in the caller; avoid JS floats.
|
package/lib/stake.js
CHANGED
|
@@ -35553,6 +35553,33 @@ class ConvertClient {
|
|
|
35553
35553
|
};
|
|
35554
35554
|
});
|
|
35555
35555
|
}
|
|
35556
|
+
claimWithdraw(tokenId) {
|
|
35557
|
+
return __async$5(this, null, function* () {
|
|
35558
|
+
var _a, _b;
|
|
35559
|
+
let tx, receipt;
|
|
35560
|
+
try {
|
|
35561
|
+
tx = yield this.contract.DepositManager.claim(tokenId);
|
|
35562
|
+
receipt = yield tx.wait(1);
|
|
35563
|
+
} catch (err) {
|
|
35564
|
+
let errorObj = formatContractErrors(err);
|
|
35565
|
+
throw new Error((_a = errorObj.name) != null ? _a : errorObj.raw);
|
|
35566
|
+
}
|
|
35567
|
+
let event;
|
|
35568
|
+
const ev = (_b = receipt.events) == null ? void 0 : _b.find((e) => e.event === "Claimed");
|
|
35569
|
+
if (ev && ev.args) {
|
|
35570
|
+
const { sender, ethAmount } = ev.args;
|
|
35571
|
+
event = {
|
|
35572
|
+
sender,
|
|
35573
|
+
ethAmount: ethers.BigNumber.from(ethAmount)
|
|
35574
|
+
};
|
|
35575
|
+
}
|
|
35576
|
+
return {
|
|
35577
|
+
txHash: tx.hash,
|
|
35578
|
+
receipt,
|
|
35579
|
+
event
|
|
35580
|
+
};
|
|
35581
|
+
});
|
|
35582
|
+
}
|
|
35556
35583
|
}
|
|
35557
35584
|
|
|
35558
35585
|
var __async$4 = (__this, __arguments, generator) => {
|
|
@@ -35598,12 +35625,13 @@ class StakeClient {
|
|
|
35598
35625
|
var _a;
|
|
35599
35626
|
const depositor = this.contract.Depositor.address;
|
|
35600
35627
|
const liqRead = this.contract.LiqEthToken;
|
|
35601
|
-
yield liqRead.balanceOf(signerAddress);
|
|
35628
|
+
const bal = yield liqRead.balanceOf(signerAddress);
|
|
35602
35629
|
const allowance = yield liqRead.allowance(signerAddress, depositor);
|
|
35603
35630
|
const paused = yield this.contract.Depositor.paused();
|
|
35604
35631
|
if (paused) {
|
|
35605
35632
|
throw new Error("Error - Depositor is in a paused state");
|
|
35606
35633
|
}
|
|
35634
|
+
if (bal.lt(amountWei)) throw new Error("Insufficient LiqETH balance");
|
|
35607
35635
|
if (allowance.lt(amountWei)) {
|
|
35608
35636
|
const liqWrite = this.contractService.getWrite("LiqEthToken");
|
|
35609
35637
|
console.warn(`allowance insufficient (${allowance.toString()} < ${amountWei.toString()}); sending approve(${depositor}, ${amountWei.toString()})`);
|
|
@@ -36129,7 +36157,7 @@ class ReceiptClient {
|
|
|
36129
36157
|
fetchPreLaunchReceipts(address, type) {
|
|
36130
36158
|
return __async$1(this, null, function* () {
|
|
36131
36159
|
const receiptContract = this.contract.ReceiptNFT;
|
|
36132
|
-
const tokenIds = yield this.
|
|
36160
|
+
const tokenIds = yield this.getOwnedReceiptNFTsFor(address);
|
|
36133
36161
|
const results = [];
|
|
36134
36162
|
for (const idBN of tokenIds) {
|
|
36135
36163
|
try {
|
|
@@ -36163,7 +36191,7 @@ class ReceiptClient {
|
|
|
36163
36191
|
return results;
|
|
36164
36192
|
});
|
|
36165
36193
|
}
|
|
36166
|
-
|
|
36194
|
+
getOwnedReceiptNFTsFor(owner, fromBlock = 0, toBlock = "latest") {
|
|
36167
36195
|
return __async$1(this, null, function* () {
|
|
36168
36196
|
var _a, _b;
|
|
36169
36197
|
const receiptContract = this.contract.ReceiptNFT;
|
|
@@ -36191,6 +36219,61 @@ class ReceiptClient {
|
|
|
36191
36219
|
return Array.from(owned).map((id) => ethers.BigNumber.from(id));
|
|
36192
36220
|
});
|
|
36193
36221
|
}
|
|
36222
|
+
fetchWithdrawReceipts(address) {
|
|
36223
|
+
return __async$1(this, null, function* () {
|
|
36224
|
+
const tokenIds = yield this.getOwnedWithdrawReceiptsFor(address);
|
|
36225
|
+
const results = [];
|
|
36226
|
+
for (const idBN of tokenIds) {
|
|
36227
|
+
try {
|
|
36228
|
+
const receiptData = yield this.contract.WithdrawalQueue.info(idBN);
|
|
36229
|
+
results.push({
|
|
36230
|
+
tokenId: idBN.toBigInt(),
|
|
36231
|
+
receipt: {
|
|
36232
|
+
ethAmount: receiptData.ethAmount,
|
|
36233
|
+
ethBalance: {
|
|
36234
|
+
amount: receiptData.ethAmount.toBigInt(),
|
|
36235
|
+
decimals: 18,
|
|
36236
|
+
symbol: "ETH"
|
|
36237
|
+
},
|
|
36238
|
+
readyAt: new Date(Number(receiptData.readyAt.toString()) * 1e3).valueOf()
|
|
36239
|
+
}
|
|
36240
|
+
});
|
|
36241
|
+
} catch (err) {
|
|
36242
|
+
console.warn(`Failed to load receipt for tokenId=${idBN.toString()}`, err);
|
|
36243
|
+
continue;
|
|
36244
|
+
}
|
|
36245
|
+
}
|
|
36246
|
+
return results;
|
|
36247
|
+
});
|
|
36248
|
+
}
|
|
36249
|
+
getOwnedWithdrawReceiptsFor(owner, fromBlock = 0, toBlock = "latest") {
|
|
36250
|
+
return __async$1(this, null, function* () {
|
|
36251
|
+
var _a, _b;
|
|
36252
|
+
const contract = this.contract.WithdrawalQueue;
|
|
36253
|
+
const toLogs = yield contract.queryFilter(
|
|
36254
|
+
contract.filters.Transfer(null, owner),
|
|
36255
|
+
fromBlock,
|
|
36256
|
+
toBlock
|
|
36257
|
+
);
|
|
36258
|
+
const fromLogs = yield contract.queryFilter(
|
|
36259
|
+
contract.filters.Transfer(owner, null),
|
|
36260
|
+
fromBlock,
|
|
36261
|
+
toBlock
|
|
36262
|
+
);
|
|
36263
|
+
const owned = new Set();
|
|
36264
|
+
for (const e of toLogs) {
|
|
36265
|
+
const tokenId = (_a = e.args) == null ? void 0 : _a.tokenId;
|
|
36266
|
+
if (!tokenId) continue;
|
|
36267
|
+
owned.add(tokenId.toString());
|
|
36268
|
+
}
|
|
36269
|
+
for (const e of fromLogs) {
|
|
36270
|
+
const tokenId = (_b = e.args) == null ? void 0 : _b.tokenId;
|
|
36271
|
+
if (!tokenId) continue;
|
|
36272
|
+
owned.delete(tokenId.toString());
|
|
36273
|
+
}
|
|
36274
|
+
return Array.from(owned).map((id) => ethers.BigNumber.from(id));
|
|
36275
|
+
});
|
|
36276
|
+
}
|
|
36194
36277
|
}
|
|
36195
36278
|
|
|
36196
36279
|
var __async = (__this, __arguments, generator) => {
|
|
@@ -36261,6 +36344,21 @@ class EthereumStakingClient {
|
|
|
36261
36344
|
return result.txHash;
|
|
36262
36345
|
});
|
|
36263
36346
|
}
|
|
36347
|
+
loadPendingWithdraws() {
|
|
36348
|
+
return __async(this, null, function* () {
|
|
36349
|
+
this.ensureUser();
|
|
36350
|
+
const address = yield this.signer.getAddress();
|
|
36351
|
+
return yield this.receiptClient.fetchWithdrawReceipts(address);
|
|
36352
|
+
});
|
|
36353
|
+
}
|
|
36354
|
+
claimWithdraw(tokenId) {
|
|
36355
|
+
return __async(this, null, function* () {
|
|
36356
|
+
this.ensureUser();
|
|
36357
|
+
const tokenIdBigNum = ethers.BigNumber.from(tokenId);
|
|
36358
|
+
const result = yield this.convertClient.claimWithdraw(tokenIdBigNum);
|
|
36359
|
+
return result.txHash;
|
|
36360
|
+
});
|
|
36361
|
+
}
|
|
36264
36362
|
stake(amount) {
|
|
36265
36363
|
return __async(this, null, function* () {
|
|
36266
36364
|
this.ensureUser();
|
|
@@ -36330,6 +36428,12 @@ class EthereumStakingClient {
|
|
|
36330
36428
|
}
|
|
36331
36429
|
let estimatedClaim = BigInt(0);
|
|
36332
36430
|
let estimatedYield = BigInt(0);
|
|
36431
|
+
if (userShares > BigInt(0) && currentIndex > BigInt(0)) {
|
|
36432
|
+
estimatedClaim = userShares * currentIndex / indexScale;
|
|
36433
|
+
if (estimatedClaim > stakeBalanceBN.toBigInt()) {
|
|
36434
|
+
estimatedYield = estimatedClaim - stakeBalanceBN.toBigInt();
|
|
36435
|
+
}
|
|
36436
|
+
}
|
|
36333
36437
|
const portfolio = {
|
|
36334
36438
|
native: {
|
|
36335
36439
|
amount: nativeBalance.toBigInt(),
|