hedge-web3 0.1.18 → 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/Constants.d.ts +2 -1
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/lib/Constants.js +9 -2
- package/lib/instructions/closeLiquidationPoolPosition.js +10 -6
- package/lib/instructions/createStakingPool.js +1 -0
- package/lib/state/LiquidationPosition.js +2 -1
- package/package.json +1 -1
- package/src/Constants.ts +5 -1
- package/src/instructions/closeLiquidationPoolPosition.ts +10 -13
- package/src/instructions/createStakingPool.ts +1 -0
- package/src/state/LiquidationPosition.ts +2 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
2
|
-
export declare const HEDGE_PROGRAM_ID = "
|
2
|
+
export declare const HEDGE_PROGRAM_ID = "h8i3RfCeswxUSEwXCi5hjnvMfcdY6ZGr44dLKEKL8b3";
|
3
3
|
export declare const HEDGE_PROGRAM_PUBLICKEY: PublicKey;
|
4
4
|
export declare const CHAINLINK_SOL_USD_ID = "FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf";
|
5
5
|
export declare const CHAINLINK_SOL_USD_PUBLICKEY: PublicKey;
|
@@ -10,5 +10,6 @@ export declare function getVaultSystemStatePublicKey(): Promise<PublicKey>;
|
|
10
10
|
export declare function getHedgeMintPublicKey(): Promise<PublicKey>;
|
11
11
|
export declare function getPoolPublicKeyForMint(mintPublicKey: PublicKey): Promise<[PublicKey, number, string]>;
|
12
12
|
export declare function getVaultTypeAccountPublicKey(collateralType: string): Promise<PublicKey>;
|
13
|
+
export declare function getVaultTypeOracleAccountPublicKey(collateralType: string): Promise<PublicKey>;
|
13
14
|
export declare function findVaultAddress(vaultSalt: string): Promise<PublicKey>;
|
14
15
|
export declare function findAssociatedTokenAddress(walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor';
|
2
2
|
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
3
|
export declare function closeLiquidationPoolPosition(program: Program, provider: Provider, poolPosition: PublicKey, payer: Signer, overrideStartTime?: number): Promise<PublicKey>;
|
4
|
-
export declare function closeLiquidationPoolPositionInstruction(program: Program,
|
4
|
+
export declare function closeLiquidationPoolPositionInstruction(program: Program, poolEra: PublicKey, poolPosition: PublicKey, payerPublicKey: PublicKey, payerUsdhAccount: PublicKey, payerAssociatedHedgeAccount: PublicKey, communityAssociatedHedgeTokenAccount: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
|
package/lib/Constants.js
CHANGED
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getVaultSystemStatePublicKey = exports.getUsdhMintPublicKey = exports.getLiquidationPoolUsdhAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = exports.HEDGE_PROGRAM_PUBLICKEY = exports.HEDGE_PROGRAM_ID = void 0;
|
12
|
+
exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeOracleAccountPublicKey = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getVaultSystemStatePublicKey = exports.getUsdhMintPublicKey = exports.getLiquidationPoolUsdhAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = exports.HEDGE_PROGRAM_PUBLICKEY = exports.HEDGE_PROGRAM_ID = void 0;
|
13
13
|
const spl_token_1 = require("@solana/spl-token");
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
15
|
-
exports.HEDGE_PROGRAM_ID = '
|
15
|
+
exports.HEDGE_PROGRAM_ID = 'h8i3RfCeswxUSEwXCi5hjnvMfcdY6ZGr44dLKEKL8b3';
|
16
16
|
exports.HEDGE_PROGRAM_PUBLICKEY = new web3_js_1.PublicKey(exports.HEDGE_PROGRAM_ID);
|
17
17
|
exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
|
18
18
|
exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
|
@@ -67,6 +67,13 @@ function getVaultTypeAccountPublicKey(collateralType) {
|
|
67
67
|
});
|
68
68
|
}
|
69
69
|
exports.getVaultTypeAccountPublicKey = getVaultTypeAccountPublicKey;
|
70
|
+
function getVaultTypeOracleAccountPublicKey(collateralType) {
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
72
|
+
const [vaultTypeOracleAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
73
|
+
return vaultTypeOracleAccount;
|
74
|
+
});
|
75
|
+
}
|
76
|
+
exports.getVaultTypeOracleAccountPublicKey = getVaultTypeOracleAccountPublicKey;
|
70
77
|
function findVaultAddress(vaultSalt) {
|
71
78
|
return __awaiter(this, void 0, void 0, function* () {
|
72
79
|
const [vaultAddress] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -19,26 +19,29 @@ function closeLiquidationPoolPosition(program, provider, poolPosition, payer, ov
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
20
|
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
21
21
|
const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
|
22
|
-
const
|
22
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
23
23
|
const liquidationPositionAccount = yield program.account.liquidationPosition.fetch(poolPosition);
|
24
24
|
const poolEra = liquidationPositionAccount.era;
|
25
|
-
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
26
|
-
const poolUsdhAccount = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
|
27
25
|
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
28
26
|
const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
|
29
27
|
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
|
30
|
-
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program,
|
28
|
+
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUsdhAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
|
31
29
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts).catch(Errors_1.parseAnchorErrors);
|
32
30
|
return poolPosition;
|
33
31
|
});
|
34
32
|
}
|
35
33
|
exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
|
36
|
-
function closeLiquidationPoolPositionInstruction(program,
|
34
|
+
function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUsdhAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
|
37
35
|
return __awaiter(this, void 0, void 0, function* () {
|
36
|
+
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
37
|
+
const usdhMint = yield (0, Constants_1.getUsdhMintPublicKey)();
|
38
|
+
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
39
|
+
const poolUsdhAccount = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
|
40
|
+
const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
38
41
|
return program.instruction.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
39
42
|
{
|
40
43
|
accounts: {
|
41
|
-
vaultSystemState:
|
44
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
42
45
|
poolState: poolState,
|
43
46
|
poolEra: poolEra,
|
44
47
|
poolPosition: poolPosition,
|
@@ -46,6 +49,7 @@ function closeLiquidationPoolPositionInstruction(program, vaultSystemState, pool
|
|
46
49
|
payer: payerPublicKey,
|
47
50
|
ownerUsdhAccount: payerUsdhAccount,
|
48
51
|
hedgeMint: hedgeMint,
|
52
|
+
usdhMint: usdhMint,
|
49
53
|
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
50
54
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
51
55
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -26,6 +26,7 @@ function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensT
|
|
26
26
|
exports.createStakingPool = createStakingPool;
|
27
27
|
function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
|
+
console.log("createStakingPoolInstruction program ID", program.programId.toString());
|
29
30
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
30
31
|
const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
|
31
32
|
const [poolPublickey, poolBump, poolSeedPhrase] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
@@ -20,7 +20,8 @@ class LiquidationPosition {
|
|
20
20
|
this.sumSnapshotsEntry = poolPositionInfo.sumSnapshotsEntry.map((sum) => { return (0, HedgeDecimal_1.DecimalFromU128)(sum); });
|
21
21
|
this.sumSnapshotsClosed = poolPositionInfo.sumSnapshotsClosed.map((sum) => { return (0, HedgeDecimal_1.DecimalFromU128)(sum); });
|
22
22
|
this.hedgeRewardsSnapshot = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.hedgeRewardsSnapshotAccum);
|
23
|
-
this.open = poolPositionInfo.state
|
23
|
+
this.open = poolPositionInfo.state === 1;
|
24
|
+
console.log("poolPositionInfo.state, poolPositionInfo.state");
|
24
25
|
}
|
25
26
|
getUsdhAvailable(era) {
|
26
27
|
return (era.product.div(this.productSnapshotEntry)).mul(new decimal_js_1.default(this.deposit));
|
package/package.json
CHANGED
package/src/Constants.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
2
2
|
import { PublicKey } from '@solana/web3.js'
|
3
3
|
|
4
|
-
export const HEDGE_PROGRAM_ID = '
|
4
|
+
export const HEDGE_PROGRAM_ID = 'h8i3RfCeswxUSEwXCi5hjnvMfcdY6ZGr44dLKEKL8b3'
|
5
5
|
export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
|
6
6
|
|
7
7
|
export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
|
@@ -43,6 +43,10 @@ export async function getVaultTypeAccountPublicKey (collateralType: string): Pro
|
|
43
43
|
const [vaultTypeAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY)
|
44
44
|
return vaultTypeAccount
|
45
45
|
}
|
46
|
+
export async function getVaultTypeOracleAccountPublicKey (collateralType: string): Promise<PublicKey> {
|
47
|
+
const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY)
|
48
|
+
return vaultTypeOracleAccount
|
49
|
+
}
|
46
50
|
export async function findVaultAddress (vaultSalt: string): Promise<PublicKey> {
|
47
51
|
const [vaultAddress] = await PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], HEDGE_PROGRAM_PUBLICKEY)
|
48
52
|
return vaultAddress
|
@@ -13,13 +13,10 @@ export async function closeLiquidationPoolPosition (
|
|
13
13
|
): Promise<PublicKey> {
|
14
14
|
const usdhMintPublickey = await getUsdhMintPublicKey()
|
15
15
|
const payerUsdhAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
|
16
|
-
|
17
|
-
const poolState = await getLiquidationPoolStatePublicKey()
|
16
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
18
17
|
const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition)
|
19
18
|
const poolEra = liquidationPositionAccount.era
|
20
19
|
|
21
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
22
|
-
const poolUsdhAccount = await getLiquidationPoolUsdhAccountPublicKey()
|
23
20
|
const hedgeMint = await getHedgeMintPublicKey()
|
24
21
|
const payerAssociatedHedgeAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, hedgeMint, payer.publicKey)
|
25
22
|
const communityAssociatedHedgeTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true)
|
@@ -27,14 +24,10 @@ export async function closeLiquidationPoolPosition (
|
|
27
24
|
const transaction = new Transaction().add(
|
28
25
|
await closeLiquidationPoolPositionInstruction(
|
29
26
|
program,
|
30
|
-
vaultSystemStatePublicKey,
|
31
|
-
poolState,
|
32
27
|
poolEra,
|
33
28
|
poolPosition,
|
34
|
-
poolUsdhAccount,
|
35
29
|
payer.publicKey,
|
36
30
|
payerUsdhAccount.address,
|
37
|
-
hedgeMint,
|
38
31
|
payerAssociatedHedgeAccount.address,
|
39
32
|
communityAssociatedHedgeTokenAccount.address,
|
40
33
|
overrideStartTime
|
@@ -46,23 +39,26 @@ export async function closeLiquidationPoolPosition (
|
|
46
39
|
|
47
40
|
export async function closeLiquidationPoolPositionInstruction (
|
48
41
|
program: Program,
|
49
|
-
vaultSystemState: PublicKey,
|
50
|
-
poolState: PublicKey,
|
51
42
|
poolEra: PublicKey,
|
52
43
|
poolPosition: PublicKey,
|
53
|
-
poolUsdhAccount: PublicKey,
|
54
44
|
payerPublicKey: PublicKey,
|
55
45
|
payerUsdhAccount: PublicKey,
|
56
|
-
hedgeMint: PublicKey,
|
57
46
|
payerAssociatedHedgeAccount: PublicKey,
|
58
47
|
communityAssociatedHedgeTokenAccount: PublicKey,
|
59
48
|
overrideStartTime?: number
|
60
49
|
): Promise<TransactionInstruction> {
|
50
|
+
|
51
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
52
|
+
const usdhMint = await getUsdhMintPublicKey()
|
53
|
+
const hedgeMint = await getHedgeMintPublicKey()
|
54
|
+
const poolUsdhAccount = await getLiquidationPoolUsdhAccountPublicKey()
|
55
|
+
const poolState = await getLiquidationPoolStatePublicKey()
|
56
|
+
|
61
57
|
return program.instruction.closeLiquidationPoolPosition(
|
62
58
|
new BN(overrideStartTime ?? Date.now() / 1000), // override current time
|
63
59
|
{
|
64
60
|
accounts: {
|
65
|
-
vaultSystemState:
|
61
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
66
62
|
poolState: poolState,
|
67
63
|
poolEra: poolEra,
|
68
64
|
poolPosition: poolPosition,
|
@@ -70,6 +66,7 @@ export async function closeLiquidationPoolPositionInstruction (
|
|
70
66
|
payer: payerPublicKey,
|
71
67
|
ownerUsdhAccount: payerUsdhAccount,
|
72
68
|
hedgeMint: hedgeMint,
|
69
|
+
usdhMint: usdhMint,
|
73
70
|
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
74
71
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
75
72
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -33,6 +33,7 @@ export async function createStakingPoolInstruction (
|
|
33
33
|
hedgeTokensToBeMinted: number,
|
34
34
|
overrideStartTime?: number
|
35
35
|
): Promise<TransactionInstruction> {
|
36
|
+
console.log("createStakingPoolInstruction program ID", program.programId.toString())
|
36
37
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
37
38
|
const usdhMintPublickey = await getUsdhMintPublicKey()
|
38
39
|
const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey)
|
@@ -36,7 +36,8 @@ export class LiquidationPosition {
|
|
36
36
|
this.sumSnapshotsEntry = poolPositionInfo.sumSnapshotsEntry.map((sum: any) => { return DecimalFromU128(sum) })
|
37
37
|
this.sumSnapshotsClosed = poolPositionInfo.sumSnapshotsClosed.map((sum: any) => { return DecimalFromU128(sum) })
|
38
38
|
this.hedgeRewardsSnapshot = DecimalFromU128(poolPositionInfo.hedgeRewardsSnapshotAccum)
|
39
|
-
this.open = poolPositionInfo.state
|
39
|
+
this.open = poolPositionInfo.state === 1
|
40
|
+
console.log("poolPositionInfo.state, poolPositionInfo.state")
|
40
41
|
}
|
41
42
|
|
42
43
|
public getUsdhAvailable (era: LiquidationPoolEra): Decimal {
|