hedge-web3 0.1.43 → 0.1.44

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 (35) hide show
  1. package/declarations/Constants.d.ts +1 -1
  2. package/declarations/idl/vault.d.ts +26 -5
  3. package/declarations/instructions/liquidateVault.d.ts +1 -1
  4. package/declarations/state/VaultAccount.d.ts +8 -6
  5. package/declarations/state/VaultType.d.ts +24 -0
  6. package/declarations/utils/Sender.d.ts +2 -0
  7. package/declarations/utils/sendAndConfirmWithDebug.d.ts +2 -0
  8. package/lib/Constants.js +1 -1
  9. package/lib/idl/vault.js +26 -5
  10. package/lib/instructions/createStakingPool.js +1 -0
  11. package/lib/instructions/depositVault.js +7 -7
  12. package/lib/instructions/liquidateVault.js +5 -7
  13. package/lib/instructions/loanVault.js +7 -6
  14. package/lib/instructions/redeemVault.js +4 -5
  15. package/lib/instructions/refreshOraclePrice.js +2 -2
  16. package/lib/instructions/repayVault.js +4 -5
  17. package/lib/instructions/withdrawVault.js +4 -5
  18. package/lib/state/VaultAccount.js +9 -8
  19. package/lib/state/VaultType.js +32 -0
  20. package/lib/utils/Sender.js +32 -0
  21. package/lib/utils/getLinkedListAccounts.js +15 -15
  22. package/lib/utils/sendAndConfirmWithDebug.js +35 -0
  23. package/package.json +1 -1
  24. package/src/Constants.ts +1 -1
  25. package/src/idl/vault.ts +52 -10
  26. package/src/instructions/createStakingPool.ts +1 -0
  27. package/src/instructions/depositVault.ts +8 -8
  28. package/src/instructions/liquidateVault.ts +5 -7
  29. package/src/instructions/loanVault.ts +11 -8
  30. package/src/instructions/redeemVault.ts +4 -5
  31. package/src/instructions/refreshOraclePrice.ts +2 -2
  32. package/src/instructions/repayVault.ts +4 -5
  33. package/src/instructions/withdrawVault.ts +4 -5
  34. package/src/state/VaultAccount.ts +14 -10
  35. package/src/utils/getLinkedListAccounts.ts +16 -16
@@ -21,13 +21,14 @@ const decimal_js_1 = __importDefault(require("decimal.js"));
21
21
  const bs58_1 = __importDefault(require("bs58"));
22
22
  function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, loanAmount, redeem, liquidate, cachedVaults) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- console.log('Getting getLinkedListAccounts');
24
+ // console.log('Getting getLinkedListAccounts')
25
25
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
26
26
  // Default for null is the vault itself, so set them all to this vault
27
27
  let oldSmallerPublicKey = vaultPublicKey;
28
28
  let newSmallerPublicKey = vaultPublicKey;
29
29
  let newLargerPublicKey = vaultPublicKey;
30
30
  const thisVaultData = yield program.account.vault.fetch(vaultPublicKey);
31
+ const accountInfo = yield program.provider.connection.getAccountInfo(vaultPublicKey);
31
32
  const thisVault = new VaultAccount_1.VaultAccount(thisVaultData, vaultPublicKey);
32
33
  // Load all the vaults
33
34
  let vaults;
@@ -50,10 +51,10 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
50
51
  // vaults = allVaults.map((vault) => {
51
52
  // return new VaultAccount(vault.account, vault.publicKey)
52
53
  // })
53
- vaults = yield getMiniVaults(program, vaultTypeAccount.collateralType);
54
+ vaults = yield getMiniVaults(program, vaultTypeAccount.vaultTypeName);
54
55
  }
55
- console.log('Vault count found:', vaults.length);
56
- console.log('First Vault', vaults[0]);
56
+ // console.log('Vault count found:', vaults.length)
57
+ // console.log('First Vault', vaults[0])
57
58
  // Filter out the accounts that are not open
58
59
  // TODO filter on vault status. Or we enable people to "close out" empty vaults
59
60
  // vaults = _.filter(vaults, (vault) => {
@@ -76,6 +77,11 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
76
77
  if (indexBefore > 0) {
77
78
  oldSmallerPublicKey = vaults[indexBefore - 1].publicKey;
78
79
  }
