hedge-web3 0.2.21 → 0.2.25
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/declarations/Constants.d.ts +25 -12
- package/declarations/idl/pyth.d.ts +44 -24
- package/declarations/idl/switchboard.d.ts +47 -0
- package/declarations/idl/vault.d.ts +905 -155
- package/declarations/index.d.ts +26 -20
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +2 -2
- package/declarations/instructions/createReferralAccount.d.ts +17 -0
- package/declarations/instructions/createUserReferralAccount.d.ts +5 -0
- package/declarations/instructions/depositLiquidationPool.d.ts +2 -2
- package/declarations/instructions/loanVault.d.ts +2 -2
- package/declarations/instructions/psmEditAccount.d.ts +12 -0
- package/declarations/instructions/psmMintUsh.d.ts +2 -2
- package/declarations/instructions/psmRedeemUsh.d.ts +2 -2
- package/declarations/instructions/referralClaimFees.d.ts +16 -0
- package/declarations/instructions/transferVault.d.ts +3 -17
- package/declarations/instructions/updateReferralAccount.d.ts +13 -0
- package/declarations/instructions/updateReferralState.d.ts +20 -0
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
- package/lib/Constants.js +57 -28
- package/lib/idl/pyth.js +44 -24
- package/lib/idl/switchboard.js +49 -0
- package/lib/idl/vault.js +898 -148
- package/lib/index.js +26 -20
- package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
- package/lib/instructions/claimStakingPoolPosition.js +5 -5
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
- package/lib/instructions/closeLiquidationPoolPosition.js +25 -12
- package/lib/instructions/createReferralAccount.js +80 -0
- package/lib/instructions/createStakingPool.js +7 -7
- package/lib/instructions/createUserReferralAccount.js +61 -0
- package/lib/instructions/createVault.js +15 -15
- package/lib/instructions/depositLiquidationPool.js +21 -10
- package/lib/instructions/depositStakingPool.js +5 -5
- package/lib/instructions/depositVault.js +11 -9
- package/lib/instructions/initHedgeFoundation.js +8 -8
- package/lib/instructions/initHedgeFoundationTokens.js +5 -5
- package/lib/instructions/liquidateVault.js +8 -8
- package/lib/instructions/loanVault.js +23 -10
- package/lib/instructions/psmEditAccount.js +60 -0
- package/lib/instructions/psmMintUsh.js +24 -13
- package/lib/instructions/psmRedeemUsh.js +24 -13
- package/lib/instructions/redeemVault.js +7 -7
- package/lib/instructions/referralClaimFees.js +84 -0
- package/lib/instructions/refreshOraclePrice.js +3 -3
- package/lib/instructions/repayVault.js +9 -9
- package/lib/instructions/setHalted.js +1 -1
- package/lib/instructions/transferVault.js +10 -24
- package/lib/instructions/updateReferralAccount.js +50 -0
- package/lib/instructions/updateReferralState.js +57 -0
- package/lib/instructions/updateVaultType.js +1 -1
- package/lib/instructions/withdrawStakingPool.js +11 -11
- package/lib/instructions/withdrawVault.js +5 -5
- package/lib/state/VaultAccount.js +3 -1
- package/lib/utils/getLinkedListAccounts.js +2 -3
- package/package.json +1 -1
- package/src/Constants.ts +64 -63
- package/src/idl/pyth.ts +88 -48
- package/src/idl/switchboard.ts +93 -0
- package/src/idl/vault.ts +1851 -351
- package/src/index.ts +28 -24
- package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
- package/src/instructions/claimStakingPoolPosition.ts +10 -15
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
- package/src/instructions/closeLiquidationPoolPosition.ts +36 -18
- package/src/instructions/createReferralAccount.ts +115 -0
- package/src/instructions/createStakingPool.ts +11 -13
- package/src/instructions/createUserReferralAccount.ts +75 -0
- package/src/instructions/createVault.ts +44 -26
- package/src/instructions/depositLiquidationPool.ts +34 -21
- package/src/instructions/depositStakingPool.ts +18 -14
- package/src/instructions/depositVault.ts +23 -18
- package/src/instructions/initHedgeFoundation.ts +16 -14
- package/src/instructions/initHedgeFoundationTokens.ts +12 -14
- package/src/instructions/liquidateVault.ts +15 -20
- package/src/instructions/loanVault.ts +29 -19
- package/src/instructions/{psmEditAccount.rs → psmEditAccount.ts} +10 -18
- package/src/instructions/psmMintUsh.ts +35 -38
- package/src/instructions/psmRedeemUsh.ts +35 -40
- package/src/instructions/redeemVault.ts +12 -15
- package/src/instructions/referralClaimFees.ts +145 -0
- package/src/instructions/refreshOraclePrice.ts +6 -8
- package/src/instructions/repayVault.ts +18 -16
- package/src/instructions/setHalted.ts +5 -24
- package/src/instructions/transferVault.ts +57 -0
- package/src/instructions/updateReferralAccount.ts +70 -0
- package/src/instructions/updateReferralState.ts +86 -0
- package/src/instructions/updateVaultType.ts +9 -23
- package/src/instructions/withdrawStakingPool.ts +17 -21
- package/src/instructions/withdrawVault.ts +10 -16
- package/src/state/VaultAccount.ts +9 -10
- package/src/utils/getLinkedListAccounts.ts +4 -7
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.initHedgeFoundationInstruction = exports.initHedgeFoundation = void 0;
|
|
16
16
|
const spl_token_1 = require("@solana/spl-token");
|
|
17
17
|
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
-
const Errors_1 = require("../utils/Errors");
|
|
19
18
|
const Constants_1 = require("../Constants");
|
|
19
|
+
const Errors_1 = require("../utils/Errors");
|
|
20
20
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
21
21
|
function initHedgeFoundation(program, provider, payer) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -29,13 +29,13 @@ function initHedgeFoundation(program, provider, payer) {
|
|
|
29
29
|
exports.initHedgeFoundation = initHedgeFoundation;
|
|
30
30
|
function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKey) {
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
33
|
-
const poolStatePublickey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
|
34
|
-
const poolUshTokenAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
|
35
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
36
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
37
|
-
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
|
38
|
-
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
|
32
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
33
|
+
const poolStatePublickey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
|
34
|
+
const poolUshTokenAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
|
35
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
36
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
37
|
+
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
|
|
38
|
+
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
|
|
39
39
|
return yield program.methods
|
|
40
40
|
.initHedgeFoundation()
|
|
41
41
|
.accounts({
|
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.initHedgeFoundationTokensInstruction = exports.initHedgeFoundationTokens = void 0;
|
|
16
16
|
const spl_token_1 = require("@solana/spl-token");
|
|
17
17
|
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
-
const Errors_1 = require("../utils/Errors");
|
|
19
18
|
const Constants_1 = require("../Constants");
|
|
19
|
+
const Errors_1 = require("../utils/Errors");
|
|
20
20
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
21
21
|
function initHedgeFoundationTokens(program, provider, payer) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -29,10 +29,10 @@ function initHedgeFoundationTokens(program, provider, payer) {
|
|
|
29
29
|
exports.initHedgeFoundationTokens = initHedgeFoundationTokens;
|
|
30
30
|
function initHedgeFoundationTokensInstruction(program, payerPublicKey) {
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
33
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
34
|
-
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
|
35
|
-
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
|
32
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
33
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
34
|
+
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
|
|
35
|
+
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
|
|
36
36
|
return yield program.methods
|
|
37
37
|
.initHedgeFoundationTokens()
|
|
38
38
|
.accounts({
|
|
@@ -16,18 +16,18 @@ exports.liquidateVaultInstruction = exports.liquidateVault = void 0;
|
|
|
16
16
|
const anchor_1 = require("@project-serum/anchor");
|
|
17
17
|
const spl_token_1 = require("@solana/spl-token");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
-
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
22
|
function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
|
25
25
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
|
26
26
|
const collateralMint = vaultTypeAccountInfo.collateralMint;
|
|
27
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
28
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
29
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
|
30
|
-
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
|
27
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
28
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
29
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
30
|
+
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
|
31
31
|
const poolStateInfo = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
|
32
32
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey, true);
|
|
33
33
|
const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true);
|
|
@@ -47,9 +47,9 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
|
|
|
47
47
|
exports.liquidateVault = liquidateVault;
|
|
48
48
|
function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultTypeAccount, overrideTime) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
51
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
52
|
-
const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
|
50
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
51
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
52
|
+
const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
|
53
53
|
return yield program.methods
|
|
54
54
|
.liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
55
55
|
)
|
|
@@ -16,32 +16,42 @@ exports.loanVaultInstruction = exports.loanVault = void 0;
|
|
|
16
16
|
const anchor_1 = require("@project-serum/anchor");
|
|
17
17
|
const spl_token_1 = require("@solana/spl-token");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
-
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
|
-
function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
|
|
22
|
+
function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime, referrer) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
24
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
25
25
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
26
26
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
|
27
27
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
|
28
28
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultAccount.vaultType, true);
|
|
29
29
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
|
|
30
30
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(loanAmount), new anchor_1.BN(0), false, false);
|
|
31
|
+
let referralAccountPublicKey = null;
|
|
32
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
33
|
+
if (typeof referrer === 'undefined') {
|
|
34
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
38
|
+
}
|
|
31
39
|
const history = web3_js_1.Keypair.generate();
|
|
32
|
-
const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(loanAmount), overrideTime));
|
|
40
|
+
const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(loanAmount), referralAccountPublicKey, overrideTime));
|
|
33
41
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
|
|
34
42
|
return vaultPublicKey;
|
|
35
43
|
});
|
|
36
44
|
}
|
|
37
45
|
exports.loanVault = loanVault;
|
|
38
|
-
function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime) {
|
|
46
|
+
function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, referralAccountPublicKey, overrideTime) {
|
|
39
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
41
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
42
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
43
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
|
44
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
48
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
49
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
50
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
51
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
52
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
53
|
+
const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
|
|
54
|
+
const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payerPublicKey);
|
|
45
55
|
return yield program.methods
|
|
46
56
|
.loanVault(loanAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
47
57
|
)
|
|
@@ -60,6 +70,9 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
|
|
|
60
70
|
oldSmallerVaultInfo: oldSmallerPublicKey,
|
|
61
71
|
newSmallerVaultInfo: newSmallerPublicKey,
|
|
62
72
|
newLargerVaultInfo: newLargerPublicKey,
|
|
73
|
+
referralState: referralStatePublicKey,
|
|
74
|
+
referralAccount: referralAccountPublicKey,
|
|
75
|
+
userReferralAccount: userReferralAccountPublicKey,
|
|
63
76
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
64
77
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
65
78
|
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.psmEditAccountInstruction = exports.psmEditAccount = exports.psmStatus = void 0;
|
|
16
|
+
const anchor_1 = require("@project-serum/anchor");
|
|
17
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
18
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
+
const Constants_1 = require("../Constants");
|
|
20
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
21
|
+
var psmStatus;
|
|
22
|
+
(function (psmStatus) {
|
|
23
|
+
psmStatus[psmStatus["PsmEnabled"] = 0] = "PsmEnabled";
|
|
24
|
+
psmStatus[psmStatus["PsmDisabled"] = 1] = "PsmDisabled";
|
|
25
|
+
psmStatus[psmStatus["MintOnly"] = 2] = "MintOnly";
|
|
26
|
+
psmStatus[psmStatus["RedeemOnly"] = 3] = "RedeemOnly";
|
|
27
|
+
})(psmStatus = exports.psmStatus || (exports.psmStatus = {}));
|
|
28
|
+
function psmEditAccount(program, provider, payer, collateralMint, mintFee, redeemFee, debtLimit, minSwap, overrideTime) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
31
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
32
|
+
const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
|
33
|
+
const enc = new TextEncoder();
|
|
34
|
+
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
|
|
35
|
+
const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
|
|
36
|
+
const transaction = new web3_js_1.Transaction().add(yield psmEditAccountInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(mintFee), new anchor_1.BN(redeemFee), new anchor_1.BN(debtLimit), new anchor_1.BN(minSwap), overrideTime));
|
|
37
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
|
38
|
+
return payer.publicKey;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.psmEditAccount = psmEditAccount;
|
|
42
|
+
function psmEditAccountInstruction(program, payerPublicKey, psmAccount, collateralMint, mintFee, redeemFee, debtLimit, minSwap, overrideTime) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
45
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
46
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
47
|
+
return yield program.methods
|
|
48
|
+
.psmEditAccount(mintFee, redeemFee, debtLimit, minSwap, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
49
|
+
)
|
|
50
|
+
.accounts({
|
|
51
|
+
payer: payerPublicKey,
|
|
52
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
|
53
|
+
psmAccount: psmAccount,
|
|
54
|
+
collateralMint: collateralMint,
|
|
55
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
56
|
+
})
|
|
57
|
+
.instruction();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.psmEditAccountInstruction = psmEditAccountInstruction;
|
|
@@ -18,30 +18,39 @@ const spl_token_1 = require("@solana/spl-token");
|
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
19
|
const Constants_1 = require("../Constants");
|
|
20
20
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
21
|
-
function psmMintUsh(program, provider, payer, collateralMint, collateralAmount, overrideTime) {
|
|
21
|
+
function psmMintUsh(program, provider, payer, collateralMint, collateralAmount, overrideTime, referrer) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
23
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
24
24
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
25
25
|
const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
|
26
26
|
const enc = new TextEncoder();
|
|
27
|
-
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
|
27
|
+
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
|
|
28
28
|
const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
|
|
29
|
-
|
|
29
|
+
let referralAccountPublicKey;
|
|
30
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
31
|
+
if (!referrer) {
|
|
32
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
36
|
+
}
|
|
37
|
+
const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
|
|
38
|
+
const transaction = new web3_js_1.Transaction().add(yield psmMintUshInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(collateralAmount), referralStatePublicKey, referralAccountPublicKey, overrideTime));
|
|
30
39
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
|
31
40
|
return payer.publicKey;
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
43
|
exports.psmMintUsh = psmMintUsh;
|
|
35
|
-
function psmMintUshInstruction(program, payerPublicKey, psmAccount, collateralMint, collateralAmount, overrideTime) {
|
|
44
|
+
function psmMintUshInstruction(program, payerPublicKey, psmAccount, collateralMint, collateralAmount, referralStatePublicKey, referralAccountPublicKey, overrideTime) {
|
|
36
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
38
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
39
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
40
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
|
41
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
42
|
-
const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(psmAccount, collateralMint);
|
|
43
|
-
const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, collateralMint);
|
|
44
|
-
const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
|
|
46
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
47
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
48
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
49
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
50
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
51
|
+
const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, psmAccount, collateralMint);
|
|
52
|
+
const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, collateralMint);
|
|
53
|
+
const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
|
|
45
54
|
return yield program.methods
|
|
46
55
|
.psmMintUsh(collateralAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
47
56
|
)
|
|
@@ -56,6 +65,8 @@ function psmMintUshInstruction(program, payerPublicKey, psmAccount, collateralMi
|
|
|
56
65
|
ownerCollateralAccount: ownerCollateralAccount,
|
|
57
66
|
collateralMint: collateralMint,
|
|
58
67
|
ushMint: ushMintPublickey,
|
|
68
|
+
referralState: referralStatePublicKey,
|
|
69
|
+
referralAccount: referralAccountPublicKey,
|
|
59
70
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
60
71
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
61
72
|
})
|
|
@@ -18,30 +18,39 @@ const spl_token_1 = require("@solana/spl-token");
|
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
19
|
const Constants_1 = require("../Constants");
|
|
20
20
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
21
|
-
function psmRedeemUsh(program, provider, payer, collateralMint, ushAmount, overrideTime) {
|
|
21
|
+
function psmRedeemUsh(program, provider, payer, collateralMint, ushAmount, overrideTime, referrer) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
23
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
24
24
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
25
25
|
const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
|
26
26
|
const enc = new TextEncoder();
|
|
27
|
-
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
|
27
|
+
const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
|
|
28
28
|
const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
|
|
29
|
-
|
|
29
|
+
let referralAccountPublicKey;
|
|
30
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
31
|
+
if (!referrer) {
|
|
32
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
36
|
+
}
|
|
37
|
+
const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
|
|
38
|
+
const transaction = new web3_js_1.Transaction().add(yield psmRedeemUshInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(ushAmount), referralStatePublicKey, referralAccountPublicKey, overrideTime));
|
|
30
39
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
|
31
40
|
return payer.publicKey;
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
43
|
exports.psmRedeemUsh = psmRedeemUsh;
|
|
35
|
-
function psmRedeemUshInstruction(program, payerPublicKey, psmAccount, collateralMint, ushAmount, overrideTime) {
|
|
44
|
+
function psmRedeemUshInstruction(program, payerPublicKey, psmAccount, collateralMint, ushAmount, referralStatePublicKey, referralAccountPublicKey, overrideTime) {
|
|
36
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
38
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
39
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
40
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
|
41
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
42
|
-
const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(psmAccount, collateralMint);
|
|
43
|
-
const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, collateralMint);
|
|
44
|
-
const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
|
|
46
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
47
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
48
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
49
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
50
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
51
|
+
const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, psmAccount, collateralMint);
|
|
52
|
+
const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, collateralMint);
|
|
53
|
+
const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
|
|
45
54
|
return yield program.methods
|
|
46
55
|
.psmRedeemUsh(ushAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
47
56
|
)
|
|
@@ -56,6 +65,8 @@ function psmRedeemUshInstruction(program, payerPublicKey, psmAccount, collateral
|
|
|
56
65
|
ownerCollateralAccount: ownerCollateralAccount,
|
|
57
66
|
collateralMint: collateralMint,
|
|
58
67
|
ushMint: ushMintPublickey,
|
|
68
|
+
referralState: referralStatePublicKey,
|
|
69
|
+
referralAccount: referralAccountPublicKey,
|
|
59
70
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
60
71
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
61
72
|
})
|
|
@@ -17,12 +17,12 @@ const anchor_1 = require("@project-serum/anchor");
|
|
|
17
17
|
const spl_token_1 = require("@solana/spl-token");
|
|
18
18
|
// import { TokenInstructions } from '@project-serum/serum'
|
|
19
19
|
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
-
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
21
20
|
const Constants_1 = require("../Constants");
|
|
21
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
22
22
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
23
23
|
function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
25
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
26
26
|
// Prep the user to get USH back out at some point
|
|
27
27
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
28
28
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
|
@@ -40,11 +40,11 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
|
|
|
40
40
|
exports.redeemVault = redeemVault;
|
|
41
41
|
function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
44
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
45
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
46
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
|
47
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
43
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
44
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
45
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
46
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
47
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
48
48
|
return yield program.methods
|
|
49
49
|
.redeemVault(redeemAmount, new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : Date.now() / 1000) // override start time
|
|
50
50
|
)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.referralClaimFeesInstruction = exports.referralClaimFees = void 0;
|
|
16
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
17
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
+
const Constants_1 = require("../Constants");
|
|
19
|
+
const Errors_1 = require("../utils/Errors");
|
|
20
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
21
|
+
/** @type {Function} - Allows a referrer to claims their fees.
|
|
22
|
+
* This checks the user has enough HDG in their wallet or staked and
|
|
23
|
+
* then allows them to claim earned fees. If they meet the PSM referral threshold,
|
|
24
|
+
* they will be eligible for PSM cut.
|
|
25
|
+
* Params:
|
|
26
|
+
* - program: Program<Vault> : The program instance of Hedge Vault program
|
|
27
|
+
* - provider: Provider : Current connection
|
|
28
|
+
* - payer: Signer : who we are creating the referral account for
|
|
29
|
+
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
|
30
|
+
* - referrer: PublicKey
|
|
31
|
+
*/
|
|
32
|
+
function referralClaimFees(program, provider, payer, poolPosition) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
// setup transaction
|
|
35
|
+
const transaction = new web3_js_1.Transaction();
|
|
36
|
+
const signers = [payer];
|
|
37
|
+
// General variables
|
|
38
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
39
|
+
// Find referrer account
|
|
40
|
+
const referrer = yield payer.publicKey;
|
|
41
|
+
const referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
42
|
+
// Derive the user referral account public key
|
|
43
|
+
const referallStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
|
|
44
|
+
const hedgeMintPublicKey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
45
|
+
// Get HDG account of signer
|
|
46
|
+
const payerHdgAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, payer.publicKey);
|
|
47
|
+
const ushMintPublicKey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
48
|
+
// Get USH account of signer
|
|
49
|
+
const payerUshAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublicKey, payer.publicKey);
|
|
50
|
+
// Get community_associated_hedge_token_account
|
|
51
|
+
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, vaultSystemStatePublicKey, true);
|
|
52
|
+
const [feePoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublicKey);
|
|
53
|
+
const feePoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublicKey, feePoolPublicKey, true);
|
|
54
|
+
transaction.add(yield referralClaimFeesInstruction(program, payer.publicKey, vaultSystemStatePublicKey, poolPosition, referralAccountPublicKey, referallStatePublicKey, hedgeMintPublicKey, payerHdgAssociatedTokenAccount.address, ushMintPublicKey, payerUshAssociatedTokenAccount.address, communityAssociatedHedgeTokenAccount.address, feePoolPublicKey, feePoolAssociatedUshTokenAccount.address));
|
|
55
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
|
56
|
+
return referralAccountPublicKey;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.referralClaimFees = referralClaimFees;
|
|
60
|
+
function referralClaimFeesInstruction(program, payerPublicKey, vaultSystemStatePublicKey, poolPositionPublicKey, referralAccountPublicKey, referralStatePublicKey, hedgeMintPublicKey, hdgAssociatedTokenAccountPublicKey, ushMintPublicKey, ushAssociatedTokenAccountPublicKey, communityAssociatedHedgeTokenAccountPublicKey, feePoolPublicKey, feePoolAssociatedUshTokenAccountPublicKey) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
return yield program.methods
|
|
63
|
+
.referralClaimFees()
|
|
64
|
+
.accounts({
|
|
65
|
+
signer: payerPublicKey,
|
|
66
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
|
67
|
+
referralState: referralStatePublicKey,
|
|
68
|
+
referralAccount: referralAccountPublicKey,
|
|
69
|
+
poolPosition: poolPositionPublicKey,
|
|
70
|
+
hedgeMint: hedgeMintPublicKey,
|
|
71
|
+
signerHdgAta: hdgAssociatedTokenAccountPublicKey,
|
|
72
|
+
ushMint: ushMintPublicKey,
|
|
73
|
+
signerUshAta: ushAssociatedTokenAccountPublicKey,
|
|
74
|
+
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccountPublicKey,
|
|
75
|
+
feePool: feePoolPublicKey,
|
|
76
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccountPublicKey,
|
|
77
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
78
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
79
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
80
|
+
})
|
|
81
|
+
.instruction();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.referralClaimFeesInstruction = referralClaimFeesInstruction;
|
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.Cluster = exports.refreshOraclePriceInstruction = exports.refreshOraclePrice = void 0;
|
|
16
16
|
const anchor_1 = require("@project-serum/anchor");
|
|
17
17
|
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
-
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
19
18
|
const Constants_1 = require("../Constants");
|
|
19
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
20
20
|
function refreshOraclePrice(program, provider, payer, collateralType, network, overridePrice, overrideTime) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
const transaction = new web3_js_1.Transaction().add(yield refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime));
|
|
@@ -27,8 +27,8 @@ exports.refreshOraclePrice = refreshOraclePrice;
|
|
|
27
27
|
function refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime) {
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
const enc = new TextEncoder();
|
|
30
|
-
const [oracleInfoAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')],
|
|
31
|
-
const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')],
|
|
30
|
+
const [oracleInfoAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], program.programId);
|
|
31
|
+
const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], program.programId);
|
|
32
32
|
const oracleInfo = yield program.account.oracleInfoForCollateralType.fetch(oracleInfoAccount);
|
|
33
33
|
return yield program.methods
|
|
34
34
|
.refreshOraclePrice(new anchor_1.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js_1.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
|
@@ -16,18 +16,18 @@ exports.repayVaultInstruction = exports.repayVault = void 0;
|
|
|
16
16
|
const anchor_1 = require("@project-serum/anchor");
|
|
17
17
|
const spl_token_1 = require("@solana/spl-token");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
-
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
22
|
function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
24
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
25
25
|
// Prep the user to get USH back out at some point
|
|
26
26
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
27
27
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
|
28
28
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
|
29
|
-
const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultAccount.vaultType, vaultTypeAccount.collateralMint);
|
|
30
|
-
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
|
|
29
|
+
const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultAccount.vaultType, vaultTypeAccount.collateralMint);
|
|
30
|
+
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultPublicKey, vaultTypeAccount.collateralMint);
|
|
31
31
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(Math.abs(repayAmount)), false, false);
|
|
32
32
|
const history = web3_js_1.Keypair.generate();
|
|
33
33
|
const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(repayAmount), overrideTime));
|
|
@@ -38,11 +38,11 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
|
|
|
38
38
|
exports.repayVault = repayVault;
|
|
39
39
|
function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
42
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
43
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
44
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
|
45
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
41
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
42
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
43
|
+
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
44
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
|
45
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
46
46
|
return yield program.methods
|
|
47
47
|
.repayVault(repayAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
48
48
|
)
|
|
@@ -19,7 +19,7 @@ const Errors_1 = require("../utils/Errors");
|
|
|
19
19
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
20
20
|
function setHalted(program, provider, payer, halted) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
22
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
23
23
|
const transaction = new web3_js_1.Transaction().add(yield setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted));
|
|
24
24
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
|
25
25
|
return vaultSystemStatePublicKey;
|
|
@@ -14,40 +14,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.transferVaultInstruction = exports.transferVault = void 0;
|
|
16
16
|
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
-
const Constants_1 = require("../Constants");
|
|
18
17
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
19
|
-
function transferVault(program, provider, payer,
|
|
18
|
+
function transferVault(program, provider, payer, vaultPublicKey, vaultSystemStatePublicKey, vaultTypeAccount, newOwner) {
|
|
20
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const
|
|
22
|
-
const transaction = new web3_js_1.Transaction().add(yield transferVaultInstruction(
|
|
23
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
|
|
24
|
-
return
|
|
20
|
+
const history = web3_js_1.Keypair.generate();
|
|
21
|
+
const transaction = new web3_js_1.Transaction().add(yield transferVaultInstruction(vaultPublicKey, vaultSystemStatePublicKey, vaultTypeAccount, history.publicKey, payer.publicKey, program, newOwner));
|
|
22
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
|
|
23
|
+
return vaultPublicKey;
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
26
|
exports.transferVault = transferVault;
|
|
28
|
-
function transferVaultInstruction(
|
|
29
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
27
|
+
function transferVaultInstruction(vaultPublickey, vaultSystemStatePublicKey, vaultTypeAccount, historyPublicKey, vaultOwner, program, newOwner) {
|
|
30
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const config = {
|
|
32
|
-
maxDebtExtended: (_a = vaultTypeConfig.maxDebtExtended) !== null && _a !== void 0 ? _a : null,
|
|
33
|
-
minDebtPerVault: (_b = vaultTypeConfig.minDebtPerVault) !== null && _b !== void 0 ? _b : null,
|
|
34
|
-
loanInitFee: (_c = vaultTypeConfig.loanInitFee) !== null && _c !== void 0 ? _c : null,
|
|
35
|
-
emergencyModeThreshold: (_d = vaultTypeConfig.emergencyModeThreshold) !== null && _d !== void 0 ? _d : null,
|
|
36
|
-
oracleChainlink: (_e = vaultTypeConfig.oracleChainlink) !== null && _e !== void 0 ? _e : null,
|
|
37
|
-
oraclePyth: (_f = vaultTypeConfig.oraclePyth) !== null && _f !== void 0 ? _f : null,
|
|
38
|
-
oracleSwitchboard: (_g = vaultTypeConfig.oracleSwitchboard) !== null && _g !== void 0 ? _g : null,
|
|
39
|
-
deprecated: (_h = vaultTypeConfig.deprecated) !== null && _h !== void 0 ? _h : null,
|
|
40
|
-
priorityPyth: (_j = vaultTypeConfig.priorityPyth) !== null && _j !== void 0 ? _j : null,
|
|
41
|
-
priorityChainlink: (_k = vaultTypeConfig.priorityChainlink) !== null && _k !== void 0 ? _k : null,
|
|
42
|
-
prioritySwitchboard: (_l = vaultTypeConfig.prioritySwitchboard) !== null && _l !== void 0 ? _l : null,
|
|
43
|
-
};
|
|
44
29
|
return yield program.methods
|
|
45
|
-
.
|
|
30
|
+
.transferVault(newOwner)
|
|
46
31
|
.accounts({
|
|
47
|
-
|
|
32
|
+
vault: vaultPublickey,
|
|
48
33
|
vaultSystemState: vaultSystemStatePublicKey,
|
|
49
34
|
vaultType: vaultTypeAccount,
|
|
50
|
-
|
|
35
|
+
history: historyPublicKey,
|
|
36
|
+
vaultOwner: vaultOwner,
|
|
51
37
|
})
|
|
52
38
|
.instruction();
|
|
53
39
|
});
|