hedge-web3 0.2.24 → 0.2.26

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 (73) hide show
  1. package/declarations/Constants.d.ts +13 -15
  2. package/declarations/idl/vault.d.ts +36 -0
  3. package/declarations/instructions/createReferralAccount.d.ts +1 -1
  4. package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
  5. package/declarations/instructions/referralClaimFees.d.ts +1 -1
  6. package/declarations/state/VaultAccount.d.ts +15 -2
  7. package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
  8. package/lib/Constants.js +28 -34
  9. package/lib/idl/vault.js +36 -0
  10. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  11. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  12. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  13. package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
  14. package/lib/instructions/createReferralAccount.js +8 -8
  15. package/lib/instructions/createStakingPool.js +7 -7
  16. package/lib/instructions/createUserReferralAccount.js +6 -6
  17. package/lib/instructions/createVault.js +16 -16
  18. package/lib/instructions/depositLiquidationPool.js +9 -9
  19. package/lib/instructions/depositStakingPool.js +5 -5
  20. package/lib/instructions/depositVault.js +11 -9
  21. package/lib/instructions/initHedgeFoundation.js +8 -8
  22. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  23. package/lib/instructions/liquidateVault.js +8 -8
  24. package/lib/instructions/loanVault.js +12 -12
  25. package/lib/instructions/psmEditAccount.js +5 -5
  26. package/lib/instructions/psmMintUsh.js +14 -14
  27. package/lib/instructions/psmRedeemUsh.js +14 -14
  28. package/lib/instructions/redeemVault.js +7 -7
  29. package/lib/instructions/referralClaimFees.js +8 -8
  30. package/lib/instructions/refreshOraclePrice.js +3 -3
  31. package/lib/instructions/repayVault.js +9 -9
  32. package/lib/instructions/setHalted.js +1 -1
  33. package/lib/instructions/updateReferralAccount.js +2 -2
  34. package/lib/instructions/updateReferralState.js +2 -2
  35. package/lib/instructions/updateVaultType.js +1 -1
  36. package/lib/instructions/withdrawStakingPool.js +11 -11
  37. package/lib/instructions/withdrawVault.js +5 -5
  38. package/lib/state/VaultAccount.js +16 -16
  39. package/lib/utils/getLinkedListAccounts.js +20 -4
  40. package/package.json +1 -1
  41. package/src/Constants.ts +44 -85
  42. package/src/idl/vault.ts +72 -0
  43. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  44. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  45. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  46. package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
  47. package/src/instructions/createReferralAccount.ts +17 -29
  48. package/src/instructions/createStakingPool.ts +11 -13
  49. package/src/instructions/createUserReferralAccount.ts +13 -24
  50. package/src/instructions/createVault.ts +44 -21
  51. package/src/instructions/depositLiquidationPool.ts +16 -23
  52. package/src/instructions/depositStakingPool.ts +18 -14
  53. package/src/instructions/depositVault.ts +23 -18
  54. package/src/instructions/initHedgeFoundation.ts +16 -14
  55. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  56. package/src/instructions/liquidateVault.ts +15 -20
  57. package/src/instructions/loanVault.ts +18 -27
  58. package/src/instructions/psmEditAccount.ts +10 -18
  59. package/src/instructions/psmMintUsh.ts +19 -41
  60. package/src/instructions/psmRedeemUsh.ts +21 -45
  61. package/src/instructions/redeemVault.ts +12 -15
  62. package/src/instructions/referralClaimFees.ts +17 -31
  63. package/src/instructions/refreshOraclePrice.ts +6 -8
  64. package/src/instructions/repayVault.ts +18 -16
  65. package/src/instructions/setHalted.ts +5 -24
  66. package/src/instructions/transferVault.ts +4 -9
  67. package/src/instructions/updateReferralAccount.ts +7 -14
  68. package/src/instructions/updateReferralState.ts +7 -14
  69. package/src/instructions/updateVaultType.ts +9 -23
  70. package/src/instructions/withdrawStakingPool.ts +17 -21
  71. package/src/instructions/withdrawVault.ts +10 -16
  72. package/src/state/VaultAccount.ts +31 -17
  73. package/src/utils/getLinkedListAccounts.ts +20 -7
@@ -1,27 +1,21 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
4
+ PublicKey, Signer,
7
5
  SystemProgram,
