hedge-web3 0.2.33 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) 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 +278 -1259
  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/declarations/utils/sendAndConfirmWithDebug.d.ts +2 -2
  39. package/lib/Constants.js +14 -41
  40. package/lib/HedgeConstants.js +170 -0
  41. package/lib/HedgeDecimal.js +1 -2
  42. package/lib/StakingPools.js +5 -1
  43. package/lib/Vaults.js +5 -1
  44. package/lib/idl/vault.js +277 -1258
  45. package/lib/index.js +6 -13
  46. package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
  47. package/lib/instructions/claimStakingPoolPosition.js +7 -8
  48. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
  49. package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
  50. package/lib/instructions/createReferralAccount.js +10 -11
  51. package/lib/instructions/createStakingPool.js +10 -11
  52. package/lib/instructions/createUserReferralAccount.js +9 -10
  53. package/lib/instructions/createVault.js +35 -50
  54. package/lib/instructions/depositLiquidationPool.js +12 -13
  55. package/lib/instructions/depositStakingPool.js +8 -9
  56. package/lib/instructions/depositVault.js +15 -26
  57. package/lib/instructions/initHedgeFoundation.js +24 -13
  58. package/lib/instructions/initHedgeFoundationTokens.js +7 -8
  59. package/lib/instructions/liquidateVault.js +12 -19
  60. package/lib/instructions/loanVault.js +17 -24
  61. package/lib/instructions/psmEditAccount.js +11 -11
  62. package/lib/instructions/psmMintUsh.js +18 -19
  63. package/lib/instructions/psmRedeemUsh.js +18 -19
  64. package/lib/instructions/redeemVault.js +10 -12
  65. package/lib/instructions/referralClaimFees.js +9 -10
  66. package/lib/instructions/refreshOraclePrice.js +10 -10
  67. package/lib/instructions/repayVault.js +12 -13
  68. package/lib/instructions/setHalted.js +4 -5
  69. package/lib/instructions/transferVault.js +2 -3
  70. package/lib/instructions/updateReferralAccount.js +6 -7
  71. package/lib/instructions/updateReferralState.js +6 -7
  72. package/lib/instructions/updateVaultType.js +5 -6
  73. package/lib/instructions/withdrawStakingPool.js +14 -15
  74. package/lib/instructions/withdrawVault.js +10 -11
  75. package/lib/state/VaultAccount.js +23 -9
  76. package/lib/state/VaultHistoryEvent.js +2 -2
  77. package/lib/utils/Errors.js +2 -3
  78. package/lib/utils/getLinkedListAccounts.js +2 -3
  79. package/lib/utils/sendAndConfirmWithDebug.js +50 -14
  80. package/package.json +9 -8
  81. package/src/{Constants.ts → HedgeConstants.ts} +13 -43
  82. package/src/idl/vault.ts +2004 -3966
  83. package/src/index.ts +3 -12
  84. package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
  85. package/src/instructions/claimStakingPoolPosition.ts +2 -2
  86. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
  87. package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
  88. package/src/instructions/createReferralAccount.ts +11 -8
  89. package/src/instructions/createStakingPool.ts +11 -4
  90. package/src/instructions/createUserReferralAccount.ts +2 -2
  91. package/src/instructions/createVault.ts +26 -37
  92. package/src/instructions/depositLiquidationPool.ts +2 -2
  93. package/src/instructions/depositStakingPool.ts +2 -2
  94. package/src/instructions/depositVault.ts +24 -18
  95. package/src/instructions/initHedgeFoundation.ts +19 -4
  96. package/src/instructions/initHedgeFoundationTokens.ts +2 -2
  97. package/src/instructions/liquidateVault.ts +29 -39
  98. package/src/instructions/loanVault.ts +24 -37
  99. package/src/instructions/psmEditAccount.ts +3 -3
  100. package/src/instructions/psmMintUsh.ts +3 -3
  101. package/src/instructions/psmRedeemUsh.ts +3 -3
  102. package/src/instructions/redeemVault.ts +2 -3
  103. package/src/instructions/referralClaimFees.ts +11 -9
  104. package/src/instructions/refreshOraclePrice.ts +5 -5
  105. package/src/instructions/repayVault.ts +2 -2
  106. package/src/instructions/setHalted.ts +2 -2
  107. package/src/instructions/transferVault.ts +1 -1
  108. package/src/instructions/updateReferralAccount.ts +2 -2
  109. package/src/instructions/updateReferralState.ts +2 -2
  110. package/src/instructions/updateVaultType.ts +2 -2
  111. package/src/instructions/withdrawStakingPool.ts +2 -2
  112. package/src/instructions/withdrawVault.ts +4 -4
  113. package/src/state/VaultAccount.ts +1 -1
  114. package/src/utils/Errors.ts +1 -1
  115. package/src/utils/getLinkedListAccounts.ts +1 -1
  116. package/src/utils/sendAndConfirmWithDebug.ts +72 -23
  117. package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
  118. package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
  119. package/declarations/instructions/compoundCreateReferralAccount.d.ts +0 -17
  120. package/declarations/instructions/compoundReferralClaimFees.d.ts +0 -16
  121. package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
  122. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
  123. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
  124. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
  125. package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
  126. package/declarations/instructions/setDelegateWallet.d.ts +0 -5
  127. package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
  128. package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
  129. package/declarations/utils/Sender.d.ts +0 -2
  130. package/lib/instructions/adminWithdrawCol.js +0 -60
  131. package/lib/instructions/adminWithdrawUsh.js +0 -57
  132. package/lib/instructions/compoundCreateReferralAccount.js +0 -83
  133. package/lib/instructions/compoundReferralClaimFees.js +0 -87
  134. package/lib/instructions/createCompoundStakingPool.js +0 -58
  135. package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
  136. package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
  137. package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
  138. package/lib/instructions/setCompoundPoolActive.js +0 -43
  139. package/lib/instructions/setDelegateWallet.js +0 -43
  140. package/lib/instructions/setVaultTypeStatus.js +0 -38
  141. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
  142. package/lib/utils/Sender.js +0 -32
  143. package/src/instructions/adminWithdrawCol.ts +0 -87
  144. package/src/instructions/adminWithdrawUsh.ts +0 -78
  145. package/src/instructions/compoundCreateReferralAccount.ts +0 -119
  146. package/src/instructions/compoundReferralClaimFees.ts +0 -151
  147. package/src/instructions/createCompoundStakingPool.ts +0 -63
  148. package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
  149. package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
  150. package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
  151. package/src/instructions/setCompoundPoolActive.ts +0 -51
  152. package/src/instructions/setDelegateWallet.ts +0 -51
  153. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
