hedge-web3 0.1.42 → 0.1.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/declarations/Constants.d.ts +1 -1
  2. package/declarations/idl/vault.d.ts +79 -6
  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 +79 -6
  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 +158 -12
  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
@@ -33,11 +33,11 @@ const borsh = __importStar(require("@project-serum/borsh"));
33
33
  class VaultAccount {
34
34
  constructor(vault, publicKey) {
35
35
  var _a, _b, _c;
36
- /** Debt redistribution snapshop */
36
+ /** Debt redistribution snapshot */
37
37
  this.debtProductSnapshotBytes = new decimal_js_1.default(0);
38
- /** Collateral redistribution snapshop' */
38
+ /** Collateral redistribution snapshot' */
39
39
  this.collateralAccumulatorSnapshotBytes = new decimal_js_1.default(0);
40
- /** Current State of the vautl ("Open", "Closed", "Liquidated") */
40
+ /** Current State of the vault ("Open", "Closed", "Liquidated") */
41
41
  this.vaultStatus = '';
42
42
  this.publicKey = publicKey;
43
43
  this.vaultOwner = vault.vaultOwner;
@@ -51,11 +51,12 @@ class VaultAccount {
51
51
  if (vault.collateralAccumulatorSnapshotBytes) {
52
52
  this.collateralAccumulatorSnapshotBytes = (0, HedgeDecimal_1.DecimalFromU128)(vault.collateralAccumulatorSnapshotBytes.toString());
53
53
  }
54
- this.collateralType = vault.collateralType;
54
+ this.vaultTypeName = vault.vaultTypeName;
55
55
  this.nextVaultToRedeem = vault.nextVaultToRedeem;
56
56
  if (vault.vaultStatus) {
57
57
  this.vaultStatus = Object.keys(vault.vaultStatus)[0];
58
58
  }
59
+ this.vaultType = vault.vaultType;
59
60
  }
60
61
  /**
61
62
  * Check if some `PublicKey` is the owner
@@ -110,9 +111,9 @@ class VaultAccount {
110
111
  this.denormalizedDebt = 0;
111
112
  this.vaultStatus = 'liquidated';
112
113
  }
113
- updateDebtAndCollateral(vaultTypeAccuntData) {
114
- const debtProductCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccuntData.debtRedistributionProduct);
115
- const collateralAccumulatorCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccuntData.collateralRedistributionAccumulator);
114
+ updateDebtAndCollateral(vaultTypeAccountData) {
115
+ const debtProductCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccountData.debtRedistributionProduct);
116
+ const collateralAccumulatorCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccountData.collateralRedistributionAccumulator);
116
117
  this.denormalizedDebt = debtProductCurrent
117
118
  .div(this.debtProductSnapshotBytes)
118
119
  .mul(new decimal_js_1.default(this.denormalizedDebt))
@@ -135,7 +136,7 @@ class VaultAccount {
135
136
  if (this.nextVaultToRedeem) {
136
137
  nextVault = this.nextVaultToRedeem.toString().substring(0, 6);
137
138
  }
138
- return `Vault(${this.vaultNumber}): ${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} NextVault: ${nextVault} ${arrow} `;
139
+ return `Vault(${this.vaultNumber}): ${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `;
139
140
  }
140
141
  /**
141
142
  * Creates a VaultAccount from a slice of data
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const decimal_js_1 = __importDefault(require("decimal.js"));
7
+ const HedgeDecimal_1 = require("../HedgeDecimal");
8
+ class VaultType {
9
+ constructor(config, publicKey) {
10
+ var _a;
11
+ this.publicKey = publicKey;
12
+ this.name = config.collateralType;
13
+ this.loanInitFee = (0, HedgeDecimal_1.DecimalFromU128)(config.loanInitFee);
14
+ this.minCollateralRatio = (0, HedgeDecimal_1.DecimalFromU128)(config.minCollateralRatio);
15
+ this.interestRatePerSecond = (0, HedgeDecimal_1.DecimalFromU128)(config.interestRatePerSecond);
16
+ this.minDebtPerVault = (0, HedgeDecimal_1.DecimalFromU128)(config.minDebtPerVault);
17
+ this.maxDebtExtended = (0, HedgeDecimal_1.DecimalFromU128)(config.maxDebtExtended);
18
+ this.canBeRedeemed = config.canBeRedeemed;
19
+ this.collateralMint = config.collateralMint;
20
+ this.firstVaultToRedeem = config.firstVaultToRedeem;
21
+ this.recentPrice = (0, HedgeDecimal_1.DecimalFromU128)((_a = config.recentPrice) === null || _a === void 0 ? void 0 : _a.toString());
22
+ this.priceLastUpdatedTimestamp = new decimal_js_1.default(config.priceLastUpdatedTimestamp.toString());
23
+ this.collateralHeld = new decimal_js_1.default(config.collateralHeld.toString());
24
+ this.denormalizedDebtExtended = new decimal_js_1.default(config.denormalizedDebtExtended.toString());
25
+ this.debtRedistributionProduct = (0, HedgeDecimal_1.DecimalFromU128)(config.debtRedistributionProduct.toString());
26
+ this.collateralRedistributionAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(config.collateralRedistributionAccumulator.toString());
27
+ this.cumulativeRate = (0, HedgeDecimal_1.DecimalFromU128)(config.cumulativeRate.toString());
28
+ this.cumulativeRateLastUpdated = new decimal_js_1.default(config.cumulativeRateLastUpdated.toString());
29
+ this.collateralIndex = config.collateralIndex.toNumber();
30
+ }
31
+ }
32
+ exports.default = VaultType;
@@ -0,0 +1,32 @@
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
+ exports.sendAndConfirmWithDebug = void 0;
13
+ function sendAndConfirmWithDebug(connection, transaction, signers) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ return connection
16
+ .sendTransaction(transaction, signers)
17
+ .then((signature) => {
18
+ return connection
19
+ .confirmTransaction(signature)
20
+ .then((signatureContext) => {
21
+ return signature;
22
+ })
23
+ .catch((error) => {
24
+ console.log('There was an error confirming the transaction', error);
25
+ });
26
+ })
27
+ .catch((error) => {
28
+ console.log('There was an error sending the transaction', error);
29
+ });
30
+ });
31
+ }
32
+ exports.sendAndConfirmWithDebug = sendAndConfirmWithDebug;
@@ -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.42",
3
+ "version": "0.1.45",
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
@@ -1649,6 +1649,58 @@ 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": []
1652
1704
  }
1653
1705
  ],
1654
1706
  "accounts": [
@@ -1844,7 +1896,7 @@ export type Vault = {
1844
1896
  "kind": "struct",
1845
1897
  "fields": [
1846
1898
  {
1847
- "name": "collateralType",
1899
+ "name": "vaultTypeName",
1848
1900
  "type": "string"
1849
1901
  },
1850
1902
  {
@@ -1858,6 +1910,10 @@ export type Vault = {
1858
1910
  {
1859
1911
  "name": "oracleSwitchboard",
1860
1912
  "type": "publicKey"
1913
+ },
1914
+ {
1915
+ "name": "vaultType",
1916
+ "type": "publicKey"
1861
1917
  }
1862
1918
  ]
1863
1919
  }
@@ -1968,7 +2024,7 @@ export type Vault = {
1968
2024
  "type": {
1969
2025
  "array": [
1970
2026
  "u8",
1971
- 12
2027
+ 16
1972
2028
  ]
1973
2029
  }
1974
2030
  },
@@ -2102,7 +2158,7 @@ export type Vault = {
2102
2158
  "kind": "struct",
2103
2159
  "fields": [
2104
2160
  {
2105
- "name": "collateralType",
2161
+ "name": "vaultTypeName",
2106
2162
  "type": "string"
2107
2163
  },
2108
2164
  {
@@ -2186,6 +2242,14 @@ export type Vault = {
2186
2242
  {
2187
2243
  "name": "deprecated",
2188
2244
  "type": "bool"
2245
+ },
2246
+ {
2247
+ "name": "totalFeesAccumulatedUsh",
2248
+ "type": "u128"
2249
+ },
2250
+ {
2251
+ "name": "totalFeesAccumulatedCollateral",
2252
+ "type": "u128"
2189
2253
  }
2190
2254
  ]
2191
2255
  }
@@ -2212,7 +2276,7 @@ export type Vault = {
2212
2276
  "type": "u64"
2213
2277
  },
2214
2278
  {
2215
- "name": "collateralType",
2279
+ "name": "vaultTypeName",
2216
2280
  "type": "string"
2217
2281
  },
2218
2282
  {
@@ -2260,6 +2324,10 @@ export type Vault = {
2260
2324
  "type": {
2261
2325
  "option": "publicKey"
2262
2326
  }
2327
+ },
2328
+ {
2329
+ "name": "vaultType",
2330
+ "type": "publicKey"
2263
2331
  }
2264
2332
  ]
2265
2333
  }
@@ -2673,8 +2741,8 @@ export type Vault = {
2673
2741
  },
2674
2742
  {
2675
2743
  "code": 6020,
2676
- "name": "RedeemingNonHighestCollateralRatioVault",
2677
- "msg": "Can only redeem highest collateral ratio vault in system."
2744
+ "name": "NotRedeemingLowestCollateralRatioVault",
2745
+ "msg": "Can only redeem lowest collateral ratio vault in system."
2678
2746
  },
2679
2747
  {
2680
2748
  "code": 6021,
@@ -2688,6 +2756,11 @@ export type Vault = {
2688
2756
  },
2689
2757
  {
2690
2758
  "code": 6023,
2759
+ "name": "InvalidSaltLength",
2760
+ "msg": "Salt for new vaults must be of length 8"
2761
+ },
2762
+ {
2763
+ "code": 6024,
2691
2764
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2692
2765
  "msg": "New Max debt extended value is less than the current debt!"
2693
2766
  }
@@ -4345,6 +4418,58 @@ export const IDL: Vault = {
4345
4418
  }
4346
4419
  }
4347
4420
  ]
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": []
4348
4473
  }
4349
4474
  ],
4350
4475
  "accounts": [
@@ -4540,7 +4665,7 @@ export const IDL: Vault = {
4540
4665
  "kind": "struct",
4541
4666
  "fields": [
4542
4667
  {
4543
- "name": "collateralType",
4668
+ "name": "vaultTypeName",
4544
4669
  "type": "string"
4545
4670
  },
4546
4671
  {
@@ -4554,6 +4679,10 @@ export const IDL: Vault = {
4554
4679
  {
4555
4680
  "name": "oracleSwitchboard",
4556
4681
  "type": "publicKey"
4682
+ },
4683
+ {
4684
+ "name": "vaultType",
4685
+ "type": "publicKey"
4557
4686
  }
4558
4687
  ]
4559
4688
  }
@@ -4664,7 +4793,7 @@ export const IDL: Vault = {
4664
4793
  "type": {
4665
4794
  "array": [
4666
4795
  "u8",
4667
- 12
4796
+ 16
4668
4797
  ]
4669
4798
  }
4670
4799
  },
@@ -4798,7 +4927,7 @@ export const IDL: Vault = {
4798
4927
  "kind": "struct",
4799
4928
  "fields": [
4800
4929
  {
4801
- "name": "collateralType",
4930
+ "name": "vaultTypeName",
4802
4931
  "type": "string"
4803
4932
  },
4804
4933
  {
@@ -4882,6 +5011,14 @@ export const IDL: Vault = {
4882
5011
  {
4883
5012
  "name": "deprecated",
4884
5013
  "type": "bool"
5014
+ },
5015
+ {
5016
+ "name": "totalFeesAccumulatedUsh",
5017
+ "type": "u128"
5018
+ },
5019
+ {
5020
+ "name": "totalFeesAccumulatedCollateral",
5021
+ "type": "u128"
4885
5022
  }
4886
5023
  ]
4887
5024
  }
@@ -4908,7 +5045,7 @@ export const IDL: Vault = {
4908
5045
  "type": "u64"
4909
5046
  },
4910
5047
  {
4911
- "name": "collateralType",
5048
+ "name": "vaultTypeName",
4912
5049
  "type": "string"
4913
5050
  },
4914
5051
  {
@@ -4956,6 +5093,10 @@ export const IDL: Vault = {
4956
5093
  "type": {
4957
5094
  "option": "publicKey"
4958
5095
  }
5096
+ },
5097
+ {
5098
+ "name": "vaultType",
5099
+ "type": "publicKey"
4959
5100
  }
4960
5101
  ]
4961
5102
  }
@@ -5369,8 +5510,8 @@ export const IDL: Vault = {
5369
5510
  },
5370
5511
  {
5371
5512
  "code": 6020,
5372
- "name": "RedeemingNonHighestCollateralRatioVault",
5373
- "msg": "Can only redeem highest collateral ratio vault in system."
5513
+ "name": "NotRedeemingLowestCollateralRatioVault",
5514
+ "msg": "Can only redeem lowest collateral ratio vault in system."
5374
5515
  },
5375
5516
  {
5376
5517
  "code": 6021,
@@ -5384,6 +5525,11 @@ export const IDL: Vault = {
5384
5525
  },
5385
5526
  {
5386
5527
  "code": 6023,
5528
+ "name": "InvalidSaltLength",
5529
+ "msg": "Salt for new vaults must be of length 8"
5530
+ },
5531
+ {
5532
+ "code": 6024,
5387
5533
  "name": "UpdateVaultTypeBadMaxDebtExtended",
5388
5534
  "msg": "New Max debt extended value is less than the current debt!"
5389
5535
  }
@@ -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,