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
package/lib/index.js
CHANGED
|
@@ -10,36 +10,42 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./
|
|
14
|
-
__exportStar(require("./
|
|
15
|
-
__exportStar(require("./
|
|
16
|
-
__exportStar(require("./instructions/claimStakingPoolPosition"), exports);
|
|
17
|
-
__exportStar(require("./instructions/depositLiquidationPool"), exports);
|
|
18
|
-
__exportStar(require("./instructions/closeLiquidationPoolPosition"), exports);
|
|
13
|
+
__exportStar(require("./Constants"), exports);
|
|
14
|
+
__exportStar(require("./HedgeDecimal"), exports);
|
|
15
|
+
__exportStar(require("./idl/vault"), exports);
|
|
19
16
|
__exportStar(require("./instructions/claimLiquidationPoolPosition"), exports);
|
|
17
|
+
__exportStar(require("./instructions/claimStakingPoolPosition"), exports);
|
|
20
18
|
__exportStar(require("./instructions/closeClaimedLiquidationPoolPosition"), exports);
|
|
19
|
+
__exportStar(require("./instructions/closeLiquidationPoolPosition"), exports);
|
|
20
|
+
__exportStar(require("./instructions/createReferralAccount"), exports);
|
|
21
|
+
__exportStar(require("./instructions/createStakingPool"), exports);
|
|
22
|
+
__exportStar(require("./instructions/createUserReferralAccount"), exports);
|
|
21
23
|
__exportStar(require("./instructions/createVault"), exports);
|
|
22
|
-
__exportStar(require("./instructions/
|
|
23
|
-
__exportStar(require("./instructions/
|
|
24
|
+
__exportStar(require("./instructions/depositLiquidationPool"), exports);
|
|
25
|
+
__exportStar(require("./instructions/depositStakingPool"), exports);
|
|
24
26
|
__exportStar(require("./instructions/depositVault"), exports);
|
|
25
|
-
__exportStar(require("./instructions/
|
|
27
|
+
__exportStar(require("./instructions/initHedgeFoundation"), exports);
|
|
28
|
+
__exportStar(require("./instructions/initHedgeFoundationTokens"), exports);
|
|
29
|
+
__exportStar(require("./instructions/liquidateVault"), exports);
|
|
26
30
|
__exportStar(require("./instructions/loanVault"), exports);
|
|
27
|
-
__exportStar(require("./instructions/
|
|
31
|
+
__exportStar(require("./instructions/psmMintUsh"), exports);
|
|
32
|
+
__exportStar(require("./instructions/psmRedeemUsh"), exports);
|
|
28
33
|
__exportStar(require("./instructions/redeemVault"), exports);
|
|
29
|
-
__exportStar(require("./instructions/
|
|
34
|
+
__exportStar(require("./instructions/referralClaimFees"), exports);
|
|
30
35
|
__exportStar(require("./instructions/refreshOraclePrice"), exports);
|
|
31
|
-
__exportStar(require("./instructions/
|
|
32
|
-
__exportStar(require("./instructions/initHedgeFoundationTokens"), exports);
|
|
36
|
+
__exportStar(require("./instructions/repayVault"), exports);
|
|
33
37
|
__exportStar(require("./instructions/setHalted"), exports);
|
|
38
|
+
__exportStar(require("./instructions/transferVault"), exports);
|
|
39
|
+
__exportStar(require("./instructions/updateReferralAccount"), exports);
|
|
40
|
+
__exportStar(require("./instructions/updateReferralState"), exports);
|
|
34
41
|
__exportStar(require("./instructions/updateVaultType"), exports);
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./state/VaultAccount"), exports);
|
|
38
|
-
__exportStar(require("./state/VaultHistoryEvent"), exports);
|
|
39
|
-
__exportStar(require("./state/StakingPool"), exports);
|
|
40
|
-
__exportStar(require("./state/StakingPoolPosition"), exports);
|
|
42
|
+
__exportStar(require("./instructions/withdrawStakingPool"), exports);
|
|
43
|
+
__exportStar(require("./instructions/withdrawVault"), exports);
|
|
41
44
|
__exportStar(require("./state/LiquidationPoolEra"), exports);
|
|
42
45
|
__exportStar(require("./state/LiquidationPoolState"), exports);
|
|
43
46
|
__exportStar(require("./state/LiquidationPosition"), exports);
|
|
47
|
+
__exportStar(require("./state/StakingPool"), exports);
|
|
48
|
+
__exportStar(require("./state/StakingPoolPosition"), exports);
|
|
49
|
+
__exportStar(require("./state/VaultAccount"), exports);
|
|
50
|
+
__exportStar(require("./state/VaultHistoryEvent"), exports);
|
|
44
51
|
__exportStar(require("./utils/getLinkedListAccounts"), exports);
|
|
45
|
-
__exportStar(require("./idl/vault"), exports);
|
|
@@ -15,12 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.claimLiquidationPoolPositionInstruction = exports.claimLiquidationPoolPosition = 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 claimLiquidationPoolPosition(program, provider, poolPosition, payer, collateralType, overrideStartTime) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
|
23
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
|
24
24
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
|
25
25
|
const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint;
|
|
26
26
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMintPublicKey, payer.publicKey);
|
|
@@ -32,10 +32,12 @@ function claimLiquidationPoolPosition(program, provider, poolPosition, payer, co
|
|
|
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, Constants_1.getVaultSystemStatePublicKey)();
|
|
36
|
-
const poolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
|
37
|
-
const poolAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolStatePublicKey, collateralMint);
|
|
38
|
-
return yield program.methods
|
|
35
|
+
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
36
|
+
const poolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
|
37
|
+
const poolAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolStatePublicKey, collateralMint);
|
|
38
|
+
return yield program.methods
|
|
39
|
+
.claimLiquidationPoolPosition()
|
|
40
|
+
.accounts({
|
|
39
41
|
vaultSystemState: vaultSystemState,
|
|
40
42
|
poolState: poolStatePublicKey,
|
|
41
43
|
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
|
@@ -48,7 +50,8 @@ function claimLiquidationPoolPositionInstruction(program, vaultTypeAccount, coll
|
|
|
48
50
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
49
51
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
50
52
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
51
|
-
})
|
|
53
|
+
})
|
|
54
|
+
.instruction();
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
exports.claimLiquidationPoolPositionInstruction = claimLiquidationPoolPositionInstruction;
|
|
@@ -15,16 +15,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.claimStakingPoolPositionInstruction = exports.claimStakingPoolPosition = 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 claimStakingPoolPosition(program, provider, poolPosition, payer, collateralType) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
|
23
|
+
const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
|
24
24
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccount);
|
|
25
25
|
const collateralMint = vaultTypeAccountInfo.collateralMint;
|
|
26
|
-
const stakedTokenMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
27
|
-
const [feePool] = yield (0, Constants_1.getPoolPublicKeyForMint)(stakedTokenMint);
|
|
26
|
+
const stakedTokenMint = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
27
|
+
const [feePool] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, stakedTokenMint);
|
|
28
28
|
const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, feePool, true);
|
|
29
29
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
|
30
30
|
const transaction = new web3_js_1.Transaction().add(yield claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount.address, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address));
|
|
@@ -35,7 +35,7 @@ function claimStakingPoolPosition(program, provider, poolPosition, payer, collat
|
|
|
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, Constants_1.getVaultSystemStatePublicKey)();
|
|
38
|
+
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
39
39
|
return yield program.methods
|
|
40
40
|
.claimStakingPoolPosition()
|
|
41
41
|
.accounts({
|
|
@@ -16,32 +16,42 @@ exports.closeLiquidationPoolPositionInstruction = exports.closeLiquidationPoolPo
|
|
|
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 Errors_1 = require("../utils/Errors");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const Errors_1 = require("../utils/Errors");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
|
-
function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime) {
|
|
22
|
+
function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime, 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
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
26
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
27
|
+
const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
|
|
27
28
|
const liquidationPositionAccount = yield program.account.liquidationPosition.fetch(poolPosition);
|
|
28
29
|
const poolEra = liquidationPositionAccount.era;
|
|
29
|
-
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
30
|
+
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
30
31
|
const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
|
|
31
32
|
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
|
|
32
|
-
|
|
33
|
+
let referralAccountPublicKey = null;
|
|
34
|
+
if (typeof referrer === 'undefined') {
|
|
35
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
39
|
+
}
|
|
40
|
+
// Derive the user referral account public key
|
|
41
|
+
const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
|
42
|
+
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));
|
|
33
43
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
|
34
44
|
return poolPosition;
|
|
35
45
|
});
|
|
36
46
|
}
|
|
37
47
|
exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
|
|
38
|
-
function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUshAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
|
|
48
|
+
function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUshAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, userReferralAccountPublicKey, referralAccountPublicKey, referralStatePublicKey, overrideStartTime) {
|
|
39
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
41
|
-
const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
|
|
42
|
-
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
|
43
|
-
const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
|
44
|
-
const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
|
50
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
51
|
+
const ushMint = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
52
|
+
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
53
|
+
const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
|
54
|
+
const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
|
45
55
|
return yield program.methods
|
|
46
56
|
.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
|
47
57
|
)
|
|
@@ -57,6 +67,9 @@ function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition,
|
|
|
57
67
|
ushMint: ushMint,
|
|
58
68
|
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
|
59
69
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
|
70
|
+
userReferralAccount: userReferralAccountPublicKey,
|
|
71
|
+
referralAccount: referralAccountPublicKey,
|
|
72
|
+
referralState: referralStatePublicKey,
|
|
60
73
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
61
74
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
62
75
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
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.createReferralAccountInstruction = exports.createReferralAccount = 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 Errors_1 = require("../utils/Errors");
|
|
21
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
|
+
/** @type {Function} - Creates a new referral account.
|
|
23
|
+
* This checks the user has enough HDG in their wallet or staked and
|
|
24
|
+
* then allows them to create a referral account. If they meet the PSM referral threshold,
|
|
25
|
+
* they will be eligible for PSM cut.
|
|
26
|
+
* Params:
|
|
27
|
+
* - program: Program<Vault> : The program instance of Hedge Vault program
|
|
28
|
+
* - provider: Provider : Current connection
|
|
29
|
+
* - payer: Signer : who we are creating the referral account for
|
|
30
|
+
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
|
31
|
+
* - referrer: PublicKey
|
|
32
|
+
* - overrideTime?: number
|
|
33
|
+
*/
|
|
34
|
+
function createReferralAccount(program, provider, payer, poolPosition, overrideTime) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
// setup transaction
|
|
37
|
+
const transaction = new web3_js_1.Transaction();
|
|
38
|
+
const signers = [payer];
|
|
39
|
+
const referrer = payer.publicKey;
|
|
40
|
+
// Setup public keys
|
|
41
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
42
|
+
// Find referral account
|
|
43
|
+
let referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
44
|
+
// Get the referral state PDA
|
|
45
|
+
const referallStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
|
|
46
|
+
// Get HDG mint public key
|
|
47
|
+
const hedgeMintPublicKey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
|
48
|
+
// Get HDG account of signer
|
|
49
|
+
const payerHdgAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, payer.publicKey);
|
|
50
|
+
// Derive the user referral account public key
|
|
51
|
+
const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
|
52
|
+
transaction.add(yield createReferralAccountInstruction(program, payer.publicKey, poolPosition, referralAccountPublicKey, referallStatePublicKey, hedgeMintPublicKey, payerHdgAssociatedTokenAccount.address, userReferralAccountPublicKey, overrideTime));
|
|
53
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
|
54
|
+
return referralAccountPublicKey;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.createReferralAccount = createReferralAccount;
|
|
58
|
+
function createReferralAccountInstruction(program, payerPublicKey, poolPositionPublicKey, referralAccountPublicKey, referralStatePublicKey, hedgeMintPublicKey, hdgAssociatedTokenAccountPublicKey, userReferralAccountPublicKey, overrideTime) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
61
|
+
return yield program.methods
|
|
62
|
+
.createReferralAccount(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override times
|
|
63
|
+
)
|
|
64
|
+
.accounts({
|
|
65
|
+
signer: payerPublicKey,
|
|
66
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
|
67
|
+
referralState: referralStatePublicKey,
|
|
68
|
+
referralAccount: referralAccountPublicKey,
|
|
69
|
+
userReferralAccount: userReferralAccountPublicKey,
|
|
70
|
+
poolPosition: poolPositionPublicKey,
|
|
71
|
+
hedgeMint: hedgeMintPublicKey,
|
|
72
|
+
hdgAta: hdgAssociatedTokenAccountPublicKey,
|
|
73
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
74
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
75
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
76
|
+
})
|
|
77
|
+
.instruction();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.createReferralAccountInstruction = createReferralAccountInstruction;
|
|
@@ -16,25 +16,25 @@ exports.createStakingPoolInstruction = exports.createStakingPool = 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 Errors_1 = require("../utils/Errors");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const Errors_1 = require("../utils/Errors");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
22
|
function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
const transaction = new web3_js_1.Transaction().add(yield createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
|
|
25
25
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
|
26
|
-
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
|
26
|
+
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
|
27
27
|
return poolPublickey;
|
|
28
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, Constants_1.getVaultSystemStatePublicKey)();
|
|
34
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
35
|
-
const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
|
36
|
-
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
|
|
37
|
-
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
|
|
33
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
34
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
35
|
+
const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
|
36
|
+
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, mintPublicKey);
|
|
37
|
+
const poolAssociatedUshTokenAccount = yield (0, Constants_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({
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
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.createUserReferralAccountInstruction = exports.createUserReferralAccount = 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 Errors_1 = require("../utils/Errors");
|
|
21
|
+
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
|
+
function createUserReferralAccount(program, provider, payer, referrer, overrideTime) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
// setup transaction
|
|
25
|
+
const transaction = new web3_js_1.Transaction();
|
|
26
|
+
const signers = [payer];
|
|
27
|
+
// Find referrer account
|
|
28
|
+
let referralAccountPublicKey = null;
|
|
29
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
30
|
+
if (typeof referrer === 'undefined') {
|
|
31
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
35
|
+
}
|
|
36
|
+
// Derive the user referral account public key
|
|
37
|
+
const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
|
38
|
+
transaction.add(yield createUserReferralAccountInstruction(program, payer.publicKey, referralAccountPublicKey, userReferralAccountPublicKey, overrideTime));
|
|
39
|
+
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
|
40
|
+
return userReferralAccountPublicKey;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.createUserReferralAccount = createUserReferralAccount;
|
|
44
|
+
function createUserReferralAccountInstruction(program, payerPublicKey, referralAccount, userReferralAccount, overrideTime) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
47
|
+
return yield program.methods
|
|
48
|
+
.createUserReferralAccount(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
49
|
+
)
|
|
50
|
+
.accounts({
|
|
51
|
+
signer: payerPublicKey,
|
|
52
|
+
userReferralAccount: userReferralAccount,
|
|
53
|
+
referralAccount: referralAccount,
|
|
54
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
55
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
56
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
57
|
+
})
|
|
58
|
+
.instruction();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.createUserReferralAccountInstruction = createUserReferralAccountInstruction;
|
|
@@ -23,22 +23,22 @@ const Errors_1 = require("../utils/Errors");
|
|
|
23
23
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
24
24
|
function createVault(program, provider, payer, collateralType, depositAmount, overrideTime) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
26
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
27
27
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
|
28
|
-
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
|
|
28
|
+
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(program.programId, salt);
|
|
29
29
|
const history = web3_js_1.Keypair.generate();
|
|
30
30
|
// Prep the user to get USH back out at some point
|
|
31
31
|
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
32
|
-
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
|
32
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
|
33
33
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
|
34
|
-
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
|
35
|
-
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
34
|
+
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
|
35
|
+
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
36
36
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
|
37
37
|
const transaction = new web3_js_1.Transaction();
|
|
38
38
|
const signers = [payer, history];
|
|
39
39
|
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
|
40
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
|
41
|
-
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
40
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
|
|
41
|
+
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
42
42
|
if (isWrappedSol) {
|
|
43
43
|
transaction.add(web3_js_1.SystemProgram.createAccount({
|
|
44
44
|
fromPubkey: payer.publicKey,
|
|
@@ -69,9 +69,9 @@ exports.createVault = createVault;
|
|
|
69
69
|
function buildCreateVaultTransaction(program, payerPublicKey, collateralType, depositAmount, overrideTime) {
|
|
70
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
71
|
console.log('HEDGE SDK: buildCreateVaultTransaction');
|
|
72
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
72
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
73
73
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
|
74
|
-
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
|
|
74
|
+
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(program.programId, salt);
|
|
75
75
|
const history = web3_js_1.Keypair.generate();
|
|
76
76
|
const { blockhash } = yield program.provider.connection.getLatestBlockhash();
|
|
77
77
|
const transaction = new web3_js_1.Transaction({
|
|
@@ -82,15 +82,15 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
|
|
|
82
82
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
|
83
83
|
console.log('Lookup getVaultTypeAccountPublicKey', collateralType);
|
|
84
84
|
// Lookup the vault type info
|
|
85
|
-
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
|
85
|
+
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
|
|
86
86
|
console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString());
|
|
87
87
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
|
88
88
|
console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo);
|
|
89
89
|
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
|
90
|
-
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
91
|
-
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
92
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
|
93
|
-
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
90
|
+
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
91
|
+
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
92
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
|
|
93
|
+
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
94
94
|
console.log('about to start building transaction');
|
|
95
95
|
// If wrapped SOL collateral, we convert the SOL to wSOL to use in the instruction
|
|
96
96
|
if (isWrappedSol) {
|
|
@@ -125,7 +125,7 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
|
|
|
125
125
|
exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
|
|
126
126
|
function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
|
|
127
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
128
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
129
129
|
return yield program.methods
|
|
130
130
|
.createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
|
131
131
|
)
|
|
@@ -16,32 +16,41 @@ exports.depositLiquidationPoolInstruction = exports.depositLiquidationPool = voi
|
|
|
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 Errors_1 = require("../utils/Errors");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const Errors_1 = require("../utils/Errors");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
|
-
function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime) {
|
|
22
|
+
function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime, 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
|
+
let referralAccountPublicKey = null;
|
|
27
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
28
|
+
if (typeof referrer === 'undefined') {
|
|
29
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
|
33
|
+
}
|
|
34
|
+
// Derive the user referral account public key
|
|
35
|
+
const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
|
|
26
36
|
const poolPosition = web3_js_1.Keypair.generate();
|
|
27
|
-
const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, new anchor_1.BN(depositAmount), overrideStartTime));
|
|
37
|
+
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));
|
|
28
38
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
|
|
29
39
|
return poolPosition.publicKey;
|
|
30
40
|
});
|
|
31
41
|
}
|
|
32
42
|
exports.depositLiquidationPool = depositLiquidationPool;
|
|
33
|
-
function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAccount, poolPositionPublicKey, depositAmount, overrideStartTime) {
|
|
43
|
+
function depositLiquidationPoolInstruction(program, payerPublicKey, vaultSystemStatePublicKey, payerUshAccount, poolPositionPublicKey, depositAmount, userReferralAccountPublicKey, referralAccountPublicKey, overrideStartTime) {
|
|
34
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
|
45
|
+
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
|
36
46
|
const liquidationPoolState = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
|
37
|
-
const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
|
38
|
-
const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
|
|
39
|
-
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
47
|
+
const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
|
48
|
+
const ushMint = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
40
49
|
return yield program.methods
|
|
41
50
|
.depositLiquidationPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
|
42
51
|
)
|
|
43
52
|
.accounts({
|
|
44
|
-
vaultSystemState:
|
|
53
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
|
45
54
|
poolState: liquidationPoolStatePublicKey,
|
|
46
55
|
poolUshAccount: poolUSHAccount,
|
|
47
56
|
poolEra: liquidationPoolState.currentEra,
|
|
@@ -49,6 +58,8 @@ function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAcco
|
|
|
49
58
|
ushMint: ushMint,
|
|
50
59
|
payer: payerPublicKey,
|
|
51
60
|
ownerUshAccount: payerUshAccount,
|
|
61
|
+
userReferralAccount: userReferralAccountPublicKey,
|
|
62
|
+
referralAccount: referralAccountPublicKey,
|
|
52
63
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
53
64
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
54
65
|
})
|
|
@@ -16,8 +16,8 @@ exports.depositStakingPoolInstruction = exports.depositStakingPool = 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 Errors_1 = require("../utils/Errors");
|
|
20
19
|
const Constants_1 = require("../Constants");
|
|
20
|
+
const Errors_1 = require("../utils/Errors");
|
|
21
21
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
22
22
|
function depositStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -30,10 +30,10 @@ function depositStakingPool(program, provider, payer, mintPublicKey, depositAmou
|
|
|
30
30
|
exports.depositStakingPool = depositStakingPool;
|
|
31
31
|
function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, depositAmount, overrideStartTime) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(stakedTokenMintPublicKey);
|
|
34
|
-
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, stakedTokenMintPublicKey);
|
|
35
|
-
const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
|
|
36
|
-
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
33
|
+
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
|
|
34
|
+
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
|
|
35
|
+
const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
|
|
36
|
+
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
37
37
|
return yield program.methods
|
|
38
38
|
.depositStakingPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
|
39
39
|
)
|
|
@@ -15,27 +15,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.depositVaultInstruction = exports.depositVault = void 0;
|
|
16
16
|
const anchor_1 = require("@project-serum/anchor");
|
|
17
17
|
const serum_1 = require("@project-serum/serum");
|
|
18
|
+
const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
|
|
18
19
|
const spl_token_1 = require("@solana/spl-token");
|
|
19
20
|
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
-
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
21
21
|
const Constants_1 = require("../Constants");
|
|
22
|
+
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
|
22
23
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
|
23
|
-
const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
|
|
24
24
|
function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
|
26
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
|
27
27
|
// Prep the user to get USH back out at some point
|
|
28
28
|
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
|
29
29
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
|
30
30
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
|
31
31
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
|
|
32
|
-
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
|
33
|
-
const vaultAssociatedCollateralAccountPublicKey = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
32
|
+
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
|
33
|
+
const vaultAssociatedCollateralAccountPublicKey = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
|
34
34
|
const history = web3_js_1.Keypair.generate();
|
|
35
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
|
35
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
|
36
36
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
|
37
|
-
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
|
38
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
37
|
+
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
|
|
38
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
|
39
39
|
const transaction = new web3_js_1.Transaction();
|
|
40
40
|
const signers = [payer, history];
|
|
41
41
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(depositAmount), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), false, false);
|
|
@@ -53,7 +53,9 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
|
53
53
|
}));
|
|
54
54
|
signers.push(wrappedSolAccount);
|
|
55
55
|
}
|
|
56
|
-
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()
|
|
56
|
+
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()
|
|
57
|
+
? wrappedSolAccount.publicKey
|
|
58
|
+
: payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(depositAmount), overrideTime));
|
|
57
59
|
if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
|
|
58
60
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
|
59
61
|
source: wrappedSolAccount.publicKey,
|