hedge-web3 0.2.33 → 0.3.0

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 (150) hide show
  1. package/declarations/Constants.d.ts +0 -12
  2. package/declarations/HedgeConstants.d.ts +76 -0
  3. package/declarations/idl/pyth.d.ts +1 -1
  4. package/declarations/idl/switchboard.d.ts +1 -1
  5. package/declarations/idl/vault.d.ts +2 -843
  6. package/declarations/index.d.ts +1 -12
  7. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
  8. package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
  9. package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +1 -1
  10. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
  11. package/declarations/instructions/createReferralAccount.d.ts +1 -1
  12. package/declarations/instructions/createStakingPool.d.ts +1 -1
  13. package/declarations/instructions/createUserReferralAccount.d.ts +1 -1
  14. package/declarations/instructions/createVault.d.ts +1 -2
  15. package/declarations/instructions/depositLiquidationPool.d.ts +1 -2
  16. package/declarations/instructions/depositStakingPool.d.ts +1 -2
  17. package/declarations/instructions/depositVault.d.ts +1 -2
  18. package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
  19. package/declarations/instructions/initHedgeFoundationTokens.d.ts +1 -1
  20. package/declarations/instructions/liquidateVault.d.ts +1 -1
  21. package/declarations/instructions/loanVault.d.ts +1 -2
  22. package/declarations/instructions/psmEditAccount.d.ts +1 -2
  23. package/declarations/instructions/psmMintUsh.d.ts +1 -2
  24. package/declarations/instructions/psmRedeemUsh.d.ts +1 -2
  25. package/declarations/instructions/redeemVault.d.ts +1 -2
  26. package/declarations/instructions/referralClaimFees.d.ts +1 -1
  27. package/declarations/instructions/refreshOraclePrice.d.ts +1 -1
  28. package/declarations/instructions/repayVault.d.ts +1 -2
  29. package/declarations/instructions/setHalted.d.ts +1 -1
  30. package/declarations/instructions/transferVault.d.ts +1 -1
  31. package/declarations/instructions/updateReferralAccount.d.ts +1 -2
  32. package/declarations/instructions/updateReferralState.d.ts +1 -2
  33. package/declarations/instructions/updateVaultType.d.ts +1 -2
  34. package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
  35. package/declarations/instructions/withdrawVault.d.ts +1 -2
  36. package/declarations/state/VaultAccount.d.ts +2 -3
  37. package/declarations/utils/getLinkedListAccounts.d.ts +1 -2
  38. package/lib/Constants.js +27 -54
  39. package/lib/HedgeConstants.js +170 -0
  40. package/lib/HedgeDecimal.js +1 -2
  41. package/lib/StakingPools.js +5 -1
  42. package/lib/Vaults.js +5 -1
  43. package/lib/idl/vault.js +1 -842
  44. package/lib/index.js +6 -13
  45. package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
  46. package/lib/instructions/claimStakingPoolPosition.js +7 -8
  47. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
  48. package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
  49. package/lib/instructions/createReferralAccount.js +10 -11
  50. package/lib/instructions/createStakingPool.js +10 -11
  51. package/lib/instructions/createUserReferralAccount.js +9 -10
  52. package/lib/instructions/createVault.js +20 -21
  53. package/lib/instructions/depositLiquidationPool.js +12 -13
  54. package/lib/instructions/depositStakingPool.js +8 -9
  55. package/lib/instructions/depositVault.js +10 -11
  56. package/lib/instructions/initHedgeFoundation.js +10 -11
  57. package/lib/instructions/initHedgeFoundationTokens.js +7 -8
  58. package/lib/instructions/liquidateVault.js +12 -19
  59. package/lib/instructions/loanVault.js +16 -23
  60. package/lib/instructions/psmEditAccount.js +11 -11
  61. package/lib/instructions/psmMintUsh.js +18 -19
  62. package/lib/instructions/psmRedeemUsh.js +18 -19
  63. package/lib/instructions/redeemVault.js +10 -11
  64. package/lib/instructions/referralClaimFees.js +9 -10
  65. package/lib/instructions/refreshOraclePrice.js +9 -9
  66. package/lib/instructions/repayVault.js +12 -13
  67. package/lib/instructions/setHalted.js +4 -5
  68. package/lib/instructions/transferVault.js +2 -3
  69. package/lib/instructions/updateReferralAccount.js +6 -7
  70. package/lib/instructions/updateReferralState.js +6 -7
  71. package/lib/instructions/updateVaultType.js +5 -6
  72. package/lib/instructions/withdrawStakingPool.js +14 -15
  73. package/lib/instructions/withdrawVault.js +8 -9
  74. package/lib/state/VaultAccount.js +22 -8
  75. package/lib/state/VaultHistoryEvent.js +2 -2
  76. package/lib/utils/Errors.js +2 -3
  77. package/lib/utils/getLinkedListAccounts.js +2 -3
  78. package/lib/utils/sendAndConfirmWithDebug.js +1 -1
  79. package/package.json +9 -8
  80. package/src/{Constants.ts → HedgeConstants.ts} +13 -43
  81. package/src/idl/vault.ts +2342 -4024
  82. package/src/index.ts +3 -12
  83. package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
  84. package/src/instructions/claimStakingPoolPosition.ts +2 -2
  85. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
  86. package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
  87. package/src/instructions/createReferralAccount.ts +11 -8
  88. package/src/instructions/createStakingPool.ts +11 -4
  89. package/src/instructions/createUserReferralAccount.ts +2 -2
  90. package/src/instructions/createVault.ts +2 -2
  91. package/src/instructions/depositLiquidationPool.ts +2 -2
  92. package/src/instructions/depositStakingPool.ts +2 -2
  93. package/src/instructions/depositVault.ts +2 -2
  94. package/src/instructions/initHedgeFoundation.ts +2 -2
  95. package/src/instructions/initHedgeFoundationTokens.ts +2 -2
  96. package/src/instructions/liquidateVault.ts +29 -39
  97. package/src/instructions/loanVault.ts +23 -36
  98. package/src/instructions/psmEditAccount.ts +3 -3
  99. package/src/instructions/psmMintUsh.ts +3 -3
  100. package/src/instructions/psmRedeemUsh.ts +3 -3
  101. package/src/instructions/redeemVault.ts +2 -2
  102. package/src/instructions/referralClaimFees.ts +11 -9
  103. package/src/instructions/refreshOraclePrice.ts +4 -4
  104. package/src/instructions/repayVault.ts +2 -2
  105. package/src/instructions/setHalted.ts +2 -2
  106. package/src/instructions/transferVault.ts +1 -1
  107. package/src/instructions/updateReferralAccount.ts +2 -2
  108. package/src/instructions/updateReferralState.ts +2 -2
  109. package/src/instructions/updateVaultType.ts +2 -2
  110. package/src/instructions/withdrawStakingPool.ts +2 -2
  111. package/src/instructions/withdrawVault.ts +2 -2
  112. package/src/utils/Errors.ts +1 -1
  113. package/src/utils/getLinkedListAccounts.ts +1 -1
  114. package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
  115. package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
  116. package/declarations/instructions/compoundCreateReferralAccount.d.ts +0 -17
  117. package/declarations/instructions/compoundReferralClaimFees.d.ts +0 -16
  118. package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
  119. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
  120. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
  121. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
  122. package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
  123. package/declarations/instructions/setDelegateWallet.d.ts +0 -5
  124. package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
  125. package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
  126. package/declarations/utils/Sender.d.ts +0 -2
  127. package/lib/instructions/adminWithdrawCol.js +0 -60
  128. package/lib/instructions/adminWithdrawUsh.js +0 -57
  129. package/lib/instructions/compoundCreateReferralAccount.js +0 -83
  130. package/lib/instructions/compoundReferralClaimFees.js +0 -87
  131. package/lib/instructions/createCompoundStakingPool.js +0 -58
  132. package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
  133. package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
  134. package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
  135. package/lib/instructions/setCompoundPoolActive.js +0 -43
  136. package/lib/instructions/setDelegateWallet.js +0 -43
  137. package/lib/instructions/setVaultTypeStatus.js +0 -38
  138. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
  139. package/lib/utils/Sender.js +0 -32
  140. package/src/instructions/adminWithdrawCol.ts +0 -87
  141. package/src/instructions/adminWithdrawUsh.ts +0 -78
  142. package/src/instructions/compoundCreateReferralAccount.ts +0 -119
  143. package/src/instructions/compoundReferralClaimFees.ts +0 -151
  144. package/src/instructions/createCompoundStakingPool.ts +0 -63
  145. package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
  146. package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
  147. package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
  148. package/src/instructions/setCompoundPoolActive.ts +0 -51
  149. package/src/instructions/setDelegateWallet.ts +0 -51
  150. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
