hedge-web3 0.2.27 → 0.2.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) 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/declarations/utils/getLinkedListAccounts.d.ts +2 -1
  16. package/lib/Constants.js +28 -1
  17. package/lib/idl/vault.js +741 -57
  18. package/lib/index.js +9 -0
  19. package/lib/instructions/adminWithdrawCol.js +60 -0
  20. package/lib/instructions/adminWithdrawUsh.js +57 -0
  21. package/lib/instructions/createCompoundStakingPool.js +58 -0
  22. package/lib/instructions/createCompoundStakingPoolPosition.js +56 -0
  23. package/lib/instructions/createReferralAccount.js +6 -3
  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/referralClaimFees.js +6 -3
  29. package/lib/instructions/setCompoundPoolActive.js +43 -0
  30. package/lib/instructions/setDelegateWallet.js +43 -0
  31. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +64 -0
  32. package/lib/utils/getLinkedListAccounts.js +5 -21
  33. package/package.json +5 -2
  34. package/src/Constants.ts +30 -0
  35. package/src/idl/vault.ts +3638 -2270
  36. package/src/index.ts +9 -2
  37. package/src/instructions/adminWithdrawCol.ts +87 -0
  38. package/src/instructions/adminWithdrawUsh.ts +78 -0
  39. package/src/instructions/createCompoundStakingPool.ts +63 -0
  40. package/src/instructions/createCompoundStakingPoolPosition.ts +85 -0
  41. package/src/instructions/createReferralAccount.ts +13 -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 +16 -10
  48. package/src/instructions/setCompoundPoolActive.ts +51 -0
  49. package/src/instructions/setDelegateWallet.ts +51 -0
  50. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +100 -0
  51. package/src/utils/getLinkedListAccounts.ts +6 -20
package/src/index.ts CHANGED
@@ -24,6 +24,15 @@ export * from './instructions/refreshOraclePrice'
24
24
  export * from './instructions/repayVault'
25
25
  export * from './instructions/setHalted'
26
26
  export * from './instructions/transferVault'
27
+ export * from './instructions/createCompoundStakingPool'
28
+ export * from './instructions/createCompoundStakingPoolPosition'
29
+ export * from './instructions/depositCompoundStakingPoolPosition'
30
+ export * from './instructions/withdrawCompoundStakingPoolPosition'
31
+ export * from './instructions/setDelegateWallet'
32
+ export * from './instructions/setCompoundPoolActive'
33
+ export * from './instructions/adminWithdrawCol'
34
+ export * from './instructions/adminWithdrawUsh'
35
+ export * from './instructions/depositRewardsToCompoundPool'
27
36
  export * from './instructions/updateReferralAccount'
28
37
  export * from './instructions/updateReferralState'
29
38
  export * from './instructions/updateVaultType'
@@ -37,5 +46,3 @@ export * from './state/StakingPoolPosition'
37
46
  export * from './state/VaultAccount'
38
47
  export * from './state/VaultHistoryEvent'
39
48
  export * from './utils/getLinkedListAccounts'
