hedge-web3 0.2.24 → 0.2.25

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 (70) 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/utils/getLinkedListAccounts.d.ts +2 -2
  7. package/lib/Constants.js +28 -34
  8. package/lib/idl/vault.js +36 -0
  9. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  10. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  11. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  12. package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
  13. package/lib/instructions/createReferralAccount.js +8 -8
  14. package/lib/instructions/createStakingPool.js +7 -7
  15. package/lib/instructions/createUserReferralAccount.js +6 -6
  16. package/lib/instructions/createVault.js +15 -15
  17. package/lib/instructions/depositLiquidationPool.js +9 -9
  18. package/lib/instructions/depositStakingPool.js +5 -5
  19. package/lib/instructions/depositVault.js +11 -9
  20. package/lib/instructions/initHedgeFoundation.js +8 -8
  21. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  22. package/lib/instructions/liquidateVault.js +8 -8
  23. package/lib/instructions/loanVault.js +12 -12
  24. package/lib/instructions/psmEditAccount.js +5 -5
  25. package/lib/instructions/psmMintUsh.js +14 -14
  26. package/lib/instructions/psmRedeemUsh.js +14 -14
  27. package/lib/instructions/redeemVault.js +7 -7
  28. package/lib/instructions/referralClaimFees.js +8 -8
  29. package/lib/instructions/refreshOraclePrice.js +3 -3
  30. package/lib/instructions/repayVault.js +9 -9
  31. package/lib/instructions/setHalted.js +1 -1
  32. package/lib/instructions/updateReferralAccount.js +2 -2
  33. package/lib/instructions/updateReferralState.js +2 -2
  34. package/lib/instructions/updateVaultType.js +1 -1
  35. package/lib/instructions/withdrawStakingPool.js +11 -11
  36. package/lib/instructions/withdrawVault.js +5 -5
  37. package/lib/utils/getLinkedListAccounts.js +2 -3
  38. package/package.json +1 -1
  39. package/src/Constants.ts +44 -85
  40. package/src/idl/vault.ts +72 -0
  41. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  42. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  43. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  44. package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
  45. package/src/instructions/createReferralAccount.ts +17 -29
  46. package/src/instructions/createStakingPool.ts +11 -13
  47. package/src/instructions/createUserReferralAccount.ts +13 -24
  48. package/src/instructions/createVault.ts +44 -26
  49. package/src/instructions/depositLiquidationPool.ts +16 -23
  50. package/src/instructions/depositStakingPool.ts +18 -14
  51. package/src/instructions/depositVault.ts +23 -18
  52. package/src/instructions/initHedgeFoundation.ts +16 -14
  53. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  54. package/src/instructions/liquidateVault.ts +15 -20
  55. package/src/instructions/loanVault.ts +18 -27
  56. package/src/instructions/psmEditAccount.ts +10 -18
  57. package/src/instructions/psmMintUsh.ts +19 -41
  58. package/src/instructions/psmRedeemUsh.ts +21 -45
  59. package/src/instructions/redeemVault.ts +12 -15
  60. package/src/instructions/referralClaimFees.ts +17 -31
  61. package/src/instructions/refreshOraclePrice.ts +6 -8
  62. package/src/instructions/repayVault.ts +18 -16
  63. package/src/instructions/setHalted.ts +5 -24
  64. package/src/instructions/transferVault.ts +4 -9
  65. package/src/instructions/updateReferralAccount.ts +7 -14
  66. package/src/instructions/updateReferralState.ts +7 -14
  67. package/src/instructions/updateVaultType.ts +9 -23
  68. package/src/instructions/withdrawStakingPool.ts +17 -21
  69. package/src/instructions/withdrawVault.ts +10 -16
  70. package/src/utils/getLinkedListAccounts.ts +4 -7
@@ -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,30 +1,24 @@
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
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
6
+ PublicKey, Signer,
9
7
  SystemProgram,
10
8
  SYSVAR_RENT_PUBKEY,
11
9
  Transaction,
12
- TransactionInstruction,
10
+ TransactionInstruction
13
11
  } from '@solana/web3.js'
14
12
  import {
15
13
  findAssociatedTokenAddress,
16
- findVaultAddress,
17
- getVaultTypeAccountPublicKey,
18
- getUshMintPublicKey,
19
- getVaultSystemStatePublicKey,
20
- getPoolPublicKeyForMint,
21
- getHedgeMintPublicKey,
14
+ findVaultAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
15
+ getVaultSystemStatePublicKey, getVaultTypeAccountPublicKey
22
16
  } from '../Constants'
