hedge-web3 0.2.24 → 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.
Files changed (70) hide show
  1. package/declarations/Constants.d.ts +13 -15
  2. package/declarations/idl/vault.d.ts +36 -0
  3. package/declarations/instructions/createReferralAccount.d.ts +1 -1
  4. package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
  5. package/declarations/instructions/referralClaimFees.d.ts +1 -1
  6. package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
  7. package/lib/Constants.js +28 -34
  8. package/lib/idl/vault.js +36 -0
  9. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  10. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  11. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  12. package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
  13. package/lib/instructions/createReferralAccount.js +8 -8
  14. package/lib/instructions/createStakingPool.js +7 -7
  15. package/lib/instructions/createUserReferralAccount.js +6 -6
  16. package/lib/instructions/createVault.js +15 -15
  17. package/lib/instructions/depositLiquidationPool.js +9 -9
  18. package/lib/instructions/depositStakingPool.js +5 -5
  19. package/lib/instructions/depositVault.js +11 -9
  20. package/lib/instructions/initHedgeFoundation.js +8 -8
  21. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  22. package/lib/instructions/liquidateVault.js +8 -8
  23. package/lib/instructions/loanVault.js +12 -12
  24. package/lib/instructions/psmEditAccount.js +5 -5
  25. package/lib/instructions/psmMintUsh.js +14 -14
  26. package/lib/instructions/psmRedeemUsh.js +14 -14
  27. package/lib/instructions/redeemVault.js +7 -7
  28. package/lib/instructions/referralClaimFees.js +8 -8
  29. package/lib/instructions/refreshOraclePrice.js +3 -3
  30. package/lib/instructions/repayVault.js +9 -9
  31. package/lib/instructions/setHalted.js +1 -1
  32. package/lib/instructions/updateReferralAccount.js +2 -2
  33. package/lib/instructions/updateReferralState.js +2 -2
  34. package/lib/instructions/updateVaultType.js +1 -1
  35. package/lib/instructions/withdrawStakingPool.js +11 -11
  36. package/lib/instructions/withdrawVault.js +5 -5
  37. package/lib/utils/getLinkedListAccounts.js +2 -3
  38. package/package.json +1 -1
  39. package/src/Constants.ts +44 -85
  40. package/src/idl/vault.ts +72 -0
  41. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  42. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  43. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  44. package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
  45. package/src/instructions/createReferralAccount.ts +17 -29
  46. package/src/instructions/createStakingPool.ts +11 -13
  47. package/src/instructions/createUserReferralAccount.ts +13 -24
  48. package/src/instructions/createVault.ts +44 -26
  49. package/src/instructions/depositLiquidationPool.ts +16 -23
  50. package/src/instructions/depositStakingPool.ts +18 -14
  51. package/src/instructions/depositVault.ts +23 -18
  52. package/src/instructions/initHedgeFoundation.ts +16 -14
  53. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  54. package/src/instructions/liquidateVault.ts +15 -20
  55. package/src/instructions/loanVault.ts +18 -27
  56. package/src/instructions/psmEditAccount.ts +10 -18
  57. package/src/instructions/psmMintUsh.ts +19 -41
  58. package/src/instructions/psmRedeemUsh.ts +21 -45
  59. package/src/instructions/redeemVault.ts +12 -15
  60. package/src/instructions/referralClaimFees.ts +17 -31
  61. package/src/instructions/refreshOraclePrice.ts +6 -8
  62. package/src/instructions/repayVault.ts +18 -16
  63. package/src/instructions/setHalted.ts +5 -24
  64. package/src/instructions/transferVault.ts +4 -9
  65. package/src/instructions/updateReferralAccount.ts +7 -14
  66. package/src/instructions/updateReferralState.ts +7 -14
  67. package/src/instructions/updateVaultType.ts +9 -23
  68. package/src/instructions/withdrawStakingPool.ts +17 -21
  69. package/src/instructions/withdrawVault.ts +10 -16
  70. package/src/utils/getLinkedListAccounts.ts +4 -7
