hedge-web3 0.1.50 → 0.2.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 (77) hide show
  1. package/declarations/Constants.d.ts +2 -1
  2. package/declarations/idl/vault.d.ts +192 -41
  3. package/declarations/index.d.ts +1 -0
  4. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
  5. package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
  6. package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +5 -0
  7. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
  8. package/declarations/instructions/createStakingPool.d.ts +1 -1
  9. package/declarations/instructions/createVault.d.ts +1 -1
  10. package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
  11. package/declarations/instructions/depositStakingPool.d.ts +1 -1
  12. package/declarations/instructions/depositVault.d.ts +1 -1
  13. package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
  14. package/declarations/instructions/liquidateVault.d.ts +2 -2
  15. package/declarations/instructions/loanVault.d.ts +1 -1
  16. package/declarations/instructions/redeemVault.d.ts +1 -1
  17. package/declarations/instructions/refreshOraclePrice.d.ts +3 -3
  18. package/declarations/instructions/repayVault.d.ts +1 -1
  19. package/declarations/instructions/setHalted.d.ts +1 -1
  20. package/declarations/instructions/updateVaultType.d.ts +4 -1
  21. package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
  22. package/declarations/instructions/withdrawVault.d.ts +1 -1
  23. package/declarations/state/VaultAccount.d.ts +9 -6
  24. package/declarations/utils/getLinkedListAccounts.d.ts +1 -1
  25. package/lib/Constants.js +3 -2
  26. package/lib/idl/vault.js +192 -41
  27. package/lib/index.js +1 -0
  28. package/lib/instructions/claimLiquidationPoolPosition.js +5 -1
  29. package/lib/instructions/claimStakingPoolPosition.js +5 -1
  30. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +38 -0
  31. package/lib/instructions/closeLiquidationPoolPosition.js +5 -1
  32. package/lib/instructions/createStakingPool.js +5 -1
  33. package/lib/instructions/createVault.js +5 -1
  34. package/lib/instructions/depositLiquidationPool.js +5 -1
  35. package/lib/instructions/depositStakingPool.js +5 -1
  36. package/lib/instructions/depositVault.js +12 -8
  37. package/lib/instructions/initHedgeFoundation.js +5 -1
  38. package/lib/instructions/initHedgeFoundationTokens.js +5 -1
  39. package/lib/instructions/liquidateVault.js +10 -8
  40. package/lib/instructions/loanVault.js +9 -6
  41. package/lib/instructions/redeemVault.js +9 -6
  42. package/lib/instructions/refreshOraclePrice.js +8 -3
  43. package/lib/instructions/repayVault.js +9 -6
  44. package/lib/instructions/setHalted.js +5 -1
  45. package/lib/instructions/updateVaultType.js +9 -2
  46. package/lib/instructions/withdrawStakingPool.js +5 -1
  47. package/lib/instructions/withdrawVault.js +9 -6
  48. package/lib/state/VaultAccount.js +28 -32
  49. package/lib/utils/getLinkedListAccounts.js +54 -57
  50. package/package.json +1 -1
  51. package/src/Constants.ts +2 -1
  52. package/src/idl/vault.ts +384 -82
  53. package/src/index.ts +1 -0
  54. package/src/instructions/claimLiquidationPoolPosition.ts +3 -2
  55. package/src/instructions/claimStakingPoolPosition.ts +3 -2
  56. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +31 -0
  57. package/src/instructions/closeLiquidationPoolPosition.ts +3 -2
  58. package/src/instructions/createStakingPool.ts +3 -2
  59. package/src/instructions/createVault.ts +3 -2
  60. package/src/instructions/depositLiquidationPool.ts +3 -2
  61. package/src/instructions/depositStakingPool.ts +3 -2
  62. package/src/instructions/depositVault.ts +11 -11
  63. package/src/instructions/initHedgeFoundation.ts +3 -2
  64. package/src/instructions/initHedgeFoundationTokens.ts +2 -1
  65. package/src/instructions/liquidateVault.ts +11 -10
  66. package/src/instructions/loanVault.ts +11 -9
  67. package/src/instructions/redeemVault.ts +7 -7
  68. package/src/instructions/refreshOraclePrice.ts +9 -6
  69. package/src/instructions/repayVault.ts +7 -7
  70. package/src/instructions/setHalted.ts +3 -2
  71. package/src/instructions/updateVaultType.ts +10 -2
  72. package/src/instructions/withdrawStakingPool.ts +5 -3
  73. package/src/instructions/withdrawVault.ts +7 -7
  74. package/src/state/VaultAccount.ts +37 -32
  75. package/src/state/VaultType.ts +62 -0
  76. package/src/utils/getLinkedListAccounts.ts +61 -60
  77. package/src/utils/sendAndConfirmWithDebug.ts +27 -0
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './instructions/claimStakingPoolPosition'
6
6
  export * from './instructions/depositLiquidationPool'
