hedge-web3 0.2.28 → 0.2.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/declarations/Constants.d.ts +12 -0
  2. package/declarations/idl/vault.d.ts +842 -1
  3. package/declarations/index.d.ts +11 -0
  4. package/declarations/instructions/adminWithdrawCol.d.ts +5 -0
  5. package/declarations/instructions/adminWithdrawUsh.d.ts +5 -0
  6. package/declarations/instructions/compoundCreateReferralAccount.d.ts +17 -0
  7. package/declarations/instructions/compoundReferralClaimFees.d.ts +16 -0
  8. package/declarations/instructions/createCompoundStakingPool.d.ts +5 -0
  9. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +6 -0
  10. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +6 -0
  11. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +6 -0
  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 +842 -1
  17. package/lib/index.js +11 -0
  18. package/lib/instructions/adminWithdrawCol.js +60 -0
  19. package/lib/instructions/adminWithdrawUsh.js +57 -0
  20. package/lib/instructions/compoundCreateReferralAccount.js +83 -0
  21. package/lib/instructions/compoundReferralClaimFees.js +87 -0
  22. package/lib/instructions/createCompoundStakingPool.js +58 -0
  23. package/lib/instructions/createCompoundStakingPoolPosition.js +56 -0
  24. package/lib/instructions/depositCompoundStakingPoolPosition.js +55 -0
  25. package/lib/instructions/depositRewardsToCompoundPool.js +64 -0
  26. package/lib/instructions/liquidateVault.js +7 -1
  27. package/lib/instructions/loanVault.js +7 -1
  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 +3753 -2071
  34. package/src/index.ts +11 -2
  35. package/src/instructions/adminWithdrawCol.ts +87 -0
  36. package/src/instructions/adminWithdrawUsh.ts +78 -0
  37. package/src/instructions/compoundCreateReferralAccount.ts +119 -0
  38. package/src/instructions/compoundReferralClaimFees.ts +151 -0
  39. package/src/instructions/createCompoundStakingPool.ts +63 -0
  40. package/src/instructions/createCompoundStakingPoolPosition.ts +85 -0
  41. package/src/instructions/createReferralAccount.ts +6 -9
  42. package/src/instructions/createStakingPool.ts +2 -9
  43. package/src/instructions/depositCompoundStakingPoolPosition.ts +78 -0
  44. package/src/instructions/depositRewardsToCompoundPool.ts +110 -0
  45. package/src/instructions/liquidateVault.ts +37 -27
  46. package/src/instructions/loanVault.ts +34 -21
  47. package/src/instructions/referralClaimFees.ts +7 -9
  48. package/src/instructions/setCompoundPoolActive.ts +51 -0
  49. package/src/instructions/setDelegateWallet.ts +51 -0
  50. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +100 -0