@@ -1,29 +1,10 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { TokenInstructions } from '@project-serum/serum'
3
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
4
- import {
5
- Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
9
- SystemProgram,
10
- SYSVAR_RENT_PUBKEY,
11
- Transaction,
12
- TransactionInstruction,
13
- } from '@solana/web3.js'
14
- import {
15
- findAssociatedTokenAddress,
16
- findVaultAddress,
17
- getVaultTypeAccountPublicKey,
18
- getUshMintPublicKey,
19
- getVaultSystemStatePublicKey,
20
- getPoolPublicKeyForMint,
21
- getHedgeMintPublicKey,
22
- } from '../Constants'
1
+ import { Program, Provider } from '@project-serum/anchor'
2
+ import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
3
+ import { getVaultSystemStatePublicKey } from '../Constants'
23
4
 
5
+ import { Vault } from '../idl/vault'
24
6
  import { parseAnchorErrors } from '../utils/Errors'
25
7
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
26
- import { Vault } from '../idl/vault'
27
8
 
28
9
  export async function setHalted(
29
10
  program: Program<Vault>,
@@ -31,7 +12,7 @@ export async function setHalted(
31
12
  payer: Signer,
32
13
  halted: boolean
33
14
  ): Promise<PublicKey> {
34
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
15
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
35
16
 
36
17
  const transaction = new Transaction().add(
37
18
  await setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted)
@@ -1,17 +1,12 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
1
+ import { Program, Provider } from '@project-serum/anchor'
2
2
  import {
3
3
  Keypair,
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
7
- SystemProgram,
8
- SYSVAR_RENT_PUBKEY,
9
- Transaction,
10
- TransactionInstruction,
4
+ PublicKey, Signer, Transaction,
5
+ TransactionInstruction
11
6
  } from '@solana/web3.js'
12
7
 
13
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
14
8
  import { Vault } from '../idl/vault'
9
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
15
10
 
16
11
  export async function transferVault(
17
12
  program: Program<Vault>,
@@ -1,22 +1,15 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import {
3
- Keypair,
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
7
- SystemProgram,
8
- SYSVAR_RENT_PUBKEY,
9
- Transaction,
10
- TransactionInstruction,
3
+ PublicKey, Signer,
4
+ SystemProgram, Transaction,
5
+ TransactionInstruction
11
6
  } from '@solana/web3.js'
12
7
  import {
13
- getVaultSystemStatePublicKey,
14
- getReferralAccountPublicKey,
8
+ getReferralAccountPublicKey, getVaultSystemStatePublicKey
15
9
  } from '../Constants'
16
10
 
17
- import { parseAnchorErrors } from '../utils/Errors'
18
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
19
11
  import { Vault } from '../idl/vault'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
13
 
21
14
  export interface ReferralAccountConfig {
22
15
  setupCut?: BN
@@ -34,8 +27,8 @@ export async function updateReferralAccount(
34
27
  referrer: PublicKey,
35
28
  config: ReferralAccountConfig
36
29
  ): Promise<PublicKey> {
37
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
38
- const referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
30
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
31
+ const referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
39
32
  const transaction = new Transaction().add(
40
33
  await updateReferralAccountInstruction(
41
34
  program,
@@ -1,22 +1,15 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import {
3
- Keypair,
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
7
- SystemProgram,
8
- SYSVAR_RENT_PUBKEY,
9
- Transaction,
10
- TransactionInstruction,
3
+ PublicKey, Signer,
4
+ SystemProgram, Transaction,
5
+ TransactionInstruction
11
6
  } from '@solana/web3.js'
12
7
  import {
13
- getVaultSystemStatePublicKey,
14
- getReferralStatePublicKey,
8
+ getReferralStatePublicKey, getVaultSystemStatePublicKey
15
9
  } from '../Constants'
16
10
 
17
- import { parseAnchorErrors } from '../utils/Errors'
18
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
19
11
  import { Vault } from '../idl/vault'
12
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
13
 
21
14
  export interface ReferralStateConfig {
22
15
  setupCut?: BN
@@ -43,8 +36,8 @@ export async function updateReferralState(
43
36
  payer: Signer,
44
37
  config: ReferralStateConfig
45
38
  ): Promise<PublicKey> {
46
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
47
- const referralStatePublicKey = await getReferralStatePublicKey()
39
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
40
+ const referralStatePublicKey = await getReferralStatePublicKey(program.programId, )
48
41
  const transaction = new Transaction().add(
49
42
  await updateReferralStateInstruction(
50
43
  program,
@@ -1,44 +1,30 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import {
3
- Keypair,
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
7
- SystemProgram,
8
- SYSVAR_RENT_PUBKEY,
9
- Transaction,
10
- TransactionInstruction,
3
+ PublicKey, Signer, Transaction,
4
+ TransactionInstruction
11
5
  } from '@solana/web3.js'
12
6
  import {
13
- findAssociatedTokenAddress,
14
- findVaultAddress,
15
- getVaultTypeAccountPublicKey,
16
- getUshMintPublicKey,
17
- getVaultSystemStatePublicKey,
18
- getPoolPublicKeyForMint,
19
- getHedgeMintPublicKey,
7
+ getVaultSystemStatePublicKey
20
8
  } from '../Constants'
21
9
 
22
- import { v4 as uuidv4 } from 'uuid'
23
- import { parseAnchorErrors } from '../utils/Errors'
24
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
10
  import { Vault } from '../idl/vault'
11
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
26
12
 
27
13
  export interface VaultTypeConfig {
28
14
  maxDebtExtended?: BN
29
15
  minDebtPerVault?: BN
30
16
  loanInitFee?: BN
31
17
  interestRatePerSecond?: BN
32
-
18
+
33
19
  emergencyModeThreshold?: BN
34
20
 
35
21
  oracleChainlink?: PublicKey
36
22
  oraclePyth?: PublicKey
37
23
  oracleSwitchboard?: PublicKey
38
24
 
39
- priorityPyth?: number,
40
- priorityChainlink?: number,
41
- prioritySwitchboard?: number,
25
+ priorityPyth?: number
26
+ priorityChainlink?: number
27
+ prioritySwitchboard?: number
42
28
 
43
29
  deprecated?: boolean
44
30
  }
@@ -51,7 +37,7 @@ export async function updateVaultType(
51
37
  oracleInfoAccount: PublicKey,
52
38
  config: VaultTypeConfig
53
39
  ): Promise<PublicKey> {
54
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
40
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
55
41
  const transaction = new Transaction().add(
56
42
  await updateVaultTypeStatusInstruction(
57
43
  program,
@@ -1,25 +1,21 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
2
+ import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
4
  Keypair,
5
- PublicKey,
6
- sendAndConfirmTransaction,
7
- Signer,
8
- SystemProgram,
9
- SYSVAR_RENT_PUBKEY,
10
- Transaction,
11
- TransactionInstruction,
5
+ PublicKey, Signer,
6
+ SystemProgram, Transaction,
7
+ TransactionInstruction
12
8
  } from '@solana/web3.js'
13
- import { parseAnchorErrors } from '../utils/Errors'
14
9
  import {
15
10
  findAssociatedTokenAddress,
16
11
  getHedgeMintPublicKey,
17
12
  getPoolPublicKeyForMint,
18
13
  getUshMintPublicKey,
19
- getVaultSystemStatePublicKey,
14
+ getVaultSystemStatePublicKey
20
15
  } from '../Constants'
21
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
22
16
  import { Vault } from '../idl/vault'
17
+ import { parseAnchorErrors } from '../utils/Errors'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
19
 
24
20
  export async function withdrawStakingPool(
25
21
  program: Program<Vault>,
@@ -51,16 +47,16 @@ export async function withdrawStakingPoolInstruction(
51
47
  stakedTokenMintPublicKey: PublicKey,
52
48
  overrideStartTime?: number
53
49
  ): Promise<TransactionInstruction> {
54
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
55
- const ushMintPublickey = await getUshMintPublicKey()
56
- const hedgeMintPublickey = await getHedgeMintPublicKey()
57
- const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey)
58
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey)
59
- const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
60
- const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
61
- const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
62
- const payerAssociatedUshAccount = await findAssociatedTokenAddress(payerPublicKey, ushMintPublickey)
63
- const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
50
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
51
+ const ushMintPublickey = await getUshMintPublicKey(program.programId, )
52
+ const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId, )
53
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
54
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, stakedTokenMintPublicKey)
55
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
56
+ const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, stakedTokenMintPublicKey)
57
+ const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
58
+ const payerAssociatedUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
59
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey)
64
60
 
65
61
  return await program.methods
66
62
  .withdrawStakingPool(
@@ -1,26 +1,20 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
2
  import { TokenInstructions } from '@project-serum/serum'
3
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
4
  import {
5
5
  Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
6
+ PublicKey, Signer,
9
7
  SystemProgram,
10
8
  Transaction,
11
- TransactionInstruction,
9
+ TransactionInstruction
12
10
  } from '@solana/web3.js'
13
11
  import {
14
- findAssociatedTokenAddress,
15
- getVaultTypeAccountPublicKey,
16
- getUshMintPublicKey,
17
- getVaultSystemStatePublicKey,
18
- getPoolPublicKeyForMint,
19
- getHedgeMintPublicKey,
12
+ findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
13
+ getVaultSystemStatePublicKey
20
14
  } from '../Constants'
15
+ import { Vault } from '../idl/vault'
21
16
  import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
22
17
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
23
- import { Vault } from '../idl/vault'
24
18
 
25
19
  export async function withdrawVault(
26
20
  program: Program<Vault>,
@@ -30,13 +24,13 @@ export async function withdrawVault(
30
24
  withdrawAmount: number,
31
25
  overrideTime?: number
32
26
  ): Promise<PublicKey> {
33
- const ushMintPublickey = await getUshMintPublicKey()
27
+ const ushMintPublickey = await getUshMintPublicKey(program.programId, )
34
28
 
35
29
  // Prep the user to get USH back out at some point
36
30
  await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
37
31
 
38
32
  const history = Keypair.generate()
39
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
33
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
40
34
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
41
35
  const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
42
36
  provider.connection,
@@ -61,8 +55,8 @@ export async function withdrawVault(
61
55
  vaultTypeAccountInfo.collateralMint,
62
56
  payer.publicKey
63
57
  )
64
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
65
- const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
58
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, await getHedgeMintPublicKey(program.programId, ))
59
+ const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId,
66
60
  hedgeStakingPoolPublicKey,
67
61
  ushMintPublickey
68
62
  )
@@ -1,14 +1,11 @@
1
- import { Program, Provider, BN } from '@project-serum/anchor'
2
- import { PublicKey, Signer } from '@solana/web3.js'
1
+ import { BN, Program } from '@project-serum/anchor'
2
+ import { PublicKey } from '@solana/web3.js'
3
3
  import _ from 'underscore'
4
- import { getVaultSystemStatePublicKey, getVaultTypeOracleAccountPublicKey, HEDGE_PROGRAM_PUBLICKEY } from '../Constants'
5
4
 
6
- import { DecimalFromU128 } from '../HedgeDecimal'
7
- import { VaultAccount } from '../state/VaultAccount'
8
5
  import Decimal from 'decimal.js'
9
6
  import { Vault } from '../idl/vault'
7
+ import { VaultAccount } from '../state/VaultAccount'
10
8
 
11
- import * as borsh from '@project-serum/borsh'
12
9
  import base58 from 'bs58'
13
10
  import VaultType from '../state/VaultType'
14
11
 
@@ -228,7 +225,7 @@ async function getMiniVaults(program: Program<Vault>, vaultTypePublicKey: Public
228
225
  },
229
226
  },
230
227
  ]
231
- const allAccounts = await program.provider.connection.getProgramAccounts(HEDGE_PROGRAM_PUBLICKEY, {
228
+ const allAccounts = await program.provider.connection.getProgramAccounts(program.programId, {
232
229
  filters: filters,
233
230
  // Slice the data only to grab the 3 u64's of size 8 bytes each
234
231
  dataSlice: {