hedge-web3 0.1.23 → 0.1.27

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 (62) hide show
  1. package/declarations/Constants.d.ts +3 -3
  2. package/declarations/idl/vault.d.ts +889 -752
  3. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
  4. package/declarations/instructions/createVault.d.ts +1 -1
  5. package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
  6. package/declarations/instructions/depositVault.d.ts +1 -1
  7. package/declarations/instructions/liquidateVault.d.ts +1 -1
  8. package/declarations/instructions/loanVault.d.ts +1 -1
  9. package/declarations/instructions/redeemVault.d.ts +1 -1
  10. package/declarations/instructions/repayVault.d.ts +1 -1
  11. package/declarations/instructions/withdrawVault.d.ts +1 -1
  12. package/declarations/state/LiquidationPosition.d.ts +2 -2
  13. package/declarations/state/StakingPool.d.ts +1 -1
  14. package/declarations/state/StakingPoolPosition.d.ts +2 -2
  15. package/declarations/state/VaultAccount.d.ts +3 -3
  16. package/declarations/state/VaultHistoryEvent.d.ts +2 -2
  17. package/lib/Constants.js +10 -10
  18. package/lib/idl/vault.js +922 -785
  19. package/lib/instructions/closeLiquidationPoolPosition.js +9 -9
  20. package/lib/instructions/createStakingPool.js +4 -4
  21. package/lib/instructions/createVault.js +11 -11
  22. package/lib/instructions/depositLiquidationPool.js +9 -9
  23. package/lib/instructions/depositVault.js +8 -8
  24. package/lib/instructions/initHedgeFoundation.js +4 -4
  25. package/lib/instructions/liquidateVault.js +9 -9
  26. package/lib/instructions/loanVault.js +9 -9
  27. package/lib/instructions/redeemVault.js +10 -10
  28. package/lib/instructions/repayVault.js +10 -10
  29. package/lib/instructions/withdrawStakingPool.js +6 -6
  30. package/lib/instructions/withdrawVault.js +8 -8
  31. package/lib/state/LiquidationPosition.js +2 -2
  32. package/lib/state/StakingPool.js +1 -1
  33. package/lib/state/StakingPoolPosition.js +3 -3
  34. package/lib/state/VaultAccount.js +2 -2
  35. package/lib/state/VaultHistoryEvent.js +2 -2
  36. package/lib/utils/Errors.js +2 -2
  37. package/package.json +8 -9
  38. package/src/Constants.ts +73 -31
  39. package/src/idl/vault.ts +1848 -1574
  40. package/src/instructions/closeLiquidationPoolPosition.ts +10 -10
  41. package/src/instructions/createStakingPool.ts +5 -5
  42. package/src/instructions/createVault.ts +17 -17
  43. package/src/instructions/depositLiquidationPool.ts +10 -10
  44. package/src/instructions/depositVault.ts +12 -12
  45. package/src/instructions/initHedgeFoundation.ts +5 -5
  46. package/src/instructions/initHedgeFoundationTokens.ts +1 -1
  47. package/src/instructions/liquidateVault.ts +10 -10
  48. package/src/instructions/loanVault.ts +11 -11
  49. package/src/instructions/redeemVault.ts +12 -12
  50. package/src/instructions/repayVault.ts +12 -12
  51. package/src/instructions/setHalted.ts +1 -1
  52. package/src/instructions/withdrawStakingPool.ts +7 -7
  53. package/src/instructions/withdrawVault.ts +12 -12
  54. package/src/state/LiquidationPosition.ts +3 -3
  55. package/src/state/StakingPool.ts +2 -6
  56. package/src/state/StakingPoolPosition.ts +4 -4
  57. package/src/state/VaultAccount.ts +3 -3
  58. package/src/state/VaultHistoryEvent.ts +4 -4
  59. package/src/utils/Errors.ts +2 -2
  60. package/declarations/idl/idl.d.ts +0 -2
  61. package/lib/idl/idl.js +0 -1475
  62. package/src/idl/idl.ts +0 -1474
