@wireio/stake 0.1.3 → 0.2.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 (135) hide show
  1. package/lib/stake.browser.js +15333 -4964
  2. package/lib/stake.browser.js.map +1 -1
  3. package/lib/stake.d.ts +4880 -112
  4. package/lib/stake.js +15636 -5116
  5. package/lib/stake.js.map +1 -1
  6. package/lib/stake.m.js +15333 -4964
  7. package/lib/stake.m.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/assets/ethereum/ABI/liqEth/DepositManager.sol/DepositManager.dbg.json +1 -1
  10. package/src/assets/ethereum/ABI/liqEth/DepositManager.sol/DepositManager.json +26 -65
  11. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IAccounting.dbg.json +1 -1
  12. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IAccounting.json +24 -20
  13. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IDepositContract.dbg.json +1 -1
  14. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IDepositManager.dbg.json +1 -1
  15. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IRewardsERC20.dbg.json +1 -1
  16. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IStakingModule.dbg.json +1 -1
  17. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IStakingModule.json +0 -20
  18. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IValidatorBalanceVerifier.dbg.json +1 -1
  19. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IWithdrawalRecord.dbg.json +1 -1
  20. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/LiqEthCommon.dbg.json +1 -1
  21. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/LiqEthCommon.json +2 -2
  22. package/src/assets/ethereum/ABI/liqEth/RewardsERC20.sol/RewardsERC20.dbg.json +1 -1
  23. package/src/assets/ethereum/ABI/liqEth/RewardsERC20Pausable.sol/RewardsERC20Pausable.dbg.json +1 -1
  24. package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/BeaconRoots.dbg.json +1 -1
  25. package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/SSZ.dbg.json +1 -1
  26. package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/ValidatorBalanceVerifier.dbg.json +1 -1
  27. package/src/assets/ethereum/ABI/liqEth/Yield.sol/BeaconRoots.dbg.json +1 -1
  28. package/src/assets/ethereum/ABI/liqEth/Yield.sol/BeaconRoots.json +2 -2
  29. package/src/assets/ethereum/ABI/liqEth/Yield.sol/SSZ.dbg.json +1 -1
  30. package/src/assets/ethereum/ABI/liqEth/Yield.sol/SSZ.json +2 -2
  31. package/src/assets/ethereum/ABI/liqEth/Yield.sol/YieldOracle.dbg.json +1 -1
  32. package/src/assets/ethereum/ABI/liqEth/Yield.sol/YieldOracle.json +2 -2
  33. package/src/assets/ethereum/ABI/liqEth/accounting.sol/Accounting.dbg.json +1 -1
  34. package/src/assets/ethereum/ABI/liqEth/accounting.sol/Accounting.json +31 -109
  35. package/src/assets/ethereum/ABI/liqEth/liqEth.sol/LiqEthToken.dbg.json +1 -1
  36. package/src/assets/ethereum/ABI/liqEth/liqEth.sol/LiqEthToken.json +2 -25
  37. package/src/assets/ethereum/ABI/liqEth/stakingModule.sol/StakingModule.dbg.json +1 -1
  38. package/src/assets/ethereum/ABI/liqEth/stakingModule.sol/StakingModule.json +30 -72
  39. package/src/assets/ethereum/ABI/liqEth/withdrawalQueue.sol/WithdrawalQueue.dbg.json +1 -1
  40. package/src/assets/ethereum/ABI/liqEth/withdrawalQueue.sol/WithdrawalQueue.json +2 -2
  41. package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/Uint64BE.dbg.json +1 -1
  42. package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/Uint64BE.json +2 -2
  43. package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/WithdrawalVault.dbg.json +1 -1
  44. package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/WithdrawalVault.json +2 -2
  45. package/src/assets/ethereum/ABI/outpost/BAR.sol/BAR.dbg.json +4 -0
  46. package/src/assets/ethereum/ABI/outpost/BAR.sol/BAR.json +1856 -0
  47. package/src/assets/ethereum/ABI/outpost/Depositor.sol/Depositor.dbg.json +4 -0
  48. package/src/assets/ethereum/ABI/outpost/Depositor.sol/Depositor.json +1753 -0
  49. package/src/assets/ethereum/ABI/outpost/EthUsdPriceConsumer.sol/AggregatorV3Interface.dbg.json +4 -0
  50. package/src/assets/ethereum/ABI/outpost/EthUsdPriceConsumer.sol/AggregatorV3Interface.json +122 -0
  51. package/src/assets/ethereum/ABI/outpost/EthUsdPriceConsumer.sol/EthUsdPriceConsumer.dbg.json +4 -0
  52. package/src/assets/ethereum/ABI/outpost/EthUsdPriceConsumer.sol/EthUsdPriceConsumer.json +601 -0
  53. package/src/assets/ethereum/ABI/outpost/OPP.sol/OPP.dbg.json +4 -0
  54. package/src/assets/ethereum/ABI/outpost/OPP.sol/OPP.json +930 -0
  55. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPP.dbg.json +4 -0
  56. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPP.json +88 -0
  57. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPEndpoint.dbg.json +4 -0
  58. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPEndpoint.json +29 -0
  59. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPInbound.dbg.json +4 -0
  60. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPInbound.json +194 -0
  61. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPReceiver.dbg.json +4 -0
  62. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPReceiver.json +29 -0
  63. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPSender.dbg.json +4 -0
  64. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/IOPPSender.json +36 -0
  65. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/OPPCommon.dbg.json +4 -0
  66. package/src/assets/ethereum/ABI/outpost/OPPCommon.sol/OPPCommon.json +199 -0
  67. package/src/assets/ethereum/ABI/outpost/OPPEndpoint.sol/OPPEndpoint.dbg.json +4 -0
  68. package/src/assets/ethereum/ABI/outpost/OPPEndpoint.sol/OPPEndpoint.json +273 -0
  69. package/src/assets/ethereum/ABI/outpost/OPPEndpointManaged.sol/OPPEndpointManaged.dbg.json +4 -0
  70. package/src/assets/ethereum/ABI/outpost/OPPEndpointManaged.sol/OPPEndpointManaged.json +394 -0
  71. package/src/assets/ethereum/ABI/outpost/OPPEndpointOwnable.sol/OPPEndpointOwnable.dbg.json +4 -0
  72. package/src/assets/ethereum/ABI/outpost/OPPEndpointOwnable.sol/OPPEndpointOwnable.json +378 -0
  73. package/src/assets/ethereum/ABI/outpost/OPPErrors.sol/OPPErrors.dbg.json +4 -0
  74. package/src/assets/ethereum/ABI/outpost/OPPErrors.sol/OPPErrors.json +224 -0
  75. package/src/assets/ethereum/ABI/outpost/OPPInbound.sol/OPPInbound.dbg.json +4 -0
  76. package/src/assets/ethereum/ABI/outpost/OPPInbound.sol/OPPInbound.json +1010 -0
  77. package/src/assets/ethereum/ABI/outpost/OPPReceiver.sol/OPPReceiver.dbg.json +4 -0
  78. package/src/assets/ethereum/ABI/outpost/OPPReceiver.sol/OPPReceiver.json +291 -0
  79. package/src/assets/ethereum/ABI/outpost/OPPSender.sol/OPPSender.dbg.json +4 -0
  80. package/src/assets/ethereum/ABI/outpost/OPPSender.sol/OPPSender.json +298 -0
  81. package/src/assets/ethereum/ABI/outpost/OutpostErrors.sol/OutpostErrors.dbg.json +4 -0
  82. package/src/assets/ethereum/ABI/outpost/OutpostErrors.sol/OutpostErrors.json +473 -0
  83. package/src/assets/ethereum/ABI/outpost/OutpostManaged.sol/OutpostManaged.dbg.json +4 -0
  84. package/src/assets/ethereum/ABI/outpost/OutpostManaged.sol/OutpostManaged.json +229 -0
  85. package/src/assets/ethereum/ABI/outpost/OutpostManager.sol/OutpostManager.dbg.json +4 -0
  86. package/src/assets/ethereum/ABI/outpost/OutpostManager.sol/OutpostManager.json +730 -0
  87. package/src/assets/ethereum/ABI/outpost/OutpostManagerAuthority.sol/OutpostManagerAuthority.dbg.json +4 -0
  88. package/src/assets/ethereum/ABI/outpost/OutpostManagerAuthority.sol/OutpostManagerAuthority.json +1432 -0
  89. package/src/assets/ethereum/ABI/outpost/OutpostManagerCommon.sol/IOutpostManager.dbg.json +4 -0
  90. package/src/assets/ethereum/ABI/outpost/OutpostManagerCommon.sol/IOutpostManager.json +130 -0
  91. package/src/assets/ethereum/ABI/outpost/OutpostManagerCommon.sol/IOutpostUpgradeable.dbg.json +4 -0
  92. package/src/assets/ethereum/ABI/outpost/OutpostManagerCommon.sol/IOutpostUpgradeable.json +29 -0
  93. package/src/assets/ethereum/ABI/outpost/OutpostManagerCommon.sol/OutpostManagerCommon.dbg.json +4 -0
  94. package/src/assets/ethereum/ABI/outpost/OutpostManagerCommon.sol/OutpostManagerCommon.json +141 -0
  95. package/src/assets/ethereum/ABI/outpost/OutpostOwnable.sol/OutpostOwnable.dbg.json +4 -0
  96. package/src/assets/ethereum/ABI/outpost/OutpostOwnable.sol/OutpostOwnable.json +213 -0
  97. package/src/assets/ethereum/ABI/outpost/Pool.sol/Pool.dbg.json +4 -0
  98. package/src/assets/ethereum/ABI/outpost/Pool.sol/Pool.json +921 -0
  99. package/src/assets/ethereum/ABI/outpost/ReceiptNFT.sol/ReceiptNFT.dbg.json +4 -0
  100. package/src/assets/ethereum/ABI/outpost/ReceiptNFT.sol/ReceiptNFT.json +2020 -0
  101. package/src/assets/ethereum/ABI/outpost/Warrant.sol/Warrant.dbg.json +4 -0
  102. package/src/assets/ethereum/ABI/outpost/Warrant.sol/Warrant.json +1650 -0
  103. package/src/assets/ethereum/ABI/outpost/interfaces/IWarrant.sol/IWarrant.dbg.json +4 -0
  104. package/src/assets/ethereum/ABI/{liqEth/LiqEthCommon.sol/ILiqEthMint.json → outpost/interfaces/IWarrant.sol/IWarrant.json} +6 -12
  105. package/src/assets/ethereum/ABI/outpost/token/ERC721EthEquivalentVotesUpgradeable.sol/ERC721EthEquivalentVotesUpgradeable.dbg.json +4 -0
  106. package/src/assets/ethereum/ABI/outpost/token/ERC721EthEquivalentVotesUpgradeable.sol/ERC721EthEquivalentVotesUpgradeable.json +858 -0
  107. package/src/assets/ethereum/ABI/outpost/token/IERC721EthEquivalent.sol/IERC721EthEquivalent.dbg.json +4 -0
  108. package/src/assets/ethereum/ABI/outpost/token/IERC721EthEquivalent.sol/IERC721EthEquivalent.json +30 -0
  109. package/src/assets/solana/idl/liqsol_core.json +1369 -1129
  110. package/src/assets/solana/idl/liqsol_token.json +1 -1
  111. package/src/assets/solana/idl/validator_leaderboard.json +1 -1
  112. package/src/assets/solana/types/liqsol_core.ts +1369 -1129
  113. package/src/assets/solana/types/liqsol_token.ts +1 -1
  114. package/src/assets/solana/types/validator_leaderboard.ts +1 -1
  115. package/src/index.ts +2 -1
  116. package/src/networks/ethereum/clients/deposit.client.ts +82 -0
  117. package/src/networks/ethereum/clients/stake.client.ts +215 -0
  118. package/src/networks/ethereum/contract.ts +82 -23
  119. package/src/networks/ethereum/ethereum.ts +148 -69
  120. package/src/networks/ethereum/types.ts +74 -7
  121. package/src/networks/solana/clients/deposit.client.ts +7 -11
  122. package/src/networks/solana/clients/distribution.client.ts +1 -3
  123. package/src/networks/solana/clients/outpost.client.ts +474 -0
  124. package/src/networks/solana/constants.ts +90 -52
  125. package/src/networks/solana/solana.ts +155 -128
  126. package/src/networks/solana/types.ts +95 -8
  127. package/src/networks/solana/utils.ts +111 -94
  128. package/src/staker/types.ts +7 -5
  129. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthBurn.dbg.json +0 -4
  130. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthBurn.json +0 -24
  131. package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthMint.dbg.json +0 -4
  132. package/src/assets/ethereum/ABI/liqEth/liqEthBurn.sol/LiqEthBurn.dbg.json +0 -4
  133. package/src/assets/ethereum/ABI/liqEth/liqEthBurn.sol/LiqEthBurn.json +0 -391
  134. package/src/assets/ethereum/ABI/liqEth/liqEthMint.sol/LiqEthMint.dbg.json +0 -4
  135. package/src/assets/ethereum/ABI/liqEth/liqEthMint.sol/LiqEthMint.json +0 -402
