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,56 @@
1
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
2
+ import { PublicKey } from '@solana/web3.js'
3
+
4
+ export const HEDGE_PROGRAM_ID = 'fff6FuPWrBPzFHeWwtBQaPjKvMvW27w8Jf4P7SSoueX'
5
+ export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
6
+
7
+ export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
8
+ export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
9
+
10
+ export async function getPoolStatePublicKey (): Promise<[PublicKey, number]> {
11
+ const enc = new TextEncoder()
12
+ const [poolPublicKey, bump] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY)
13
+ return [poolPublicKey, bump]
14
+ }
15
+
16
+ export async function getPoolUsdhAccountPublicKey (): Promise<[PublicKey, number]> {
17
+ const enc = new TextEncoder()
18
+ const [poolPublicKey, bump] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY)
19
+ return [poolPublicKey, bump]
20
+ }
21
+
22
+ export async function getUsdhMintPublicKey (): Promise<[PublicKey, number]> {
23
+ const enc = new TextEncoder()
24
+ const [findMintPublicKey, bump] = await PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY)
25
+ return [findMintPublicKey, bump]
26
+ }
27
+
28
+ export async function getVaultSystemStatePublicKey (): Promise<[PublicKey, number]> {
29
+ const enc = new TextEncoder()
30
+ const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY)
31
+ return [publicKey, bump]
32
+ }
33
+
34
+ export async function getHedgeMintPublicKey (): Promise<[PublicKey, number]> {
35
+ const enc = new TextEncoder()
36
+ const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY)
37
+ return [publicKey, bump]
38
+ }
39
+
40
+ export async function getPoolPublicKeyForMint (mintPublicKey: PublicKey): Promise<[PublicKey, number, string]> {
41
+ const enc = new TextEncoder()
42
+ const strToEncode = (mintPublicKey.toString().substring(0, 12))
43
+ const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY)
44
+ return [publicKey, bump, strToEncode]
45
+ }
46
+
47
+ export async function findAssociatedTokenAddress (walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey> {
48
+ return (await PublicKey.findProgramAddress(
49
+ [
50
+ walletAddress.toBuffer(),
51
+ TOKEN_PROGRAM_ID.toBuffer(),
52
+ tokenMintAddress.toBuffer()
53
+ ],
54
+ ASSOCIATED_TOKEN_PROGRAM_ID
55
+ ))[0]
56
+ }
@@ -1,10 +1,18 @@
1
1
  import Decimal from 'decimal.js'
2
2
 
3
- export class HedgeDecimal {
4
- public value: Decimal
5
-
6
- constructor (val: Number) {
7
- this.value = new Decimal(val.toString())
8
- this.value = this.value.div(new Decimal('1e+24'))
9
- }
3
+ /**
4
+ * Convert a U128 to a Decimal
5
+ *
6
+ * On chain, u128s are used to store Decimal numbers. These values
7
+ * are simply stored as u128 where the actual value is divided by
8
+ * 1.0e+24. This gives 24 digits of percision on decimal numbers.
9
+ *
10
+ * Example: the number 1.5 is stored as a u128: 1.5 * 10^24
11
+ *
12
+ * @param value the value to be converted to Decimal
13
+ * @returns the converted value as a decimal.js object
14
+ */
15
+ export function DecimalFromU128 (value: number|string): Decimal {
16
+ const adjustedValue = new Decimal(value.toString())
17
+ return adjustedValue.div(new Decimal('1e+24'))
10
18
  }