@@ -14,7 +14,7 @@ class StakingPool {
14
14
  this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber();
15
15
  this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber();
16
16
  this.hedgeRewardAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.hedgeRewardAccumulator);
17
- this.usdhFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.usdhFeeAccumulator);
17
+ this.ushFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.ushFeeAccumulator);
18
18
  this.collateralFeeAccumulator = poolInfo.collateralFeeAccumulator.map((sum) => { return (0, HedgeDecimal_1.DecimalFromU128)(sum); });
19
19
  // this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
20
20
  }
@@ -17,12 +17,12 @@ class StakingPoolPosition {
17
17
  this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
18
18
  this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber();
19
19
  this.startHedgeRewardAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startHedgeRewardAccumulator);
20
- this.startUsdhFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startUsdhFeeAccumulator);
20
+ this.startUshFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startUshFeeAccumulator);
21
21
  this.startSolFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startSolFeeAccumulator);
22
22
  this.open = poolPositionInfo.state.open !== undefined;
23
23
  }
24
- getCurrentUsdhFeeReward() {
25
- return this.pool.usdhFeeAccumulator.minus(this.startUsdhFeeAccumulator).times(new decimal_js_1.default(this.deposited));
24
+ getCurrentUshFeeReward() {
25
+ return this.pool.ushFeeAccumulator.minus(this.startUshFeeAccumulator).times(new decimal_js_1.default(this.deposited));
26
26
  }
27
27
  }
28
28
  exports.StakingPoolPosition = StakingPoolPosition;
@@ -36,9 +36,9 @@ class VaultAccount {
36
36
  return this.deposited / web3_js_1.LAMPORTS_PER_SOL;
37
37
  }
38
38
  /**
39
- * Get the debt value in USDH
39
+ * Get the debt value in USH
40
40
  *
41
- * @returns debt value in USDH
41
+ * @returns debt value in USH
42
42
  */
