hedge-web3 0.1.13 → 0.1.16
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/{lib/types/src → declarations}/Constants.d.ts +8 -8
- package/{lib/types/src → declarations}/HedgeDecimal.d.ts +2 -3
- package/{lib/types/src → declarations}/StakingPools.d.ts +0 -1
- package/{lib/types/src → declarations}/Vaults.d.ts +0 -1
- package/{lib/types/src → declarations}/idl/idl.d.ts +0 -1
- package/declarations/idl/vault.d.ts +2283 -0
- package/{lib/types/src → declarations}/index.d.ts +6 -1
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +4 -0
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/createStakingPool.d.ts +0 -1
- package/declarations/instructions/createVault.d.ts +4 -0
- package/declarations/instructions/depositLiquidationPool.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/depositStakingPool.d.ts +0 -1
- package/declarations/instructions/depositVault.d.ts +4 -0
- package/declarations/instructions/initHedgeFoundation.d.ts +4 -0
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +4 -0
- package/declarations/instructions/liquidateVault.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/loanVault.d.ts +2 -3
- package/declarations/instructions/redeemVault.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/refreshOraclePrice.d.ts +2 -3
- package/{lib/types/src → declarations}/instructions/repayVault.d.ts +2 -3
- package/declarations/instructions/setHalted.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/withdrawStakingPool.d.ts +0 -1
- package/declarations/instructions/withdrawVault.d.ts +4 -0
- package/{lib/types/src → declarations}/state/LiquidationPoolEra.d.ts +1 -2
- package/{lib/types/src → declarations}/state/LiquidationPoolState.d.ts +0 -1
- package/{lib/types/src → declarations}/state/LiquidationPosition.d.ts +8 -10
- package/{lib/types/src → declarations}/state/StakingPool.d.ts +0 -1
- package/{lib/types/src → declarations}/state/StakingPoolPosition.d.ts +0 -1
- package/{lib/types/src → declarations}/state/VaultAccount.d.ts +0 -1
- package/{lib/types/src → declarations}/state/VaultHistoryEvent.d.ts +0 -1
- package/{lib/types/src → declarations}/utils/Errors.d.ts +0 -1
- package/lib/Constants.js +86 -0
- package/lib/HedgeDecimal.js +24 -0
- package/lib/StakingPools.js +15 -0
- package/lib/Vaults.js +20 -0
- package/lib/idl/idl.js +1475 -0
- package/lib/idl/vault.js +2285 -0
- package/lib/index.js +37 -2156
- package/lib/instructions/claimLiquidationPoolPosition.js +53 -0
- package/lib/instructions/closeLiquidationPoolPosition.js +60 -0
- package/lib/instructions/createStakingPool.js +52 -0
- package/lib/instructions/createVault.js +92 -0
- package/lib/instructions/depositLiquidationPool.js +55 -0
- package/lib/instructions/depositStakingPool.js +52 -0
- package/lib/instructions/depositVault.js +87 -0
- package/lib/instructions/initHedgeFoundation.js +55 -0
- package/lib/instructions/initHedgeFoundationTokens.js +48 -0
- package/lib/instructions/liquidateVault.js +80 -0
- package/lib/instructions/loanVault.js +61 -0
- package/lib/instructions/redeemVault.js +65 -0
- package/lib/instructions/refreshOraclePrice.js +65 -0
- package/lib/instructions/repayVault.js +62 -0
- package/lib/instructions/setHalted.js +37 -0
- package/lib/instructions/withdrawStakingPool.js +64 -0
- package/lib/instructions/withdrawVault.js +62 -0
- package/lib/state/LiquidationPoolEra.js +19 -0
- package/lib/state/LiquidationPoolState.js +12 -0
- package/lib/state/LiquidationPosition.js +39 -0
- package/lib/state/StakingPool.js +22 -0
- package/lib/state/StakingPoolPosition.js +28 -0
- package/lib/state/VaultAccount.js +52 -0
- package/lib/state/VaultHistoryEvent.js +45 -0
- package/lib/utils/Errors.js +14 -0
- package/package.json +14 -8
- package/src/Constants.ts +24 -19
- package/src/HedgeDecimal.ts +3 -3
- package/src/idl/idl.ts +13 -13
- package/src/idl/vault.ts +4565 -0
- package/src/index.ts +6 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +76 -0
- package/src/instructions/closeLiquidationPoolPosition.ts +82 -0
- package/src/instructions/createStakingPool.ts +4 -4
- package/src/instructions/createVault.ts +98 -27
- package/src/instructions/depositLiquidationPool.ts +67 -0
- package/src/instructions/depositStakingPool.ts +5 -3
- package/src/instructions/depositVault.ts +95 -27
- package/src/instructions/initHedgeFoundation.ts +64 -0
- package/src/instructions/initHedgeFoundationTokens.ts +55 -0
- package/src/instructions/liquidateVault.ts +87 -35
- package/src/instructions/loanVault.ts +30 -20
- package/src/instructions/redeemVault.ts +37 -24
- package/src/instructions/refreshOraclePrice.ts +6 -3
- package/src/instructions/repayVault.ts +30 -20
- package/src/instructions/setHalted.ts +48 -0
- package/src/instructions/withdrawStakingPool.ts +6 -6
- package/src/instructions/withdrawVault.ts +50 -17
- package/src/state/LiquidationPoolEra.ts +2 -8
- package/src/state/LiquidationPosition.ts +38 -39
- package/tsconfig.json +3 -2
- package/.github/workflows/npm-publish.yml +0 -34
- package/README.md +0 -44
- package/jsconfig.json +0 -12
- package/lib/index.js.map +0 -1
- package/lib/types/src/Constants.d.ts.map +0 -1
- package/lib/types/src/HedgeDecimal.d.ts.map +0 -1
- package/lib/types/src/StakingPools.d.ts.map +0 -1
- package/lib/types/src/Vaults.d.ts.map +0 -1
- package/lib/types/src/idl/idl.d.ts.map +0 -1
- package/lib/types/src/index.d.ts.map +0 -1
- package/lib/types/src/instructions/createStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/createVault.d.ts +0 -5
- package/lib/types/src/instructions/createVault.d.ts.map +0 -1
- package/lib/types/src/instructions/depositStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/depositVault.d.ts +0 -5
- package/lib/types/src/instructions/depositVault.d.ts.map +0 -1
- package/lib/types/src/instructions/liquidateVault.d.ts +0 -5
- package/lib/types/src/instructions/liquidateVault.d.ts.map +0 -1
- package/lib/types/src/instructions/loanVault.d.ts.map +0 -1
- package/lib/types/src/instructions/redeemVault.d.ts +0 -5
- package/lib/types/src/instructions/redeemVault.d.ts.map +0 -1
- package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +0 -1
- package/lib/types/src/instructions/repayVault.d.ts.map +0 -1
- package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/withdrawVault.d.ts +0 -5
- package/lib/types/src/instructions/withdrawVault.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPoolEra.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPoolState.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPosition.d.ts.map +0 -1
- package/lib/types/src/state/StakingPool.d.ts.map +0 -1
- package/lib/types/src/state/StakingPoolPosition.d.ts.map +0 -1
- package/lib/types/src/state/VaultAccount.d.ts.map +0 -1
- package/lib/types/src/state/VaultHistoryEvent.d.ts.map +0 -1
- package/lib/types/src/utils/Errors.d.ts.map +0 -1
- package/lib/types/tsconfig.base.tsbuildinfo +0 -1
- package/rollup.config.js +0 -40
@@ -0,0 +1,80 @@
|
|
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.liquidateVaultInstruction = exports.liquidateVault = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const spl_token_1 = require("@solana/spl-token");
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const Constants_1 = require("../Constants");
|
17
|
+
function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
19
|
+
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
20
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
21
|
+
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
22
|
+
const collateralMint = vaultTypeAccountInfo.collateralMint;
|
23
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
24
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
25
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
26
|
+
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
27
|
+
const poolStateInfo = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
28
|
+
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey, true);
|
29
|
+
const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true);
|
30
|
+
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultPublicKey, true);
|
31
|
+
const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
|
32
|
+
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
|
33
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, hedgeStakingPoolPublicKey, true);
|
34
|
+
const history = web3_js_1.Keypair.generate();
|
35
|
+
const newEra = web3_js_1.Keypair.generate();
|
36
|
+
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, hedgeStakingPoolAssociatedUsdhTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, vaultAccount.collateralType, overrideTime));
|
38
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra], provider.opts);
|
39
|
+
return vaultPublicKey;
|
40
|
+
});
|
41
|
+
}
|
42
|
+
exports.liquidateVault = liquidateVault;
|
43
|
+
function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUsdhTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, collateralType, overrideTime) {
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
45
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
46
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
47
|
+
const liquidationPoolUsdhAccountPublickey = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
|
48
|
+
const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
49
|
+
const payload = {
|
50
|
+
accounts: {
|
51
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
52
|
+
vaultTypeAccount: vaultTypeAccount,
|
53
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
54
|
+
collateralMint: collateralMint,
|
55
|
+
poolEra: poolEra,
|
56
|
+
vaultAccount: vaultPublickey,
|
57
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
58
|
+
poolState: poolState,
|
59
|
+
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
60
|
+
usdhMint: usdhMintPublickey,
|
61
|
+
history: historyPublicKey,
|
62
|
+
payer: payerPublicKey,
|
63
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
64
|
+
feePool: feePool,
|
65
|
+
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
66
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
67
|
+
liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
|
68
|
+
newEra: newEraPublicKey,
|
69
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
70
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
71
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
72
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
73
|
+
},
|
74
|
+
signers: []
|
75
|
+
};
|
76
|
+
return program.instruction.liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
77
|
+
payload);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
exports.liquidateVaultInstruction = liquidateVaultInstruction;
|
@@ -0,0 +1,61 @@
|
|
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.loanVaultInstruction = exports.loanVault = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const spl_token_1 = require("@solana/spl-token");
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const Constants_1 = require("../Constants");
|
17
|
+
function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
19
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
20
|
+
const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
|
21
|
+
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
22
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
23
|
+
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
24
|
+
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true);
|
25
|
+
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
|
26
|
+
const history = web3_js_1.Keypair.generate();
|
27
|
+
const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, loanAmount, overrideTime));
|
28
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
29
|
+
return vaultPublicKey;
|
30
|
+
});
|
31
|
+
}
|
32
|
+
exports.loanVault = loanVault;
|
33
|
+
function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, loanAmount, overrideTime) {
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
35
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
36
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
37
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
38
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
39
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
40
|
+
return program.instruction.loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
41
|
+
{
|
42
|
+
accounts: {
|
43
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
44
|
+
vaultTypeAccount: vaultTypeAccount,
|
45
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
46
|
+
vaultAccount: vaultPublickey,
|
47
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
48
|
+
history: historyPublicKey,
|
49
|
+
feePool: hedgeStakingPoolPublicKey,
|
50
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
51
|
+
usdhMint: usdhMintPublickey,
|
52
|
+
vaultOwner: payerPublicKey,
|
53
|
+
ownerUsdhAccount: ownerUsdhAccount,
|
54
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
55
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
56
|
+
},
|
57
|
+
signers: []
|
58
|
+
});
|
59
|
+
});
|
60
|
+
}
|
61
|
+
exports.loanVaultInstruction = loanVaultInstruction;
|
@@ -0,0 +1,65 @@
|
|
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.redeemVaultInstruction = exports.redeemVault = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const spl_token_1 = require("@solana/spl-token");
|
15
|
+
// import { TokenInstructions } from '@project-serum/serum'
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
17
|
+
const Constants_1 = require("../Constants");
|
18
|
+
function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
20
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
21
|
+
// Prep the user to get USDH back out at some point
|
22
|
+
const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
|
23
|
+
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
24
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
25
|
+
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
26
|
+
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
|
27
|
+
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
|
28
|
+
const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
29
|
+
const history = web3_js_1.Keypair.generate();
|
30
|
+
const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, redeemAmount, transactionOverrideTime));
|
31
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
32
|
+
return vaultPublicKey;
|
33
|
+
});
|
34
|
+
}
|
35
|
+
exports.redeemVault = redeemVault;
|
36
|
+
function redeemVaultInstruction(program, payerPublicKey, payerUsdhAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
38
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
39
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
40
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
41
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
42
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
43
|
+
return program.instruction.redeemVault(new anchor_1.BN(redeemAmount), new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
|
44
|
+
{
|
45
|
+
accounts: {
|
46
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
47
|
+
vaultTypeAccount: vaultTypeAccount,
|
48
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
49
|
+
vault: vaultPublickey,
|
50
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
51
|
+
history: historyPublicKey,
|
52
|
+
feePool: hedgeStakingPoolPublicKey,
|
53
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
54
|
+
usdhMint: usdhMintPublickey,
|
55
|
+
payer: payerPublicKey,
|
56
|
+
payerUsdhAccount: payerUsdhAccount,
|
57
|
+
destinationTokenAccount: destinationTokenAccount,
|
58
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
59
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
60
|
+
},
|
61
|
+
signers: []
|
62
|
+
});
|
63
|
+
});
|
64
|
+
}
|
65
|
+
exports.redeemVaultInstruction = redeemVaultInstruction;
|
@@ -0,0 +1,65 @@
|
|
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.refreshOraclePriceInstruction = exports.refreshOraclePrice = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
15
|
+
const Constants_1 = require("../Constants");
|
16
|
+
function refreshOraclePrice(program, provider, payer, collateralType, network, overridePrice, overrideTime) {
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
18
|
+
const transaction = new web3_js_1.Transaction().add(yield refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime));
|
19
|
+
return yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts);
|
20
|
+
});
|
21
|
+
}
|
22
|
+
exports.refreshOraclePrice = refreshOraclePrice;
|
23
|
+
function refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime) {
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
25
|
+
const enc = new TextEncoder();
|
26
|
+
const [oracleInfoAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
|
27
|
+
const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
|
28
|
+
return program.instruction.refreshOraclePrice(new anchor_1.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js_1.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
29
|
+
new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
30
|
+
{
|
31
|
+
accounts: {
|
32
|
+
oracleInfoAccount: oracleInfoAccount,
|
33
|
+
vaultTypeAccount: vaultTypeAccount,
|
34
|
+
oracleChainlink: chainlinkAccunts[network],
|
35
|
+
oraclePyth: pythAccounts[network],
|
36
|
+
oracleSwitchboard: switchboardAccounts[network],
|
37
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
38
|
+
},
|
39
|
+
signers: []
|
40
|
+
});
|
41
|
+
});
|
42
|
+
}
|
43
|
+
exports.refreshOraclePriceInstruction = refreshOraclePriceInstruction;
|
44
|
+
var Cluster;
|
45
|
+
(function (Cluster) {
|
46
|
+
Cluster["Testing"] = "Testing";
|
47
|
+
Cluster["Devnet"] = "Devnet";
|
48
|
+
Cluster["MainnetBeta"] = "MainnetBeta";
|
49
|
+
})(Cluster || (Cluster = {}));
|
50
|
+
const pythAccounts = {
|
51
|
+
Testing: web3_js_1.SystemProgram.programId,
|
52
|
+
Devnet: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
53
|
+
MainnetBeta: new web3_js_1.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
|
54
|
+
};
|
55
|
+
const chainlinkAccunts = {
|
56
|
+
Testing: web3_js_1.SystemProgram.programId,
|
57
|
+
Devnet: new web3_js_1.PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
|
58
|
+
MainnetBeta: web3_js_1.SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
|
59
|
+
};
|
60
|
+
const switchboardAccounts = {
|
61
|
+
Testing: web3_js_1.SystemProgram.programId,
|
62
|
+
// Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
|
63
|
+
Devnet: new web3_js_1.PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
|
64
|
+
MainnetBeta: web3_js_1.SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
|
65
|
+
};
|
@@ -0,0 +1,62 @@
|
|
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.repayVaultInstruction = exports.repayVault = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const spl_token_1 = require("@solana/spl-token");
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const Constants_1 = require("../Constants");
|
17
|
+
function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
19
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
20
|
+
// Prep the user to get USDH back out at some point
|
21
|
+
const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
|
22
|
+
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
23
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
24
|
+
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
25
|
+
const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint);
|
26
|
+
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
|
27
|
+
const history = web3_js_1.Keypair.generate();
|
28
|
+
const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime));
|
29
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
30
|
+
return vaultPublicKey;
|
31
|
+
});
|
32
|
+
}
|
33
|
+
exports.repayVault = repayVault;
|
34
|
+
function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime) {
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
36
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
37
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
38
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
39
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
40
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
41
|
+
return program.instruction.repayVault(new anchor_1.BN(repayAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
42
|
+
{
|
43
|
+
accounts: {
|
44
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
45
|
+
vaultTypeAccount: vaultTypeAccount,
|
46
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
47
|
+
vaultAccount: vaultPublickey,
|
48
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
49
|
+
history: historyPublicKey,
|
50
|
+
feePool: hedgeStakingPoolPublicKey,
|
51
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
52
|
+
usdhMint: usdhMintPublickey,
|
53
|
+
vaultOwner: payerPublicKey,
|
54
|
+
ownerUsdhAccount: ownerUsdhAccount,
|
55
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
56
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
57
|
+
},
|
58
|
+
signers: []
|
59
|
+
});
|
60
|
+
});
|
61
|
+
}
|
62
|
+
exports.repayVaultInstruction = repayVaultInstruction;
|
@@ -0,0 +1,37 @@
|
|
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.setHaltedInstruction = exports.setHalted = 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 setHalted(program, provider, payer, halted) {
|
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 setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted));
|
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.setHalted = setHalted;
|
25
|
+
function setHaltedInstruction(program, vaultSystemStatePublicKey, payerPublicKey, halted) {
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
27
|
+
const ix = program.instruction.setHalted(halted, {
|
28
|
+
accounts: {
|
29
|
+
payer: payerPublicKey,
|
30
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
31
|
+
},
|
32
|
+
signers: []
|
33
|
+
});
|
34
|
+
return ix;
|
35
|
+
});
|
36
|
+
}
|
37
|
+
exports.setHaltedInstruction = setHaltedInstruction;
|
@@ -0,0 +1,64 @@
|
|
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.withdrawStakingPoolInstruction = exports.withdrawStakingPool = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const spl_token_1 = require("@solana/spl-token");
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
16
|
+
const Errors_1 = require("../utils/Errors");
|
17
|
+
const Constants_1 = require("../Constants");
|
18
|
+
function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
20
|
+
const poolPosition = web3_js_1.Keypair.generate();
|
21
|
+
const transaction = new web3_js_1.Transaction().add(yield withdrawStakingPoolInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime));
|
22
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts).catch(Errors_1.parseAnchorErrors);
|
23
|
+
return poolPosition.publicKey;
|
24
|
+
});
|
25
|
+
}
|
26
|
+
exports.withdrawStakingPool = withdrawStakingPool;
|
27
|
+
function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
29
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
30
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
31
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
32
|
+
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(stakedTokenMintPublicKey);
|
33
|
+
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, stakedTokenMintPublicKey);
|
34
|
+
const poolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, usdhMintPublickey);
|
35
|
+
const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
|
36
|
+
const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
37
|
+
const payerAssociatedUsdhAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, usdhMintPublickey);
|
38
|
+
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
39
|
+
return program.instruction.withdrawStakingPool(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
40
|
+
{
|
41
|
+
accounts: {
|
42
|
+
payer: payerPublicKey,
|
43
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
44
|
+
pool: poolPublickey,
|
45
|
+
poolPosition: poolPositionPublicKey,
|
46
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
47
|
+
poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
|
48
|
+
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
49
|
+
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
50
|
+
payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
|
51
|
+
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
52
|
+
hedgeMint: hedgeMintPublickey,
|
53
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
54
|
+
usdhMint: usdhMintPublickey,
|
55
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
56
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
57
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
58
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
59
|
+
},
|
60
|
+
signers: []
|
61
|
+
});
|
62
|
+
});
|
63
|
+
}
|
64
|
+
exports.withdrawStakingPoolInstruction = withdrawStakingPoolInstruction;
|
@@ -0,0 +1,62 @@
|
|
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.withdrawVaultInstruction = exports.withdrawVault = void 0;
|
13
|
+
const anchor_1 = require("@project-serum/anchor");
|
14
|
+
const spl_token_1 = require("@solana/spl-token");
|
15
|
+
const serum_1 = require("@project-serum/serum");
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
17
|
+
const Constants_1 = require("../Constants");
|
18
|
+
function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount, overrideTime) {
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
20
|
+
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
21
|
+
// Prep the user to get USDH back out at some point
|
22
|
+
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
|
23
|
+
const history = web3_js_1.Keypair.generate();
|
24
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
25
|
+
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
26
|
+
const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
27
|
+
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(vaultTypeAccount);
|
29
|
+
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccount, true);
|
30
|
+
const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
31
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
32
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
33
|
+
const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultTypeAccount, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUsdhTokenAccount, usdhMintPublickey, history.publicKey, withdrawAmount, overrideTime));
|
34
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
35
|
+
return vaultPublicKey;
|
36
|
+
});
|
37
|
+
}
|
38
|
+
exports.withdrawVault = withdrawVault;
|
39
|
+
function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUsdhTokenAccount, usdhMint, historyPublicKey, withdrawAmount, overrideTime) {
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
41
|
+
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
|
+
{
|
43
|
+
accounts: {
|
44
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
45
|
+
vaultTypeAccount: vaultTypeAccount,
|
46
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
47
|
+
vault: vaultPublickey,
|
48
|
+
vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
|
49
|
+
feePool: hedgeStakingPoolPublicKey,
|
50
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
51
|
+
usdhMint: usdhMint,
|
52
|
+
history: historyPublicKey,
|
53
|
+
vaultOwner: payerPublicKey,
|
54
|
+
destinationTokenAccount: destinationTokenAccount,
|
55
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
56
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
57
|
+
},
|
58
|
+
signers: []
|
59
|
+
});
|
60
|
+
});
|
61
|
+
}
|
62
|
+
exports.withdrawVaultInstruction = withdrawVaultInstruction;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LiquidationPoolEra = void 0;
|
4
|
+
const HedgeDecimal_1 = require("../HedgeDecimal");
|
5
|
+
/**
|
6
|
+
* Represents an on-chian pool era. In the event an era is depleted of deposits, a new era is
|
7
|
+
* created to maintain each users contribution to the pool.
|
8
|
+
*/
|
9
|
+
class LiquidationPoolEra {
|
10
|
+
constructor(liquidyPoolEra) {
|
11
|
+
this.liquidyPoolEra = liquidyPoolEra;
|
12
|
+
this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber();
|
13
|
+
this.product = (0, HedgeDecimal_1.DecimalFromU128)(liquidyPoolEra.productBytes);
|
14
|
+
this.sum = liquidyPoolEra.sumBytes.map((sumBytes) => { return (0, HedgeDecimal_1.DecimalFromU128)(sumBytes); });
|
15
|
+
this.hedgeRewardsAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(liquidyPoolEra.hedgeRewardsAccumulatorBytes);
|
16
|
+
this.hedgeRewardsTimestamp = liquidyPoolEra.hedgeRewardsTimestamp.toNumber();
|
17
|
+
}
|
18
|
+
}
|
19
|
+
exports.LiquidationPoolEra = LiquidationPoolEra;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LiquidationPoolState = void 0;
|
4
|
+
class LiquidationPoolState {
|
5
|
+
constructor(liquidationPoolState) {
|
6
|
+
this.liquidationPoolState = liquidationPoolState;
|
7
|
+
this.lifetimeDeposits = liquidationPoolState.lifetimeDeposits.toNumber();
|
8
|
+
this.hedgeInitRewardsTimestamp = liquidationPoolState.hedgeInitRewardsTimestamp.toNumber();
|
9
|
+
// TODO Add the rest that are missing. Do we need them?
|
10
|
+
}
|
11
|
+
}
|
12
|
+
exports.LiquidationPoolState = LiquidationPoolState;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.LiquidationPosition = void 0;
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
8
|
+
const HedgeDecimal_1 = require("../HedgeDecimal");
|
9
|
+
class LiquidationPosition {
|
10
|
+
constructor(poolPositionInfo, key) {
|
11
|
+
this.publicKey = key;
|
12
|
+
this.eraPublicKey = poolPositionInfo.era;
|
13
|
+
this.ownerAccount = poolPositionInfo.ownerAccount;
|
14
|
+
this.deposit = poolPositionInfo.deposit.toNumber();
|
15
|
+
this.closedUsdh = poolPositionInfo.closedUsdh.toNumber();
|
16
|
+
this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
|
17
|
+
this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
|
18
|
+
this.productSnapshotEntry = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.productSnapshotEntry);
|
19
|
+
this.productSnapshotClosed = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.productSnapshotClosed);
|
20
|
+
this.sumSnapshotsEntry = poolPositionInfo.sumSnapshotsEntry.map((sum) => { return (0, HedgeDecimal_1.DecimalFromU128)(sum); });
|
21
|
+
this.sumSnapshotsClosed = poolPositionInfo.sumSnapshotsClosed.map((sum) => { return (0, HedgeDecimal_1.DecimalFromU128)(sum); });
|
22
|
+
this.hedgeRewardsSnapshot = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.hedgeRewardsSnapshotAccum);
|
23
|
+
this.open = poolPositionInfo.state.open !== undefined;
|
24
|
+
}
|
25
|
+
getUsdhAvailable(era) {
|
26
|
+
return (era.product.div(this.productSnapshotEntry)).mul(new decimal_js_1.default(this.deposit));
|
27
|
+
}
|
28
|
+
getTokensAvailable(era, index) {
|
29
|
+
return era.sum[index].minus(this.sumSnapshotsEntry[index]).div(this.productSnapshotEntry).mul(new decimal_js_1.default(this.deposit)).floor();
|
30
|
+
}
|
31
|
+
}
|
32
|
+
exports.LiquidationPosition = LiquidationPosition;
|
33
|
+
// function hedgeRewardsDecay (supply: number, birthTime: number, timeIn: number, timeOut: number, halfLifeInDays: number): number {
|
34
|
+
// const timeInOffsetStart = timeIn - birthTime
|
35
|
+
// const timeOutOffsetStart = timeOut - birthTime
|
36
|
+
// const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24)
|
37
|
+
// const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart))
|
38
|
+
// return awardedTokens
|
39
|
+
// }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.StakingPool = void 0;
|
4
|
+
const HedgeDecimal_1 = require("../HedgeDecimal");
|
5
|
+
class StakingPool {
|
6
|
+
constructor(poolInfo, publicKey) {
|
7
|
+
this.poolInfo = poolInfo;
|
8
|
+
this.publicKey = publicKey;
|
9
|
+
this.deposits = poolInfo.deposits.toNumber();
|
10
|
+
// this.totalFeesNow = poolInfo.totalFeesNow.toNumber()
|
11
|
+
// this.totalFeesPrevious = poolInfo.totalFeesPrevious.toNumber()
|
12
|
+
this.lastTransactionTime = poolInfo.lastTransactionTime.toNumber();
|
13
|
+
this.startTime = poolInfo.startTime.toNumber();
|
14
|
+
this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber();
|
15
|
+
this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber();
|
16
|
+
this.hedgeRewardAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.hedgeRewardAccumulator);
|
17
|
+
this.usdhFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.usdhFeeAccumulator);
|
18
|
+
this.solFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.solFeeAccumulator);
|
19
|
+
// this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
exports.StakingPool = StakingPool;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.StakingPoolPosition = void 0;
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
8
|
+
const HedgeDecimal_1 = require("../HedgeDecimal");
|
9
|
+
class StakingPoolPosition {
|
10
|
+
constructor(poolPositionInfo, key, stakingPool) {
|
11
|
+
this.poolPositionInfo = poolPositionInfo;
|
12
|
+
this.publicKey = key;
|
13
|
+
this.pool = stakingPool;
|
14
|
+
this.owner = poolPositionInfo.owner;
|
15
|
+
this.deposited = poolPositionInfo.deposited.toNumber();
|
16
|
+
this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
|
17
|
+
this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
|
18
|
+
this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber();
|
19
|
+
this.startHedgeRewardAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startHedgeRewardAccumulator);
|
20
|
+
this.startUsdhFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startUsdhFeeAccumulator);
|
21
|
+
this.startSolFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startSolFeeAccumulator);
|
22
|
+
this.open = poolPositionInfo.state.open !== undefined;
|
23
|
+
}
|
24
|
+
getCurrentUsdhFeeReward() {
|
25
|
+
return this.pool.usdhFeeAccumulator.minus(this.startUsdhFeeAccumulator).times(new decimal_js_1.default(this.deposited));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
exports.StakingPoolPosition = StakingPoolPosition;
|