23
17
 
24
18
  import { v4 as uuidv4 } from 'uuid'
19
+ import { Vault } from '../idl/vault'
25
20
  import { parseAnchorErrors } from '../utils/Errors'
26
21
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
27
- import { Vault } from '../idl/vault'
28
22
 
29
23
  export async function createVault(
30
24
  program: Program<Vault>,
@@ -34,20 +28,25 @@ export async function createVault(
34
28
  depositAmount: number,
35
29
  overrideTime?: number
36
30
  ): Promise<PublicKey> {
37
- const ushMintPublickey = await getUshMintPublicKey()
31
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
38
32
 
39
33
  const salt = uuidv4().substring(0, 8)
40
- const newVaultPublicKey = await findVaultAddress(salt)
34
+ const newVaultPublicKey = await findVaultAddress(program.programId, salt)
41
35
  const history = Keypair.generate()
42
36
 
43
37
  // Prep the user to get USH back out at some point
44
38
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
45
39
 
46
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
40
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
47
41
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
48
42
 
49
- const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
43
+ const payerTokenAccount = await findAssociatedTokenAddress(
44
+ program.programId,
45
+ payer.publicKey,
46
+ vaultTypeAccountInfo.collateralMint
47
+ )
50
48
  const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
49
+ program.programId,
51
50
  newVaultPublicKey,
52
51
  vaultTypeAccountInfo.collateralMint
53
52
  )
@@ -59,8 +58,15 @@ export async function createVault(
59
58
 
60
59
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === TokenInstructions.WRAPPED_SOL_MINT.toString()
61
60
 
62
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
63
- const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, ushMintPublickey)
61
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
62
+ program.programId,
63
+ await getHedgeMintPublicKey(program.programId)
64
+ )
65
+ const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
66
+ program.programId,
67
+ hedgeStakingPoolPublicKey,
68
+ ushMintPublickey
69
+ )
64
70
 