43
43
  inUsd() {
44
44
  return this.denormalizedDebt / web3_js_1.LAMPORTS_PER_SOL;
@@ -8,8 +8,8 @@ class VaultHistoryEvent {
8
8
  this.publicKey = publicKey;
9
9
  this.actorAccount = account.actorAccount;
10
10
  this.usdSolPrice = (0, HedgeDecimal_1.DecimalFromU128)(account.usdSolPrice.toString());
11
- this.usdhDebtBefore = account.usdhDebtBefore.toNumber();
12
- this.usdhDebtAfter = account.usdhDebtAfter.toNumber();
11
+ this.ushDebtBefore = account.ushDebtBefore.toNumber();
12
+ this.ushDebtAfter = account.ushDebtAfter.toNumber();
13
13
  this.collateralBalanceBefore = account.collateralBalanceBefore.toNumber();
14
14
  this.collateralBalanceAfter = account.collateralBalanceAfter.toNumber();
15
15
  this.minCollateralRatioBefore = (0, HedgeDecimal_1.DecimalFromU128)(account.minCollateralRatioBefore);
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseAnchorErrors = void 0;
4
4
  const anchor_1 = require("@project-serum/anchor");
5
- const idl_1 = require("../idl/idl");
5
+ const vault_1 = require("../idl/vault");
6
6
  function parseAnchorErrors(error) {
7
- const idlErrors = (0, anchor_1.parseIdlErrors)(idl_1.vaultIdl);
7
+ const idlErrors = (0, anchor_1.parseIdlErrors)(vault_1.IDL);
8
8
  const parsedError = anchor_1.ProgramError.parse(error, idlErrors);
9
9
  if (parsedError !== null) {
10
10
  throw parsedError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.23",
3
+ "version": "0.1.27",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
@@ -13,21 +13,20 @@
13
13
  },
14
14
  "author": "Chris Coudron <coudron@hedge.so>",
15
15
  "license": "ISC",
16
- "devDependencies": {
17
- "@rollup/plugin-typescript": "^8.3.0",
18
- "rollup": "^2.62.0",
19
- "ts-standard": "^11.0.0",
20
- "typedoc": "^0.22.10"
21
- },
22
16
  "dependencies": {
23
- "@project-serum/anchor": "^0.21.0",
17
+ "@project-serum/anchor": "^0.23.0",
24
18
  "@project-serum/serum": "^0.13.61",
19
+ "@rollup/plugin-typescript": "^8.3.0",
25
20
  "@solana/buffer-layout": "^4.0.0",
26
21
  "@solana/spl-token": "^0.2.0",
27
- "@solana/web3.js": "^1.35.0",
22
+ "@solana/web3.js": "^1.37.0",
23
+ "@types/bn.js": "^5.1.0",
28
24
  "@types/uuid": "^8.3.4",
29
25
  "bn.js": "^5.2.0",
30
26
  "decimal.js": "^10.3.1",
27
+ "rollup": "^2.62.0",
28
+ "ts-standard": "^11.0.0",
29
+ "typedoc": "^0.22.10",
31
30
  "typescript": "^4.5.5",
32
31
  "uuid": "^8.3.2"
33
32
  }
package/src/Constants.ts CHANGED
@@ -1,64 +1,106 @@
1
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
1
+ import {
2
+ ASSOCIATED_TOKEN_PROGRAM_ID,
3
+ TOKEN_PROGRAM_ID,
4
+ } from '@solana/spl-token'
2
5
  import { PublicKey } from '@solana/web3.js'
3
6
 
4
- export const HEDGE_PROGRAM_ID = 'h14ydGHkAt6vpBaxX461fgxGYsZjaf2K8Fqwm7Cn3ik'
7
+ export const HEDGE_PROGRAM_ID = 'HDG2DRczYGkTuYTwTYy1UUhXXucT2Ujede2j4bWEoE6p'
5
8
  export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
6
9
 
7
- export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
10
+ export const CHAINLINK_SOL_USD_ID =
11
+ 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
8
12
  export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
9
13
 
10
14
  const enc = new TextEncoder()
11
15
 
12
- export async function getLiquidationPoolStatePublicKey (): Promise<PublicKey> {
13
- const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY)
16
+ export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
17
+ const [poolPublicKey] = await PublicKey.findProgramAddress(
18
+ [enc.encode('LiquidationPoolStateV1')],
19
+ HEDGE_PROGRAM_PUBLICKEY
20
+ )
14
21
  return poolPublicKey
15
22
  }
16
23
 
17
- export async function getLiquidationPoolUsdhAccountPublicKey (): Promise<PublicKey> {
18
- const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY)
24
+ export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
25
+ const [poolPublicKey] = await PublicKey.findProgramAddress(
26
+ [enc.encode('LiquidationPoolUSHAccountV1')],
27
+ HEDGE_PROGRAM_PUBLICKEY
28
+ )
19
29
  return poolPublicKey
20
30
  }
21
31
 
22
- export async function getUsdhMintPublicKey (): Promise<PublicKey> {
23
- const [findMintPublicKey] = await PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY)
32
+ export async function getUshMintPublicKey(): Promise<PublicKey> {
33
+ const [findMintPublicKey] = await PublicKey.findProgramAddress(
34
+ [enc.encode('UshMintV1')],
35
+ HEDGE_PROGRAM_PUBLICKEY
36
+ )
24
37
  return findMintPublicKey
25
38
  }
26
39
 
27
- export async function getVaultSystemStatePublicKey (): Promise<PublicKey> {
28
- const [publicKey] = await PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY)
40
+ export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
41
+ const [publicKey] = await PublicKey.findProgramAddress(
42
+ [enc.encode('VaultSystemStateV1')],
43
+ HEDGE_PROGRAM_PUBLICKEY
44
+ )
29
45
  return publicKey
30
46
  }
