@wireio/stake 0.3.1 → 0.4.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.
Files changed (36) hide show
  1. package/lib/stake.browser.js +12887 -10017
  2. package/lib/stake.browser.js.map +1 -1
  3. package/lib/stake.d.ts +3305 -1364
  4. package/lib/stake.js +16298 -13436
  5. package/lib/stake.js.map +1 -1
  6. package/lib/stake.m.js +12887 -10017
  7. package/lib/stake.m.js.map +1 -1
  8. package/package.json +3 -1
  9. package/src/assets/solana/idl/liqsol_core.json +2327 -887
  10. package/src/assets/solana/idl/liqsol_token.json +1 -1
  11. package/src/assets/solana/idl/transfer_hook.json +192 -0
  12. package/src/assets/solana/idl/validator_leaderboard.json +147 -4
  13. package/src/assets/solana/types/liqsol_core.ts +2327 -887
  14. package/src/assets/solana/types/liqsol_token.ts +1 -1
  15. package/src/assets/solana/types/transfer_hook.ts +198 -0
  16. package/src/assets/solana/types/validator_leaderboard.ts +147 -4
  17. package/src/networks/ethereum/clients/{deposit.client.ts → convert.client.ts} +36 -4
  18. package/src/networks/ethereum/clients/opp.client.ts +390 -0
  19. package/src/networks/ethereum/clients/pretoken.client.ts +88 -49
  20. package/src/networks/ethereum/clients/receipt.client.ts +129 -0
  21. package/src/networks/ethereum/clients/stake.client.ts +1 -148
  22. package/src/networks/ethereum/contract.ts +7 -4
  23. package/src/networks/ethereum/ethereum.ts +44 -70
  24. package/src/networks/ethereum/types.ts +1 -0
  25. package/src/networks/ethereum/utils.ts +1 -1
  26. package/src/networks/solana/clients/deposit.client.ts +154 -8
  27. package/src/networks/solana/clients/distribution.client.ts +72 -291
  28. package/src/networks/solana/clients/leaderboard.client.ts +59 -14
  29. package/src/networks/solana/clients/outpost.client.ts +188 -359
  30. package/src/networks/solana/clients/token.client.ts +85 -100
  31. package/src/networks/solana/constants.ts +155 -64
  32. package/src/networks/solana/solana.ts +273 -154
  33. package/src/networks/solana/types.ts +532 -71
  34. package/src/networks/solana/utils.ts +68 -51
  35. package/src/types.ts +161 -17
  36. package/src/networks/ethereum/clients/liq.client.ts +0 -47
@@ -38,14 +38,12 @@ import {
38
38
  DEFAULT_PAY_RATE_LOOKBACK,
39
39
  deriveOutpostGlobalStatePda,
40
40
  deriveOutpostPoolAuthorityPda,
41
- deriveSolBucketPda,
41
+ deriveOutpostAccountPda,
42
42
  deriveTrancheStatePda,
43
- deriveWireReceiptPda,
44
- derivePoolUserRecordPda,
45
- deriveUserUserRecordPda,
46
- deriveUserWarrantRecordPda,
43
+ deriveUserPretokenRecordPda,
47
44
  CHAINLINK_FEED,
48
45
  CHAINLINK_PROGRAM,
46
+ deriveExtraAccountMetaListPda,
49
47
  } from './constants';
50
48
 
51
49
  import liqsolCoreIDL from '../../assets/solana/idl/liqsol_core.json';
@@ -54,12 +52,10 @@ import { GlobalState, TrancheState } from './types';
54
52
  import { TrancheLadderItem, TrancheSnapshot } from '../../types';
55
53
  import { ChainID } from '@wireio/core';
56
54
 
57
-
58
55
  // -----------------------------------------------------------------------------
59
56
  // Tranche Support
60
57
  // -----------------------------------------------------------------------------
61
58
 
62
-
63
59
  const INDEX_SCALE = BigInt(1_000_000_000_000); // 1e12
64
60
  const USD_SCALE = BigInt(100_000_000); // 1e8
65
61
  const BPS = BigInt(10_000);
