hedge-web3 0.2.21 → 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 (92) hide show
  1. package/declarations/Constants.d.ts +25 -12
  2. package/declarations/idl/pyth.d.ts +44 -24
  3. package/declarations/idl/switchboard.d.ts +47 -0
  4. package/declarations/idl/vault.d.ts +905 -155
  5. package/declarations/index.d.ts +26 -20
  6. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +2 -2
  7. package/declarations/instructions/createReferralAccount.d.ts +17 -0
  8. package/declarations/instructions/createUserReferralAccount.d.ts +5 -0
  9. package/declarations/instructions/depositLiquidationPool.d.ts +2 -2
  10. package/declarations/instructions/loanVault.d.ts +2 -2
  11. package/declarations/instructions/psmEditAccount.d.ts +12 -0
  12. package/declarations/instructions/psmMintUsh.d.ts +2 -2
  13. package/declarations/instructions/psmRedeemUsh.d.ts +2 -2
  14. package/declarations/instructions/referralClaimFees.d.ts +16 -0
  15. package/declarations/instructions/transferVault.d.ts +3 -17
  16. package/declarations/instructions/updateReferralAccount.d.ts +13 -0
  17. package/declarations/instructions/updateReferralState.d.ts +20 -0
  18. package/declarations/state/VaultAccount.d.ts +1 -1
  19. package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
  20. package/lib/Constants.js +57 -28
  21. package/lib/idl/pyth.js +44 -24
  22. package/lib/idl/switchboard.js +49 -0
  23. package/lib/idl/vault.js +898 -148
  24. package/lib/index.js +26 -20
  25. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  26. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  27. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  28. package/lib/instructions/closeLiquidationPoolPosition.js +25 -12
  29. package/lib/instructions/createReferralAccount.js +80 -0
  30. package/lib/instructions/createStakingPool.js +7 -7
  31. package/lib/instructions/createUserReferralAccount.js +61 -0
  32. package/lib/instructions/createVault.js +15 -15
  33. package/lib/instructions/depositLiquidationPool.js +21 -10
  34. package/lib/instructions/depositStakingPool.js +5 -5
  35. package/lib/instructions/depositVault.js +11 -9
  36. package/lib/instructions/initHedgeFoundation.js +8 -8
  37. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  38. package/lib/instructions/liquidateVault.js +8 -8
  39. package/lib/instructions/loanVault.js +23 -10
  40. package/lib/instructions/psmEditAccount.js +60 -0
  41. package/lib/instructions/psmMintUsh.js +24 -13
  42. package/lib/instructions/psmRedeemUsh.js +24 -13
  43. package/lib/instructions/redeemVault.js +7 -7
  44. package/lib/instructions/referralClaimFees.js +84 -0
  45. package/lib/instructions/refreshOraclePrice.js +3 -3
  46. package/lib/instructions/repayVault.js +9 -9
  47. package/lib/instructions/setHalted.js +1 -1
  48. package/lib/instructions/transferVault.js +10 -24
  49. package/lib/instructions/updateReferralAccount.js +50 -0
  50. package/lib/instructions/updateReferralState.js +57 -0
  51. package/lib/instructions/updateVaultType.js +1 -1
  52. package/lib/instructions/withdrawStakingPool.js +11 -11
  53. package/lib/instructions/withdrawVault.js +5 -5
  54. package/lib/state/VaultAccount.js +3 -1
  55. package/lib/utils/getLinkedListAccounts.js +2 -3
  56. package/package.json +1 -1
  57. package/src/Constants.ts +64 -63
  58. package/src/idl/pyth.ts +88 -48
  59. package/src/idl/switchboard.ts +93 -0
  60. package/src/idl/vault.ts +1851 -351
  61. package/src/index.ts +28 -24
  62. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  63. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  64. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  65. package/src/instructions/closeLiquidationPoolPosition.ts +36 -18
  66. package/src/instructions/createReferralAccount.ts +115 -0
  67. package/src/instructions/createStakingPool.ts +11 -13
  68. package/src/instructions/createUserReferralAccount.ts +75 -0
  69. package/src/instructions/createVault.ts +44 -26
  70. package/src/instructions/depositLiquidationPool.ts +34 -21
  71. package/src/instructions/depositStakingPool.ts +18 -14
  72. package/src/instructions/depositVault.ts +23 -18
  73. package/src/instructions/initHedgeFoundation.ts +16 -14
  74. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  75. package/src/instructions/liquidateVault.ts +15 -20
  76. package/src/instructions/loanVault.ts +29 -19
  77. package/src/instructions/{psmEditAccount.rs → psmEditAccount.ts} +10 -18
  78. package/src/instructions/psmMintUsh.ts +35 -38
  79. package/src/instructions/psmRedeemUsh.ts +35 -40
  80. package/src/instructions/redeemVault.ts +12 -15
  81. package/src/instructions/referralClaimFees.ts +145 -0
  82. package/src/instructions/refreshOraclePrice.ts +6 -8
  83. package/src/instructions/repayVault.ts +18 -16
  84. package/src/instructions/setHalted.ts +5 -24
  85. package/src/instructions/transferVault.ts +57 -0
  86. package/src/instructions/updateReferralAccount.ts +70 -0
  87. package/src/instructions/updateReferralState.ts +86 -0
  88. package/src/instructions/updateVaultType.ts +9 -23
  89. package/src/instructions/withdrawStakingPool.ts +17 -21
  90. package/src/instructions/withdrawVault.ts +10 -16
  91. package/src/state/VaultAccount.ts +9 -10
  92. package/src/utils/getLinkedListAccounts.ts +4 -7