7
7
  export * from './instructions/closeLiquidationPoolPosition'
8
8
  export * from './instructions/claimLiquidationPoolPosition'
9
+ export * from './instructions/closeClaimedLiquidationPoolPosition'
9
10
  export * from './instructions/createVault'
10
11
  export * from './instructions/depositVault'
11
12
  export * from './instructions/withdrawVault'
@@ -16,7 +16,8 @@ import {
16
16
  getLiquidationPoolStatePublicKey,
17
17
  getVaultSystemStatePublicKey,
18
18
  } from '../Constants'
19
- import { Vault } from 'idl/vault'
19
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
+ import { Vault } from '../idl/vault'
20
21
 
21
22
  export async function claimLiquidationPoolPosition(
22
23
  program: Program<Vault>,
@@ -48,7 +49,7 @@ export async function claimLiquidationPoolPosition(
48
49
  overrideStartTime
49
50
  )
50
51
  )
51
- await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
52
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
52
53
  return payerAssociatedTokenAccount.address
53
54
  }
54
55
 
@@ -17,7 +17,8 @@ import {
17
17
  getPoolPublicKeyForMint,
18
18
  getVaultSystemStatePublicKey,
19
19
  } from '../Constants'
20
- import { Vault } from 'idl/vault'
20
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
+ import { Vault } from '../idl/vault'
21
22
 
22
23
  export async function claimStakingPoolPosition(
23
24
  program: Program<Vault>,
@@ -58,7 +59,7 @@ export async function claimStakingPoolPosition(
58
59
  payerAssociatedTokenAccount.address
59
60
  )
60
61
  )
61
- await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
62
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
62
63
  return payerAssociatedTokenAccount.address
63
64
  }
64
65
 
@@ -0,0 +1,31 @@
1
+ import { Program, Provider } from '@project-serum/anchor'
2
+ import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import { parseAnchorErrors } from '../utils/Errors'
4
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
5
+ import { Vault } from '../idl/vault'
6
+
7
+ export async function closeClaimedLiquidationPoolPosition(
8
+ program: Program<Vault>,
9
+ provider: Provider,
10
+ poolPosition: PublicKey,
11
+ payer: Signer
12
+ ): Promise<PublicKey> {
13
+ const transaction = new Transaction().add(await closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer.publicKey))
14
+
15
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
16
+ return poolPosition
17
+ }
18
+
19
+ export async function closeClaimedLiquidationPoolPositionInstruction(
20
+ program: Program<Vault>,
21
+ poolPosition: PublicKey,
22
+ payer: PublicKey
23
+ ): Promise<TransactionInstruction> {
24
+ return program.methods
25
+ .closeClaimedLiquidationPool()
26
+ .accounts({
27
+ poolPosition: poolPosition,
28
+ payer: payer
29
+ })
30
+ .instruction()
31
+ }
@@ -17,7 +17,8 @@ import {
17
17
  getUshMintPublicKey,
18
18
  getVaultSystemStatePublicKey,
19
19
  } from '../Constants'
20
- import { Vault } from 'idl/vault'
20
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
+ import { Vault } from '../idl/vault'
21
22
 