@@ -116,7 +112,6 @@ export function buildSolanaTrancheLadder(options: {
116
112
  currentTranche: number;
117
113
  initialTrancheSupply: bigint;
118
114
  currentTrancheSupply: bigint;
119
- totalWarrantsSold: bigint; // informational only
120
115
  currentPriceUsd: bigint;
121
116
  supplyGrowthBps: number;
122
117
  priceGrowthBps: number;
@@ -209,35 +204,25 @@ export function buildSolanaTrancheSnapshot(options: {
209
204
 
210
205
  const currentIndex = toBigint(globalState.currentIndex);
211
206
  const totalShares = toBigint(globalState.totalShares);
212
-
213
207
  const currentTranche = trancheState.currentTrancheNumber.toNumber();
214
208
  const currentTrancheSupply = toBigint(trancheState.currentTrancheSupply);
215
209
  const initialTrancheSupply = toBigint(trancheState.initialTrancheSupply);
216
- const totalWarrantsSold = toBigint(trancheState.totalWarrantsSold);
210
+ const totalPretokensSold = toBigint(trancheState.totalPretokensSold);
217
211
  const currentPriceUsd = toBigint(trancheState.currentTranchePriceUsd);
218
-
219
212
  const supplyGrowthBps = trancheState.supplyGrowthBps;
220
213
  const priceGrowthBps = trancheState.priceGrowthBps;
221
214
 
222
- const minPriceUsd = trancheState.minPriceUsd
223
- ? toBigint(trancheState.minPriceUsd)
224
- : undefined;
225
- const maxPriceUsd = trancheState.maxPriceUsd
226
- ? toBigint(trancheState.maxPriceUsd)
227
- : undefined;
228
-
229
215
  const ladder = buildSolanaTrancheLadder({
230
216
  currentTranche,
231
217
  initialTrancheSupply,
232
218
  currentTrancheSupply,
233
- totalWarrantsSold,
234
219
  currentPriceUsd,
235
220
  supplyGrowthBps,
236
221
  priceGrowthBps,
237
222
  windowBefore: ladderWindowBefore,
238
223
  windowAfter: ladderWindowAfter,
239
224
  });
240
-
225
+
241
226
  return {
242
227
  chainID,
243
228
  currentIndex,
@@ -246,9 +231,9 @@ export function buildSolanaTrancheSnapshot(options: {
246
231
  currentPriceUsd,
247
232
  supplyGrowthBps,
248
233
  priceGrowthBps,
234
+ totalPretokensSold,
249
235
  currentTrancheSupply,
250
236
  initialTrancheSupply,
251
- totalWarrantsSold,
252
237
  nativePriceUsd: solPriceUsd,
253
238
  nativePriceTimestamp,
254
239
  ladder,
@@ -271,7 +256,11 @@ export function getLiqsolCoreProgram(
271
256
 
272
257
  // Dummy wallet – we're only doing read-only account fetches here.
273
258
  const tmpKeypair = Keypair.generate();
274
- const wallet: any = { publicKey: tmpKeypair.publicKey, signAllTransactions: async () => [], signTransaction: async () => tmpKeypair };
259
+ const wallet: any = {
260
+ publicKey: tmpKeypair.publicKey,
261
+ signAllTransactions: async () => [],
262
+ signTransaction: async () => tmpKeypair,
263
+ };
275
264
 
276
265
  const provider = new AnchorProvider(connection, wallet, {
277
266
  commitment: 'confirmed',
@@ -368,16 +357,27 @@ export async function getPayoutStateRaw(
368
357
 
369
358
  /**
370
359
  * Raw account info for a user's distribution user_record.
360
+ *
361
+ * NOTE: user_record is keyed by the TOKEN ACCOUNT (ATA), not the wallet.
362
+ * Here we derive the user's liqSOL ATA and then its user_record PDA.
371
363
  */
372
364
  export async function getUserRecordRaw(
373
365
  connection: Connection,
374
366
  user: PublicKey,
375
367
  ): Promise<Uint8Array | null> {
376
- const pda = deriveUserRecordPda(user);
368
+ const liqsolMint = deriveLiqsolMintPda();
369
+ const userAta = await getAssociatedTokenAddress(
370
+ liqsolMint,
371
+ user,
372
+ false,
373
+ TOKEN_2022_PROGRAM_ID,
374
+ );
375
+ const pda = deriveUserRecordPda(userAta);
377
376
  const info = await connection.getAccountInfo(pda);
378
377
  return info?.data ?? null;
379
378
  }
380
379
 
380
+
381
381
  // -----------------------------------------------------------------------------
382
382
  // Pay-rate & fee utilities (on-chain compatible)
383
383
  // -----------------------------------------------------------------------------
@@ -390,12 +390,12 @@ export async function getAveragePayRate(
390
390
  const payRateHistoryPda = derivePayRateHistoryPda();
391
391
 
392
392
  try {
393
- const anyProgram = program as any;
393
+ const anyProgram = program;
394
394
  const payRateHistoryAccount = await anyProgram.account.payRateHistory.fetch(
395
395
  payRateHistoryPda,
396
396
  );
397
397
 
398
- const entries: any[] = payRateHistoryAccount.entries ?? [];
398
+ const entries = payRateHistoryAccount.entries ?? [];
399
399
  const totalEntriesAdded = Number(
400
400
  payRateHistoryAccount.totalEntriesAdded ?? 0,
401
401
  );
@@ -448,6 +448,7 @@ export async function getAveragePayRate(
448
448
  return DEFAULT_AVERAGE_PAY_RATE;
449
449
  }
450
450
  }
451
+
451
452
  /**
452
453
  * On-chain fee formula:
453
454
  * fee = (average_pay_rate * 4 * deposit_amount_lamports) / 10^12
@@ -502,30 +503,39 @@ export function previewDepositEffects(params: {
502
503
  * ---------------------------------------------------------------------------
503
504
  * Outpost-specific helpers
504
505
  * ---------------------------------------------------------------------------
506
+ *
507
+ * This is the SDK equivalent of `deriveWirePdas` in capital-staking tests.
508
+ * It aggregates all PDAs / ATAs needed for Outpost pretokens + synd/desynd.
505
509
  */
506
510
  export interface OutpostAccounts {
507
511
  user: PublicKey;
508
512
 
509
- // Warrant / outpost
513
+ // Outpost / pretoken wiring
510
514
  globalState: PublicKey;
511
515
  poolAuthority: PublicKey;
512
516
  liqsolMint: PublicKey;
513
517
  liqsolPoolAta: PublicKey;
514
518
  userAta: PublicKey;
515
- wireReceipt: PublicKey;
516
- poolUserRecord: PublicKey;
517
- userUserRecord: PublicKey;
519
+ outpostAccount: PublicKey;
520
+ userPretokenRecord: PublicKey;
521
+
522
+ // Distribution / yield context (user_record keyed by token accounts)
518
523
  distributionState: PublicKey;
519
- payRateHistory: PublicKey;
520
524
  bucketAuthority: PublicKey;
521
525
  bucketTokenAccount: PublicKey;
522
- solBucket: PublicKey;
526
+ bucketUserRecord: PublicKey;
527
+ liqsolPoolUserRecord: PublicKey;
528
+ userUserRecord: PublicKey;
529
+
530
+ // Tranche / pricing
523
531
  trancheState: PublicKey;
524
- userWarrantRecord: PublicKey;
525
532
 
526
533
  // Chainlink
527
534
  chainLinkFeed: PublicKey;
528
535
  chainLinkProgram: PublicKey;
536
+
537
+ // Transfer hook extra accounts
538
+ extraAccountMetaList: PublicKey;
529
539
  }
530
540
 
531
541
  export async function buildOutpostAccounts(
@@ -536,15 +546,14 @@ export async function buildOutpostAccounts(
536
546
  const poolAuthority = deriveOutpostPoolAuthorityPda();
537
547
  const liqsolMint = deriveLiqsolMintPda();
538
548
  const distributionState = deriveDistributionStatePda();
539
- const payRateHistory = derivePayRateHistoryPda();
540
549
  const bucketAuthority = deriveBucketAuthorityPda();
541
- const solBucket = deriveSolBucketPda();
542
550
  const trancheState = deriveTrancheStatePda();
543
- const wireReceipt = deriveWireReceiptPda(user);
544
- const poolUserRecord = derivePoolUserRecordPda(poolAuthority);
545
- const userUserRecord = deriveUserUserRecordPda(user);
546
- const userWarrantRecord = deriveUserWarrantRecordPda(user);
547
551
 
552
+ // Outpost / pretoken PDAs
553
+ const outpostAccount = deriveOutpostAccountPda(user);
554
+ const userPretokenRecord = deriveUserPretokenRecordPda(user);
555
+
556
+ // ATAs
548
557
  const liqsolPoolAta = await getAssociatedTokenAddress(
549
558
  liqsolMint,
550
559
  poolAuthority,
@@ -566,21 +575,31 @@ export async function buildOutpostAccounts(
566
575
  TOKEN_2022_PROGRAM_ID,
567
576
  );
568
577
 
578
+ // user_record PDAs keyed by TOKEN ACCOUNTS (matches capital-staking)
579
+ const bucketUserRecord = deriveUserRecordPda(bucketTokenAccount);
580
+ const liqsolPoolUserRecord = deriveUserRecordPda(liqsolPoolAta);
581
+ const userUserRecord = deriveUserRecordPda(userAta);
582
+
583
+ const extraAccountMetaList = deriveExtraAccountMetaListPda(liqsolMint);
584
+
569
585
  // Chainlink program feeds
570
586
  let chainLinkFeed = CHAINLINK_FEED;
571
- let chainLinkProgram = CHAINLINK_PROGRAM
587
+ let chainLinkProgram = CHAINLINK_PROGRAM;
572
588
 
573
589
  try {
574
590
  const program = getLiqsolCoreProgram(connection);
575
- const ts: TrancheState = await program.account.trancheState.fetch(trancheState);
591
+ const ts: TrancheState =
592
+ await program.account.trancheState.fetch(trancheState);
593
+
594
+ // If on-chain config overrides are present, prefer those.
576
595
  if (ts.chainlinkFeed && ts.chainlinkProgram) {
577
596
  chainLinkFeed = ts.chainlinkFeed as PublicKey;
578
597
  chainLinkProgram = ts.chainlinkProgram as PublicKey;
579
598
  }
580
599
  } catch {
581
600
  // If trancheState isn't initialized yet, we fall back to the constants.
582
- // In that case, pretoken instructions will still fail, which is the correct
583
- // behavior until admin initializes TrancheState on-chain.
601
+ // In that case, purchase instructions will still fail, which is the
602
+ // correct behavior until admin initializes TrancheState on-chain.
584
603
  }
585
604
 
586
605
  void connection; // reserved for future extra validation
@@ -592,21 +611,20 @@ export async function buildOutpostAccounts(
592
611
  liqsolMint,
593
612
  liqsolPoolAta,
594
613
  userAta,
595
- wireReceipt,
596
- poolUserRecord,
597
- userUserRecord,
614
+ outpostAccount,
615
+ userPretokenRecord,
598
616
  distributionState,
599
- payRateHistory,
600
617
  bucketAuthority,
601
618
  bucketTokenAccount,
602
- solBucket,
619
+ bucketUserRecord,
620
+ liqsolPoolUserRecord,
621
+ userUserRecord,
603
622
  trancheState,
604
- userWarrantRecord,
605
623
  chainLinkFeed,
606
624
  chainLinkProgram,
625
+ extraAccountMetaList
607
626
  };
608
627
  }
609
-
610
628
  // -----------------------------------------------------------------------------
611
629
  // Epoch / scheduling helpers
612
630
  // -----------------------------------------------------------------------------
@@ -780,5 +798,4 @@ export async function waitUntilSafeToExecuteFunction(
780
798
  export interface ScheduleConfig {
781
799
  early?: number; // fraction of epoch, default 0.10
782
800
  late?: number; // fraction of epoch, default 0.90
783
- }
784
-
801
+ }
package/src/types.ts CHANGED
@@ -37,30 +37,120 @@ export interface IStakingClient {
37
37
  }): Promise<TrancheSnapshot | null>;
38
38
  }
39
39
 
40
+ /**
41
+ * Cross-chain portfolio view for a single account/wallet.
42
+ *
43
+ * On Solana (liqSOL + Outpost + pretokens) we fill:
44
+ * - native: SOL wallet lamports
45
+ * - liq: liqSOL in user ATA
46
+ * - staked: liqSOL staked into Outpost (stakedLiqsol)
47
+ * - wire: WIRE pretokens purchased (1e8 scale)
48
+ * - yield: Outpost yield view (index/shares + implied claim/yield)
49
+ *
50
+ * On other chains:
51
+ * - native/liq/wire/staked can still be populated as appropriate
52
+ * - yield may be undefined if no index/shares concept exists.
53
+ */
40
54
  export interface Portfolio {
41
- /** Native balance on chain: ETH, SOL */
55
+ /** Native balance on chain: ETH, SOL, etc. */
42
56
  native: BalanceView;
43
- /** Actual Liquid balance of LiqETH, LiqSOL*/
57
+
58
+ /** Liquid staking token balance (LiqETH, LiqSOL, etc.). */
44
59
  liq: BalanceView;
45
- /** Outpost Staked balance */
46
- staked: BalanceView
47
- /** Prelaunch WIRE “shares” (pretokens) */
60
+
61
+ /**
62
+ * Outpost-staked balance:
63
+ * - On Solana: liqSOL staked via `synd` (stakedLiqsol, in lamports).
64
+ * - On other chains: protocol-specific staked principal, if any.
65
+ */
66
+ staked: BalanceView;
67
+
68
+ /**
69
+ * Prelaunch WIRE “shares” (pretokens).
70
+ * - On Solana: totalPretokensPurchased (1e8 scale).
71
+ * - On other chains: analogous pretoken balance if supported.
72
+ */
48
73
  wire: BalanceView;
49
- /** SOL ONLY!
50
- * Tracked liqSOL balance from distribution program */
51
- tracked?: BalanceView;
52
- /** Extra PDAs and account addresses */
74
+
75
+ /**
76
+ * Yield / index-based view (SOL + Outpost only for now).
77
+ *
78
+ * If the connected chain doesn’t expose an index+shares model,
79
+ * this will be undefined.
80
+ */
81
+ yield?: YieldView;
82
+
83
+ /**
84
+ * Extra PDAs, account addresses, and raw state useful for debugging
85
+ * and advanced UI (e.g. tranche price, global index, PDAs).
86
+ */
53
87
  extras?: Record<string, any>;
54
- /** Chain ID of the network for which this portfolio is from */
88
+
89
+ /** Chain ID of the network from which this portfolio was fetched. */
55
90
  chainID: ChainID;
56
91
  }
57
92
 
58
- export type BalanceView = {
59
- amount: bigint; // raw on-chain integer value
60
- decimals: number; // number of decimal places
61
- symbol: string; // optional token symbol identifier
62
- ata?: SolPubKey; // associated token account address
63
- };
93
+ /**
94
+ * Canonical view of a single balance on a given chain.
95
+ *
96
+ * amount – integer base units (wei, lamports, token base units)
97
+ * symbol – display symbol (“SOL”, “LiqSOL”, “$WIRE”, etc.)
98
+ * decimals – how many decimal places to use when formatting
99
+ * ata – optional SPL ATA / ERC-20 address (where applicable)
100
+ */
101
+ export interface BalanceView {
102
+ amount: bigint;
103
+ symbol: string;
104
+ decimals: number;
105
+ ata?: SolPubKey;
106
+ }
107
+
108
+ /**
109
+ * SOL / Outpost yield view.
110
+ *
111
+ * All amounts are integers in base units (lamports for liqSOL).
112
+ *
113
+ * Math matches capital-staking:
114
+ * INDEX_SCALE = 1e12
115
+ * sharesToTokens = shares * currentIndex / INDEX_SCALE
116
+ */
117
+ export interface YieldView {
118
+ /**
119
+ * Current global index for the Outpost pool.
120
+ * - 1e12 scale (INDEX_SCALE)
121
+ * - sharesToTokens(shares) = shares * currentIndex / indexScale
122
+ */
123
+ currentIndex: bigint;
124
+
125
+ /**
126
+ * Fixed scale factor used for index math.
127
+ * - Always 1_000_000_000_000n (1e12) on Solana Outpost.
128
+ */
129
+ indexScale: bigint;
130
+
131
+ /** Total shares outstanding in the Outpost pool (all users). */
132
+ totalShares: bigint;
133
+
134
+ /** User’s staked shares in the Outpost pool. */
135
+ userShares: bigint;
136
+
137
+ /**
138
+ * Total liqSOL (lamports) the user could claim right now if they fully
139
+ * unwound their stake:
140
+ * estimatedClaimLiqsol = userShares * currentIndex / indexScale
141
+ */
142
+ estimatedClaimLiqsol: bigint;
143
+
144
+ /**
145
+ * Portion of estimatedClaimLiqsol that is “yield” above principal:
146
+ * estimatedYieldLiqsol = max(0, estimatedClaimLiqsol - stakedLiqsol)
147
+ *
148
+ * NOTE: stakedLiqsol principal itself is surfaced separately as
149
+ * Portfolio.staked.amount.
150
+ */
151
+ estimatedYieldLiqsol: bigint;
152
+ }
153
+
64
154
  export interface TrancheLadderItem {
65
155
  /** On-chain tranche id, 0-based (0,1,2,...) */
66
156
  id: number;
@@ -110,10 +200,11 @@ export interface TrancheSnapshot {
110
200
  supplyGrowthBps: number; // e.g. 100 = +1% per tranche
111
201
  priceGrowthBps: number; // e.g. 200 = +2% per tranche
112
202
 
203
+ totalPretokensSold: bigint; // total pretokens sold across all tranches (1e8 scale)
204
+
113
205
  /** Current tranche supply state (1e8 scale) */
114
206
  currentTrancheSupply: bigint; // remaining in current tranche
115
207
  initialTrancheSupply: bigint; // capacity for current tranche
116
- totalWarrantsSold: bigint; // global cumulative sold (all tranches), 1e8
117
208
 
118
209
  /** Native token → USD price if available (SOL/USD, ETH/USD, etc, 1e8 scale) */
119
210
  nativePriceUsd?: bigint;
@@ -125,4 +216,57 @@ export interface TrancheSnapshot {
125
216
  * Used directly by the frontend for ladder graphs.
126
217
  */
127
218
  ladder: TrancheLadderItem[];
219
+ }
220
+
221
+
222
+ // Enum describing which asset is being used to buy pretoken
223
+ export enum PurchaseAsset {
224
+ SOL = 'SOL',
225
+ LIQSOL = 'LIQSOL',
226
+ ETH = 'ETH',
227
+ LIQETH = 'LIQETH',
228
+ YIELD = 'YIELD',
229
+ }
230
+
231
+ export interface PurchaseQuote {
232
+ purchaseAsset: PurchaseAsset;
233
+ amountIn: bigint; // lamports / wei / token units
234
+
235
+ /** Expected pretoken “shares” (pretokens) and decimals */
236
+ wireShares: bigint; // 1e8 scale
237
+ wireDecimals: number; // always 8 for now
238
+
239
+ /** Current price + notional in USD (1e8 scale) */
240
+ wirePriceUsd: bigint;
241
+ notionalUsd: bigint;
242
+ }
243
+
244
+ // export interface OPPEvent {
245
+ // type: 'liq_pretoken_purchase' | 'yield_pretoken_purchase' | 'pretoken_purchase' | 'stake' | 'unstake' | 'unknown';
246
+ // amount: bigint | null;
247
+ // chain: 'ETH' | 'SOL';
248
+ // timestamp: number | null;
249
+ // from: string | null;
250
+ // to: string | null;
251
+ // txHash: string;
252
+ // raw: any;
253
+ // assertions: OPPAssertion[]
254
+ // }
255
+
256
+ export interface OPPAssertion {
257
+ type: 'liq_pretoken_purchase' | 'yield_pretoken_purchase' | 'pretoken_purchase' | 'stake' | 'unstake' | 'bonded_actor' | 'unbonded_actor' | 'unknown',
258
+ data: any
259
+ chain: 'ETH' | 'SOL';
260
+ timestamp: number | null;
261
+ from: string | null;
262
+ to: string | null;
263
+ txHash: string;
264
+ raw: any;
265
+ }
266
+
267
+
268
+
269
+ export enum ReceiptNFTKind {
270
+ STAKE = 0,
271
+ PRETOKEN_PURCHASE = 1,
128
272
  }
@@ -1,47 +0,0 @@
1
- import { BigNumber, ethers } from "ethers";
2
- import { preLaunchReceipt, SharesBurnedEvent, StakedEvent, WithdrawnStakeEvent, WithdrawnStakeResult } from "../types";
3
- import { EthereumContractService } from "../contract";
4
- import { formatContractErrors } from "../utils";
5
-
6
- export class LiqClient {
7
-
8
- private readonly contractService: EthereumContractService;
9
-
10
- get contract() { return this.contractService.contract; }
11
-
12
- constructor(contract: EthereumContractService) {
13
- this.contractService = contract;
14
- }
15
-
16
-
17
- public async safeBurn(signerAddress: string, amountWei: BigNumber): Promise<any> {
18
- let tx, receipt;
19
- try {
20
- tx = await this.contract.LiqEth.safeBurn(signerAddress, amountWei);
21
- receipt = await tx.wait(1);
22
- } catch (err: any) {
23
- let errorObj = formatContractErrors(err);
24
- throw new Error(errorObj.name ?? errorObj.raw)
25
- }
26
-
27
- // Parse SharesBurned event if present
28
- let event: SharesBurnedEvent | undefined;
29
- const ev = receipt.events?.find((e) => e.event === 'SharesBurned');
30
-
31
- if (ev && ev.args) {
32
- const { from, shares, tokenValue } = ev.args;
33
- event = {
34
- from,
35
- shares: BigNumber.from(shares),
36
- tokenValue: BigNumber.from(tokenValue),
37
- };
38
- }
39
-
40
- return {
41
- txHash: tx.hash,
42
- receipt,
43
- event,
44
- };
45
- }
46
-
47
- }