@@ -1,29 +1,10 @@
1
- import { BN, 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'
4
- import {
5
- Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
9
- SystemProgram,
10
- SYSVAR_RENT_PUBKEY,
11
- Transaction,
12
- TransactionInstruction,
13
- } from '@solana/web3.js'
14
- import {
15
- findAssociatedTokenAddress,
16
- findVaultAddress,
17
- getVaultTypeAccountPublicKey,
18
- getUshMintPublicKey,
19
- getVaultSystemStatePublicKey,
20
- getPoolPublicKeyForMint,
21
- getHedgeMintPublicKey,
22
- } from '../Constants'
1
+ import { Program, Provider } from '@project-serum/anchor'
2
+ import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import { getVaultSystemStatePublicKey } from '../Constants'
23
4
 
5
+ import { Vault } from '../idl/vault'
24
6
  import { parseAnchorErrors } from '../utils/Errors'
25
7
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
26
- import { Vault } from '../idl/vault'
27
8
 
28
9
  export async function setHalted(
29
10
  program: Program<Vault>,
@@ -31,7 +12,7 @@ export async function setHalted(
31
12
  payer: Signer,
32
13
  halted: boolean
33
14
  ): Promise<PublicKey> {
34
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
15
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
35
16
 
36
17
  const transaction = new Transaction().add(
37
18
  await setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted)
@@ -0,0 +1,57 @@
1
+ import { Program, Provider } from '@project-serum/anchor'
2
+ import {
3
+ Keypair,
4
+ PublicKey, Signer, Transaction,
5
+ TransactionInstruction
6
+ } from '@solana/web3.js'
7
+
8
+ import { Vault } from '../idl/vault'
9
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
10
+
11
+ export async function transferVault(
12
+ program: Program<Vault>,
13
+ provider: Provider,
14
+ payer: Signer,
15
+ vaultPublicKey: PublicKey,
16
+ vaultSystemStatePublicKey: PublicKey,
17
+ vaultTypeAccount: PublicKey,
18
+ newOwner: PublicKey
19
+ ): Promise<PublicKey> {
20
+ const history = Keypair.generate()
21
+
22
+ const transaction = new Transaction().add(
23
+ await transferVaultInstruction(
24
+ vaultPublicKey,
25
+ vaultSystemStatePublicKey,
26
+ vaultTypeAccount,
27
+ history.publicKey,
28
+ payer.publicKey,
29
+ program,
30
+ newOwner
31
+ )
32
+ )
33
+
34
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
35
+ return vaultPublicKey
36
+ }
37
+
38
+ export async function transferVaultInstruction(
39
+ vaultPublickey: PublicKey,
40
+ vaultSystemStatePublicKey: PublicKey,
41
+ vaultTypeAccount: PublicKey,
42
+ historyPublicKey: PublicKey,
43
+ vaultOwner: PublicKey,
44
+ program: Program<Vault>,
45
+ newOwner: PublicKey
46
+ ): Promise<TransactionInstruction> {
47
+ return await program.methods
48
+ .transferVault(newOwner)
49
+ .accounts({
50
+ vault: vaultPublickey,
51
+ vaultSystemState: vaultSystemStatePublicKey,
52
+ vaultType: vaultTypeAccount,
53
+ history: historyPublicKey,
54
+ vaultOwner: vaultOwner,
55
+ })
56
+ .instruction()
57
+ }
@@ -0,0 +1,70 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import {
3
+ PublicKey, Signer,
4
+ SystemProgram, Transaction,
5
+ TransactionInstruction
6
+ } from '@solana/web3.js'
7
+ import {
8
+ getReferralAccountPublicKey, getVaultSystemStatePublicKey
9
+ } from '../Constants'
10
+
11
+ import { Vault } from '../idl/vault'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
+
14
+ export interface ReferralAccountConfig {
15
+ setupCut?: BN
16
+ referredUserDiscount?: BN
17
+ stabilityCut?: BN
18
+ psmCut?: BN
19
+
20
+ hdgThreshold?: BN
21
+ }
22
+
23
+ export async function updateReferralAccount(
24
+ program: Program<Vault>,
25
+ provider: Provider,
26
+ payer: Signer,
27
+ referrer: PublicKey,
28
+ config: ReferralAccountConfig
29
+ ): Promise<PublicKey> {
30
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
31
+ const referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
32
+ const transaction = new Transaction().add(
33
+ await updateReferralAccountInstruction(
34
+ program,
35
+ vaultSystemStatePublicKey,
36
+ referralAccountPublicKey,
37
+ payer.publicKey,
38
+ config
39
+ )
40
+ )
41
+
42
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
43
+ return referralAccountPublicKey
44
+ }
45
+
46
+ export async function updateReferralAccountInstruction(
47
+ program: Program<Vault>,
48
+ vaultSystemStatePublicKey: PublicKey,
49
+ referralAccountPublicKey: PublicKey,
50
+ payerPublicKey: PublicKey,
51
+ referralAccountConfig: ReferralAccountConfig
52
+ ): Promise<TransactionInstruction> {
53
+ const config = {
54
+ setupCut: referralAccountConfig.setupCut ?? null,
55
+ stabilityCut: referralAccountConfig.stabilityCut ?? null,
56
+ referredUserDiscount: referralAccountConfig.referredUserDiscount ?? null,
57
+ psmCut: referralAccountConfig.psmCut ?? null,
58
+ hdgThreshold: referralAccountConfig.hdgThreshold ?? null,
59
+ }
60
+
61
+ return await program.methods
62
+ .updateReferralAccount(config)
63
+ .accounts({
64
+ signer: payerPublicKey,
65
+ vaultSystemState: vaultSystemStatePublicKey,
66
+ referralAccount: referralAccountPublicKey,
67
+ systemProgram: SystemProgram.programId,
68
+ })
69
+ .instruction()
70
+ }
@@ -0,0 +1,86 @@
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import {
3
+ PublicKey, Signer,
4
+ SystemProgram, Transaction,
5
+ TransactionInstruction
6
+ } from '@solana/web3.js'
7
+ import {
8
+ getReferralStatePublicKey, getVaultSystemStatePublicKey
9
+ } from '../Constants'
10
+
11
+ import { Vault } from '../idl/vault'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
+
14
+ export interface ReferralStateConfig {
15
+ setupCut?: BN
16
+ referredUserDiscount?: BN
17
+ stabilityCut?: BN
18
+ psmCut?: BN
19
+
20
+ maxSetupCut?: BN
21
+ maxReferredDiscount?: BN
22
+ maxStabilityCut?: BN
23
+ maxPsmCut?: BN
24
+
25
+ hdgThreshold?: BN
26
+ hdgPsmThreshold?: BN
27
+
28
+ referralThreshold?: BN
29
+
30
+ referralEnabled?: boolean
31
+ }
32
+
33
+ export async function updateReferralState(
34
+ program: Program<Vault>,
35
+ provider: Provider,
36
+ payer: Signer,
37
+ config: ReferralStateConfig
38
+ ): Promise<PublicKey> {
39
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
40
+ const referralStatePublicKey = await getReferralStatePublicKey(program.programId, )
41
+ const transaction = new Transaction().add(
42
+ await updateReferralStateInstruction(
43
+ program,
44
+ vaultSystemStatePublicKey,
45
+ referralStatePublicKey,
46
+ payer.publicKey,
47
+ config
48
+ )
49
+ )
50
+
51
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
52
+ return referralStatePublicKey
53
+ }
54
+
55
+ export async function updateReferralStateInstruction(
56
+ program: Program<Vault>,
57
+ vaultSystemStatePublicKey: PublicKey,
58
+ referralStatePublicKey: PublicKey,
59
+ payerPublicKey: PublicKey,
60
+ referralStateConfig: ReferralStateConfig
61
+ ): Promise<TransactionInstruction> {
62
+ const config = {
63
+ setupCut: referralStateConfig.setupCut ?? null,
64
+ stabilityCut: referralStateConfig.stabilityCut ?? null,
65
+ referredUserDiscount: referralStateConfig.referredUserDiscount ?? null,
66
+ psmCut: referralStateConfig.psmCut ?? null,
67
+ maxSetupCut: referralStateConfig.maxSetupCut ?? null,
68
+ maxReferredDiscount: referralStateConfig.maxReferredDiscount ?? null,
69
+ maxStabilityCut: referralStateConfig.maxStabilityCut ?? null,
70
+ maxPsmCut: referralStateConfig.maxPsmCut ?? null,
71
+ hdgThreshold: referralStateConfig.hdgThreshold ?? null,
72
+ hdgPsmThreshold: referralStateConfig.hdgPsmThreshold ?? null,
73
+ referralPromoThreshold: referralStateConfig.referralThreshold ?? null,
74
+ referralEnabled: referralStateConfig.referralEnabled ?? null,
75
+ }
76
+
77
+ return await program.methods
78
+ .updateReferralState(config)
79
+ .accounts({
80
+ signer: payerPublicKey,
81
+ vaultSystemState: vaultSystemStatePublicKey,
82
+ referralState: referralStatePublicKey,
83
+ systemProgram: SystemProgram.programId,
84
+ })
85
+ .instruction()
86
+ }
@@ -1,44 +1,30 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import {
3
- Keypair,
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
7
- SystemProgram,
8
- SYSVAR_RENT_PUBKEY,
9
- Transaction,
10
- TransactionInstruction,
3
+ PublicKey, Signer, Transaction,
4
+ TransactionInstruction
11
5
  } from '@solana/web3.js'
12
6
  import {
13
- findAssociatedTokenAddress,
14
- findVaultAddress,
15
- getVaultTypeAccountPublicKey,
16
- getUshMintPublicKey,
17
- getVaultSystemStatePublicKey,
18
- getPoolPublicKeyForMint,
19
- getHedgeMintPublicKey,
7
+ getVaultSystemStatePublicKey
20
8
  } from '../Constants'
21
9
 
22
- import { v4 as uuidv4 } from 'uuid'
23
- import { parseAnchorErrors } from '../utils/Errors'
24
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
10
  import { Vault } from '../idl/vault'
11
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
26
12
 
27
13
  export interface VaultTypeConfig {
28
14
  maxDebtExtended?: BN
29
15
  minDebtPerVault?: BN
30
16
  loanInitFee?: BN
31
17
  interestRatePerSecond?: BN
32
-
18
+
33
19
  emergencyModeThreshold?: BN
34
20
 
35
21
  oracleChainlink?: PublicKey
36
22
  oraclePyth?: PublicKey
37
23
  oracleSwitchboard?: PublicKey
38
24
 
39
- priorityPyth?: number,
40
- priorityChainlink?: number,
41
- prioritySwitchboard?: number,
25
+ priorityPyth?: number
26
+ priorityChainlink?: number
27
+ prioritySwitchboard?: number
42
28
 
43
29
  deprecated?: boolean
44
30
  }
@@ -51,7 +37,7 @@ export async function updateVaultType(
51
37
  oracleInfoAccount: PublicKey,
52
38
  config: VaultTypeConfig
53
39
  ): Promise<PublicKey> {
54
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
40
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
55
41
  const transaction = new Transaction().add(
56
42
  await updateVaultTypeStatusInstruction(
57
43
  program,
@@ -1,25 +1,21 @@
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 {
15
10
  findAssociatedTokenAddress,
16
11
  getHedgeMintPublicKey,
17
12
  getPoolPublicKeyForMint,
18
13
  getUshMintPublicKey,
19
- getVaultSystemStatePublicKey,
14
+ getVaultSystemStatePublicKey
20
15
  } from '../Constants'
21
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
22
16
  import { Vault } from '../idl/vault'
17
+ import { parseAnchorErrors } from '../utils/Errors'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
19
 
24
20
  export async function withdrawStakingPool(
25
21
  program: Program<Vault>,
@@ -51,16 +47,16 @@ export async function withdrawStakingPoolInstruction(
51
47
  stakedTokenMintPublicKey: PublicKey,
52
48
  overrideStartTime?: number
53
49
  ): Promise<TransactionInstruction> {
54
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
55
- const ushMintPublickey = await getUshMintPublicKey()
56
- const hedgeMintPublickey = await getHedgeMintPublicKey()
57
- const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey)
58
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey)
59
- const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
60
- const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
61
- const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
62
- const payerAssociatedUshAccount = await findAssociatedTokenAddress(payerPublicKey, ushMintPublickey)
63
- const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
50
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
51
+ const ushMintPublickey = await getUshMintPublicKey(program.programId, )
52
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId, )
53
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
54
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, stakedTokenMintPublicKey)
55
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
56
+ const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, stakedTokenMintPublicKey)
57
+ const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
58
+ const payerAssociatedUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
59
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey)
64
60
 
65
61
  return await program.methods
66
62
  .withdrawStakingPool(
@@ -1,26 +1,20 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
2
  import { TokenInstructions } from '@project-serum/serum'
3
+ import { 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
  Transaction,
11
- TransactionInstruction,
9
+ TransactionInstruction
12
10
  } from '@solana/web3.js'
13
11
  import {
14
- findAssociatedTokenAddress,
15
- getVaultTypeAccountPublicKey,
16
- getUshMintPublicKey,
17
- getVaultSystemStatePublicKey,
18
- getPoolPublicKeyForMint,
19
- getHedgeMintPublicKey,
12
+ findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
13
+ getVaultSystemStatePublicKey
20
14
  } from '../Constants'
15
+ import { Vault } from '../idl/vault'
21
16
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
22
17
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
- import { Vault } from '../idl/vault'
24
18
 
25
19
  export async function withdrawVault(
26
20
  program: Program<Vault>,
@@ -30,13 +24,13 @@ export async function withdrawVault(
30
24
  withdrawAmount: number,
31
25
  overrideTime?: number
32
26
  ): Promise<PublicKey> {
33
- const ushMintPublickey = await getUshMintPublicKey()
27
+ const ushMintPublickey = await getUshMintPublicKey(program.programId, )
34
28
 
35
29
  // Prep the user to get USH back out at some point
36
30
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
37
31
 
38
32
  const history = Keypair.generate()
39
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
33
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
40
34
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
41
35
  const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
42
36
  provider.connection,
@@ -61,8 +55,8 @@ export async function withdrawVault(
61
55
  vaultTypeAccountInfo.collateralMint,
62
56
  payer.publicKey
63
57
  )
64
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
65
- const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
58
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, await getHedgeMintPublicKey(program.programId, ))
59
+ const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId,
66
60
  hedgeStakingPoolPublicKey,
67
61
  ushMintPublickey
68
62
  )
@@ -16,7 +16,7 @@ export class VaultAccount {
16
16
  /** The public key of the vault owner. */
17
17
  vaultOwner: PublicKey
18
18
 
19
- /** The public key of the vault owner. */
19
+ /** The salt used to derive the PDA for the vault. */
20
20
  pdaSalt: string
21
21
 
22
22
  /** The deposited collateral of the vault (in SOL Lamports). */
@@ -50,7 +50,7 @@ export class VaultAccount {
50
50
  this.publicKey = publicKey
51
51
  this.vaultOwner = vault.vaultOwner
52
52
  this.pdaSalt = vault.pdaSalt
53
-
53
+
54
54
  this.deposited = vault.deposited
55
55
  this.denormalizedDebt = vault.denormalizedDebt
56
56
 
@@ -177,16 +177,15 @@ export class VaultAccount {
177
177
  public updateDebtAndCollateral(vaultTypeAccountData: VaultType) {
178
178
  this.denormalizedDebt = new BN(
179
179
  vaultTypeAccountData.debtRedistributionProduct
180
- .div(this.debtProductSnapshotBytes)
181
- .mul(new Decimal(this.denormalizedDebt.toString()))
182
- .floor()
183
- .toString()
180
+ .div(this.debtProductSnapshotBytes)
181
+ .mul(new Decimal(this.denormalizedDebt.toString()))
182
+ .floor()
183
+ .toString()
184
184
  )
185
185
 
186
- const extraCollateralDeposited =
187
- new Decimal(this.denormalizedDebt.toString()).mul(
188
- vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()
189
- ).floor()
186
+ const extraCollateralDeposited = new Decimal(this.denormalizedDebt.toString())
187
+ .mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber())
188
+ .floor()
190
189
  this.deposited = this.deposited.add(new BN(extraCollateralDeposited.toString()))
191
190
 
192
191
  this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator
@@ -1,14 +1,11 @@
1
- import { Program, Provider, BN } from '@project-serum/anchor'
2
- import { PublicKey, Signer } from '@solana/web3.js'
1
+ import { BN, Program } from '@project-serum/anchor'
2
+ import { PublicKey } from '@solana/web3.js'
3
3
  import _ from 'underscore'
4
- import { getVaultSystemStatePublicKey, getVaultTypeOracleAccountPublicKey, HEDGE_PROGRAM_PUBLICKEY } from '../Constants'
5
4
 
6
- import { DecimalFromU128 } from '../HedgeDecimal'
7
- import { VaultAccount } from '../state/VaultAccount'
8
5
  import Decimal from 'decimal.js'
9
6
  import { Vault } from '../idl/vault'
7
+ import { VaultAccount } from '../state/VaultAccount'
10
8
 
11
- import * as borsh from '@project-serum/borsh'
12
9
  import base58 from 'bs58'
13
10
  import VaultType from '../state/VaultType'
14
11
 
@@ -228,7 +225,7 @@ async function getMiniVaults(program: Program<Vault>, vaultTypePublicKey: Public
228
225
  },
229
226
  },
230
227
  ]
231
- const allAccounts = await program.provider.connection.getProgramAccounts(HEDGE_PROGRAM_PUBLICKEY, {
228
+ const allAccounts = await program.provider.connection.getProgramAccounts(program.programId, {
232
229
  filters: filters,
233
230
  // Slice the data only to grab the 3 u64's of size 8 bytes each
234
231
  dataSlice: {