@wireio/stake 0.1.1 → 0.1.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 +6677 -116
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +21 -38
- package/lib/stake.js +6680 -121
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +6677 -116
- package/lib/stake.m.js.map +1 -1
- package/package.json +1 -1
- package/src/assets/ethereum/ABI/liqEth/DepositManager.sol/DepositManager.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/DepositManager.sol/DepositManager.json +1153 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IAccounting.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IAccounting.json +172 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IDepositContract.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IDepositContract.json +39 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IDepositManager.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IDepositManager.json +64 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthBurn.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthBurn.json +24 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthMint.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/ILiqEthMint.json +35 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IRewardsERC20.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IRewardsERC20.json +213 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IStakingModule.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IStakingModule.json +138 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IValidatorBalanceVerifier.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IValidatorBalanceVerifier.json +70 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IWithdrawalRecord.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/IWithdrawalRecord.json +64 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/LiqEthCommon.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/LiqEthCommon.sol/LiqEthCommon.json +10 -0
- package/src/assets/ethereum/ABI/liqEth/RewardsERC20.sol/RewardsERC20.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/RewardsERC20.sol/RewardsERC20.json +749 -0
- package/src/assets/ethereum/ABI/liqEth/RewardsERC20Pausable.sol/RewardsERC20Pausable.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/RewardsERC20Pausable.sol/RewardsERC20Pausable.json +812 -0
- package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/BeaconRoots.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/BeaconRoots.json +10 -0
- package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/SSZ.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/SSZ.json +10 -0
- package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/ValidatorBalanceVerifier.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/ValidatorBalanceVerifier.json +225 -0
- package/src/assets/ethereum/ABI/liqEth/Yield.sol/BeaconRoots.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/Yield.sol/BeaconRoots.json +10 -0
- package/src/assets/ethereum/ABI/liqEth/Yield.sol/SSZ.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/Yield.sol/SSZ.json +10 -0
- package/src/assets/ethereum/ABI/liqEth/Yield.sol/YieldOracle.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/Yield.sol/YieldOracle.json +813 -0
- package/src/assets/ethereum/ABI/liqEth/accounting.sol/Accounting.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/accounting.sol/Accounting.json +651 -0
- package/src/assets/ethereum/ABI/liqEth/liqEth.sol/LiqEthToken.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/liqEth.sol/LiqEthToken.json +1110 -0
- package/src/assets/ethereum/ABI/liqEth/liqEthBurn.sol/LiqEthBurn.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/liqEthBurn.sol/LiqEthBurn.json +391 -0
- package/src/assets/ethereum/ABI/liqEth/liqEthMint.sol/LiqEthMint.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/liqEthMint.sol/LiqEthMint.json +402 -0
- package/src/assets/ethereum/ABI/liqEth/stakingModule.sol/StakingModule.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/stakingModule.sol/StakingModule.json +1225 -0
- package/src/assets/ethereum/ABI/liqEth/withdrawalQueue.sol/WithdrawalQueue.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/withdrawalQueue.sol/WithdrawalQueue.json +927 -0
- package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/Uint64BE.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/Uint64BE.json +10 -0
- package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/WithdrawalVault.dbg.json +4 -0
- package/src/assets/ethereum/ABI/liqEth/withdrawalVault.sol/WithdrawalVault.json +447 -0
- package/src/networks/ethereum/contract.ts +53 -90
- package/src/networks/ethereum/ethereum.ts +31 -64
- package/src/networks/ethereum/types.ts +6 -9
- package/src/networks/solana/solana.ts +36 -32
- package/src/staker/staker.ts +5 -2
- package/src/staker/types.ts +12 -7
|
@@ -3,24 +3,23 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides a unified service for interacting with Ethereum smart contracts using ethers.js.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// import
|
|
11
|
-
|
|
12
|
-
// import
|
|
13
|
-
|
|
14
|
-
// import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// import
|
|
18
|
-
// import WithdrawalQueueArtifact from '../../assets/ethereum/ABI/liqeth/withdrawalQueue.sol/withdrawalQueue.json';
|
|
19
|
-
// import WithdrawalVaultArtifact from '../../assets/ethereum/ABI/liqeth/withdrawalVault.sol/withdrawalVault.json';
|
|
6
|
+
import AccountingArtifact from '../../assets/ethereum/ABI/liqEth/accounting.sol/Accounting.json';
|
|
7
|
+
import DepositManagerArtifact from '../../assets/ethereum/ABI/liqEth/DepositManager.sol/DepositManager.json';
|
|
8
|
+
import LiqEthArtifact from '../../assets/ethereum/ABI/liqEth/liqEth.sol/LiqEthToken.json';
|
|
9
|
+
import LiqEthBurnArtifact from '../../assets/ethereum/ABI/liqEth/liqEthBurn.sol/LiqEthBurn.json';
|
|
10
|
+
// import LiqEthCommonArtifact from '../../assets/ethereum/ABI/liqEth/liqEthCommon.sol/liqEthCommon.json';
|
|
11
|
+
import LiqEthMintArtifact from '../../assets/ethereum/ABI/liqEth/liqEthMint.sol/LiqEthMint.json';
|
|
12
|
+
// import RewardsERC20Artifact from '../../assets/ethereum/ABI/liqEth/RewardsERC20.sol/RewardsERC20.json';
|
|
13
|
+
import StakingModuleArtifact from '../../assets/ethereum/ABI/liqEth/stakingModule.sol/StakingModule.json';
|
|
14
|
+
// import ValidatorBalanceArtifact from '../../assets/ethereum/ABI/liqEth/ValidatorBalanceVerifier.sol/ValidatorBalanceVerifier.json';
|
|
15
|
+
import WithdrawalQueueArtifact from '../../assets/ethereum/ABI/liqEth/withdrawalQueue.sol/WithdrawalQueue.json';
|
|
16
|
+
import WithdrawalVaultArtifact from '../../assets/ethereum/ABI/liqEth/withdrawalVault.sol/WithdrawalVault.json';
|
|
17
|
+
// import YieldArtifact from '../../assets/ethereum/ABI/liqEth/Yield.sol/YieldOracle.json';
|
|
20
18
|
|
|
21
19
|
import ERC20Artifact from '../../assets/ethereum/ABI/token/ERC20Token.sol/ERC20Token.json';
|
|
22
20
|
import ERC721Artifact from '../../assets/ethereum/ABI/token/ERC721Token.sol/ERC721Token.json';
|
|
23
21
|
import ERC1155Artifact from '../../assets/ethereum/ABI/token/ERC1155Token.sol/ERC1155Token.json';
|
|
22
|
+
|
|
24
23
|
import { AddressBook, ContractName } from './types';
|
|
25
24
|
import { Contract, ethers, providers, Signer } from 'ethers';
|
|
26
25
|
import { JsonFragment } from '@ethersproject/abi';
|
|
@@ -36,23 +35,14 @@ export const ERC1155Abi = ERC1155Artifact.abi;
|
|
|
36
35
|
|
|
37
36
|
// Make sure ContractName in ./types includes all of these keys.
|
|
38
37
|
export const ADDRESSES: AddressBook = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
LiqEthTreasury: '0xLiqEthTreasuryAddress',
|
|
48
|
-
LiqEthCommon: '0xLiqEthCommonAddress',
|
|
49
|
-
RewardsERC20: '0xRewardsErc20Address',
|
|
50
|
-
ValidatorBalanceVerifier: '0xValidatorBalanceVerifierAddress',
|
|
51
|
-
Yield: '0xYieldAddress',
|
|
52
|
-
Accounting: '0xAccountingAddress',
|
|
53
|
-
StakingModule: '0xStakingModuleAddress',
|
|
54
|
-
WithdrawalQueue: '0xWithdrawalQueueAddress',
|
|
55
|
-
WithdrawalVault: '0xWithdrawalVaultAddress',
|
|
38
|
+
Accounting: "0xd51CC479c25dc7Cd23f568Ef5c1AdE1671a4D15b",
|
|
39
|
+
DepositManager: "0x2249D309f086363ABF5057Ae7f8057279162786B",
|
|
40
|
+
LiqEth: "0xd5bd3DC2fD86e917A46f7571708aBB88CbfCc197",
|
|
41
|
+
LiqEthMint: "0xdBAa1539eB7b80C29d825FCda76c0d7F8F0E6cFB",
|
|
42
|
+
LiqEthBurn: "0x02e0A02fE2311FAd661677B7117FDdc801c1216b",
|
|
43
|
+
StakingModule: "0x87047291c3b0D55A551C97B9194A02E1D84e06A9",
|
|
44
|
+
WithdrawalQueue: "0x7781368720294fE0bB6D97F14fE2E9275fFED071",
|
|
45
|
+
WithdrawalVault: "0x24457626938d4132556005ecA4d9e6F24F85297E",
|
|
56
46
|
};
|
|
57
47
|
|
|
58
48
|
export type Contracts<T extends string = ContractName> = Record<T, ContractConfig>;
|
|
@@ -67,75 +57,50 @@ export type ContractConfig = {
|
|
|
67
57
|
// -----------------------------------------------------------------------------
|
|
68
58
|
|
|
69
59
|
export const CONTRACTS: Contracts<ContractName> = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
Accounting: {
|
|
61
|
+
address: ADDRESSES.Accounting,
|
|
62
|
+
abi: AccountingArtifact.abi as JsonFragment[],
|
|
63
|
+
},
|
|
74
64
|
LiqEth: {
|
|
75
65
|
address: ADDRESSES.LiqEth,
|
|
76
|
-
abi:
|
|
77
|
-
// abi: LiqEthArtifact.abi as JsonFragment[],
|
|
66
|
+
abi: LiqEthArtifact.abi as JsonFragment[],
|
|
78
67
|
},
|
|
79
68
|
DepositManager: {
|
|
80
69
|
address: ADDRESSES.DepositManager,
|
|
81
|
-
abi:
|
|
82
|
-
// abi: DepositManagerArtifact.abi as JsonFragment[],
|
|
70
|
+
abi: DepositManagerArtifact.abi as JsonFragment[],
|
|
83
71
|
},
|
|
84
72
|
LiqEthMint: {
|
|
85
73
|
address: ADDRESSES.LiqEthMint,
|
|
86
|
-
abi:
|
|
87
|
-
// abi: LiqEthMintArtifact.abi as JsonFragment[],
|
|
74
|
+
abi: LiqEthMintArtifact.abi as JsonFragment[],
|
|
88
75
|
},
|
|
89
76
|
LiqEthBurn: {
|
|
90
77
|
address: ADDRESSES.LiqEthBurn,
|
|
91
|
-
abi:
|
|
92
|
-
// abi: LiqEthBurnArtifact.abi as JsonFragment[],
|
|
93
|
-
},
|
|
94
|
-
LiqEthTreasury: {
|
|
95
|
-
address: ADDRESSES.LiqEthTreasury,
|
|
96
|
-
abi: undefined as any,
|
|
97
|
-
// abi: LiqEthTreasuryArtifact.abi as JsonFragment[],
|
|
98
|
-
},
|
|
99
|
-
LiqEthCommon: {
|
|
100
|
-
address: ADDRESSES.LiqEthCommon,
|
|
101
|
-
abi: undefined as any,
|
|
102
|
-
// abi: LiqEthCommonArtifact.abi as JsonFragment[],
|
|
103
|
-
},
|
|
104
|
-
RewardsERC20: {
|
|
105
|
-
address: ADDRESSES.RewardsERC20,
|
|
106
|
-
abi: undefined as any,
|
|
107
|
-
// abi: RewardsERC20Artifact.abi as JsonFragment[],
|
|
108
|
-
},
|
|
109
|
-
ValidatorBalanceVerifier: {
|
|
110
|
-
address: ADDRESSES.ValidatorBalanceVerifier,
|
|
111
|
-
abi: undefined as any,
|
|
112
|
-
// abi: ValidatorBalanceVerifierArtifact.abi as JsonFragment[],
|
|
113
|
-
},
|
|
114
|
-
Yield: {
|
|
115
|
-
address: ADDRESSES.Yield,
|
|
116
|
-
abi: undefined as any,
|
|
117
|
-
// abi: YieldArtifact.abi as JsonFragment[],
|
|
118
|
-
},
|
|
119
|
-
Accounting: {
|
|
120
|
-
address: ADDRESSES.Accounting,
|
|
121
|
-
abi: undefined as any,
|
|
122
|
-
// abi: AccountingArtifact.abi as JsonFragment[],
|
|
78
|
+
abi: LiqEthBurnArtifact.abi as JsonFragment[],
|
|
123
79
|
},
|
|
80
|
+
// RewardsERC20: {
|
|
81
|
+
// address: ADDRESSES.RewardsERC20,
|
|
82
|
+
// abi: RewardsERC20Artifact.abi as JsonFragment[],
|
|
83
|
+
// },
|
|
124
84
|
StakingModule: {
|
|
125
85
|
address: ADDRESSES.StakingModule,
|
|
126
|
-
abi:
|
|
127
|
-
// abi: StakingModuleArtifact.abi as JsonFragment[],
|
|
86
|
+
abi: StakingModuleArtifact.abi as JsonFragment[],
|
|
128
87
|
},
|
|
88
|
+
// ValidatorBalance: {
|
|
89
|
+
// address: ADDRESSES.ValidatorBalance,
|
|
90
|
+
// abi: ValidatorBalanceArtifact.abi as JsonFragment[],
|
|
91
|
+
// },
|
|
129
92
|
WithdrawalQueue: {
|
|
130
93
|
address: ADDRESSES.WithdrawalQueue,
|
|
131
|
-
abi:
|
|
132
|
-
// abi: WithdrawalQueueArtifact.abi as JsonFragment[],
|
|
94
|
+
abi: WithdrawalQueueArtifact.abi as JsonFragment[],
|
|
133
95
|
},
|
|
134
96
|
WithdrawalVault: {
|
|
135
97
|
address: ADDRESSES.WithdrawalVault,
|
|
136
|
-
abi:
|
|
137
|
-
// abi: WithdrawalVaultArtifact.abi as JsonFragment[],
|
|
98
|
+
abi: WithdrawalVaultArtifact.abi as JsonFragment[],
|
|
138
99
|
},
|
|
100
|
+
// Yield: {
|
|
101
|
+
// address: ADDRESSES.Yield,
|
|
102
|
+
// abi: YieldArtifact.abi as JsonFragment[],
|
|
103
|
+
// },
|
|
139
104
|
};
|
|
140
105
|
|
|
141
106
|
export interface ContractOptions {
|
|
@@ -219,19 +184,17 @@ export class EthereumContractService {
|
|
|
219
184
|
ERC1155Artifact,
|
|
220
185
|
|
|
221
186
|
// liqETH suite
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
// LiqEthCommonArtifact,
|
|
187
|
+
AccountingArtifact,
|
|
188
|
+
DepositManagerArtifact,
|
|
189
|
+
LiqEthArtifact,
|
|
190
|
+
LiqEthBurnArtifact,
|
|
191
|
+
LiqEthMintArtifact,
|
|
228
192
|
// RewardsERC20Artifact,
|
|
229
|
-
|
|
193
|
+
StakingModuleArtifact,
|
|
194
|
+
// ValidatorBalanceArtifact,
|
|
195
|
+
WithdrawalQueueArtifact,
|
|
196
|
+
WithdrawalVaultArtifact,
|
|
230
197
|
// YieldArtifact,
|
|
231
|
-
// AccountingArtifact,
|
|
232
|
-
// StakingModuleArtifact,
|
|
233
|
-
// WithdrawalQueueArtifact,
|
|
234
|
-
// WithdrawalVaultArtifact,
|
|
235
198
|
];
|
|
236
199
|
|
|
237
200
|
allArtifacts.forEach(artifact => {
|
|
@@ -17,17 +17,20 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
17
17
|
get network() { return this.config.network; }
|
|
18
18
|
|
|
19
19
|
constructor(private config: StakerConfig) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
try {
|
|
21
|
+
this.provider = config.provider as ethers.providers.Web3Provider;
|
|
22
|
+
this.signer = this.provider.getSigner();
|
|
23
|
+
this.pubKey = config.pubKey as WirePubKey;
|
|
24
|
+
|
|
25
|
+
this.contractService = new EthereumContractService({
|
|
26
|
+
provider: this.provider,
|
|
27
|
+
signer: this.signer,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
// console.error('Error initializing EthereumStakingClient:', error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
// ---------------------------------------------------------------------
|
|
@@ -108,23 +111,6 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
/**
|
|
112
|
-
* Build, sign, and submit a single transaction that:
|
|
113
|
-
* - Corrects other users (if needed) to free available balance, then
|
|
114
|
-
* - Registers the caller’s untracked liqSOL.
|
|
115
|
-
*
|
|
116
|
-
* @param amount Optional: register a smaller amount than your full untracked balance.
|
|
117
|
-
* @returns signature string
|
|
118
|
-
*/
|
|
119
|
-
async register(amount?: bigint): Promise<string> {
|
|
120
|
-
try {
|
|
121
|
-
return 'Not implemented yet for Ethereum';
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error('Error in register:', error);
|
|
124
|
-
throw error;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
114
|
/**
|
|
129
115
|
* Resolve the user's ETH + liqETH balances.
|
|
130
116
|
*
|
|
@@ -137,56 +123,37 @@ export class EthereumStakingClient implements IStakingClient {
|
|
|
137
123
|
|
|
138
124
|
// 1) Native ETH balance
|
|
139
125
|
const nativeBalance = await this.provider.getBalance(walletAddress);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const nativeSymbol =
|
|
143
|
-
this.network?.nativeCurrency?.symbol ?? 'ETH';
|
|
126
|
+
// console.log('nativeBalance', nativeBalance);
|
|
127
|
+
const nativeDecimals = this.network?.nativeCurrency?.decimals ?? 18;
|
|
128
|
+
const nativeSymbol = this.network?.nativeCurrency?.symbol ?? 'ETH';
|
|
144
129
|
|
|
145
130
|
// 2) liqETH ERC-20 balance (actual)
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
let trackedBalance: ethers.BigNumber = actualBalance;
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
// Adjust this to your real view method:
|
|
155
|
-
// e.g. function getUserBalance(address user)
|
|
156
|
-
const result = await this.contract.Accounting.getUserBalance(walletAddress);
|
|
157
|
-
|
|
158
|
-
// Support either struct or plain uint256
|
|
159
|
-
if (result && typeof result === 'object' && 'amount' in result) {
|
|
160
|
-
trackedBalance = result.amount;
|
|
161
|
-
// if result.decimals exists and differs, override liqDecimals if desired
|
|
162
|
-
} else if (result != null) {
|
|
163
|
-
trackedBalance = result;
|
|
164
|
-
}
|
|
165
|
-
} catch (err) {
|
|
166
|
-
console.warn(
|
|
167
|
-
'[EthereumStakingClient] getPortfolio: Accounting view unavailable, using actual balance as tracked.',
|
|
168
|
-
err
|
|
169
|
-
);
|
|
170
|
-
trackedBalance = actualBalance;
|
|
171
|
-
}
|
|
131
|
+
const liqBalance: ethers.BigNumber = await this.contract.LiqEth.balanceOf(walletAddress);
|
|
132
|
+
// console.log('liqBalance', liqBalance);
|
|
133
|
+
|
|
134
|
+
const liqDecimals = this.network?.nativeCurrency?.decimals ?? 18;
|
|
135
|
+
const liqSymbol = 'Liq' + (this.network?.nativeCurrency?.symbol ?? 'ETH');
|
|
172
136
|
|
|
173
|
-
|
|
137
|
+
const portfolio: Portfolio = {
|
|
174
138
|
native: {
|
|
175
139
|
amount: nativeBalance,
|
|
176
140
|
decimals: nativeDecimals,
|
|
177
141
|
symbol: nativeSymbol,
|
|
178
142
|
},
|
|
179
|
-
|
|
180
|
-
amount:
|
|
143
|
+
liq: {
|
|
144
|
+
amount: liqBalance,
|
|
181
145
|
decimals: liqDecimals,
|
|
182
146
|
symbol: liqSymbol,
|
|
183
147
|
},
|
|
184
|
-
|
|
185
|
-
amount:
|
|
148
|
+
staked: { // TODO fetch staked balance from outpost
|
|
149
|
+
amount: BigNumber.from(0),
|
|
186
150
|
decimals: liqDecimals,
|
|
187
151
|
symbol: liqSymbol,
|
|
188
152
|
},
|
|
189
|
-
|
|
153
|
+
chainID: this.network.chainId
|
|
154
|
+
}
|
|
155
|
+
// console.log('ETH PORTFOLIO', portfolio);
|
|
156
|
+
return portfolio;
|
|
190
157
|
}
|
|
191
158
|
|
|
192
159
|
// TODO: implement withdraw, claimRewards, etc.
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { BigNumber, ethers } from 'ethers';
|
|
2
2
|
|
|
3
3
|
export const CONTRACT_NAMES = [
|
|
4
|
-
'
|
|
5
|
-
'LiqEth',
|
|
4
|
+
'Accounting',
|
|
6
5
|
'DepositManager',
|
|
7
|
-
'
|
|
6
|
+
'LiqEth',
|
|
8
7
|
'LiqEthBurn',
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'RewardsERC20',
|
|
12
|
-
'ValidatorBalanceVerifier',
|
|
13
|
-
'Yield',
|
|
14
|
-
'Accounting',
|
|
8
|
+
'LiqEthMint',
|
|
9
|
+
// 'RewardsERC20',
|
|
15
10
|
'StakingModule',
|
|
11
|
+
// 'ValidatorBalance',
|
|
16
12
|
'WithdrawalQueue',
|
|
17
13
|
'WithdrawalVault',
|
|
14
|
+
// 'Yield',
|
|
18
15
|
] as const;
|
|
19
16
|
|
|
20
17
|
export type ContractName = typeof CONTRACT_NAMES[number];
|
|
@@ -34,13 +34,8 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
34
34
|
private distributionClient: DistributionClient;
|
|
35
35
|
private leaderboardClient: LeaderboardClient;
|
|
36
36
|
|
|
37
|
-
get solPubKey(): SolPubKey {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get network() {
|
|
42
|
-
return this.config.network;
|
|
43
|
-
}
|
|
37
|
+
get solPubKey(): SolPubKey { return new SolPubKey(this.pubKey.data.array); }
|
|
38
|
+
get network() { return this.config.network; }
|
|
44
39
|
|
|
45
40
|
constructor(private config: StakerConfig) {
|
|
46
41
|
const adapter = config.provider as BaseSignerWalletAdapter;
|
|
@@ -101,6 +96,7 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
101
96
|
TOKEN_2022_PROGRAM_ID,
|
|
102
97
|
);
|
|
103
98
|
|
|
99
|
+
// Fetch balances and user record in parallel
|
|
104
100
|
const [nativeLamports, actualBalResp, userRecord] = await Promise.all([
|
|
105
101
|
this.connection.getBalance(user),
|
|
106
102
|
this.connection.getTokenAccountBalance(userLiqsolAta).catch(() => null),
|
|
@@ -110,34 +106,42 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
110
106
|
const actualAmountStr = actualBalResp?.value?.amount ?? '0';
|
|
111
107
|
const actualDecimals = actualBalResp?.value?.decimals ?? 9;
|
|
112
108
|
|
|
113
|
-
const trackedAmountStr = userRecord?.trackedBalance
|
|
114
|
-
? userRecord.trackedBalance.toString()
|
|
115
|
-
: '0';
|
|
109
|
+
const trackedAmountStr = userRecord?.trackedBalance ? userRecord.trackedBalance.toString() : '0';
|
|
116
110
|
const trackedDecimals = actualDecimals;
|
|
117
111
|
|
|
112
|
+
const nativeSymbol = 'SOL';
|
|
113
|
+
const liqSymbol = 'LiqSOL';
|
|
114
|
+
|
|
118
115
|
const portfolio: Portfolio = {
|
|
119
116
|
native: {
|
|
120
|
-
symbol: 'SOL',
|
|
121
|
-
decimals: 9,
|
|
122
117
|
amount: BigInt(nativeLamports),
|
|
118
|
+
symbol: nativeSymbol,
|
|
119
|
+
decimals: 9,
|
|
123
120
|
},
|
|
124
|
-
|
|
125
|
-
symbol: 'LiqSOL',
|
|
126
|
-
decimals: actualDecimals,
|
|
121
|
+
liq: {
|
|
127
122
|
amount: BigInt(actualAmountStr),
|
|
123
|
+
symbol: liqSymbol,
|
|
124
|
+
decimals: actualDecimals,
|
|
128
125
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
staked: { // TODO: fetch staked balance from outpost
|
|
127
|
+
amount: BigInt(0),
|
|
128
|
+
symbol: liqSymbol,
|
|
129
|
+
decimals: actualDecimals,
|
|
130
|
+
},
|
|
131
|
+
tracked: { // SOL ONLY
|
|
132
132
|
amount: BigInt(trackedAmountStr),
|
|
133
|
+
symbol: liqSymbol,
|
|
134
|
+
decimals: trackedDecimals,
|
|
133
135
|
},
|
|
134
136
|
extras: {
|
|
135
137
|
userLiqsolAta: userLiqsolAta.toBase58(),
|
|
136
138
|
reservePoolPDA: reservePoolPDA.toBase58(),
|
|
137
139
|
vaultPDA: vaultPDA.toBase58(),
|
|
138
140
|
},
|
|
141
|
+
chainID: this.network.chainId
|
|
139
142
|
};
|
|
140
143
|
|
|
144
|
+
// console.log('SOL PORTFOLIO', portfolio);
|
|
141
145
|
return portfolio;
|
|
142
146
|
}
|
|
143
147
|
catch (error) {
|
|
@@ -159,6 +163,19 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
159
163
|
// TODO: wire to pay-rate math once we finalize protocol fee API
|
|
160
164
|
}
|
|
161
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Deposit funds into the staking pool.
|
|
168
|
+
* @param lamports The amount to deposit (in lamports).
|
|
169
|
+
* @returns The transaction signature.
|
|
170
|
+
*/
|
|
171
|
+
async deposit(lamports: number): Promise<string> {
|
|
172
|
+
const { transaction } = await this.depositClient.buildDepositTx(this.solPubKey, lamports);
|
|
173
|
+
const { tx, blockhash, lastValidBlockHeight } = await this.prepareTx(transaction);
|
|
174
|
+
const signed = await this.signTransaction(tx);
|
|
175
|
+
const result = await this.sendAndConfirmHttp(signed, { blockhash, lastValidBlockHeight });
|
|
176
|
+
return result.signature;
|
|
177
|
+
}
|
|
178
|
+
|
|
162
179
|
/**
|
|
163
180
|
* Build, sign, and submit a single transaction that:
|
|
164
181
|
* - Corrects other users (if needed) to free available balance, then
|
|
@@ -167,7 +184,7 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
167
184
|
* @param amount Optional: register a smaller amount than your full untracked balance.
|
|
168
185
|
* @returns signature string
|
|
169
186
|
*/
|
|
170
|
-
async
|
|
187
|
+
async correctBalance(amount?: bigint): Promise<string> {
|
|
171
188
|
try {
|
|
172
189
|
const build = await this.distributionClient.buildCorrectRegisterTx({ amount });
|
|
173
190
|
if (!build.canSucceed || !build.transaction) {
|
|
@@ -194,19 +211,6 @@ export class SolanaStakingClient implements IStakingClient {
|
|
|
194
211
|
}
|
|
195
212
|
}
|
|
196
213
|
|
|
197
|
-
/**
|
|
198
|
-
* Deposit funds into the staking pool.
|
|
199
|
-
* @param lamports The amount to deposit (in lamports).
|
|
200
|
-
* @returns The transaction signature.
|
|
201
|
-
*/
|
|
202
|
-
async deposit(lamports: number): Promise<string> {
|
|
203
|
-
const { transaction } = await this.depositClient.buildDepositTx(this.solPubKey, lamports);
|
|
204
|
-
const { tx, blockhash, lastValidBlockHeight } = await this.prepareTx(transaction);
|
|
205
|
-
const signed = await this.signTransaction(tx);
|
|
206
|
-
const result = await this.sendAndConfirmHttp(signed, { blockhash, lastValidBlockHeight });
|
|
207
|
-
return result.signature;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
214
|
private async sendAndConfirmHttp(
|
|
211
215
|
signed: SolanaTransaction,
|
|
212
216
|
ctx: { blockhash: string; lastValidBlockHeight: number },
|
package/src/staker/staker.ts
CHANGED
|
@@ -32,6 +32,8 @@ export class Staker {
|
|
|
32
32
|
if (!config) throw new Error('StakerConfig is required');
|
|
33
33
|
if (!Array.isArray(config)) config = [config];
|
|
34
34
|
|
|
35
|
+
// console.log('STAKER INIT', config);
|
|
36
|
+
|
|
35
37
|
config.forEach((cfg) => {
|
|
36
38
|
switch (cfg.network.chainId) {
|
|
37
39
|
case SolChainID.WireTestnet:
|
|
@@ -41,9 +43,10 @@ export class Staker {
|
|
|
41
43
|
case EvmChainID.Hoodi:
|
|
42
44
|
this.clients.set(EvmChainID.Hoodi, new EthereumStakingClient(cfg));
|
|
43
45
|
break;
|
|
46
|
+
|
|
44
47
|
default:
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
console.log(`No staking client available for chain ${cfg.network.chainId}`);
|
|
49
|
+
throw new Error(`Unsupported network curve: ${cfg.network.name}`);
|
|
47
50
|
}
|
|
48
51
|
});
|
|
49
52
|
|
package/src/staker/types.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { BaseSignerWalletAdapter } from '@solana/wallet-adapter-base';
|
|
4
4
|
import { PublicKey as SolPubKey } from '@solana/web3.js';
|
|
5
|
-
import { ExternalNetwork, PublicKey } from '@wireio/core';
|
|
5
|
+
import { ChainID, ExternalNetwork, PublicKey } from '@wireio/core';
|
|
6
6
|
import { BigNumberish, ethers } from 'ethers';
|
|
7
7
|
|
|
8
8
|
export interface IStakingClient {
|
|
@@ -13,7 +13,7 @@ export interface IStakingClient {
|
|
|
13
13
|
deposit(amount: number): Promise<string>;
|
|
14
14
|
|
|
15
15
|
/** Register any untracked LIQ staked tokens */
|
|
16
|
-
register(): Promise<string>;
|
|
16
|
+
// register(): Promise<string>;
|
|
17
17
|
|
|
18
18
|
/** Fetch the portfolio for the LIQ stake user */
|
|
19
19
|
getPortfolio(): Promise<Portfolio>;
|
|
@@ -26,14 +26,19 @@ export type StakerConfig = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export interface Portfolio {
|
|
29
|
-
/** Native
|
|
29
|
+
/** Native balance on chain: ETH, SOL */
|
|
30
30
|
native: BalanceView;
|
|
31
|
-
/** Actual
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
|
|
31
|
+
/** Actual Liquid balance of LiqETH, LiqSOL*/
|
|
32
|
+
liq: BalanceView;
|
|
33
|
+
/** Outpost Staked balance */
|
|
34
|
+
staked: BalanceView
|
|
35
|
+
/** SOL ONLY!
|
|
36
|
+
* Tracked liqSOL balance from distribution program */
|
|
37
|
+
tracked?: BalanceView;
|
|
35
38
|
/** Extra PDAs and account addresses */
|
|
36
39
|
extras?: Record<string, any>;
|
|
40
|
+
/** Chain ID of the network for which this portfolio is from */
|
|
41
|
+
chainID: ChainID;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export type BalanceView = {
|