hedge-web3 0.1.28 → 0.1.32
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/idl/vault.d.ts +277 -126
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/claimStakingPoolPosition.d.ts +3 -2
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/createStakingPool.d.ts +3 -2
- package/declarations/instructions/createVault.d.ts +6 -5
- package/declarations/instructions/depositLiquidationPool.d.ts +3 -2
- package/declarations/instructions/depositStakingPool.d.ts +3 -2
- package/declarations/instructions/depositVault.d.ts +3 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +3 -2
- package/declarations/instructions/liquidateVault.d.ts +3 -2
- package/declarations/instructions/loanVault.d.ts +3 -2
- package/declarations/instructions/redeemVault.d.ts +3 -2
- package/declarations/instructions/refreshOraclePrice.d.ts +3 -2
- package/declarations/instructions/repayVault.d.ts +3 -2
- package/declarations/instructions/setHalted.d.ts +3 -2
- package/declarations/instructions/setVaultTypeStatus.d.ts +3 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
- package/declarations/instructions/withdrawVault.d.ts +3 -2
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -1
- package/lib/idl/vault.js +277 -126
- package/lib/index.js +1 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +19 -22
- package/lib/instructions/claimStakingPoolPosition.js +19 -19
- package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
- package/lib/instructions/createStakingPool.js +17 -18
- package/lib/instructions/createVault.js +28 -31
- package/lib/instructions/depositLiquidationPool.js +17 -18
- package/lib/instructions/depositStakingPool.js +16 -18
- package/lib/instructions/depositVault.js +25 -27
- package/lib/instructions/initHedgeFoundation.js +17 -19
- package/lib/instructions/initHedgeFoundationTokens.js +15 -15
- package/lib/instructions/liquidateVault.js +32 -33
- package/lib/instructions/loanVault.js +23 -23
- package/lib/instructions/redeemVault.js +24 -24
- package/lib/instructions/refreshOraclePrice.js +17 -17
- package/lib/instructions/repayVault.js +23 -23
- package/lib/instructions/setHalted.js +8 -9
- package/lib/instructions/setVaultTypeStatus.js +9 -10
- package/lib/instructions/withdrawStakingPool.js +22 -24
- package/lib/instructions/withdrawVault.js +23 -23
- package/lib/state/LiquidationPoolEra.js +3 -1
- package/lib/state/LiquidationPosition.js +0 -7
- package/lib/state/StakingPool.js +3 -4
- package/lib/state/VaultAccount.js +2 -5
- package/lib/utils/getLinkedListAccounts.js +24 -16
- package/package.json +1 -1
- package/src/idl/vault.ts +554 -252
- package/src/index.ts +1 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +39 -29
- package/src/instructions/claimStakingPoolPosition.ts +45 -25
- package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
- package/src/instructions/createStakingPool.ts +37 -35
- package/src/instructions/createVault.ts +81 -125
- package/src/instructions/depositLiquidationPool.ts +45 -26
- package/src/instructions/depositStakingPool.ts +32 -24
- package/src/instructions/depositVault.ts +57 -86
- package/src/instructions/initHedgeFoundation.ts +42 -43
- package/src/instructions/initHedgeFoundationTokens.ts +38 -39
- package/src/instructions/liquidateVault.ts +42 -65
- package/src/instructions/loanVault.ts +51 -69
- package/src/instructions/redeemVault.ts +83 -47
- package/src/instructions/refreshOraclePrice.ts +41 -32
- package/src/instructions/repayVault.ts +45 -65
- package/src/instructions/setHalted.ts +32 -24
- package/src/instructions/setVaultTypeStatus.ts +32 -24
- package/src/instructions/withdrawStakingPool.ts +44 -30
- package/src/instructions/withdrawVault.ts +58 -82
- package/src/state/LiquidationPoolEra.ts +4 -3
- package/src/state/LiquidationPosition.ts +0 -27
- package/src/state/StakingPool.ts +4 -7
- package/src/state/StakingPoolPosition.ts +2 -3
- package/src/state/VaultAccount.ts +9 -28
- package/src/state/VaultHistoryEvent.ts +1 -2
- package/src/utils/getLinkedListAccounts.ts +31 -30
@@ -1,27 +1,24 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { PublicKey, Signer } from '@solana/web3.js'
|
3
3
|
import _ from 'underscore'
|
4
|
-
import {
|
5
|
-
getVaultSystemStatePublicKey,
|
6
|
-
getVaultTypeOracleAccountPublicKey,
|
7
|
-
} from '../Constants'
|
4
|
+
import { getVaultSystemStatePublicKey, getVaultTypeOracleAccountPublicKey } from '../Constants'
|
8
5
|
|
9
6
|
import { DecimalFromU128 } from '../HedgeDecimal'
|
10
7
|
import { VaultAccount } from '../state/VaultAccount'
|
11
8
|
import Decimal from 'decimal.js'
|
9
|
+
import { Vault } from 'idl/vault'
|
12
10
|
export async function getLinkedListAccounts(
|
13
|
-
program: Program
|
11
|
+
program: Program<Vault>,
|
14
12
|
provider: Provider,
|
15
13
|
vaultTypeAccountPublicKey: PublicKey,
|
16
14
|
vaultPublicKey: PublicKey,
|
17
15
|
depositAmount: number,
|
18
16
|
loanAmount: number,
|
19
17
|
redeem: boolean,
|
20
|
-
liquidate: boolean
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
)
|
18
|
+
liquidate: boolean,
|
19
|
+
cachedVaults?: VaultAccount[]
|
20
|
+
): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]> {
|
21
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
25
22
|
|
26
23
|
// Default for null is the vault itself, so set them all to this vault
|
27
24
|
let oldSmallerPublicKey = vaultPublicKey
|
@@ -32,21 +29,27 @@ export async function getLinkedListAccounts(
|
|
32
29
|
const thisVault = new VaultAccount(thisVaultData, vaultPublicKey)
|
33
30
|
|
34
31
|
// Load all the vaults
|
35
|
-
let
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
let vaults
|
33
|
+
if (cachedVaults) {
|
34
|
+
vaults = cachedVaults
|
35
|
+
} else {
|
36
|
+
let allVaults = cachedVaults
|
37
|
+
? cachedVaults
|
38
|
+
: (await program.account.vault
|
39
|
+
.all([
|
40
|
+
// {
|
41
|
+
// memcmp: { bytes: bs58.encode(inputCollateralType), offset: 8 + 32 + 8 },
|
42
|
+
// },
|
43
|
+
])
|
44
|
+
.catch((error) => {
|
45
|
+
console.log('error', error)
|
46
|
+
})) || []
|
47
|
+
|
48
|
+
// Load them into our account objects
|
49
|
+
vaults = allVaults.map((vault) => {
|
50
|
+
return new VaultAccount(vault.account, vault.publicKey)
|
51
|
+
})
|
52
|
+
}
|
50
53
|
|
51
54
|
// Filter out the account that are not the same vault type
|
52
55
|
vaults = _.filter(vaults, (vault) => {
|
@@ -89,9 +92,8 @@ export async function getLinkedListAccounts(
|
|
89
92
|
// Now that we know it's def in the list, iterate the list and update
|
90
93
|
// this vault with the opeation we're going to apply
|
91
94
|
const newNormalizedDebt = new Decimal(loanAmount)
|
92
|
-
const vaultTypeCompoundedInterest = DecimalFromU128(
|
93
|
-
|
94
|
-
)
|
95
|
+
const vaultTypeCompoundedInterest = DecimalFromU128(vaultTypeAccount.cumulativeRate.toString())
|
96
|
+
vaults[indexBefore].updateDebtAndCollateral(vaultTypeAccount)
|
95
97
|
vaults[indexBefore].addDebt(newNormalizedDebt, vaultTypeCompoundedInterest)
|
96
98
|
vaults[indexBefore].addDeposit(depositAmount)
|
97
99
|
|
@@ -101,7 +103,6 @@ export async function getLinkedListAccounts(
|
|
101
103
|
if (redeem) {
|
102
104
|
vaults[indexBefore].redeem()
|
103
105
|
}
|
104
|
-
vaults[indexBefore].redistribution(vaultTypeAccount)
|
105
106
|
|
106
107
|
if (vaults[indexBefore].denormalizedDebt === 0) {
|
107
108
|
vaults.splice(indexBefore, 1)
|
@@ -141,7 +142,7 @@ export async function getLinkedListAccounts(
|
|
141
142
|
// console.log('newSmallerPublicKey', newSmallerPublicKey.toString())
|
142
143
|
// console.log('newLargerPublicKey', newLargerPublicKey.toString())
|
143
144
|
|
144
|
-
return [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey]
|
145
|
+
return [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaults]
|
145
146
|
}
|
146
147
|
|
147
148
|
// Sort function we can use to sort the vaults
|