hedge-web3 0.1.9 → 0.1.13

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.
Files changed (32) hide show
  1. package/lib/index.js +67 -37
  2. package/lib/index.js.map +1 -1
  3. package/lib/types/src/Constants.d.ts +2 -2
  4. package/lib/types/src/instructions/createVault.d.ts +1 -1
  5. package/lib/types/src/instructions/createVault.d.ts.map +1 -1
  6. package/lib/types/src/instructions/depositVault.d.ts +1 -1
  7. package/lib/types/src/instructions/depositVault.d.ts.map +1 -1
  8. package/lib/types/src/instructions/liquidateVault.d.ts +2 -2
  9. package/lib/types/src/instructions/liquidateVault.d.ts.map +1 -1
  10. package/lib/types/src/instructions/redeemVault.d.ts +2 -2
  11. package/lib/types/src/instructions/redeemVault.d.ts.map +1 -1
  12. package/lib/types/src/instructions/refreshOraclePrice.d.ts +8 -2
  13. package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +1 -1
  14. package/lib/types/src/instructions/repayVault.d.ts.map +1 -1
  15. package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +1 -1
  16. package/lib/types/src/instructions/withdrawVault.d.ts +2 -2
  17. package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -1
  18. package/lib/types/src/state/VaultAccount.d.ts +0 -2
  19. package/lib/types/src/state/VaultAccount.d.ts.map +1 -1
  20. package/lib/types/tsconfig.base.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/src/Constants.ts +4 -4
  23. package/src/instructions/createVault.ts +7 -4
  24. package/src/instructions/depositVault.ts +7 -4
  25. package/src/instructions/liquidateVault.ts +8 -11
  26. package/src/instructions/loanVault.ts +3 -3
  27. package/src/instructions/redeemVault.ts +4 -7
  28. package/src/instructions/refreshOraclePrice.ts +31 -5
  29. package/src/instructions/repayVault.ts +4 -1
  30. package/src/instructions/withdrawStakingPool.ts +2 -0
  31. package/src/instructions/withdrawVault.ts +10 -13
  32. package/src/state/VaultAccount.ts +0 -4
@@ -42,6 +42,7 @@ export async function withdrawStakingPoolInstruction (
42
42
  const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
43
43
  const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
44
44
  const payerAssociatedUsdhAccount = await findAssociatedTokenAddress(payerPublicKey, usdhMintPublickey)
45
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey,hedgeMintPublickey)
45
46
 
46
47
  return program.instruction.withdrawStakingPool(
47
48
  new BN(overrideStartTime ?? Date.now() / 1000), // override current time
@@ -56,6 +57,7 @@ export async function withdrawStakingPoolInstruction (
56
57
  payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
57
58
  payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
58
59
  payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
60
+ communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
59
61
  hedgeMint: hedgeMintPublickey,
60
62
  stakedTokenMint: stakedTokenMintPublicKey,
61
63
  usdhMint: usdhMintPublickey,
@@ -1,15 +1,14 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, LAMPORTS_PER_SOL, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import { CHAINLINK_SOL_USD_PUBLICKEY, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
3
+ import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
+ import { getSolCollateralStateAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
5
5
 
6
6
  export async function withdrawVault (
7
7
  program: Program,
8
8
  provider: Provider,
9
9
  payer: Signer,
10
10
  vaultPublicKey: PublicKey,
11
- withdrawAmount: number,
12
- chainlinkOverridePrice?: number
11
+ withdrawAmount: number
13
12
  ): Promise<PublicKey> {
14
13
  const [usdhMintPublickey] = await getUsdhMintPublicKey()
15
14
  const USDH = new Token(
@@ -25,39 +24,37 @@ export async function withdrawVault (
25
24
  const history = Keypair.generate()
26
25
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey()
27
26
  const transaction = new Transaction().add(
28
- withdrawVaultInstruction(
27
+ await withdrawVaultInstruction(
29
28
  program,
30
29
  vaultSystemStatePublicKey,
31
30
  payer.publicKey,
32
31
  vaultPublicKey,
33
32
  history.publicKey,
34
- withdrawAmount,
35
- chainlinkOverridePrice
33
+ withdrawAmount
36
34
  )
37
35
  )
38
36
  await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
39
37
  return vaultPublicKey
40
38
  }
41
39
 
42
- export function withdrawVaultInstruction (
40
+ export async function withdrawVaultInstruction (
43
41
  program: Program,
44
42
  vaultSystemStatePublicKey: PublicKey,
45
43
  payerPublicKey: PublicKey,
46
44
  vaultPublickey: PublicKey,
47
45
  historyPublicKey: PublicKey,
48
- withdrawAmount: number,
49
- chainlinkOverridePrice?: number
50
- ): TransactionInstruction {
46
+ withdrawAmount: number
47
+ ): Promise<TransactionInstruction> {
48
+ const collateralStateAccount = await getSolCollateralStateAccountPublicKey()
51
49
  return program.instruction.withdrawVault(
52
50
  new BN(withdrawAmount),
53
- new BN(chainlinkOverridePrice ?? 200 * LAMPORTS_PER_SOL),
54
51
  {
55
52
  accounts: {
56
53
  vaultSystemState: vaultSystemStatePublicKey,
54
+ collateralStateAccount: collateralStateAccount,
57
55
  vaultAccount: vaultPublickey,
58
56
  history: historyPublicKey,
59
57
  vaultOwner: payerPublicKey,
60
- chainlinkFeedAccount: CHAINLINK_SOL_USD_PUBLICKEY,
61
58
  systemProgram: SystemProgram.programId
62
59
  },
63
60
  signers: []
@@ -21,9 +21,6 @@ export class VaultAccount {
21
21
  /** The minimum collateral ratio this vault must maintain to not be subject to liquidation. */
22
22
  minCollateralRatio: Decimal
23
23
 
24
- /** The SOL/USD price at which this vault is subject to liquidation */
25
- liquidationPrice: number
26
-
27
24
  /** Current State of the vautl ("Open", "Closed", "Liquidated") */
28
25
  vaultStatus: string
29
26
 
@@ -33,7 +30,6 @@ export class VaultAccount {
33
30
  this.debt = vault.debt.toNumber()
34
31
  this.deposited = vault.deposited.toNumber()
35
32
  this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio)
36
- this.liquidationPrice = vault.liquidationPrice.toNumber()
37
33
  this.vaultStatus = Object.keys(vault.vaultStatus)[0]
38
34
  }
39
35