hedge-web3 0.1.46 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/Constants.d.ts +2 -1
- package/declarations/idl/vault.d.ts +109 -35
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createStakingPool.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -1
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
- package/declarations/instructions/depositStakingPool.d.ts +1 -1
- package/declarations/instructions/depositVault.d.ts +1 -1
- package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -1
- package/declarations/instructions/redeemVault.d.ts +1 -1
- package/declarations/instructions/refreshOraclePrice.d.ts +3 -3
- package/declarations/instructions/repayVault.d.ts +1 -1
- package/declarations/instructions/setHalted.d.ts +1 -1
- package/declarations/instructions/updateVaultType.d.ts +4 -1
- package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -1
- package/declarations/state/VaultAccount.d.ts +4 -3
- package/declarations/utils/getLinkedListAccounts.d.ts +1 -1
- package/lib/Constants.js +3 -2
- package/lib/idl/vault.js +109 -35
- package/lib/instructions/claimLiquidationPoolPosition.js +5 -1
- package/lib/instructions/claimStakingPoolPosition.js +5 -1
- package/lib/instructions/closeLiquidationPoolPosition.js +5 -1
- package/lib/instructions/createStakingPool.js +5 -2
- package/lib/instructions/createVault.js +5 -1
- package/lib/instructions/depositLiquidationPool.js +5 -1
- package/lib/instructions/depositStakingPool.js +5 -1
- package/lib/instructions/depositVault.js +5 -1
- package/lib/instructions/initHedgeFoundation.js +5 -1
- package/lib/instructions/initHedgeFoundationTokens.js +5 -1
- package/lib/instructions/liquidateVault.js +5 -1
- package/lib/instructions/loanVault.js +5 -3
- package/lib/instructions/redeemVault.js +5 -1
- package/lib/instructions/refreshOraclePrice.js +6 -1
- package/lib/instructions/repayVault.js +5 -1
- package/lib/instructions/setHalted.js +5 -1
- package/lib/instructions/updateVaultType.js +9 -2
- package/lib/instructions/withdrawStakingPool.js +5 -1
- package/lib/instructions/withdrawVault.js +5 -1
- package/lib/state/VaultAccount.js +11 -9
- package/lib/utils/getLinkedListAccounts.js +48 -48
- package/package.json +1 -1
- package/src/Constants.ts +2 -1
- package/src/idl/vault.ts +218 -70
- package/src/instructions/claimLiquidationPoolPosition.ts +3 -2
- package/src/instructions/claimStakingPoolPosition.ts +3 -2
- package/src/instructions/closeLiquidationPoolPosition.ts +3 -2
- package/src/instructions/createStakingPool.ts +3 -3
- package/src/instructions/createVault.ts +3 -2
- package/src/instructions/depositLiquidationPool.ts +3 -2
- package/src/instructions/depositStakingPool.ts +3 -2
- package/src/instructions/depositVault.ts +3 -3
- package/src/instructions/initHedgeFoundation.ts +3 -2
- package/src/instructions/initHedgeFoundationTokens.ts +2 -1
- package/src/instructions/liquidateVault.ts +5 -3
- package/src/instructions/loanVault.ts +3 -4
- package/src/instructions/redeemVault.ts +3 -2
- package/src/instructions/refreshOraclePrice.ts +7 -4
- package/src/instructions/repayVault.ts +3 -2
- package/src/instructions/setHalted.ts +3 -2
- package/src/instructions/updateVaultType.ts +10 -2
- package/src/instructions/withdrawStakingPool.ts +3 -2
- package/src/instructions/withdrawVault.ts +3 -2
- package/src/state/VaultAccount.ts +17 -12
- package/src/state/VaultType.ts +62 -0
- package/src/utils/getLinkedListAccounts.ts +54 -49
- package/src/utils/sendAndConfirmWithDebug.ts +27 -0
@@ -8,6 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
exports.repayVaultInstruction = exports.repayVault = void 0;
|
13
16
|
const anchor_1 = require("@project-serum/anchor");
|
@@ -15,6 +18,7 @@ const spl_token_1 = require("@solana/spl-token");
|
|
15
18
|
const web3_js_1 = require("@solana/web3.js");
|
16
19
|
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
17
20
|
const Constants_1 = require("../Constants");
|
21
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
18
22
|
function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
|
19
23
|
return __awaiter(this, void 0, void 0, function* () {
|
20
24
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -27,7 +31,7 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
|
|
27
31
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, repayAmount * -1, false, false);
|
28
32
|
const history = web3_js_1.Keypair.generate();
|
29
33
|
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
|
-
yield (0,
|
34
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
|
31
35
|
return vaultPublicKey;
|
32
36
|
});
|
33
37
|
}
|
@@ -8,16 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
exports.setHaltedInstruction = exports.setHalted = void 0;
|
13
16
|
const web3_js_1 = require("@solana/web3.js");
|
14
17
|
const Constants_1 = require("../Constants");
|
15
18
|
const Errors_1 = require("../utils/Errors");
|
19
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
16
20
|
function setHalted(program, provider, payer, halted) {
|
17
21
|
return __awaiter(this, void 0, void 0, function* () {
|
18
22
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
19
23
|
const transaction = new web3_js_1.Transaction().add(yield setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted));
|
20
|
-
yield (0,
|
24
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
21
25
|
return vaultSystemStatePublicKey;
|
22
26
|
});
|
23
27
|
}
|
@@ -8,21 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
exports.updateVaultTypeStatusInstruction = exports.updateVaultType = void 0;
|
13
16
|
const web3_js_1 = require("@solana/web3.js");
|
14
17
|
const Constants_1 = require("../Constants");
|
18
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
15
19
|
function updateVaultType(program, provider, payer, vaultTypeAccount, oracleInfoAccount, config) {
|
16
20
|
return __awaiter(this, void 0, void 0, function* () {
|
17
21
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
18
22
|
const transaction = new web3_js_1.Transaction().add(yield updateVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, oracleInfoAccount, config));
|
19
|
-
yield (0,
|
23
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
20
24
|
return vaultSystemStatePublicKey;
|
21
25
|
});
|
22
26
|
}
|
23
27
|
exports.updateVaultType = updateVaultType;
|
24
28
|
function updateVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, oracleInfoAccount, vaultTypeConfig) {
|
25
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
29
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
26
30
|
return __awaiter(this, void 0, void 0, function* () {
|
27
31
|
const config = {
|
28
32
|
maxDebtExtended: (_a = vaultTypeConfig.maxDebtExtended) !== null && _a !== void 0 ? _a : null,
|
@@ -32,6 +36,9 @@ function updateVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, pa
|
|
32
36
|
oraclePyth: (_e = vaultTypeConfig.oraclePyth) !== null && _e !== void 0 ? _e : null,
|
33
37
|
oracleSwitchboard: (_f = vaultTypeConfig.oracleSwitchboard) !== null && _f !== void 0 ? _f : null,
|
34
38
|
deprecated: (_g = vaultTypeConfig.deprecated) !== null && _g !== void 0 ? _g : null,
|
39
|
+
priorityPyth: (_h = vaultTypeConfig.priorityPyth) !== null && _h !== void 0 ? _h : null,
|
40
|
+
priorityChainlink: (_j = vaultTypeConfig.priorityChainlink) !== null && _j !== void 0 ? _j : null,
|
41
|
+
prioritySwitchboard: (_k = vaultTypeConfig.prioritySwitchboard) !== null && _k !== void 0 ? _k : null,
|
35
42
|
};
|
36
43
|
return yield program.methods
|
37
44
|
.updateVaultType(config)
|
@@ -8,6 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
exports.withdrawStakingPoolInstruction = exports.withdrawStakingPool = void 0;
|
13
16
|
const anchor_1 = require("@project-serum/anchor");
|
@@ -15,11 +18,12 @@ const spl_token_1 = require("@solana/spl-token");
|
|
15
18
|
const web3_js_1 = require("@solana/web3.js");
|
16
19
|
const Errors_1 = require("../utils/Errors");
|
17
20
|
const Constants_1 = require("../Constants");
|
21
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
18
22
|
function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
19
23
|
return __awaiter(this, void 0, void 0, function* () {
|
20
24
|
const poolPosition = web3_js_1.Keypair.generate();
|
21
25
|
const transaction = new web3_js_1.Transaction().add(yield withdrawStakingPoolInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime));
|
22
|
-
yield (0,
|
26
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
23
27
|
return poolPosition.publicKey;
|
24
28
|
});
|
25
29
|
}
|
@@ -8,6 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
exports.withdrawVaultInstruction = exports.withdrawVault = void 0;
|
13
16
|
const anchor_1 = require("@project-serum/anchor");
|
@@ -16,6 +19,7 @@ const serum_1 = require("@project-serum/serum");
|
|
16
19
|
const web3_js_1 = require("@solana/web3.js");
|
17
20
|
const Constants_1 = require("../Constants");
|
18
21
|
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
22
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
19
23
|
function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount, overrideTime) {
|
20
24
|
return __awaiter(this, void 0, void 0, function* () {
|
21
25
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -32,7 +36,7 @@ function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount,
|
|
32
36
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
33
37
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, withdrawAmount * -1, 0, false, false);
|
34
38
|
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));
|
35
|
-
yield (0,
|
39
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
|
36
40
|
return vaultPublicKey;
|
37
41
|
});
|
38
42
|
}
|
@@ -93,10 +93,14 @@ class VaultAccount {
|
|
93
93
|
.toString()
|
94
94
|
.substring(this.publicKey.toString().length - 6)}`;
|
95
95
|
}
|
96
|
-
addDebt(
|
97
|
-
|
96
|
+
addDebt(additionalDebt, vaultTypeAccount) {
|
97
|
+
let loanFee = new decimal_js_1.default(0);
|
98
|
+
if (additionalDebt.isPositive()) {
|
99
|
+
loanFee = vaultTypeAccount.loanInitFee.mul(additionalDebt);
|
100
|
+
}
|
101
|
+
const totalNormalizedLoan = additionalDebt.add(loanFee);
|
102
|
+
const denormalizedNewDebt = totalNormalizedLoan.div(new decimal_js_1.default(vaultTypeAccount.cumulativeRate.toString()));
|
98
103
|
this.denormalizedDebt = denormalizedNewDebt.add(new decimal_js_1.default(this.denormalizedDebt)).floor().toNumber();
|
99
|
-
// this.denormalizedDebt = parseFloat(this.denormalizedDebt.toFixed(0))
|
100
104
|
}
|
101
105
|
addDeposit(depositAmount) {
|
102
106
|
this.deposited += depositAmount;
|
@@ -112,16 +116,14 @@ class VaultAccount {
|
|
112
116
|
this.vaultStatus = 'liquidated';
|
113
117
|
}
|
114
118
|
updateDebtAndCollateral(vaultTypeAccountData) {
|
115
|
-
|
116
|
-
const collateralAccumulatorCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccountData.collateralRedistributionAccumulator);
|
117
|
-
this.denormalizedDebt = debtProductCurrent
|
119
|
+
this.denormalizedDebt = vaultTypeAccountData.debtRedistributionProduct
|
118
120
|
.div(this.debtProductSnapshotBytes)
|
119
121
|
.mul(new decimal_js_1.default(this.denormalizedDebt))
|
120
122
|
.toNumber();
|
121
|
-
const extraCollateralDeposited = this.denormalizedDebt *
|
123
|
+
const extraCollateralDeposited = this.denormalizedDebt * vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber();
|
122
124
|
this.deposited += extraCollateralDeposited;
|
123
|
-
this.collateralAccumulatorSnapshotBytes =
|
124
|
-
this.debtProductSnapshotBytes =
|
125
|
+
this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator;
|
126
|
+
this.debtProductSnapshotBytes = vaultTypeAccountData.debtRedistributionProduct;
|
125
127
|
}
|
126
128
|
toString(highlight) {
|
127
129
|
let arrow = '';
|
@@ -15,20 +15,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getLinkedListAccounts = void 0;
|
16
16
|
const underscore_1 = __importDefault(require("underscore"));
|
17
17
|
const Constants_1 = require("../Constants");
|
18
|
-
const HedgeDecimal_1 = require("../HedgeDecimal");
|
19
18
|
const VaultAccount_1 = require("../state/VaultAccount");
|
20
19
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
21
20
|
const bs58_1 = __importDefault(require("bs58"));
|
21
|
+
const VaultType_1 = __importDefault(require("../state/VaultType"));
|
22
22
|
function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, loanAmount, redeem, liquidate, cachedVaults) {
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
|
25
|
-
const
|
24
|
+
const vaultTypeRaw = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
25
|
+
const vaultType = new VaultType_1.default(vaultTypeRaw, vaultTypeAccountPublicKey);
|
26
|
+
const DEBUG = false;
|
26
27
|
// Default for null is the vault itself, so set them all to this vault
|
27
28
|
let oldSmallerPublicKey = vaultPublicKey;
|
28
29
|
let newSmallerPublicKey = vaultPublicKey;
|
29
30
|
let newLargerPublicKey = vaultPublicKey;
|
30
31
|
const thisVaultData = yield program.account.vault.fetch(vaultPublicKey);
|
31
|
-
const accountInfo =
|
32
|
+
// const accountInfo = await program.provider.connection.getAccountInfo(vaultPublicKey)
|
32
33
|
const thisVault = new VaultAccount_1.VaultAccount(thisVaultData, vaultPublicKey);
|
33
34
|
// Load all the vaults
|
34
35
|
let vaults;
|
@@ -36,27 +37,14 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
36
37
|
vaults = cachedVaults;
|
37
38
|
}
|
38
39
|
else {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
// memcmp: { bytes: vaultTypeAccount.collateralType, offset: 8 + 32 + 8 },
|
45
|
-
// },
|
46
|
-
// ])
|
47
|
-
// .catch((error) => {
|
48
|
-
// console.log('error', error)
|
49
|
-
// })) || []
|
50
|
-
// // Load them into our account objects
|
51
|
-
// vaults = allVaults.map((vault) => {
|
52
|
-
// return new VaultAccount(vault.account, vault.publicKey)
|
53
|
-
// })
|
54
|
-
vaults = yield getMiniVaults(program, vaultTypeAccount.vaultTypeName);
|
40
|
+
vaults = yield getMiniVaults(program, vaultTypeAccountPublicKey);
|
41
|
+
}
|
42
|
+
if (DEBUG) {
|
43
|
+
console.log('Vault count found:', vaults.length);
|
44
|
+
console.log('First Vault', vaults[0]);
|
55
45
|
}
|
56
|
-
// console.log('Vault count found:', vaults.length)
|
57
|
-
// console.log('First Vault', vaults[0])
|
58
46
|
// Filter out the accounts that are not open
|
59
|
-
// TODO filter on vault status. Or we enable people to "close out" empty vaults
|
47
|
+
// TODO filter on vault status. Or we enable people to "close out" empty vaults
|
60
48
|
// vaults = _.filter(vaults, (vault) => {
|
61
49
|
// return vault.vaultStatus === 'open'
|
62
50
|
// })
|
@@ -77,11 +65,13 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
77
65
|
if (indexBefore > 0) {
|
78
66
|
oldSmallerPublicKey = vaults[indexBefore - 1].publicKey;
|
79
67
|
}
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
68
|
+
if (DEBUG) {
|
69
|
+
// Pretty print the list again
|
70
|
+
console.log('Sorted open vaults. Index Before: ', indexBefore);
|
71
|
+
console.log(vaults.map((vault) => {
|
72
|
+
return vault.toString(vaultPublicKey);
|
73
|
+
}));
|
74
|
+
}
|
85
75
|
// Pretty print all the vaults before the operation
|
86
76
|
// console.log('Sorted open vaults BEFORE at index:', indexBefore)
|
87
77
|
// let correctOrderBefore = true
|
@@ -112,9 +102,8 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
112
102
|
// Now that we know it's def in the list, iterate the list and update
|
113
103
|
// this vault with the operation we're going to apply
|
114
104
|
const newNormalizedDebt = new decimal_js_1.default(loanAmount);
|
115
|
-
|
116
|
-
vaults[indexBefore].
|
117
|
-
vaults[indexBefore].addDebt(newNormalizedDebt, vaultTypeCompoundedInterest);
|
105
|
+
vaults[indexBefore].updateDebtAndCollateral(vaultType);
|
106
|
+
vaults[indexBefore].addDebt(newNormalizedDebt, vaultType);
|
118
107
|
vaults[indexBefore].addDeposit(depositAmount);
|
119
108
|
if (liquidate) {
|
120
109
|
vaults[indexBefore].liquidate();
|
@@ -134,15 +123,17 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
134
123
|
indexAfter = index;
|
135
124
|
}
|
136
125
|
});
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
126
|
+
if (DEBUG) {
|
127
|
+
// New list with vault
|
128
|
+
console.log('New list with vault now at index:', indexAfter);
|
129
|
+
console.log(vaults.map((vault) => {
|
130
|
+
return vault.toString(vaultPublicKey);
|
131
|
+
}));
|
132
|
+
}
|
133
|
+
if (DEBUG) {
|
134
|
+
// Print where it moved from / to
|
135
|
+
console.log('Index After', indexAfter);
|
136
|
+
}
|
146
137
|
// Save references to the new left and right
|
147
138
|
if (indexAfter > 0) {
|
148
139
|
newSmallerPublicKey = vaults[indexAfter - 1].publicKey;
|
@@ -150,10 +141,12 @@ function getLinkedListAccounts(program, provider, vaultTypeAccountPublicKey, vau
|
|
150
141
|
if (indexAfter < vaults.length - 1 && indexAfter >= 0) {
|
151
142
|
newLargerPublicKey = vaults[indexAfter + 1].publicKey;
|
152
143
|
}
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
144
|
+
if (DEBUG) {
|
145
|
+
// Print out the new left/right
|
146
|
+
console.log('oldSmallerPublicKey', oldSmallerPublicKey.toString());
|
147
|
+
console.log('newSmallerPublicKey', newSmallerPublicKey.toString());
|
148
|
+
console.log('newLargerPublicKey', newLargerPublicKey.toString());
|
149
|
+
}
|
157
150
|
return [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaults];
|
158
151
|
});
|
159
152
|
}
|
@@ -168,7 +161,7 @@ function sortVaults(a, b) {
|
|
168
161
|
}
|
169
162
|
return aRatio - bRatio;
|
170
163
|
}
|
171
|
-
function getMiniVaults(program,
|
164
|
+
function getMiniVaults(program, vaultTypePublicKey) {
|
172
165
|
return __awaiter(this, void 0, void 0, function* () {
|
173
166
|
const filters = [
|
174
167
|
// Filter for Vault Accounts
|
@@ -176,13 +169,20 @@ function getMiniVaults(program, vaultTypeName) {
|
|
176
169
|
// @ts-ignore
|
177
170
|
memcmp: program.account.vault.coder.accounts.memcmp(program.account.vault._idlAccount.name),
|
178
171
|
},
|
179
|
-
// Filter for Vaults
|
172
|
+
// Filter for Vaults that are open
|
180
173
|
{
|
181
174
|
memcmp: {
|
182
|
-
bytes: bs58_1.default.encode(
|
175
|
+
bytes: bs58_1.default.encode(Buffer.from([1])),
|
183
176
|
offset: 8 + 32 + 24,
|
184
177
|
},
|
185
178
|
},
|
179
|
+
// Filter for Vaults with this collateral type
|
180
|
+
{
|
181
|
+
memcmp: {
|
182
|
+
bytes: vaultTypePublicKey.toString(),
|
183
|
+
offset: 8 + 32 + 24 + 1,
|
184
|
+
},
|
185
|
+
},
|
186
186
|
];
|
187
187
|
const allAccounts = yield program.provider.connection.getProgramAccounts(Constants_1.HEDGE_PROGRAM_PUBLICKEY, {
|
188
188
|
filters: filters,
|
@@ -193,7 +193,7 @@ function getMiniVaults(program, vaultTypeName) {
|
|
193
193
|
length: 24,
|
194
194
|
},
|
195
195
|
});
|
196
|
-
return allAccounts.map(vaultData => {
|
196
|
+
return allAccounts.map((vaultData) => {
|
197
197
|
return VaultAccount_1.VaultAccount.FromMiniSlice(vaultData.account.data, vaultData.pubkey);
|
198
198
|
});
|
199
199
|
});
|
package/package.json
CHANGED
package/src/Constants.ts
CHANGED
@@ -4,12 +4,13 @@ import {
|
|
4
4
|
} from '@solana/spl-token'
|
5
5
|
import { PublicKey } from '@solana/web3.js'
|
6
6
|
|
7
|
-
export const HEDGE_PROGRAM_ID = '
|
7
|
+
export const HEDGE_PROGRAM_ID = 'HedgeiSAoDWrgfyJ9z8XVsxhcCY2D9aHq1o3kTEbG1C1'
|
8
8
|
export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
|
9
9
|
|
10
10
|
export const CHAINLINK_SOL_USD_ID =
|
11
11
|
'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
|
12
12
|
export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
|
13
|
+
export const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
|
13
14
|
|
14
15
|
const enc = new TextEncoder()
|
15
16
|
|