hedge-web3 0.1.1 → 0.1.2

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 (66) hide show
  1. package/lib/index.js +1790 -0
  2. package/lib/index.js.map +1 -0
  3. package/lib/types/src/Constants.d.ts +13 -0
  4. package/lib/types/src/Constants.d.ts.map +1 -0
  5. package/lib/types/src/HedgeDecimal.d.ts +15 -0
  6. package/lib/types/src/HedgeDecimal.d.ts.map +1 -0
  7. package/lib/types/src/idl/idl.d.ts +3 -0
  8. package/lib/types/src/idl/idl.d.ts.map +1 -0
  9. package/lib/types/src/index.d.ts +10 -0
  10. package/lib/types/src/index.d.ts.map +1 -0
  11. package/lib/types/src/instructions/createVault.d.ts +4 -0
  12. package/lib/types/src/instructions/createVault.d.ts.map +1 -0
  13. package/lib/types/src/instructions/depositVault.d.ts +4 -0
  14. package/lib/types/src/instructions/depositVault.d.ts.map +1 -0
  15. package/lib/types/src/instructions/loanVault.d.ts +4 -0
  16. package/lib/types/src/instructions/loanVault.d.ts.map +1 -0
  17. package/lib/types/src/instructions/redeemVault.d.ts +4 -0
  18. package/lib/types/src/instructions/redeemVault.d.ts.map +1 -0
  19. package/lib/types/src/instructions/repayVault.d.ts +4 -0
  20. package/lib/types/src/instructions/repayVault.d.ts.map +1 -0
  21. package/lib/types/src/instructions/withdrawVault.d.ts +4 -0
  22. package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -0
  23. package/lib/types/src/state/LiquidationPoolEra.d.ts +15 -0
  24. package/lib/types/src/state/LiquidationPoolEra.d.ts.map +1 -0
  25. package/lib/types/src/state/LiquidationPoolState.d.ts +7 -0
  26. package/lib/types/src/state/LiquidationPoolState.d.ts.map +1 -0
  27. package/lib/types/src/state/LiquidationPosition.d.ts +24 -0
  28. package/lib/types/src/state/LiquidationPosition.d.ts.map +1 -0
  29. package/lib/types/src/state/StakingPool.d.ts +17 -0
  30. package/lib/types/src/state/StakingPool.d.ts.map +1 -0
  31. package/lib/types/src/state/StakingPoolPosition.d.ts +19 -0
  32. package/lib/types/src/state/StakingPoolPosition.d.ts.map +1 -0
  33. package/lib/types/src/state/VaultAccount.d.ts +48 -0
  34. package/lib/types/src/state/VaultAccount.d.ts.map +1 -0
  35. package/lib/types/src/state/VaultHistoryEvent.d.ts +40 -0
  36. package/lib/types/src/state/VaultHistoryEvent.d.ts.map +1 -0
  37. package/lib/types/tsconfig.base.tsbuildinfo +1 -0
  38. package/package.json +5 -4
  39. package/rollup.config.js +14 -8
  40. package/src/Constants.ts +56 -0
  41. package/src/HedgeDecimal.ts +15 -7
  42. package/src/idl/idl.ts +1474 -0
  43. package/src/index.ts +7 -1
  44. package/src/instructions/createVault.ts +66 -0
  45. package/src/instructions/depositVault.ts +61 -0
  46. package/src/instructions/loanVault.ts +79 -0
  47. package/src/instructions/redeemVault.ts +83 -0
  48. package/src/instructions/repayVault.ts +74 -0
  49. package/src/instructions/withdrawVault.ts +66 -0
  50. package/src/state/LiquidationPoolEra.ts +29 -0
  51. package/src/state/LiquidationPoolState.ts +10 -0
  52. package/src/state/LiquidationPosition.ts +69 -0
  53. package/src/state/StakingPool.ts +39 -0
  54. package/src/state/StakingPoolPosition.ts +40 -0
  55. package/src/{accounts → state}/VaultAccount.ts +5 -5
  56. package/src/state/VaultHistoryEvent.ts +61 -0
  57. package/tsconfig.base.json +3 -3
  58. package/tsconfig.d.json +3 -1
  59. package/tsconfig.json +1 -1
  60. package/typedoc.json +2 -1
  61. package/src/accounts/LiquidationPoolEra.ts +0 -16
  62. package/src/accounts/LiquidationPoolState.ts +0 -22
  63. package/src/accounts/LiquidationPosition.ts +0 -72
  64. package/src/accounts/StakingPool.ts +0 -31
  65. package/src/accounts/StakingPoolPosition.ts +0 -29
  66. package/src/accounts/VaultHistoryEvent.ts +0 -27
