hedge-web3 0.2.8 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,12 +27,16 @@ const web3_js_1 = require("@solana/web3.js");
27
27
  const decimal_js_1 = __importDefault(require("decimal.js"));
28
28
  const HedgeDecimal_1 = require("../HedgeDecimal");
29
29
  const borsh = __importStar(require("@project-serum/borsh"));
30
+ const bn_js_1 = __importDefault(require("bn.js"));
30
31
  /**
31
32
  * A class that represents an on-chian vault.
32
33
  */
33
34
  class VaultAccount {
34
35
  constructor(vault, publicKey) {
35
- var _a, _b;
36
+ /** The deposited collateral of the vault (in SOL Lamports). */
37
+ this.deposited = new bn_js_1.default(0);
38
+ /** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
39
+ this.denormalizedDebt = new bn_js_1.default(0);
36
40
  /** The ordered number of when this vault was created. */
37
41
  this.vaultNumber = 0;
38
42
  /** Debt redistribution snapshot */
@@ -44,8 +48,8 @@ class VaultAccount {
44
48
  this.publicKey = publicKey;
45
49
  this.vaultOwner = vault.vaultOwner;
46
50
  this.pdaSalt = vault.pdaSalt;
47
- this.deposited = (_a = vault.deposited) === null || _a === void 0 ? void 0 : _a.toNumber();
48
- this.denormalizedDebt = (_b = vault.denormalizedDebt) === null || _b === void 0 ? void 0 : _b.toNumber();
51
+ this.deposited = vault.deposited;
52
+ this.denormalizedDebt = vault.denormalizedDebt;
49
53
  if (vault.vaultNumber) {
50
54
  this.vaultNumber = vault.vaultNumber.toNumber();
51
55
  }
@@ -71,21 +75,22 @@ class VaultAccount {
71
75
  isOwnedBy(publicKey) {
72
76
  return publicKey && publicKey.toString() === this.vaultOwner.toString();
73
77
  }
74
- /**
75
- * Get the collateral value in SOL
76
- *
77
- * @returns collateral value in SOL
78
- */
79
- inSol() {
80
- return this.deposited / web3_js_1.LAMPORTS_PER_SOL;
81
- }
78
+ // /**
79
+ // * Get the collateral value in SOL
80
+ // *
81
+ // * @returns collateral value in SOL
82
+ // */
83
+ // public inSol(): number {
84
+ // This should not be LAMPORTS_PER_SOL. Should be collateral units like Ray
85
+ // return new Decimal(this.deposited.toString()).div(LAMPORTS_PER_SOL).toNumber()
86
+ // }
82
87
  /**
83
88
  * Get the debt value in USH
84
89
  *
85
90
  * @returns debt value in USH
86
91
  */
87
92
  inUsd() {
88
- return this.denormalizedDebt / web3_js_1.LAMPORTS_PER_SOL;
93
+ return new decimal_js_1.default(this.denormalizedDebt.toString()).div(web3_js_1.LAMPORTS_PER_SOL).toNumber();
89
94
  }
90
95
  /**
91
96
  * Pretty print the vault publickey for easy display
@@ -97,35 +102,69 @@ class VaultAccount {
97
102
  .toString()
98
103
  .substring(this.publicKey.toString().length - 6)}`;
99
104
  }
105
+ /**
106
+ * Add additional debt to the vault.
107
+ *
108
+ * @param {BN} additionalDebt - Additional normalized debt to add in (USH) lamports.
109
+ * @param {VaultType} vaultTypeAccount - Vault's vaultType
110
+ *
111
+ */
100
112
  addDebt(additionalDebt, vaultTypeAccount) {
101
- let loanFee = new decimal_js_1.default(0);
102
- if (additionalDebt.isPositive()) {
103
- loanFee = vaultTypeAccount.loanInitFee.mul(additionalDebt);
104
- }
105
- const totalNormalizedLoan = additionalDebt.add(loanFee);
106
- const denormalizedNewDebt = totalNormalizedLoan.div(new decimal_js_1.default(vaultTypeAccount.cumulativeRate.toString()));
107
- this.denormalizedDebt = denormalizedNewDebt.add(new decimal_js_1.default(this.denormalizedDebt)).floor().toNumber();
113
+ const additionalDebtAsDecimal = new decimal_js_1.default(additionalDebt.toString());
114
+ // Calculate the fee on the loan
115
+ const loanFee = vaultTypeAccount.loanInitFee.mul(additionalDebtAsDecimal);
116
+ // TODO: There's a chance this needs to be .Floor()
117
+ const totalNormalizedLoan = additionalDebtAsDecimal.add(loanFee);
118
+ const denormalizedNewDebt = new bn_js_1.default(totalNormalizedLoan.div(vaultTypeAccount.cumulativeRate).floor().toString());
119
+ this.denormalizedDebt = this.denormalizedDebt.add(denormalizedNewDebt);
108
120
  }
109
- addDeposit(depositAmount) {
110
- this.deposited += depositAmount;
121
+ /**
122
+ * Repay debt on a vault
123
+ *
124
+ * @param {BN} repayAmount - Normalized debt to repay in (USH) lamports.
125
+ * @param {VaultType} vaultTypeAccount - Vault's vaultType
126
+ *
127
+ */
128
+ repayDebt(repayAmount, vaultTypeAccount) {
129
+ const denormalizedRepayment = new decimal_js_1.default(repayAmount.toString()).div(vaultTypeAccount.cumulativeRate).floor();
130
+ this.denormalizedDebt = this.denormalizedDebt.sub(new bn_js_1.default(denormalizedRepayment.toString()));
131
+ }
132
+ /**
133
+ * Deposit Collateral
134
+ *
135
+ * @param {BN} depositAmount - Amount to deposit in (CollateralMint) lamports
136
+ *
137
+ */
138
+ depositCollateral(depositAmount) {
139
+ this.deposited = this.deposited.add(depositAmount);
140
+ }
141
+ /**
142
+ * Withdraw Collateral
143
+ *
144
+ * @param {BN} withdrawAmount - Amount to withdraw in (CollateralMint) lamports
145
+ *
146
+ */
147
+ withdrawCollateral(withdrawAmount) {
148
+ this.deposited = this.deposited.sub(withdrawAmount);
111
149
  }
112
150
  redeem() {
113
151
  // TODO - Calculate actual redeem amount and adust correctly
114
- this.denormalizedDebt = 0;
152
+ this.denormalizedDebt = new bn_js_1.default(0);
115
153
  this.vaultStatus = 'initialized';
116
154
  }
117
155
  liquidate() {
118
156
  // TODO - Calculate actual liquidate amount and adust correctly
119
- this.denormalizedDebt = 0;
157
+ this.denormalizedDebt = new bn_js_1.default(0);
120
158
  this.vaultStatus = 'liquidated';
121
159
  }
122
160
  updateDebtAndCollateral(vaultTypeAccountData) {
123
- this.denormalizedDebt = vaultTypeAccountData.debtRedistributionProduct
161
+ this.denormalizedDebt = new bn_js_1.default(vaultTypeAccountData.debtRedistributionProduct
124
162
  .div(this.debtProductSnapshotBytes)
125
- .mul(new decimal_js_1.default(this.denormalizedDebt))
126
- .toNumber();
127
- const extraCollateralDeposited = this.denormalizedDebt * vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber();
128
- this.deposited += extraCollateralDeposited;
163
+ .mul(new decimal_js_1.default(this.denormalizedDebt.toString()))
164
+ .floor()
165
+ .toString());
166
+ const extraCollateralDeposited = new decimal_js_1.default(this.denormalizedDebt.toString()).mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()).floor();
167
+ this.deposited = this.deposited.add(new bn_js_1.default(extraCollateralDeposited.toString()));
129
168
  this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator;
130
169
  this.debtProductSnapshotBytes = vaultTypeAccountData.debtRedistributionProduct;
131
170
  }
@@ -135,8 +174,8 @@ class VaultAccount {
135
174
  arrow = ' <----!!';
136
175
  }
137
176
  let collateralRatio = 'Infinite';
138
- if (this.denormalizedDebt > 0) {
139
- collateralRatio = new decimal_js_1.default(this.deposited).div(new decimal_js_1.default(this.denormalizedDebt)).toString();
177
+ if (this.denormalizedDebt.gt(new bn_js_1.default(0))) {
178
+ collateralRatio = new decimal_js_1.default(this.deposited.toString()).div(new decimal_js_1.default(this.denormalizedDebt.toString())).toString();
140
179
  }
141
180
  let nextVault = 'None';
142
181
  if (this.nextVaultToRedeem) {
@@ -13,13 +13,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getLinkedListAccounts = void 0;
16
+ const anchor_1 = require("@project-serum/anchor");
16
17
  const underscore_1 = __importDefault(require("underscore"));
17
18
  const Constants_1 = require("../Constants");
18
19
  const VaultAccount_1 = require("../state/VaultAccount");
19
20
  const decimal_js_1 = __importDefault(require("decimal.js"));
20
21
  const bs58_1 = __importDefault(require("bs58"));
21
22
  const VaultType_1 = __importDefault(require("../state/VaultType"));
22
- function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, loanAmount, redeem, liquidate, cachedVaults) {
23
+ /**
24
+ * Get the accounts the left and right for re-inserting in the linked list
25
+ *
26
+ * @param {Program<Vault>} program - Anchor program <Vault ILD>
27
+ * @param {PublicKey} vaultTypeAccountPublicKey - Vault Type Account PublicKey
28
+ * @param {PublicKey} vaultPublicKey - Vault Account PublicKey
29
+ * @param {BN} depositAmount - Amount that will be deposited into vault with instruction
30
+ * @param {BN} withdrawAmount - Amount that will be withdrawn from vault with instruction
31
+ * @param {BN} loanAmount - Amount that will be deposited into vault with transaction (sans fees)
32
+ * @param {BN} repayAmount - Amount that will be repaid into vault with transaction
33
+ * @param {boolean} redeem - True if vault is going to be redeemed fully
34
+ * @param {boolean} liquidate - True if vault is going to be liquidated fully
35
+ * @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
36
+ */
37
+ function getLinkedListAccounts(program, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, withdrawAmount, loanAmount, repayAmount, redeem, liquidate, cachedVaults) {
23
38
  return __awaiter(this, void 0, void 0, function* () {
24
39
  const vaultTypeRaw = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
25
40
  const vaultType = new VaultType_1.default(vaultTypeRaw, vaultTypeAccountPublicKey);
@@ -50,7 +65,7 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
50
65
  // })
51
66
  // Remove any vaults with no debt or collateral
52
67
  vaults = underscore_1.default.filter(vaults, (vault) => {
53
- return vault.denormalizedDebt > 0 && vault.deposited > 0;
68
+ return vault.denormalizedDebt.gt(new anchor_1.BN(0)) && vault.deposited.gt(new anchor_1.BN(0));
54
69
  });
55
70
  // Sort them
56
71
  vaults.sort(sortVaults);
@@ -101,17 +116,18 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
101
116
  }
102
117
  // Now that we know it's def in the list, iterate the list and update
103
118
  // this vault with the operation we're going to apply
104
- const newNormalizedDebt = new decimal_js_1.default(loanAmount);
105
119
  vaults[indexBefore].updateDebtAndCollateral(vaultType);
106
- vaults[indexBefore].addDebt(newNormalizedDebt, vaultType);
107
- vaults[indexBefore].addDeposit(depositAmount);
120
+ vaults[indexBefore].addDebt(loanAmount, vaultType);
121
+ vaults[indexBefore].repayDebt(repayAmount, vaultType);
122
+ vaults[indexBefore].depositCollateral(depositAmount);
123
+ vaults[indexBefore].withdrawCollateral(withdrawAmount);
108
124
  if (liquidate) {
109
125
  vaults[indexBefore].liquidate();
110
126
  }
111
127
  if (redeem) {
112
128
  vaults[indexBefore].redeem();
113
129
  }
114
- if (vaults[indexBefore].denormalizedDebt === 0) {
130
+ if (vaults[indexBefore].denormalizedDebt.isZero()) {
115
131
  vaults.splice(indexBefore, 1);
116
132
  }
117
133
  // Sort it again since we've changed one vault
@@ -154,12 +170,12 @@ exports.getLinkedListAccounts = getLinkedListAccounts;
154
170
  // Sort function we can use to sort the vaults
155
171
  // Sorted by collateral ratio. If two are the same, newer vault first
156
172
  function sortVaults(a, b) {
157
- const aRatio = a.deposited / a.denormalizedDebt;
158
- const bRatio = b.deposited / b.denormalizedDebt;
159
- if (aRatio === bRatio) {
173
+ const aRatio = new decimal_js_1.default(a.deposited.toString()).div(new decimal_js_1.default(a.denormalizedDebt.toString()));
174
+ const bRatio = new decimal_js_1.default(b.deposited.toString()).div(new decimal_js_1.default(b.denormalizedDebt.toString()));
175
+ if (aRatio.equals(bRatio)) {
160
176
  return a.publicKey.toString() > b.publicKey.toString() ? 1 : -1;
161
177
  }
162
- return aRatio - bRatio;
178
+ return aRatio.greaterThan(bRatio) ? 1 : -1;
163
179
  }
164
180
  function getMiniVaults(program, vaultTypePublicKey) {
165
181
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.2.8",
3
+ "version": "0.2.11",
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
@@ -14,6 +14,9 @@ export const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHn
14
14
 
15
15
  const enc = new TextEncoder()
16
16
 
17
+ /**
18
+ * @returns The Liquidation pool public key
19
+ */
17
20
  export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
18
21
  const [poolPublicKey] = await PublicKey.findProgramAddress(
19
22
  [enc.encode('LiquidationPoolStateV1')],
@@ -21,7 +24,10 @@ export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
21
24
  )
22
25
  return poolPublicKey
23
26
  }
24
-
27
+ /**
28
+ *
29
+ * @returns The liquidation pool ush account public key
30
+ */
25
31
  export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
26
32
  const [poolPublicKey] = await PublicKey.findProgramAddress(
27
33
  [enc.encode('LiquidationPoolUSHAccountV1')],
@@ -29,7 +35,10 @@ export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey
29
35
  )
30
36
  return poolPublicKey
31
37
  }
32
-
38
+ /**
39
+ *
40
+ * @returns The USH mint public key
41
+ */
33
42
  export async function getUshMintPublicKey(): Promise<PublicKey> {
34
43
  const [findMintPublicKey] = await PublicKey.findProgramAddress(
35
44
  [enc.encode('UshMintV1')],
@@ -37,7 +46,10 @@ export async function getUshMintPublicKey(): Promise<PublicKey> {
37
46
  )
38
47
  return findMintPublicKey
39
48
  }
40
-
49
+ /**
50
+ *
51
+ * @returns The Vault System State public key
52
+ */
41
53
  export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
42
54
  const [publicKey] = await PublicKey.findProgramAddress(
43
55
  [enc.encode('VaultSystemStateV1')],
@@ -46,6 +58,10 @@ export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
46
58
  return publicKey
47
59
  }
48
60
 
61
+ /**
62
+ *
63
+ * @returns The HDG mint public key
64
+ */
49
65
  export async function getHedgeMintPublicKey(): Promise<PublicKey> {
50
66
  const [publicKey] = await PublicKey.findProgramAddress(
51
67
  [enc.encode('HEDGEMintV1')],
@@ -53,7 +69,12 @@ export async function getHedgeMintPublicKey(): Promise<PublicKey> {
53
69
  )
54
70
  return publicKey
55
71
  }
56
-
72
+ /**
73
+ * Get the public key for any staking pool
74
+ *
75
+ * @param mintPublicKey Staked collateral mint public key
76
+ * @returns the public key for that staking pool
77
+ */
57
78
  export async function getPoolPublicKeyForMint(
58
79
  mintPublicKey: PublicKey
59
80
  ): Promise<[PublicKey, number, string]> {
@@ -64,6 +85,12 @@ export async function getPoolPublicKeyForMint(
64
85
  )
65
86
  return [publicKey, bump, strToEncode]
66
87
  }
88
+
89
+ /**
90
+ *
91
+ * @param collateralType String name of the collateral type (must be 16 chars)
92
+ * @returns The public key for that Vault Type account
93
+ */
67
94
  export async function getVaultTypeAccountPublicKey(
68
95
  collateralType: string
69
96
  ): Promise<PublicKey> {
@@ -73,6 +100,12 @@ export async function getVaultTypeAccountPublicKey(
73
100
  )
74
101
  return vaultTypeAccount
75
102
  }
103
+
104
+ /**
105
+ *
106
+ * @param collateralType String name of the collateral type (must be 16 chars)
107
+ * @returns The public key for that Vault Type oracle info
108
+ */
76
109
  export async function getVaultTypeOracleAccountPublicKey(
77
110
  collateralType: string
78
111
  ): Promise<PublicKey> {
@@ -82,6 +115,13 @@ export async function getVaultTypeOracleAccountPublicKey(
82
115
  )
83
116
  return vaultTypeOracleAccount
84
117
  }
118
+
119
+ /**
120
+ * Vaults are stored in PDA accounts. Use this to get the address from a salt
121
+ *
122
+ * @param vaultSalt String salt for the vault (must be 8 chars)
123
+ * @returns The public key for that Vault Type oracle info
124
+ */
85
125
  export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
86
126
  const [vaultAddress] = await PublicKey.findProgramAddress(
87
127
  [enc.encode('Vault'), enc.encode(vaultSalt)],
@@ -90,6 +130,12 @@ export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
90
130
  return vaultAddress
91
131
  }
92
132
 
133
+ /**
134
+ *
135
+ * @param walletAddress Owner public key
136
+ * @param tokenMintAddress Token mint
137
+ * @returns The associated token account public key
138
+ */
93
139
  export async function findAssociatedTokenAddress(
94
140
  walletAddress: PublicKey,
95
141
  tokenMintAddress: PublicKey
@@ -0,0 +1,159 @@
1
+ export type Pyth = {
2
+ "version": "0.1.0",
3
+ "name": "pyth",
4
+ "instructions": [
5
+ {
6
+ "name": "initialize",
7
+ "accounts": [
8
+ {
9
+ "name": "payer",
10
+ "isMut": true,
11
+ "isSigner": true
12
+ },
13
+ {
14
+ "name": "price",
15
+ "isMut": true,
16
+ "isSigner": true
17
+ },
18
+ {
19
+ "name": "systemProgram",
20
+ "isMut": false,
21
+ "isSigner": false
22
+ }
23
+ ],
24
+ "args": [
25
+ {
26
+ "name": "price",
27
+ "type": "i64"
28
+ },
29
+ {
30
+ "name": "expo",
31
+ "type": "i32"
32
+ },
33
+ {
34
+ "name": "conf",
35
+ "type": "u64"
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "name": "setPrice",
41
+ "accounts": [
42
+ {
43
+ "name": "price",
44
+ "isMut": true,
45
+ "isSigner": false
46
+ }
47
+ ],
48
+ "args": [
49
+ {
50
+ "name": "price",
51
+ "type": "i64"
52
+ }
53
+ ]
54
+ }
55
+ ],
56
+ "accounts": [
57
+ {
58
+ "name": "priceWrapper",
59
+ "type": {
60
+ "kind": "struct",
61
+ "fields": [
62
+ {
63
+ "name": "price",
64
+ "type": {
65
+ "defined": "Price"
66
+ }
67
+ }
68
+ ]
69
+ }
70
+ }
71
+ ],
72
+ "errors": [
73
+ {
74
+ "code": 6000,
75
+ "name": "InvalidTradingStatus",
76
+ "msg": "invalid trading status"
77
+ }
78
+ ]
79
+ };
80
+
81
+ export const IDL: Pyth = {
82
+ "version": "0.1.0",
83
+ "name": "pyth",
84
+ "instructions": [
85
+ {
86
+ "name": "initialize",
87
+ "accounts": [
88
+ {
89
+ "name": "payer",
90
+ "isMut": true,
91
+ "isSigner": true
92
+ },
93
+ {
94
+ "name": "price",
95
+ "isMut": true,
96
+ "isSigner": true
97
+ },
98
+ {
99
+ "name": "systemProgram",
100
+ "isMut": false,
101
+ "isSigner": false
102
+ }
103
+ ],
104
+ "args": [
105
+ {
106
+ "name": "price",
107
+ "type": "i64"
108
+ },
109
+ {
110
+ "name": "expo",
111
+ "type": "i32"
112
+ },
113
+ {
114
+ "name": "conf",
115
+ "type": "u64"
116
+ }
117
+ ]
118
+ },
119
+ {
120
+ "name": "setPrice",
121
+ "accounts": [
122
+ {
123
+ "name": "price",
124
+ "isMut": true,
125
+ "isSigner": false
126
+ }
127
+ ],
128
+ "args": [
129
+ {
130
+ "name": "price",
131
+ "type": "i64"
132
+ }
133
+ ]
134
+ }
135
+ ],
136
+ "accounts": [
137
+ {
138
+ "name": "priceWrapper",
139
+ "type": {
140
+ "kind": "struct",
141
+ "fields": [
142
+ {
143
+ "name": "price",
144
+ "type": {
145
+ "defined": "Price"
146
+ }
147
+ }
148
+ ]
149
+ }
150
+ }
151
+ ],
152
+ "errors": [
153
+ {
154
+ "code": 6000,
155
+ "name": "InvalidTradingStatus",
156
+ "msg": "invalid trading status"
157
+ }
158
+ ]
159
+ };
package/src/idl/vault.ts CHANGED
@@ -1754,6 +1754,47 @@ export type Vault = {
1754
1754
  }
1755
1755
  ],
1756
1756
  "args": []
1757
+ },
1758
+ {
1759
+ "name": "adminResetVault",
1760
+ "accounts": [
1761
+ {
1762
+ "name": "payer",
1763
+ "isMut": true,
1764
+ "isSigner": true
1765
+ },
1766
+ {
1767
+ "name": "vaultSystemState",
1768
+ "isMut": true,
1769
+ "isSigner": false
1770
+ },
1771
+ {
1772
+ "name": "vaultAccount",
1773
+ "isMut": true,
1774
+ "isSigner": false
1775
+ },
1776
+ {
1777
+ "name": "vaultAssociatedTokenAccount",
1778
+ "isMut": true,
1779
+ "isSigner": false
1780
+ },
1781
+ {
1782
+ "name": "vaultTypeAccount",
1783
+ "isMut": true,
1784
+ "isSigner": false
1785
+ },
1786
+ {
1787
+ "name": "vaultTypeAssociatedTokenAccount",
1788
+ "isMut": true,
1789
+ "isSigner": false
1790
+ }
1791
+ ],
1792
+ "args": [
1793
+ {
1794
+ "name": "amountToSendFromVaultType",
1795
+ "type": "u64"
1796
+ }
1797
+ ]
1757
1798
  }
1758
1799
  ],
1759
1800
  "accounts": [
@@ -2558,9 +2599,6 @@ export type Vault = {
2558
2599
  },
2559
2600
  {
2560
2601
  "name": "Distributed"
2561
- },
2562
- {
2563
- "name": "Redeemed"
2564
2602
  }
2565
2603
  ]
2566
2604
  }
@@ -4643,6 +4681,47 @@ export const IDL: Vault = {
4643
4681
  }
4644
4682
  ],
4645
4683
  "args": []
4684
+ },
4685
+ {
4686
+ "name": "adminResetVault",
4687
+ "accounts": [
4688
+ {
4689
+ "name": "payer",
4690
+ "isMut": true,
4691
+ "isSigner": true
4692
+ },
4693
+ {
4694
+ "name": "vaultSystemState",
4695
+ "isMut": true,
4696
+ "isSigner": false
4697
+ },
4698
+ {
4699
+ "name": "vaultAccount",
4700
+ "isMut": true,
4701
+ "isSigner": false
4702
+ },
4703
+ {
4704
+ "name": "vaultAssociatedTokenAccount",
4705
+ "isMut": true,
4706
+ "isSigner": false
4707
+ },
4708
+ {
4709
+ "name": "vaultTypeAccount",
4710
+ "isMut": true,
4711
+ "isSigner": false
4712
+ },
4713
+ {
4714
+ "name": "vaultTypeAssociatedTokenAccount",
4715
+ "isMut": true,
4716
+ "isSigner": false
4717
+ }
4718
+ ],
4719
+ "args": [
4720
+ {
4721
+ "name": "amountToSendFromVaultType",
4722
+ "type": "u64"
4723
+ }
4724
+ ]
4646
4725
  }
4647
4726
  ],
4648
4727
  "accounts": [
@@ -5447,9 +5526,6 @@ export const IDL: Vault = {
5447
5526
  },
5448
5527
  {
5449
5528
  "name": "Distributed"
5450
- },
5451
- {
5452
- "name": "Redeemed"
5453
5529
  }
5454
5530
  ]
5455
5531
  }
@@ -67,11 +67,12 @@ export async function depositVault(
67
67
  const signers = [payer, history]
68
68
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
69
69
  program,
70
- provider,
71
70
  vaultAccount.vaultType,
72
71
  vaultPublicKey,
73
- depositAmount,
74
- 0,
72
+ new BN(depositAmount),
73
+ new BN(0),
74
+ new BN(0),
75
+ new BN(0),
75
76
  false,
76
77
  false
77
78
  )
@@ -87,11 +87,12 @@ export async function liquidateVault(
87
87
 
88
88
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
89
89
  program,
90
- provider,
91
90
  vaultAccount.vaultType,
92
91
  vaultPublicKey,
93
- 0,
94
- 0,
92
+ new BN(0),
93
+ new BN(0),
94
+ new BN(0),
95
+ new BN(0),
95
96
  false,
96
97
  true
97
98
  )
@@ -59,11 +59,12 @@ export async function loanVault(
59
59
  )
60
60
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
61
61
  program,
62
- provider,
63
62
  vaultAccount.vaultType,
64
63
  vaultPublicKey,
65
- 0,
66
- loanAmount,
64
+ new BN(0),
65
+ new BN(0),
66
+ new BN(loanAmount),
67
+ new BN(0),
67
68
  false,
68
69
  false
69
70
  )