hedge-web3 0.1.0 → 0.1.4
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/.github/workflows/npm-publish.yml +34 -0
- package/README.md +44 -0
- package/lib/index.js +1976 -0
- package/lib/index.js.map +1 -0
- package/lib/types/src/Constants.d.ts +13 -0
- package/lib/types/src/Constants.d.ts.map +1 -0
- package/lib/types/src/HedgeDecimal.d.ts +15 -0
- package/lib/types/src/HedgeDecimal.d.ts.map +1 -0
- package/lib/types/src/StakingPools.d.ts +4 -0
- package/lib/types/src/StakingPools.d.ts.map +1 -0
- package/lib/types/src/Vaults.d.ts +9 -0
- package/lib/types/src/Vaults.d.ts.map +1 -0
- package/lib/types/src/idl/idl.d.ts +3 -0
- package/lib/types/src/idl/idl.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +5 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/instructions/createStakingPool.d.ts +4 -0
- package/lib/types/src/instructions/createStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/createVault.d.ts +4 -0
- package/lib/types/src/instructions/createVault.d.ts.map +1 -0
- package/lib/types/src/instructions/depositStakingPool.d.ts +4 -0
- package/lib/types/src/instructions/depositStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/depositVault.d.ts +4 -0
- package/lib/types/src/instructions/depositVault.d.ts.map +1 -0
- package/lib/types/src/instructions/liquidateVault.d.ts +4 -0
- package/lib/types/src/instructions/liquidateVault.d.ts.map +1 -0
- package/lib/types/src/instructions/loanVault.d.ts +4 -0
- package/lib/types/src/instructions/loanVault.d.ts.map +1 -0
- package/lib/types/src/instructions/redeemVault.d.ts +4 -0
- package/lib/types/src/instructions/redeemVault.d.ts.map +1 -0
- package/lib/types/src/instructions/repayVault.d.ts +4 -0
- package/lib/types/src/instructions/repayVault.d.ts.map +1 -0
- package/lib/types/src/instructions/withdrawStakingPool.d.ts +4 -0
- package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/withdrawVault.d.ts +4 -0
- package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -0
- package/lib/types/src/state/LiquidationPoolEra.d.ts +15 -0
- package/lib/types/src/state/LiquidationPoolEra.d.ts.map +1 -0
- package/lib/types/src/state/LiquidationPoolState.d.ts +7 -0
- package/lib/types/src/state/LiquidationPoolState.d.ts.map +1 -0
- package/lib/types/src/state/LiquidationPosition.d.ts +24 -0
- package/lib/types/src/state/LiquidationPosition.d.ts.map +1 -0
- package/lib/types/src/state/StakingPool.d.ts +17 -0
- package/lib/types/src/state/StakingPool.d.ts.map +1 -0
- package/lib/types/src/state/StakingPoolPosition.d.ts +19 -0
- package/lib/types/src/state/StakingPoolPosition.d.ts.map +1 -0
- package/lib/types/src/state/VaultAccount.d.ts +48 -0
- package/lib/types/src/state/VaultAccount.d.ts.map +1 -0
- package/lib/types/src/state/VaultHistoryEvent.d.ts +40 -0
- package/lib/types/src/state/VaultHistoryEvent.d.ts.map +1 -0
- package/lib/types/src/utils/Errors.d.ts +2 -0
- package/lib/types/src/utils/Errors.d.ts.map +1 -0
- package/lib/types/tsconfig.base.tsbuildinfo +1 -0
- package/package.json +6 -6
- package/rollup.config.js +14 -8
- package/src/Constants.ts +56 -0
- package/src/HedgeDecimal.ts +15 -7
- package/src/StakingPools.ts +3 -0
- package/src/Vaults.ts +8 -0
- package/src/idl/idl.ts +1474 -0
- package/src/index.ts +3 -5
- package/src/instructions/createStakingPool.ts +65 -0
- package/src/instructions/createVault.ts +66 -0
- package/src/instructions/depositStakingPool.ts +61 -0
- package/src/instructions/depositVault.ts +61 -0
- package/src/instructions/liquidateVault.ts +67 -0
- package/src/instructions/loanVault.ts +79 -0
- package/src/instructions/redeemVault.ts +83 -0
- package/src/instructions/repayVault.ts +74 -0
- package/src/instructions/withdrawStakingPool.ts +70 -0
- package/src/instructions/withdrawVault.ts +66 -0
- package/src/state/LiquidationPoolEra.ts +29 -0
- package/src/state/LiquidationPoolState.ts +10 -0
- package/src/state/LiquidationPosition.ts +69 -0
- package/src/state/StakingPool.ts +39 -0
- package/src/state/StakingPoolPosition.ts +40 -0
- package/src/state/VaultAccount.ts +77 -0
- package/src/state/VaultHistoryEvent.ts +61 -0
- package/src/types/buffer-layout/index.d.ts +88 -0
- package/src/utils/Errors.ts +11 -0
- package/tsconfig.base.json +3 -3
- package/tsconfig.d.json +3 -1
- package/tsconfig.json +1 -1
- package/src/accounts/LiquidationPoolEra.ts +0 -16
- package/src/accounts/LiquidationPoolState.ts +0 -22
- package/src/accounts/LiquidationPosition.ts +0 -72
- package/src/accounts/StakingPool.ts +0 -31
- package/src/accounts/StakingPoolPosition.ts +0 -29
- package/src/accounts/VaultAccount.ts +0 -40
- package/src/accounts/VaultHistoryEvent.ts +0 -27
@@ -1,31 +0,0 @@
|
|
1
|
-
// import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
|
2
|
-
// import Decimal from 'decimal.js'
|
3
|
-
|
4
|
-
import { PublicKey } from '@solana/web3.js';
|
5
|
-
|
6
|
-
// import { WAD } from './HedgeConstants'
|
7
|
-
|
8
|
-
export class StakingPool {
|
9
|
-
constructor (public poolInfo: any, key: PublicKey) {
|
10
|
-
// this.publicKey = key
|
11
|
-
// this.deposits = poolInfo.deposits.toNumber()
|
12
|
-
// // this.totalFeesNow = poolInfo.totalFeesNow.toNumber()
|
13
|
-
// // this.totalFeesPrevious = poolInfo.totalFeesPrevious.toNumber()
|
14
|
-
// this.lastTransactionTime = poolInfo.lastTransactionTime.toNumber()
|
15
|
-
// this.startTime = poolInfo.startTime.toNumber()
|
16
|
-
// this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber()
|
17
|
-
// this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber()
|
18
|
-
|
19
|
-
// this.hedgeRewardAccumulator = byteArrayToFloat64(poolInfo.hedgeRewardAccumulator)
|
20
|
-
// this.usdhFeeAccumulator = byteArrayToFloat64(poolInfo.usdhFeeAccumulator)
|
21
|
-
// this.solFeeAccumulator = byteArrayToFloat64(poolInfo.solFeeAccumulator)
|
22
|
-
// this.currentRewardsPerDay = byteArrayToFloat64(poolInfo.currentRewardsPerDay)
|
23
|
-
|
24
|
-
// // "stakedTokenMint": { missing
|
25
|
-
}
|
26
|
-
|
27
|
-
// updateFeeAccumulator () {
|
28
|
-
// this.feeAccumulator = (this.totalFeesNow - this.totalFeesPrevious) / this.deposits
|
29
|
-
// this.totalFeesPrevious = this.totalFeesNow
|
30
|
-
// }
|
31
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
// import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
|
2
|
-
// import Decimal from 'decimal.js'
|
3
|
-
|
4
|
-
import { PublicKey } from '@solana/web3.js'
|
5
|
-
import { StakingPool } from './StakingPool'
|
6
|
-
|
7
|
-
// import { WAD } from './HedgeConstants'
|
8
|
-
|
9
|
-
export class StakingPoolPosition {
|
10
|
-
constructor (public poolPositionInfo: any, key: PublicKey, stakingPool: StakingPool) {
|
11
|
-
// this.open = !!poolPositionInfo.state.open
|
12
|
-
// this.publicKey = key
|
13
|
-
// this.pool = stakingPool
|
14
|
-
// this.owner = poolPositionInfo.owner
|
15
|
-
// this.deposited = poolPositionInfo.deposited.toNumber()
|
16
|
-
// this.timestampOpened = poolPositionInfo.timestampOpened.toNumber()
|
17
|
-
// this.timestampClosed = poolPositionInfo.timestampClosed.toNumber()
|
18
|
-
// this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber()
|
19
|
-
|
20
|
-
// this.startHedgeRewardAccumulator = byteArrayToFloat64(poolPositionInfo.startHedgeRewardAccumulator)
|
21
|
-
// this.startUsdhFeeAccumulator = byteArrayToFloat64(poolPositionInfo.startUsdhFeeAccumulator)
|
22
|
-
// this.startSolFeeAccumulator = byteArrayToFloat64(poolPositionInfo.startSolFeeAccumulator)
|
23
|
-
}
|
24
|
-
|
25
|
-
// getCurrentUsdhFeeReward () {
|
26
|
-
// const feesAccured = (this.pool.usdhFeeAccumulator - this.startUsdhFeeAccumulator) * this.deposited
|
27
|
-
// return feesAccured
|
28
|
-
// }
|
29
|
-
}
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
|
2
|
-
import { HedgeDecimal } from '../HedgeDecimal'
|
3
|
-
|
4
|
-
export class VaultAccount {
|
5
|
-
publicKey: PublicKey
|
6
|
-
vaultOwner: PublicKey
|
7
|
-
debt: number
|
8
|
-
deposited: number
|
9
|
-
minCollateralRatio: HedgeDecimal
|
10
|
-
liquidationPrice: number
|
11
|
-
vaultStatus: string
|
12
|
-
|
13
|
-
constructor (vault: any
|
14
|
-
, publicKey: PublicKey) {
|
15
|
-
this.publicKey = publicKey
|
16
|
-
this.vaultOwner = vault.vaultOwner
|
17
|
-
this.debt = vault.debt.toNumber()
|
18
|
-
this.deposited = vault.deposited.toNumber()
|
19
|
-
this.minCollateralRatio = vault.minCollateralRatio.toNumber()
|
20
|
-
this.liquidationPrice = vault.liquidationPrice.toNumber()
|
21
|
-
this.minCollateralRatio = vault.minCollateralRatio.toNumber()
|
22
|
-
this.vaultStatus = Object.keys(vault.vaultStatus)[0]
|
23
|
-
}
|
24
|
-
|
25
|
-
public isOwnedBy (publicKey: PublicKey): boolean {
|
26
|
-
return publicKey.toString() === this.vaultOwner.toString()
|
27
|
-
}
|
28
|
-
|
29
|
-
public inSol (): number {
|
30
|
-
return this.deposited / LAMPORTS_PER_SOL
|
31
|
-
}
|
32
|
-
|
33
|
-
public inUsd (): number {
|
34
|
-
return this.debt / LAMPORTS_PER_SOL
|
35
|
-
}
|
36
|
-
|
37
|
-
public toDisplayString (): string {
|
38
|
-
return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey.toString().substring(this.publicKey.toString().length - 6)}`
|
39
|
-
}
|
40
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
// import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
|
2
|
-
// import Decimal from 'decimal.js'
|
3
|
-
|
4
|
-
import { PublicKey } from '@solana/web3.js'
|
5
|
-
|
6
|
-
// import { WAD } from './HedgeConstants'
|
7
|
-
|
8
|
-
export class VaultHistoryEvent {
|
9
|
-
constructor (public account: any, publicKey: PublicKey) {
|
10
|
-
// this.publicKey = publicKey
|
11
|
-
// this.actorAccount = account.actorAccount
|
12
|
-
|
13
|
-
// this.usdSolPrice = (new Decimal(account.usdSolPrice.toString())).dividedBy(WAD)
|
14
|
-
|
15
|
-
// this.usdhDebtBefore = account.usdhDebtBefore.toNumber()
|
16
|
-
// this.usdhDebtAfter = account.usdhDebtAfter.toNumber()
|
17
|
-
// this.solBalanceBefore = account.solBalanceBefore.toNumber()
|
18
|
-
// this.solBalanceAfter = account.solBalanceAfter.toNumber()
|
19
|
-
// this.minCollateralRatioBefore = account.minCollateralRatioBefore.toNumber()
|
20
|
-
// this.minCollateralRatioAfter = account.minCollateralRatioAfter.toNumber()
|
21
|
-
// this.vaultStateBefore = Object.keys(account.vaultStateBefore)[0]
|
22
|
-
// this.vaultStateAfter = Object.keys(account.vaultStateAfter)[0]
|
23
|
-
|
24
|
-
// this.timestamp = account.timestamp.toNumber()
|
25
|
-
// this.action = Object.keys(account.action)[0]
|
26
|
-
}
|
27
|
-
}
|