hedge-web3 0.1.43 → 0.1.44

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 +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
@@ -1,5 +1,5 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- export declare const HEDGE_PROGRAM_ID = "HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ";
2
+ export declare const HEDGE_PROGRAM_ID = "zooJaircVAoQ4e7EXRDocnsbB7UPYQ6J7bKyZEMh784";
3
3
  export declare const HEDGE_PROGRAM_PUBLICKEY: PublicKey;
4
4
  export declare const CHAINLINK_SOL_USD_ID = "FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf";
5
5
  export declare const CHAINLINK_SOL_USD_PUBLICKEY: PublicKey;
@@ -1844,7 +1844,7 @@ export declare 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 declare 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 declare 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 declare 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 declare 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 declare 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 declare 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 declare 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
  }
@@ -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, collateralType: string, 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, vaultTypeAccount: PublicKey, overrideTime?: number): Promise<TransactionInstruction>;
@@ -17,16 +17,18 @@ export declare class VaultAccount {
17
17
  denormalizedDebt: number;
18
18
  /** The ordered number of when this vault was created. */
19
19
  vaultNumber: number;
20
- /** Debt redistribution snapshop */
20
+ /** Debt redistribution snapshot */
21
21
  debtProductSnapshotBytes: Decimal;
22
- /** Collateral redistribution snapshop' */
22
+ /** Collateral redistribution snapshot' */
23
23
  collateralAccumulatorSnapshotBytes: Decimal;
24
- /** The vault type eg 'SOL-150' */
25
- collateralType: string;
26
- /** Current State of the vautl ("Open", "Closed", "Liquidated") */
24
+ /** The vault type eg '2-SOL-150-0' */
25
+ vaultTypeName: string;
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;
30
32
  constructor(vault: any, publicKey: PublicKey);
31
33
  /**
32
34
  * Check if some `PublicKey` is the owner
@@ -57,7 +59,7 @@ export declare class VaultAccount {
57
59
  addDeposit(depositAmount: number): void;
58
60
  redeem(): void;
59
61
  liquidate(): void;
60
- updateDebtAndCollateral(vaultTypeAccuntData: any): void;
62
+ updateDebtAndCollateral(vaultTypeAccountData: any): void;
61
63
  toString(highlight: PublicKey): string;
62
64
  /**
63
65
  * Creates a VaultAccount from a slice of data
@@ -0,0 +1,24 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import Decimal from 'decimal.js';
3
+ export default class VaultType {
4
+ publicKey?: PublicKey;
5
+ name: string;
6
+ collateralMint: PublicKey;
7
+ collateralIndex: number;
8
+ recentPrice: Decimal;
9
+ priceLastUpdatedTimestamp: Decimal;
10
+ collateralHeld: Decimal;
11
+ denormalizedDebtExtended: Decimal;
12
+ debtRedistributionProduct: Decimal;
13
+ collateralRedistributionAccumulator: Decimal;
14
+ minCollateralRatio: Decimal;
15
+ loanInitFee: Decimal;
16
+ minDebtPerVault: Decimal;
17
+ maxDebtExtended: Decimal;
18
+ canBeRedeemed: boolean;
19
+ cumulativeRate: Decimal;
20
+ cumulativeRateLastUpdated: Decimal;
21
+ interestRatePerSecond: Decimal;
22
+ firstVaultToRedeem: PublicKey;
23
+ constructor(config: any, publicKey?: PublicKey);
24
+ }
@@ -0,0 +1,2 @@
1
+ import { Connection, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
2
+ export declare function sendAndConfirmWithDebug(connection: Connection, transaction: Transaction, signers: Signer[]): Promise<TransactionSignature | void>;
@@ -0,0 +1,2 @@
1
+ import { Connection, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
2
+ export default function sendAndConfirmWithDebug(connection: Connection, transaction: Transaction, signers: Signer[]): Promise<TransactionSignature | void>;
package/lib/Constants.js CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeOracleAccountPublicKey = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getVaultSystemStatePublicKey = exports.getUshMintPublicKey = exports.getLiquidationPoolUshAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = exports.HEDGE_PROGRAM_PUBLICKEY = exports.HEDGE_PROGRAM_ID = void 0;
13
13
  const spl_token_1 = require("@solana/spl-token");
14
14
  const web3_js_1 = require("@solana/web3.js");
15
- exports.HEDGE_PROGRAM_ID = 'HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ';
15
+ exports.HEDGE_PROGRAM_ID = 'zooJaircVAoQ4e7EXRDocnsbB7UPYQ6J7bKyZEMh784';
16
16
  exports.HEDGE_PROGRAM_PUBLICKEY = new web3_js_1.PublicKey(exports.HEDGE_PROGRAM_ID);
17
17
  exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
18
18
  exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
package/lib/idl/vault.js CHANGED
@@ -1847,7 +1847,7 @@ exports.IDL = {
1847
1847
  "kind": "struct",
1848
1848
  "fields": [
1849
1849
  {
1850
- "name": "collateralType",
1850
+ "name": "vaultTypeName",
1851
1851
  "type": "string"
1852
1852
  },
1853
1853
  {
@@ -1861,6 +1861,10 @@ exports.IDL = {
1861
1861
  {
1862
1862
  "name": "oracleSwitchboard",
1863
1863
  "type": "publicKey"
1864
+ },
1865
+ {
1866
+ "name": "vaultType",
1867
+ "type": "publicKey"
1864
1868
  }
1865
1869
  ]
1866
1870
  }
@@ -2105,7 +2109,7 @@ exports.IDL = {
2105
2109
  "kind": "struct",
2106
2110
  "fields": [
2107
2111
  {
2108
- "name": "collateralType",
2112
+ "name": "vaultTypeName",
2109
2113
  "type": "string"
2110
2114
  },
2111
2115
  {
@@ -2189,6 +2193,14 @@ exports.IDL = {
2189
2193
  {
2190
2194
  "name": "deprecated",
2191
2195
  "type": "bool"
2196
+ },
2197
+ {
2198
+ "name": "totalFeesAccumulatedUsh",
2199
+ "type": "u128"
2200
+ },
2201
+ {
2202
+ "name": "totalFeesAccumulatedCollateral",
2203
+ "type": "u128"
2192
2204
  }
2193
2205
  ]
2194
2206
  }
@@ -2215,7 +2227,7 @@ exports.IDL = {
2215
2227
  "type": "u64"
2216
2228
  },
2217
2229
  {
2218
- "name": "collateralType",
2230
+ "name": "vaultTypeName",
2219
2231
  "type": "string"
2220
2232
  },
2221
2233
  {
@@ -2263,6 +2275,10 @@ exports.IDL = {
2263
2275
  "type": {
2264
2276
  "option": "publicKey"
2265
2277
  }
2278
+ },
2279
+ {
2280
+ "name": "vaultType",
2281
+ "type": "publicKey"
2266
2282
  }
2267
2283
  ]
2268
2284
  }
@@ -2676,8 +2692,8 @@ exports.IDL = {
2676
2692
  },
2677
2693
  {
2678
2694
  "code": 6020,
2679
- "name": "RedeemingNonHighestCollateralRatioVault",
2680
- "msg": "Can only redeem highest collateral ratio vault in system."
2695
+ "name": "NotRedeemingLowestCollateralRatioVault",
2696
+ "msg": "Can only redeem lowest collateral ratio vault in system."
2681
2697
  },
2682
2698
  {
2683
2699
  "code": 6021,
@@ -2691,6 +2707,11 @@ exports.IDL = {
2691
2707
  },
2692
2708
  {
2693
2709
  "code": 6023,
2710
+ "name": "InvalidSaltLength",
2711
+ "msg": "Salt for new vaults must be of length 8"
2712
+ },
2713
+ {
2714
+ "code": 6024,
2694
2715
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2695
2716
  "msg": "New Max debt extended value is less than the current debt!"
2696
2717
  }
@@ -26,6 +26,7 @@ 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");
29
30
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
30
31
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
31
32
  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");
19
20
  function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
20
21
  return __awaiter(this, void 0, void 0, function* () {
21
22
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
22
23
  // Prep the user to get USH back out at some point
23
24
  yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
24
25
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
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);
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);
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, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, 0, false, false);
38
- if (vaultAccount.collateralType === 'SOL') {
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()) {
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, 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') {
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()) {
54
54
  transaction.add(serum_1.TokenInstructions.closeAccount({
55
55
  source: wrappedSolAccount.publicKey,
56
56
  destination: payer.publicKey,
@@ -18,8 +18,7 @@ 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 vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
22
- const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
21
+ const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
23
22
  const collateralMint = vaultTypeAccountInfo.collateralMint;
24
23
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
25
24
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
@@ -30,24 +29,23 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
30
29
  const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true);
31
30
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultPublicKey, true);
32
31
  const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
33
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
32
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultAccount.vaultType, true);
34
33
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
35
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, false, true);
34
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, 0, false, true);
36
35
  const history = web3_js_1.Keypair.generate();
37
36
  const newEra = web3_js_1.Keypair.generate();
38
37
  const transaction = new web3_js_1.Transaction();
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));
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));
40
39
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra]);
41
40
  return vaultPublicKey;
42
41
  });
43
42
  }
44
43
  exports.liquidateVault = liquidateVault;
45
- function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, collateralType, overrideTime) {
44
+ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultTypeAccount, overrideTime) {
46
45
  return __awaiter(this, void 0, void 0, function* () {
47
46
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
48
47
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
49
48
  const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
50
- const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
51
49
  return yield program.methods
52
50
  .liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
53
51
  )
@@ -15,19 +15,20 @@ 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');
18
20
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
19
21
  return __awaiter(this, void 0, void 0, function* () {
20
22
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
21
23
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
22
24
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
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);
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);
26
27
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
27
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
28
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, loanAmount, false, false);
28
29
  const history = web3_js_1.Keypair.generate();
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]);
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);
31
32
  return vaultPublicKey;
32
33
  });
33
34
  }
@@ -22,14 +22,13 @@ 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 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);
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);
28
27
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
29
28
  const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
30
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, true, false);
29
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, 0, true, false);
31
30
  const history = web3_js_1.Keypair.generate();
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));
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));
33
32
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
34
33
  return vaultPublicKey;
35
34
  });
@@ -32,7 +32,7 @@ function refreshOraclePriceInstruction(program, collateralType, network, overrid
32
32
  .accounts({
33
33
  oracleInfoAccount: oracleInfoAccount,
34
34
  vaultTypeAccount: vaultTypeAccount,
35
- oracleChainlink: chainlinkAccunts[network],
35
+ oracleChainlink: chainlinkAccounts[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 chainlinkAccunts = {
55
+ const chainlinkAccounts = {
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,13 +21,12 @@ 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 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);
24
+ const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
25
+ const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultAccount.vaultType, vaultTypeAccount.collateralMint);
27
26
  const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
28
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, repayAmount * -1, false, false);
27
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, repayAmount * -1, false, false);
29
28
  const history = web3_js_1.Keypair.generate();
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));
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));
31
30
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
32
31
  return vaultPublicKey;
33
32
  });
@@ -24,15 +24,14 @@ 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);
28
27
  const vaultAssociatedCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, serum_1.TokenInstructions.WRAPPED_SOL_MINT, vaultPublicKey, 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);
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);
31
30
  const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
32
31
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
33
32
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
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));
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));
36
35
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
37
36
  return vaultPublicKey;
38
37
  });
@@ -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;