hedge-web3 0.2.24 → 0.2.26

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 (73) 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/state/VaultAccount.d.ts +15 -2
  7. package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
  8. package/lib/Constants.js +28 -34
  9. package/lib/idl/vault.js +36 -0
  10. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  11. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  12. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  13. package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
  14. package/lib/instructions/createReferralAccount.js +8 -8
  15. package/lib/instructions/createStakingPool.js +7 -7
  16. package/lib/instructions/createUserReferralAccount.js +6 -6
  17. package/lib/instructions/createVault.js +16 -16
  18. package/lib/instructions/depositLiquidationPool.js +9 -9
  19. package/lib/instructions/depositStakingPool.js +5 -5
  20. package/lib/instructions/depositVault.js +11 -9
  21. package/lib/instructions/initHedgeFoundation.js +8 -8
  22. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  23. package/lib/instructions/liquidateVault.js +8 -8
  24. package/lib/instructions/loanVault.js +12 -12
  25. package/lib/instructions/psmEditAccount.js +5 -5
  26. package/lib/instructions/psmMintUsh.js +14 -14
  27. package/lib/instructions/psmRedeemUsh.js +14 -14
  28. package/lib/instructions/redeemVault.js +7 -7
  29. package/lib/instructions/referralClaimFees.js +8 -8
  30. package/lib/instructions/refreshOraclePrice.js +3 -3
  31. package/lib/instructions/repayVault.js +9 -9
  32. package/lib/instructions/setHalted.js +1 -1
  33. package/lib/instructions/updateReferralAccount.js +2 -2
  34. package/lib/instructions/updateReferralState.js +2 -2
  35. package/lib/instructions/updateVaultType.js +1 -1
  36. package/lib/instructions/withdrawStakingPool.js +11 -11
  37. package/lib/instructions/withdrawVault.js +5 -5
  38. package/lib/state/VaultAccount.js +16 -16
  39. package/lib/utils/getLinkedListAccounts.js +20 -4
  40. package/package.json +1 -1
  41. package/src/Constants.ts +44 -85
  42. package/src/idl/vault.ts +72 -0
  43. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  44. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  45. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  46. package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
  47. package/src/instructions/createReferralAccount.ts +17 -29
  48. package/src/instructions/createStakingPool.ts +11 -13
  49. package/src/instructions/createUserReferralAccount.ts +13 -24
  50. package/src/instructions/createVault.ts +44 -21
  51. package/src/instructions/depositLiquidationPool.ts +16 -23
  52. package/src/instructions/depositStakingPool.ts +18 -14
  53. package/src/instructions/depositVault.ts +23 -18
  54. package/src/instructions/initHedgeFoundation.ts +16 -14
  55. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  56. package/src/instructions/liquidateVault.ts +15 -20
  57. package/src/instructions/loanVault.ts +18 -27
  58. package/src/instructions/psmEditAccount.ts +10 -18
  59. package/src/instructions/psmMintUsh.ts +19 -41
  60. package/src/instructions/psmRedeemUsh.ts +21 -45
  61. package/src/instructions/redeemVault.ts +12 -15
  62. package/src/instructions/referralClaimFees.ts +17 -31
  63. package/src/instructions/refreshOraclePrice.ts +6 -8
  64. package/src/instructions/repayVault.ts +18 -16
  65. package/src/instructions/setHalted.ts +5 -24
  66. package/src/instructions/transferVault.ts +4 -9
  67. package/src/instructions/updateReferralAccount.ts +7 -14
  68. package/src/instructions/updateReferralState.ts +7 -14
  69. package/src/instructions/updateVaultType.ts +9 -23
  70. package/src/instructions/withdrawStakingPool.ts +17 -21
  71. package/src/instructions/withdrawVault.ts +10 -16
  72. package/src/state/VaultAccount.ts +31 -17
  73. package/src/utils/getLinkedListAccounts.ts +20 -7
@@ -6,6 +6,20 @@ import * as borsh from '@project-serum/borsh'
6
6
  import BN from 'bn.js'
7
7
  import VaultType from './VaultType'
8
8
 
9
+ export type VaultAccountData = {
10
+ vaultOwner: PublicKey
11
+ pdaSalt: string
12
+ deposited: BN
13
+ denormalizedDebt: BN
14
+ vaultNumber: BN
15
+ debtProductSnapshotBytes: BN
16
+ collateralAccumulatorSnapshotBytes: BN
17
+ vaultTypeName: string
18
+ nextVaultToRedeem: PublicKey | null
19
+ vaultStatus: any
20
+ vaultType: PublicKey
21
+ }
22
+
9
23
  /**
10
24
  * A class that represents an on-chian vault.
11
25
  */
