hedge-web3 0.2.28 → 0.2.31

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 (48) hide show
  1. package/declarations/Constants.d.ts +12 -0
  2. package/declarations/idl/vault.d.ts +743 -59
  3. package/declarations/index.d.ts +9 -0
  4. package/declarations/instructions/adminWithdrawCol.d.ts +5 -0
  5. package/declarations/instructions/adminWithdrawUsh.d.ts +5 -0
  6. package/declarations/instructions/createCompoundStakingPool.d.ts +5 -0
  7. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +6 -0
  8. package/declarations/instructions/createReferralAccount.d.ts +2 -2
  9. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +6 -0
  10. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +6 -0
  11. package/declarations/instructions/referralClaimFees.d.ts +2 -2
  12. package/declarations/instructions/setCompoundPoolActive.d.ts +5 -0
  13. package/declarations/instructions/setDelegateWallet.d.ts +5 -0
  14. package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +6 -0
  15. package/lib/Constants.js +28 -1
  16. package/lib/idl/vault.js +741 -57
  17. package/lib/index.js +9 -0
  18. package/lib/instructions/adminWithdrawCol.js +60 -0
  19. package/lib/instructions/adminWithdrawUsh.js +57 -0
  20. package/lib/instructions/createCompoundStakingPool.js +58 -0
  21. package/lib/instructions/createCompoundStakingPoolPosition.js +56 -0
  22. package/lib/instructions/createReferralAccount.js +6 -3
  23. package/lib/instructions/depositCompoundStakingPoolPosition.js +55 -0
  24. package/lib/instructions/depositRewardsToCompoundPool.js +64 -0
  25. package/lib/instructions/liquidateVault.js +7 -1
  26. package/lib/instructions/loanVault.js +7 -1
  27. package/lib/instructions/referralClaimFees.js +6 -3
  28. package/lib/instructions/setCompoundPoolActive.js +43 -0
  29. package/lib/instructions/setDelegateWallet.js +43 -0
  30. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +64 -0
  31. package/package.json +5 -2
  32. package/src/Constants.ts +30 -0
  33. package/src/idl/vault.ts +3638 -2270
  34. package/src/index.ts +9 -2
  35. package/src/instructions/adminWithdrawCol.ts +87 -0
  36. package/src/instructions/adminWithdrawUsh.ts +78 -0
  37. package/src/instructions/createCompoundStakingPool.ts +63 -0
  38. package/src/instructions/createCompoundStakingPoolPosition.ts +85 -0
  39. package/src/instructions/createReferralAccount.ts +13 -9
  40. package/src/instructions/createStakingPool.ts +2 -9
  41. package/src/instructions/depositCompoundStakingPoolPosition.ts +78 -0
  42. package/src/instructions/depositRewardsToCompoundPool.ts +110 -0
  43. package/src/instructions/liquidateVault.ts +37 -27
  44. package/src/instructions/loanVault.ts +34 -21
  45. package/src/instructions/referralClaimFees.ts +16 -10
  46. package/src/instructions/setCompoundPoolActive.ts +51 -0
  47. package/src/instructions/setDelegateWallet.ts +51 -0
  48. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +100 -0
@@ -1,19 +1,22 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
+ ComputeBudgetProgram,
4
5
  Keypair,
5
- PublicKey, Signer,
6
+ PublicKey,
7
+ Signer,
6
8
  SystemProgram,
7
9
  SYSVAR_RENT_PUBKEY,
8
10
  Transaction,
9
- TransactionInstruction
11
+ TransactionInstruction,
10
12
  } from '@solana/web3.js'
11
13
  import {
12
14
  getHedgeMintPublicKey,
13
15
  getLiquidationPoolStatePublicKey,
14
16
  getLiquidationPoolUshAccountPublicKey,
15
- getPoolPublicKeyForMint, getUshMintPublicKey,
16
- getVaultSystemStatePublicKey
17
+ getPoolPublicKeyForMint,
18
+ getUshMintPublicKey,
19
+ getVaultSystemStatePublicKey,
17
20
  } from '../Constants'