@@ -1,10 +1,12 @@
1
- // src/networks/ethereum/ethereum.ts
2
-
3
- import { BigNumber, BigNumberish, ethers } from 'ethers';
1
+ import { BigNumber, ethers } from 'ethers';
4
2
  import { IStakingClient, Portfolio, StakerConfig } from '../../staker/types';
5
3
  import { PublicKey as WirePubKey } from '@wireio/core';
6
- import { ERC20Abi, EthereumContractService } from './contract'; // TODO replace with staking contract ABI
7
- import { DepositEvent, DepositResult } from './types';
4
+ import { EthereumContractService } from './contract';
5
+ import { preLaunchReceipt, WithdrawRequestedEvent, WithdrawResult } from './types';
6
+ import { DepositClient } from './clients/deposit.client';
7
+ import { StakeClient } from './clients/stake.client';
8
+
9
+
8
10
 
9
11
  export class EthereumStakingClient implements IStakingClient {
10
12
  public readonly pubKey: WirePubKey;
@@ -12,6 +14,9 @@ export class EthereumStakingClient implements IStakingClient {
12
14
  private readonly signer: ethers.Signer;
13
15
  private readonly contractService: EthereumContractService;
14
16
 
17
+ private depositClient: DepositClient;
18
+ private stakeClient: StakeClient;
19
+
15
20
  get contract() { return this.contractService.contract; }
16
21
  get network() { return this.config.network; }
17
22
 
@@ -25,6 +30,8 @@ export class EthereumStakingClient implements IStakingClient {
25
30
  provider: this.provider,
26
31
  signer: this.signer,
27
32
  });
33
+ this.depositClient = new DepositClient(this.contractService);
34
+ this.stakeClient = new StakeClient(this.contractService);
28
35
  }