40
-
41
-
@@ -0,0 +1,87 @@
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 { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
+ import {
5
+ findAssociatedTokenAddress,
6
+ getPoolPublicKeyForMint,
7
+ getVaultSystemStatePublicKey,
8
+ getVaultTypeAccountPublicKey,
9
+ } from '../Constants'
10
+ import { Vault } from '../idl/vault'
11
+ import { parseAnchorErrors } from '../utils/Errors'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
+
14
+ export async function adminWithdrawCollateral(
15
+ program: Program<Vault>,
16
+ provider: Provider,
17
+ payer: Signer,
18
+ mintPublicKey: PublicKey,
19
+ collateralType: string
20
+ ): Promise<PublicKey> {
21
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
22
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
23
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
24
+ const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
25
+
26
+ const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
27
+ provider.connection,
28
+ payer,
29
+ vaultTypeAccountInfo.collateralMint,
30
+ stakingPoolAccountObject.compoundPoolDelegateWallet
31
+ )
32
+
33
+ const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
34
+ program.programId,
35
+ poolPublickey,
36
+ vaultTypeAccountInfo.collateralMint
37
+ )
38
+
39
+ const transaction = new Transaction().add(
40
+ await adminWithdrawCollateralInstruction(program, payer.publicKey, mintPublicKey, vaultTypeAccountPublicKey)
41
+ )
42
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
43
+
44
+ return poolPublickey
45
+ }
46
+
47
+ export async function adminWithdrawCollateralInstruction(
48
+ program: Program<Vault>,
49
+ payerPublicKey: PublicKey,
50
+ stakedTokenMintPublicKey: PublicKey,
51
+ vaultTypeAccountPublicKey: PublicKey
52
+ ): Promise<TransactionInstruction> {
53
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
54
+
55
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
56
+ const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
57
+
58
+ const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
59
+ program.programId,
60
+ poolPublickey,
61
+ vaultTypeAccountInfo.collateralMint
62
+ )
63
+
64
+ const delegateAssociatedTokenAccount = await findAssociatedTokenAddress(
65
+ program.programId,
66
+ stakingPoolAccountObject.compoundPoolDelegateWallet,
67
+ vaultTypeAccountInfo.collateralMint
68
+ )
69
+
70
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
71
+
72
+ return await program.methods
73
+ .adminWithdrawColAta()
74
+ .accounts({
75
+ payer: payerPublicKey,
76
+ vaultSystemState: vaultSystemState,
77
+ pool: poolPublickey,
78
+ vaultTypeAccount: vaultTypeAccountPublicKey,
79
+ stakedTokenMint: stakedTokenMintPublicKey,
80
+ poolAssociatedTokenAccount: poolAssociatedTokenAccount,
81
+ delegateAssociatedColAccount: delegateAssociatedTokenAccount,
82
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
83
+ tokenProgram: TOKEN_PROGRAM_ID,
84
+ systemProgram: SystemProgram.programId,
85
+ })
86
+ .instruction()
87
+ }
@@ -0,0 +1,78 @@
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 { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
+ import {
5
+ findAssociatedTokenAddress,
6
+ getPoolPublicKeyForMint,
7
+ getUshMintPublicKey,
8
+ getVaultSystemStatePublicKey,
9
+ } from '../Constants'
10
+ import { Vault } from '../idl/vault'
11
+ import { parseAnchorErrors } from '../utils/Errors'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
+
14
+ export async function adminWithdrawUsh(
15
+ program: Program<Vault>,
16
+ provider: Provider,
17
+ payer: Signer,
18
+ mintPublicKey: PublicKey
19
+ ): Promise<PublicKey> {
20
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
21
+
22
+ const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
23
+
24
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
25
+
26
+ const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
27
+ provider.connection,
28
+ payer,
29
+ ushMintPublickey,
30
+ stakingPoolAccountObject.compoundPoolDelegateWallet
31
+ )
32
+
33
+ const transaction = new Transaction().add(
34
+ await adminWithdrawUshInstruction(program, payer.publicKey, mintPublicKey, poolPublickey)
35
+ )
36
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
37
+ return poolPublickey
38
+ }
39
+
40
+ export async function adminWithdrawUshInstruction(
41
+ program: Program<Vault>,
42
+ payerPublicKey: PublicKey,
43
+ stakedTokenMintPublicKey: PublicKey,
44
+ poolPublickey: PublicKey
45
+ ): Promise<TransactionInstruction> {
46
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
47
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
48
+
49
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
50
+ program.programId,
51
+ poolPublickey,
52
+ ushMintPublickey
53
+ )
54
+
55
+ const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
56
+
57
+ const delegateWalletAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
58
+ program.programId,
59
+ stakingPoolAccountObject.compoundPoolDelegateWallet,
60
+ ushMintPublickey
61
+ )
62
+
63
+ return await program.methods
64
+ .adminWithdrawUshAta()
65
+ .accounts({
66
+ payer: payerPublicKey,
67
+ vaultSystemState: vaultSystemState,
68
+ pool: poolPublickey,
69
+ ushMint: ushMintPublickey,
70
+ stakedTokenMint: stakedTokenMintPublicKey,
71
+ poolAssociatedTokenAccount: poolAssociatedStakedTokenAccount,
72
+ delegateAssociatedUshAccount: delegateWalletAssociatedStakedTokenAccount,
73
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
74
+ tokenProgram: TOKEN_PROGRAM_ID,
75
+ systemProgram: SystemProgram.programId,
76
+ })
77
+ .instruction()
78
+ }
@@ -0,0 +1,63 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
+ import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
+ import {
5
+ findAssociatedTokenAddress,
6
+ getCompoundPoolPublicKeyForMint,
7
+ getHedgeMintPublicKey,
8
+ getPoolPublicKeyForMint,
9
+ getUshMintPublicKey,
10
+ getVaultSystemStatePublicKey,
11
+ } from '../Constants'
12
+ import { Vault } from '../idl/vault'
13
+ import { parseAnchorErrors } from '../utils/Errors'
14
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
15
+
16
+ export async function createCompoundStakingPool(
17
+ program: Program<Vault>,
18
+ provider: Provider,
19
+ payer: Signer,
20
+ mintPublicKey: PublicKey,
21
+ overrideStartTime?: number
22
+ ): Promise<PublicKey> {
23
+ const transaction = new Transaction().add(
24
+ await createCompoundStakingPoolInstruction(program, payer.publicKey, mintPublicKey, overrideStartTime)
25
+ )
26
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
27
+ const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
28
+ return poolPublickey
29
+ }
30
+
31
+ export async function createCompoundStakingPoolInstruction(
32
+ program: Program<Vault>,
33
+ payerPublicKey: PublicKey,
34
+ mintPublicKey: PublicKey,
35
+ overrideStartTime?: number
36
+ ): Promise<TransactionInstruction> {
37
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
38
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
39
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
40
+
41
+ const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
42
+
43
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, mintPublicKey)
44
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
45
+
46
+ return await program.methods
47
+ .createCompoundStakingPool(new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)))
48
+ .accounts({
49
+ signer: payerPublicKey,
50
+ vaultSystemState: vaultSystemStatePublicKey,
51
+ pool: poolPublickey,
52
+ stakedTokenMint: mintPublicKey,
53
+ ushMint: ushMintPublickey,
54
+ hedgeMint: hedgeMintPublickey,
55
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
56
+ poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
57
+ rent: SYSVAR_RENT_PUBKEY,
58
+ tokenProgram: TOKEN_PROGRAM_ID,
59
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
60
+ systemProgram: SystemProgram.programId,
61
+ })
62
+ .instruction()
63
+ }
@@ -0,0 +1,85 @@
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
+ 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 createCompoundStakingPoolPosition(
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
+ const poolPosition = await getCompoundPoolPositionAddress(program.programId, poolPublickey, payer.publicKey)
25
+
26
+ const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
27
+ provider.connection,
28
+ payer,
29
+ mintPublicKey,
30
+ payer.publicKey
31
+ )
32
+
33
+ const transaction = new Transaction().add(
34
+ await createCompoundStakingPoolPositionInstruction(
35
+ program,
36
+ payer.publicKey,
37
+ poolPosition,
38
+ mintPublicKey,
39
+ new BN(depositAmount),
40
+ overrideStartTime
41
+ )
42
+ )
43
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
44
+ return poolPosition
45
+ }
46
+ export async function createCompoundStakingPoolPositionInstruction(
47
+ program: Program<Vault>,
48
+ payerPublicKey: PublicKey,
49
+ poolPositionPublicKey: PublicKey,
50
+ stakedTokenMintPublicKey: PublicKey,
51
+ depositAmount: BN,
52
+ overrideStartTime?: number
53
+ ): Promise<TransactionInstruction> {
54
+ const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
55
+
56
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
57
+ program.programId,
58
+ poolPublickey,
59
+ stakedTokenMintPublicKey
60
+ )
61
+ const payersArbitraryTokenAccount = await findAssociatedTokenAddress(
62
+ program.programId,
63
+ payerPublicKey,
64
+ stakedTokenMintPublicKey
65
+ )
66
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
67
+
68
+ return await program.methods
69
+ .createCompoundStakingPoolPosition(
70
+ depositAmount,
71
+ new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
72
+ )
73
+ .accounts({
74
+ payer: payerPublicKey,
75
+ vaultSystemState: vaultSystemState,
76
+ pool: poolPublickey,
77
+ poolPosition: poolPositionPublicKey,
78
+ stakedTokenMint: stakedTokenMintPublicKey,
79
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
80
+ payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
81
+ tokenProgram: TOKEN_PROGRAM_ID,
82
+ systemProgram: SystemProgram.programId,
83
+ })
84
+ .instruction()
85
+ }
@@ -1,15 +1,13 @@
1
1
  import { BN, 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, getReferralAccountPublicKey, getReferralStatePublicKey,
12
- getUserReferralAccountPublicKey, getVaultSystemStatePublicKey
5
+ getCompoundPoolPublicKeyForMint,
6
+ getHedgeMintPublicKey,
7
+ getReferralAccountPublicKey,
8
+ getReferralStatePublicKey,
9
+ getUserReferralAccountPublicKey,
10
+ getVaultSystemStatePublicKey,
13
11
  } from '../Constants'