@@ -1,24 +1,18 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- ComputeBudgetProgram,
5
4
  Keypair,
6
- PublicKey,
7
- Signer,
5
+ PublicKey, Signer,
8
6
  SystemProgram,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
10
  import {
13
11
  findAssociatedTokenAddress,
14
12
  getHedgeMintPublicKey,
15
- getPoolPublicKeyForMint,
16
- getReferralAccountPublicKey,
17
- getReferralStatePublicKey,
18
- getUserReferralAccountPublicKey,
19
- getUshMintPublicKey,
20
- getVaultSystemStatePublicKey,
21
- } from '../Constants'
13
+ getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
14
+ getVaultSystemStatePublicKey
15
+ } from '../HedgeConstants'
22
16
  import { Vault } from '../idl/vault'
23
17
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
24
18
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -32,11 +26,6 @@ export async function loanVault(
32
26
  overrideTime?: number,
33
27
  referrer?: PublicKey
34
28
  ): Promise<PublicKey> {
35
- const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
36
- units: 300000,
37
- additionalFee: 0,
38
- })
39
-
40
29
  const ushMintPublickey = await getUshMintPublicKey(program.programId)
41
30
 
42
31
  const payerUshAccount = await getOrCreateAssociatedTokenAccount(
@@ -83,27 +72,25 @@ export async function loanVault(
83
72
  }
84
73
 
85
74
  const history = Keypair.generate()
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
- )
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
105
91
  )
106
- await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
92
+ )
93
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history], 300000)
107
94
  return vaultPublicKey
108
95
  }
109
96
 
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
3
3
  import {
4
4
  PublicKey, Signer,
@@ -11,7 +11,7 @@ import {
11
11
  getPoolPublicKeyForMint,
12
12
  getUshMintPublicKey,
13
13
  getVaultSystemStatePublicKey
14
- } from '../Constants'
14
+ } from '../HedgeConstants'
15
15
  import { Vault } from '../idl/vault'
16
16
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
17
17
 