@@ -41,35 +55,35 @@ export class VaultAccount {
41
55
  vaultStatus = ''
42
56
 
43
57
  /** The public key of the next vault to redeem. */
44
- nextVaultToRedeem: PublicKey
58
+ nextVaultToRedeem: PublicKey | null
45
59
 
46
60
  /** The public key of the vault type. */
47
61
  vaultType: PublicKey
48
62
 
49
- constructor(vault: any, publicKey: PublicKey) {
63
+ constructor(vaultData: VaultAccountData, publicKey: PublicKey) {
50
64
  this.publicKey = publicKey
51
- this.vaultOwner = vault.vaultOwner
52
- this.pdaSalt = vault.pdaSalt
65
+ this.vaultOwner = vaultData.vaultOwner
66
+ this.pdaSalt = vaultData.pdaSalt
53
67
 
54
- this.deposited = vault.deposited
55
- this.denormalizedDebt = vault.denormalizedDebt
68
+ this.deposited = vaultData.deposited
69
+ this.denormalizedDebt = vaultData.denormalizedDebt
56
70
 
57
- if (vault.vaultNumber) {
58
- this.vaultNumber = vault.vaultNumber.toNumber()
71
+ if (vaultData.vaultNumber) {
72
+ this.vaultNumber = vaultData.vaultNumber.toNumber()
59
73
  }
60
- if (vault.debtProductSnapshotBytes) {
61
- this.debtProductSnapshotBytes = DecimalFromU128(vault.debtProductSnapshotBytes.toString())
74
+ if (vaultData.debtProductSnapshotBytes) {
75
+ this.debtProductSnapshotBytes = DecimalFromU128(vaultData.debtProductSnapshotBytes.toString())
62
76
  }
63
- if (vault.collateralAccumulatorSnapshotBytes) {
64
- this.collateralAccumulatorSnapshotBytes = DecimalFromU128(vault.collateralAccumulatorSnapshotBytes.toString())
77
+ if (vaultData.collateralAccumulatorSnapshotBytes) {
78
+ this.collateralAccumulatorSnapshotBytes = DecimalFromU128(vaultData.collateralAccumulatorSnapshotBytes.toString())
65
79
  }
66
- this.vaultTypeName = vault.vaultTypeName
67
- this.nextVaultToRedeem = vault.nextVaultToRedeem
80
+ this.vaultTypeName = vaultData.vaultTypeName
81
+ this.nextVaultToRedeem = vaultData.nextVaultToRedeem
68
82
 
69
- if (vault.vaultStatus) {
70
- this.vaultStatus = Object.keys(vault.vaultStatus)[0]
83
+ if (vaultData.vaultStatus) {
84
+ this.vaultStatus = Object.keys(vaultData.vaultStatus)[0]
71
85
  }
72
- this.vaultType = vault.vaultType
86
+ this.vaultType = vaultData.vaultType
73
87
  }
74
88
 
75
89
  /**
@@ -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
 
@@ -49,6 +46,22 @@ export async function getLinkedListAccounts(
49
46
  let newLargerPublicKey = vaultPublicKey
50
47
 
51
48
  const thisVaultData = await program.account.vault.fetch(vaultPublicKey)
49
+ .catch((e) => {
50
+ console.log('Error fetching vault account. Assuming it does not exist yet')
51
+ return {
52
+ vaultOwner: new PublicKey('11111111111111111111111111111111'),
53
+ pdaSalt: 'foo',
54
+ deposited: new BN(0),
55
+ denormalizedDebt: new BN(0),
56
+ vaultNumber: new BN(0),
57
+ debtProductSnapshotBytes: new BN(0),
58
+ collateralAccumulatorSnapshotBytes: new BN(0),
59
+ vaultTypeName: vaultType.name,
60
+ nextVaultToRedeem: new PublicKey('11111111111111111111111111111111'),
61
+ vaultStatus: {open: true},
62
+ vaultType: vaultTypeAccountPublicKey
63
+ }
64
+ })
52
65
  // const accountInfo = await program.provider.connection.getAccountInfo(vaultPublicKey)
53
66
  const thisVault = new VaultAccount(thisVaultData, vaultPublicKey)
54
67
 
@@ -228,7 +241,7 @@ async function getMiniVaults(program: Program<Vault>, vaultTypePublicKey: Public
228
241
  },
229
242
  },
230
243
  ]
231
- const allAccounts = await program.provider.connection.getProgramAccounts(HEDGE_PROGRAM_PUBLICKEY, {
244
+ const allAccounts = await program.provider.connection.getProgramAccounts(program.programId, {
232
245
  filters: filters,
233
246
  // Slice the data only to grab the 3 u64's of size 8 bytes each
234
247
  dataSlice: {