14
12
 
15
13
  import { Vault } from '../idl/vault'
@@ -33,6 +31,7 @@ export async function createReferralAccount(
33
31
  provider: Provider,
34
32
  payer: Signer,
35
33
  poolPosition: PublicKey,
34
+ stakedTokenMintPublicKey: PublicKey,
36
35
  overrideTime?: number
37
36
  ): Promise<PublicKey> {
38
37
  // setup transaction
@@ -68,6 +67,7 @@ export async function createReferralAccount(
68
67
  program,
69
68
  payer.publicKey,
70
69
  poolPosition,
70
+ stakedTokenMintPublicKey,
71
71
  referralAccountPublicKey,
72
72
  referallStatePublicKey,
73
73
  hedgeMintPublicKey,
@@ -85,6 +85,7 @@ export async function createReferralAccountInstruction(
85
85
  program: Program<Vault>,
86
86
  payerPublicKey: PublicKey,
87
87
  poolPositionPublicKey: PublicKey,
88
+ stakedTokenMintPublicKey: PublicKey,
88
89
  referralAccountPublicKey: PublicKey,
89
90
  referralStatePublicKey: PublicKey,
90
91
  hedgeMintPublicKey: PublicKey,
@@ -93,6 +94,7 @@ export async function createReferralAccountInstruction(
93
94
  overrideTime?: number
94
95
  ): Promise<TransactionInstruction> {
95
96
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
97
+ const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
96
98
 
97
99
  return await program.methods
98
100
  .createReferralAccount(
@@ -105,6 +107,8 @@ export async function createReferralAccountInstruction(
105
107
  referralAccount: referralAccountPublicKey,
106
108
  userReferralAccount: userReferralAccountPublicKey,
107
109
  poolPosition: poolPositionPublicKey,
110
+ pool: poolPublickey,
111
+ stakedTokenMint: stakedTokenMintPublicKey,
108
112
  hedgeMint: hedgeMintPublicKey,
109
113
  hdgAta: hdgAssociatedTokenAccountPublicKey,
110
114
  systemProgram: SystemProgram.programId,
@@ -1,17 +1,11 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import {
4
- PublicKey, Signer,
5
- SystemProgram,
6
- SYSVAR_RENT_PUBKEY,
7
- Transaction,
8
- TransactionInstruction
9
- } from '@solana/web3.js'
3
+ import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
10
4
  import {
11
5
  findAssociatedTokenAddress,
12
6
  getPoolPublicKeyForMint,
13
7
  getUshMintPublicKey,
14
- getVaultSystemStatePublicKey
8
+ getVaultSystemStatePublicKey,
15
9
  } from '../Constants'
16
10
  import { Vault } from '../idl/vault'
17
11
  import { parseAnchorErrors } from '../utils/Errors'
@@ -43,7 +37,6 @@ export async function createStakingPoolInstruction(
43
37
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
44
38
  const ushMintPublickey = await getUshMintPublicKey(program.programId)
45
39
  const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
46
-
47
40
  const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, mintPublicKey)
48
41
  const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
49
42
  return await program.methods
@@ -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
+ }