@@ -0,0 +1,78 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { 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
+ getPoolPublicKeyForMint,
9
+ getVaultSystemStatePublicKey,
10
+ } from '../Constants'
11
+ import { Vault } from '../idl/vault'
12
+ import { parseAnchorErrors } from '../utils/Errors'
13
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
14
+
15
+ export async function depositCompoundStakingPoolPosition(
16
+ program: Program<Vault>,
17
+ provider: Provider,
18
+ payer: Signer,
19
+ mintPublicKey: PublicKey,
20
+ depositAmount: number,
21
+ overrideStartTime?: number
22
+ ): Promise<PublicKey> {
23
+ const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
24
+
25
+ const poolPosition = await getCompoundPoolPositionAddress(program.programId, poolPublickey, payer.publicKey)
26
+ const transaction = new Transaction().add(
27
+ await depositCompoundStakingPoolPositionInstruction(
28
+ program,
29
+ payer.publicKey,
30
+ poolPosition,
31
+ mintPublicKey,
32
+ new BN(depositAmount),
33
+ overrideStartTime
34
+ )
35
+ )
36
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
37
+ return poolPosition
38
+ }
39
+
40
+ export async function depositCompoundStakingPoolPositionInstruction(
41
+ program: Program<Vault>,
42
+ payerPublicKey: PublicKey,
43
+ poolPositionPublicKey: PublicKey,
44
+ stakedTokenMintPublicKey: PublicKey,
45
+ depositAmount: BN,
46
+ overrideStartTime?: number
47
+ ): Promise<TransactionInstruction> {
48
+ const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
49
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
50
+ program.programId,
51
+ poolPublickey,
52
+ stakedTokenMintPublicKey
53
+ )
54
+ const payersArbitraryTokenAccount = await findAssociatedTokenAddress(
55
+ program.programId,
56
+ payerPublicKey,
57
+ stakedTokenMintPublicKey
58
+ )
59
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
60
+
61
+ return await program.methods
62
+ .depositCompoundStakingPoolPosition(
63
+ depositAmount,
64
+ new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
65
+ )
66
+ .accounts({
67
+ payer: payerPublicKey,
68
+ vaultSystemState: vaultSystemState,
69
+ pool: poolPublickey,
70
+ poolPosition: poolPositionPublicKey,
71
+ stakedTokenMint: stakedTokenMintPublicKey,
72
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
73
+ payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
74
+ tokenProgram: TOKEN_PROGRAM_ID,
75
+ systemProgram: SystemProgram.programId,
76
+ })
77
+ .instruction()
78
+ }
@@ -0,0 +1,110 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
+ import {
4
+ Keypair,
5
+ PublicKey,
6
+ Signer,
7
+ SystemProgram,
8
+ SYSVAR_RENT_PUBKEY,
9
+ Transaction,
10
+ TransactionInstruction,
11
+ } from '@solana/web3.js'
12
+ import {
13
+ findAssociatedTokenAddress,
14
+ getCompoundPoolPublicKeyForMint,
15
+ getHedgeMintPublicKey,
16
+ getPoolPublicKeyForMint,
17
+ getUshMintPublicKey,
18
+ getVaultSystemStatePublicKey,
19
+ getVaultTypeAccountPublicKey,
20
+ } from '../Constants'
21
+ import { Vault } from '../idl/vault'
22
+ import { parseAnchorErrors } from '../utils/Errors'
23
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
+
25
+ export async function depositRewardsToCompoundStakingPool(
26
+ program: Program<Vault>,
27
+ provider: Provider,
28
+ payer: Signer,
29
+ mintPublicKey: PublicKey,
30
+ depositAmount: number,
31
+ overrideStartTime?: number
32
+ ): Promise<PublicKey> {
33
+ const history = Keypair.generate()
34
+
35
+ const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
36
+ const [poolStakingPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
37
+
38
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
39
+
40
+ const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolStakingPublickey)
41
+
42
+ const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
43
+ provider.connection,
44
+ payer,
45
+ hedgeMintPublickey,
46
+ stakingPoolAccountObject.compoundPoolDelegateWallet
47
+ )
48
+
49
+ const transaction = new Transaction().add(
50
+ await depositRewardsToCompoundStakingPoolInstruction(
51
+ program,
52
+ payer.publicKey,
53
+ mintPublicKey,
54
+ history.publicKey,
55
+ new BN(depositAmount),
56
+ overrideStartTime
57
+ )
58
+ )
59
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history]).catch(parseAnchorErrors)
60
+ return poolPublickey
61
+ }
62
+
63
+ export async function depositRewardsToCompoundStakingPoolInstruction(
64
+ program: Program<Vault>,
65
+ payerPublicKey: PublicKey,
66
+ mintPublicKey: PublicKey,
67
+ historyPublicKey: PublicKey,
68
+ amount: BN,
69
+ overrideStartTime?: number
70
+ ): Promise<TransactionInstruction> {
71
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
72
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
73
+
74
+ const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
75
+
76
+ const [poolStakingPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
77
+
78
+ const poolAssociatedHedgeTokenAccount = await findAssociatedTokenAddress(
79
+ program.programId,
80
+ poolPublickey,
81
+ hedgeMintPublickey
82
+ )
83
+
84
+ const payerAssociatedHedgeTokenAccount = await findAssociatedTokenAddress(
85
+ program.programId,
86
+ payerPublicKey,
87
+ hedgeMintPublickey
88
+ )
89
+
90
+ return await program.methods
91
+ .depositRewardsToCompoundPool(
92
+ amount,
93
+ new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
94
+ )
95
+ .accounts({
96
+ payer: payerPublicKey,
97
+ vaultSystemState: vaultSystemStatePublicKey,
98
+ history: historyPublicKey,
99
+ compoundPool: poolPublickey,
100
+ pool: poolStakingPublickey,
101
+ stakedTokenMint: mintPublicKey,
102
+ hedgeMint: hedgeMintPublickey,
103
+ poolAssociatedHedgeAccount: poolAssociatedHedgeTokenAccount,
104
+ payerAssociatedHedgeAccount: payerAssociatedHedgeTokenAccount,
105
+ tokenProgram: TOKEN_PROGRAM_ID,
106
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
107
+ systemProgram: SystemProgram.programId,
108
+ })
109
+ .instruction()
110
+ }
@@ -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,13 @@
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
+ getHedgeMintPublicKey,
6
+ getPoolPublicKeyForMint,
7
+ getReferralAccountPublicKey,
8
+ getReferralStatePublicKey,
9
+ getUshMintPublicKey,
10
+ getVaultSystemStatePublicKey,
13
11
  } from '../Constants'
14
12
 
15
13
  import { Vault } from '../idl/vault'
@@ -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
+ }