@@ -1,151 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor'
2
- import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import {
5
- getCompoundPoolPublicKeyForMint,
6
- getHedgeMintPublicKey,
7
- getPoolPublicKeyForMint,
8
- getReferralAccountPublicKey,
9
- getReferralStatePublicKey,
10
- getUshMintPublicKey,
11
- getVaultSystemStatePublicKey,
12
- } from '../Constants'
13
-
14
- import { Vault } from '../idl/vault'
15
- import { parseAnchorErrors } from '../utils/Errors'
16
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
17
-
18
- /** @type {Function} - Allows a referrer to claims their fees.
19
- * This checks the user has enough HDG in their wallet or staked and
20
- * then allows them to claim earned fees. If they meet the PSM referral threshold,
21
- * they will be eligible for PSM cut.
22
- * Params:
23
- * - program: Program<Vault> : The program instance of Hedge Vault program
24
- * - provider: Provider : Current connection
25
- * - payer: Signer : who we are creating the referral account for
26
- * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
27
- * - referrer: PublicKey
28
- */
29
- export async function compoundReferralClaimFees(
30
- program: Program<Vault>,
31
- provider: Provider,
32
- payer: Signer,
33
- poolPosition: PublicKey,
34
- stakedTokenMintPublicKey: PublicKey
35
- ): Promise<PublicKey> {
36
- // setup transaction
37
- const transaction = new Transaction()
38
- const signers = [payer]
39
-
40
- // General variables
41
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
42
-
43
- // Find referrer account
44
- const referrer = await payer.publicKey
45
- const referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
46
-
47
- // Derive the user referral account public key
48
- const referallStatePublicKey = await getReferralStatePublicKey(program.programId)
49
-
50
- const hedgeMintPublicKey = await getHedgeMintPublicKey(program.programId)
51
-
52
- // Get HDG account of signer
53
- const payerHdgAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
54
- provider.connection,
55
- payer,
56
- hedgeMintPublicKey,
57
- payer.publicKey
58
- )
59
-
60
- const ushMintPublicKey = await getUshMintPublicKey(program.programId)
61
-
62
- // Get USH account of signer
63
- const payerUshAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
64
- provider.connection,
65
- payer,
66
- ushMintPublicKey,
67
- payer.publicKey
68
- )
69
-
70
- // Get community_associated_hedge_token_account
71
- const communityAssociatedHedgeTokenAccount = await getOrCreateAssociatedTokenAccount(
72
- provider.connection,
73
- payer,
74
- hedgeMintPublicKey,
75
- vaultSystemStatePublicKey,
76
- true
77
- )
78
-
79
- const [feePoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublicKey)
80
-
81
- const feePoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
82
- provider.connection,
83
- payer,
84
- ushMintPublicKey,
85
- feePoolPublicKey,
86
- true
87
- )
88
- transaction.add(
89
- await compoundReferralClaimFeesInstruction(
90
- program,
91
- payer.publicKey,
92
- vaultSystemStatePublicKey,
93
- poolPosition,
94
- stakedTokenMintPublicKey,
95
- referralAccountPublicKey,
96
- referallStatePublicKey,
97
- hedgeMintPublicKey,
98
- payerHdgAssociatedTokenAccount.address,
99
- ushMintPublicKey,
100
- payerUshAssociatedTokenAccount.address,
101
- communityAssociatedHedgeTokenAccount.address,
102
- feePoolPublicKey,
103
- feePoolAssociatedUshTokenAccount.address
104
- )
105
- )
106
-
107
- await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
108
- return referralAccountPublicKey
109
- }
110
-
111
- export async function compoundReferralClaimFeesInstruction(
112
- program: Program<Vault>,
113
- payerPublicKey: PublicKey,
114
- vaultSystemStatePublicKey: PublicKey,
115
- poolPositionPublicKey: PublicKey,
116
- stakedTokenMintPublicKey: PublicKey,
117
- referralAccountPublicKey: PublicKey,
118
- referralStatePublicKey: PublicKey,
119
- hedgeMintPublicKey: PublicKey,
120
- hdgAssociatedTokenAccountPublicKey: PublicKey,
121
- ushMintPublicKey: PublicKey,
122
- ushAssociatedTokenAccountPublicKey: PublicKey,
123
- communityAssociatedHedgeTokenAccountPublicKey: PublicKey,
124
- feePoolPublicKey: PublicKey,
125
- feePoolAssociatedUshTokenAccountPublicKey: PublicKey
126
- ): Promise<TransactionInstruction> {
127
- const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
128
-
129
- return await program.methods
130
- .compoundReferralClaimFees()
131
- .accounts({
132
- signer: payerPublicKey,
133
- vaultSystemState: vaultSystemStatePublicKey,
134
- referralState: referralStatePublicKey,
135
- referralAccount: referralAccountPublicKey,
136
- poolPosition: poolPositionPublicKey,
137
- hedgeMint: hedgeMintPublicKey,
138
- signerHdgAta: hdgAssociatedTokenAccountPublicKey,
139
- ushMint: ushMintPublicKey,
140
- signerUshAta: ushAssociatedTokenAccountPublicKey,
141
- communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccountPublicKey,
142
- pool: poolPublickey,
143
- stakedTokenMint: stakedTokenMintPublicKey,
144
- feePool: feePoolPublicKey,
145
- feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccountPublicKey,
146
- systemProgram: SystemProgram.programId,
147
- tokenProgram: TOKEN_PROGRAM_ID,
148
- rent: SYSVAR_RENT_PUBKEY,
149
- })
150
- .instruction()
151
- }
@@ -1,63 +0,0 @@
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
- }
@@ -1,85 +0,0 @@
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,78 +0,0 @@
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
- }
@@ -1,110 +0,0 @@
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,51 +0,0 @@
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
- }
@@ -1,51 +0,0 @@
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
- }
@@ -1,100 +0,0 @@
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
- }