18
21
  import { Vault } from '../idl/vault'
19
22
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
@@ -37,6 +40,11 @@ export async function liquidateVault(
37
40
  const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
38
41
  const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
39
42
 
43
+ const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
44
+ units: 300000,
45
+ additionalFee: 0,
46
+ })
47
+
40
48
  const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
41
49
  provider.connection,
42
50
  payer,
@@ -96,30 +104,32 @@ export async function liquidateVault(
96
104
  const newEra = Keypair.generate()
97
105
  const transaction = new Transaction()
98
106
 
99
- transaction.add(
100
- await liquidateVaultInstruction(
101
- program,
102
- payer.publicKey,
103
- payerAssociatedTokenAccount.address,
104
- vaultPublicKey,
105
- vaultAssociatedTokenAccount.address,
106
- liquidationPoolStatePublicKey,
107
- poolStateInfo.currentEra,
108
- poolAssociatedTokenAccount.address,
109
- history.publicKey,
110
- newEra.publicKey,
111
- hedgeStakingPoolPublicKey,
112
- feePoolAssociatedTokenAccount.address,
113
- hedgeStakingPoolAssociatedUshTokenAccount.address,
114
- collateralMint,
115
- vaultTypeAssociatedTokenAccount.address,
116
- oldSmallerPublicKey,
117
- newSmallerPublicKey,
118
- newLargerPublicKey,
119
- vaultAccount.vaultType,
120
- overrideTime
107
+ transaction
108
+ .add(additionalComputationBudget)
109
+ .add(
110
+ await liquidateVaultInstruction(
111
+ program,
112
+ payer.publicKey,
113
+ payerAssociatedTokenAccount.address,
114
+ vaultPublicKey,
115
+ vaultAssociatedTokenAccount.address,
116
+ liquidationPoolStatePublicKey,
117
+ poolStateInfo.currentEra,
118
+ poolAssociatedTokenAccount.address,
119
+ history.publicKey,
120
+ newEra.publicKey,
121
+ hedgeStakingPoolPublicKey,
122
+ feePoolAssociatedTokenAccount.address,
123
+ hedgeStakingPoolAssociatedUshTokenAccount.address,
124
+ collateralMint,
125
+ vaultTypeAssociatedTokenAccount.address,
126
+ oldSmallerPublicKey,
127
+ newSmallerPublicKey,
128
+ newLargerPublicKey,
129
+ vaultAccount.vaultType,
130
+ overrideTime
131
+ )
121
132
  )
122
- )
123
133
 
124
134
  await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history, newEra])
125
135
  return vaultPublicKey
@@ -1,17 +1,23 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
+ ComputeBudgetProgram,
4
5
  Keypair,
5
- PublicKey, Signer,
6
+ PublicKey,
7
+ Signer,
6
8
  SystemProgram,
7
9
  Transaction,
8
- TransactionInstruction
10
+ TransactionInstruction,
9
11
  } from '@solana/web3.js'
10
12
  import {
11
13
  findAssociatedTokenAddress,
12
14
  getHedgeMintPublicKey,
13
- getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
14
- getVaultSystemStatePublicKey
15
+ getPoolPublicKeyForMint,
16
+ getReferralAccountPublicKey,
17
+ getReferralStatePublicKey,
18
+ getUserReferralAccountPublicKey,
19
+ getUshMintPublicKey,
20
+ getVaultSystemStatePublicKey,
15
21
  } from '../Constants'
16
22
  import { Vault } from '../idl/vault'
17
23
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
@@ -26,6 +32,11 @@ export async function loanVault(
26
32
  overrideTime?: number,
27
33
  referrer?: PublicKey
28
34
  ): Promise<PublicKey> {
35
+ const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
36
+ units: 300000,
37
+ additionalFee: 0,
38
+ })
39
+
29
40
  const ushMintPublickey = await getUshMintPublicKey(program.programId)