80
+ // Pretty print the list again
81
+ // console.log('Sorted open vaults. Index Before: ', indexBefore)
82
+ // console.log(vaults.map((vault) => {
83
+ // return vault.toString(vaultPublicKey)
84
+ // }))
79
85
  // Pretty print all the vaults before the operation
80
86
  // console.log('Sorted open vaults BEFORE at index:', indexBefore)
81
87
  // let correctOrderBefore = true
@@ -89,7 +95,7 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
89
95
  // }
90
96
  // }
91
97
  // if (correctOrderBefore) {
92
- // console.log(`Verfied the on-chain order of vault type:`, vaultTypeAccount.collateralType)
98
+ // console.log(`Verified the on-chain order of vault type:`, vaultTypeAccount.collateralType)
93
99
  // } else {
94
100
  // throw new Error('On-Chian vaults not in order!')
95
101
  // }
@@ -104,7 +110,7 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
104
110
  vaults[indexBefore] = thisVault;
105
111
  }
106
112
  // Now that we know it's def in the list, iterate the list and update
107
- // this vault with the opeation we're going to apply
113
+ // this vault with the operation we're going to apply
108
114
  const newNormalizedDebt = new decimal_js_1.default(loanAmount);
109
115
  const vaultTypeCompoundedInterest = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccount.cumulativeRate.toString());
110
116
  vaults[indexBefore].updateDebtAndCollateral(vaultTypeAccount);
@@ -121,11 +127,6 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
121
127
  }
122
128
  // Sort it again since we've changed one vault
123
129
  vaults = vaults.sort(sortVaults);
124
- // Pretty print the list again
125
- // console.log('Sorted open vaults with new debt added at index: ', indexAfter)
126
- // console.log(vaults.map((vault) => {
127
- // return vault.toString(vaultPublicKey)
128
- // }))
129
130
  // Search for the vaults new position
130
131
  let indexAfter = -1;
