hedge-web3 0.2.1 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/idl/vault.d.ts +62 -4
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +5 -0
- package/declarations/instructions/setVaultTypeStatus.d.ts +2 -3
- package/lib/idl/vault.js +62 -4
- package/lib/index.js +1 -0
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +38 -0
- 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/idl/vault.ts +124 -8
- package/src/index.ts +1 -0
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +31 -0
- package/src/instructions/liquidateVault.ts +1 -0
- package/src/instructions/withdrawStakingPool.ts +2 -1
- package/src/state/VaultAccount.ts +6 -4
- package/src/utils/getLinkedListAccounts.ts +3 -3
@@ -1706,6 +1706,54 @@ export declare type Vault = {
|
|
1706
1706
|
}
|
1707
1707
|
];
|
1708
1708
|
"args": [];
|
1709
|
+
},
|
1710
|
+
{
|
1711
|
+
"name": "closeClaimedLiquidationPoolPosition";
|
1712
|
+
"accounts": [
|
1713
|
+
{
|
1714
|
+
"name": "payer";
|
1715
|
+
"isMut": true;
|
1716
|
+
"isSigner": true;
|
1717
|
+
},
|
1718
|
+
{
|
1719
|
+
"name": "poolPosition";
|
1720
|
+
"isMut": true;
|
1721
|
+
"isSigner": false;
|
1722
|
+
}
|
1723
|
+
];
|
1724
|
+
"args": [];
|
1725
|
+
},
|
1726
|
+
{
|
1727
|
+
"name": "closeClaimedStakingPoolPosition";
|
1728
|
+
"accounts": [
|
1729
|
+
{
|
1730
|
+
"name": "payer";
|
1731
|
+
"isMut": true;
|
1732
|
+
"isSigner": true;
|
1733
|
+
},
|
1734
|
+
{
|
1735
|
+
"name": "poolPosition";
|
1736
|
+
"isMut": true;
|
1737
|
+
"isSigner": false;
|
1738
|
+
}
|
1739
|
+
];
|
1740
|
+
"args": [];
|
1741
|
+
},
|
1742
|
+
{
|
1743
|
+
"name": "closeUnusedPoolEra";
|
1744
|
+
"accounts": [
|
1745
|
+
{
|
1746
|
+
"name": "payer";
|
1747
|
+
"isMut": true;
|
1748
|
+
"isSigner": true;
|
1749
|
+
},
|
1750
|
+
{
|
1751
|
+
"name": "poolEra";
|
1752
|
+
"isMut": true;
|
1753
|
+
"isSigner": false;
|
1754
|
+
}
|
1755
|
+
];
|
1756
|
+
"args": [];
|
1709
1757
|
}
|
1710
1758
|
];
|
1711
1759
|
"accounts": [
|
@@ -2803,26 +2851,36 @@ export declare type Vault = {
|
|
2803
2851
|
},
|
2804
2852
|
{
|
2805
2853
|
"code": 6025;
|
2854
|
+
"name": "PositionNotClaimed";
|
2855
|
+
"msg": "Not all positions claimed. Claim all before closing account to recover SOL rent.";
|
2856
|
+
},
|
2857
|
+
{
|
2858
|
+
"code": 6026;
|
2859
|
+
"name": "PoolWasUsed";
|
2860
|
+
"msg": "Era was not unused. Cannot reclaim the SOL rent.";
|
2861
|
+
},
|
2862
|
+
{
|
2863
|
+
"code": 6027;
|
2806
2864
|
"name": "UpdateVaultTypeBadMaxDebtExtended";
|
2807
2865
|
"msg": "New Max debt extended value is less than the current debt!";
|
2808
2866
|
},
|
2809
2867
|
{
|
2810
|
-
"code":
|
2868
|
+
"code": 6028;
|
2811
2869
|
"name": "UpdateVaultTypeNoEnabledOracles";
|
2812
2870
|
"msg": "No Enabled Oracles!";
|
2813
2871
|
},
|
2814
2872
|
{
|
2815
|
-
"code":
|
2873
|
+
"code": 6029;
|
2816
2874
|
"name": "UpdateVaultTypeDuplicateOraclePriorities";
|
2817
2875
|
"msg": "Duplicate Oracle Priorities";
|
2818
2876
|
},
|
2819
2877
|
{
|
2820
|
-
"code":
|
2878
|
+
"code": 6030;
|
2821
2879
|
"name": "UpdateVaultTypeInvalidOraclePriority";
|
2822
2880
|
"msg": "Invalid Oracle Priority";
|
2823
2881
|
},
|
2824
2882
|
{
|
2825
|
-
"code":
|
2883
|
+
"code": 6031;
|
2826
2884
|
"name": "OracleUpdateFailed";
|
2827
2885
|
"msg": "OracleUpdateFailed";
|
2828
2886
|
}
|
package/declarations/index.d.ts
CHANGED
@@ -5,6 +5,7 @@ export * from './instructions/claimStakingPoolPosition';
|
|
5
5
|
export * from './instructions/depositLiquidationPool';
|
6
6
|
export * from './instructions/closeLiquidationPoolPosition';
|
7
7
|
export * from './instructions/claimLiquidationPoolPosition';
|
8
|
+
export * from './instructions/closeClaimedLiquidationPoolPosition';
|
8
9
|
export * from './instructions/createVault';
|
9
10
|
export * from './instructions/depositVault';
|
10
11
|
export * from './instructions/withdrawVault';
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor';
|
2
|
+
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
+
import { Vault } from '../idl/vault';
|
4
|
+
export declare function closeClaimedLiquidationPoolPosition(program: Program<Vault>, provider: Provider, poolPosition: PublicKey, payer: Signer): Promise<PublicKey>;
|
5
|
+
export declare function closeClaimedLiquidationPoolPositionInstruction(program: Program<Vault>, poolPosition: PublicKey, payer: PublicKey): Promise<TransactionInstruction>;
|
@@ -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>;
|
package/lib/idl/vault.js
CHANGED
@@ -1709,6 +1709,54 @@ exports.IDL = {
|
|
1709
1709
|
}
|
1710
1710
|
],
|
1711
1711
|
"args": []
|
1712
|
+
},
|
1713
|
+
{
|
1714
|
+
"name": "closeClaimedLiquidationPoolPosition",
|
1715
|
+
"accounts": [
|
1716
|
+
{
|
1717
|
+
"name": "payer",
|
1718
|
+
"isMut": true,
|
1719
|
+
"isSigner": true
|
1720
|
+
},
|
1721
|
+
{
|
1722
|
+
"name": "poolPosition",
|
1723
|
+
"isMut": true,
|
1724
|
+
"isSigner": false
|
1725
|
+
}
|
1726
|
+
],
|
1727
|
+
"args": []
|
1728
|
+
},
|
1729
|
+
{
|
1730
|
+
"name": "closeClaimedStakingPoolPosition",
|
1731
|
+
"accounts": [
|
1732
|
+
{
|
1733
|
+
"name": "payer",
|
1734
|
+
"isMut": true,
|
1735
|
+
"isSigner": true
|
1736
|
+
},
|
1737
|
+
{
|
1738
|
+
"name": "poolPosition",
|
1739
|
+
"isMut": true,
|
1740
|
+
"isSigner": false
|
1741
|
+
}
|
1742
|
+
],
|
1743
|
+
"args": []
|
1744
|
+
},
|
1745
|
+
{
|
1746
|
+
"name": "closeUnusedPoolEra",
|
1747
|
+
"accounts": [
|
1748
|
+
{
|
1749
|
+
"name": "payer",
|
1750
|
+
"isMut": true,
|
1751
|
+
"isSigner": true
|
1752
|
+
},
|
1753
|
+
{
|
1754
|
+
"name": "poolEra",
|
1755
|
+
"isMut": true,
|
1756
|
+
"isSigner": false
|
1757
|
+
}
|
1758
|
+
],
|
1759
|
+
"args": []
|
1712
1760
|
}
|
1713
1761
|
],
|
1714
1762
|
"accounts": [
|
@@ -2806,26 +2854,36 @@ exports.IDL = {
|
|
2806
2854
|
},
|
2807
2855
|
{
|
2808
2856
|
"code": 6025,
|
2857
|
+
"name": "PositionNotClaimed",
|
2858
|
+
"msg": "Not all positions claimed. Claim all before closing account to recover SOL rent."
|
2859
|
+
},
|
2860
|
+
{
|
2861
|
+
"code": 6026,
|
2862
|
+
"name": "PoolWasUsed",
|
2863
|
+
"msg": "Era was not unused. Cannot reclaim the SOL rent."
|
2864
|
+
},
|
2865
|
+
{
|
2866
|
+
"code": 6027,
|
2809
2867
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
2810
2868
|
"msg": "New Max debt extended value is less than the current debt!"
|
2811
2869
|
},
|
2812
2870
|
{
|
2813
|
-
"code":
|
2871
|
+
"code": 6028,
|
2814
2872
|
"name": "UpdateVaultTypeNoEnabledOracles",
|
2815
2873
|
"msg": "No Enabled Oracles!"
|
2816
2874
|
},
|
2817
2875
|
{
|
2818
|
-
"code":
|
2876
|
+
"code": 6029,
|
2819
2877
|
"name": "UpdateVaultTypeDuplicateOraclePriorities",
|
2820
2878
|
"msg": "Duplicate Oracle Priorities"
|
2821
2879
|
},
|
2822
2880
|
{
|
2823
|
-
"code":
|
2881
|
+
"code": 6030,
|
2824
2882
|
"name": "UpdateVaultTypeInvalidOraclePriority",
|
2825
2883
|
"msg": "Invalid Oracle Priority"
|
2826
2884
|
},
|
2827
2885
|
{
|
2828
|
-
"code":
|
2886
|
+
"code": 6031,
|
2829
2887
|
"name": "OracleUpdateFailed",
|
2830
2888
|
"msg": "OracleUpdateFailed"
|
2831
2889
|
}
|
package/lib/index.js
CHANGED
@@ -17,6 +17,7 @@ __exportStar(require("./instructions/claimStakingPoolPosition"), exports);
|
|
17
17
|
__exportStar(require("./instructions/depositLiquidationPool"), exports);
|
18
18
|
__exportStar(require("./instructions/closeLiquidationPoolPosition"), exports);
|
19
19
|
__exportStar(require("./instructions/claimLiquidationPoolPosition"), exports);
|
20
|
+
__exportStar(require("./instructions/closeClaimedLiquidationPoolPosition"), exports);
|
20
21
|
__exportStar(require("./instructions/createVault"), exports);
|
21
22
|
__exportStar(require("./instructions/depositVault"), exports);
|
22
23
|
__exportStar(require("./instructions/withdrawVault"), exports);
|
@@ -0,0 +1,38 @@
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.closeClaimedLiquidationPoolPositionInstruction = exports.closeClaimedLiquidationPoolPosition = void 0;
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
17
|
+
const Errors_1 = require("../utils/Errors");
|
18
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
19
|
+
function closeClaimedLiquidationPoolPosition(program, provider, poolPosition, payer) {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
const transaction = new web3_js_1.Transaction().add(yield closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer.publicKey));
|
22
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
23
|
+
return poolPosition;
|
24
|
+
});
|
25
|
+
}
|
26
|
+
exports.closeClaimedLiquidationPoolPosition = closeClaimedLiquidationPoolPosition;
|
27
|
+
function closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer) {
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
29
|
+
return program.methods
|
30
|
+
.closeClaimedLiquidationPoolPosition()
|
31
|
+
.accounts({
|
32
|
+
poolPosition: poolPosition,
|
33
|
+
payer: payer
|
34
|
+
})
|
35
|
+
.instruction();
|
36
|
+
});
|
37
|
+
}
|
38
|
+
exports.closeClaimedLiquidationPoolPositionInstruction = closeClaimedLiquidationPoolPositionInstruction;
|
@@ -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
package/src/idl/vault.ts
CHANGED
@@ -1706,6 +1706,54 @@ export type Vault = {
|
|
1706
1706
|
}
|
1707
1707
|
],
|
1708
1708
|
"args": []
|
1709
|
+
},
|
1710
|
+
{
|
1711
|
+
"name": "closeClaimedLiquidationPoolPosition",
|
1712
|
+
"accounts": [
|
1713
|
+
{
|
1714
|
+
"name": "payer",
|
1715
|
+
"isMut": true,
|
1716
|
+
"isSigner": true
|
1717
|
+
},
|
1718
|
+
{
|
1719
|
+
"name": "poolPosition",
|
1720
|
+
"isMut": true,
|
1721
|
+
"isSigner": false
|
1722
|
+
}
|
1723
|
+
],
|
1724
|
+
"args": []
|
1725
|
+
},
|
1726
|
+
{
|
1727
|
+
"name": "closeClaimedStakingPoolPosition",
|
1728
|
+
"accounts": [
|
1729
|
+
{
|
1730
|
+
"name": "payer",
|
1731
|
+
"isMut": true,
|
1732
|
+
"isSigner": true
|
1733
|
+
},
|
1734
|
+
{
|
1735
|
+
"name": "poolPosition",
|
1736
|
+
"isMut": true,
|
1737
|
+
"isSigner": false
|
1738
|
+
}
|
1739
|
+
],
|
1740
|
+
"args": []
|
1741
|
+
},
|
1742
|
+
{
|
1743
|
+
"name": "closeUnusedPoolEra",
|
1744
|
+
"accounts": [
|
1745
|
+
{
|
1746
|
+
"name": "payer",
|
1747
|
+
"isMut": true,
|
1748
|
+
"isSigner": true
|
1749
|
+
},
|
1750
|
+
{
|
1751
|
+
"name": "poolEra",
|
1752
|
+
"isMut": true,
|
1753
|
+
"isSigner": false
|
1754
|
+
}
|
1755
|
+
],
|
1756
|
+
"args": []
|
1709
1757
|
}
|
1710
1758
|
],
|
1711
1759
|
"accounts": [
|
@@ -2803,26 +2851,36 @@ export type Vault = {
|
|
2803
2851
|
},
|
2804
2852
|
{
|
2805
2853
|
"code": 6025,
|
2854
|
+
"name": "PositionNotClaimed",
|
2855
|
+
"msg": "Not all positions claimed. Claim all before closing account to recover SOL rent."
|
2856
|
+
},
|
2857
|
+
{
|
2858
|
+
"code": 6026,
|
2859
|
+
"name": "PoolWasUsed",
|
2860
|
+
"msg": "Era was not unused. Cannot reclaim the SOL rent."
|
2861
|
+
},
|
2862
|
+
{
|
2863
|
+
"code": 6027,
|
2806
2864
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
2807
2865
|
"msg": "New Max debt extended value is less than the current debt!"
|
2808
2866
|
},
|
2809
2867
|
{
|
2810
|
-
"code":
|
2868
|
+
"code": 6028,
|
2811
2869
|
"name": "UpdateVaultTypeNoEnabledOracles",
|
2812
2870
|
"msg": "No Enabled Oracles!"
|
2813
2871
|
},
|
2814
2872
|
{
|
2815
|
-
"code":
|
2873
|
+
"code": 6029,
|
2816
2874
|
"name": "UpdateVaultTypeDuplicateOraclePriorities",
|
2817
2875
|
"msg": "Duplicate Oracle Priorities"
|
2818
2876
|
},
|
2819
2877
|
{
|
2820
|
-
"code":
|
2878
|
+
"code": 6030,
|
2821
2879
|
"name": "UpdateVaultTypeInvalidOraclePriority",
|
2822
2880
|
"msg": "Invalid Oracle Priority"
|
2823
2881
|
},
|
2824
2882
|
{
|
2825
|
-
"code":
|
2883
|
+
"code": 6031,
|
2826
2884
|
"name": "OracleUpdateFailed",
|
2827
2885
|
"msg": "OracleUpdateFailed"
|
2828
2886
|
}
|
@@ -4537,6 +4595,54 @@ export const IDL: Vault = {
|
|
4537
4595
|
}
|
4538
4596
|
],
|
4539
4597
|
"args": []
|
4598
|
+
},
|
4599
|
+
{
|
4600
|
+
"name": "closeClaimedLiquidationPoolPosition",
|
4601
|
+
"accounts": [
|
4602
|
+
{
|
4603
|
+
"name": "payer",
|
4604
|
+
"isMut": true,
|
4605
|
+
"isSigner": true
|
4606
|
+
},
|
4607
|
+
{
|
4608
|
+
"name": "poolPosition",
|
4609
|
+
"isMut": true,
|
4610
|
+
"isSigner": false
|
4611
|
+
}
|
4612
|
+
],
|
4613
|
+
"args": []
|
4614
|
+
},
|
4615
|
+
{
|
4616
|
+
"name": "closeClaimedStakingPoolPosition",
|
4617
|
+
"accounts": [
|
4618
|
+
{
|
4619
|
+
"name": "payer",
|
4620
|
+
"isMut": true,
|
4621
|
+
"isSigner": true
|
4622
|
+
},
|
4623
|
+
{
|
4624
|
+
"name": "poolPosition",
|
4625
|
+
"isMut": true,
|
4626
|
+
"isSigner": false
|
4627
|
+
}
|
4628
|
+
],
|
4629
|
+
"args": []
|
4630
|
+
},
|
4631
|
+
{
|
4632
|
+
"name": "closeUnusedPoolEra",
|
4633
|
+
"accounts": [
|
4634
|
+
{
|
4635
|
+
"name": "payer",
|
4636
|
+
"isMut": true,
|
4637
|
+
"isSigner": true
|
4638
|
+
},
|
4639
|
+
{
|
4640
|
+
"name": "poolEra",
|
4641
|
+
"isMut": true,
|
4642
|
+
"isSigner": false
|
4643
|
+
}
|
4644
|
+
],
|
4645
|
+
"args": []
|
4540
4646
|
}
|
4541
4647
|
],
|
4542
4648
|
"accounts": [
|
@@ -5634,26 +5740,36 @@ export const IDL: Vault = {
|
|
5634
5740
|
},
|
5635
5741
|
{
|
5636
5742
|
"code": 6025,
|
5743
|
+
"name": "PositionNotClaimed",
|
5744
|
+
"msg": "Not all positions claimed. Claim all before closing account to recover SOL rent."
|
5745
|
+
},
|
5746
|
+
{
|
5747
|
+
"code": 6026,
|
5748
|
+
"name": "PoolWasUsed",
|
5749
|
+
"msg": "Era was not unused. Cannot reclaim the SOL rent."
|
5750
|
+
},
|
5751
|
+
{
|
5752
|
+
"code": 6027,
|
5637
5753
|
"name": "UpdateVaultTypeBadMaxDebtExtended",
|
5638
5754
|
"msg": "New Max debt extended value is less than the current debt!"
|
5639
5755
|
},
|
5640
5756
|
{
|
5641
|
-
"code":
|
5757
|
+
"code": 6028,
|
5642
5758
|
"name": "UpdateVaultTypeNoEnabledOracles",
|
5643
5759
|
"msg": "No Enabled Oracles!"
|
5644
5760
|
},
|
5645
5761
|
{
|
5646
|
-
"code":
|
5762
|
+
"code": 6029,
|
5647
5763
|
"name": "UpdateVaultTypeDuplicateOraclePriorities",
|
5648
5764
|
"msg": "Duplicate Oracle Priorities"
|
5649
5765
|
},
|
5650
5766
|
{
|
5651
|
-
"code":
|
5767
|
+
"code": 6030,
|
5652
5768
|
"name": "UpdateVaultTypeInvalidOraclePriority",
|
5653
5769
|
"msg": "Invalid Oracle Priority"
|
5654
5770
|
},
|
5655
5771
|
{
|
5656
|
-
"code":
|
5772
|
+
"code": 6031,
|
5657
5773
|
"name": "OracleUpdateFailed",
|
5658
5774
|
"msg": "OracleUpdateFailed"
|
5659
5775
|
}
|
package/src/index.ts
CHANGED
@@ -6,6 +6,7 @@ export * from './instructions/claimStakingPoolPosition'
|
|
6
6
|
export * from './instructions/depositLiquidationPool'
|
7
7
|
export * from './instructions/closeLiquidationPoolPosition'
|
8
8
|
export * from './instructions/claimLiquidationPoolPosition'
|
9
|
+
export * from './instructions/closeClaimedLiquidationPoolPosition'
|
9
10
|
export * from './instructions/createVault'
|
10
11
|
export * from './instructions/depositVault'
|
11
12
|
export * from './instructions/withdrawVault'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
|
3
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
4
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
5
|
+
import { Vault } from '../idl/vault'
|
6
|
+
|
7
|
+
export async function closeClaimedLiquidationPoolPosition(
|
8
|
+
program: Program<Vault>,
|
9
|
+
provider: Provider,
|
10
|
+
poolPosition: PublicKey,
|
11
|
+
payer: Signer
|
12
|
+
): Promise<PublicKey> {
|
13
|
+
const transaction = new Transaction().add(await closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer.publicKey))
|
14
|
+
|
15
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
16
|
+
return poolPosition
|
17
|
+
}
|
18
|
+
|
19
|
+
export async function closeClaimedLiquidationPoolPositionInstruction(
|
20
|
+
program: Program<Vault>,
|
21
|
+
poolPosition: PublicKey,
|
22
|
+
payer: PublicKey
|
23
|
+
): Promise<TransactionInstruction> {
|
24
|
+
return program.methods
|
25
|
+
.closeClaimedLiquidationPoolPosition()
|
26
|
+
.accounts({
|
27
|
+
poolPosition: poolPosition,
|
28
|
+
payer: payer
|
29
|
+
})
|
30
|
+
.instruction()
|
31
|
+
}
|
@@ -27,7 +27,7 @@ export async function withdrawStakingPool(
|
|
27
27
|
payer: Signer,
|
28
28
|
poolPositionPublicKey: PublicKey,
|
29
29
|
stakedTokenMintPublicKey: PublicKey,
|
30
|
-
overrideStartTime?: number
|
30
|
+
overrideStartTime?: number,
|
31
31
|
): Promise<PublicKey> {
|
32
32
|
const poolPosition = Keypair.generate()
|
33
33
|
const transaction = new Transaction().add(
|
@@ -39,6 +39,7 @@ export async function withdrawStakingPool(
|
|
39
39
|
overrideStartTime
|
40
40
|
)
|
41
41
|
)
|
42
|
+
|
42
43
|
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
43
44
|
return poolPosition.publicKey
|
44
45
|
}
|
@@ -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
|
|