hedge-web3 0.2.3 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/instructions/setVaultTypeStatus.d.ts +2 -3
- package/lib/instructions/setVaultTypeStatus.js +10 -9
- package/lib/state/VaultAccount.js +10 -6
- package/lib/utils/getLinkedListAccounts.js +3 -3
- package/package.json +1 -1
- package/src/state/VaultAccount.ts +6 -4
- package/src/utils/getLinkedListAccounts.ts +3 -3
@@ -1,5 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
|
4
|
-
export declare function
|
5
|
-
export declare function setVaultTypeStatusInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<TransactionInstruction>;
|
3
|
+
export declare function setVaultTypeStatus(program: Program, provider: Provider, payer: Signer, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<PublicKey>;
|
4
|
+
export declare function setVaultTypeStatusInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<TransactionInstruction>;
|
@@ -17,21 +17,22 @@ function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecat
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
18
18
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
19
19
|
const transaction = new web3_js_1.Transaction().add(yield setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, deprecated));
|
20
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
20
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider === null || provider === void 0 ? void 0 : provider.opts).catch(Errors_1.parseAnchorErrors);
|
21
21
|
return vaultSystemStatePublicKey;
|
22
22
|
});
|
23
23
|
}
|
24
24
|
exports.setVaultTypeStatus = setVaultTypeStatus;
|
25
25
|
function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
const ix = program.instruction.setVaultTypeStatus(deprecated, {
|
28
|
+
accounts: {
|
29
|
+
payer: payerPublicKey,
|
30
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
31
|
+
vaultType: vaultTypeAccount,
|
32
|
+
},
|
33
|
+
signers: []
|
34
|
+
});
|
35
|
+
return ix;
|
35
36
|
});
|
36
37
|
}
|
37
38
|
exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
|
@@ -32,7 +32,9 @@ const borsh = __importStar(require("@project-serum/borsh"));
|
|
32
32
|
*/
|
33
33
|
class VaultAccount {
|
34
34
|
constructor(vault, publicKey) {
|
35
|
-
var _a, _b
|
35
|
+
var _a, _b;
|
36
|
+
/** The ordered number of when this vault was created. */
|
37
|
+
this.vaultNumber = 0;
|
36
38
|
/** Debt redistribution snapshot */
|
37
39
|
this.debtProductSnapshotBytes = new decimal_js_1.default(0);
|
38
40
|
/** Collateral redistribution snapshot' */
|
@@ -41,10 +43,12 @@ class VaultAccount {
|
|
41
43
|
this.vaultStatus = '';
|
42
44
|
this.publicKey = publicKey;
|
43
45
|
this.vaultOwner = vault.vaultOwner;
|
44
|
-
this.vaultNumber = (_a = vault.vaultNumber) === null || _a === void 0 ? void 0 : _a.toNumber();
|
45
46
|
this.pdaSalt = vault.pdaSalt;
|
46
|
-
this.deposited = (
|
47
|
-
this.denormalizedDebt = (
|
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();
|
49
|
+
if (vault.vaultNumber) {
|
50
|
+
this.vaultNumber = vault.vaultNumber.toNumber();
|
51
|
+
}
|
48
52
|
if (vault.debtProductSnapshotBytes) {
|
49
53
|
this.debtProductSnapshotBytes = (0, HedgeDecimal_1.DecimalFromU128)(vault.debtProductSnapshotBytes.toString());
|
50
54
|
}
|
@@ -138,7 +142,7 @@ class VaultAccount {
|
|
138
142
|
if (this.nextVaultToRedeem) {
|
139
143
|
nextVault = this.nextVaultToRedeem.toString().substring(0, 6);
|
140
144
|
}
|
141
|
-
return
|
145
|
+
return `${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `;
|
142
146
|
}
|
143
147
|
/**
|
144
148
|
* Creates a VaultAccount from a slice of data
|
@@ -153,7 +157,7 @@ class VaultAccount {
|
|
153
157
|
* @returns a new VaultAccount
|
154
158
|
*/
|
155
159
|
static FromMiniSlice(data, pubkey) {
|
156
|
-
const props = [borsh.u64('
|
160
|
+
const props = [borsh.u64('deposited'), borsh.u64('denormalizedDebt')];
|
157
161
|
const miniVaultLayout = borsh.struct(props, 'minVaultLayout');
|
158
162
|
const decodedData = miniVaultLayout.decode(data);
|
159
163
|
return new VaultAccount(decodedData, pubkey);
|
@@ -157,7 +157,7 @@ function sortVaults(a, b) {
|
|
157
157
|
const aRatio = a.deposited / a.denormalizedDebt;
|
158
158
|
const bRatio = b.deposited / b.denormalizedDebt;
|
159
159
|
if (aRatio === bRatio) {
|
160
|
-
return b.
|
160
|
+
return a.publicKey.toString() > b.publicKey.toString() ? 1 : -1;
|
161
161
|
}
|
162
162
|
return aRatio - bRatio;
|
163
163
|
}
|
@@ -189,8 +189,8 @@ function getMiniVaults(program, vaultTypePublicKey) {
|
|
189
189
|
// Slice the data only to grab the 3 u64's of size 8 bytes each
|
190
190
|
dataSlice: {
|
191
191
|
// See programs/hedge-vault/src/account_data/vault.rs for struct layout
|
192
|
-
offset: 8 + 32,
|
193
|
-
length:
|
192
|
+
offset: 8 + 32 + 8,
|
193
|
+
length: 16,
|
194
194
|
},
|
195
195
|
});
|
196
196
|
return allAccounts.map((vaultData) => {
|
package/package.json
CHANGED
@@ -26,7 +26,7 @@ export class VaultAccount {
|
|
26
26
|
denormalizedDebt: number
|
27
27
|
|
28
28
|
/** The ordered number of when this vault was created. */
|
29
|
-
vaultNumber
|
29
|
+
vaultNumber = 0
|
30
30
|
|
31
31
|
/** Debt redistribution snapshot */
|
32
32
|
debtProductSnapshotBytes = new Decimal(0)
|
@@ -49,10 +49,12 @@ export class VaultAccount {
|
|
49
49
|
constructor(vault: any, publicKey: PublicKey) {
|
50
50
|
this.publicKey = publicKey
|
51
51
|
this.vaultOwner = vault.vaultOwner
|
52
|
-
this.vaultNumber = vault.vaultNumber?.toNumber()
|
53
52
|
this.pdaSalt = vault.pdaSalt
|
54
53
|
this.deposited = vault.deposited?.toNumber()
|
55
54
|
this.denormalizedDebt = vault.denormalizedDebt?.toNumber()
|
55
|
+
if (vault.vaultNumber) {
|
56
|
+
this.vaultNumber = vault.vaultNumber.toNumber()
|
57
|
+
}
|
56
58
|
if (vault.debtProductSnapshotBytes) {
|
57
59
|
this.debtProductSnapshotBytes = DecimalFromU128(vault.debtProductSnapshotBytes.toString())
|
58
60
|
}
|
@@ -163,7 +165,7 @@ export class VaultAccount {
|
|
163
165
|
nextVault = this.nextVaultToRedeem.toString().substring(0, 6)
|
164
166
|
}
|
165
167
|
|
166
|
-
return
|
168
|
+
return `${this.publicKey.toString().substring(0, 6)}. Debt: ${
|
167
169
|
this.denormalizedDebt
|
168
170
|
} Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `
|
169
171
|
}
|
@@ -180,7 +182,7 @@ export class VaultAccount {
|
|
180
182
|
* @returns a new VaultAccount
|
181
183
|
*/
|
182
184
|
static FromMiniSlice(data: Buffer, pubkey: PublicKey) {
|
183
|
-
const props = [borsh.u64('
|
185
|
+
const props = [borsh.u64('deposited'), borsh.u64('denormalizedDebt')]
|
184
186
|
const miniVaultLayout = borsh.struct(props, 'minVaultLayout')
|
185
187
|
const decodedData: any = miniVaultLayout.decode(data)
|
186
188
|
|
@@ -183,7 +183,7 @@ function sortVaults(a: VaultAccount, b: VaultAccount) {
|
|
183
183
|
const aRatio = a.deposited / a.denormalizedDebt
|
184
184
|
const bRatio = b.deposited / b.denormalizedDebt
|
185
185
|
if (aRatio === bRatio) {
|
186
|
-
return b.
|
186
|
+
return a.publicKey.toString() > b.publicKey.toString() ? 1 : -1
|
187
187
|
}
|
188
188
|
return aRatio - bRatio
|
189
189
|
}
|
@@ -215,8 +215,8 @@ async function getMiniVaults(program: Program<Vault>, vaultTypePublicKey: Public
|
|
215
215
|
// Slice the data only to grab the 3 u64's of size 8 bytes each
|
216
216
|
dataSlice: {
|
217
217
|
// See programs/hedge-vault/src/account_data/vault.rs for struct layout
|
218
|
-
offset: 8 + 32,
|
219
|
-
length:
|
218
|
+
offset: 8 + 32 + 8,
|
219
|
+
length: 16,
|
220
220
|
},
|
221
221
|
})
|
222
222
|
|