@@ -0,0 +1,61 @@
1
+
2
+ import { PublicKey } from '@solana/web3.js'
3
+ import Decimal from 'decimal.js'
4
+ import { DecimalFromU128 } from '..'
5
+
6
+ export class VaultHistoryEvent {
7
+ publicKey: PublicKey
8
+ actorAccount: PublicKey
9
+ usdSolPrice: Decimal
10
+ usdhDebtBefore: number
11
+ usdhDebtAfter: number
12
+ solBalanceBefore: number
13
+ solBalanceAfter: number
14
+ minCollateralRatioBefore: Decimal
15
+ minCollateralRatioAfter: Decimal
16
+ vaultStateBefore: PublicKey
17
+ vaultStateAfter: PublicKey
18
+ timestamp: PublicKey
19
+ action: VaultHistoryAction
20
+
21
+ constructor (public account: any, publicKey: PublicKey) {
22
+ this.publicKey = publicKey
23
+ this.actorAccount = account.actorAccount
24
+
25
+ this.usdSolPrice = DecimalFromU128(account.usdSolPrice.toString())
26
+
27
+ this.usdhDebtBefore = account.usdhDebtBefore.toNumber()
28
+ this.usdhDebtAfter = account.usdhDebtAfter.toNumber()
29
+ this.solBalanceBefore = account.solBalanceBefore.toNumber()
30
+ this.solBalanceAfter = account.solBalanceAfter.toNumber()
31
+ this.minCollateralRatioBefore = DecimalFromU128(account.minCollateralRatioBefore)
32
+ this.minCollateralRatioAfter = DecimalFromU128(account.minCollateralRatioAfter)
33
+ this.vaultStateBefore = account.vaultStateBefore
34
+ this.vaultStateAfter = account.vaultStateAfter
35
+
36
+ this.timestamp = account.timestamp.toNumber()
37
+ this.action = account.action
38
+ }
39
+ }
40
+
41
+ export enum VaultStatus {
42
+ Open,
43
+ Closed,
44
+ Liquidated,
45
+ Distributed,
46
+ Redeemed,
47
+ }
48
+
49
+ export enum VaultHistoryAction {
50
+ Create,
51
+ Close,
52
+ Liquidate,
53
+ PartialLiquidate,
54
+ Distributed,
55
+ Redeem,
56
+ TransferOwnership,
57
+ Deposit,
58
+ Withdraw,
59
+ Loan,
60
+ RepayCredit,
61
+ }
@@ -11,8 +11,6 @@
11
11
  "emitDecoratorMetadata": true,
12
12
  "noImplicitAny": false,
13
13
  "strictNullChecks": true,
14
- "esModuleInterop": true,
15
- "resolveJsonModule": true,
16
14
  "composite": true,
17
15
  "baseUrl": ".",
18
16
  "typeRoots": [
@@ -23,6 +21,8 @@
23
21
  "@solana/web3.js": [
24
22
  "./node_modules/@solana/web3.js/lib"
25
23
  ]
26
- }
24
+ },
25
+ "resolveJsonModule": true,
26
+ "esModuleInterop": true
27
27
  }
28
28
  }
package/tsconfig.d.json CHANGED
@@ -2,7 +2,9 @@
2
2
  "extends": "./tsconfig.json",
3
3
  "compilerOptions": {
4
4
  "emitDeclarationOnly": true,
5
- "stripInternal": true
5
+ "stripInternal": true,
6
+ "resolveJsonModule": true,
7
+ "esModuleInterop": true,
6
8
  },
7
9
  "include": [
8
10
  "./src/**/*"
package/tsconfig.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "isolatedModules": true,
15
15
  "baseUrl": "src",
16
16
  "noFallthroughCasesInSwitch": true,
17
- "noImplicitReturns": true
17
+ "noImplicitReturns": true,
18
18
  },
19
19
  "include": ["src"]
20
20
  }
package/typedoc.json CHANGED
@@ -2,5 +2,6 @@
2
2
  "entryPoints": ["src/index.ts"],
3
3
  "excludeInternal": true,
4
4
  "excludePrivate": true,
5
- "out": "doc"
5
+ "out": "doc",
6
+ "externalPattern": "./node_modules/**"
6
7
  }