30
41
 
31
42
  const payerUshAccount = await getOrCreateAssociatedTokenAccount(
@@ -72,24 +83,26 @@ export async function loanVault(
72
83
  }
73
84
 
74
85
  const history = Keypair.generate()
75
- const transaction = new Transaction().add(
76
- await loanVaultInstruction(
77
- program,
78
- payer.publicKey,
79
- payerUshAccount.address,
80
- vaultPublicKey,
81
- vaultAssociatedTokenAccount.address,
82
- history.publicKey,
83
- vaultAccount.vaultType,
84
- vaultTypeAssociatedTokenAccount.address,
85
- oldSmallerPublicKey,
86
- newSmallerPublicKey,
87
- newLargerPublicKey,
88
- new BN(loanAmount),
89
- referralAccountPublicKey,
90
- overrideTime
86
+ const transaction = new Transaction()
87
+ .add(additionalComputationBudget)
88
+ .add(
89
+ await loanVaultInstruction(
90
+ program,
91
+ payer.publicKey,
92
+ payerUshAccount.address,
93
+ vaultPublicKey,
94
+ vaultAssociatedTokenAccount.address,
95
+ history.publicKey,
96
+ vaultAccount.vaultType,
97
+ vaultTypeAssociatedTokenAccount.address,
98
+ oldSmallerPublicKey,
99
+ newSmallerPublicKey,
100
+ newLargerPublicKey,
101
+ new BN(loanAmount),
102
+ referralAccountPublicKey,
103
+ overrideTime
104
+ )
91
105
  )
92
- )
93
106
  await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
94
107
  return vaultPublicKey
95
108
  }
@@ -1,15 +1,14 @@
1
1
  import { Program, Provider } from '@project-serum/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
+ import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
3
4
  import {
4
- PublicKey, Signer,
5
- SystemProgram,
6
- SYSVAR_RENT_PUBKEY,
7
- Transaction,
8
- TransactionInstruction
9
- } from '@solana/web3.js'
10
- import {
11
- getHedgeMintPublicKey, getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey,
12
- getUshMintPublicKey, getVaultSystemStatePublicKey
5
+ getCompoundPoolPublicKeyForMint,
6
+ getHedgeMintPublicKey,
7
+ getPoolPublicKeyForMint,
8
+ getReferralAccountPublicKey,
9
+ getReferralStatePublicKey,
10
+ getUshMintPublicKey,
11
+ getVaultSystemStatePublicKey,
13
12
  } from '../Constants'
14
13
 
15
14
  import { Vault } from '../idl/vault'
@@ -31,7 +30,8 @@ export async function referralClaimFees(
31
30
  program: Program<Vault>,
32
31
  provider: Provider,
33
32
  payer: Signer,
34
- poolPosition: PublicKey
33
+ poolPosition: PublicKey,
34
+ stakedTokenMintPublicKey: PublicKey
35
35
  ): Promise<PublicKey> {
36
36
  // setup transaction
37
37
  const transaction = new Transaction()
@@ -91,6 +91,7 @@ export async function referralClaimFees(
91
91
  payer.publicKey,
92
92
  vaultSystemStatePublicKey,
93
93
  poolPosition,
94
+ stakedTokenMintPublicKey,
94
95
  referralAccountPublicKey,
95
96
  referallStatePublicKey,
96
97
  hedgeMintPublicKey,
@@ -112,6 +113,7 @@ export async function referralClaimFeesInstruction(
112
113
  payerPublicKey: PublicKey,
113
114
  vaultSystemStatePublicKey: PublicKey,
114
115
  poolPositionPublicKey: PublicKey,
116
+ stakedTokenMintPublicKey: PublicKey,
115
117
  referralAccountPublicKey: PublicKey,
116
118
  referralStatePublicKey: PublicKey,
117
119
  hedgeMintPublicKey: PublicKey,
@@ -122,6 +124,8 @@ export async function referralClaimFeesInstruction(
122
124
  feePoolPublicKey: PublicKey,
123
125
  feePoolAssociatedUshTokenAccountPublicKey: PublicKey
124
126
  ): Promise<TransactionInstruction> {
127
+ const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
128
+
125
129
  return await program.methods
126
130
  .referralClaimFees()
127
131
  .accounts({
@@ -135,6 +139,8 @@ export async function referralClaimFeesInstruction(
135
139
  ushMint: ushMintPublicKey,
136
140
  signerUshAta: ushAssociatedTokenAccountPublicKey,
137
141
  communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccountPublicKey,
142
+ pool: poolPublickey,
143
+ stakedTokenMint: stakedTokenMintPublicKey,
138
144
  feePool: feePoolPublicKey,
139
145
  feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccountPublicKey,
140
146
  systemProgram: SystemProgram.programId,
@@ -0,0 +1,51 @@
1
+ import { Program, Provider } from '@project-serum/anchor'
2
+ import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import { getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
4
+
5
+ import { Vault } from '../idl/vault'
6
+ import { parseAnchorErrors } from '../utils/Errors'
7
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
8
+
9
+ export async function setCompoundPoolActive(
10
+ program: Program<Vault>,
11
+ provider: Provider,
12
+ payer: Signer,
13
+ mintPublicKey: PublicKey,
14
+ setActive: boolean
15
+ ): Promise<PublicKey> {
16
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
17
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
18
+
19
+ const transaction = new Transaction().add(
20
+ await setCompoundPoolActiveInstruction(
21
+ program,
22
+ vaultSystemStatePublicKey,
23
+ payer.publicKey,
24
+ poolPublickey,
25
+ mintPublicKey,
26
+ setActive
27
+ )
28
+ )
29
+
30
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
31
+ return poolPublickey
32
+ }
33
+
34
+ export async function setCompoundPoolActiveInstruction(
35
+ program: Program<Vault>,
36
+ vaultSystemStatePublicKey: PublicKey,
37
+ payerPublicKey: PublicKey,
38
+ poolPublicKey: PublicKey,
39
+ stakedTokenMintPublicKey: PublicKey,
40
+ setActive: boolean
41
+ ): Promise<TransactionInstruction> {
42
+ return await program.methods
43
+ .setCompoundPoolActive(setActive)
44
+ .accounts({
45
+ payer: payerPublicKey,
46
+ vaultSystemState: vaultSystemStatePublicKey,
47
+ pool: poolPublicKey,
48
+ stakedTokenMint: stakedTokenMintPublicKey,
49
+ })
50
+ .instruction()
51
+ }
@@ -0,0 +1,51 @@
1
+ import { Program, Provider } from '@project-serum/anchor'
2
+ import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import { getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
4
+
5
+ import { Vault } from '../idl/vault'
6
+ import { parseAnchorErrors } from '../utils/Errors'
7
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
8
+
9
+ export async function setDelegateWallet(
10
+ program: Program<Vault>,
11
+ provider: Provider,
12
+ payer: Signer,
13
+ mintPublicKey: PublicKey,
14
+ delegateWallet: PublicKey
15
+ ): Promise<PublicKey> {
16
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
17
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
18
+
19
+ const transaction = new Transaction().add(
20
+ await setDelegateWalletInstruction(
21
+ program,
22
+ vaultSystemStatePublicKey,
23
+ payer.publicKey,
24
+ poolPublickey,
25
+ mintPublicKey,
26
+ delegateWallet
27
+ )
28
+ )
29
+
30
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
31
+ return delegateWallet
32
+ }
33
+
34
+ export async function setDelegateWalletInstruction(
35
+ program: Program<Vault>,
36
+ vaultSystemStatePublicKey: PublicKey,
37
+ payerPublicKey: PublicKey,
38
+ poolPublicKey: PublicKey,
39
+ stakedTokenMintPublicKey: PublicKey,
40
+ delegateWallet: PublicKey
41
+ ): Promise<TransactionInstruction> {
42
+ return await program.methods
43
+ .setDelegateWallet(delegateWallet)
44
+ .accounts({
45
+ payer: payerPublicKey,
46
+ vaultSystemState: vaultSystemStatePublicKey,
47
+ pool: poolPublicKey,
48
+ stakedTokenMint: stakedTokenMintPublicKey,
49
+ })
50
+ .instruction()
51
+ }
@@ -0,0 +1,100 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
+ import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
+ import {
5
+ findAssociatedTokenAddress,
6
+ getCompoundPoolPositionAddress,
7
+ getCompoundPoolPublicKeyForMint,
8
+ getHedgeMintPublicKey,
9
+ getPoolPublicKeyForMint,
10
+ getUshMintPublicKey,
11
+ getVaultSystemStatePublicKey,
12
+ } from '../Constants'
13
+ import { Vault } from '../idl/vault'
14
+ import { parseAnchorErrors } from '../utils/Errors'
15
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
16
+
17
+ export async function withdrawCompoundStakingPoolPosition(
18
+ program: Program<Vault>,
19
+ provider: Provider,
20
+ payer: Signer,
21
+ poolPositionPublicKey: PublicKey,
22
+ stakedTokenMintPublicKey: PublicKey,
23
+ claimAmount: number,
24
+ overrideStartTime?: number
25
+ ): Promise<PublicKey> {
26
+ const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
27
+
28
+ const poolPosition = await getCompoundPoolPositionAddress(program.programId, poolPublickey, payer.publicKey)
29
+
30
+ const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
31
+ provider.connection,
32
+ payer,
33
+ stakedTokenMintPublicKey,
34
+ payer.publicKey
35
+ )
36
+ const transaction = new Transaction().add(
37
+ await withdrawCompoundStakingPoolPositionInstruction(
38
+ program,
39
+ payer.publicKey,
40
+ poolPositionPublicKey,
41
+ stakedTokenMintPublicKey,
42
+ new BN(claimAmount),
43
+ overrideStartTime
44
+ )
45
+ )
46
+
47
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
48
+ return payerAssociatedTokenAccount.address
49
+ }
50
+
51
+ export async function withdrawCompoundStakingPoolPositionInstruction(
52
+ program: Program<Vault>,
53
+ payerPublicKey: PublicKey,
54
+ poolPositionPublicKey: PublicKey,
55
+ stakedTokenMintPublicKey: PublicKey,
56
+ claimAmount: BN,
57
+ overrideStartTime?: number
58
+ ): Promise<TransactionInstruction> {
59
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
60
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
61
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
62
+ const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
63
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
64
+ program.programId,
65
+ poolPublickey,
66
+ stakedTokenMintPublicKey
67
+ )
68
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
69
+ const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
70
+ program.programId,
71
+ payerPublicKey,
72
+ stakedTokenMintPublicKey
73
+ )
74
+ const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
75
+ const payerAssociatedUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
76
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(
77
+ program.programId,
78
+ vaultSystemStatePublicKey,
79
+ hedgeMintPublickey
80
+ )
81
+
82
+ return await program.methods
83
+ .withdrawCompoundStakingPoolPosition(
84
+ new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
85
+ claimAmount //amount to be claimed
86
+ )
87
+ .accounts({
88
+ payer: payerPublicKey,
89
+ vaultSystemState: vaultSystemStatePublicKey,
90
+ pool: poolPublickey,
91
+ poolPosition: poolPositionPublicKey,
92
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
93
+ payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
94
+ hedgeMint: hedgeMintPublickey,
95
+ stakedTokenMint: stakedTokenMintPublicKey,
96
+ tokenProgram: TOKEN_PROGRAM_ID,
97
+ systemProgram: SystemProgram.programId,
98
+ })
99
+ .instruction()
100
+ }