22
23
  export async function closeLiquidationPoolPosition(
23
24
  program: Program<Vault>,
@@ -64,7 +65,7 @@ export async function closeLiquidationPoolPosition(
64
65
  overrideStartTime
65
66
  )
66
67
  )
67
- await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
68
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
68
69
  return poolPosition
69
70
  }
70
71
 
@@ -16,7 +16,8 @@ import {
16
16
  getUshMintPublicKey,
17
17
  getVaultSystemStatePublicKey,
18
18
  } from '../Constants'
19
- import { Vault } from 'idl/vault'
19
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
+ import { Vault } from '../idl/vault'
20
21
 
21
22
  export async function createStakingPool(
22
23
  program: Program<Vault>,
@@ -29,7 +30,7 @@ export async function createStakingPool(
29
30
  const transaction = new Transaction().add(
30
31
  await createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime)
31
32
  )
32
- await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
33
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
33
34
  const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey)
34
35
  return poolPublickey
35
36
  }
@@ -23,7 +23,8 @@ import {
23
23
 
24
24
  import { v4 as uuidv4 } from 'uuid'
25
25
  import { parseAnchorErrors } from '../utils/Errors'
26
- import { Vault } from 'idl/vault'
26
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
27
+ import { Vault } from '../idl/vault'
27
28
 
28
29
  export async function createVault(
29
30
  program: Program<Vault>,
@@ -106,7 +107,7 @@ export async function createVault(
106
107
  )
107
108
  }
108
109
 
109
- await sendAndConfirmTransaction(provider.connection, transaction, signers).catch(parseAnchorErrors)
110
+ await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
110
111
  return newVaultPublicKey
111
112
  }
112
113
 
@@ -17,7 +17,8 @@ import {
17
17
  getUshMintPublicKey,
18
18
  getVaultSystemStatePublicKey,
19
19
  } from '../Constants'
20
- import { Vault } from 'idl/vault'
20
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
+ import { Vault } from '../idl/vault'
21
22
 
22
23
  export async function depositLiquidationPool(
23
24
  program: Program<Vault>,
@@ -45,7 +46,7 @@ export async function depositLiquidationPool(
45
46
  overrideStartTime
46
47
  )
47
48
  )
48
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
49
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
49
50
  return poolPosition.publicKey
50
51
  }
51
52
 
@@ -12,7 +12,8 @@ import {
12
12
  } from '@solana/web3.js'
13
13
  import { parseAnchorErrors } from '../utils/Errors'
14
14
  import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
15
- import { Vault } from 'idl/vault'
15
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
16
+ import { Vault } from '../idl/vault'
16
17
 
17
18
  export async function depositStakingPool(
18
19
  program: Program<Vault>,
@@ -33,7 +34,7 @@ export async function depositStakingPool(
33
34
  overrideStartTime
34
35
  )
35
36
  )
36
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
37
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
37
38
  return poolPosition.publicKey
38
39
  }
39
40
 
@@ -19,7 +19,9 @@ import {
19
19
  getPoolPublicKeyForMint,
20
20
  getHedgeMintPublicKey,
21
21
  } from '../Constants'
22
- import { Vault } from 'idl/vault'
22
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
+ import { Vault } from '../idl/vault'
24
+ import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
23
25
 