29
36
  catch (error) {
30
37
  // console.error('Error initializing EthereumStakingClient:', error);
@@ -33,7 +40,7 @@ export class EthereumStakingClient implements IStakingClient {
33
40
  }
34
41
 
35
42
  // ---------------------------------------------------------------------
36
- // Public IStakingClient.deposit
43
+ // Public IStakingClient Interface Methods
37
44
  // ---------------------------------------------------------------------
38
45
 
39
46
  /**
@@ -47,71 +54,67 @@ export class EthereumStakingClient implements IStakingClient {
47
54
  ? amount
48
55
  : BigNumber.from(amount);
49
56
 
50
- const result = await this.performDeposit(amountWei);
51
- // For now, IStakingClient contract is: just return tx hash.
52
- // If/when you extend the interface, you can surface more here.
57
+ const result = await this.depositClient.performDeposit(amountWei);
53
58
  return result.txHash;
54
59
  }
55
60
 
56
-
57
- /**
58
- * Simulate a deposit via callStatic.
59
- *
60
- * Useful for pre-flight checks; will throw with the same revert
61
- * reason as a real tx if it would fail.
62
- */
63
- async simulateDeposit(amount: number | string | bigint | BigNumber): Promise<void> {
61
+
62
+ // TODO - In progress
63
+ async withdraw(amount: number | string | bigint | BigNumber): Promise<string> {
64
64
  const amountWei = BigNumber.isBigNumber(amount)
65
65
  ? amount
66
66
  : BigNumber.from(amount);
67
67
 
68
- // callStatic executes the function locally without sending a tx.
69
- // deposit() doesn't return anything, so we only care if it reverts.
70
- await this.contract.DepositManager.callStatic.deposit({
71
- value: amountWei,
72
- });
68
+ const result = await this.requestWithdraw(amountWei);
69
+ return result.txHash;
73
70
  }
74
71
 
75
- private async performDeposit(amountWei: BigNumber): Promise<DepositResult> {
76
- // Pre-check minDeposit
77
- const minDeposit: BigNumber = await this.contract.DepositManager.minDeposit();
78
- if (amountWei.lt(minDeposit)) {
79
- throw new Error(
80
- `Deposit amount below minDeposit: ` +
81
- `amount=${ethers.utils.formatEther(amountWei)} ETH, ` +
82
- `min=${ethers.utils.formatEther(minDeposit)} ETH`
83
- );
84
- }
85
72
 
86
- // Send the payable tx
87
- const tx = await this.contract.DepositManager.deposit({
88
- value: amountWei,
89
- });
73
+ // TODO - In progress
74
+ async stake(amount: bigint): Promise<string> {
75
+ const walletAddress = await this.signer.getAddress();
76
+ const amountWei = BigNumber.from(amount);
90
77
 
91
- // Wait for 1 confirmation
92
- const receipt = await tx.wait(1);
78
+ const result = await this.stakeClient.performStake(amountWei, walletAddress);
79
+ return result.txHash;
80
+ }
93
81
 
94
- // Parse Deposited event if present
95
- let deposited: DepositEvent | undefined;
96
- const ev = receipt.events?.find((e) => e.event === 'Deposited');
97
82
 
98
- if (ev && ev.args) {
99
- const { user, netEth, fee, shares } = ev.args;
100
- deposited = {
101
- user,
102
- netEth: BigNumber.from(netEth),
103
- fee: BigNumber.from(fee),
104
- shares: BigNumber.from(shares),
105
- };
106
- }
83
+ // TODO
84
+ async unstake(): Promise<string> {
85
+ throw new Error("Method not yet implemented.");
86
+ }
87
+
88
+ // TODO
89
+ async unstakePrelaunch(tokenId: bigint, recipient: string): Promise<string> {
90
+ const tokenIdBigNum = BigNumber.from(tokenId)
91
+ const result = await this.stakeClient.performWithdrawStake(tokenIdBigNum, recipient);
92
+ return result.txHash;
93
+ }
94
+
95
+
96
+ async fetchPrelaunchReceipts(address?: string): Promise<preLaunchReceipt[]> {
97
+ if(address === undefined) address = await this.signer.getAddress();
98
+
99
+ let receipts = await this.stakeClient.fetchPreLaunchReceipts(address);
100
+ return receipts
101
+ }
102
+
103
+
104
+
105
+ async getEthStats(): Promise<any> {
106
+ let withdrawDelay = await this.contract.DepositManager.withdrawDelay();
107
+ let minDeposit = await this.contract.DepositManager.minDeposit();
108
+ let rewardCooldown = await this.contract.DepositManager.rewardCooldown();
107
109
 
108
110
  return {
109
- txHash: tx.hash,
110
- receipt,
111
- deposited,
112
- };
111
+ withdrawDelay,
112
+ minDeposit,
113
+ rewardCooldown,
114
+ }
113
115
  }
114
116
 
117
+
115
118
  /**
116
119
  * Resolve the user's ETH + liqETH balances.
117
120
  *
@@ -122,40 +125,40 @@ export class EthereumStakingClient implements IStakingClient {
122
125
  async getPortfolio(): Promise<Portfolio> {
123
126
  const walletAddress = await this.signer.getAddress();
124
127
  // console.log('getPortfolio() wallet address', walletAddress)
128
+
129
+
125
130
  // 1) Native ETH balance
126
131
  const nativeBalance = await this.provider.getBalance(walletAddress);
127
- // console.log('nativeBalance', nativeBalance);
128
132
  const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
129
133
  const nativeSymbol = this.network?.nativeCurrency?.symbol ?? 'ETH';
130
134
 
131
-
132
-
133
135
  // 2) liqETH ERC-20 balance (actual)
134
136
  const liqBalance: ethers.BigNumber = await this.contract.LiqEth.balanceOf(walletAddress);
135
- // console.log('liqBalance', liqBalance);
136
-
137
- const liqDecimals = this.network?.nativeCurrency?.decimals ?? 18;
138
137
  const liqSymbol = 'Liq' + (this.network?.nativeCurrency?.symbol ?? 'ETH');
139
138
 
139
+ // 3) staked liqEth ERC-20 balance (actual)
140
+ const stakedLiqBalance = await this.contract.Depositor.sharesOf(walletAddress);
141
+
142
+
140
143
  const portfolio: Portfolio = {
141
144
  native: {
142
- amount: nativeBalance,
145
+ amount: nativeBalance.toBigInt(),
143
146
  decimals: nativeDecimals,
144
147
  symbol: nativeSymbol,
145
148
  },
146
149
  liq: {
147
- amount: liqBalance,
148
- decimals: liqDecimals,
150
+ amount: liqBalance.toBigInt(),
151
+ decimals: nativeDecimals,
149
152
  symbol: liqSymbol,
150
153
  },
151
154
  tracked: {
152
- amount: liqBalance,
153
- decimals: liqDecimals,
155
+ amount: liqBalance.toBigInt(),
156
+ decimals: nativeDecimals,
154
157
  symbol: liqSymbol,
155
158
  },
156
- staked: { // TODO fetch staked balance from outpost
157
- amount: BigNumber.from(0),
158
- decimals: liqDecimals,
159
+ staked: {
160
+ amount: stakedLiqBalance.toBigInt(),
161
+ decimals: nativeDecimals,
159
162
  symbol: liqSymbol,
160
163
  },
161
164
  chainID: this.network.chainId
@@ -164,5 +167,81 @@ export class EthereumStakingClient implements IStakingClient {
164
167
  return portfolio;
165
168
  }
166
169
 
167
- // TODO: implement withdraw, claimRewards, etc.
170
+
171
+ // ---------------------------------------------------------------------
172
+ // Internal ETH Staking client helper functions
173
+ // ---------------------------------------------------------------------
174
+
175
+ private async requestWithdraw(amountWei: BigNumber): Promise<WithdrawResult> {
176
+ // deadline is a period of time in the future that the signature is valid for
177
+ const deadline = Math.floor(Date.now() / 1000) + 3600;
178
+ const liqEth = this.contract.LiqEth;
179
+ const owner = await this.signer.getAddress();
180
+ const liqEthAddress = this.contractService.getAddress('LiqEth');
181
+
182
+ const nonce: BigNumber = await liqEth.nonces(owner);
183
+ const chainId = this.network?.chainId ?? (await this.provider.getNetwork()).chainId;
184
+ const domain = {
185
+ name: await liqEth.name(),
186
+ version: '1',
187
+ chainId,
188
+ verifyingContract: liqEthAddress,
189
+ } as any;
190
+
191
+ const types = {
192
+ Permit: [
193
+ { name: 'owner', type: 'address' },
194
+ { name: 'spender', type: 'address' },
195
+ { name: 'value', type: 'uint256' },
196
+ { name: 'nonce', type: 'uint256' },
197
+ { name: 'deadline', type: 'uint256' },
198
+ ],
199
+ } as any;
200
+
201
+ const values = {
202
+ owner,
203
+ spender: this.contractService.getAddress('DepositManager'),
204
+ value: amountWei,
205
+ nonce: nonce,
206
+ deadline,
207
+ } as any;
208
+
209
+ const signature = await (this.signer as any)._signTypedData(domain, types, values);
210
+ const split = ethers.utils.splitSignature(signature);
211
+
212
+ const tx = await this.contract.DepositManager.requestWithdrawal(
213
+ amountWei,
214
+ deadline,
215
+ split.v,
216
+ split.r,
217
+ split.s
218
+ );
219
+
220
+ // wait for 1 confirmation
221
+ const receipt = await tx.wait(1);
222
+
223
+ // if WithdrawRequested event exists, parse it and get arguments
224
+ let withdrawRequested: WithdrawRequestedEvent | undefined;
225
+ const ev = receipt.events?.find((e) => e.event === 'WithdrawRequested');
226
+
227
+ if (ev && ev.args) {
228
+ const { user, ethAmount, nftId, readyAt } = ev.args;
229
+ withdrawRequested = {
230
+ user,
231
+ ethAmount: BigNumber.from(ethAmount),
232
+ nftId: BigNumber.from(nftId),
233
+ readyAt: readyAt,
234
+ };
235
+ }
236
+
237
+ return {
238
+ txHash: tx.hash,
239
+ receipt,
240
+ withdrawRequested,
241
+ } as WithdrawResult;
242
+ }
243
+
244
+
245
+
246
+ // TODO: implement claimRewards, etc.
168
247
  }
@@ -1,22 +1,43 @@
1
1
  import { BigNumber, ethers } from 'ethers';
2
+ import { BalanceView } from '../../staker/types';
2
3
 
3
4
  export const CONTRACT_NAMES = [
4
5
  'Accounting',
5
6
  'DepositManager',
6
7
  'LiqEth',
7
- 'LiqEthBurn',
8
- 'LiqEthMint',
8
+ // 'LiqEthBurn',
9
+ // 'LiqEthMint',
9
10
  // 'RewardsERC20',
10
11
  'StakingModule',
11
12
  // 'ValidatorBalance',
12
13
  'WithdrawalQueue',
13
14
  'WithdrawalVault',
14
15
  // 'Yield',
16
+
17
+ //Outpost contracts
18
+ 'Depositor',
19
+ 'ReceiptNFT',
20
+ 'OutpostManager',
21
+ 'BAR',
22
+ 'OPP',
23
+ 'OPPCommon',
24
+ 'OPPInbound',
25
+ 'Warrant',
26
+
15
27
  ] as const;
16
28
 
17
29
  export type ContractName = typeof CONTRACT_NAMES[number];
18
30
  export type AddressBook = Record<ContractName, string>;
19
31
 
32
+
33
+ interface Result {
34
+ /** EVM transaction hash */
35
+ txHash: string;
36
+ /** Full receipt, if you want it */
37
+ receipt: ethers.providers.TransactionReceipt;
38
+ }
39
+
40
+
20
41
  export interface DepositEvent {
21
42
  user: string;
22
43
  netEth: BigNumber;
@@ -24,11 +45,57 @@ export interface DepositEvent {
24
45
  shares: BigNumber;
25
46
  }
26
47
 
27
- export interface DepositResult {
28
- /** EVM transaction hash */
29
- txHash: string;
30
- /** Full receipt, if you want it */
31
- receipt: ethers.providers.TransactionReceipt;
48
+ export interface DepositResult extends Result {
32
49
  /** Parsed Deposited event, if present */
33
50
  deposited?: DepositEvent;
51
+ }
52
+
53
+ export interface WithdrawRequestedEvent {
54
+ user: string;
55
+ ethAmount: BigNumber;
56
+ nftId: BigNumber;
57
+ readyAt: string;
58
+ }
59
+
60
+ export interface WithdrawResult extends Result {
61
+ /** Parsed WithdrawRequested event, if present */
62
+ withdrawRequested?: WithdrawRequestedEvent;
63
+ }
64
+
65
+
66
+ export interface StakedEvent {
67
+ user: string;
68
+ amountLiq: BigNumber;
69
+ shares: BigNumber;
70
+ tokenId: BigNumber;
71
+ }
72
+
73
+ export interface StakedResult extends Result {
74
+ /** Parsed Staked event, if present */
75
+ staked?: StakedEvent;
76
+ }
77
+
78
+
79
+ export interface WithdrawnStakeEvent {
80
+ user: string;
81
+ tokenId: BigNumber;
82
+ tokenOut: BigNumber;
83
+ }
84
+ export interface WithdrawnStakeResult extends Result {
85
+ /** Parsed WithdrawnStake event, if present */
86
+ withdrawnstake?: WithdrawnStakeEvent;
87
+
88
+ }
89
+
90
+ export interface preLaunchReceipt {
91
+ tokenId: bigint;
92
+ receipt: {
93
+ account: string,
94
+ currency: number,
95
+ kind: number,
96
+ indexAtMint: BalanceView,
97
+ principal: BalanceView,
98
+ shares: BalanceView,
99
+ timestamp: string,
100
+ }
34
101
  }
@@ -34,22 +34,19 @@ import {
34
34
  derivePayoutStatePda,
35
35
  deriveEphemeralStakeAddress,
36
36
  } from '../constants';
37
+ import { WalletLike } from '../types';
37
38
 
38
39
  export class DepositClient {
39
40
  private program: Program<LiqsolCore>;
40
41
 
42
+ get wallet(): WalletLike { return this.provider.wallet; }
43
+
41
44
  constructor(private provider: AnchorProvider) {
42
45
  const svc = new SolanaProgramService(provider);
43
46
  this.program = svc.getProgram('liqsolCore');
44
47
  }
45
48
 
46
- async buildDepositTx(
47
- user: PublicKey,
48
- lamports: number
49
- ): Promise<{ transaction: Transaction; ephemeralStake: PublicKey }> {
50
-
51
- const program = this.program;
52
-
49
+ async buildDepositTx(amount: bigint, user = this.wallet.publicKey): Promise<Transaction> {
53
50
  // -------------------------------------------------------------
54
51
  // PDAs
55
52
  // -------------------------------------------------------------
@@ -91,8 +88,8 @@ export class DepositClient {
91
88
  // -------------------------------------------------------------
92
89
  // BUILD IX (MUST MATCH IDL)
93
90
  // -------------------------------------------------------------
94
- const ix: TransactionInstruction = await program.methods
95
- .deposit(new BN(lamports), seed)
91
+ const ix: TransactionInstruction = await this.program.methods
92
+ .deposit(new BN(amount.toString()), seed)
96
93
  .accounts({
97
94
  user,
98
95
  depositAuthority,
@@ -125,7 +122,6 @@ export class DepositClient {
125
122
  })
126
123
  .instruction();
127
124
 
128
- const tx = new Transaction().add(ix);
129
- return { transaction: tx, ephemeralStake };
125
+ return new Transaction().add(ix);
130
126
  }
131
127
  }
@@ -42,9 +42,7 @@ export class DistributionClient {
42
42
  this.program = svc.getProgram('liqsolCore');
43
43
  }
44
44
 
45
- get connection() {
46
- return this.provider.connection;
47
- }
45
+ get connection() { return this.provider.connection; }
48
46
 
49
47
  /**
50
48
  * Fetch the global distribution state account.