8
6
  SYSVAR_RENT_PUBKEY,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
10
  import {
14
11
  getHedgeMintPublicKey,
15
12
  getLiquidationPoolStatePublicKey,
16
- getLiquidationPoolUshAccountPublicKey,
17
- getUshMintPublicKey,
18
- getVaultSystemStatePublicKey,
19
- getReferralAccountPublicKey,
20
- getUserReferralAccountPublicKey,
21
- getReferralStatePublicKey
13
+ getLiquidationPoolUshAccountPublicKey, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
14
+ getVaultSystemStatePublicKey
22
15
  } from '../Constants'
23
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
16
  import { Vault } from '../idl/vault'
17
+ import { parseAnchorErrors } from '../utils/Errors'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
19
 
26
20
  export async function closeLiquidationPoolPosition(
27
21
  program: Program<Vault>,
@@ -31,19 +25,19 @@ export async function closeLiquidationPoolPosition(
31
25
  overrideStartTime?: number,
32
26
  referrer?: PublicKey
33
27
  ): Promise<PublicKey> {
34
- const ushMintPublickey = await getUshMintPublicKey()
28
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
35
29
  const payerUshAccount = await getOrCreateAssociatedTokenAccount(
36
30
  provider.connection,
37
31
  payer,
38
32
  ushMintPublickey,
39
33
  payer.publicKey
40
34
  )
41
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
42
- const referralStatePublicKey = await getReferralStatePublicKey()
35
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
36
+ const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
43
37
  const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition)
44
38
  const poolEra = liquidationPositionAccount.era
45
39
 
46
- const hedgeMint = await getHedgeMintPublicKey()
40
+ const hedgeMint = await getHedgeMintPublicKey(program.programId)
47
41
  const payerAssociatedHedgeAccount = await getOrCreateAssociatedTokenAccount(
48
42
  provider.connection,
49
43
  payer,
@@ -60,13 +54,13 @@ export async function closeLiquidationPoolPosition(
60
54
 
61
55
  let referralAccountPublicKey = null
62
56
  if (typeof referrer === 'undefined') {
63
- referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
57
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
64
58
  } else {
65
- referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
59
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
66
60
  }
67
61
 
68
62
  // Derive the user referral account public key
69
- const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payer.publicKey)
63
+ const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
70
64
 
71
65
  const transaction = new Transaction().add(
72
66
  await closeLiquidationPoolPositionInstruction(
@@ -100,11 +94,11 @@ export async function closeLiquidationPoolPositionInstruction(
100
94
  referralStatePublicKey: PublicKey,
101
95
  overrideStartTime?: number
102
96
  ): Promise<TransactionInstruction> {
103
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
104
- const ushMint = await getUshMintPublicKey()
105
- const hedgeMint = await getHedgeMintPublicKey()
106
- const poolUshAccount = await getLiquidationPoolUshAccountPublicKey()
107
- const poolState = await getLiquidationPoolStatePublicKey()
97
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
98
+ const ushMint = await getUshMintPublicKey(program.programId)
99
+ const hedgeMint = await getHedgeMintPublicKey(program.programId)
100
+ const poolUshAccount = await getLiquidationPoolUshAccountPublicKey(program.programId)
101
+ const poolState = await getLiquidationPoolStatePublicKey(program.programId)
108
102
 
109
103
  return await program.methods
110
104
  .closeLiquidationPoolPosition(
@@ -1,29 +1,20 @@
1
- import { BN, Idl, Program, Provider } from '@project-serum/anchor'
2
- import { TokenInstructions } from '@project-serum/serum'
3
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
3
  import {
5
- Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
4
+ PublicKey, Signer,
9
5
  SystemProgram,
10
6
  SYSVAR_RENT_PUBKEY,
11
7
  Transaction,
12
- TransactionInstruction,
8
+ TransactionInstruction
13
9
  } from '@solana/web3.js'
14
10
  import {
15
- getVaultSystemStatePublicKey,
16
- getReferralAccountPublicKey,
17
- getHedgeMintPublicKey,
18
- getReferralStatePublicKey,
19
- getUserReferralAccountPublicKey
11
+ getHedgeMintPublicKey, getReferralAccountPublicKey, getReferralStatePublicKey,
12
+ getUserReferralAccountPublicKey, getVaultSystemStatePublicKey
20
13
  } from '../Constants'
21
14
 
15
+ import { Vault } from '../idl/vault'
22
16
  import { parseAnchorErrors } from '../utils/Errors'
23
17
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
- import { Vault } from '../idl/vault'
25
-
26
-
27
18
 
28
19
  /** @type {Function} - Creates a new referral account.
29
20
  * This checks the user has enough HDG in their wallet or staked and
@@ -36,7 +27,7 @@ import { Vault } from '../idl/vault'
36
27
  * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
37
28
  * - referrer: PublicKey
38
29
  * - overrideTime?: number
39
- */
30
+ */
40
31
  export async function createReferralAccount(
41
32
  program: Program<Vault>,
42
33
  provider: Provider,
@@ -44,24 +35,23 @@ export async function createReferralAccount(
44
35
  poolPosition: PublicKey,
45
36
  overrideTime?: number
46
37
  ): Promise<PublicKey> {
47
- // setup transaction
38
+ // setup transaction
48
39
  const transaction = new Transaction()
49
40
  const signers = [payer]
50
41
  const referrer = payer.publicKey
51
42
 
52
43
  // Setup public keys
53
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
44
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
54
45
 
55
46
  // Find referral account
56
- let referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
57
-
47
+ let referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
58
48
 
59
49
  // Get the referral state PDA
60
- const referallStatePublicKey = await getReferralStatePublicKey()
50
+ const referallStatePublicKey = await getReferralStatePublicKey(program.programId)
61
51
 
62
52
  // Get HDG mint public key
63
- const hedgeMintPublicKey = await getHedgeMintPublicKey()
64
-
53
+ const hedgeMintPublicKey = await getHedgeMintPublicKey(program.programId)
54
+
65
55
  // Get HDG account of signer
66
56
  const payerHdgAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
67
57
  provider.connection,
@@ -71,8 +61,8 @@ export async function createReferralAccount(
71
61
  )
72
62
 
73
63
  // Derive the user referral account public key
74
- const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payer.publicKey)
75
-
64
+ const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
65
+
76
66
  transaction.add(
77
67
  await createReferralAccountInstruction(
78
68
  program,
@@ -87,12 +77,10 @@ export async function createReferralAccount(
87
77
  )
88
78
  )
89
79
 
90
-
91
80
  await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
92
81
  return referralAccountPublicKey
93
82
  }
94
83
 
95
-
96
84
  export async function createReferralAccountInstruction(
97
85
  program: Program<Vault>,
98
86
  payerPublicKey: PublicKey,
@@ -104,7 +92,7 @@ export async function createReferralAccountInstruction(
104
92
  userReferralAccountPublicKey: PublicKey,
105
93
  overrideTime?: number
106
94
  ): Promise<TransactionInstruction> {
107
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
95
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
108
96
 
109
97
  return await program.methods
110
98
  .createReferralAccount(
@@ -1,23 +1,21 @@
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
3
  import {
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
4
+ PublicKey, Signer,
7
5
  SystemProgram,
8
6
  SYSVAR_RENT_PUBKEY,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
10
  import {
14
11
  findAssociatedTokenAddress,
15
12
  getPoolPublicKeyForMint,
16
13
  getUshMintPublicKey,
17
- getVaultSystemStatePublicKey,
14
+ getVaultSystemStatePublicKey
18
15
  } from '../Constants'
19
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
16
  import { Vault } from '../idl/vault'
17
+ import { parseAnchorErrors } from '../utils/Errors'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
19
 
22
20
  export async function createStakingPool(
23
21
  program: Program<Vault>,
@@ -31,7 +29,7 @@ export async function createStakingPool(
31
29
  await createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime)
32
30
  )
33
31
  await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
34
- const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey)
32
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
35
33
  return poolPublickey
36
34
  }
37
35
 
@@ -42,12 +40,12 @@ export async function createStakingPoolInstruction(
42
40
  hedgeTokensToBeMinted: number,
43
41
  overrideStartTime?: number
44
42
  ): Promise<TransactionInstruction> {
45
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
46
- const ushMintPublickey = await getUshMintPublicKey()
47
- const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
43
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
44
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
45
+ const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
48
46
 
49
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey)
50
- const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
47
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, mintPublicKey)
48
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
51
49
  return await program.methods
52
50
  .createStakingPool(poolBump, new BN(hedgeTokensToBeMinted), new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)))
53
51
  .accounts({
@@ -1,26 +1,17 @@
1
- import { BN, Idl, Program, Provider } from '@project-serum/anchor'
2
- import { TokenInstructions } from '@project-serum/serum'
3
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
3
  import {
5
- Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
4
+ PublicKey, Signer,
9
5
  SystemProgram,
10
6
  SYSVAR_RENT_PUBKEY,
11
7
  Transaction,
12
- TransactionInstruction,
8
+ TransactionInstruction
13
9
  } from '@solana/web3.js'
14
- import {
15
- getVaultSystemStatePublicKey,
16
- getReferralAccountPublicKey,
17
- getUserReferralAccountPublicKey
18
- } from '../Constants'
10
+ import { getReferralAccountPublicKey, getUserReferralAccountPublicKey, getVaultSystemStatePublicKey } from '../Constants'
19
11
 
20
- import { v4 as uuidv4 } from 'uuid'
12
+ import { Vault } from '../idl/vault'
21
13
  import { parseAnchorErrors } from '../utils/Errors'
22
14
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
- import { Vault } from '../idl/vault'
24
15
 
25
16
  export async function createUserReferralAccount(
26
17
  program: Program<Vault>,
@@ -29,21 +20,21 @@ export async function createUserReferralAccount(
29
20
  referrer?: PublicKey,
30
21
  overrideTime?: number
31
22
  ): Promise<PublicKey> {
32
- // setup transaction
23
+ // setup transaction
33
24
  const transaction = new Transaction()
34
25
  const signers = [payer]
35
26
 
36
27
  // Find referrer account
37
28
  let referralAccountPublicKey = null
38
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
29
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
39
30
  if (typeof referrer === 'undefined') {
40
- referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
31
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
41
32
  } else {
42
- referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
33
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
43
34
  }
44
35
 
45
36
  // Derive the user referral account public key
46
- const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payer.publicKey)
37
+ const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
47
38
 
48
39
  transaction.add(
49
40
  await createUserReferralAccountInstruction(
@@ -55,12 +46,10 @@ export async function createUserReferralAccount(
55
46
  )
56
47
  )
57
48
 
58
-
59
49
  await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
60
50
  return userReferralAccountPublicKey
61
51
  }
62
52
 
63
-
64
53
  export async function createUserReferralAccountInstruction(
65
54
  program: Program<Vault>,
66
55
  payerPublicKey: PublicKey,
@@ -68,11 +57,11 @@ export async function createUserReferralAccountInstruction(
68
57
  userReferralAccount: PublicKey,
69
58
  overrideTime?: number
70
59
  ): Promise<TransactionInstruction> {
71
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
60
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
72
61
 
73
62
  return await program.methods
74
63
  .createUserReferralAccount(
75
- new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
64
+ new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
76
65
  )
77
66
  .accounts({
78
67
  signer: payerPublicKey,
@@ -1,10 +1,9 @@
1
- import { BN, Idl, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { TokenInstructions } from '@project-serum/serum'
3
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
3
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
4
  import {
5
5
  Keypair,
6
6
  PublicKey,
7
- sendAndConfirmTransaction,
8
7
  Signer,
9
8
  SystemProgram,
10
9
  SYSVAR_RENT_PUBKEY,
@@ -14,17 +13,17 @@ import {
14
13
  import {
15
14
  findAssociatedTokenAddress,
16
15
  findVaultAddress,
17
- getVaultTypeAccountPublicKey,
16
+ getHedgeMintPublicKey,
17
+ getPoolPublicKeyForMint,
18
18
  getUshMintPublicKey,
19
19
  getVaultSystemStatePublicKey,
20
- getPoolPublicKeyForMint,
21
- getHedgeMintPublicKey,
20
+ getVaultTypeAccountPublicKey,
22
21
  } from '../Constants'
23
22
 
24
23
  import { v4 as uuidv4 } from 'uuid'
24
+ import { Vault } from '../idl/vault'
25
25
  import { parseAnchorErrors } from '../utils/Errors'
26
26
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
27
- import { Vault } from '../idl/vault'
28
27
 
29
28
  export async function createVault(
30
29
  program: Program<Vault>,
@@ -34,20 +33,25 @@ export async function createVault(
34
33
  depositAmount: number,
35
34
  overrideTime?: number
36
35
  ): Promise<PublicKey> {
37
- const ushMintPublickey = await getUshMintPublicKey()
36
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
38
37
 
39
38
  const salt = uuidv4().substring(0, 8)
40
- const newVaultPublicKey = await findVaultAddress(salt)
39
+ const newVaultPublicKey = await findVaultAddress(program.programId, salt)
41
40
  const history = Keypair.generate()
42
41
 
43
42
  // Prep the user to get USH back out at some point
44
43
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
45
44
 
46
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
45
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
47
46
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
48
47
 
49
- const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
48
+ const payerTokenAccount = await findAssociatedTokenAddress(
49
+ program.programId,
50
+ payer.publicKey,
51
+ vaultTypeAccountInfo.collateralMint
52
+ )
50
53
  const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
54
+ program.programId,
51
55
  newVaultPublicKey,
52
56
  vaultTypeAccountInfo.collateralMint
53
57
  )
@@ -59,8 +63,15 @@ export async function createVault(
59
63
 
60
64
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === TokenInstructions.WRAPPED_SOL_MINT.toString()
61
65
 
62
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
63
- const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, ushMintPublickey)
66
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
67
+ program.programId,
68
+ await getHedgeMintPublicKey(program.programId)
69
+ )
70
+ const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
71
+ program.programId,
72
+ hedgeStakingPoolPublicKey,
73
+ ushMintPublickey
74
+ )
64
75
 
65
76
  if (isWrappedSol) {
66
77
  transaction.add(
@@ -119,11 +130,11 @@ export async function buildCreateVaultTransaction(
119
130
  overrideTime?: number
120
131
  ): Promise<[Transaction, Signer[], PublicKey]> {
121
132
  console.log('HEDGE SDK: buildCreateVaultTransaction')
122
- const ushMintPublickey = await getUshMintPublicKey()
133
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
123
134
  const salt = uuidv4().substring(0, 8)
124
- const newVaultPublicKey = await findVaultAddress(salt)
135
+ const newVaultPublicKey = await findVaultAddress(program.programId, salt)
125
136
  const history = Keypair.generate() as Signer
126
- const { blockhash } = await program.provider.connection.getLatestBlockhash()
137
+ const { blockhash, lastValidBlockHeight } = await program.provider.connection.getLatestBlockhash()
127
138
  const transaction = new Transaction({
128
139
  feePayer: payerPublicKey,
129
140
  recentBlockhash: blockhash,
@@ -134,7 +145,7 @@ export async function buildCreateVaultTransaction(
134
145
  console.log('Lookup getVaultTypeAccountPublicKey', collateralType)
135
146
 
136
147
  // Lookup the vault type info
137
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
148
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
138
149
 
139
150
  console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString())
140
151
 
@@ -143,14 +154,26 @@ export async function buildCreateVaultTransaction(
143
154
 
144
155
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === TokenInstructions.WRAPPED_SOL_MINT.toString()
145
156
 
146
- const payerTokenAccount = await findAssociatedTokenAddress(payerPublicKey, vaultTypeAccountInfo.collateralMint)
157
+ const payerTokenAccount = await findAssociatedTokenAddress(
158
+ program.programId,
159
+ payerPublicKey,
160
+ vaultTypeAccountInfo.collateralMint
161
+ )
147
162
  const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
163
+ program.programId,
148
164
  newVaultPublicKey,
149
165
  vaultTypeAccountInfo.collateralMint
150
166
  )
151
167
 
152
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
153
- const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, ushMintPublickey)
168
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
169
+ program.programId,
170
+ await getHedgeMintPublicKey(program.programId)
171
+ )
172
+ const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
173
+ program.programId,
174
+ hedgeStakingPoolPublicKey,
175
+ ushMintPublickey
176
+ )
154
177
 
155
178
  console.log('about to start building transaction')
156
179
 
@@ -224,7 +247,7 @@ export async function createVaultInstruction(
224
247
  depositAmount: BN,
225
248
  overrideTime?: number
226
249
  ): Promise<TransactionInstruction> {
227
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
250
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
228
251
 
229
252
  return await program.methods
230
253
  .createVault(
@@ -2,35 +2,28 @@ import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
5
- PublicKey,
6
- sendAndConfirmTransaction,
7
- Signer,
8
- SystemProgram,
9
- SYSVAR_RENT_PUBKEY,
10
- Transaction,
11
- TransactionInstruction,
5
+ PublicKey, Signer,
6
+ SystemProgram, Transaction,
7
+ TransactionInstruction
12
8
  } from '@solana/web3.js'
13
- import { parseAnchorErrors } from '../utils/Errors'
14
9
  import {
15
10
  getLiquidationPoolStatePublicKey,
16
- getLiquidationPoolUshAccountPublicKey,
17
- getUserReferralAccountPublicKey,
18
- getReferralAccountPublicKey,
19
- getUshMintPublicKey,
20
- getVaultSystemStatePublicKey,
11
+ getLiquidationPoolUshAccountPublicKey, getReferralAccountPublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
12
+ getVaultSystemStatePublicKey
21
13
  } from '../Constants'
22
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
14
  import { Vault } from '../idl/vault'
15
+ import { parseAnchorErrors } from '../utils/Errors'
16
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
17
 
25
18
  export async function depositLiquidationPool(
26
19
  program: Program<Vault>,
27
20
  provider: Provider,
28
21
  payer: Signer,
29
- depositAmount: BN,
22
+ depositAmount: number,
30
23
  overrideStartTime?: number,
31
24
  referrer?: PublicKey
32
25
  ): Promise<PublicKey> {
33
- const ushMintPublickey = await getUshMintPublicKey()
26
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
34
27
  const payerUshAccount = await getOrCreateAssociatedTokenAccount(
35
28
  provider.connection,
36
29
  payer,
@@ -39,15 +32,15 @@ export async function depositLiquidationPool(
39
32
  )
40
33
 
41
34
  let referralAccountPublicKey = null
42
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
35
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
43
36
  if (typeof referrer === 'undefined') {
44
- referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
37
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
45
38
  } else {
46
- referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
39
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
47
40
  }
48
41
 
49
42
  // Derive the user referral account public key
50
- const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payer.publicKey)
43
+ const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
51
44
 
52
45
  const poolPosition = Keypair.generate()
53
46
  const transaction = new Transaction().add(
@@ -78,11 +71,11 @@ export async function depositLiquidationPoolInstruction(
78
71
  referralAccountPublicKey: PublicKey,
79
72
  overrideStartTime?: number
80
73
  ): Promise<TransactionInstruction> {
81
- const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
74
+ const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
82
75
  const liquidationPoolState = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
83
76
 
84
- const poolUSHAccount = await getLiquidationPoolUshAccountPublicKey()
85
- const ushMint = await getUshMintPublicKey()
77
+ const poolUSHAccount = await getLiquidationPoolUshAccountPublicKey(program.programId)
78
+ const ushMint = await getUshMintPublicKey(program.programId)
86
79
 
87
80
  return await program.methods
88
81
  .depositLiquidationPool(
@@ -1,19 +1,15 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
2
+ import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
5
- PublicKey,
6
- sendAndConfirmTransaction,
7
- Signer,
8
- SystemProgram,
9
- SYSVAR_RENT_PUBKEY,
10
- Transaction,
11
- TransactionInstruction,
5
+ PublicKey, Signer,
6
+ SystemProgram, Transaction,
7
+ TransactionInstruction
12
8
  } from '@solana/web3.js'
13
- import { parseAnchorErrors } from '../utils/Errors'
14
9
  import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
15
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
16
10
  import { Vault } from '../idl/vault'
11
+ import { parseAnchorErrors } from '../utils/Errors'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
17
13
 
18
14
  export async function depositStakingPool(
19
15
  program: Program<Vault>,
@@ -46,10 +42,18 @@ export async function depositStakingPoolInstruction(
46
42
  depositAmount: BN,
47
43
  overrideStartTime?: number
48
44
  ): Promise<TransactionInstruction> {
49
- const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey)
50
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey)
51
- const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
52
- const vaultSystemState = await getVaultSystemStatePublicKey()
45
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
46
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
47
+ program.programId,
48
+ poolPublickey,
49
+ stakedTokenMintPublicKey
50
+ )
51
+ const payersArbitraryTokenAccount = await findAssociatedTokenAddress(
52
+ program.programId,
53
+ payerPublicKey,
54
+ stakedTokenMintPublicKey
55
+ )
56
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
53
57
 
54
58
  return await program.methods
55
59
  .depositStakingPool(