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.
- package/declarations/Constants.d.ts +13 -15
- package/declarations/idl/vault.d.ts +36 -0
- package/declarations/instructions/createReferralAccount.d.ts +1 -1
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
- package/declarations/instructions/referralClaimFees.d.ts +1 -1
- package/declarations/state/VaultAccount.d.ts +15 -2
- package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
- package/lib/Constants.js +28 -34
- package/lib/idl/vault.js +36 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
- package/lib/instructions/claimStakingPoolPosition.js +5 -5
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
- package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
- package/lib/instructions/createReferralAccount.js +8 -8
- package/lib/instructions/createStakingPool.js +7 -7
- package/lib/instructions/createUserReferralAccount.js +6 -6
- package/lib/instructions/createVault.js +16 -16
- package/lib/instructions/depositLiquidationPool.js +9 -9
- package/lib/instructions/depositStakingPool.js +5 -5
- package/lib/instructions/depositVault.js +11 -9
- package/lib/instructions/initHedgeFoundation.js +8 -8
- package/lib/instructions/initHedgeFoundationTokens.js +5 -5
- package/lib/instructions/liquidateVault.js +8 -8
- package/lib/instructions/loanVault.js +12 -12
- package/lib/instructions/psmEditAccount.js +5 -5
- package/lib/instructions/psmMintUsh.js +14 -14
- package/lib/instructions/psmRedeemUsh.js +14 -14
- package/lib/instructions/redeemVault.js +7 -7
- package/lib/instructions/referralClaimFees.js +8 -8
- package/lib/instructions/refreshOraclePrice.js +3 -3
- package/lib/instructions/repayVault.js +9 -9
- package/lib/instructions/setHalted.js +1 -1
- package/lib/instructions/updateReferralAccount.js +2 -2
- package/lib/instructions/updateReferralState.js +2 -2
- package/lib/instructions/updateVaultType.js +1 -1
- package/lib/instructions/withdrawStakingPool.js +11 -11
- package/lib/instructions/withdrawVault.js +5 -5
- package/lib/state/VaultAccount.js +16 -16
- package/lib/utils/getLinkedListAccounts.js +20 -4
- package/package.json +1 -1
- package/src/Constants.ts +44 -85
- package/src/idl/vault.ts +72 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
- package/src/instructions/claimStakingPoolPosition.ts +10 -15
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
- package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
- package/src/instructions/createReferralAccount.ts +17 -29
- package/src/instructions/createStakingPool.ts +11 -13
- package/src/instructions/createUserReferralAccount.ts +13 -24
- package/src/instructions/createVault.ts +44 -21
- package/src/instructions/depositLiquidationPool.ts +16 -23
- package/src/instructions/depositStakingPool.ts +18 -14
- package/src/instructions/depositVault.ts +23 -18
- package/src/instructions/initHedgeFoundation.ts +16 -14
- package/src/instructions/initHedgeFoundationTokens.ts +12 -14
- package/src/instructions/liquidateVault.ts +15 -20
- package/src/instructions/loanVault.ts +18 -27
- package/src/instructions/psmEditAccount.ts +10 -18
- package/src/instructions/psmMintUsh.ts +19 -41
- package/src/instructions/psmRedeemUsh.ts +21 -45
- package/src/instructions/redeemVault.ts +12 -15
- package/src/instructions/referralClaimFees.ts +17 -31
- package/src/instructions/refreshOraclePrice.ts +6 -8
- package/src/instructions/repayVault.ts +18 -16
- package/src/instructions/setHalted.ts +5 -24
- package/src/instructions/transferVault.ts +4 -9
- package/src/instructions/updateReferralAccount.ts +7 -14
- package/src/instructions/updateReferralState.ts +7 -14
- package/src/instructions/updateVaultType.ts +9 -23
- package/src/instructions/withdrawStakingPool.ts +17 -21
- package/src/instructions/withdrawVault.ts +10 -16
- package/src/state/VaultAccount.ts +31 -17
- 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(
|
63
|
+
constructor(vaultData: VaultAccountData, publicKey: PublicKey) {
|
50
64
|
this.publicKey = publicKey
|
51
|
-
this.vaultOwner =
|
52
|
-
this.pdaSalt =
|
65
|
+
this.vaultOwner = vaultData.vaultOwner
|
66
|
+
this.pdaSalt = vaultData.pdaSalt
|
53
67
|
|
54
|
-
this.deposited =
|
55
|
-
this.denormalizedDebt =
|
68
|
+
this.deposited = vaultData.deposited
|
69
|
+
this.denormalizedDebt = vaultData.denormalizedDebt
|
56
70
|
|
57
|
-
if (
|
58
|
-
this.vaultNumber =
|
71
|
+
if (vaultData.vaultNumber) {
|
72
|
+
this.vaultNumber = vaultData.vaultNumber.toNumber()
|
59
73
|
}
|
60
|
-
if (
|
61
|
-
this.debtProductSnapshotBytes = DecimalFromU128(
|
74
|
+
if (vaultData.debtProductSnapshotBytes) {
|
75
|
+
this.debtProductSnapshotBytes = DecimalFromU128(vaultData.debtProductSnapshotBytes.toString())
|
62
76
|
}
|
63
|
-
if (
|
64
|
-
this.collateralAccumulatorSnapshotBytes = DecimalFromU128(
|
77
|
+
if (vaultData.collateralAccumulatorSnapshotBytes) {
|
78
|
+
this.collateralAccumulatorSnapshotBytes = DecimalFromU128(vaultData.collateralAccumulatorSnapshotBytes.toString())
|
65
79
|
}
|
66
|
-
this.vaultTypeName =
|
67
|
-
this.nextVaultToRedeem =
|
80
|
+
this.vaultTypeName = vaultData.vaultTypeName
|
81
|
+
this.nextVaultToRedeem = vaultData.nextVaultToRedeem
|
68
82
|
|
69
|
-
if (
|
70
|
-
this.vaultStatus = Object.keys(
|
83
|
+
if (vaultData.vaultStatus) {
|
84
|
+
this.vaultStatus = Object.keys(vaultData.vaultStatus)[0]
|
71
85
|
}
|
72
|
-
this.vaultType =
|
86
|
+
this.vaultType = vaultData.vaultType
|
73
87
|
}
|
74
88
|
|
75
89
|
/**
|
@@ -1,14 +1,11 @@
|
|
1
|
-
import {
|
2
|
-
import { PublicKey
|
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(
|
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: {
|