@@ -51,7 +51,7 @@ export async function psmEditAccount(
51
51
 
52
52
 
53
53
  const enc = new TextEncoder()
54
- const [psmAccount] = await PublicKey.findProgramAddress(
54
+ const [psmAccount] = await PublicKey.findProgramAddressSync(
55
55
  [enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
56
56
  program.programId
57
57
  )
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  PublicKey, Signer,
@@ -14,7 +14,7 @@ import {
14
14
  getReferralStatePublicKey,
15
15
  getUshMintPublicKey,
16
16
  getVaultSystemStatePublicKey
17
- } from '../Constants'
17
+ } from '../HedgeConstants'
18
18
  import { Vault } from '../idl/vault'
19
19
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
20
 
@@ -44,7 +44,7 @@ export async function psmMintUsh(
44
44
  )
45
45
 
46
46
  const enc = new TextEncoder()
47
- const [psmAccount] = await PublicKey.findProgramAddress(
47
+ const [psmAccount] = await PublicKey.findProgramAddressSync(
48
48
  [enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
49
49
  program.programId
50
50
  )
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  PublicKey, Signer,
@@ -12,7 +12,7 @@ import {
12
12
  getPoolPublicKeyForMint, getReferralAccountPublicKey,
13
13
  getReferralStatePublicKey, getUshMintPublicKey,
14
14
  getVaultSystemStatePublicKey
15
- } from '../Constants'
15
+ } from '../HedgeConstants'
16
16
  import { Vault } from '../idl/vault'
17
17
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
18
18
 
@@ -42,7 +42,7 @@ export async function psmRedeemUsh(
42
42
  )
43
43
 
44
44
  const enc = new TextEncoder()
45
- const [psmAccount] = await PublicKey.findProgramAddress(
45
+ const [psmAccount] = await PublicKey.findProgramAddressSync(
46
46
  [enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
47
47
  program.programId
48
48
  )
@@ -1,6 +1,5 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- // import { TokenInstructions } from '@project-serum/serum'
4
3
  import {
5
4
  Keypair,
6
5
  PublicKey, Signer,
@@ -13,7 +12,7 @@ import {
13
12
  getHedgeMintPublicKey,
14
13
  getPoolPublicKeyForMint, getUshMintPublicKey,
15
14
  getVaultSystemStatePublicKey
16
- } from '../Constants'
15
+ } from '../HedgeConstants'
17
16
  import { Vault } from '../idl/vault'
18
17
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
19
18
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -1,14 +1,16 @@
1
- import { Program, Provider } from '@project-serum/anchor'
1
+ import { Program, Provider } from '@coral-xyz/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'
4
3
  import {
5
- getHedgeMintPublicKey,
6
- getPoolPublicKeyForMint,
7
- getReferralAccountPublicKey,
8
- getReferralStatePublicKey,
9
- getUshMintPublicKey,
10
- getVaultSystemStatePublicKey,
11
- } from '../Constants'
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
13
+ } from '../HedgeConstants'
12
14
 
13
15
  import { Vault } from '../idl/vault'
14
16
  import { parseAnchorErrors } from '../utils/Errors'
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import {
3
3
  LAMPORTS_PER_SOL,
4
4
  PublicKey, Signer,
@@ -7,7 +7,7 @@ import {
7
7
  TransactionInstruction,
8
8
  TransactionSignature
9
9
  } from '@solana/web3.js'
10
- import { CHAINLINK_PROGRAM_ID } from '../Constants'
10
+ import { CHAINLINK_PROGRAM_ID } from '../HedgeConstants'
11
11
  import { Vault } from '../idl/vault'
12
12
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
13
 
@@ -23,7 +23,7 @@ export async function refreshOraclePrice(
23
23
  const transaction = new Transaction().add(
24
24
  await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime)
25
25
  )
26
- return await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
26
+ return await sendAndConfirmWithDebug(provider.connection, transaction, [payer], 800000)
27
27
  }
28
28
 
29
29
  export async function refreshOraclePriceInstruction(
@@ -34,11 +34,11 @@ export async function refreshOraclePriceInstruction(
34
34
  overrideTime?: number
35
35
  ): Promise<TransactionInstruction> {
36
36
  const enc = new TextEncoder()
37
- const [oracleInfoAccount] = await PublicKey.findProgramAddress(
37
+ const [oracleInfoAccount] = await PublicKey.findProgramAddressSync(
38
38
  [enc.encode(collateralType), enc.encode('Oracle')],
39
39
  program.programId
40
40
  )
41
- const [vaultTypeAccount] = await PublicKey.findProgramAddress(
41
+ const [vaultTypeAccount] = await PublicKey.findProgramAddressSync(
42
42
  [enc.encode(collateralType), enc.encode('State')],
43
43
  program.programId
44
44
  )
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
@@ -12,7 +12,7 @@ import {
12
12
  getHedgeMintPublicKey,
13
13
  getPoolPublicKeyForMint, getUshMintPublicKey,
14
14
  getVaultSystemStatePublicKey
15
- } from '../Constants'
15
+ } from '../HedgeConstants'
16
16
  import { Vault } from '../idl/vault'
17
17
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
18
18
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -1,6 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor'
1
+ import { Program, Provider } from '@coral-xyz/anchor'
2
2
  import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
3
- import { getVaultSystemStatePublicKey } from '../Constants'
3
+ import { getVaultSystemStatePublicKey } from '../HedgeConstants'
4
4
 
5
5
  import { Vault } from '../idl/vault'
6
6
  import { parseAnchorErrors } from '../utils/Errors'
@@ -1,4 +1,4 @@
1
- import { Program, Provider } from '@project-serum/anchor'
1
+ import { Program, Provider } from '@coral-xyz/anchor'
2
2
  import {
3
3
  Keypair,
4
4
  PublicKey, Signer, Transaction,
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import {
3
3
  PublicKey, Signer,
4
4
  SystemProgram, Transaction,
@@ -6,7 +6,7 @@ import {
6
6
  } from '@solana/web3.js'
7
7
  import {
8
8
  getReferralAccountPublicKey, getVaultSystemStatePublicKey
9
- } from '../Constants'
9
+ } from '../HedgeConstants'
10
10
 
11
11
  import { Vault } from '../idl/vault'
12
12
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import {
3
3
  PublicKey, Signer,
4
4
  SystemProgram, Transaction,
@@ -6,7 +6,7 @@ import {
6
6
  } from '@solana/web3.js'
7
7
  import {
8
8
  getReferralStatePublicKey, getVaultSystemStatePublicKey
9
- } from '../Constants'
9
+ } from '../HedgeConstants'
10
10
 
11
11
  import { Vault } from '../idl/vault'
12
12
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -1,11 +1,11 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import {
3
3
  PublicKey, Signer, Transaction,
4
4
  TransactionInstruction
5
5
  } from '@solana/web3.js'
6
6
  import {
7
7
  getVaultSystemStatePublicKey
8
- } from '../Constants'
8
+ } from '../HedgeConstants'
9
9
 
10
10
  import { Vault } from '../idl/vault'
11
11
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -1,4 +1,4 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
2
2
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
@@ -12,7 +12,7 @@ import {
12
12
  getPoolPublicKeyForMint,
13
13
  getUshMintPublicKey,
14
14
  getVaultSystemStatePublicKey
15
- } from '../Constants'
15
+ } from '../HedgeConstants'
16
16
  import { Vault } from '../idl/vault'
17
17
  import { parseAnchorErrors } from '../utils/Errors'
18
18
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -1,6 +1,6 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { TokenInstructions } from '@project-serum/serum'
1
+ import { BN, Program, Provider } from '@coral-xyz/anchor'
3
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
+ import { NATIVE_MINT } from '@solana/spl-token'
4
4
  import {
5
5
  Keypair,
6
6
  PublicKey, Signer,
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
13
13
  getVaultSystemStatePublicKey
14
- } from '../Constants'
14
+ } from '../HedgeConstants'
15
15
  import { Vault } from '../idl/vault'
16
16
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
17
17
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
@@ -35,7 +35,7 @@ export async function withdrawVault(
35
35
  const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
36
36
  provider.connection,
37
37
  payer,
38
- TokenInstructions.WRAPPED_SOL_MINT,
38
+ NATIVE_MINT,
39
39
  vaultPublicKey,
40
40
  true
41
41
  )
@@ -2,7 +2,7 @@ import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
2
2
  import Decimal from 'decimal.js'
3
3
  import { DecimalFromU128 } from '../HedgeDecimal'
4
4
 
5
- import * as borsh from '@project-serum/borsh'
5
+ import * as borsh from '@coral-xyz/borsh'
6
6
  import BN from 'bn.js'
7
7
  import VaultType from './VaultType'
8
8
 
@@ -1,4 +1,4 @@
1
- import { parseIdlErrors, ProgramError } from '@project-serum/anchor'
1
+ import { parseIdlErrors, ProgramError } from '@coral-xyz/anchor'
2
2
  import { IDL } from '../idl/vault'
3
3
 
4
4
  export function parseAnchorErrors (error: any): void {
@@ -1,4 +1,4 @@
1
- import { BN, Program } from '@project-serum/anchor'
1
+ import { BN, Program } from '@coral-xyz/anchor'
2
2
  import { PublicKey } from '@solana/web3.js'
3
3
  import _ from 'underscore'
4
4
 
@@ -1,27 +1,76 @@
1
- import { Connection, Keypair, Signer, Transaction, TransactionSignature } from '@solana/web3.js'
1
+ import {
2
+ Connection,
3
+ Signer,
4
+ Transaction,
5
+ TransactionSignature,
6
+ VersionedTransaction,
7
+ ComputeBudgetProgram,
8
+ Keypair,
9
+ LAMPORTS_PER_SOL
10
+ } from '@solana/web3.js'
2
11
 
3
12
  export default async function sendAndConfirmWithDebug(
4
13
  connection: Connection,
5
- transaction: Transaction,
6
- signers: Signer[]
14
+ transaction: Transaction | VersionedTransaction,
15
+ signers: Signer[],
16
+ computeUnits?: number
7
17
  ): Promise<TransactionSignature | void> {
8
- return connection
9
- .sendTransaction(transaction, signers)
10
- .then((signature) => {
11
- return connection
12
- .confirmTransaction(signature)
13
- .then((signatureContext) => {
14
- return signature
15
- })
16
- .catch((error) => {
17
- console.log('There was an error confirming the transaction', error)
18
- console.trace()
19
- throw error
20
- })
21
- })
22
- .catch((error) => {
23
- console.log('There was an error sending the transaction', error)
24
- console.trace()
25
- throw error
26
- })
27
- }
18
+ try {
19
+ // Get the latest blockhash before sending
20
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
21
+
22
+ // Set blockhash AND feePayer BEFORE converting to VersionedTransaction
23
+ if (transaction instanceof Transaction) {
24
+ // Add compute unit instruction FIRST if requested
25
+ if (computeUnits) {
26
+ const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnits });
27
+ transaction.instructions.unshift(computeIx);
28
+ }
29
+ transaction.recentBlockhash = blockhash;
30
+ // Ensure feePayer is explicitly set on legacy transaction
31
+ if (!transaction.feePayer) {
32
+ transaction.feePayer = signers[0].publicKey;
33
+ }
34
+ } else if (computeUnits) {
35
+ throw new Error('Compute units must be added before creating VersionedTransaction');
36
+ }
37
+
38
+ // Convert legacy Transaction to VersionedTransaction if needed
39
+ const versionedTx = transaction instanceof Transaction
40
+ ? new VersionedTransaction(transaction.compileMessage())
41
+ : transaction;
42
+
43
+ // For VersionedTransaction, verify blockhash is set
44
+ if (!(transaction instanceof Transaction) && !versionedTx.message.recentBlockhash) {
45
+ throw new Error('Versioned transaction requires recent blockhash');
46
+ }
47
+
48
+ // Sign the transaction if signers are provided
49
+ if (signers.length > 0) {
50
+ versionedTx.sign(signers);
51
+ }
52
+
53
+ // Send the transaction
54
+ const signature = await connection.sendTransaction(versionedTx);
55
+
56
+ // Confirm using the newer confirmation strategy
57
+ const confirmationStrategy = {
58
+ signature,
59
+ blockhash,
60
+ lastValidBlockHeight
61
+ };
62
+
63
+ try {
64
+ await connection.confirmTransaction(confirmationStrategy);
65
+ return signature;
66
+ } catch (error) {
67
+ console.log('There was an error confirming the transaction', error);
68
+ console.trace();
69
+ throw error;
70
+ }
71
+ } catch (error) {
72
+ console.log('There was an error sending the transaction', error);
73
+ console.trace();
74
+ throw error;
75
+ }
76
+ }
@@ -1,5 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- export declare function adminWithdrawCollateral(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, collateralType: string): Promise<PublicKey>;
5
- export declare function adminWithdrawCollateralInstruction(program: Program<Vault>, payerPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
@@ -1,5 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- export declare function adminWithdrawUsh(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey): Promise<PublicKey>;
5
- export declare function adminWithdrawUshInstruction(program: Program<Vault>, payerPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, poolPublickey: PublicKey): Promise<TransactionInstruction>;
@@ -1,17 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- /** @type {Function} - Creates a new referral account.
5
- * This checks the user has enough HDG in their wallet or staked and
6
- * then allows them to create a referral account. If they meet the PSM referral threshold,
7
- * they will be eligible for PSM cut.
8
- * Params:
9
- * - program: Program<Vault> : The program instance of Hedge Vault program
10
- * - provider: Provider : Current connection
11
- * - payer: Signer : who we are creating the referral account for
12
- * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
13
- * - referrer: PublicKey
14
- * - overrideTime?: number
15
- */
16
- export declare function compoundCreateReferralAccount(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, stakedTokenMintPublicKey: PublicKey, overrideTime?: number): Promise<PublicKey>;
17
- export declare function compoundCreateReferralAccountInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, userReferralAccountPublicKey: PublicKey, overrideTime?: number): Promise<TransactionInstruction>;
@@ -1,16 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- /** @type {Function} - Allows a referrer to claims their fees.
5
- * This checks the user has enough HDG in their wallet or staked and
6
- * then allows them to claim earned fees. If they meet the PSM referral threshold,
7
- * they will be eligible for PSM cut.
8
- * Params:
9
- * - program: Program<Vault> : The program instance of Hedge Vault program
10
- * - provider: Provider : Current connection
11
- * - payer: Signer : who we are creating the referral account for
12
- * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
13
- * - referrer: PublicKey
14
- */
15
- export declare function compoundReferralClaimFees(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, stakedTokenMintPublicKey: PublicKey): Promise<PublicKey>;
16
- export declare function compoundReferralClaimFeesInstruction(program: Program<Vault>, payerPublicKey: PublicKey, vaultSystemStatePublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, ushMintPublicKey: PublicKey, ushAssociatedTokenAccountPublicKey: PublicKey, communityAssociatedHedgeTokenAccountPublicKey: PublicKey, feePoolPublicKey: PublicKey, feePoolAssociatedUshTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
@@ -1,5 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- export declare function createCompoundStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, overrideStartTime?: number): Promise<PublicKey>;
5
- export declare function createCompoundStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, mintPublicKey: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,6 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BN, Program, Provider } from '@project-serum/anchor';
3
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
- import { Vault } from '../idl/vault';
5
- export declare function createCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
- export declare function createCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,6 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BN, Program, Provider } from '@project-serum/anchor';
3
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
- import { Vault } from '../idl/vault';
5
- export declare function depositCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
- export declare function depositCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,6 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BN, Program, Provider } from '@project-serum/anchor';
3
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
- import { Vault } from '../idl/vault';
5
- export declare function depositRewardsToCompoundStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
- export declare function depositRewardsToCompoundStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, mintPublicKey: PublicKey, historyPublicKey: PublicKey, amount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- export declare function setCompoundPoolActive(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, setActive: boolean): Promise<PublicKey>;
5
- export declare function setCompoundPoolActiveInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, poolPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, setActive: boolean): Promise<TransactionInstruction>;
@@ -1,5 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from '../idl/vault';
4
- export declare function setDelegateWallet(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, delegateWallet: PublicKey): Promise<PublicKey>;
5
- export declare function setDelegateWalletInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, poolPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, delegateWallet: PublicKey): Promise<TransactionInstruction>;
@@ -1,4 +0,0 @@
1
- import { Program, Provider } from '@project-serum/anchor';
2
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- export declare function setVaultTypeStatus(program: Program, provider: Provider, payer: Signer, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<PublicKey>;
4
- export declare function setVaultTypeStatusInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<TransactionInstruction>;
@@ -1,6 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BN, Program, Provider } from '@project-serum/anchor';
3
- import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
- import { Vault } from '../idl/vault';
5
- export declare function withdrawCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, claimAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
- export declare function withdrawCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, claimAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,2 +0,0 @@
1
- import { Connection, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
2
- export declare function sendAndConfirmWithDebug(connection: Connection, transaction: Transaction, signers: Signer[]): Promise<TransactionSignature | void>;