hedge-web3 0.2.33 → 0.3.0
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 +2 -843
- 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/lib/Constants.js +27 -54
- 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 +1 -842
- 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 +20 -21
- package/lib/instructions/depositLiquidationPool.js +12 -13
- package/lib/instructions/depositStakingPool.js +8 -9
- package/lib/instructions/depositVault.js +10 -11
- package/lib/instructions/initHedgeFoundation.js +10 -11
- package/lib/instructions/initHedgeFoundationTokens.js +7 -8
- package/lib/instructions/liquidateVault.js +12 -19
- package/lib/instructions/loanVault.js +16 -23
- 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 -11
- package/lib/instructions/referralClaimFees.js +9 -10
- package/lib/instructions/refreshOraclePrice.js +9 -9
- 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 +8 -9
- package/lib/state/VaultAccount.js +22 -8
- 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 +1 -1
- package/package.json +9 -8
- package/src/{Constants.ts → HedgeConstants.ts} +13 -43
- package/src/idl/vault.ts +2342 -4024
- 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 +2 -2
- package/src/instructions/depositLiquidationPool.ts +2 -2
- package/src/instructions/depositStakingPool.ts +2 -2
- package/src/instructions/depositVault.ts +2 -2
- package/src/instructions/initHedgeFoundation.ts +2 -2
- package/src/instructions/initHedgeFoundationTokens.ts +2 -2
- package/src/instructions/liquidateVault.ts +29 -39
- package/src/instructions/loanVault.ts +23 -36
- 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 -2
- package/src/instructions/referralClaimFees.ts +11 -9
- package/src/instructions/refreshOraclePrice.ts +4 -4
- 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 +2 -2
- package/src/utils/Errors.ts +1 -1
- package/src/utils/getLinkedListAccounts.ts +1 -1
- 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
@@ -1,55 +0,0 @@
|
|
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.depositCompoundStakingPoolPositionInstruction = exports.depositCompoundStakingPoolPosition = 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 depositCompoundStakingPoolPosition(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
25
|
-
const poolPosition = yield (0, Constants_1.getCompoundPoolPositionAddress)(program.programId, poolPublickey, payer.publicKey);
|
26
|
-
const transaction = new web3_js_1.Transaction().add(yield depositCompoundStakingPoolPositionInstruction(program, payer.publicKey, poolPosition, mintPublicKey, new anchor_1.BN(depositAmount), overrideStartTime));
|
27
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
28
|
-
return poolPosition;
|
29
|
-
});
|
30
|
-
}
|
31
|
-
exports.depositCompoundStakingPoolPosition = depositCompoundStakingPoolPosition;
|
32
|
-
function depositCompoundStakingPoolPositionInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, depositAmount, overrideStartTime) {
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
34
|
-
const [poolPublickey] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
|
35
|
-
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
|
36
|
-
const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
|
37
|
-
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
38
|
-
return yield program.methods
|
39
|
-
.depositCompoundStakingPoolPosition(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
40
|
-
)
|
41
|
-
.accounts({
|
42
|
-
payer: payerPublicKey,
|
43
|
-
vaultSystemState: vaultSystemState,
|
44
|
-
pool: poolPublickey,
|
45
|
-
poolPosition: poolPositionPublicKey,
|
46
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
47
|
-
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
48
|
-
payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
|
49
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
50
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
51
|
-
})
|
52
|
-
.instruction();
|
53
|
-
});
|
54
|
-
}
|
55
|
-
exports.depositCompoundStakingPoolPositionInstruction = depositCompoundStakingPoolPositionInstruction;
|
@@ -1,64 +0,0 @@
|
|
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.depositRewardsToCompoundStakingPoolInstruction = exports.depositRewardsToCompoundStakingPool = 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 depositRewardsToCompoundStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
const history = web3_js_1.Keypair.generate();
|
25
|
-
const [poolPublickey] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
26
|
-
const [poolStakingPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
27
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
28
|
-
const stakingPoolAccountObject = yield program.account.stakingPool.fetch(poolStakingPublickey);
|
29
|
-
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublickey, stakingPoolAccountObject.compoundPoolDelegateWallet);
|
30
|
-
const transaction = new web3_js_1.Transaction().add(yield depositRewardsToCompoundStakingPoolInstruction(program, payer.publicKey, mintPublicKey, history.publicKey, new anchor_1.BN(depositAmount), overrideStartTime));
|
31
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]).catch(Errors_1.parseAnchorErrors);
|
32
|
-
return poolPublickey;
|
33
|
-
});
|
34
|
-
}
|
35
|
-
exports.depositRewardsToCompoundStakingPool = depositRewardsToCompoundStakingPool;
|
36
|
-
function depositRewardsToCompoundStakingPoolInstruction(program, payerPublicKey, mintPublicKey, historyPublicKey, amount, overrideStartTime) {
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
38
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
39
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
40
|
-
const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
41
|
-
const [poolStakingPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
42
|
-
const poolAssociatedHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, hedgeMintPublickey);
|
43
|
-
const payerAssociatedHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
|
44
|
-
return yield program.methods
|
45
|
-
.depositRewardsToCompoundPool(amount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
46
|
-
)
|
47
|
-
.accounts({
|
48
|
-
payer: payerPublicKey,
|
49
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
50
|
-
history: historyPublicKey,
|
51
|
-
compoundPool: poolPublickey,
|
52
|
-
pool: poolStakingPublickey,
|
53
|
-
stakedTokenMint: mintPublicKey,
|
54
|
-
hedgeMint: hedgeMintPublickey,
|
55
|
-
poolAssociatedHedgeAccount: poolAssociatedHedgeTokenAccount,
|
56
|
-
payerAssociatedHedgeAccount: payerAssociatedHedgeTokenAccount,
|
57
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
58
|
-
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
59
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
60
|
-
})
|
61
|
-
.instruction();
|
62
|
-
});
|
63
|
-
}
|
64
|
-
exports.depositRewardsToCompoundStakingPoolInstruction = depositRewardsToCompoundStakingPoolInstruction;
|
@@ -1,43 +0,0 @@
|
|
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.setCompoundPoolActiveInstruction = exports.setCompoundPoolActive = void 0;
|
16
|
-
const web3_js_1 = require("@solana/web3.js");
|
17
|
-
const Constants_1 = require("../Constants");
|
18
|
-
const Errors_1 = require("../utils/Errors");
|
19
|
-
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
20
|
-
function setCompoundPoolActive(program, provider, payer, mintPublicKey, setActive) {
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
22
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
23
|
-
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
24
|
-
const transaction = new web3_js_1.Transaction().add(yield setCompoundPoolActiveInstruction(program, vaultSystemStatePublicKey, payer.publicKey, poolPublickey, mintPublicKey, setActive));
|
25
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
26
|
-
return poolPublickey;
|
27
|
-
});
|
28
|
-
}
|
29
|
-
exports.setCompoundPoolActive = setCompoundPoolActive;
|
30
|
-
function setCompoundPoolActiveInstruction(program, vaultSystemStatePublicKey, payerPublicKey, poolPublicKey, stakedTokenMintPublicKey, setActive) {
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
32
|
-
return yield program.methods
|
33
|
-
.setCompoundPoolActive(setActive)
|
34
|
-
.accounts({
|
35
|
-
payer: payerPublicKey,
|
36
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
37
|
-
pool: poolPublicKey,
|
38
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
39
|
-
})
|
40
|
-
.instruction();
|
41
|
-
});
|
42
|
-
}
|
43
|
-
exports.setCompoundPoolActiveInstruction = setCompoundPoolActiveInstruction;
|
@@ -1,43 +0,0 @@
|
|
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.setDelegateWalletInstruction = exports.setDelegateWallet = void 0;
|
16
|
-
const web3_js_1 = require("@solana/web3.js");
|
17
|
-
const Constants_1 = require("../Constants");
|
18
|
-
const Errors_1 = require("../utils/Errors");
|
19
|
-
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
20
|
-
function setDelegateWallet(program, provider, payer, mintPublicKey, delegateWallet) {
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
22
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
23
|
-
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
|
24
|
-
const transaction = new web3_js_1.Transaction().add(yield setDelegateWalletInstruction(program, vaultSystemStatePublicKey, payer.publicKey, poolPublickey, mintPublicKey, delegateWallet));
|
25
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
26
|
-
return delegateWallet;
|
27
|
-
});
|
28
|
-
}
|
29
|
-
exports.setDelegateWallet = setDelegateWallet;
|
30
|
-
function setDelegateWalletInstruction(program, vaultSystemStatePublicKey, payerPublicKey, poolPublicKey, stakedTokenMintPublicKey, delegateWallet) {
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
32
|
-
return yield program.methods
|
33
|
-
.setDelegateWallet(delegateWallet)
|
34
|
-
.accounts({
|
35
|
-
payer: payerPublicKey,
|
36
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
37
|
-
pool: poolPublicKey,
|
38
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
39
|
-
})
|
40
|
-
.instruction();
|
41
|
-
});
|
42
|
-
}
|
43
|
-
exports.setDelegateWalletInstruction = setDelegateWalletInstruction;
|
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.setVaultTypeStatusInstruction = exports.setVaultTypeStatus = void 0;
|
13
|
-
const web3_js_1 = require("@solana/web3.js");
|
14
|
-
const Constants_1 = require("../Constants");
|
15
|
-
const Errors_1 = require("../utils/Errors");
|
16
|
-
function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecated) {
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
18
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
19
|
-
const transaction = new web3_js_1.Transaction().add(yield setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, deprecated));
|
20
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider === null || provider === void 0 ? void 0 : provider.opts).catch(Errors_1.parseAnchorErrors);
|
21
|
-
return vaultSystemStatePublicKey;
|
22
|
-
});
|
23
|
-
}
|
24
|
-
exports.setVaultTypeStatus = setVaultTypeStatus;
|
25
|
-
function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
27
|
-
const ix = program.instruction.setVaultTypeStatus(deprecated, {
|
28
|
-
accounts: {
|
29
|
-
payer: payerPublicKey,
|
30
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
31
|
-
vaultType: vaultTypeAccount,
|
32
|
-
},
|
33
|
-
signers: []
|
34
|
-
});
|
35
|
-
return ix;
|
36
|
-
});
|
37
|
-
}
|
38
|
-
exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
|
@@ -1,64 +0,0 @@
|
|
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.withdrawCompoundStakingPoolPositionInstruction = exports.withdrawCompoundStakingPoolPosition = 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 withdrawCompoundStakingPoolPosition(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, claimAmount, overrideStartTime) {
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
24
|
-
const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
|
25
|
-
const poolPosition = yield (0, Constants_1.getCompoundPoolPositionAddress)(program.programId, poolPublickey, payer.publicKey);
|
26
|
-
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, stakedTokenMintPublicKey, payer.publicKey);
|
27
|
-
const transaction = new web3_js_1.Transaction().add(yield withdrawCompoundStakingPoolPositionInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, new anchor_1.BN(claimAmount), overrideStartTime));
|
28
|
-
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
29
|
-
return payerAssociatedTokenAccount.address;
|
30
|
-
});
|
31
|
-
}
|
32
|
-
exports.withdrawCompoundStakingPoolPosition = withdrawCompoundStakingPoolPosition;
|
33
|
-
function withdrawCompoundStakingPoolPositionInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, claimAmount, overrideStartTime) {
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
35
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
|
36
|
-
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
|
37
|
-
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
|
38
|
-
const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
|
39
|
-
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
|
40
|
-
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, ushMintPublickey);
|
41
|
-
const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
|
42
|
-
const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
|
43
|
-
const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
|
44
|
-
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
|
45
|
-
return yield program.methods
|
46
|
-
.withdrawCompoundStakingPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
|
47
|
-
claimAmount //amount to be claimed
|
48
|
-
)
|
49
|
-
.accounts({
|
50
|
-
payer: payerPublicKey,
|
51
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
52
|
-
pool: poolPublickey,
|
53
|
-
poolPosition: poolPositionPublicKey,
|
54
|
-
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
55
|
-
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
56
|
-
hedgeMint: hedgeMintPublickey,
|
57
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
58
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
59
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
60
|
-
})
|
61
|
-
.instruction();
|
62
|
-
});
|
63
|
-
}
|
64
|
-
exports.withdrawCompoundStakingPoolPositionInstruction = withdrawCompoundStakingPoolPositionInstruction;
|
package/lib/utils/Sender.js
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.sendAndConfirmWithDebug = void 0;
|
13
|
-
function sendAndConfirmWithDebug(connection, transaction, signers) {
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
15
|
-
return connection
|
16
|
-
.sendTransaction(transaction, signers)
|
17
|
-
.then((signature) => {
|
18
|
-
return connection
|
19
|
-
.confirmTransaction(signature)
|
20
|
-
.then((signatureContext) => {
|
21
|
-
return signature;
|
22
|
-
})
|
23
|
-
.catch((error) => {
|
24
|
-
console.log('There was an error confirming the transaction', error);
|
25
|
-
});
|
26
|
-
})
|
27
|
-
.catch((error) => {
|
28
|
-
console.log('There was an error sending the transaction', error);
|
29
|
-
});
|
30
|
-
});
|
31
|
-
}
|
32
|
-
exports.sendAndConfirmWithDebug = sendAndConfirmWithDebug;
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import {
|
5
|
-
findAssociatedTokenAddress,
|
6
|
-
getPoolPublicKeyForMint,
|
7
|
-
getVaultSystemStatePublicKey,
|
8
|
-
getVaultTypeAccountPublicKey,
|
9
|
-
} from '../Constants'
|
10
|
-
import { Vault } from '../idl/vault'
|
11
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
12
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
13
|
-
|
14
|
-
export async function adminWithdrawCollateral(
|
15
|
-
program: Program<Vault>,
|
16
|
-
provider: Provider,
|
17
|
-
payer: Signer,
|
18
|
-
mintPublicKey: PublicKey,
|
19
|
-
collateralType: string
|
20
|
-
): Promise<PublicKey> {
|
21
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
|
22
|
-
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
|
23
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
24
|
-
const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
|
25
|
-
|
26
|
-
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
27
|
-
provider.connection,
|
28
|
-
payer,
|
29
|
-
vaultTypeAccountInfo.collateralMint,
|
30
|
-
stakingPoolAccountObject.compoundPoolDelegateWallet
|
31
|
-
)
|
32
|
-
|
33
|
-
const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
|
34
|
-
program.programId,
|
35
|
-
poolPublickey,
|
36
|
-
vaultTypeAccountInfo.collateralMint
|
37
|
-
)
|
38
|
-
|
39
|
-
const transaction = new Transaction().add(
|
40
|
-
await adminWithdrawCollateralInstruction(program, payer.publicKey, mintPublicKey, vaultTypeAccountPublicKey)
|
41
|
-
)
|
42
|
-
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
43
|
-
|
44
|
-
return poolPublickey
|
45
|
-
}
|
46
|
-
|
47
|
-
export async function adminWithdrawCollateralInstruction(
|
48
|
-
program: Program<Vault>,
|
49
|
-
payerPublicKey: PublicKey,
|
50
|
-
stakedTokenMintPublicKey: PublicKey,
|
51
|
-
vaultTypeAccountPublicKey: PublicKey
|
52
|
-
): Promise<TransactionInstruction> {
|
53
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
|
54
|
-
|
55
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
56
|
-
const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
|
57
|
-
|
58
|
-
const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
|
59
|
-
program.programId,
|
60
|
-
poolPublickey,
|
61
|
-
vaultTypeAccountInfo.collateralMint
|
62
|
-
)
|
63
|
-
|
64
|
-
const delegateAssociatedTokenAccount = await findAssociatedTokenAddress(
|
65
|
-
program.programId,
|
66
|
-
stakingPoolAccountObject.compoundPoolDelegateWallet,
|
67
|
-
vaultTypeAccountInfo.collateralMint
|
68
|
-
)
|
69
|
-
|
70
|
-
const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
|
71
|
-
|
72
|
-
return await program.methods
|
73
|
-
.adminWithdrawColAta()
|
74
|
-
.accounts({
|
75
|
-
payer: payerPublicKey,
|
76
|
-
vaultSystemState: vaultSystemState,
|
77
|
-
pool: poolPublickey,
|
78
|
-
vaultTypeAccount: vaultTypeAccountPublicKey,
|
79
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
80
|
-
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
81
|
-
delegateAssociatedColAccount: delegateAssociatedTokenAccount,
|
82
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
83
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
84
|
-
systemProgram: SystemProgram.programId,
|
85
|
-
})
|
86
|
-
.instruction()
|
87
|
-
}
|
@@ -1,78 +0,0 @@
|
|
1
|
-
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import {
|
5
|
-
findAssociatedTokenAddress,
|
6
|
-
getPoolPublicKeyForMint,
|
7
|
-
getUshMintPublicKey,
|
8
|
-
getVaultSystemStatePublicKey,
|
9
|
-
} from '../Constants'
|
10
|
-
import { Vault } from '../idl/vault'
|
11
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
12
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
13
|
-
|
14
|
-
export async function adminWithdrawUsh(
|
15
|
-
program: Program<Vault>,
|
16
|
-
provider: Provider,
|
17
|
-
payer: Signer,
|
18
|
-
mintPublicKey: PublicKey
|
19
|
-
): Promise<PublicKey> {
|
20
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
|
21
|
-
|
22
|
-
const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
|
23
|
-
|
24
|
-
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
25
|
-
|
26
|
-
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
27
|
-
provider.connection,
|
28
|
-
payer,
|
29
|
-
ushMintPublickey,
|
30
|
-
stakingPoolAccountObject.compoundPoolDelegateWallet
|
31
|
-
)
|
32
|
-
|
33
|
-
const transaction = new Transaction().add(
|
34
|
-
await adminWithdrawUshInstruction(program, payer.publicKey, mintPublicKey, poolPublickey)
|
35
|
-
)
|
36
|
-
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
37
|
-
return poolPublickey
|
38
|
-
}
|
39
|
-
|
40
|
-
export async function adminWithdrawUshInstruction(
|
41
|
-
program: Program<Vault>,
|
42
|
-
payerPublicKey: PublicKey,
|
43
|
-
stakedTokenMintPublicKey: PublicKey,
|
44
|
-
poolPublickey: PublicKey
|
45
|
-
): Promise<TransactionInstruction> {
|
46
|
-
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
47
|
-
const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
|
48
|
-
|
49
|
-
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
|
50
|
-
program.programId,
|
51
|
-
poolPublickey,
|
52
|
-
ushMintPublickey
|
53
|
-
)
|
54
|
-
|
55
|
-
const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
|
56
|
-
|
57
|
-
const delegateWalletAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
|
58
|
-
program.programId,
|
59
|
-
stakingPoolAccountObject.compoundPoolDelegateWallet,
|
60
|
-
ushMintPublickey
|
61
|
-
)
|
62
|
-
|
63
|
-
return await program.methods
|
64
|
-
.adminWithdrawUshAta()
|
65
|
-
.accounts({
|
66
|
-
payer: payerPublicKey,
|
67
|
-
vaultSystemState: vaultSystemState,
|
68
|
-
pool: poolPublickey,
|
69
|
-
ushMint: ushMintPublickey,
|
70
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
71
|
-
poolAssociatedTokenAccount: poolAssociatedStakedTokenAccount,
|
72
|
-
delegateAssociatedUshAccount: delegateWalletAssociatedStakedTokenAccount,
|
73
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
74
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
75
|
-
systemProgram: SystemProgram.programId,
|
76
|
-
})
|
77
|
-
.instruction()
|
78
|
-
}
|
@@ -1,119 +0,0 @@
|
|
1
|
-
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import {
|
5
|
-
getCompoundPoolPublicKeyForMint,
|
6
|
-
getHedgeMintPublicKey,
|
7
|
-
getReferralAccountPublicKey,
|
8
|
-
getReferralStatePublicKey,
|
9
|
-
getUserReferralAccountPublicKey,
|
10
|
-
getVaultSystemStatePublicKey,
|
11
|
-
} from '../Constants'
|
12
|
-
|
13
|
-
import { Vault } from '../idl/vault'
|
14
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
15
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
16
|
-
|
17
|
-
/** @type {Function} - Creates a new referral account.
|
18
|
-
* This checks the user has enough HDG in their wallet or staked and
|
19
|
-
* then allows them to create a referral account. If they meet the PSM referral threshold,
|
20
|
-
* they will be eligible for PSM cut.
|
21
|
-
* Params:
|
22
|
-
* - program: Program<Vault> : The program instance of Hedge Vault program
|
23
|
-
* - provider: Provider : Current connection
|
24
|
-
* - payer: Signer : who we are creating the referral account for
|
25
|
-
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
26
|
-
* - referrer: PublicKey
|
27
|
-
* - overrideTime?: number
|
28
|
-
*/
|
29
|
-
export async function compoundCreateReferralAccount(
|
30
|
-
program: Program<Vault>,
|
31
|
-
provider: Provider,
|
32
|
-
payer: Signer,
|
33
|
-
poolPosition: PublicKey,
|
34
|
-
stakedTokenMintPublicKey: PublicKey,
|
35
|
-
overrideTime?: number
|
36
|
-
): Promise<PublicKey> {
|
37
|
-
// setup transaction
|
38
|
-
const transaction = new Transaction()
|
39
|
-
const signers = [payer]
|
40
|
-
const referrer = payer.publicKey
|
41
|
-
|
42
|
-
// Setup public keys
|
43
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
44
|
-
|
45
|
-
// Find referral account
|
46
|
-
let referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
47
|
-
|
48
|
-
// Get the referral state PDA
|
49
|
-
const referallStatePublicKey = await getReferralStatePublicKey(program.programId)
|
50
|
-
|
51
|
-
// Get HDG mint public key
|
52
|
-
const hedgeMintPublicKey = await getHedgeMintPublicKey(program.programId)
|
53
|
-
|
54
|
-
// Get HDG account of signer
|
55
|
-
const payerHdgAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
56
|
-
provider.connection,
|
57
|
-
payer,
|
58
|
-
hedgeMintPublicKey,
|
59
|
-
payer.publicKey
|
60
|
-
)
|
61
|
-
|
62
|
-
// Derive the user referral account public key
|
63
|
-
const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
|
64
|
-
|
65
|
-
transaction.add(
|
66
|
-
await compoundCreateReferralAccountInstruction(
|
67
|
-
program,
|
68
|
-
payer.publicKey,
|
69
|
-
poolPosition,
|
70
|
-
stakedTokenMintPublicKey,
|
71
|
-
referralAccountPublicKey,
|
72
|
-
referallStatePublicKey,
|
73
|
-
hedgeMintPublicKey,
|
74
|
-
payerHdgAssociatedTokenAccount.address,
|
75
|
-
userReferralAccountPublicKey,
|
76
|
-
overrideTime
|
77
|
-
)
|
78
|
-
)
|
79
|
-
|
80
|
-
await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
|
81
|
-
return referralAccountPublicKey
|
82
|
-
}
|
83
|
-
|
84
|
-
export async function compoundCreateReferralAccountInstruction(
|
85
|
-
program: Program<Vault>,
|
86
|
-
payerPublicKey: PublicKey,
|
87
|
-
poolPositionPublicKey: PublicKey,
|
88
|
-
stakedTokenMintPublicKey: PublicKey,
|
89
|
-
referralAccountPublicKey: PublicKey,
|
90
|
-
referralStatePublicKey: PublicKey,
|
91
|
-
hedgeMintPublicKey: PublicKey,
|
92
|
-
hdgAssociatedTokenAccountPublicKey: PublicKey,
|
93
|
-
userReferralAccountPublicKey: PublicKey,
|
94
|
-
overrideTime?: number
|
95
|
-
): Promise<TransactionInstruction> {
|
96
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
97
|
-
const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
|
98
|
-
|
99
|
-
return await program.methods
|
100
|
-
.compoundCreateReferralAccount(
|
101
|
-
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override times
|
102
|
-
)
|
103
|
-
.accounts({
|
104
|
-
signer: payerPublicKey,
|
105
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
106
|
-
referralState: referralStatePublicKey,
|
107
|
-
referralAccount: referralAccountPublicKey,
|
108
|
-
userReferralAccount: userReferralAccountPublicKey,
|
109
|
-
poolPosition: poolPositionPublicKey,
|
110
|
-
pool: poolPublickey,
|
111
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
112
|
-
hedgeMint: hedgeMintPublicKey,
|
113
|
-
hdgAta: hdgAssociatedTokenAccountPublicKey,
|
114
|
-
systemProgram: SystemProgram.programId,
|
115
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
116
|
-
rent: SYSVAR_RENT_PUBKEY,
|
117
|
-
})
|
118
|
-
.instruction()
|
119
|
-
}
|