hedge-web3 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/Constants.d.ts +1 -1
- package/declarations/index.d.ts +2 -0
- package/declarations/instructions/depositVault.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/repayVault.d.ts +1 -1
- package/declarations/instructions/setVaultTypeStatus.d.ts +4 -0
- package/declarations/instructions/withdrawVault.d.ts +1 -1
- package/declarations/state/VaultAccount.d.ts +8 -0
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -0
- package/lib/Constants.js +1 -1
- package/lib/index.js +2 -0
- package/lib/instructions/createStakingPool.js +2 -2
- package/lib/instructions/depositVault.js +14 -7
- package/lib/instructions/liquidateVault.js +9 -4
- package/lib/instructions/loanVault.js +9 -4
- package/lib/instructions/redeemVault.js +7 -2
- package/lib/instructions/repayVault.js +9 -4
- package/lib/instructions/setVaultTypeStatus.js +38 -0
- package/lib/instructions/withdrawVault.js +12 -7
- package/lib/state/VaultAccount.js +54 -1
- package/lib/utils/getLinkedListAccounts.js +131 -0
- package/package.json +3 -1
- package/src/Constants.ts +1 -1
- package/src/index.ts +3 -0
- package/src/instructions/createStakingPool.ts +1 -2
- package/src/instructions/depositVault.ts +97 -22
- package/src/instructions/liquidateVault.ts +118 -21
- package/src/instructions/loanVault.ts +91 -19
- package/src/instructions/redeemVault.ts +23 -0
- package/src/instructions/repayVault.ts +84 -19
- package/src/instructions/setVaultTypeStatus.ts +50 -0
- package/src/instructions/withdrawVault.ts +99 -21
- package/src/state/VaultAccount.ts +86 -10
- package/src/utils/getLinkedListAccounts.ts +156 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
2
|
-
export declare const HEDGE_PROGRAM_ID = "
|
2
|
+
export declare const HEDGE_PROGRAM_ID = "HDG3uyafYaKxSYRW37ZBTdxaUCoyzaqbuirYucAeaPFY";
|
3
3
|
export declare const HEDGE_PROGRAM_PUBLICKEY: PublicKey;
|
4
4
|
export declare const CHAINLINK_SOL_USD_ID = "FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf";
|
5
5
|
export declare const CHAINLINK_SOL_USD_PUBLICKEY: PublicKey;
|
package/declarations/index.d.ts
CHANGED
@@ -16,6 +16,7 @@ export * from './instructions/refreshOraclePrice';
|
|
16
16
|
export * from './instructions/initHedgeFoundation';
|
17
17
|
export * from './instructions/initHedgeFoundationTokens';
|
18
18
|
export * from './instructions/setHalted';
|
19
|
+
export * from './instructions/setVaultTypeStatus';
|
19
20
|
export * from './HedgeDecimal';
|
20
21
|
export * from './Constants';
|
21
22
|
export * from './state/VaultAccount';
|
@@ -25,3 +26,4 @@ export * from './state/StakingPoolPosition';
|
|
25
26
|
export * from './state/LiquidationPoolEra';
|
26
27
|
export * from './state/LiquidationPoolState';
|
27
28
|
export * from './state/LiquidationPosition';
|
29
|
+
export * from './utils/getLinkedListAccounts';
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function depositVault(program: Program, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, depositAmount: number, overrideTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function depositVaultInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, vaultOwner: PublicKey, vaultOwnerTokenAccount: PublicKey, vaultPublicKey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, ushMintPublickey: PublicKey, depositAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
4
|
+
export declare function depositVaultInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, vaultOwner: PublicKey, vaultOwnerTokenAccount: PublicKey, vaultPublicKey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, ushMintPublickey: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, depositAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function liquidateVault(program: Program, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, overrideTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function liquidateVaultInstruction(program: Program, payerPublicKey: PublicKey, payerAssociatedTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, poolState: PublicKey, poolEra: PublicKey, poolAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, newEraPublicKey: PublicKey, feePool: PublicKey, feePoolAssociatedTokenAccount: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, collateralType: string, overrideTime?: number): Promise<TransactionInstruction>;
|
4
|
+
export declare function liquidateVaultInstruction(program: Program, payerPublicKey: PublicKey, payerAssociatedTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, poolState: PublicKey, poolEra: PublicKey, poolAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, newEraPublicKey: PublicKey, feePool: PublicKey, feePoolAssociatedTokenAccount: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, collateralType: string, overrideTime?: number): Promise<TransactionInstruction>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function loanVault(program: Program, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, loanAmount: number, overrideTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function loanVaultInstruction(program: Program, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, loanAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
4
|
+
export declare function loanVaultInstruction(program: Program, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, loanAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function redeemVault(program: Program, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, redeemAmount: number, transactionOverrideTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function redeemVaultInstruction(program: Program, payerPublicKey: PublicKey, payerUshAccount: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, redeemAmount: number, transactionOverrideTime?: number): Promise<TransactionInstruction>;
|
4
|
+
export declare function redeemVaultInstruction(program: Program, payerPublicKey: PublicKey, payerUshAccount: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, redeemAmount: number, transactionOverrideTime?: number): Promise<TransactionInstruction>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function repayVault(program: Program, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, repayAmount: number, overrideTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function repayVaultInstruction(program: Program, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, repayAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
4
|
+
export declare function repayVaultInstruction(program: Program, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, repayAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor';
|
2
|
+
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
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>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function withdrawVault(program: Program, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, withdrawAmount: number, overrideTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function withdrawVaultInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedCollateralPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, ushMint: PublicKey, historyPublicKey: PublicKey, withdrawAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
4
|
+
export declare function withdrawVaultInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedCollateralPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, ushMint: PublicKey, historyPublicKey: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, withdrawAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
|
@@ -14,6 +14,8 @@ export declare class VaultAccount {
|
|
14
14
|
deposited: number;
|
15
15
|
/** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
|
16
16
|
denormalizedDebt: number;
|
17
|
+
/** The ordered number of when this vault was created. */
|
18
|
+
vaultNumber: number;
|
17
19
|
debtProductSnapshotBytes: Decimal;
|
18
20
|
collateralAccumulatorSnapshotBytes: Decimal;
|
19
21
|
collateralType: string;
|
@@ -45,4 +47,10 @@ export declare class VaultAccount {
|
|
45
47
|
* @returns example: `1b6ca...azy71s`
|
46
48
|
*/
|
47
49
|
toDisplayString(): string;
|
50
|
+
addDebt(newNormalizedDebt: Decimal, vaultTypeCompoundedInterest: Decimal): void;
|
51
|
+
addDeposit(depositAmount: number): void;
|
52
|
+
redeem(): void;
|
53
|
+
liquidate(): void;
|
54
|
+
redistribution(vaultTypeAccuntData: any): void;
|
55
|
+
toString(highlight: PublicKey): string;
|
48
56
|
}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor';
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
3
|
+
export declare function getLinkedListAccounts(program: Program, provider: Provider, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: number, loanAmount: number, redeem: boolean, liquidate: boolean): Promise<[PublicKey, PublicKey, PublicKey]>;
|
package/lib/Constants.js
CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeOracleAccountPublicKey = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getVaultSystemStatePublicKey = exports.getUshMintPublicKey = exports.getLiquidationPoolUshAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = exports.HEDGE_PROGRAM_PUBLICKEY = exports.HEDGE_PROGRAM_ID = void 0;
|
13
13
|
const spl_token_1 = require("@solana/spl-token");
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
15
|
-
exports.HEDGE_PROGRAM_ID = '
|
15
|
+
exports.HEDGE_PROGRAM_ID = 'HDG3uyafYaKxSYRW37ZBTdxaUCoyzaqbuirYucAeaPFY';
|
16
16
|
exports.HEDGE_PROGRAM_PUBLICKEY = new web3_js_1.PublicKey(exports.HEDGE_PROGRAM_ID);
|
17
17
|
exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
|
18
18
|
exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
|
package/lib/index.js
CHANGED
@@ -28,6 +28,7 @@ __exportStar(require("./instructions/refreshOraclePrice"), exports);
|
|
28
28
|
__exportStar(require("./instructions/initHedgeFoundation"), exports);
|
29
29
|
__exportStar(require("./instructions/initHedgeFoundationTokens"), exports);
|
30
30
|
__exportStar(require("./instructions/setHalted"), exports);
|
31
|
+
__exportStar(require("./instructions/setVaultTypeStatus"), exports);
|
31
32
|
__exportStar(require("./HedgeDecimal"), exports);
|
32
33
|
__exportStar(require("./Constants"), exports);
|
33
34
|
__exportStar(require("./state/VaultAccount"), exports);
|
@@ -37,3 +38,4 @@ __exportStar(require("./state/StakingPoolPosition"), exports);
|
|
37
38
|
__exportStar(require("./state/LiquidationPoolEra"), exports);
|
38
39
|
__exportStar(require("./state/LiquidationPoolState"), exports);
|
39
40
|
__exportStar(require("./state/LiquidationPosition"), exports);
|
41
|
+
__exportStar(require("./utils/getLinkedListAccounts"), exports);
|
@@ -29,10 +29,10 @@ function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, he
|
|
29
29
|
console.log("createStakingPoolInstruction program ID", program.programId.toString());
|
30
30
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
31
31
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
32
|
-
const [poolPublickey, poolBump
|
32
|
+
const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
33
33
|
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
|
34
34
|
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
|
35
|
-
return program.instruction.createStakingPool(poolBump,
|
35
|
+
return program.instruction.createStakingPool(poolBump, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), {
|
36
36
|
accounts: {
|
37
37
|
signer: payerPublicKey,
|
38
38
|
vaultSystemState: vaultSystemStatePublicKey,
|
@@ -14,6 +14,7 @@ const anchor_1 = require("@project-serum/anchor");
|
|
14
14
|
const serum_1 = require("@project-serum/serum");
|
15
15
|
const spl_token_1 = require("@solana/spl-token");
|
16
16
|
const web3_js_1 = require("@solana/web3.js");
|
17
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
17
18
|
const Constants_1 = require("../Constants");
|
18
19
|
function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -33,26 +34,29 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
33
34
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
34
35
|
const transaction = new web3_js_1.Transaction();
|
35
36
|
const signers = [payer, history];
|
37
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, 0, false, false);
|
36
38
|
if (vaultAccount.collateralType === 'SOL') {
|
37
39
|
transaction.add(web3_js_1.SystemProgram.createAccount({
|
38
40
|
fromPubkey: payer.publicKey,
|
39
41
|
lamports: depositAmount + 2.04e6,
|
40
42
|
newAccountPubkey: wrappedSolAccount.publicKey,
|
41
43
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
42
|
-
space: 165
|
44
|
+
space: 165,
|
43
45
|
}), serum_1.TokenInstructions.initializeAccount({
|
44
46
|
account: wrappedSolAccount.publicKey,
|
45
47
|
mint: serum_1.TokenInstructions.WRAPPED_SOL_MINT,
|
46
|
-
owner: payer.publicKey
|
48
|
+
owner: payer.publicKey,
|
47
49
|
}));
|
48
50
|
signers.push(wrappedSolAccount);
|
49
51
|
}
|
50
|
-
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL'
|
52
|
+
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL'
|
53
|
+
? wrappedSolAccount.publicKey
|
54
|
+
: payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
|
51
55
|
if (vaultAccount.collateralType === 'SOL') {
|
52
56
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
53
57
|
source: wrappedSolAccount.publicKey,
|
54
58
|
destination: payer.publicKey,
|
55
|
-
owner: payer.publicKey
|
59
|
+
owner: payer.publicKey,
|
56
60
|
}));
|
57
61
|
}
|
58
62
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers, provider.opts);
|
@@ -60,7 +64,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
60
64
|
});
|
61
65
|
}
|
62
66
|
exports.depositVault = depositVault;
|
63
|
-
function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, depositAmount, overrideTime) {
|
67
|
+
function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime) {
|
64
68
|
return __awaiter(this, void 0, void 0, function* () {
|
65
69
|
return program.instruction.depositVault(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
66
70
|
{
|
@@ -77,10 +81,13 @@ function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner,
|
|
77
81
|
vaultOwner: vaultOwner,
|
78
82
|
vaultOwnerTokenAccount: vaultOwnerTokenAccount,
|
79
83
|
ushMint: ushMintPublickey,
|
84
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
85
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
86
|
+
newLargerVaultInfo: newLargerPublicKey,
|
80
87
|
systemProgram: web3_js_1.SystemProgram.programId,
|
81
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
88
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
82
89
|
},
|
83
|
-
signers: []
|
90
|
+
signers: [],
|
84
91
|
});
|
85
92
|
});
|
86
93
|
}
|
@@ -13,6 +13,7 @@ exports.liquidateVaultInstruction = exports.liquidateVault = void 0;
|
|
13
13
|
const anchor_1 = require("@project-serum/anchor");
|
14
14
|
const spl_token_1 = require("@solana/spl-token");
|
15
15
|
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
16
17
|
const Constants_1 = require("../Constants");
|
17
18
|
function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -31,16 +32,17 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
|
|
31
32
|
const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
|
32
33
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
|
33
34
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
|
35
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, false, true);
|
34
36
|
const history = web3_js_1.Keypair.generate();
|
35
37
|
const newEra = web3_js_1.Keypair.generate();
|
36
38
|
const transaction = new web3_js_1.Transaction();
|
37
|
-
transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, vaultAccount.collateralType, overrideTime));
|
39
|
+
transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultAccount.collateralType, overrideTime));
|
38
40
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra], provider.opts);
|
39
41
|
return vaultPublicKey;
|
40
42
|
});
|
41
43
|
}
|
42
44
|
exports.liquidateVault = liquidateVault;
|
43
|
-
function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, collateralType, overrideTime) {
|
45
|
+
function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, collateralType, overrideTime) {
|
44
46
|
return __awaiter(this, void 0, void 0, function* () {
|
45
47
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
46
48
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -66,12 +68,15 @@ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedToken
|
|
66
68
|
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
67
69
|
liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
|
68
70
|
newEra: newEraPublicKey,
|
71
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
72
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
73
|
+
newLargerVaultInfo: newLargerPublicKey,
|
69
74
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
70
75
|
systemProgram: web3_js_1.SystemProgram.programId,
|
71
76
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
72
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
77
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
73
78
|
},
|
74
|
-
signers: []
|
79
|
+
signers: [],
|
75
80
|
};
|
76
81
|
return program.instruction.liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
77
82
|
payload);
|
@@ -13,6 +13,7 @@ exports.loanVaultInstruction = exports.loanVault = void 0;
|
|
13
13
|
const anchor_1 = require("@project-serum/anchor");
|
14
14
|
const spl_token_1 = require("@solana/spl-token");
|
15
15
|
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
16
17
|
const Constants_1 = require("../Constants");
|
17
18
|
function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -23,14 +24,15 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
|
|
23
24
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
24
25
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true);
|
25
26
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
|
27
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
|
26
28
|
const history = web3_js_1.Keypair.generate();
|
27
|
-
const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, loanAmount, overrideTime));
|
29
|
+
const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
|
28
30
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
29
31
|
return vaultPublicKey;
|
30
32
|
});
|
31
33
|
}
|
32
34
|
exports.loanVault = loanVault;
|
33
|
-
function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, loanAmount, overrideTime) {
|
35
|
+
function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime) {
|
34
36
|
return __awaiter(this, void 0, void 0, function* () {
|
35
37
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
36
38
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -51,10 +53,13 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
|
|
51
53
|
ushMint: ushMintPublickey,
|
52
54
|
vaultOwner: payerPublicKey,
|
53
55
|
ownerUshAccount: ownerUshAccount,
|
56
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
57
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
58
|
+
newLargerVaultInfo: newLargerPublicKey,
|
54
59
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
55
|
-
systemProgram: web3_js_1.SystemProgram.programId
|
60
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
56
61
|
},
|
57
|
-
signers: []
|
62
|
+
signers: [],
|
58
63
|
});
|
59
64
|
});
|
60
65
|
}
|
@@ -14,6 +14,7 @@ const anchor_1 = require("@project-serum/anchor");
|
|
14
14
|
const spl_token_1 = require("@solana/spl-token");
|
15
15
|
// import { TokenInstructions } from '@project-serum/serum'
|
16
16
|
const web3_js_1 = require("@solana/web3.js");
|
17
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
17
18
|
const Constants_1 = require("../Constants");
|
18
19
|
function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -26,14 +27,15 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
|
|
26
27
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
|
27
28
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
|
28
29
|
const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
30
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, true, false);
|
29
31
|
const history = web3_js_1.Keypair.generate();
|
30
|
-
const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, redeemAmount, transactionOverrideTime));
|
32
|
+
const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime));
|
31
33
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
32
34
|
return vaultPublicKey;
|
33
35
|
});
|
34
36
|
}
|
35
37
|
exports.redeemVault = redeemVault;
|
36
|
-
function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
|
38
|
+
function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime) {
|
37
39
|
return __awaiter(this, void 0, void 0, function* () {
|
38
40
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
39
41
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -55,6 +57,9 @@ function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destin
|
|
55
57
|
payer: payerPublicKey,
|
56
58
|
payerUshAccount: payerUshAccount,
|
57
59
|
destinationTokenAccount: destinationTokenAccount,
|
60
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
61
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
62
|
+
newLargerVaultInfo: newLargerPublicKey,
|
58
63
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
59
64
|
systemProgram: web3_js_1.SystemProgram.programId
|
60
65
|
},
|
@@ -13,6 +13,7 @@ exports.repayVaultInstruction = exports.repayVault = void 0;
|
|
13
13
|
const anchor_1 = require("@project-serum/anchor");
|
14
14
|
const spl_token_1 = require("@solana/spl-token");
|
15
15
|
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
16
17
|
const Constants_1 = require("../Constants");
|
17
18
|
function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -24,14 +25,15 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
|
|
24
25
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
25
26
|
const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint);
|
26
27
|
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
|
28
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, repayAmount * -1, false, false);
|
27
29
|
const history = web3_js_1.Keypair.generate();
|
28
|
-
const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime));
|
30
|
+
const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime));
|
29
31
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
30
32
|
return vaultPublicKey;
|
31
33
|
});
|
32
34
|
}
|
33
35
|
exports.repayVault = repayVault;
|
34
|
-
function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime) {
|
36
|
+
function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime) {
|
35
37
|
return __awaiter(this, void 0, void 0, function* () {
|
36
38
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
37
39
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -51,11 +53,14 @@ function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPu
|
|
51
53
|
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
52
54
|
ushMint: ushMintPublickey,
|
53
55
|
vaultOwner: payerPublicKey,
|
56
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
57
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
58
|
+
newLargerVaultInfo: newLargerPublicKey,
|
54
59
|
ownerUshAccount: ownerUshAccount,
|
55
60
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
56
|
-
systemProgram: web3_js_1.SystemProgram.programId
|
61
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
57
62
|
},
|
58
|
-
signers: []
|
63
|
+
signers: [],
|
59
64
|
});
|
60
65
|
});
|
61
66
|
}
|
@@ -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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.setVaultTypeStatusInstruction = exports.setVaultTypeStatus = void 0;
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
14
|
+
const Constants_1 = require("../Constants");
|
15
|
+
const Errors_1 = require("../utils/Errors");
|
16
|
+
function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecated) {
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
18
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
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], provider === null || provider === void 0 ? void 0 : provider.opts).catch(Errors_1.parseAnchorErrors);
|
21
|
+
return vaultSystemStatePublicKey;
|
22
|
+
});
|
23
|
+
}
|
24
|
+
exports.setVaultTypeStatus = setVaultTypeStatus;
|
25
|
+
function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
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;
|
36
|
+
});
|
37
|
+
}
|
38
|
+
exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
|
@@ -15,6 +15,7 @@ const spl_token_1 = require("@solana/spl-token");
|
|
15
15
|
const serum_1 = require("@project-serum/serum");
|
16
16
|
const web3_js_1 = require("@solana/web3.js");
|
17
17
|
const Constants_1 = require("../Constants");
|
18
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
18
19
|
function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount, overrideTime) {
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
20
21
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
@@ -23,20 +24,21 @@ function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount,
|
|
23
24
|
const history = web3_js_1.Keypair.generate();
|
24
25
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
25
26
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
26
|
-
const
|
27
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
27
28
|
const vaultAssociatedCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, serum_1.TokenInstructions.WRAPPED_SOL_MINT, vaultPublicKey, true);
|
28
|
-
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(
|
29
|
-
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint,
|
29
|
+
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
30
|
+
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
|
30
31
|
const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
31
32
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
32
33
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
33
|
-
const
|
34
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, withdrawAmount * -1, 0, false, false);
|
35
|
+
const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMintPublickey, history.publicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime));
|
34
36
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
35
37
|
return vaultPublicKey;
|
36
38
|
});
|
37
39
|
}
|
38
40
|
exports.withdrawVault = withdrawVault;
|
39
|
-
function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMint, historyPublicKey, withdrawAmount, overrideTime) {
|
41
|
+
function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMint, historyPublicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime) {
|
40
42
|
return __awaiter(this, void 0, void 0, function* () {
|
41
43
|
return program.instruction.withdrawVault(new anchor_1.BN(withdrawAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
42
44
|
{
|
@@ -52,10 +54,13 @@ function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPubli
|
|
52
54
|
history: historyPublicKey,
|
53
55
|
vaultOwner: payerPublicKey,
|
54
56
|
destinationTokenAccount: destinationTokenAccount,
|
57
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
58
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
59
|
+
newLargerVaultInfo: newLargerPublicKey,
|
55
60
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
56
|
-
systemProgram: web3_js_1.SystemProgram.programId
|
61
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
57
62
|
},
|
58
|
-
signers: []
|
63
|
+
signers: [],
|
59
64
|
});
|
60
65
|
});
|
61
66
|
}
|
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
6
|
exports.VaultAccount = void 0;
|
4
7
|
const web3_js_1 = require("@solana/web3.js");
|
8
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
5
9
|
const HedgeDecimal_1 = require("../HedgeDecimal");
|
6
10
|
/**
|
7
11
|
* A class that represents an on-chian vault.
|
@@ -10,6 +14,7 @@ class VaultAccount {
|
|
10
14
|
constructor(vault, publicKey) {
|
11
15
|
this.publicKey = publicKey;
|
12
16
|
this.vaultOwner = vault.vaultOwner;
|
17
|
+
this.vaultNumber = vault.vaultNumber.toNumber();
|
13
18
|
this.pdaSalt = vault.pdaSalt;
|
14
19
|
this.deposited = vault.deposited.toNumber();
|
15
20
|
this.denormalizedDebt = vault.denormalizedDebt.toNumber();
|
@@ -49,7 +54,55 @@ class VaultAccount {
|
|
49
54
|
* @returns example: `1b6ca...azy71s`
|
50
55
|
*/
|
51
56
|
toDisplayString() {
|
52
|
-
return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey
|
57
|
+
return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey
|
58
|
+
.toString()
|
59
|
+
.substring(this.publicKey.toString().length - 6)}`;
|
60
|
+
}
|
61
|
+
addDebt(newNormalizedDebt, vaultTypeCompoundedInterest) {
|
62
|
+
const denormalizedNewDebt = newNormalizedDebt.div(vaultTypeCompoundedInterest);
|
63
|
+
this.denormalizedDebt += denormalizedNewDebt.toNumber();
|
64
|
+
}
|
65
|
+
addDeposit(depositAmount) {
|
66
|
+
this.deposited += depositAmount;
|
67
|
+
}
|
68
|
+
redeem() {
|
69
|
+
// TODO - Calculate actual redeem amount and adust correctly
|
70
|
+
this.denormalizedDebt = 0;
|
71
|
+
this.vaultStatus = 'initialized';
|
72
|
+
}
|
73
|
+
liquidate() {
|
74
|
+
// TODO - Calculate actual liquidate amount and adust correctly
|
75
|
+
this.denormalizedDebt = 0;
|
76
|
+
this.vaultStatus = 'liquidated';
|
77
|
+
}
|
78
|
+
redistribution(vaultTypeAccuntData) {
|
79
|
+
const debtProductCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccuntData.debtRedistributionProduct);
|
80
|
+
const collateralAccumulatorCurrent = (0, HedgeDecimal_1.DecimalFromU128)(vaultTypeAccuntData.collateralRedistributionAccumulator);
|
81
|
+
this.denormalizedDebt = debtProductCurrent
|
82
|
+
.div(this.debtProductSnapshotBytes)
|
83
|
+
.mul(new decimal_js_1.default(this.denormalizedDebt))
|
84
|
+
// .add(new Decimal(vaultTypeAccuntData.debtRedistributionError))
|
85
|
+
.toNumber();
|
86
|
+
const extraCollateralDeposited = this.denormalizedDebt *
|
87
|
+
collateralAccumulatorCurrent
|
88
|
+
.sub(this.collateralAccumulatorSnapshotBytes)
|
89
|
+
.toNumber();
|
90
|
+
this.deposited += extraCollateralDeposited;
|
91
|
+
this.collateralAccumulatorSnapshotBytes = collateralAccumulatorCurrent;
|
92
|
+
this.debtProductSnapshotBytes = debtProductCurrent;
|
93
|
+
}
|
94
|
+
toString(highlight) {
|
95
|
+
let arrow = '';
|
96
|
+
if (this.publicKey.toString() === highlight.toString()) {
|
97
|
+
arrow = ' <----';
|
98
|
+
}
|
99
|
+
let collateralRatio = 'Infinite';
|
100
|
+
if (this.denormalizedDebt > 0) {
|
101
|
+
collateralRatio = (this.deposited / this.denormalizedDebt).toFixed(8);
|
102
|
+
}
|
103
|
+
return `Vault(${this.vaultNumber}): ${this.publicKey
|
104
|
+
.toString()
|
105
|
+
.substring(0, 6)}. Debt: ${this.inUsd()} Collat: ${collateralRatio} ${arrow}`;
|
53
106
|
}
|
54
107
|
}
|
55
108
|
exports.VaultAccount = VaultAccount;
|