hedge-web3 0.2.27 → 0.2.28
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.
@@ -16,5 +16,6 @@ import { VaultAccount } from '../state/VaultAccount';
|
|
16
16
|
* @param {boolean} redeem - True if vault is going to be redeemed fully
|
17
17
|
* @param {boolean} liquidate - True if vault is going to be liquidated fully
|
18
18
|
* @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
|
19
|
+
* @param {VaultAccount} preLoadedVault - Optional vault to use as target vault. Overrides the need to load the vault from on-chain data.
|
19
20
|
*/
|
20
|
-
export declare function getLinkedListAccounts(program: Program<Vault>, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: BN, withdrawAmount: BN, loanAmount: BN, repayAmount: BN, redeem: boolean, liquidate: boolean, cachedVaults?: VaultAccount[]): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]>;
|
21
|
+
export declare function getLinkedListAccounts(program: Program<Vault>, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: BN, withdrawAmount: BN, loanAmount: BN, repayAmount: BN, redeem: boolean, liquidate: boolean, cachedVaults?: VaultAccount[], preLoadedVault?: VaultAccount): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]>;
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.getLinkedListAccounts = void 0;
|
16
16
|
const anchor_1 = require("@project-serum/anchor");
|
17
|
-
const web3_js_1 = require("@solana/web3.js");
|
18
17
|
const underscore_1 = __importDefault(require("underscore"));
|
19
18
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
20
19
|
const VaultAccount_1 = require("../state/VaultAccount");
|
@@ -33,8 +32,9 @@ const VaultType_1 = __importDefault(require("../state/VaultType"));
|
|
33
32
|
* @param {boolean} redeem - True if vault is going to be redeemed fully
|
34
33
|
* @param {boolean} liquidate - True if vault is going to be liquidated fully
|
35
34
|
* @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
|
35
|
+
* @param {VaultAccount} preLoadedVault - Optional vault to use as target vault. Overrides the need to load the vault from on-chain data.
|
36
36
|
*/
|
37
|
-
function getLinkedListAccounts(program, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, withdrawAmount, loanAmount, repayAmount, redeem, liquidate, cachedVaults) {
|
37
|
+
function getLinkedListAccounts(program, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, withdrawAmount, loanAmount, repayAmount, redeem, liquidate, cachedVaults, preLoadedVault) {
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
39
39
|
const vaultTypeRaw = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
40
40
|
const vaultType = new VaultType_1.default(vaultTypeRaw, vaultTypeAccountPublicKey);
|
@@ -43,25 +43,9 @@ function getLinkedListAccounts(program, vaultTypeAccountPublicKey, vaultPublicKe
|
|
43
43
|
let oldSmallerPublicKey = vaultPublicKey;
|
44
44
|
let newSmallerPublicKey = vaultPublicKey;
|
45
45
|
let newLargerPublicKey = vaultPublicKey;
|
46
|
-
const
|
47
|
-
|
48
|
-
|
49
|
-
return {
|
50
|
-
vaultOwner: new web3_js_1.PublicKey('11111111111111111111111111111111'),
|
51
|
-
pdaSalt: 'foo',
|
52
|
-
deposited: new anchor_1.BN(0),
|
53
|
-
denormalizedDebt: new anchor_1.BN(0),
|
54
|
-
vaultNumber: new anchor_1.BN(0),
|
55
|
-
debtProductSnapshotBytes: new anchor_1.BN(1),
|
56
|
-
collateralAccumulatorSnapshotBytes: new anchor_1.BN(1),
|
57
|
-
vaultTypeName: vaultType.name,
|
58
|
-
nextVaultToRedeem: new web3_js_1.PublicKey('11111111111111111111111111111111'),
|
59
|
-
vaultStatus: { open: true },
|
60
|
-
vaultType: vaultTypeAccountPublicKey
|
61
|
-
};
|
62
|
-
});
|
63
|
-
// const accountInfo = await program.provider.connection.getAccountInfo(vaultPublicKey)
|
64
|
-
const thisVault = new VaultAccount_1.VaultAccount(thisVaultData, vaultPublicKey);
|
46
|
+
const thisVault = preLoadedVault
|
47
|
+
? preLoadedVault
|
48
|
+
: new VaultAccount_1.VaultAccount(yield program.account.vault.fetch(vaultPublicKey), vaultPublicKey);
|
65
49
|
// Load all the vaults
|
66
50
|
let vaults;
|
67
51
|
if (cachedVaults) {
|
package/package.json
CHANGED
@@ -22,6 +22,7 @@ import VaultType from '../state/VaultType'
|
|
22
22
|
* @param {boolean} redeem - True if vault is going to be redeemed fully
|
23
23
|
* @param {boolean} liquidate - True if vault is going to be liquidated fully
|
24
24
|
* @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
|
25
|
+
* @param {VaultAccount} preLoadedVault - Optional vault to use as target vault. Overrides the need to load the vault from on-chain data.
|
25
26
|
*/
|
26
27
|
export async function getLinkedListAccounts(
|
27
28
|
program: Program<Vault>,
|
@@ -33,7 +34,8 @@ export async function getLinkedListAccounts(
|
|
33
34
|
repayAmount: BN,
|
34
35
|
redeem: boolean,
|
35
36
|
liquidate: boolean,
|
36
|
-
cachedVaults?: VaultAccount[]
|
37
|
+
cachedVaults?: VaultAccount[],
|
38
|
+
preLoadedVault?: VaultAccount
|
37
39
|
): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]> {
|
38
40
|
const vaultTypeRaw = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
39
41
|
const vaultType = new VaultType(vaultTypeRaw, vaultTypeAccountPublicKey)
|
@@ -45,25 +47,9 @@ export async function getLinkedListAccounts(
|
|
45
47
|
let newSmallerPublicKey = vaultPublicKey
|
46
48
|
let newLargerPublicKey = vaultPublicKey
|
47
49
|
|
48
|
-
const
|
49
|
-
|
50
|
-
|
51
|
-
return {
|
52
|
-
vaultOwner: new PublicKey('11111111111111111111111111111111'),
|
53
|
-
pdaSalt: 'foo',
|
54
|
-
deposited: new BN(0),
|
55
|
-
denormalizedDebt: new BN(0),
|
56
|
-
vaultNumber: new BN(0),
|
57
|
-
debtProductSnapshotBytes: new BN(1),
|
58
|
-
collateralAccumulatorSnapshotBytes: new BN(1),
|
59
|
-
vaultTypeName: vaultType.name,
|
60
|
-
nextVaultToRedeem: new PublicKey('11111111111111111111111111111111'),
|
61
|
-
vaultStatus: {open: true},
|
62
|
-
vaultType: vaultTypeAccountPublicKey
|
63
|
-
}
|
64
|
-
})
|
65
|
-
// const accountInfo = await program.provider.connection.getAccountInfo(vaultPublicKey)
|
66
|
-
const thisVault = new VaultAccount(thisVaultData, vaultPublicKey)
|
50
|
+
const thisVault = preLoadedVault
|
51
|
+
? preLoadedVault
|
52
|
+
: new VaultAccount(await program.account.vault.fetch(vaultPublicKey), vaultPublicKey)
|
67
53
|
|
68
54
|
// Load all the vaults
|
69
55
|
let vaults
|