hedge-web3 0.1.46 → 0.1.50

Sign up to get free protection for your applications and to get access to all the features.
@@ -1649,58 +1649,6 @@ export declare 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 declare 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 declare 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 declare 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 declare 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 declare 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 declare 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 declare 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 declare 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
  }
@@ -2,4 +2,4 @@ import { Program, Provider } from '@project-serum/anchor';
2
2
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
3
  import { Vault } from 'idl/vault';
4
4
  export declare function liquidateVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, overrideTime?: number): Promise<PublicKey>;
5
- export declare function liquidateVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, payerAssociatedTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, poolState: PublicKey, poolEra: PublicKey, poolAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, newEraPublicKey: PublicKey, feePool: PublicKey, feePoolAssociatedTokenAccount: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, vaultTypeAccount: PublicKey, overrideTime?: number): Promise<TransactionInstruction>;
5
+ export declare function liquidateVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, payerAssociatedTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, poolState: PublicKey, poolEra: PublicKey, poolAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, newEraPublicKey: PublicKey, feePool: PublicKey, feePoolAssociatedTokenAccount: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, collateralType: string, overrideTime?: number): Promise<TransactionInstruction>;
@@ -12,23 +12,21 @@ export declare class VaultAccount {
12
12
  /** The public key of the vault owner. */
13
13
  pdaSalt: string;
14
14
  /** The deposited collateral of the vault (in SOL Lamports). */
15
- deposited: number;
15
+ deposited: Decimal;
16
16
  /** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
17
- denormalizedDebt: number;
17
+ denormalizedDebt: Decimal;
18
18
  /** The ordered number of when this vault was created. */
19
19
  vaultNumber: number;
20
20
  /** Debt redistribution snapshot */
21
21
  debtProductSnapshotBytes: Decimal;
22
22
  /** Collateral redistribution snapshot' */
23
23
  collateralAccumulatorSnapshotBytes: Decimal;
24
- /** The vault type eg '2-SOL-150-0' */
25
- vaultTypeName: string;
24
+ /** The vault type eg 'SOL-150' */
25
+ collateralType: string;
26
26
  /** Current State of the vault ("Open", "Closed", "Liquidated") */
27
27
  vaultStatus: string;
28
28
  /** The public key of the next vault to redeem. */
29
29
  nextVaultToRedeem: PublicKey;
30
- /** The public key of the vault type. */
31
- vaultType: PublicKey;
32
30
  constructor(vault: any, publicKey: PublicKey);
33
31
  /**
34
32
  * Check if some `PublicKey` is the owner
@@ -59,7 +57,7 @@ export declare class VaultAccount {
59
57
  addDeposit(depositAmount: number): void;
60
58
  redeem(): void;
61
59
  liquidate(): void;
62
- updateDebtAndCollateral(vaultTypeAccountData: any): void;
60
+ updateDebtAndCollateral(vaultTypeAccuntData: any): void;
63
61
  toString(highlight: PublicKey): string;
64
62
  /**
65
63
  * Creates a VaultAccount from a slice of data
package/lib/idl/vault.js CHANGED
@@ -1652,58 +1652,6 @@ exports.IDL = {
1652
1652
  }
1653
1653
  }
1654
1654
  ]
1655
- },
1656
- {
1657
- "name": "adminMigrateVault",
1658
- "accounts": [
1659
- {
1660
- "name": "payer",
1661
- "isMut": true,
1662
- "isSigner": true
1663
- },
1664
- {
1665
- "name": "vaultSystemState",
1666
- "isMut": true,
1667
- "isSigner": false
1668
- },
1669
- {
1670
- "name": "vaultAccount",
1671
- "isMut": true,
1672
- "isSigner": false
1673
- },
1674
- {
1675
- "name": "vaultTypeAccount",
1676
- "isMut": true,
1677
- "isSigner": false
1678
- }
1679
- ],
1680
- "args": []
1681
- },
1682
- {
1683
- "name": "adminMigrateOracle",
1684
- "accounts": [
1685
- {
1686
- "name": "payer",
1687
- "isMut": true,
1688
- "isSigner": true
1689
- },
1690
- {
1691
- "name": "vaultSystemState",
1692
- "isMut": true,
1693
- "isSigner": false
1694
- },
1695
- {
1696
- "name": "oracleInfoAccount",
1697
- "isMut": true,
1698
- "isSigner": false
1699
- },
1700
- {
1701
- "name": "vaultTypeAccount",
1702
- "isMut": true,
1703
- "isSigner": false
1704
- }
1705
- ],
1706
- "args": []
1707
1655
  }
1708
1656
  ],
1709
1657
  "accounts": [
@@ -1899,7 +1847,7 @@ exports.IDL = {
1899
1847
  "kind": "struct",
1900
1848
  "fields": [
1901
1849
  {
1902
- "name": "vaultTypeName",
1850
+ "name": "collateralType",
1903
1851
  "type": "string"
1904
1852
  },
1905
1853
  {
@@ -1913,10 +1861,6 @@ exports.IDL = {
1913
1861
  {
1914
1862
  "name": "oracleSwitchboard",
1915
1863
  "type": "publicKey"
1916
- },
1917
- {
1918
- "name": "vaultType",
1919
- "type": "publicKey"
1920
1864
  }
1921
1865
  ]
1922
1866
  }
@@ -2161,7 +2105,7 @@ exports.IDL = {
2161
2105
  "kind": "struct",
2162
2106
  "fields": [
2163
2107
  {
2164
- "name": "vaultTypeName",
2108
+ "name": "collateralType",
2165
2109
  "type": "string"
2166
2110
  },
2167
2111
  {
@@ -2245,14 +2189,6 @@ exports.IDL = {
2245
2189
  {
2246
2190
  "name": "deprecated",
2247
2191
  "type": "bool"
2248
- },
2249
- {
2250
- "name": "totalFeesAccumulatedUsh",
2251
- "type": "u128"
2252
- },
2253
- {
2254
- "name": "totalFeesAccumulatedCollateral",
2255
- "type": "u128"
2256
2192
  }
2257
2193
  ]
2258
2194
  }
@@ -2279,7 +2215,7 @@ exports.IDL = {
2279
2215
  "type": "u64"
2280
2216
  },
2281
2217
  {
2282
- "name": "vaultTypeName",
2218
+ "name": "collateralType",
2283
2219
  "type": "string"
2284
2220
  },
2285
2221
  {
@@ -2327,10 +2263,6 @@ exports.IDL = {
2327
2263
  "type": {
2328
2264
  "option": "publicKey"
2329
2265
  }
2330
- },
2331
- {
2332
- "name": "vaultType",
2333
- "type": "publicKey"
2334
2266
  }
2335
2267
  ]
2336
2268
  }
@@ -2744,8 +2676,8 @@ exports.IDL = {
2744
2676
  },
2745
2677
  {
2746
2678
  "code": 6020,
2747
- "name": "NotRedeemingLowestCollateralRatioVault",
2748
- "msg": "Can only redeem lowest collateral ratio vault in system."
2679
+ "name": "RedeemingNonHighestCollateralRatioVault",
2680
+ "msg": "Can only redeem highest collateral ratio vault in system."
2749
2681
  },
2750
2682
  {
2751
2683
  "code": 6021,
@@ -2759,11 +2691,6 @@ exports.IDL = {
2759
2691
  },
2760
2692
  {
2761
2693
  "code": 6023,
2762
- "name": "InvalidSaltLength",
2763
- "msg": "Salt for new vaults must be of length 8"
2764
- },
2765
- {
2766
- "code": 6024,
2767
2694
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2768
2695
  "msg": "New Max debt extended value is less than the current debt!"
2769
2696
  }
@@ -26,7 +26,6 @@ function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensT
26
26
  exports.createStakingPool = createStakingPool;
27
27
  function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
- console.log("new createStakingPoolInstruction");
30
29
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
31
30
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
32
31
  const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
@@ -16,15 +16,15 @@ const spl_token_1 = require("@solana/spl-token");
16
16
  const web3_js_1 = require("@solana/web3.js");
17
17
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
18
18
  const Constants_1 = require("../Constants");
19
- const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
20
19
  function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
21
20
  return __awaiter(this, void 0, void 0, function* () {
22
21
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
23
22
  // Prep the user to get USH back out at some point
24
23
  yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
25
24
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
26
- const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
27
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
25
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
26
+ const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
27
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
28
28
  const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
29
29
  const vaultAssociatedCollateralAccountPublicKey = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccountInfo.collateralMint);
30
30
  const history = web3_js_1.Keypair.generate();
@@ -34,8 +34,8 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
34
34
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
35
35
  const transaction = new web3_js_1.Transaction();
36
36
  const signers = [payer, history];
37
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, depositAmount, 0, false, false);
38
- if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
37
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, 0, false, false);
38
+ if (vaultAccount.collateralType === 'SOL') {
39
39
  transaction.add(web3_js_1.SystemProgram.createAccount({
40
40
  fromPubkey: payer.publicKey,
41
41
  lamports: depositAmount + 2.04e6,
@@ -49,8 +49,8 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
49
49
  }));
50
50
  signers.push(wrappedSolAccount);
51
51
  }
52
- transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
53
- if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
52
+ transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
53
+ if (vaultAccount.collateralType === 'SOL') {
54
54
  transaction.add(serum_1.TokenInstructions.closeAccount({
55
55
  source: wrappedSolAccount.publicKey,
56
56
  destination: payer.publicKey,
@@ -18,7 +18,8 @@ const Constants_1 = require("../Constants");
18
18
  function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
20
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
21
- const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
21
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
22
+ const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
22
23
  const collateralMint = vaultTypeAccountInfo.collateralMint;
23
24
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
24
25
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
@@ -29,23 +30,24 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
29
30
  const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true);
30
31
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultPublicKey, true);
31
32
  const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
32
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultAccount.vaultType, true);
33
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
33
34
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
34
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, 0, false, true);
35
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, false, true);
35
36
  const history = web3_js_1.Keypair.generate();
36
37
  const newEra = web3_js_1.Keypair.generate();
37
38
  const transaction = new web3_js_1.Transaction();
38
- transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultAccount.vaultType, overrideTime));
39
+ transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultAccount.collateralType, overrideTime));
39
40
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra]);
40
41
  return vaultPublicKey;
41
42
  });
42
43
  }
43
44
  exports.liquidateVault = liquidateVault;
44
- function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultTypeAccount, overrideTime) {
45
+ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, collateralType, overrideTime) {
45
46
  return __awaiter(this, void 0, void 0, function* () {
46
47
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
47
48
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
48
49
  const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
50
+ const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
49
51
  return yield program.methods
50
52
  .liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
51
53
  )
@@ -15,20 +15,19 @@ const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
16
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
17
17
  const Constants_1 = require("../Constants");
18
- const Errors_1 = require("../utils/Errors");
19
- const fs = require('fs');
20
18
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
21
19
  return __awaiter(this, void 0, void 0, function* () {
22
20
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
23
21
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
24
22
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
25
- const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
26
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultAccount.vaultType, true);
23
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
24
+ const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
25
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true);
27
26
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
28
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, loanAmount, false, false);
27
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
29
28
  const history = web3_js_1.Keypair.generate();
30
- const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
31
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]).catch(Errors_1.parseAnchorErrors);
29
+ const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
30
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
32
31
  return vaultPublicKey;
33
32
  });
34
33
  }
@@ -22,13 +22,14 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
22
22
  // Prep the user to get USH back out at some point
23
23
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
24
24
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
25
- const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
26
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
25
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
26
+ const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
27
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
27
28
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
28
29
  const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
29
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, 0, true, false);
30
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, true, false);
30
31
  const history = web3_js_1.Keypair.generate();
31
- const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime));
32
+ const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime));
32
33
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
33
34
  return vaultPublicKey;
34
35
  });
@@ -32,7 +32,7 @@ function refreshOraclePriceInstruction(program, collateralType, network, overrid
32
32
  .accounts({
33
33
  oracleInfoAccount: oracleInfoAccount,
34
34
  vaultTypeAccount: vaultTypeAccount,
35
- oracleChainlink: chainlinkAccounts[network],
35
+ oracleChainlink: chainlinkAccunts[network],
36
36
  oraclePyth: pythAccounts[network],
37
37
  oracleSwitchboard: switchboardAccounts[network],
38
38
  systemProgram: web3_js_1.SystemProgram.programId,
@@ -52,7 +52,7 @@ const pythAccounts = {
52
52
  Devnet: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
53
53
  MainnetBeta: new web3_js_1.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
54
54
  };
55
- const chainlinkAccounts = {
55
+ const chainlinkAccunts = {
56
56
  Testing: web3_js_1.SystemProgram.programId,
57
57
  Devnet: new web3_js_1.PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
58
58
  MainnetBeta: web3_js_1.SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
@@ -21,12 +21,13 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
21
21
  // Prep the user to get USH back out at some point
22
22
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
23
23
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
24
- const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
25
- const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultAccount.vaultType, vaultTypeAccount.collateralMint);
24
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
25
+ const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
26
+ const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint);
26
27
  const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
27
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, repayAmount * -1, false, false);
28
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, repayAmount * -1, false, false);
28
29
  const history = web3_js_1.Keypair.generate();
29
- const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime));
30
+ const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime));
30
31
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
31
32
  return vaultPublicKey;
32
33
  });
@@ -24,14 +24,15 @@ function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount,
24
24
  const history = web3_js_1.Keypair.generate();
25
25
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
26
26
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
27
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
27
28
  const vaultAssociatedCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, serum_1.TokenInstructions.WRAPPED_SOL_MINT, vaultPublicKey, true);
28
- const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
29
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
29
+ const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
30
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
30
31
  const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
31
32
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
32
33
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
33
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, withdrawAmount * -1, 0, false, false);
34
- const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMintPublickey, history.publicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime));
34
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, withdrawAmount * -1, 0, false, false);
35
+ const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMintPublickey, history.publicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime));
35
36
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
36
37
  return vaultPublicKey;
37
38
  });