131
132
  vaults.forEach((vault, index) => {
@@ -141,8 +142,7 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
141
142
  // })
142
143
  // )
143
144
  // Print where it moved from / to
144
- console.log('Index Before', indexBefore);
145
- console.log('Index After', indexAfter);
145
+ // console.log('Index After', indexAfter)
146
146
  // Save references to the new left and right
147
147
  if (indexAfter > 0) {
148
148
  newSmallerPublicKey = vaults[indexAfter - 1].publicKey;
@@ -168,7 +168,7 @@ function sortVaults(a, b) {
168
168
  }
169
169
  return aRatio - bRatio;
170
170
  }
171
- function getMiniVaults(program, collateralType) {
171
+ function getMiniVaults(program, vaultTypeName) {
172
172
  return __awaiter(this, void 0, void 0, function* () {
173
173
  const filters = [
174
174
  // Filter for Vault Accounts
@@ -179,7 +179,7 @@ function getMiniVaults(program, collateralType) {
179
179
  // Filter for Vaults with this collateral type
180
180
  {
181
181
  memcmp: {
182
- bytes: bs58_1.default.encode(VaultAccount_1.VaultAccount.getBufferForString(collateralType)),
182
+ bytes: bs58_1.default.encode(VaultAccount_1.VaultAccount.getBufferForString(vaultTypeName)),
183
183
  offset: 8 + 32 + 24,
184
184
  },
185
185
  },
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ function sendAndConfirmWithDebug(connection, transaction, signers) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ return connection
15
+ .sendTransaction(transaction, signers)
16
+ .then((signature) => {
17
+ return connection
18
+ .confirmTransaction(signature)
19
+ .then((signatureContext) => {
20
+ return signature;
21
+ })
22
+ .catch((error) => {
23
+ console.log('There was an error confirming the transaction', error);
24
+ console.trace();
25
+ throw error;
26
+ });
27
+ })
28
+ .catch((error) => {
29
+ console.log('There was an error sending the transaction', error);
30
+ console.trace();
31
+ throw error;
32
+ });
33
+ });
34
+ }
35
+ exports.default = sendAndConfirmWithDebug;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.43",
3
+ "version": "0.1.44",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/Constants.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from '@solana/spl-token'
5
5
  import { PublicKey } from '@solana/web3.js'
6
6
 
7
- export const HEDGE_PROGRAM_ID = 'HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ'
7
+ export const HEDGE_PROGRAM_ID = 'zooJaircVAoQ4e7EXRDocnsbB7UPYQ6J7bKyZEMh784'
8
8
  export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
9
9
 
10
10
  export const CHAINLINK_SOL_USD_ID =
package/src/idl/vault.ts CHANGED
@@ -1844,7 +1844,7 @@ export type Vault = {
1844
1844
  "kind": "struct",
1845
1845
  "fields": [
1846
1846
  {
1847
- "name": "collateralType",
1847
+ "name": "vaultTypeName",
1848
1848
  "type": "string"
1849
1849
  },
1850
1850
  {
@@ -1858,6 +1858,10 @@ export type Vault = {
1858
1858
  {
1859
1859
  "name": "oracleSwitchboard",
1860
1860
  "type": "publicKey"
1861
+ },
1862
+ {
1863
+ "name": "vaultType",
1864
+ "type": "publicKey"
1861
1865
  }
1862
1866
  ]
1863
1867
  }
@@ -2102,7 +2106,7 @@ export type Vault = {
2102
2106
  "kind": "struct",
2103
2107
  "fields": [
2104
2108
  {
2105
- "name": "collateralType",
2109
+ "name": "vaultTypeName",
2106
2110
  "type": "string"
2107
2111
  },
2108
2112
  {
@@ -2186,6 +2190,14 @@ export type Vault = {
2186
2190
  {
2187
2191
  "name": "deprecated",
2188
2192
  "type": "bool"
2193
+ },
2194
+ {
2195
+ "name": "totalFeesAccumulatedUsh",
2196
+ "type": "u128"
2197
+ },
2198
+ {
2199
+ "name": "totalFeesAccumulatedCollateral",
2200
+ "type": "u128"
2189
2201
  }
2190
2202
  ]
2191
2203
  }
@@ -2212,7 +2224,7 @@ export type Vault = {
2212
2224
  "type": "u64"
2213
2225
  },
2214
2226
  {
2215
- "name": "collateralType",
2227
+ "name": "vaultTypeName",
2216
2228
  "type": "string"
2217
2229
  },
2218
2230
  {
@@ -2260,6 +2272,10 @@ export type Vault = {
2260
2272
  "type": {
2261
2273
  "option": "publicKey"
2262
2274
  }
2275
+ },
2276
+ {
2277
+ "name": "vaultType",
2278
+ "type": "publicKey"
2263
2279
  }
2264
2280
  ]
2265
2281
  }
@@ -2673,8 +2689,8 @@ export type Vault = {
2673
2689
  },
2674
2690
  {
2675
2691
  "code": 6020,
2676
- "name": "RedeemingNonHighestCollateralRatioVault",
2677
- "msg": "Can only redeem highest collateral ratio vault in system."
2692
+ "name": "NotRedeemingLowestCollateralRatioVault",
2693
+ "msg": "Can only redeem lowest collateral ratio vault in system."
2678
2694
  },
2679
2695
  {
2680
2696
  "code": 6021,
@@ -2688,6 +2704,11 @@ export type Vault = {
2688
2704
  },
2689
2705
  {
2690
2706
  "code": 6023,
2707
+ "name": "InvalidSaltLength",
2708
+ "msg": "Salt for new vaults must be of length 8"
2709
+ },
2710
+ {
2711
+ "code": 6024,
2691
2712
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2692
2713
  "msg": "New Max debt extended value is less than the current debt!"
2693
2714
  }
@@ -4540,7 +4561,7 @@ export const IDL: Vault = {
4540
4561
  "kind": "struct",
4541
4562
  "fields": [
4542
4563
  {
4543
- "name": "collateralType",
4564
+ "name": "vaultTypeName",
4544
4565
  "type": "string"
4545
4566
  },
4546
4567
  {
@@ -4554,6 +4575,10 @@ export const IDL: Vault = {
4554
4575
  {
4555
4576
  "name": "oracleSwitchboard",
4556
4577
  "type": "publicKey"
4578
+ },
4579
+ {
4580
+ "name": "vaultType",
4581
+ "type": "publicKey"
4557
4582
  }
4558
4583
  ]
4559
4584
  }
@@ -4798,7 +4823,7 @@ export const IDL: Vault = {
4798
4823
  "kind": "struct",
4799
4824
  "fields": [
4800
4825
  {
4801
- "name": "collateralType",
4826
+ "name": "vaultTypeName",
4802
4827
  "type": "string"
4803
4828
  },
4804
4829
  {
@@ -4882,6 +4907,14 @@ export const IDL: Vault = {
4882
4907
  {
4883
4908
  "name": "deprecated",
4884
4909
  "type": "bool"
4910
+ },
4911
+ {
4912
+ "name": "totalFeesAccumulatedUsh",
4913
+ "type": "u128"
4914
+ },
4915
+ {
4916
+ "name": "totalFeesAccumulatedCollateral",
4917
+ "type": "u128"
4885
4918
  }
4886
4919
  ]
4887
4920
  }
@@ -4908,7 +4941,7 @@ export const IDL: Vault = {
4908
4941
  "type": "u64"
4909
4942
  },
4910
4943
  {
4911
- "name": "collateralType",
4944
+ "name": "vaultTypeName",
4912
4945
  "type": "string"
4913
4946
  },
4914
4947
  {
@@ -4956,6 +4989,10 @@ export const IDL: Vault = {
4956
4989
  "type": {
4957
4990
  "option": "publicKey"
4958
4991
  }
4992
+ },
4993
+ {
4994
+ "name": "vaultType",
4995
+ "type": "publicKey"
4959
4996
  }
4960
4997
  ]
4961
4998
  }
@@ -5369,8 +5406,8 @@ export const IDL: Vault = {
5369
5406
  },
5370
5407
  {
5371
5408
  "code": 6020,
5372
- "name": "RedeemingNonHighestCollateralRatioVault",
5373
- "msg": "Can only redeem highest collateral ratio vault in system."
5409
+ "name": "NotRedeemingLowestCollateralRatioVault",
5410
+ "msg": "Can only redeem lowest collateral ratio vault in system."
5374
5411
  },
5375
5412
  {
5376
5413
  "code": 6021,
@@ -5384,6 +5421,11 @@ export const IDL: Vault = {
5384
5421
  },
5385
5422
  {
5386
5423
  "code": 6023,
5424
+ "name": "InvalidSaltLength",
5425
+ "msg": "Salt for new vaults must be of length 8"
5426
+ },
5427
+ {
5428
+ "code": 6024,
5387
5429
  "name": "UpdateVaultTypeBadMaxDebtExtended",
5388
5430
  "msg": "New Max debt extended value is less than the current debt!"
5389
5431
  }
@@ -41,6 +41,7 @@ export async function createStakingPoolInstruction(
41
41
  hedgeTokensToBeMinted: number,
42
42
  overrideStartTime?: number
43
43
  ): Promise<TransactionInstruction> {
44
+ console.log("new createStakingPoolInstruction")
44
45
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
45
46
  const ushMintPublickey = await getUshMintPublicKey()
46
47
  const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
@@ -20,6 +20,7 @@ import {
20
20
  getHedgeMintPublicKey,
21
21
  } from '../Constants'
22
22
  import { Vault } from 'idl/vault'
23
+ import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
23
24
 
24
25
  export async function depositVault(
25
26
  program: Program<Vault>,
@@ -35,13 +36,12 @@ export async function depositVault(
35
36
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
36
37
 
37
38
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
38
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
39
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
39
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
40
40
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
41
41
  provider.connection,
42
42
  payer,
43
43
  vaultTypeAccountInfo.collateralMint,
44
- vaultTypeAccountPublicKey,
44
+ vaultAccount.vaultType,
45
45
  true
46
46
  )
47
47
 
@@ -68,7 +68,7 @@ export async function depositVault(
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,
@@ -31,8 +31,7 @@ export async function liquidateVault(
31
31
  ): Promise<PublicKey> {
32
32
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
33
33
 
34
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
35
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
34
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
36
35
  const collateralMint = vaultTypeAccountInfo.collateralMint
37
36
 
38
37
  const hedgeMintPublickey = await getHedgeMintPublicKey()
@@ -73,7 +72,7 @@ export async function liquidateVault(
73
72
  provider.connection,
74
73
  payer,
75
74
  collateralMint,
76
- vaultTypeAccountPublicKey,
75
+ vaultAccount.vaultType,
77
76
  true
78
77
  )
79
78
  const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
@@ -87,7 +86,7 @@ export async function liquidateVault(
87
86
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
88
87
  program,
89
88
  provider,
90
- vaultTypeAccountPublicKey,
89
+ vaultAccount.vaultType,
91
90
  vaultPublicKey,
92
91
  0,
93
92
  0,
@@ -119,7 +118,7 @@ export async function liquidateVault(
119
118
  oldSmallerPublicKey,
120
119
  newSmallerPublicKey,
121
120
  newLargerPublicKey,
122
- vaultAccount.collateralType,
121
+ vaultAccount.vaultType,
123
122
  overrideTime
124
123
  )
125
124
  )
@@ -146,13 +145,12 @@ export async function liquidateVaultInstruction(
146
145
  oldSmallerPublicKey: PublicKey,
147
146
  newSmallerPublicKey: PublicKey,
148
147
  newLargerPublicKey: PublicKey,
149
- collateralType: string,
148
+ vaultTypeAccount: PublicKey,
150
149
  overrideTime?: number
151
150
  ): Promise<TransactionInstruction> {
152
151
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
153
152
  const ushMintPublickey = await getUshMintPublicKey()
154
153
  const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
155
- const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
156
154
 
157
155
  return await program.methods
158
156
  .liquidateVault(
@@ -17,8 +17,13 @@ import {
17
17
  getVaultTypeAccountPublicKey,
18
18
  getUshMintPublicKey,
19
19
  getVaultSystemStatePublicKey,
20
+ HEDGE_PROGRAM_PUBLICKEY,
20
21
  } from '../Constants'
21
22
  import { Vault } from 'idl/vault'
23
+ import { parseAnchorErrors } from '../utils/Errors'
24
+ import { VaultAccount } from '../state/VaultAccount'
25
+
26
+ const fs = require('fs');
22
27
 
23
28
  export async function loanVault(
24
29
  program: Program<Vault>,
@@ -36,15 +41,14 @@ export async function loanVault(
36
41
  ushMintPublickey,
37
42
  payer.publicKey
38
43
  )
39
-
40
44
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
41
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
42
- const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
45
+ const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
46
+
43
47
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
44
48
  provider.connection,
45
49
  payer,
46
50
  vaultTypeAccount.collateralMint,
47
- vaultTypeAccountPublicKey,
51
+ vaultAccount.vaultType,
48
52
  true
49
53
  )
50
54
  const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
@@ -54,11 +58,10 @@ export async function loanVault(
54
58
  vaultPublicKey,
55
59
  true
56
60
  )
57
-
58
61
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
59
62
  program,
60
63
  provider,
61
- vaultTypeAccountPublicKey,
64
+ vaultAccount.vaultType,
62
65
  vaultPublicKey,
63
66
  0,
64
67
  loanAmount,
@@ -75,7 +78,7 @@ export async function loanVault(
75
78
  vaultPublicKey,
76
79
  vaultAssociatedTokenAccount.address,
77
80
  history.publicKey,
78
- vaultTypeAccountPublicKey,
81
+ vaultAccount.vaultType,
79
82
  vaultTypeAssociatedTokenAccount.address,
80
83
  oldSmallerPublicKey,
81
84
  newSmallerPublicKey,
@@ -84,7 +87,7 @@ export async function loanVault(
84
87
  overrideTime
85
88
  )
86
89
  )
87
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
90
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, history]).catch(parseAnchorErrors)
88
91
  return vaultPublicKey
89
92
  }
90
93
 
@@ -40,13 +40,12 @@ export async function redeemVault(
40
40
  )
41
41
 
42
42
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
43
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
44
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
43
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
45
44
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
46
45
  provider.connection,
47
46
  payer,
48
47
  vaultTypeAccountInfo.collateralMint,
49
- vaultTypeAccountPublicKey,
48
+ vaultAccount.vaultType,
50
49
  true
51
50
  )
52
51
 
@@ -68,7 +67,7 @@ export async function redeemVault(
68
67
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
69
68
  program,
70
69
  provider,
71
- vaultTypeAccountPublicKey,
70
+ vaultAccount.vaultType,
72
71
  vaultPublicKey,
73
72
  0,
74
73
  0,
@@ -86,7 +85,7 @@ export async function redeemVault(
86
85
  vaultPublicKey,
87
86
  vaultAssociatedTokenAccount.address,
88
87
  history.publicKey,
89
- vaultTypeAccountPublicKey,
88
+ vaultAccount.vaultType,
90
89
  vaultTypeAssociatedTokenAccount.address,
91
90
  oldSmallerPublicKey,
92
91
  newSmallerPublicKey,
@@ -51,7 +51,7 @@ export async function refreshOraclePriceInstruction(
51
51
  .accounts({
52
52
  oracleInfoAccount: oracleInfoAccount,
53
53
  vaultTypeAccount: vaultTypeAccount,
54
- oracleChainlink: chainlinkAccunts[network],
54
+ oracleChainlink: chainlinkAccounts[network],
55
55
  oraclePyth: pythAccounts[network],
56
56
  oracleSwitchboard: switchboardAccounts[network],
57
57
  systemProgram: SystemProgram.programId,
@@ -70,7 +70,7 @@ const pythAccounts = {
70
70
  Devnet: new PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
71
71
  MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
72
72
  }
73
- const chainlinkAccunts = {
73
+ const chainlinkAccounts = {
74
74
  Testing: SystemProgram.programId,
75
75
  Devnet: new PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
76
76
  MainnetBeta: SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
@@ -39,10 +39,9 @@ export async function repayVault(
39
39
  )
40
40
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
41
41
 
42
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
43
- const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
42
+ const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
44
43
  const vaultTypeAssociatedTokenAccount = await findAssociatedTokenAddress(
45
- vaultTypeAccountPublicKey,
44
+ vaultAccount.vaultType,
46
45
  vaultTypeAccount.collateralMint
47
46
  )
48
47
  const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, vaultTypeAccount.collateralMint)
@@ -50,7 +49,7 @@ export async function repayVault(
50
49
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
51
50
  program,
52
51
  provider,
53
- vaultTypeAccountPublicKey,
52
+ vaultAccount.vaultType,
54
53
  vaultPublicKey,
55
54
  0,
56
55
  repayAmount * -1,
@@ -67,7 +66,7 @@ export async function repayVault(
67
66
  vaultPublicKey,
68
67
  vaultAssociatedTokenAccount,
69
68
  history.publicKey,
70
- vaultTypeAccountPublicKey,
69
+ vaultAccount.vaultType,
71
70
  vaultTypeAssociatedTokenAccount,
72
71
  oldSmallerPublicKey,
73
72
  newSmallerPublicKey,
@@ -37,7 +37,6 @@ export async function withdrawVault(
37
37
  const history = Keypair.generate()
38
38
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
39
39
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
40
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
41
40
  const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
42
41
  provider.connection,
43
42
  payer,
@@ -46,12 +45,12 @@ export async function withdrawVault(
46
45
  true
47
46
  )
48
47
 
49
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
48
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
50
49
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
51
50
  provider.connection,
52
51
  payer,
53
52
  vaultTypeAccountInfo.collateralMint,
54
- vaultTypeAccountPublicKey,
53
+ vaultAccount.vaultType,
55
54
  true
56
55
  )
57
56
 
@@ -70,7 +69,7 @@ export async function withdrawVault(
70
69
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
71
70
  program,
72
71
  provider,
73
- vaultTypeAccountPublicKey,
72
+ vaultAccount.vaultType,
74
73
  vaultPublicKey,
75
74
  withdrawAmount * -1,
76
75
  0,
@@ -86,7 +85,7 @@ export async function withdrawVault(
86
85
  destinationTokenAccount.address,
87
86
  vaultPublicKey,
88
87
  vaultAssociatedCollateralAccount.address,
89
- vaultTypeAccountPublicKey,
88
+ vaultAccount.vaultType,
90
89
  vaultTypeAssociatedTokenAccount.address,
91
90
  hedgeStakingPoolPublicKey,
92
91
  hedgeStakingPoolAssociatedUshTokenAccount,