hedge-web3 0.1.19 → 0.1.20

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.
@@ -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, vaultSystemState: PublicKey, poolState: PublicKey, poolEra: PublicKey, poolPosition: PublicKey, poolUsdhAccount: PublicKey, payerPublicKey: PublicKey, payerUsdhAccount: PublicKey, hedgeMint: PublicKey, payerAssociatedHedgeAccount: PublicKey, communityAssociatedHedgeTokenAccount: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
4
+ export declare function closeLiquidationPoolPositionInstruction(program: Program, poolEra: PublicKey, poolPosition: PublicKey, payerPublicKey: PublicKey, payerUsdhAccount: PublicKey, payerAssociatedHedgeAccount: PublicKey, communityAssociatedHedgeTokenAccount: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -19,26 +19,28 @@ 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 poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
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, vaultSystemStatePublicKey, poolState, poolEra, poolPosition, poolUsdhAccount, payer.publicKey, payerUsdhAccount.address, hedgeMint, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
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, vaultSystemState, poolState, poolEra, poolPosition, poolUsdhAccount, payerPublicKey, payerUsdhAccount, hedgeMint, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
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 hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
38
+ const poolUsdhAccount = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
39
+ const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
38
40
  return program.instruction.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
39
41
  {
40
42
  accounts: {
41
- vaultSystemState: vaultSystemState,
43
+ vaultSystemState: vaultSystemStatePublicKey,
42
44
  poolState: poolState,
43
45
  poolEra: poolEra,
44
46
  poolPosition: poolPosition,
@@ -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.open !== undefined;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -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,25 @@ 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 hedgeMint = await getHedgeMintPublicKey()
53
+ const poolUsdhAccount = await getLiquidationPoolUsdhAccountPublicKey()
54
+ const poolState = await getLiquidationPoolStatePublicKey()
55
+
61
56
  return program.instruction.closeLiquidationPoolPosition(
62
57
  new BN(overrideStartTime ?? Date.now() / 1000), // override current time
63
58
  {
64
59
  accounts: {
65
- vaultSystemState: vaultSystemState,
60
+ vaultSystemState: vaultSystemStatePublicKey,
66
61
  poolState: poolState,
67
62
  poolEra: poolEra,
68
63
  poolPosition: poolPosition,
@@ -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.open !== undefined
39
+ this.open = poolPositionInfo.state === 1
40
+ console.log("poolPositionInfo.state, poolPositionInfo.state")
40
41
  }
41
42
 
42
43
  public getUsdhAvailable (era: LiquidationPoolEra): Decimal {