hedge-web3 0.2.24 → 0.2.25

Sign up to get free protection for your applications and to get access to all the features.
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
package/src/idl/vault.ts CHANGED
@@ -2413,33 +2413,54 @@ export type Vault = {
2413
2413
  "accounts": [
2414
2414
  {
2415
2415
  "name": "aggregator",
2416
+ "docs": [
2417
+ "Define the type of state stored in accounts"
2418
+ ],
2416
2419
  "type": {
2417
2420
  "kind": "struct",
2418
2421
  "fields": [
2419
2422
  {
2420
2423
  "name": "isInitialized",
2424
+ "docs": [
2425
+ "Set to true after initialization."
2426
+ ],
2421
2427
  "type": "bool"
2422
2428
  },
2423
2429
  {
2424
2430
  "name": "version",
2431
+ "docs": [
2432
+ "Version of the state"
2433
+ ],
2425
2434
  "type": "u32"
2426
2435
  },
2427
2436
  {
2428
2437
  "name": "config",
2438
+ "docs": [
2439
+ "The configuration for this aggregator"
2440
+ ],
2429
2441
  "type": {
2430
2442
  "defined": "Config"
2431
2443
  }
2432
2444
  },
2433
2445
  {
2434
2446
  "name": "updatedAt",
2447
+ "docs": [
2448
+ "When the config was last updated."
2449
+ ],
2435
2450
  "type": "i64"
2436
2451
  },
2437
2452
  {
2438
2453
  "name": "owner",
2454
+ "docs": [
2455
+ "The aggregator owner is allowed to modify it's config."
2456
+ ],
2439
2457
  "type": "publicKey"
2440
2458
  },
2441
2459
  {
2442
2460
  "name": "submissions",
2461
+ "docs": [
2462
+ "A set of current submissions, one per oracle. Array index corresponds to oracle index."
2463
+ ],
2443
2464
  "type": {
2444
2465
  "array": [
2445
2466
  {
@@ -2451,6 +2472,9 @@ export type Vault = {
2451
2472
  },
2452
2473
  {
2453
2474
  "name": "answer",
2475
+ "docs": [
2476
+ "The current median answer."
2477
+ ],
2454
2478
  "type": {
2455
2479
  "option": "u128"
2456
2480
  }
@@ -3296,20 +3320,32 @@ export type Vault = {
3296
3320
  "fields": [
3297
3321
  {
3298
3322
  "name": "oracles",
3323
+ "docs": [
3324
+ "A list of oracles allowed to submit answers."
3325
+ ],
3299
3326
  "type": {
3300
3327
  "vec": "publicKey"
3301
3328
  }
3302
3329
  },
3303
3330
  {
3304
3331
  "name": "minAnswerThreshold",
3332
+ "docs": [
3333
+ "Number of submissions required to produce an answer. Must be larger than 0."
3334
+ ],
3305
3335
  "type": "u8"
3306
3336
  },
3307
3337
  {
3308
3338
  "name": "stalenessThreshold",
3339
+ "docs": [
3340
+ "Offset in number of seconds before a submission is considered stale."
3341
+ ],
3309
3342
  "type": "u8"
3310
3343
  },
3311
3344
  {
3312
3345
  "name": "decimals",
3346
+ "docs": [
3347
+ "Decimal places for value representations"
3348
+ ],
3313
3349
  "type": "u8"
3314
3350
  }
3315
3351
  ]
@@ -6392,33 +6428,54 @@ export const IDL: Vault = {
6392
6428
  "accounts": [
6393
6429
  {
6394
6430
  "name": "aggregator",
6431
+ "docs": [
6432
+ "Define the type of state stored in accounts"
6433
+ ],
6395
6434
  "type": {
6396
6435
  "kind": "struct",
6397
6436
  "fields": [
6398
6437
  {
6399
6438
  "name": "isInitialized",
6439
+ "docs": [
6440
+ "Set to true after initialization."
6441
+ ],
6400
6442
  "type": "bool"
6401
6443
  },
6402
6444
  {
6403
6445
  "name": "version",
6446
+ "docs": [
6447
+ "Version of the state"
6448
+ ],
6404
6449
  "type": "u32"
6405
6450
  },
6406
6451
  {
6407
6452
  "name": "config",
6453
+ "docs": [
6454
+ "The configuration for this aggregator"
6455
+ ],
6408
6456
  "type": {
6409
6457
  "defined": "Config"
6410
6458
  }
6411
6459
  },
6412
6460
  {
6413
6461
  "name": "updatedAt",
6462
+ "docs": [
6463
+ "When the config was last updated."
6464
+ ],
6414
6465
  "type": "i64"
6415
6466
  },
6416
6467
  {
6417
6468
  "name": "owner",
6469
+ "docs": [
6470
+ "The aggregator owner is allowed to modify it's config."
6471
+ ],
6418
6472
  "type": "publicKey"
6419
6473
  },
6420
6474
  {
6421
6475
  "name": "submissions",
6476
+ "docs": [
6477
+ "A set of current submissions, one per oracle. Array index corresponds to oracle index."
6478
+ ],
6422
6479
  "type": {
6423
6480
  "array": [
6424
6481
  {
@@ -6430,6 +6487,9 @@ export const IDL: Vault = {
6430
6487
  },
6431
6488
  {
6432
6489
  "name": "answer",
6490
+ "docs": [
6491
+ "The current median answer."
6492
+ ],
6433
6493
  "type": {
6434
6494
  "option": "u128"
6435
6495
  }
@@ -7275,20 +7335,32 @@ export const IDL: Vault = {
7275
7335
  "fields": [
7276
7336
  {
7277
7337
  "name": "oracles",
7338
+ "docs": [
7339
+ "A list of oracles allowed to submit answers."
7340
+ ],
7278
7341
  "type": {
7279
7342
  "vec": "publicKey"
7280
7343
  }
7281
7344
  },
7282
7345
  {
7283
7346
  "name": "minAnswerThreshold",
7347
+ "docs": [
7348
+ "Number of submissions required to produce an answer. Must be larger than 0."
7349
+ ],
7284
7350
  "type": "u8"
7285
7351
  },
7286
7352
  {
7287
7353
  "name": "stalenessThreshold",
7354
+ "docs": [
7355
+ "Offset in number of seconds before a submission is considered stale."
7356
+ ],
7288
7357
  "type": "u8"
7289
7358
  },
7290
7359
  {
7291
7360
  "name": "decimals",
7361
+ "docs": [
7362
+ "Decimal places for value representations"
7363
+ ],
7292
7364
  "type": "u8"
7293
7365
  }
7294
7366
  ]
@@ -1,23 +1,19 @@
1
1
  import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
4
+ PublicKey, Signer,
7
5
  SystemProgram,
8
6
  SYSVAR_RENT_PUBKEY,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
10
  import {
14
- findAssociatedTokenAddress,
15
- getVaultTypeAccountPublicKey,
16
- getLiquidationPoolStatePublicKey,
17
- getVaultSystemStatePublicKey,
11
+ findAssociatedTokenAddress, getLiquidationPoolStatePublicKey,
12
+ getVaultSystemStatePublicKey, getVaultTypeAccountPublicKey
18
13
  } from '../Constants'
19
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
14
  import { Vault } from '../idl/vault'
15
+ import { parseAnchorErrors } from '../utils/Errors'
16
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
17
 
22
18
  export async function claimLiquidationPoolPosition(
23
19
  program: Program<Vault>,
@@ -27,7 +23,7 @@ export async function claimLiquidationPoolPosition(
27
23
  collateralType: string,
28
24
  overrideStartTime?: number
29
25
  ): Promise<PublicKey> {
30
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
26
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
31
27
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
32
28
  const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint
33
29
 
@@ -62,23 +58,29 @@ export async function claimLiquidationPoolPositionInstruction(
62
58
  payerAssociatedTokenAccount: PublicKey,
63
59
  overrideStartTime?: number
64
60
  ): Promise<TransactionInstruction> {
61
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
62
+ const poolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
63
+ const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
64
+ program.programId,
65
+ poolStatePublicKey,
66
+ collateralMint
67
+ )
65
68
 
66
- const vaultSystemState = await getVaultSystemStatePublicKey()
67
- const poolStatePublicKey = await getLiquidationPoolStatePublicKey()
68
- const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey, collateralMint)
69
-
70
- return await program.methods.claimLiquidationPoolPosition().accounts({
71
- vaultSystemState: vaultSystemState,
72
- poolState: poolStatePublicKey,
73
- poolAssociatedTokenAccount: poolAssociatedTokenAccount,
74
- vaultTypeAccount: vaultTypeAccount,
75
- collateralMint: collateralMint,
76
- poolPosition: poolPosition,
77
- payer: payer,
78
- payerAssociatedTokenAccount: payerAssociatedTokenAccount,
79
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
80
- tokenProgram: TOKEN_PROGRAM_ID,
81
- systemProgram: SystemProgram.programId,
82
- rent: SYSVAR_RENT_PUBKEY,
83
- }).instruction()
69
+ return await program.methods
70
+ .claimLiquidationPoolPosition()
71
+ .accounts({
72
+ vaultSystemState: vaultSystemState,
73
+ poolState: poolStatePublicKey,
74
+ poolAssociatedTokenAccount: poolAssociatedTokenAccount,
75
+ vaultTypeAccount: vaultTypeAccount,
76
+ collateralMint: collateralMint,
77
+ poolPosition: poolPosition,
78
+ payer: payer,
79
+ payerAssociatedTokenAccount: payerAssociatedTokenAccount,
80
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
81
+ tokenProgram: TOKEN_PROGRAM_ID,
82
+ systemProgram: SystemProgram.programId,
83
+ rent: SYSVAR_RENT_PUBKEY,
84
+ })
85
+ .instruction()
84
86
  }
@@ -1,24 +1,19 @@
1
1
  import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
4
+ PublicKey, Signer,
7
5
  SystemProgram,
8
6
  SYSVAR_RENT_PUBKEY,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
10
  import {
14
- getHedgeMintPublicKey,
15
- findAssociatedTokenAddress,
16
- getVaultTypeAccountPublicKey,
17
- getPoolPublicKeyForMint,
18
- getVaultSystemStatePublicKey,
11
+ getHedgeMintPublicKey, getPoolPublicKeyForMint,
12
+ getVaultSystemStatePublicKey, getVaultTypeAccountPublicKey
19
13
  } from '../Constants'
20
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
14
  import { Vault } from '../idl/vault'
15
+ import { parseAnchorErrors } from '../utils/Errors'
16
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
22
17
 
23
18
  export async function claimStakingPoolPosition(
24
19
  program: Program<Vault>,
@@ -27,11 +22,11 @@ export async function claimStakingPoolPosition(
27
22
  payer: Signer,
28
23
  collateralType: string
29
24
  ): Promise<PublicKey> {
30
- const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
25
+ const vaultTypeAccount = await getVaultTypeAccountPublicKey(program.programId, collateralType)
31
26
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccount)
32
27
  const collateralMint = vaultTypeAccountInfo.collateralMint
33
- const stakedTokenMint = await getHedgeMintPublicKey()
34
- const [feePool] = await getPoolPublicKeyForMint(stakedTokenMint)
28
+ const stakedTokenMint = await getHedgeMintPublicKey(program.programId)
29
+ const [feePool] = await getPoolPublicKeyForMint(program.programId, stakedTokenMint)
35
30
  const feePoolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
36
31
  provider.connection,
37
32
  payer,
@@ -74,7 +69,7 @@ export async function claimStakingPoolPositionInstruction(
74
69
  payer: PublicKey,
75
70
  payerAssociatedTokenAccount: PublicKey
76
71
  ): Promise<TransactionInstruction> {
77
- const vaultSystemState = await getVaultSystemStatePublicKey()
72
+ const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
78
73
 
79
74
  return await program.methods
80
75
  .claimStakingPoolPosition()
@@ -10,7 +10,9 @@ export async function closeClaimedLiquidationPoolPosition(
10
10
  poolPosition: PublicKey,
11
11
  payer: Signer
12
12
  ): Promise<PublicKey> {
13
- const transaction = new Transaction().add(await closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer.publicKey))
13
+ const transaction = new Transaction().add(
14
+ await closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer.publicKey)
15
+ )
14
16
 
15
17
  await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
16
18
  return poolPosition
@@ -25,7 +27,7 @@ export async function closeClaimedLiquidationPoolPositionInstruction(
25
27
  .closeClaimedLiquidationPoolPosition()
26
28
  .accounts({
27
29
  poolPosition: poolPosition,
28
- payer: payer
30
+ payer: payer,
29
31
  })
30
32
  .instruction()
31
33
  }
@@ -1,27 +1,21 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
4
+ PublicKey, Signer,
7
5
  SystemProgram,
8
6
  SYSVAR_RENT_PUBKEY,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
10
  import {
14
11
  getHedgeMintPublicKey,
15
12
  getLiquidationPoolStatePublicKey,
16
- getLiquidationPoolUshAccountPublicKey,
17
- getUshMintPublicKey,
18
- getVaultSystemStatePublicKey,
19
- getReferralAccountPublicKey,
20
- getUserReferralAccountPublicKey,
21
- getReferralStatePublicKey
13
+ getLiquidationPoolUshAccountPublicKey, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
14
+ getVaultSystemStatePublicKey
22
15
  } from '../Constants'
23
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
16
  import { Vault } from '../idl/vault'
17
+ import { parseAnchorErrors } from '../utils/Errors'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
25
19
 
26
20
  export async function closeLiquidationPoolPosition(
27
21
  program: Program<Vault>,
@@ -31,19 +25,19 @@ export async function closeLiquidationPoolPosition(
31
25
  overrideStartTime?: number,
32
26
  referrer?: PublicKey
33
27
  ): Promise<PublicKey> {
34
- const ushMintPublickey = await getUshMintPublicKey()
28
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
35
29
  const payerUshAccount = await getOrCreateAssociatedTokenAccount(
36
30
  provider.connection,
37
31
  payer,
38
32
  ushMintPublickey,
39
33
  payer.publicKey
40
34
  )
41
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
42
- const referralStatePublicKey = await getReferralStatePublicKey()
35
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
36
+ const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
43
37
  const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition)
44
38
  const poolEra = liquidationPositionAccount.era
45
39
 
46
- const hedgeMint = await getHedgeMintPublicKey()
40
+ const hedgeMint = await getHedgeMintPublicKey(program.programId)
47
41
  const payerAssociatedHedgeAccount = await getOrCreateAssociatedTokenAccount(
48
42
  provider.connection,
49
43
  payer,
@@ -60,13 +54,13 @@ export async function closeLiquidationPoolPosition(
60
54
 
61
55
  let referralAccountPublicKey = null
62
56
  if (typeof referrer === 'undefined') {
63
- referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
57
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
64
58
  } else {
65
- referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
59
+ referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
66
60
  }
67
61
 
68
62
  // Derive the user referral account public key
69
- const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payer.publicKey)
63
+ const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
70
64
 
71
65
  const transaction = new Transaction().add(
72
66
  await closeLiquidationPoolPositionInstruction(
@@ -100,11 +94,11 @@ export async function closeLiquidationPoolPositionInstruction(
100
94
  referralStatePublicKey: PublicKey,
101
95
  overrideStartTime?: number
102
96
  ): Promise<TransactionInstruction> {
103
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
104
- const ushMint = await getUshMintPublicKey()
105
- const hedgeMint = await getHedgeMintPublicKey()
106
- const poolUshAccount = await getLiquidationPoolUshAccountPublicKey()
107
- const poolState = await getLiquidationPoolStatePublicKey()
97
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
98
+ const ushMint = await getUshMintPublicKey(program.programId)
99
+ const hedgeMint = await getHedgeMintPublicKey(program.programId)
100
+ const poolUshAccount = await getLiquidationPoolUshAccountPublicKey(program.programId)
101
+ const poolState = await getLiquidationPoolStatePublicKey(program.programId)
108
102
 
109
103
  return await program.methods
110
104
  .closeLiquidationPoolPosition(
@@ -1,29 +1,20 @@
1
- import { BN, Idl, 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'
1
+ import { BN, Program, Provider } from '@project-serum/anchor'
2
+ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
3
  import {
5
- Keypair,
6
- PublicKey,
7
- sendAndConfirmTransaction,
8
- Signer,
4
+ PublicKey, Signer,
9
5
  SystemProgram,
10
6
  SYSVAR_RENT_PUBKEY,
11
7
  Transaction,
12
- TransactionInstruction,
8
+ TransactionInstruction
13
9
  } from '@solana/web3.js'
14
10
  import {
15
- getVaultSystemStatePublicKey,
16
- getReferralAccountPublicKey,
17
- getHedgeMintPublicKey,
18
- getReferralStatePublicKey,
19
- getUserReferralAccountPublicKey
11
+ getHedgeMintPublicKey, getReferralAccountPublicKey, getReferralStatePublicKey,
12
+ getUserReferralAccountPublicKey, getVaultSystemStatePublicKey
20
13
  } from '../Constants'
21
14
 
15
+ import { Vault } from '../idl/vault'
22
16
  import { parseAnchorErrors } from '../utils/Errors'
23
17
  import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
24
- import { Vault } from '../idl/vault'
25
-
26
-
27
18
 
28
19
  /** @type {Function} - Creates a new referral account.
29
20
  * This checks the user has enough HDG in their wallet or staked and
@@ -36,7 +27,7 @@ import { Vault } from '../idl/vault'
36
27
  * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
37
28
  * - referrer: PublicKey
38
29
  * - overrideTime?: number
39
- */
30
+ */
40
31
  export async function createReferralAccount(
41
32
  program: Program<Vault>,
42
33
  provider: Provider,
@@ -44,24 +35,23 @@ export async function createReferralAccount(
44
35
  poolPosition: PublicKey,
45
36
  overrideTime?: number
46
37
  ): Promise<PublicKey> {
47
- // setup transaction
38
+ // setup transaction
48
39
  const transaction = new Transaction()
49
40
  const signers = [payer]
50
41
  const referrer = payer.publicKey
51
42
 
52
43
  // Setup public keys
53
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
44
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
54
45
 
55
46
  // Find referral account
56
- let referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
57
-
47
+ let referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
58
48
 
59
49
  // Get the referral state PDA
60
- const referallStatePublicKey = await getReferralStatePublicKey()
50
+ const referallStatePublicKey = await getReferralStatePublicKey(program.programId)
61
51
 
62
52
  // Get HDG mint public key
63
- const hedgeMintPublicKey = await getHedgeMintPublicKey()
64
-
53
+ const hedgeMintPublicKey = await getHedgeMintPublicKey(program.programId)
54
+
65
55
  // Get HDG account of signer
66
56
  const payerHdgAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
67
57
  provider.connection,
@@ -71,8 +61,8 @@ export async function createReferralAccount(
71
61
  )
72
62
 
73
63
  // Derive the user referral account public key
74
- const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payer.publicKey)
75
-
64
+ const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payer.publicKey)
65
+
76
66
  transaction.add(
77
67
  await createReferralAccountInstruction(
78
68
  program,
@@ -87,12 +77,10 @@ export async function createReferralAccount(
87
77
  )
88
78
  )
89
79
 
90
-
91
80
  await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
92
81
  return referralAccountPublicKey
93
82
  }
94
83
 
95
-
96
84
  export async function createReferralAccountInstruction(
97
85
  program: Program<Vault>,
98
86
  payerPublicKey: PublicKey,
@@ -104,7 +92,7 @@ export async function createReferralAccountInstruction(
104
92
  userReferralAccountPublicKey: PublicKey,
105
93
  overrideTime?: number
106
94
  ): Promise<TransactionInstruction> {
107
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
95
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
108
96
 
109
97
  return await program.methods
110
98
  .createReferralAccount(
@@ -1,23 +1,21 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import {
4
- PublicKey,
5
- sendAndConfirmTransaction,
6
- Signer,
4
+ PublicKey, Signer,
7
5
  SystemProgram,
8
6
  SYSVAR_RENT_PUBKEY,
9
7
  Transaction,
10
- TransactionInstruction,
8
+ TransactionInstruction
11
9
  } from '@solana/web3.js'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
10
  import {
14
11
  findAssociatedTokenAddress,
15
12
  getPoolPublicKeyForMint,
16
13
  getUshMintPublicKey,
17
- getVaultSystemStatePublicKey,
14
+ getVaultSystemStatePublicKey
18
15
  } from '../Constants'
19
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
20
16
  import { Vault } from '../idl/vault'
17
+ import { parseAnchorErrors } from '../utils/Errors'
18
+ import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
21
19
 
22
20
  export async function createStakingPool(
23
21
  program: Program<Vault>,
@@ -31,7 +29,7 @@ export async function createStakingPool(
31
29
  await createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime)
32
30
  )
33
31
  await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
34
- const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey)
32
+ const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
35
33
  return poolPublickey
36
34
  }
37
35
 
@@ -42,12 +40,12 @@ export async function createStakingPoolInstruction(
42
40
  hedgeTokensToBeMinted: number,
43
41
  overrideStartTime?: number
44
42
  ): Promise<TransactionInstruction> {
45
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
46
- const ushMintPublickey = await getUshMintPublicKey()
47
- const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
43
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
44
+ const ushMintPublickey = await getUshMintPublicKey(program.programId)
45
+ const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
48
46
 
49
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey)
50
- const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
47
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, mintPublicKey)
48
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
51
49
  return await program.methods
52
50
  .createStakingPool(poolBump, new BN(hedgeTokensToBeMinted), new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)))
53
51
  .accounts({