31
47
 
32
- export async function getHedgeMintPublicKey (): Promise<PublicKey> {
33
- const [publicKey] = await PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY)
48
+ export async function getHedgeMintPublicKey(): Promise<PublicKey> {
49
+ const [publicKey] = await PublicKey.findProgramAddress(
50
+ [enc.encode('HEDGEMintV1')],
51
+ HEDGE_PROGRAM_PUBLICKEY
52
+ )
34
53
  return publicKey
35
54
  }
36
55
 
37
- export async function getPoolPublicKeyForMint (mintPublicKey: PublicKey): Promise<[PublicKey, number, string]> {
38
- const strToEncode = (mintPublicKey.toString().substring(0, 12))
39
- const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY)
56
+ export async function getPoolPublicKeyForMint(
57
+ mintPublicKey: PublicKey
58
+ ): Promise<[PublicKey, number, string]> {
59
+ const strToEncode = mintPublicKey.toString().substring(0, 12)
60
+ const [publicKey, bump] = await PublicKey.findProgramAddress(
61
+ [enc.encode(strToEncode)],
62
+ HEDGE_PROGRAM_PUBLICKEY
63
+ )
40
64
  return [publicKey, bump, strToEncode]
41
65
  }
42
- export async function getVaultTypeAccountPublicKey (collateralType: string): Promise<PublicKey> {
43
- const [vaultTypeAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY)
66
+ export async function getVaultTypeAccountPublicKey(
67
+ collateralType: string
68
+ ): Promise<PublicKey> {
69
+ const [vaultTypeAccount] = await PublicKey.findProgramAddress(
70
+ [enc.encode(collateralType), enc.encode('State')],
71
+ HEDGE_PROGRAM_PUBLICKEY
72
+ )
44
73
  return vaultTypeAccount
45
74
  }
46
- export async function getVaultTypeOracleAccountPublicKey (collateralType: string): Promise<PublicKey> {
47
- const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY)
75
+ export async function getVaultTypeOracleAccountPublicKey(
76
+ collateralType: string
77
+ ): Promise<PublicKey> {
78
+ const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress(
79
+ [enc.encode(collateralType), enc.encode('Oracle')],
80
+ HEDGE_PROGRAM_PUBLICKEY
81
+ )
48
82
  return vaultTypeOracleAccount
49
83
  }
50
- export async function findVaultAddress (vaultSalt: string): Promise<PublicKey> {
51
- const [vaultAddress] = await PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], HEDGE_PROGRAM_PUBLICKEY)
84
+ export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
85
+ const [vaultAddress] = await PublicKey.findProgramAddress(
86
+ [enc.encode('Vault'), enc.encode(vaultSalt)],
87
+ HEDGE_PROGRAM_PUBLICKEY
88
+ )
52
89
  return vaultAddress
53
90
  }
54
91
 
55
- export async function findAssociatedTokenAddress (walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey> {
56
- return (await PublicKey.findProgramAddress(
57
- [
58
- walletAddress.toBuffer(),
59
- TOKEN_PROGRAM_ID.toBuffer(),
60
- tokenMintAddress.toBuffer()
61
- ],
62
- ASSOCIATED_TOKEN_PROGRAM_ID
63
- ))[0]
92
+ export async function findAssociatedTokenAddress(
93
+ walletAddress: PublicKey,
94
+ tokenMintAddress: PublicKey
95
+ ): Promise<PublicKey> {
96
+ return (
97
+ await PublicKey.findProgramAddress(
98
+ [
99
+ walletAddress.toBuffer(),
100
+ TOKEN_PROGRAM_ID.toBuffer(),
101
+ tokenMintAddress.toBuffer(),
102
+ ],
103
+ ASSOCIATED_TOKEN_PROGRAM_ID
104
+ )
105
+ )[0]
64
106
  }