24
26
  export async function depositVault(
25
27
  program: Program<Vault>,
@@ -35,13 +37,12 @@ export async function depositVault(
35
37
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
36
38
 
37
39
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
38
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
39
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
40
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
40
41
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
41
42
  provider.connection,
42
43
  payer,
43
44
  vaultTypeAccountInfo.collateralMint,
44
- vaultTypeAccountPublicKey,
45
+ vaultAccount.vaultType,
45
46
  true
46
47
  )
47
48
 
@@ -64,11 +65,10 @@ export async function depositVault(
64
65
 
65
66
  const transaction = new Transaction()
66
67
  const signers = [payer, history]
67
-
68
68
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
69
69
  program,
70
70
  provider,
71
- vaultTypeAccountPublicKey,
71
+ vaultAccount.vaultType,
72
72
  vaultPublicKey,
73
73
  depositAmount,
74
74
  0,
@@ -76,7 +76,7 @@ export async function depositVault(
76
76
  false
77
77
  )
78
78
 
79
- if (vaultAccount.collateralType === 'SOL') {
79
+ if (vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()) {
80
80
  transaction.add(
81
81
  SystemProgram.createAccount({
82
82
  fromPubkey: payer.publicKey,
@@ -98,11 +98,11 @@ export async function depositVault(
98
98
  program,
99
99
  vaultSystemStatePublicKey,
100
100
  payer.publicKey,
101
- vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount,
101
+ vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount,
102
102
  vaultPublicKey,
103
103
  vaultAssociatedCollateralAccountPublicKey,
104
104
  history.publicKey,
105
- vaultTypeAccountPublicKey,
105
+ vaultAccount.vaultType,
106
106
  vaultTypeAssociatedTokenAccount.address,
107
107
  hedgeStakingPoolPublicKey,
108
108
  hedgeStakingPoolAssociatedUshTokenAccount,
@@ -115,7 +115,7 @@ export async function depositVault(
115
115
  overrideTime
116
116
  )
117
117
  )
118
- if (vaultAccount.collateralType === 'SOL') {
118
+ if (vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()) {
119
119
  transaction.add(
120
120
  TokenInstructions.closeAccount({
121
121
  source: wrappedSolAccount.publicKey,
@@ -125,7 +125,7 @@ export async function depositVault(
125
125
  )
126
126
  }
127
127
 
128
- await sendAndConfirmTransaction(provider.connection, transaction, signers)
128
+ await sendAndConfirmWithDebug(provider.connection, transaction, signers)
129
129
  return vaultPublicKey
130
130
  }
131
131
 
@@ -19,7 +19,8 @@ import {
19
19
  getUshMintPublicKey,
20
20
  getVaultSystemStatePublicKey,
21
21
  } from '../Constants'
22
- import { Vault } from 'idl/vault'
22
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
+ import { Vault } from '../idl/vault'
23
24
 
24
25
  export async function initHedgeFoundation(program: Program<Vault>, provider: Provider, payer: Signer): Promise<PublicKey> {
25
26
  const poolEra = Keypair.generate()
@@ -27,7 +28,7 @@ export async function initHedgeFoundation(program: Program<Vault>, provider: Pro
27
28
  await initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey)
28
29
  )
29
30
 
30
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolEra]).catch(parseAnchorErrors)
31
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, poolEra]).catch(parseAnchorErrors)
31
32
  return payer.publicKey
32
33
  }
33
34
 
@@ -19,12 +19,13 @@ import {
19
19
  getUshMintPublicKey,
20
20
  getVaultSystemStatePublicKey,
21
21
  } from '../Constants'
22
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
22
23
 
23
24
  export async function initHedgeFoundationTokens(program: Program, provider: Provider, payer: Signer): Promise<PublicKey> {
24
25
  const poolEra = Keypair.generate()
25
26
  const transaction = new Transaction().add(await initHedgeFoundationTokensInstruction(program, payer.publicKey))
26
27
 
27
- await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
28
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
28
29
  return payer.publicKey
29
30
  }
30
31
 
@@ -1,6 +1,7 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { BN, Program, Provider, translateAddress } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
3
3
  import {
4
+ Connection,
4
5
  Keypair,
5
6
  PublicKey,
6
7
  sendAndConfirmTransaction,
@@ -20,7 +21,8 @@ import {
20
21
  getUshMintPublicKey,
21
22
  getVaultSystemStatePublicKey,
22
23
  } from '../Constants'
23
- import { Vault } from 'idl/vault'
24
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
+ import { Vault } from '../idl/vault'
24
26
 
25
27
  export async function liquidateVault(
26
28
  program: Program<Vault>,
@@ -31,8 +33,7 @@ export async function liquidateVault(
31
33
  ): Promise<PublicKey> {
32
34
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
33
35
 
34
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
35
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
36
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
36
37
  const collateralMint = vaultTypeAccountInfo.collateralMint
37
38
 
38
39
  const hedgeMintPublickey = await getHedgeMintPublicKey()
@@ -73,7 +74,7 @@ export async function liquidateVault(
73
74
  provider.connection,
74
75
  payer,
75
76
  collateralMint,
76
- vaultTypeAccountPublicKey,
77
+ vaultAccount.vaultType,
77
78
  true
78
79
  )
79
80
  const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
@@ -87,7 +88,7 @@ export async function liquidateVault(
87
88
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
88
89
  program,
89
90
  provider,
90
- vaultTypeAccountPublicKey,
91
+ vaultAccount.vaultType,
91
92
  vaultPublicKey,
92
93
  0,
93
94
  0,
@@ -119,11 +120,12 @@ export async function liquidateVault(
119
120
  oldSmallerPublicKey,
120
121
  newSmallerPublicKey,
121
122
  newLargerPublicKey,
122
- vaultAccount.collateralType,
123
+ vaultAccount.vaultType,
123
124
  overrideTime
124
125
  )
125
126
  )
126
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra])
127
+
128
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history, newEra])
127
129
  return vaultPublicKey
128
130
  }
129
131
 
@@ -146,13 +148,12 @@ export async function liquidateVaultInstruction(
146
148
  oldSmallerPublicKey: PublicKey,
147
149
  newSmallerPublicKey: PublicKey,
148
150
  newLargerPublicKey: PublicKey,
149
- collateralType: string,
151
+ vaultTypeAccount: PublicKey,
150
152
  overrideTime?: number
151
153
  ): Promise<TransactionInstruction> {
152
154
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
153
155
  const ushMintPublickey = await getUshMintPublicKey()
154
156
  const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
155
- const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
156
157
 
157
158
  return await program.methods
158
159
  .liquidateVault(
@@ -17,8 +17,12 @@ import {
17
17
  getVaultTypeAccountPublicKey,
18
18
  getUshMintPublicKey,
19
19
  getVaultSystemStatePublicKey,
20
+ HEDGE_PROGRAM_PUBLICKEY,
20
21
  } from '../Constants'
21
- import { Vault } from 'idl/vault'
22
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
+ import { Vault } from '../idl/vault'
24
+ import { parseAnchorErrors } from '../utils/Errors'
25
+ import { VaultAccount } from '../state/VaultAccount'
22
26
 
23
27
  export async function loanVault(
24
28
  program: Program<Vault>,
@@ -36,15 +40,14 @@ export async function loanVault(
36
40
  ushMintPublickey,
37
41
  payer.publicKey
38
42
  )
39
-
40
43
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
41
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
42
- const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
44
+ const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
45
+
43
46
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
44
47
  provider.connection,
45
48
  payer,
46
49
  vaultTypeAccount.collateralMint,
47
- vaultTypeAccountPublicKey,
50
+ vaultAccount.vaultType,
48
51
  true
49
52
  )
50
53
  const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
@@ -54,11 +57,10 @@ export async function loanVault(
54
57
  vaultPublicKey,
55
58
  true
56
59
  )
57
-
58
60
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
59
61
  program,
60
62
  provider,
61
- vaultTypeAccountPublicKey,
63
+ vaultAccount.vaultType,
62
64
  vaultPublicKey,
63
65
  0,
64
66
  loanAmount,
@@ -75,7 +77,7 @@ export async function loanVault(
75
77
  vaultPublicKey,
76
78
  vaultAssociatedTokenAccount.address,
77
79
  history.publicKey,
78
- vaultTypeAccountPublicKey,
80
+ vaultAccount.vaultType,
79
81
  vaultTypeAssociatedTokenAccount.address,
80
82
  oldSmallerPublicKey,
81
83
  newSmallerPublicKey,
@@ -84,7 +86,7 @@ export async function loanVault(
84
86
  overrideTime
85
87
  )
86
88
  )
87
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
89
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
88
90
  return vaultPublicKey
89
91
  }
90
92
 
@@ -19,7 +19,8 @@ import {
19
19
  getUshMintPublicKey,
20
20
  getVaultSystemStatePublicKey,
21
21
  } from '../Constants'
22
- import { Vault } from 'idl/vault'
22
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
+ import { Vault } from '../idl/vault'
23
24
 
24
25
  export async function redeemVault(
25
26
  program: Program<Vault>,
@@ -40,13 +41,12 @@ export async function redeemVault(
40
41
  )
41
42
 
42
43
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
43
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
44
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
44
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
45
45
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
46
46
  provider.connection,
47
47
  payer,
48
48
  vaultTypeAccountInfo.collateralMint,
49
- vaultTypeAccountPublicKey,
49
+ vaultAccount.vaultType,
50
50
  true
51
51
  )
52
52
 
@@ -68,7 +68,7 @@ export async function redeemVault(
68
68
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
69
69
  program,
70
70
  provider,
71
- vaultTypeAccountPublicKey,
71
+ vaultAccount.vaultType,
72
72
  vaultPublicKey,
73
73
  0,
74
74
  0,
@@ -86,7 +86,7 @@ export async function redeemVault(
86
86
  vaultPublicKey,
87
87
  vaultAssociatedTokenAccount.address,
88
88
  history.publicKey,
89
- vaultTypeAccountPublicKey,
89
+ vaultAccount.vaultType,
90
90
  vaultTypeAssociatedTokenAccount.address,
91
91
  oldSmallerPublicKey,
92
92
  newSmallerPublicKey,
@@ -95,7 +95,7 @@ export async function redeemVault(
95
95
  transactionOverrideTime
96
96
  )
97
97
  )
98
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
98
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
99
99
  return vaultPublicKey
100
100
  }
101
101
 
@@ -7,9 +7,11 @@ import {
7
7
  SystemProgram,
8
8
  Transaction,
9
9
  TransactionInstruction,
10
+ TransactionSignature,
10
11
  } from '@solana/web3.js'
11
- import { Vault } from 'idl/vault'
12
- import { HEDGE_PROGRAM_PUBLICKEY } from '../Constants'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
+ import { Vault } from '../idl/vault'
14
+ import { HEDGE_PROGRAM_PUBLICKEY, CHAINLINK_PROGRAM_ID } from '../Constants'
13
15
 
14
16
  export async function refreshOraclePrice(
15
17
  program: Program<Vault>,
@@ -19,11 +21,11 @@ export async function refreshOraclePrice(
19
21
  network: Cluster,
20
22
  overridePrice?: number,
21
23
  overrideTime?: number
22
- ): Promise<string> {
24
+ ): Promise<TransactionSignature | void> {
23
25
  const transaction = new Transaction().add(
24
26
  await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime)
25
27
  )
26
- return await sendAndConfirmTransaction(provider.connection, transaction, [payer])
28
+ return await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
27
29
  }
28
30
 
29
31
  export async function refreshOraclePriceInstruction(
@@ -51,10 +53,11 @@ export async function refreshOraclePriceInstruction(
51
53
  .accounts({
52
54
  oracleInfoAccount: oracleInfoAccount,
53
55
  vaultTypeAccount: vaultTypeAccount,
54
- oracleChainlink: chainlinkAccunts[network],
56
+ oracleChainlink: chainlinkAccounts[network],
55
57
  oraclePyth: pythAccounts[network],
56
58
  oracleSwitchboard: switchboardAccounts[network],
57
59
  systemProgram: SystemProgram.programId,
60
+ chainlinkProgram: CHAINLINK_PROGRAM_ID,
58
61
  })
59
62
  .instruction()
60
63
  }
@@ -70,7 +73,7 @@ const pythAccounts = {
70
73
  Devnet: new PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
71
74
  MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
72
75
  }
73
- const chainlinkAccunts = {
76
+ const chainlinkAccounts = {
74
77
  Testing: SystemProgram.programId,
75
78
  Devnet: new PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
76
79
  MainnetBeta: SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
@@ -18,7 +18,8 @@ import {
18
18
  getUshMintPublicKey,
19
19
  getVaultSystemStatePublicKey,
20
20
  } from '../Constants'
21
- import { Vault } from 'idl/vault'
21
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
22
+ import { Vault } from '../idl/vault'
22
23
 
23
24
  export async function repayVault(
24
25
  program: Program<Vault>,
@@ -39,10 +40,9 @@ export async function repayVault(
39
40
  )
40
41
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
41
42
 
42
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
43
- const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
43
+ const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
44
44
  const vaultTypeAssociatedTokenAccount = await findAssociatedTokenAddress(
45
- vaultTypeAccountPublicKey,
45
+ vaultAccount.vaultType,
46
46
  vaultTypeAccount.collateralMint
47
47
  )
48
48
  const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, vaultTypeAccount.collateralMint)
@@ -50,7 +50,7 @@ export async function repayVault(
50
50
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
51
51
  program,
52
52
  provider,
53
- vaultTypeAccountPublicKey,
53
+ vaultAccount.vaultType,
54
54
  vaultPublicKey,
55
55
  0,
56
56
  repayAmount * -1,
@@ -67,7 +67,7 @@ export async function repayVault(
67
67
  vaultPublicKey,
68
68
  vaultAssociatedTokenAccount,
69
69
  history.publicKey,
70
- vaultTypeAccountPublicKey,
70
+ vaultAccount.vaultType,
71
71
  vaultTypeAssociatedTokenAccount,
72
72
  oldSmallerPublicKey,
73
73
  newSmallerPublicKey,
@@ -76,7 +76,7 @@ export async function repayVault(
76
76
  overrideTime
77
77
  )
78
78
  )
79
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
79
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
80
80
  return vaultPublicKey
81
81
  }
82
82
 
@@ -22,7 +22,8 @@ import {
22
22
  } from '../Constants'
23
23
 
24
24
  import { parseAnchorErrors } from '../utils/Errors'
25
- import { Vault } from 'idl/vault'
25
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
26
+ import { Vault } from '../idl/vault'
26
27
 
27
28
  export async function setHalted(
28
29
  program: Program<Vault>,
@@ -36,7 +37,7 @@ export async function setHalted(
36
37
  await setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted)
37
38
  )
38
39
 
39
- await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
40
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
40
41
  return vaultSystemStatePublicKey
41
42
  }
42
43
 
@@ -21,7 +21,8 @@ import {
21
21
 
22
22
  import { v4 as uuidv4 } from 'uuid'
23
23
  import { parseAnchorErrors } from '../utils/Errors'
24
- import { Vault } from 'idl/vault'
24
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
+ import { Vault } from '../idl/vault'
25
26
 
26
27
  export interface VaultTypeConfig {
27
28
  maxDebtExtended?: BN
@@ -32,6 +33,10 @@ export interface VaultTypeConfig {
32
33
  oraclePyth?: PublicKey
33
34
  oracleSwitchboard?: PublicKey
34
35
 
36
+ priorityPyth?: number,
37
+ priorityChainlink?: number,
38
+ prioritySwitchboard?: number,
39
+
35
40
  deprecated?: boolean
36
41
  }
37
42
 
@@ -55,7 +60,7 @@ export async function updateVaultType(
55
60
  )
56
61
  )
57
62
 
58
- await sendAndConfirmTransaction(provider.connection, transaction, [payer])
63
+ await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
59
64
  return vaultSystemStatePublicKey
60
65
  }
61
66
 
@@ -75,6 +80,9 @@ export async function updateVaultTypeStatusInstruction(
75
80
  oraclePyth: vaultTypeConfig.oraclePyth ?? null,
76
81
  oracleSwitchboard: vaultTypeConfig.oracleSwitchboard ?? null,
77
82
  deprecated: vaultTypeConfig.deprecated ?? null,
83
+ priorityPyth: vaultTypeConfig.priorityPyth ?? null,
84
+ priorityChainlink: vaultTypeConfig.priorityChainlink ?? null,
85
+ prioritySwitchboard: vaultTypeConfig.prioritySwitchboard ?? null,
78
86
  }
79
87
 
80
88
  return await program.methods