65
71
  if (isWrappedSol) {
66
72
  transaction.add(
@@ -119,9 +125,9 @@ export async function buildCreateVaultTransaction(
119
125
  overrideTime?: number
120
126
  ): Promise<[Transaction, Signer[], PublicKey]> {
121
127
  console.log('HEDGE SDK: buildCreateVaultTransaction')
122
- const ushMintPublickey = await getUshMintPublicKey()
128
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
123
129
  const salt = uuidv4().substring(0, 8)
124
- const newVaultPublicKey = await findVaultAddress(salt)
130
+ const newVaultPublicKey = await findVaultAddress(program.programId, salt)
125
131
  const history = Keypair.generate() as Signer
126
132
  const { blockhash } = await program.provider.connection.getLatestBlockhash()
127
133
  const transaction = new Transaction({
@@ -134,7 +140,7 @@ export async function buildCreateVaultTransaction(
134
140
  console.log('Lookup getVaultTypeAccountPublicKey', collateralType)
135
141
 
136
142
  // Lookup the vault type info
137
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
143
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
138
144
 
139
145
  console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString())
140
146
 
@@ -143,14 +149,26 @@ export async function buildCreateVaultTransaction(
143
149
 
144
150
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === TokenInstructions.WRAPPED_SOL_MINT.toString()
145
151
 
146
- const payerTokenAccount = await findAssociatedTokenAddress(payerPublicKey, vaultTypeAccountInfo.collateralMint)
152
+ const payerTokenAccount = await findAssociatedTokenAddress(
153
+ program.programId,
154
+ payerPublicKey,
155
+ vaultTypeAccountInfo.collateralMint
156
+ )
147
157
  const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
158
+ program.programId,
148
159
  newVaultPublicKey,
149
160
  vaultTypeAccountInfo.collateralMint
150
161
  )
151
162
 
152
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
153
- const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, ushMintPublickey)
163
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
164
+ program.programId,
165
+ await getHedgeMintPublicKey(program.programId)
166
+ )
167
+ const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
168
+ program.programId,
169
+ hedgeStakingPoolPublicKey,
170
+ ushMintPublickey
171
+ )
154
172
 
155
173
  console.log('about to start building transaction')
156
174
 
@@ -224,7 +242,7 @@ export async function createVaultInstruction(
224
242
  depositAmount: BN,
225
243
  overrideTime?: number
226
244
  ): Promise<TransactionInstruction> {
227
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
245
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
228
246
 
229
247
  return await program.methods
230
248
  .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(
@@ -1,27 +1,21 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { TokenInstructions } from '@project-serum/serum'
3
+ import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
3
4
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
5
  import {
5
6
  Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
7
+ PublicKey, Signer,
9
8
  SystemProgram,
10
9
  Transaction,
11
- TransactionInstruction,
10
+ TransactionInstruction
12
11
  } from '@solana/web3.js'
13
- import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
14
12
  import {
15
- findAssociatedTokenAddress,
16
- getVaultTypeAccountPublicKey,
17
- getUshMintPublicKey,
18
- getVaultSystemStatePublicKey,
19
- getPoolPublicKeyForMint,
20
- getHedgeMintPublicKey,
13
+ findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
14
+ getVaultSystemStatePublicKey
21
15
  } from '../Constants'
22
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
16
  import { Vault } from '../idl/vault'
24
- import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
17
+ import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
19
 
26
20
  export async function depositVault(
27
21
  program: Program<Vault>,
@@ -31,7 +25,7 @@ export async function depositVault(
31
25
  depositAmount: number,
32
26
  overrideTime?: number
33
27
  ): Promise<PublicKey> {
34
- const ushMintPublickey = await getUshMintPublicKey()
28
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
35
29
 
36
30
  // Prep the user to get USH back out at some point
37
31
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
@@ -46,19 +40,28 @@ export async function depositVault(
46
40
  true
47
41
  )
48
42
 
49
- const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
43
+ const payerTokenAccount = await findAssociatedTokenAddress(
44
+ program.programId,
45
+ payer.publicKey,
46
+ vaultTypeAccountInfo.collateralMint
47
+ )
50
48
  const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(
49
+ program.programId,
51
50
  vaultPublicKey,
52
51
  vaultTypeAccountInfo.collateralMint
53
52
  )
54
53
 
55
54
  const history = Keypair.generate()
56
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
55
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
57
56
 
58
57
  const wrappedSolAccount = Keypair.generate()
59
58
 
60
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
59
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
60
+ program.programId,
61
+ await getHedgeMintPublicKey(program.programId)
62
+ )
61
63
  const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
64
+ program.programId,
62
65
  hedgeStakingPoolPublicKey,
63
66
  ushMintPublickey
64
67
  )
@@ -99,7 +102,9 @@ export async function depositVault(
99
102
  program,
100
103
  vaultSystemStatePublicKey,
101
104
  payer.publicKey,
102
- vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount,
105
+ vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()
106
+ ? wrappedSolAccount.publicKey
107
+ : payerTokenAccount,
103
108
  vaultPublicKey,
104
109
  vaultAssociatedCollateralAccountPublicKey,
105
110
  history.publicKey,
@@ -2,25 +2,23 @@ import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
5
- PublicKey,
6
- sendAndConfirmTransaction,
7
- Signer,
5
+ PublicKey, Signer,
8
6
  SystemProgram,
9
7
  SYSVAR_RENT_PUBKEY,
10
8
  Transaction,
11
- TransactionInstruction,
9
+ TransactionInstruction
12
10
  } from '@solana/web3.js'
13
- import { parseAnchorErrors } from '../utils/Errors'
14
11
  import {
15
12
  findAssociatedTokenAddress,
16
13
  getHedgeMintPublicKey,
17
14
  getLiquidationPoolStatePublicKey,
18
15
  getLiquidationPoolUshAccountPublicKey,
19
16
  getUshMintPublicKey,
20
- getVaultSystemStatePublicKey,
17
+ getVaultSystemStatePublicKey
21
18
  } from '../Constants'
22
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
19
  import { Vault } from '../idl/vault'
20
+ import { parseAnchorErrors } from '../utils/Errors'
21
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
22
 
25
23
  export async function initHedgeFoundation(program: Program<Vault>, provider: Provider, payer: Signer): Promise<PublicKey> {
26
24
  const poolEra = Keypair.generate()
@@ -37,13 +35,17 @@ export async function initHedgeFoundationInstruction(
37
35
  poolEraPublicKey: PublicKey,
38
36
  payerPublicKey: PublicKey
39
37
  ): Promise<TransactionInstruction> {
40
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
41
- const poolStatePublickey = await getLiquidationPoolStatePublicKey()
42
- const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey()
43
- const ushMintPublickey = await getUshMintPublicKey()
44
- const hedgeMintPublickey = await getHedgeMintPublicKey()
45
- const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
46
- const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
38
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
39
+ const poolStatePublickey = await getLiquidationPoolStatePublicKey(program.programId)
40
+ const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey(program.programId)
41
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
42
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
43
+ const founderHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
44
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(
45
+ program.programId,
46
+ vaultSystemStatePublicKey,
47
+ hedgeMintPublickey
48
+ )
47
49
 
48
50
  return await program.methods
49
51
  .initHedgeFoundation()
@@ -2,23 +2,17 @@ import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
5
- PublicKey,
6
- sendAndConfirmTransaction,
7
- Signer,
5
+ PublicKey, Signer,
8
6
  SystemProgram,
9
7
  SYSVAR_RENT_PUBKEY,
10
8
  Transaction,
11
- TransactionInstruction,
9
+ TransactionInstruction
12
10
  } from '@solana/web3.js'
13
- import { parseAnchorErrors } from '../utils/Errors'
14
11
  import {
15
12
  findAssociatedTokenAddress,
16
- getHedgeMintPublicKey,
17
- getLiquidationPoolStatePublicKey,
18
- getLiquidationPoolUshAccountPublicKey,
19
- getUshMintPublicKey,
20
- getVaultSystemStatePublicKey,
13
+ getHedgeMintPublicKey, getVaultSystemStatePublicKey
21
14
  } from '../Constants'
15
+ import { parseAnchorErrors } from '../utils/Errors'
22
16
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
17
 
24
18
  export async function initHedgeFoundationTokens(program: Program, provider: Provider, payer: Signer): Promise<PublicKey> {
@@ -33,10 +27,14 @@ export async function initHedgeFoundationTokensInstruction(
33
27
  program: Program,
34
28
  payerPublicKey: PublicKey
35
29
  ): Promise<TransactionInstruction> {
36
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
37
- const hedgeMintPublickey = await getHedgeMintPublicKey()
38
- const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
39
- const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
30
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
31
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
32
+ const founderHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
33
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(
34
+ program.programId,
35
+ vaultSystemStatePublicKey,
36
+ hedgeMintPublickey
37
+ )
40
38
 
41
39
  return await program.methods
42
40
  .initHedgeFoundationTokens()
@@ -1,28 +1,23 @@
1
- import { BN, Program, Provider, translateAddress } from '@project-serum/anchor'
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- Connection,
5
4
  Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
5
+ PublicKey, Signer,
9
6
  SystemProgram,
10
7
  SYSVAR_RENT_PUBKEY,
11
8
  Transaction,
12
- TransactionInstruction,
9
+ TransactionInstruction
13
10
  } from '@solana/web3.js'
14
- import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
15
11
  import {
16
12
  getHedgeMintPublicKey,
17
13
  getLiquidationPoolStatePublicKey,
18
14
  getLiquidationPoolUshAccountPublicKey,
19
- getPoolPublicKeyForMint,
20
- getVaultTypeAccountPublicKey,
21
- getUshMintPublicKey,
22
- getVaultSystemStatePublicKey,
15
+ getPoolPublicKeyForMint, getUshMintPublicKey,
16
+ getVaultSystemStatePublicKey
23
17
  } from '../Constants'
24
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
18
  import { Vault } from '../idl/vault'
19
+ import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
20
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
26
21
 
27
22
  export async function liquidateVault(
28
23
  program: Program<Vault>,
@@ -36,10 +31,10 @@ export async function liquidateVault(
36
31
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
37
32
  const collateralMint = vaultTypeAccountInfo.collateralMint
38
33
 
39
- const hedgeMintPublickey = await getHedgeMintPublicKey()
40
- const ushMintPublickey = await getUshMintPublicKey()
41
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
42
- const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
34
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
35
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
36
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
37
+ const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
43
38
  const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
44
39
 
45
40
  const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
@@ -152,9 +147,9 @@ export async function liquidateVaultInstruction(
152
147
  vaultTypeAccount: PublicKey,
153
148
  overrideTime?: number
154
149
  ): Promise<TransactionInstruction> {
155
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
156
- const ushMintPublickey = await getUshMintPublicKey()
157
- const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
150
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
151
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
152
+ const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey(program.programId)
158
153
 
159
154
  return await program.methods
160
155
  .liquidateVault(