@wireio/stake 0.1.0 → 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/README.md +57 -0
- package/lib/stake.browser.js +11836 -4103
- package/lib/stake.browser.js.map +1 -1
- package/lib/stake.d.ts +374 -556
- package/lib/stake.js +12089 -4303
- package/lib/stake.js.map +1 -1
- package/lib/stake.m.js +11836 -4103
- 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/assets/solana/idl/liqsol_core.json +4239 -0
- package/src/assets/solana/idl/liqsol_token.json +183 -0
- package/src/assets/solana/idl/validator_leaderboard.json +270 -265
- package/src/assets/solana/types/liqsol_core.ts +4245 -0
- package/src/assets/solana/types/liqsol_token.ts +189 -0
- package/src/assets/solana/types/validator_leaderboard.ts +270 -265
- package/src/index.ts +1 -3
- package/src/networks/ethereum/contract.ts +101 -36
- package/src/networks/ethereum/ethereum.ts +141 -45
- package/src/networks/ethereum/types.ts +30 -2
- package/src/networks/solana/clients/deposit.client.ts +71 -109
- package/src/networks/solana/clients/distribution.client.ts +256 -383
- package/src/networks/solana/clients/leaderboard.client.ts +38 -133
- package/src/networks/solana/constants.ts +214 -130
- package/src/networks/solana/program.ts +25 -38
- package/src/networks/solana/solana.ts +120 -105
- package/src/networks/solana/types.ts +37 -47
- package/src/networks/solana/utils.ts +551 -0
- package/src/scripts/tsconfig.json +17 -0
- package/src/staker/staker.ts +10 -6
- package/src/staker/types.ts +14 -9
- package/src/assets/solana/idl/deposit.json +0 -296
- package/src/assets/solana/idl/distribution.json +0 -768
- package/src/assets/solana/idl/liq_sol_token.json +0 -298
- package/src/assets/solana/idl/mint_helper.json +0 -110
- package/src/assets/solana/idl/read_tracked_balance.json +0 -140
- package/src/assets/solana/idl/stake_controller.json +0 -2149
- package/src/assets/solana/idl/treasury.json +0 -110
- package/src/assets/solana/idl/validator_registry.json +0 -487
- package/src/assets/solana/idl/yield_oracle.json +0 -32
- package/src/assets/solana/types/deposit.ts +0 -302
- package/src/assets/solana/types/distribution.ts +0 -774
- package/src/assets/solana/types/liq_sol_token.ts +0 -304
- package/src/assets/solana/types/mint_helper.ts +0 -116
- package/src/assets/solana/types/read_tracked_balance.ts +0 -146
- package/src/assets/solana/types/stake_controller.ts +0 -2155
- package/src/assets/solana/types/stake_registry.ts +0 -441
- package/src/assets/solana/types/treasury.ts +0 -116
- package/src/assets/solana/types/validator_registry.ts +0 -493
- package/src/assets/solana/types/yield_oracle.ts +0 -38
- package/src/common/utils.ts +0 -9
|
@@ -1,169 +1,131 @@
|
|
|
1
|
-
import { AnchorProvider, BN } from '@coral-xyz/anchor';
|
|
1
|
+
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
|
|
2
2
|
import {
|
|
3
3
|
PublicKey,
|
|
4
|
-
Transaction,
|
|
5
4
|
SystemProgram,
|
|
5
|
+
Transaction,
|
|
6
|
+
TransactionInstruction,
|
|
7
|
+
StakeProgram,
|
|
6
8
|
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
7
9
|
SYSVAR_CLOCK_PUBKEY,
|
|
8
10
|
SYSVAR_RENT_PUBKEY,
|
|
9
11
|
SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
10
|
-
StakeProgram,
|
|
11
|
-
ComputeBudgetProgram,
|
|
12
|
-
VersionedTransaction,
|
|
13
|
-
Signer,
|
|
14
|
-
TransactionSignature,
|
|
15
12
|
} from '@solana/web3.js';
|
|
16
|
-
|
|
17
13
|
import {
|
|
18
|
-
|
|
14
|
+
TOKEN_2022_PROGRAM_ID,
|
|
19
15
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
20
|
-
|
|
16
|
+
getAssociatedTokenAddressSync,
|
|
21
17
|
} from '@solana/spl-token';
|
|
22
18
|
|
|
19
|
+
import { SolanaProgramService } from '../program';
|
|
20
|
+
import type { LiqsolCore } from '../../../assets/solana/types/liqsol_core';
|
|
21
|
+
|
|
23
22
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
deriveUserRecordPDA,
|
|
38
|
-
derivePayRateHistoryPDA,
|
|
23
|
+
PROGRAM_IDS,
|
|
24
|
+
deriveDepositAuthorityPda,
|
|
25
|
+
deriveLiqsolMintPda,
|
|
26
|
+
deriveLiqsolMintAuthorityPda,
|
|
27
|
+
deriveReservePoolPda,
|
|
28
|
+
deriveVaultPda,
|
|
29
|
+
deriveStakeControllerStatePda,
|
|
30
|
+
deriveBucketAuthorityPda,
|
|
31
|
+
derivePayRateHistoryPda,
|
|
32
|
+
deriveDistributionStatePda,
|
|
33
|
+
deriveUserRecordPda,
|
|
34
|
+
derivePayoutStatePda,
|
|
35
|
+
deriveEphemeralStakeAddress,
|
|
39
36
|
} from '../constants';
|
|
40
|
-
import { SolanaProgramService } from '../program';
|
|
41
37
|
|
|
42
|
-
/**
|
|
43
|
-
* DepositClient: builds, simulates, and sends deposit txns matching the latest IDL.
|
|
44
|
-
*
|
|
45
|
-
*/
|
|
46
38
|
export class DepositClient {
|
|
47
|
-
private
|
|
39
|
+
private program: Program<LiqsolCore>;
|
|
48
40
|
|
|
49
|
-
constructor(private provider: AnchorProvider) {
|
|
41
|
+
constructor(private provider: AnchorProvider) {
|
|
42
|
+
const svc = new SolanaProgramService(provider);
|
|
43
|
+
this.program = svc.getProgram('liqsolCore');
|
|
44
|
+
}
|
|
50
45
|
|
|
51
|
-
/**
|
|
52
|
-
* Build the deposit transaction (compute-budget bump + deposit Ix).
|
|
53
|
-
* Returns the Transaction and the derived ephemeral stake pubkey.
|
|
54
|
-
*/
|
|
55
46
|
async buildDepositTx(
|
|
56
47
|
user: PublicKey,
|
|
57
|
-
|
|
58
|
-
): Promise<{ transaction: Transaction;
|
|
59
|
-
if (amount < MIN_SOL_TO_PARTICIPATE) {
|
|
60
|
-
throw new Error(`Minimum deposit is ${MIN_SOL_TO_PARTICIPATE / 1e9} SOL`);
|
|
61
|
-
}
|
|
48
|
+
lamports: number
|
|
49
|
+
): Promise<{ transaction: Transaction; ephemeralStake: PublicKey }> {
|
|
62
50
|
|
|
63
|
-
const program = this.
|
|
51
|
+
const program = this.program;
|
|
64
52
|
|
|
53
|
+
// -------------------------------------------------------------
|
|
65
54
|
// PDAs
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
55
|
+
// -------------------------------------------------------------
|
|
56
|
+
const depositAuthority = deriveDepositAuthorityPda();
|
|
57
|
+
const liqsolMint = deriveLiqsolMintPda();
|
|
58
|
+
const liqsolMintAuthority = deriveLiqsolMintAuthorityPda();
|
|
59
|
+
const reservePool = deriveReservePoolPda();
|
|
60
|
+
const vault = deriveVaultPda();
|
|
61
|
+
const controllerState = deriveStakeControllerStatePda();
|
|
62
|
+
const payoutState = derivePayoutStatePda();
|
|
63
|
+
const bucketAuthority = deriveBucketAuthorityPda();
|
|
64
|
+
const payRateHistory = derivePayRateHistoryPda();
|
|
65
|
+
const distributionState = deriveDistributionStatePda();
|
|
66
|
+
const userRecord = deriveUserRecordPda(user);
|
|
67
|
+
|
|
68
|
+
// -------------------------------------------------------------
|
|
78
69
|
// Token-2022 ATAs
|
|
79
|
-
|
|
70
|
+
// -------------------------------------------------------------
|
|
71
|
+
const userAta = getAssociatedTokenAddressSync(
|
|
80
72
|
liqsolMint,
|
|
81
73
|
user,
|
|
82
74
|
false,
|
|
83
75
|
TOKEN_2022_PROGRAM_ID
|
|
84
76
|
);
|
|
85
|
-
|
|
77
|
+
|
|
78
|
+
const bucketTokenAccount = getAssociatedTokenAddressSync(
|
|
86
79
|
liqsolMint,
|
|
87
80
|
bucketAuthority,
|
|
88
|
-
|
|
81
|
+
true,
|
|
89
82
|
TOKEN_2022_PROGRAM_ID
|
|
90
83
|
);
|
|
91
84
|
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.deposit(new BN(amount), seed)
|
|
85
|
+
// -------------------------------------------------------------
|
|
86
|
+
// Ephemeral stake
|
|
87
|
+
// -------------------------------------------------------------
|
|
88
|
+
const seed = Math.floor(Math.random() * 2 ** 32);
|
|
89
|
+
const ephemeralStake = await deriveEphemeralStakeAddress(user, seed);
|
|
90
|
+
|
|
91
|
+
// -------------------------------------------------------------
|
|
92
|
+
// BUILD IX (MUST MATCH IDL)
|
|
93
|
+
// -------------------------------------------------------------
|
|
94
|
+
const ix: TransactionInstruction = await program.methods
|
|
95
|
+
.deposit(new BN(lamports), seed)
|
|
104
96
|
.accounts({
|
|
105
97
|
user,
|
|
106
|
-
|
|
98
|
+
depositAuthority,
|
|
107
99
|
systemProgram: SystemProgram.programId,
|
|
108
100
|
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
109
101
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
110
|
-
|
|
111
|
-
liqsolProgram: LIQSOL_TOKEN_PROGRAM_ID,
|
|
112
|
-
payRateHistory,
|
|
102
|
+
liqsolProgram: PROGRAM_IDS.LIQSOL_TOKEN,
|
|
113
103
|
stakeProgram: StakeProgram.programId,
|
|
114
|
-
distributionProgram: DISTRIBUTION_PROGRAM_ID,
|
|
115
104
|
|
|
116
|
-
// mints / ATAs / PDAs
|
|
117
105
|
liqsolMint,
|
|
118
106
|
userAta,
|
|
119
107
|
liqsolMintAuthority,
|
|
120
108
|
reservePool,
|
|
121
109
|
vault,
|
|
122
|
-
ephemeralStake
|
|
110
|
+
ephemeralStake,
|
|
111
|
+
|
|
123
112
|
controllerState,
|
|
124
|
-
|
|
113
|
+
payoutState,
|
|
125
114
|
bucketAuthority,
|
|
126
115
|
bucketTokenAccount,
|
|
116
|
+
|
|
127
117
|
userRecord,
|
|
128
118
|
distributionState,
|
|
119
|
+
payRateHistory,
|
|
129
120
|
|
|
130
|
-
// sysvars
|
|
131
121
|
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
132
122
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
133
123
|
stakeHistory: SYSVAR_STAKE_HISTORY_PUBKEY,
|
|
134
124
|
rent: SYSVAR_RENT_PUBKEY,
|
|
135
|
-
}
|
|
125
|
+
})
|
|
136
126
|
.instruction();
|
|
137
127
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const tx = new Transaction().add(computeIx, depositIx);
|
|
141
|
-
return { transaction: tx, ephemeralStakePubkey };
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Simulate a transaction (dry-run). */
|
|
145
|
-
async simulate(tx: Transaction): Promise<{ err: any; unitsConsumed: number }> {
|
|
146
|
-
tx.feePayer = this.provider.wallet.publicKey;
|
|
147
|
-
const { blockhash } = await this.provider.connection.getLatestBlockhash();
|
|
148
|
-
tx.recentBlockhash = blockhash;
|
|
149
|
-
|
|
150
|
-
const versioned = new VersionedTransaction(tx.compileMessage());
|
|
151
|
-
const sim = await this.provider.connection.simulateTransaction(versioned, {
|
|
152
|
-
sigVerify: false,
|
|
153
|
-
});
|
|
154
|
-
return { err: sim.value.err, unitsConsumed: sim.value.unitsConsumed! };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** Build + send. Returns confirmed signature. */
|
|
158
|
-
async deposit(
|
|
159
|
-
user: PublicKey,
|
|
160
|
-
amount: number,
|
|
161
|
-
signers: Signer[] = []
|
|
162
|
-
): Promise<TransactionSignature> {
|
|
163
|
-
const { transaction } = await this.buildDepositTx(user, amount);
|
|
164
|
-
transaction.feePayer = this.provider.wallet.publicKey;
|
|
165
|
-
const { blockhash } = await this.provider.connection.getLatestBlockhash();
|
|
166
|
-
transaction.recentBlockhash = blockhash;
|
|
167
|
-
return this.provider.sendAndConfirm(transaction, signers);
|
|
128
|
+
const tx = new Transaction().add(ix);
|
|
129
|
+
return { transaction: tx, ephemeralStake };
|
|
168
130
|
}
|
|
169
131
|
}
|