hedge-web3 0.2.33 → 0.3.2
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 +0 -12
- package/declarations/HedgeConstants.d.ts +76 -0
- package/declarations/idl/pyth.d.ts +1 -1
- package/declarations/idl/switchboard.d.ts +1 -1
- package/declarations/idl/vault.d.ts +278 -1259
- package/declarations/index.d.ts +1 -12
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createReferralAccount.d.ts +1 -1
- package/declarations/instructions/createStakingPool.d.ts +1 -1
- package/declarations/instructions/createUserReferralAccount.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -2
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -2
- package/declarations/instructions/depositStakingPool.d.ts +1 -2
- package/declarations/instructions/depositVault.d.ts +1 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -2
- package/declarations/instructions/psmEditAccount.d.ts +1 -2
- package/declarations/instructions/psmMintUsh.d.ts +1 -2
- package/declarations/instructions/psmRedeemUsh.d.ts +1 -2
- package/declarations/instructions/redeemVault.d.ts +1 -2
- package/declarations/instructions/referralClaimFees.d.ts +1 -1
- package/declarations/instructions/refreshOraclePrice.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -2
- package/declarations/instructions/setHalted.d.ts +1 -1
- package/declarations/instructions/transferVault.d.ts +1 -1
- package/declarations/instructions/updateReferralAccount.d.ts +1 -2
- package/declarations/instructions/updateReferralState.d.ts +1 -2
- package/declarations/instructions/updateVaultType.d.ts +1 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -2
- package/declarations/state/VaultAccount.d.ts +2 -3
- package/declarations/utils/getLinkedListAccounts.d.ts +1 -2
- package/declarations/utils/sendAndConfirmWithDebug.d.ts +2 -2
- package/lib/Constants.js +14 -41
- package/lib/HedgeConstants.js +170 -0
- package/lib/HedgeDecimal.js +1 -2
- package/lib/StakingPools.js +5 -1
- package/lib/Vaults.js +5 -1
- package/lib/idl/vault.js +277 -1258
- package/lib/index.js +6 -13
- package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
- package/lib/instructions/claimStakingPoolPosition.js +7 -8
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
- package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
- package/lib/instructions/createReferralAccount.js +10 -11
- package/lib/instructions/createStakingPool.js +10 -11
- package/lib/instructions/createUserReferralAccount.js +9 -10
- package/lib/instructions/createVault.js +35 -50
- package/lib/instructions/depositLiquidationPool.js +12 -13
- package/lib/instructions/depositStakingPool.js +8 -9
- package/lib/instructions/depositVault.js +15 -26
- package/lib/instructions/initHedgeFoundation.js +24 -13
- package/lib/instructions/initHedgeFoundationTokens.js +7 -8
- package/lib/instructions/liquidateVault.js +12 -19
- package/lib/instructions/loanVault.js +17 -24
- package/lib/instructions/psmEditAccount.js +11 -11
- package/lib/instructions/psmMintUsh.js +18 -19
- package/lib/instructions/psmRedeemUsh.js +18 -19
- package/lib/instructions/redeemVault.js +10 -12
- package/lib/instructions/referralClaimFees.js +9 -10
- package/lib/instructions/refreshOraclePrice.js +10 -10
- package/lib/instructions/repayVault.js +12 -13
- package/lib/instructions/setHalted.js +4 -5
- package/lib/instructions/transferVault.js +2 -3
- package/lib/instructions/updateReferralAccount.js +6 -7
- package/lib/instructions/updateReferralState.js +6 -7
- package/lib/instructions/updateVaultType.js +5 -6
- package/lib/instructions/withdrawStakingPool.js +14 -15
- package/lib/instructions/withdrawVault.js +10 -11
- package/lib/state/VaultAccount.js +23 -9
- package/lib/state/VaultHistoryEvent.js +2 -2
- package/lib/utils/Errors.js +2 -3
- package/lib/utils/getLinkedListAccounts.js +2 -3
- package/lib/utils/sendAndConfirmWithDebug.js +50 -14
- package/package.json +9 -8
- package/src/{Constants.ts → HedgeConstants.ts} +13 -43
- package/src/idl/vault.ts +2004 -3966
- package/src/index.ts +3 -12
- package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
- package/src/instructions/claimStakingPoolPosition.ts +2 -2
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
- package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
- package/src/instructions/createReferralAccount.ts +11 -8
- package/src/instructions/createStakingPool.ts +11 -4
- package/src/instructions/createUserReferralAccount.ts +2 -2
- package/src/instructions/createVault.ts +26 -37
- package/src/instructions/depositLiquidationPool.ts +2 -2
- package/src/instructions/depositStakingPool.ts +2 -2
- package/src/instructions/depositVault.ts +24 -18
- package/src/instructions/initHedgeFoundation.ts +19 -4
- package/src/instructions/initHedgeFoundationTokens.ts +2 -2
- package/src/instructions/liquidateVault.ts +29 -39
- package/src/instructions/loanVault.ts +24 -37
- package/src/instructions/psmEditAccount.ts +3 -3
- package/src/instructions/psmMintUsh.ts +3 -3
- package/src/instructions/psmRedeemUsh.ts +3 -3
- package/src/instructions/redeemVault.ts +2 -3
- package/src/instructions/referralClaimFees.ts +11 -9
- package/src/instructions/refreshOraclePrice.ts +5 -5
- package/src/instructions/repayVault.ts +2 -2
- package/src/instructions/setHalted.ts +2 -2
- package/src/instructions/transferVault.ts +1 -1
- package/src/instructions/updateReferralAccount.ts +2 -2
- package/src/instructions/updateReferralState.ts +2 -2
- package/src/instructions/updateVaultType.ts +2 -2
- package/src/instructions/withdrawStakingPool.ts +2 -2
- package/src/instructions/withdrawVault.ts +4 -4
- package/src/state/VaultAccount.ts +1 -1
- package/src/utils/Errors.ts +1 -1
- package/src/utils/getLinkedListAccounts.ts +1 -1
- package/src/utils/sendAndConfirmWithDebug.ts +72 -23
- package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
- package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
- package/declarations/instructions/compoundCreateReferralAccount.d.ts +0 -17
- package/declarations/instructions/compoundReferralClaimFees.d.ts +0 -16
- package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
- package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
- package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
- package/declarations/instructions/setDelegateWallet.d.ts +0 -5
- package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
- package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/utils/Sender.d.ts +0 -2
- package/lib/instructions/adminWithdrawCol.js +0 -60
- package/lib/instructions/adminWithdrawUsh.js +0 -57
- package/lib/instructions/compoundCreateReferralAccount.js +0 -83
- package/lib/instructions/compoundReferralClaimFees.js +0 -87
- package/lib/instructions/createCompoundStakingPool.js +0 -58
- package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
- package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
- package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
- package/lib/instructions/setCompoundPoolActive.js +0 -43
- package/lib/instructions/setDelegateWallet.js +0 -43
- package/lib/instructions/setVaultTypeStatus.js +0 -38
- package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
- package/lib/utils/Sender.js +0 -32
- package/src/instructions/adminWithdrawCol.ts +0 -87
- package/src/instructions/adminWithdrawUsh.ts +0 -78
- package/src/instructions/compoundCreateReferralAccount.ts +0 -119
- package/src/instructions/compoundReferralClaimFees.ts +0 -151
- package/src/instructions/createCompoundStakingPool.ts +0 -63
- package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
- package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
- package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
- package/src/instructions/setCompoundPoolActive.ts +0 -51
- package/src/instructions/setDelegateWallet.ts +0 -51
- package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
package/lib/index.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
@@ -10,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
15
|
};
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
-
__exportStar(require("./
|
17
|
+
__exportStar(require("./HedgeConstants"), exports);
|
14
18
|
__exportStar(require("./HedgeDecimal"), exports);
|
15
19
|
__exportStar(require("./idl/vault"), exports);
|
16
20
|
__exportStar(require("./instructions/claimLiquidationPoolPosition"), exports);
|
@@ -20,8 +24,6 @@ __exportStar(require("./instructions/closeLiquidationPoolPosition"), exports);
|
|
20
24
|
__exportStar(require("./instructions/createReferralAccount"), exports);
|
21
25
|
__exportStar(require("./instructions/createStakingPool"), exports);
|
22
26
|
__exportStar(require("./instructions/createUserReferralAccount"), exports);
|
23
|
-
__exportStar(require("./instructions/compoundCreateReferralAccount"), exports);
|
24
|
-
__exportStar(require("./instructions/compoundReferralClaimFees"), exports);
|
25
27
|
__exportStar(require("./instructions/createVault"), exports);
|
26
28
|
__exportStar(require("./instructions/depositLiquidationPool"), exports);
|
27
29
|
__exportStar(require("./instructions/depositStakingPool"), exports);
|
@@ -38,15 +40,6 @@ __exportStar(require("./instructions/refreshOraclePrice"), exports);
|
|
38
40
|
__exportStar(require("./instructions/repayVault"), exports);
|
39
41
|
__exportStar(require("./instructions/setHalted"), exports);
|
40
42
|
__exportStar(require("./instructions/transferVault"), exports);
|
41
|
-
__exportStar(require("./instructions/createCompoundStakingPool"), exports);
|
42
|
-
__exportStar(require("./instructions/createCompoundStakingPoolPosition"), exports);
|
43
|
-
__exportStar(require("./instructions/depositCompoundStakingPoolPosition"), exports);
|
44
|
-
__exportStar(require("./instructions/withdrawCompoundStakingPoolPosition"), exports);
|
45
|
-
__exportStar(require("./instructions/setDelegateWallet"), exports);
|
46
|
-
__exportStar(require("./instructions/setCompoundPoolActive"), exports);
|
47
|
-
__exportStar(require("./instructions/adminWithdrawCol"), exports);
|
48
|
-
__exportStar(require("./instructions/adminWithdrawUsh"), exports);
|
49
|
-
__exportStar(require("./instructions/depositRewardsToCompoundPool"), exports);
|
50
43
|
__exportStar(require("./instructions/updateReferralAccount"), exports);
|
51
44
|
__exportStar(require("./instructions/updateReferralState"), exports);
|
52
45
|
__exportStar(require("./instructions/updateVaultType"), exports);
|
@@ -12,15 +12,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
15
|
+
exports.claimLiquidationPoolPosition = claimLiquidationPoolPosition;
|
16
|
+
exports.claimLiquidationPoolPositionInstruction = claimLiquidationPoolPositionInstruction;
|
16
17
|
const spl_token_1 = require("@solana/spl-token");
|
17
18
|
const web3_js_1 = require("@solana/web3.js");
|
18
|
-
const
|
19
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
19
20
|
const Errors_1 = require("../utils/Errors");
|
20
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
21
22
|
function claimLiquidationPoolPosition(program, provider, poolPosition, payer, collateralType, overrideStartTime) {
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
23
|
-
const vaultTypeAccountPublicKey = yield (0,
|
24
|
+
const vaultTypeAccountPublicKey = yield (0, HedgeConstants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
24
25
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
25
26
|
const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint;
|
26
27
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMintPublicKey, payer.publicKey);
|
@@ -29,12 +30,11 @@ function claimLiquidationPoolPosition(program, provider, poolPosition, payer, co
|
|
29
30
|
return payerAssociatedTokenAccount.address;
|
30
31
|
});
|
31
32
|
}
|
32
|
-
exports.claimLiquidationPoolPosition = claimLiquidationPoolPosition;
|
33
33
|
function claimLiquidationPoolPositionInstruction(program, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount, overrideStartTime) {
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
35
|
-
const vaultSystemState = yield (0,
|
36
|
-
const poolStatePublicKey = yield (0,
|
37
|
-
const poolAssociatedTokenAccount = yield (0,
|
35
|
+
const vaultSystemState = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
36
|
+
const poolStatePublicKey = yield (0, HedgeConstants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
37
|
+
const poolAssociatedTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, poolStatePublicKey, collateralMint);
|
38
38
|
return yield program.methods
|
39
39
|
.claimLiquidationPoolPosition()
|
40
40
|
.accounts({
|
@@ -54,4 +54,3 @@ function claimLiquidationPoolPositionInstruction(program, vaultTypeAccount, coll
|
|
54
54
|
.instruction();
|
55
55
|
});
|
56
56
|
}
|
57
|
-
exports.claimLiquidationPoolPositionInstruction = claimLiquidationPoolPositionInstruction;
|
@@ -12,19 +12,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
15
|
+
exports.claimStakingPoolPosition = claimStakingPoolPosition;
|
16
|
+
exports.claimStakingPoolPositionInstruction = claimStakingPoolPositionInstruction;
|
16
17
|
const spl_token_1 = require("@solana/spl-token");
|
17
18
|
const web3_js_1 = require("@solana/web3.js");
|
18
|
-
const
|
19
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
19
20
|
const Errors_1 = require("../utils/Errors");
|
20
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
21
22
|
function claimStakingPoolPosition(program, provider, poolPosition, payer, collateralType) {
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
23
|
-
const vaultTypeAccount = yield (0,
|
24
|
+
const vaultTypeAccount = yield (0, HedgeConstants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
24
25
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccount);
|
25
26
|
const collateralMint = vaultTypeAccountInfo.collateralMint;
|
26
|
-
const stakedTokenMint = yield (0,
|
27
|
-
const [feePool] = yield (0,
|
27
|
+
const stakedTokenMint = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
28
|
+
const [feePool] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, stakedTokenMint);
|
28
29
|
const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, feePool, true);
|
29
30
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
30
31
|
const transaction = new web3_js_1.Transaction().add(yield claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount.address, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address));
|
@@ -32,10 +33,9 @@ function claimStakingPoolPosition(program, provider, poolPosition, payer, collat
|
|
32
33
|
return payerAssociatedTokenAccount.address;
|
33
34
|
});
|
34
35
|
}
|
35
|
-
exports.claimStakingPoolPosition = claimStakingPoolPosition;
|
36
36
|
function claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount) {
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
38
|
-
const vaultSystemState = yield (0,
|
38
|
+
const vaultSystemState = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
39
39
|
return yield program.methods
|
40
40
|
.claimStakingPoolPosition()
|
41
41
|
.accounts({
|
@@ -56,4 +56,3 @@ function claimStakingPoolPositionInstruction(program, feePool, feePoolAssociated
|
|
56
56
|
.instruction();
|
57
57
|
});
|
58
58
|
}
|
59
|
-
exports.claimStakingPoolPositionInstruction = claimStakingPoolPositionInstruction;
|
@@ -12,7 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
15
|
+
exports.closeClaimedLiquidationPoolPosition = closeClaimedLiquidationPoolPosition;
|
16
|
+
exports.closeClaimedLiquidationPoolPositionInstruction = closeClaimedLiquidationPoolPositionInstruction;
|
16
17
|
const web3_js_1 = require("@solana/web3.js");
|
17
18
|
const Errors_1 = require("../utils/Errors");
|
18
19
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
@@ -23,7 +24,6 @@ function closeClaimedLiquidationPoolPosition(program, provider, poolPosition, pa
|
|
23
24
|
return poolPosition;
|
24
25
|
});
|
25
26
|
}
|
26
|
-
exports.closeClaimedLiquidationPoolPosition = closeClaimedLiquidationPoolPosition;
|
27
27
|
function closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer) {
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
29
|
return program.methods
|
@@ -35,4 +35,3 @@ function closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, p
|
|
35
35
|
.instruction();
|
36
36
|
});
|
37
37
|
}
|
38
|
-
exports.closeClaimedLiquidationPoolPositionInstruction = closeClaimedLiquidationPoolPositionInstruction;
|
@@ -12,46 +12,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
|
15
|
+
exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
|
16
|
+
exports.closeLiquidationPoolPositionInstruction = closeLiquidationPoolPositionInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const spl_token_1 = require("@solana/spl-token");
|
18
19
|
const web3_js_1 = require("@solana/web3.js");
|
19
|
-
const
|
20
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
20
21
|
const Errors_1 = require("../utils/Errors");
|
21
22
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
22
23
|
function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime, referrer) {
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
const ushMintPublickey = yield (0,
|
25
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
25
26
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
26
|
-
const vaultSystemStatePublicKey = yield (0,
|
27
|
-
const referralStatePublicKey = yield (0,
|
27
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
28
|
+
const referralStatePublicKey = yield (0, HedgeConstants_1.getReferralStatePublicKey)(program.programId);
|
28
29
|
const liquidationPositionAccount = yield program.account.liquidationPosition.fetch(poolPosition);
|
29
30
|
const poolEra = liquidationPositionAccount.era;
|
30
|
-
const hedgeMint = yield (0,
|
31
|
+
const hedgeMint = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
31
32
|
const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
|
32
33
|
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
|
33
34
|
let referralAccountPublicKey = null;
|
34
35
|
if (typeof referrer === 'undefined') {
|
35
|
-
referralAccountPublicKey = yield (0,
|
36
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
36
37
|
}
|
37
38
|
else {
|
38
|
-
referralAccountPublicKey = yield (0,
|
39
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
39
40
|
}
|
40
41
|
// Derive the user referral account public key
|
41
|
-
const userReferralAccountPublicKey = yield (0,
|
42
|
+
const userReferralAccountPublicKey = yield (0, HedgeConstants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
42
43
|
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUshAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, userReferralAccountPublicKey, referralAccountPublicKey, referralStatePublicKey, overrideStartTime));
|
43
44
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
44
45
|
return poolPosition;
|
45
46
|
});
|
46
47
|
}
|
47
|
-
exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
|
48
48
|
function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUshAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, userReferralAccountPublicKey, referralAccountPublicKey, referralStatePublicKey, overrideStartTime) {
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
50
|
-
const vaultSystemStatePublicKey = yield (0,
|
51
|
-
const ushMint = yield (0,
|
52
|
-
const hedgeMint = yield (0,
|
53
|
-
const poolUshAccount = yield (0,
|
54
|
-
const poolState = yield (0,
|
50
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
51
|
+
const ushMint = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
52
|
+
const hedgeMint = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
53
|
+
const poolUshAccount = yield (0, HedgeConstants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
54
|
+
const poolState = yield (0, HedgeConstants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
55
55
|
return yield program.methods
|
56
56
|
.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
57
57
|
)
|
@@ -78,4 +78,3 @@ function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition,
|
|
78
78
|
.instruction();
|
79
79
|
});
|
80
80
|
}
|
81
|
-
exports.closeLiquidationPoolPositionInstruction = closeLiquidationPoolPositionInstruction;
|
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
|
15
|
+
exports.createReferralAccount = createReferralAccount;
|
16
|
+
exports.createReferralAccountInstruction = createReferralAccountInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const spl_token_1 = require("@solana/spl-token");
|
18
19
|
const web3_js_1 = require("@solana/web3.js");
|
19
|
-
const
|
20
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
20
21
|
const Errors_1 = require("../utils/Errors");
|
21
22
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
22
23
|
/** @type {Function} - Creates a new referral account.
|
@@ -38,26 +39,25 @@ function createReferralAccount(program, provider, payer, poolPosition, overrideT
|
|
38
39
|
const signers = [payer];
|
39
40
|
const referrer = payer.publicKey;
|
40
41
|
// Setup public keys
|
41
|
-
const vaultSystemStatePublicKey = yield (0,
|
42
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
42
43
|
// Find referral account
|
43
|
-
let referralAccountPublicKey = yield (0,
|
44
|
+
let referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
44
45
|
// Get the referral state PDA
|
45
|
-
const referallStatePublicKey = yield (0,
|
46
|
+
const referallStatePublicKey = yield (0, HedgeConstants_1.getReferralStatePublicKey)(program.programId);
|
46
47
|
// Get HDG mint public key
|
47
|
-
const hedgeMintPublicKey = yield (0,
|
48
|
+
const hedgeMintPublicKey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
48
49
|
// Get HDG account of signer
|
49
50
|
const payerHdgAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, payer.publicKey);
|
50
51
|
// Derive the user referral account public key
|
51
|
-
const userReferralAccountPublicKey = yield (0,
|
52
|
+
const userReferralAccountPublicKey = yield (0, HedgeConstants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
52
53
|
transaction.add(yield createReferralAccountInstruction(program, payer.publicKey, poolPosition, referralAccountPublicKey, referallStatePublicKey, hedgeMintPublicKey, payerHdgAssociatedTokenAccount.address, userReferralAccountPublicKey, overrideTime));
|
53
54
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
54
55
|
return referralAccountPublicKey;
|
55
56
|
});
|
56
57
|
}
|
57
|
-
exports.createReferralAccount = createReferralAccount;
|
58
58
|
function createReferralAccountInstruction(program, payerPublicKey, poolPositionPublicKey, referralAccountPublicKey, referralStatePublicKey, hedgeMintPublicKey, hdgAssociatedTokenAccountPublicKey, userReferralAccountPublicKey, overrideTime) {
|
59
59
|
return __awaiter(this, void 0, void 0, function* () {
|
60
|
-
const vaultSystemStatePublicKey = yield (0,
|
60
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
61
61
|
return yield program.methods
|
62
62
|
.createReferralAccount(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override times
|
63
63
|
)
|
@@ -77,4 +77,3 @@ function createReferralAccountInstruction(program, payerPublicKey, poolPositionP
|
|
77
77
|
.instruction();
|
78
78
|
});
|
79
79
|
}
|
80
|
-
exports.createReferralAccountInstruction = createReferralAccountInstruction;
|
@@ -12,29 +12,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
|
15
|
+
exports.createStakingPool = createStakingPool;
|
16
|
+
exports.createStakingPoolInstruction = createStakingPoolInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const spl_token_1 = require("@solana/spl-token");
|
18
19
|
const web3_js_1 = require("@solana/web3.js");
|
19
|
-
const
|
20
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
20
21
|
const Errors_1 = require("../utils/Errors");
|
21
22
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
22
23
|
function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
24
25
|
const transaction = new web3_js_1.Transaction().add(yield createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
|
25
26
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
26
|
-
const [poolPublickey] = yield (0,
|
27
|
+
const [poolPublickey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
27
28
|
return poolPublickey;
|
28
29
|
});
|
29
30
|
}
|
30
|
-
exports.createStakingPool = createStakingPool;
|
31
31
|
function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
33
|
-
const vaultSystemStatePublicKey = yield (0,
|
34
|
-
const ushMintPublickey = yield (0,
|
35
|
-
const [poolPublickey, poolBump] = yield (0,
|
36
|
-
const poolAssociatedStakedTokenAccount = yield (0,
|
37
|
-
const poolAssociatedUshTokenAccount = yield (0,
|
33
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
34
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
35
|
+
const [poolPublickey, poolBump] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
36
|
+
const poolAssociatedStakedTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, mintPublicKey);
|
37
|
+
const poolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, ushMintPublickey);
|
38
38
|
return yield program.methods
|
39
39
|
.createStakingPool(poolBump, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)))
|
40
40
|
.accounts({
|
@@ -53,4 +53,3 @@ function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, he
|
|
53
53
|
.instruction();
|
54
54
|
});
|
55
55
|
}
|
56
|
-
exports.createStakingPoolInstruction = createStakingPoolInstruction;
|
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
|
15
|
+
exports.createUserReferralAccount = createUserReferralAccount;
|
16
|
+
exports.createUserReferralAccountInstruction = createUserReferralAccountInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const spl_token_1 = require("@solana/spl-token");
|
18
19
|
const web3_js_1 = require("@solana/web3.js");
|
19
|
-
const
|
20
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
20
21
|
const Errors_1 = require("../utils/Errors");
|
21
22
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
22
23
|
function createUserReferralAccount(program, provider, payer, referrer, overrideTime) {
|
@@ -26,24 +27,23 @@ function createUserReferralAccount(program, provider, payer, referrer, overrideT
|
|
26
27
|
const signers = [payer];
|
27
28
|
// Find referrer account
|
28
29
|
let referralAccountPublicKey = null;
|
29
|
-
const vaultSystemStatePublicKey = yield (0,
|
30
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
30
31
|
if (typeof referrer === 'undefined') {
|
31
|
-
referralAccountPublicKey = yield (0,
|
32
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
32
33
|
}
|
33
34
|
else {
|
34
|
-
referralAccountPublicKey = yield (0,
|
35
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
35
36
|
}
|
36
37
|
// Derive the user referral account public key
|
37
|
-
const userReferralAccountPublicKey = yield (0,
|
38
|
+
const userReferralAccountPublicKey = yield (0, HedgeConstants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
38
39
|
transaction.add(yield createUserReferralAccountInstruction(program, payer.publicKey, referralAccountPublicKey, userReferralAccountPublicKey, overrideTime));
|
39
40
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
40
41
|
return userReferralAccountPublicKey;
|
41
42
|
});
|
42
43
|
}
|
43
|
-
exports.createUserReferralAccount = createUserReferralAccount;
|
44
44
|
function createUserReferralAccountInstruction(program, payerPublicKey, referralAccount, userReferralAccount, overrideTime) {
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
46
|
-
const vaultSystemStatePublicKey = yield (0,
|
46
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
47
47
|
return yield program.methods
|
48
48
|
.createUserReferralAccount(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
49
49
|
)
|
@@ -58,4 +58,3 @@ function createUserReferralAccountInstruction(program, payerPublicKey, referralA
|
|
58
58
|
.instruction();
|
59
59
|
});
|
60
60
|
}
|
61
|
-
exports.createUserReferralAccountInstruction = createUserReferralAccountInstruction;
|
@@ -12,33 +12,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
|
17
|
-
|
15
|
+
exports.createVault = createVault;
|
16
|
+
exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
|
17
|
+
exports.createVaultInstruction = createVaultInstruction;
|
18
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
18
19
|
const spl_token_1 = require("@solana/spl-token");
|
19
20
|
const web3_js_1 = require("@solana/web3.js");
|
20
|
-
const
|
21
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
21
22
|
const uuid_1 = require("uuid");
|
22
23
|
const Errors_1 = require("../utils/Errors");
|
23
24
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
25
|
+
const spl_token_2 = require("@solana/spl-token");
|
26
|
+
const spl_token_3 = require("@solana/spl-token");
|
24
27
|
function createVault(program, provider, payer, collateralType, depositAmount, overrideTime) {
|
25
28
|
return __awaiter(this, void 0, void 0, function* () {
|
26
|
-
const ushMintPublickey = yield (0,
|
29
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
27
30
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
28
|
-
const newVaultPublicKey = yield (0,
|
31
|
+
const newVaultPublicKey = yield (0, HedgeConstants_1.findVaultAddress)(program.programId, salt);
|
29
32
|
const history = web3_js_1.Keypair.generate();
|
30
33
|
// Prep the user to get USH back out at some point
|
31
34
|
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
32
|
-
const vaultTypeAccountPublicKey = yield (0,
|
35
|
+
const vaultTypeAccountPublicKey = yield (0, HedgeConstants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
33
36
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
34
|
-
const payerTokenAccount = yield (0,
|
35
|
-
const vaultAssociatedTokenAccount = yield (0,
|
37
|
+
const payerTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
38
|
+
const vaultAssociatedTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
36
39
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
37
40
|
const transaction = new web3_js_1.Transaction();
|
38
41
|
const signers = [payer, history];
|
39
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
40
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
41
|
-
const feePoolAssociatedUshTokenAccount = yield (0,
|
42
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === spl_token_1.NATIVE_MINT.toString();
|
43
|
+
const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId));
|
44
|
+
const feePoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
42
45
|
if (isWrappedSol) {
|
43
46
|
transaction.add(web3_js_1.SystemProgram.createAccount({
|
44
47
|
fromPubkey: payer.publicKey,
|
@@ -46,51 +49,43 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
46
49
|
newAccountPubkey: wrappedSolAccount.publicKey,
|
47
50
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
48
51
|
space: 165,
|
49
|
-
}),
|
50
|
-
account: wrappedSolAccount.publicKey,
|
51
|
-
mint: serum_1.TokenInstructions.WRAPPED_SOL_MINT,
|
52
|
-
owner: payer.publicKey,
|
53
|
-
}));
|
52
|
+
}), (0, spl_token_2.createInitializeAccountInstruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, payer.publicKey));
|
54
53
|
signers.push(wrappedSolAccount);
|
55
54
|
}
|
56
55
|
transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, new anchor_1.BN(depositAmount), overrideTime));
|
57
56
|
if (isWrappedSol) {
|
58
|
-
transaction.add(
|
59
|
-
source: wrappedSolAccount.publicKey,
|
60
|
-
destination: payer.publicKey,
|
61
|
-
owner: payer.publicKey,
|
62
|
-
}));
|
57
|
+
transaction.add((0, spl_token_3.createCloseAccountInstruction)(wrappedSolAccount.publicKey, payer.publicKey, payer.publicKey));
|
63
58
|
}
|
64
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
59
|
+
const result = yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
65
60
|
return newVaultPublicKey;
|
66
61
|
});
|
67
62
|
}
|
68
|
-
exports.createVault = createVault;
|
69
63
|
function buildCreateVaultTransaction(program, payerPublicKey, collateralType, depositAmount, overrideTime) {
|
70
64
|
return __awaiter(this, void 0, void 0, function* () {
|
71
65
|
console.log('HEDGE SDK: buildCreateVaultTransaction');
|
72
|
-
const ushMintPublickey = yield (0,
|
66
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
73
67
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
74
|
-
const newVaultPublicKey = yield (0,
|
68
|
+
const newVaultPublicKey = yield (0, HedgeConstants_1.findVaultAddress)(program.programId, salt);
|
75
69
|
const history = web3_js_1.Keypair.generate();
|
76
70
|
const { blockhash, lastValidBlockHeight } = yield program.provider.connection.getLatestBlockhash();
|
77
71
|
const transaction = new web3_js_1.Transaction({
|
78
72
|
feePayer: payerPublicKey,
|
79
|
-
|
73
|
+
blockhash: blockhash,
|
74
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
80
75
|
});
|
81
76
|
const signers = [history];
|
82
77
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
83
78
|
console.log('Lookup getVaultTypeAccountPublicKey', collateralType);
|
84
79
|
// Lookup the vault type info
|
85
|
-
const vaultTypeAccountPublicKey = yield (0,
|
80
|
+
const vaultTypeAccountPublicKey = yield (0, HedgeConstants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
86
81
|
console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString());
|
87
82
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
88
83
|
console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo);
|
89
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
90
|
-
const payerTokenAccount = yield (0,
|
91
|
-
const vaultAssociatedTokenAccount = yield (0,
|
92
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
93
|
-
const feePoolAssociatedUshTokenAccount = yield (0,
|
84
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === spl_token_1.NATIVE_MINT.toString();
|
85
|
+
const payerTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, vaultTypeAccountInfo.collateralMint);
|
86
|
+
const vaultAssociatedTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
87
|
+
const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId));
|
88
|
+
const feePoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
94
89
|
console.log('about to start building transaction');
|
95
90
|
// If wrapped SOL collateral, we convert the SOL to wSOL to use in the instruction
|
96
91
|
if (isWrappedSol) {
|
@@ -100,21 +95,13 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
|
|
100
95
|
newAccountPubkey: wrappedSolAccount.publicKey,
|
101
96
|
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
102
97
|
space: 165,
|
103
|
-
}),
|
104
|
-
account: wrappedSolAccount.publicKey,
|
105
|
-
mint: serum_1.TokenInstructions.WRAPPED_SOL_MINT,
|
106
|
-
owner: payerPublicKey,
|
107
|
-
}));
|
98
|
+
}), (0, spl_token_2.createInitializeAccountInstruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, payerPublicKey));
|
108
99
|
signers.push(wrappedSolAccount);
|
109
100
|
}
|
110
101
|
console.log('hedgeStakingPoolPublicKey', hedgeStakingPoolPublicKey.toString());
|
111
102
|
transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, new anchor_1.BN(depositAmount), overrideTime));
|
112
103
|
if (isWrappedSol) {
|
113
|
-
transaction.add(
|
114
|
-
source: wrappedSolAccount.publicKey,
|
115
|
-
destination: payerPublicKey,
|
116
|
-
owner: payerPublicKey,
|
117
|
-
}));
|
104
|
+
transaction.add((0, spl_token_3.createCloseAccountInstruction)(wrappedSolAccount.publicKey, payerPublicKey, payerPublicKey));
|
118
105
|
transaction.partialSign(wrappedSolAccount);
|
119
106
|
}
|
120
107
|
transaction.partialSign(history);
|
@@ -122,25 +109,24 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
|
|
122
109
|
return [transaction, signers, newVaultPublicKey];
|
123
110
|
});
|
124
111
|
}
|
125
|
-
exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
|
126
112
|
function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
|
127
113
|
return __awaiter(this, void 0, void 0, function* () {
|
128
|
-
const vaultSystemStatePublicKey = yield (0,
|
114
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
129
115
|
return yield program.methods
|
130
|
-
.createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override
|
116
|
+
.createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override time
|
131
117
|
)
|
132
118
|
.accounts({
|
133
119
|
vaultSystemState: vaultSystemStatePublicKey,
|
134
120
|
vaultTypeAccount: vaultTypeAccount,
|
135
121
|
vault: vaultPublicKey,
|
136
122
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
137
|
-
feePool: feePool,
|
138
|
-
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
123
|
+
// feePool: feePool,
|
124
|
+
// feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
139
125
|
history: historyPublicKey,
|
140
126
|
payer: payerPublicKey,
|
141
127
|
payerTokenAccount: payerTokenAccountPublicKey,
|
142
128
|
collateralMint: collateralMint,
|
143
|
-
ushMint: ushMintPublickey,
|
129
|
+
// ushMint: ushMintPublickey,
|
144
130
|
systemProgram: web3_js_1.SystemProgram.programId,
|
145
131
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
146
132
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -149,4 +135,3 @@ function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccount
|
|
149
135
|
.instruction();
|
150
136
|
});
|
151
137
|
}
|
152
|
-
exports.createVaultInstruction = createVaultInstruction;
|
@@ -12,40 +12,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
|
15
|
+
exports.depositLiquidationPool = depositLiquidationPool;
|
16
|
+
exports.depositLiquidationPoolInstruction = depositLiquidationPoolInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const spl_token_1 = require("@solana/spl-token");
|
18
19
|
const web3_js_1 = require("@solana/web3.js");
|
19
|
-
const
|
20
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
20
21
|
const Errors_1 = require("../utils/Errors");
|
21
22
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
22
23
|
function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime, referrer) {
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
const ushMintPublickey = yield (0,
|
25
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
25
26
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
26
27
|
let referralAccountPublicKey = null;
|
27
|
-
const vaultSystemStatePublicKey = yield (0,
|
28
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
28
29
|
if (typeof referrer === 'undefined') {
|
29
|
-
referralAccountPublicKey = yield (0,
|
30
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
30
31
|
}
|
31
32
|
else {
|
32
|
-
referralAccountPublicKey = yield (0,
|
33
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
33
34
|
}
|
34
35
|
// Derive the user referral account public key
|
35
|
-
const userReferralAccountPublicKey = yield (0,
|
36
|
+
const userReferralAccountPublicKey = yield (0, HedgeConstants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
36
37
|
const poolPosition = web3_js_1.Keypair.generate();
|
37
38
|
const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, vaultSystemStatePublicKey, payerUshAccount.address, poolPosition.publicKey, new anchor_1.BN(depositAmount), userReferralAccountPublicKey, referralAccountPublicKey, overrideStartTime));
|
38
39
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
|
39
40
|
return poolPosition.publicKey;
|
40
41
|
});
|
41
42
|
}
|
42
|
-
exports.depositLiquidationPool = depositLiquidationPool;
|
43
43
|
function depositLiquidationPoolInstruction(program, payerPublicKey, vaultSystemStatePublicKey, payerUshAccount, poolPositionPublicKey, depositAmount, userReferralAccountPublicKey, referralAccountPublicKey, overrideStartTime) {
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
45
|
-
const liquidationPoolStatePublicKey = yield (0,
|
45
|
+
const liquidationPoolStatePublicKey = yield (0, HedgeConstants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
46
46
|
const liquidationPoolState = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
47
|
-
const poolUSHAccount = yield (0,
|
48
|
-
const ushMint = yield (0,
|
47
|
+
const poolUSHAccount = yield (0, HedgeConstants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
48
|
+
const ushMint = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
49
49
|
return yield program.methods
|
50
50
|
.depositLiquidationPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
51
51
|
)
|
@@ -66,4 +66,3 @@ function depositLiquidationPoolInstruction(program, payerPublicKey, vaultSystemS
|
|
66
66
|
.instruction();
|
67
67
|
});
|
68
68
|
}
|
69
|
-
exports.depositLiquidationPoolInstruction = depositLiquidationPoolInstruction;
|