@@ -1,16 +0,0 @@
1
- // import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
2
- // import Decimal from 'decimal.js'
3
-
4
- // import { WAD } from './HedgeConstants'
5
-
6
- export class LiquidationPoolEra {
7
- constructor (public liquidyPoolEra: any) {
8
- // this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber()
9
-
10
- // this.product = byteArrayToFloat64(liquidyPoolEra.productBytes)
11
- // this.sum = byteArrayToFloat64(liquidyPoolEra.sumBytes)
12
- // this.hedgeRewardsAccumulator = byteArrayToFloat64(liquidyPoolEra.hedgeRewardsAccumulatorBytes)
13
-
14
- // this.hedgeRewardsTimestamp = liquidyPoolEra.hedgeRewardsTimestamp.toNumber()
15
- }
16
- }
@@ -1,22 +0,0 @@
1
- // import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
2
- // import Decimal from 'decimal.js'
3
-
4
- // import { WAD } from './HedgeConstants'
5
-
6
- export class LiquidationPoolState {
7
- constructor (public liquidationPoolState: any) {
8
- // this.lifetimeDeposits = liquidationPoolState.lifetimeDeposits.toNumber()
9
- // this.hedgeInitRewardsTimestamp = liquidationPoolState.hedgeInitRewardsTimestamp.toNumber()
10
- // // TODO Add the rest that are missing. Do we need them?
11
- }
12
-
13
- // getCurrentHedgeRewardsPerDay () {
14
- // const dailyRate = hedgeRewardsDecay(
15
- // 2000000.0 * LAMPORTS_PER_SOL,
16
- // this.hedgeInitRewardsTimestamp * 1000,
17
- // Date.now(),
18
- // Date.now() + (24 * 60 * 60 * 1000),
19
- // 365 * 1000)
20
- // return dailyRate / LAMPORTS_PER_SOL
21
- // }
22
- }
@@ -1,72 +0,0 @@
1
- // import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
2
- // import Decimal from 'decimal.js'
3
- // import { LiquidationPoolEra, LiquidationPoolState } from '../Accounts';
4
-
5
- import { PublicKey } from '@solana/web3.js'
6
- import { LiquidationPoolEra } from './LiquidationPoolEra'
7
- import { LiquidationPoolState } from './LiquidationPoolState'
8
-
9
- // import { WAD } from './HedgeConstants'
10
-
11
- export class LiquidationPosition {
12
- // publicKey: PublicKey;
13
- // eraPublicKey: PublicKey;
14
- // era: LiquidationPoolEra;
15
- // liquidationPoolState: LiquidationPoolEra;
16
- // ownerAccount: PublicKey;
17
- // deposit: Decimal
18
- // closedUsdh: Decimal
19
- // closedSol: Decimal
20
- // timestampOpened: Date
21
- // timestampClosed: Date
22
-
23
- // productSnapshot: Decimal
24
- // sumSnapshot: Decimal
25
- // hedgeRewardsSnapshot: Decimal
26
- // open: Boolean
27
-
28
- constructor (public poolPositionInfo: any, key: PublicKey, era: LiquidationPoolEra, liquidationPoolState: LiquidationPoolState) {
29
- // this.publicKey = key
30
- // this.eraPublicKey = poolPositionInfo.era
31
- // this.era = era
32
- // this.liquidationPoolState = liquidationPoolState
33
- // this.ownerAccount = poolPositionInfo.ownerAccount
34
- // this.deposit = poolPositionInfo.deposit.toNumber()
35
- // this.closedUsdh = poolPositionInfo.closedUsdh.toNumber()
36
- // this.closedSol = poolPositionInfo.closedSol.toNumber()
37
- // this.timestampOpened = poolPositionInfo.timestampOpened.toNumber()
38
- // this.timestampClosed = poolPositionInfo.timestampClosed.toNumber()
39
-
40
- // this.productSnapshot = new Decimal(poolPositionInfo.productSnapshotBytes.toString())
41
- // this.sumSnapshot = byteArrayToFloat64(poolPositionInfo.sumSnapshotBytes)
42
- // this.hedgeRewardsSnapshot = byteArrayToFloat64(poolPositionInfo.hedgeRewardsSnapshotAccum)
43
- // this.open = !!poolPositionInfo.state.open
44
- }
45
-
46
- // getUsdhAvailable () {
47
- // return (this.deposit * (this.era.product / this.productSnapshot))
48
- // }
49
-
50
- // getSolAvailable () {
51
- // return Math.floor(this.deposit * ((this.era.sum - this.sumSnapshot) / this.productSnapshot))
52
- // }
53
-
54
- // getHedgeAvailable () {
55
- // const LiquidationPoolTotalSupply = 2000000.0 * LAMPORTS_PER_SOL
56
- // const hedgeRewardsSinceLastUpdate = hedgeRewardsDecay(
57
- // LiquidationPoolTotalSupply,
58
- // this.liquidationPoolState.hedgeInitRewardsTimestamp * 1000,
59
- // this.era.hedgeRewardsTimestamp * 1000,
60
- // Date.now(),
61
- // 365 * 1000)
62
-
63
- // if (this.era.totalDeposits === 0) {
64
- // return 0
65
- // }
66
-
67
- // const rewardsPerToken = hedgeRewardsSinceLastUpdate / this.era.totalDeposits * this.era.product
68
- // const newAccumulator = this.era.hedgeRewardsAccumulator + rewardsPerToken
69
- // const hedgeAvailable = (newAccumulator - this.hedgeRewardsSnapshot) * this.deposit / this.productSnapshot
70
- // return hedgeAvailable
71
- // }
72
- }
@@ -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,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
- }