hedge-web3 0.1.46 → 0.1.50

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.
@@ -32,7 +32,11 @@ const borsh = __importStar(require("@project-serum/borsh"));
32
32
  */
33
33
  class VaultAccount {
34
34
  constructor(vault, publicKey) {
35
- var _a, _b, _c;
35
+ var _a;
36
+ /** The deposited collateral of the vault (in SOL Lamports). */
37
+ this.deposited = new decimal_js_1.default(0);
38
+ /** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
39
+ this.denormalizedDebt = new decimal_js_1.default(0);
36
40
  /** Debt redistribution snapshot */
37
41
  this.debtProductSnapshotBytes = new decimal_js_1.default(0);
38
42
  /** Collateral redistribution snapshot' */
@@ -43,20 +47,23 @@ class VaultAccount {
43
47
  this.vaultOwner = vault.vaultOwner;
44
48
  this.vaultNumber = (_a = vault.vaultNumber) === null || _a === void 0 ? void 0 : _a.toNumber();
45
49
  this.pdaSalt = vault.pdaSalt;
46
- this.deposited = (_b = vault.deposited) === null || _b === void 0 ? void 0 : _b.toNumber();
47
- this.denormalizedDebt = (_c = vault.denormalizedDebt) === null || _c === void 0 ? void 0 : _c.toNumber();
50
+ if (vault.deposited) {
51
+ this.deposited = new decimal_js_1.default(vault.deposited.toString());
52
+ }
53
+ if (vault.denormalizedDebt) {
54
+ this.denormalizedDebt = new decimal_js_1.default(vault.denormalizedDebt.toString());
55
+ }
48
56
  if (vault.debtProductSnapshotBytes) {
49
57
  this.debtProductSnapshotBytes = (0, HedgeDecimal_1.DecimalFromU128)(vault.debtProductSnapshotBytes.toString());
50
58
  }
51
59
  if (vault.collateralAccumulatorSnapshotBytes) {
52
60
  this.collateralAccumulatorSnapshotBytes = (0, HedgeDecimal_1.DecimalFromU128)(vault.collateralAccumulatorSnapshotBytes.toString());
53
61
  }
54
- this.vaultTypeName = vault.vaultTypeName;
62
+ this.collateralType = vault.collateralType;
55
63
  this.nextVaultToRedeem = vault.nextVaultToRedeem;
56
64
  if (vault.vaultStatus) {
57
65
  this.vaultStatus = Object.keys(vault.vaultStatus)[0];
58
66
  }
59
- this.vaultType = vault.vaultType;
60
67
  }
61
68
  /**
62
69
  * Check if some `PublicKey` is the owner
@@ -73,7 +80,7 @@ class VaultAccount {
73
80
  * @returns collateral value in SOL
74
81
  */
75
82
  inSol() {
76
- return this.deposited / web3_js_1.LAMPORTS_PER_SOL;
83
+ return this.deposited.div(web3_js_1.LAMPORTS_PER_SOL).toNumber();
77
84
  }
78
85
  /**
79
86
  * Get the debt value in USH
@@ -81,7 +88,7 @@ class VaultAccount {
81
88
  * @returns debt value in USH
82
89
  */
83
90
  inUsd() {
84
- return this.denormalizedDebt / web3_js_1.LAMPORTS_PER_SOL;
91
+ return this.denormalizedDebt.div(web3_js_1.LAMPORTS_PER_SOL).toNumber();
85
92
  }
86
93
  /**
87
94
  * Pretty print the vault publickey for easy display
@@ -95,31 +102,30 @@ class VaultAccount {
95
102
  }
96
103
  addDebt(newNormalizedDebt, vaultTypeCompoundedInterest) {
97
104
  const denormalizedNewDebt = newNormalizedDebt.div(vaultTypeCompoundedInterest);
98
- this.denormalizedDebt = denormalizedNewDebt.add(new decimal_js_1.default(this.denormalizedDebt)).floor().toNumber();
105
+ this.denormalizedDebt = denormalizedNewDebt.add(new decimal_js_1.default(this.denormalizedDebt)).floor();
99
106
  // this.denormalizedDebt = parseFloat(this.denormalizedDebt.toFixed(0))
100
107
  }
101
108
  addDeposit(depositAmount) {
102
- this.deposited += depositAmount;
109
+ this.deposited = this.deposited.add(depositAmount);
103
110
  }
104
111
  redeem() {
105
112
  // TODO - Calculate actual redeem amount and adust correctly
106
- this.denormalizedDebt = 0;
113
+ this.denormalizedDebt = new decimal_js_1.default(0);
107
114
  this.vaultStatus = 'initialized';
108
115
  }
109
116
  liquidate() {
110
117
  // TODO - Calculate actual liquidate amount and adust correctly
111
- this.denormalizedDebt = 0;
118
+ this.denormalizedDebt = new decimal_js_1.default(0);
112
119
  this.vaultStatus = 'liquidated';
113
120
  }
114
- updateDebtAndCollateral(vaultTypeAccountData) {
115
- const debtProductCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccountData.debtRedistributionProduct);
116
- const collateralAccumulatorCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccountData.collateralRedistributionAccumulator);
121
+ updateDebtAndCollateral(vaultTypeAccuntData) {
122
+ const debtProductCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccuntData.debtRedistributionProduct);
123
+ const collateralAccumulatorCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccuntData.collateralRedistributionAccumulator);
117
124
  this.denormalizedDebt = debtProductCurrent
118
125
  .div(this.debtProductSnapshotBytes)
119
- .mul(new decimal_js_1.default(this.denormalizedDebt))
120
- .toNumber();
121
- const extraCollateralDeposited = this.denormalizedDebt * collateralAccumulatorCurrent.sub(this.collateralAccumulatorSnapshotBytes).toNumber();
122
- this.deposited += extraCollateralDeposited;
126
+ .mul(new decimal_js_1.default(this.denormalizedDebt));
127
+ const extraCollateralDeposited = this.denormalizedDebt.mul(collateralAccumulatorCurrent.sub(this.collateralAccumulatorSnapshotBytes));
128
+ this.deposited = this.deposited.add(extraCollateralDeposited);
123
129
  this.collateralAccumulatorSnapshotBytes = collateralAccumulatorCurrent;
124
130
  this.debtProductSnapshotBytes = debtProductCurrent;
125
131
  }
@@ -129,14 +135,14 @@ class VaultAccount {
129
135
  arrow = ' <----!!';
130
136
  }
131
137
  let collateralRatio = 'Infinite';
132
- if (this.denormalizedDebt > 0) {
138
+ if (this.denormalizedDebt.greaterThan(0)) {
133
139
  collateralRatio = new decimal_js_1.default(this.deposited).div(new decimal_js_1.default(this.denormalizedDebt)).toString();
134
140
  }
135
141
  let nextVault = 'None';
136
142
  if (this.nextVaultToRedeem) {
137
143
  nextVault = this.nextVaultToRedeem.toString().substring(0, 6);
138
144
  }
139
- return `Vault(${this.vaultNumber}): ${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `;
145
+ return `Vault(${this.vaultNumber}): ${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} NextVault: ${nextVault} ${arrow} `;
140
146
  }
141
147
  /**
142
148
  * Creates a VaultAccount from a slice of data
@@ -21,14 +21,13 @@ 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);
32
31
  const thisVault = new VaultAccount_1.VaultAccount(thisVaultData, vaultPublicKey);
33
32
  // Load all the vaults
34
33
  let vaults;
@@ -51,10 +50,10 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
51
50
  // vaults = allVaults.map((vault) => {
52
51
  // return new VaultAccount(vault.account, vault.publicKey)
53
52
  // })
54
- vaults = yield getMiniVaults(program, vaultTypeAccount.vaultTypeName);
53
+ vaults = yield getMiniVaults(program, vaultTypeAccount.collateralType);
55
54
  }
56
- // console.log('Vault count found:', vaults.length)
57
- // console.log('First Vault', vaults[0])
55
+ console.log('Vault count found:', vaults.length);
56
+ console.log('First Vault', vaults[0]);
58
57
  // Filter out the accounts that are not open
59
58
  // TODO filter on vault status. Or we enable people to "close out" empty vaults
60
59
  // vaults = _.filter(vaults, (vault) => {
@@ -62,7 +61,7 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
62
61
  // })
63
62
  // Remove any vaults with no debt or collateral
64
63
  vaults = underscore_1.default.filter(vaults, (vault) => {
65
- return vault.denormalizedDebt > 0 && vault.deposited > 0;
64
+ return vault.denormalizedDebt.greaterThan(0) && vault.deposited.greaterThan(0);
66
65
  });
67
66
  // Sort them
68
67
  vaults.sort(sortVaults);
@@ -77,11 +76,6 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
77
76
  if (indexBefore > 0) {
78
77
  oldSmallerPublicKey = vaults[indexBefore - 1].publicKey;
79
78
  }
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
- // }))
85
79
  // Pretty print all the vaults before the operation
86
80
  // console.log('Sorted open vaults BEFORE at index:', indexBefore)
87
81
  // let correctOrderBefore = true
@@ -122,11 +116,16 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
122
116
  if (redeem) {
123
117
  vaults[indexBefore].redeem();
124
118
  }
125
- if (vaults[indexBefore].denormalizedDebt === 0) {
119
+ if (vaults[indexBefore].denormalizedDebt.isZero()) {
126
120
  vaults.splice(indexBefore, 1);
127
121
  }
128
122
  // Sort it again since we've changed one vault
129
123
  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
+ // }))
130
129
  // Search for the vaults new position
131
130
  let indexAfter = -1;
132
131
  vaults.forEach((vault, index) => {
@@ -142,7 +141,8 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
142
141
  // })
143
142
  // )
144
143
  // Print where it moved from / to
145
- // console.log('Index After', indexAfter)
144
+ console.log('Index Before', indexBefore);
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;
@@ -161,14 +161,17 @@ exports.getLinkedListAccounts = getLinkedListAccounts;
161
161
  // Sort function we can use to sort the vaults
162
162
  // Sorted by collateral ratio. If two are the same, newer vault first
163
163
  function sortVaults(a, b) {
164
- const aRatio = a.deposited / a.denormalizedDebt;
165
- const bRatio = b.deposited / b.denormalizedDebt;
166
- if (aRatio === bRatio) {
164
+ const aRatio = a.deposited.floor().div(a.denormalizedDebt.floor());
165
+ const bRatio = b.deposited.floor().div(b.denormalizedDebt.floor());
166
+ if (aRatio.equals(bRatio)) {
167
167
  return b.vaultNumber - a.vaultNumber;
168
168
  }
169
- return aRatio - bRatio;
169
+ if (aRatio.greaterThan(bRatio)) {
170
+ return 1;
171
+ }
172
+ return -1;
170
173
  }
171
- function getMiniVaults(program, vaultTypeName) {
174
+ function getMiniVaults(program, collateralType) {
172
175
  return __awaiter(this, void 0, void 0, function* () {
173
176
  const filters = [
174
177
  // Filter for Vault Accounts
@@ -179,7 +182,7 @@ function getMiniVaults(program, vaultTypeName) {
179
182
  // Filter for Vaults with this collateral type
180
183
  {
181
184
  memcmp: {
182
- bytes: bs58_1.default.encode(VaultAccount_1.VaultAccount.getBufferForString(vaultTypeName)),
185
+ bytes: bs58_1.default.encode(VaultAccount_1.VaultAccount.getBufferForString(collateralType)),
183
186
  offset: 8 + 32 + 24,
184
187
  },
185
188
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.46",
3
+ "version": "0.1.50",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/idl/vault.ts CHANGED
@@ -1649,58 +1649,6 @@ export type Vault = {
1649
1649
  }
1650
1650
  }
1651
1651
  ]
1652
- },
1653
- {
1654
- "name": "adminMigrateVault",
1655
- "accounts": [
1656
- {
1657
- "name": "payer",
1658
- "isMut": true,
1659
- "isSigner": true
1660
- },
1661
- {
1662
- "name": "vaultSystemState",
1663
- "isMut": true,
1664
- "isSigner": false
1665
- },
1666
- {
1667
- "name": "vaultAccount",
1668
- "isMut": true,
1669
- "isSigner": false
1670
- },
1671
- {
1672
- "name": "vaultTypeAccount",
1673
- "isMut": true,
1674
- "isSigner": false
1675
- }
1676
- ],
1677
- "args": []
1678
- },
1679
- {
1680
- "name": "adminMigrateOracle",
1681
- "accounts": [
1682
- {
1683
- "name": "payer",
1684
- "isMut": true,
1685
- "isSigner": true
1686
- },
1687
- {
1688
- "name": "vaultSystemState",
1689
- "isMut": true,
1690
- "isSigner": false
1691
- },
1692
- {
1693
- "name": "oracleInfoAccount",
1694
- "isMut": true,
1695
- "isSigner": false
1696
- },
1697
- {
1698
- "name": "vaultTypeAccount",
1699
- "isMut": true,
1700
- "isSigner": false
1701
- }
1702
- ],
1703
- "args": []
1704
1652
  }
1705
1653
  ],
1706
1654
  "accounts": [
@@ -1896,7 +1844,7 @@ export type Vault = {
1896
1844
  "kind": "struct",
1897
1845
  "fields": [
1898
1846
  {
1899
- "name": "vaultTypeName",
1847
+ "name": "collateralType",
1900
1848
  "type": "string"
1901
1849
  },
1902
1850
  {
@@ -1910,10 +1858,6 @@ export type Vault = {
1910
1858
  {
1911
1859
  "name": "oracleSwitchboard",
1912
1860
  "type": "publicKey"
1913
- },
1914
- {
1915
- "name": "vaultType",
1916
- "type": "publicKey"
1917
1861
  }
1918
1862
  ]
1919
1863
  }
@@ -2158,7 +2102,7 @@ export type Vault = {
2158
2102
  "kind": "struct",
2159
2103
  "fields": [
2160
2104
  {
2161
- "name": "vaultTypeName",
2105
+ "name": "collateralType",
2162
2106
  "type": "string"
2163
2107
  },
2164
2108
  {
@@ -2242,14 +2186,6 @@ export type Vault = {
2242
2186
  {
2243
2187
  "name": "deprecated",
2244
2188
  "type": "bool"
2245
- },
2246
- {
2247
- "name": "totalFeesAccumulatedUsh",
2248
- "type": "u128"
2249
- },
2250
- {
2251
- "name": "totalFeesAccumulatedCollateral",
2252
- "type": "u128"
2253
2189
  }
2254
2190
  ]
2255
2191
  }
@@ -2276,7 +2212,7 @@ export type Vault = {
2276
2212
  "type": "u64"
2277
2213
  },
2278
2214
  {
2279
- "name": "vaultTypeName",
2215
+ "name": "collateralType",
2280
2216
  "type": "string"
2281
2217
  },
2282
2218
  {
@@ -2324,10 +2260,6 @@ export type Vault = {
2324
2260
  "type": {
2325
2261
  "option": "publicKey"
2326
2262
  }
2327
- },
2328
- {
2329
- "name": "vaultType",
2330
- "type": "publicKey"
2331
2263
  }
2332
2264
  ]
2333
2265
  }
@@ -2741,8 +2673,8 @@ export type Vault = {
2741
2673
  },
2742
2674
  {
2743
2675
  "code": 6020,
2744
- "name": "NotRedeemingLowestCollateralRatioVault",
2745
- "msg": "Can only redeem lowest collateral ratio vault in system."
2676
+ "name": "RedeemingNonHighestCollateralRatioVault",
2677
+ "msg": "Can only redeem highest collateral ratio vault in system."
2746
2678
  },
2747
2679
  {
2748
2680
  "code": 6021,
@@ -2756,11 +2688,6 @@ export type Vault = {
2756
2688
  },
2757
2689
  {
2758
2690
  "code": 6023,
2759
- "name": "InvalidSaltLength",
2760
- "msg": "Salt for new vaults must be of length 8"
2761
- },
2762
- {
2763
- "code": 6024,
2764
2691
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2765
2692
  "msg": "New Max debt extended value is less than the current debt!"
2766
2693
  }
@@ -4418,58 +4345,6 @@ export const IDL: Vault = {
4418
4345
  }
4419
4346
  }
4420
4347
  ]
4421
- },
4422
- {
4423
- "name": "adminMigrateVault",
4424
- "accounts": [
4425
- {
4426
- "name": "payer",
4427
- "isMut": true,
4428
- "isSigner": true
4429
- },
4430
- {
4431
- "name": "vaultSystemState",
4432
- "isMut": true,
4433
- "isSigner": false
4434
- },
4435
- {
4436
- "name": "vaultAccount",
4437
- "isMut": true,
4438
- "isSigner": false
4439
- },
4440
- {
4441
- "name": "vaultTypeAccount",
4442
- "isMut": true,
4443
- "isSigner": false
4444
- }
4445
- ],
4446
- "args": []
4447
- },
4448
- {
4449
- "name": "adminMigrateOracle",
4450
- "accounts": [
4451
- {
4452
- "name": "payer",
4453
- "isMut": true,
4454
- "isSigner": true
4455
- },
4456
- {
4457
- "name": "vaultSystemState",
4458
- "isMut": true,
4459
- "isSigner": false
4460
- },
4461
- {
4462
- "name": "oracleInfoAccount",
4463
- "isMut": true,
4464
- "isSigner": false
4465
- },
4466
- {
4467
- "name": "vaultTypeAccount",
4468
- "isMut": true,
4469
- "isSigner": false
4470
- }
4471
- ],
4472
- "args": []
4473
4348
  }
4474
4349
  ],
4475
4350
  "accounts": [
@@ -4665,7 +4540,7 @@ export const IDL: Vault = {
4665
4540
  "kind": "struct",
4666
4541
  "fields": [
4667
4542
  {
4668
- "name": "vaultTypeName",
4543
+ "name": "collateralType",
4669
4544
  "type": "string"
4670
4545
  },
4671
4546
  {
@@ -4679,10 +4554,6 @@ export const IDL: Vault = {
4679
4554
  {
4680
4555
  "name": "oracleSwitchboard",
4681
4556
  "type": "publicKey"
4682
- },
4683
- {
4684
- "name": "vaultType",
4685
- "type": "publicKey"
4686
4557
  }
4687
4558
  ]
4688
4559
  }
@@ -4927,7 +4798,7 @@ export const IDL: Vault = {
4927
4798
  "kind": "struct",
4928
4799
  "fields": [
4929
4800
  {
4930
- "name": "vaultTypeName",
4801
+ "name": "collateralType",
4931
4802
  "type": "string"
4932
4803
  },
4933
4804
  {
@@ -5011,14 +4882,6 @@ export const IDL: Vault = {
5011
4882
  {
5012
4883
  "name": "deprecated",
5013
4884
  "type": "bool"
5014
- },
5015
- {
5016
- "name": "totalFeesAccumulatedUsh",
5017
- "type": "u128"
5018
- },
5019
- {
5020
- "name": "totalFeesAccumulatedCollateral",
5021
- "type": "u128"
5022
4885
  }
5023
4886
  ]
5024
4887
  }
@@ -5045,7 +4908,7 @@ export const IDL: Vault = {
5045
4908
  "type": "u64"
5046
4909
  },
5047
4910
  {
5048
- "name": "vaultTypeName",
4911
+ "name": "collateralType",
5049
4912
  "type": "string"
5050
4913
  },
5051
4914
  {
@@ -5093,10 +4956,6 @@ export const IDL: Vault = {
5093
4956
  "type": {
5094
4957
  "option": "publicKey"
5095
4958
  }
5096
- },
5097
- {
5098
- "name": "vaultType",
5099
- "type": "publicKey"
5100
4959
  }
5101
4960
  ]
5102
4961
  }
@@ -5510,8 +5369,8 @@ export const IDL: Vault = {
5510
5369
  },
5511
5370
  {
5512
5371
  "code": 6020,
5513
- "name": "NotRedeemingLowestCollateralRatioVault",
5514
- "msg": "Can only redeem lowest collateral ratio vault in system."
5372
+ "name": "RedeemingNonHighestCollateralRatioVault",
5373
+ "msg": "Can only redeem highest collateral ratio vault in system."
5515
5374
  },
5516
5375
  {
5517
5376
  "code": 6021,
@@ -5525,11 +5384,6 @@ export const IDL: Vault = {
5525
5384
  },
5526
5385
  {
5527
5386
  "code": 6023,
5528
- "name": "InvalidSaltLength",
5529
- "msg": "Salt for new vaults must be of length 8"
5530
- },
5531
- {
5532
- "code": 6024,
5533
5387
  "name": "UpdateVaultTypeBadMaxDebtExtended",
5534
5388
  "msg": "New Max debt extended value is less than the current debt!"
5535
5389
  }
@@ -41,7 +41,6 @@ export async function createStakingPoolInstruction(
41
41
  hedgeTokensToBeMinted: number,
42
42
  overrideStartTime?: number
43
43
  ): Promise<TransactionInstruction> {
44
- console.log("new createStakingPoolInstruction")
45
44
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
46
45
  const ushMintPublickey = await getUshMintPublicKey()
47
46
  const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
@@ -20,7 +20,6 @@ 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'
24
23
 
25
24
  export async function depositVault(
26
25
  program: Program<Vault>,
@@ -36,12 +35,13 @@ export async function depositVault(
36
35
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
37
36
 
38
37
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
39
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
38
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
39
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
40
40
  const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
41
41
  provider.connection,
42
42
  payer,
43
43
  vaultTypeAccountInfo.collateralMint,
44
- vaultAccount.vaultType,
44
+ vaultTypeAccountPublicKey,
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
- vaultAccount.vaultType,
71
+ vaultTypeAccountPublicKey,
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 (vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()) {
79
+ if (vaultAccount.collateralType === 'SOL') {
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
- vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount,
101
+ vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount,
102
102
  vaultPublicKey,
103
103
  vaultAssociatedCollateralAccountPublicKey,
104
104
  history.publicKey,
105
- vaultAccount.vaultType,
105
+ vaultTypeAccountPublicKey,
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 (vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()) {
118
+ if (vaultAccount.collateralType === 'SOL') {
119
119
  transaction.add(
120
120
  TokenInstructions.closeAccount({
121
121
  source: wrappedSolAccount.publicKey,
@@ -31,7 +31,8 @@ export async function liquidateVault(
31
31
  ): Promise<PublicKey> {
32
32
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
33
33
 
34
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
34
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
35
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
35
36
  const collateralMint = vaultTypeAccountInfo.collateralMint
36
37
 
37
38
  const hedgeMintPublickey = await getHedgeMintPublicKey()
@@ -72,7 +73,7 @@ export async function liquidateVault(
72
73
  provider.connection,
73
74
  payer,
74
75
  collateralMint,
75
- vaultAccount.vaultType,
76
+ vaultTypeAccountPublicKey,
76
77
  true
77
78
  )
78
79
  const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
@@ -86,7 +87,7 @@ export async function liquidateVault(
86
87
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
87
88
  program,
88
89
  provider,
89
- vaultAccount.vaultType,
90
+ vaultTypeAccountPublicKey,
90
91
  vaultPublicKey,
91
92
  0,
92
93
  0,
@@ -118,7 +119,7 @@ export async function liquidateVault(
118
119
  oldSmallerPublicKey,
119
120
  newSmallerPublicKey,
120
121
  newLargerPublicKey,
121
- vaultAccount.vaultType,
122
+ vaultAccount.collateralType,
122
123
  overrideTime
123
124
  )
124
125
  )
@@ -145,12 +146,13 @@ export async function liquidateVaultInstruction(
145
146
  oldSmallerPublicKey: PublicKey,
146
147
  newSmallerPublicKey: PublicKey,
147
148
  newLargerPublicKey: PublicKey,
148
- vaultTypeAccount: PublicKey,
149
+ collateralType: string,
149
150
  overrideTime?: number
150
151
  ): Promise<TransactionInstruction> {
151
152
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
152
153
  const ushMintPublickey = await getUshMintPublicKey()
153
154
  const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
155
+ const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
154
156
 
155
157
  return await program.methods
156
158
  .liquidateVault(