hedge-web3 0.1.12 → 0.1.15

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 (123) hide show
  1. package/{lib/types/src → declarations}/Constants.d.ts +7 -7
  2. package/{lib/types/src → declarations}/HedgeDecimal.d.ts +0 -1
  3. package/{lib/types/src → declarations}/StakingPools.d.ts +0 -1
  4. package/{lib/types/src → declarations}/Vaults.d.ts +0 -1
  5. package/{lib/types/src → declarations}/idl/idl.d.ts +0 -1
  6. package/declarations/idl/vault.d.ts +2283 -0
  7. package/{lib/types/src → declarations}/index.d.ts +5 -1
  8. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +4 -0
  9. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +4 -0
  10. package/{lib/types/src → declarations}/instructions/createStakingPool.d.ts +0 -1
  11. package/declarations/instructions/createVault.d.ts +4 -0
  12. package/declarations/instructions/depositLiquidationPool.d.ts +4 -0
  13. package/{lib/types/src → declarations}/instructions/depositStakingPool.d.ts +0 -1
  14. package/declarations/instructions/depositVault.d.ts +4 -0
  15. package/declarations/instructions/initHedgeFoundation.d.ts +4 -0
  16. package/declarations/instructions/liquidateVault.d.ts +4 -0
  17. package/{lib/types/src → declarations}/instructions/loanVault.d.ts +2 -3
  18. package/declarations/instructions/redeemVault.d.ts +4 -0
  19. package/{lib/types/src → declarations}/instructions/refreshOraclePrice.d.ts +2 -3
  20. package/{lib/types/src → declarations}/instructions/repayVault.d.ts +2 -3
  21. package/declarations/instructions/setHalted.d.ts +4 -0
  22. package/{lib/types/src → declarations}/instructions/withdrawStakingPool.d.ts +0 -1
  23. package/declarations/instructions/withdrawVault.d.ts +4 -0
  24. package/{lib/types/src → declarations}/state/LiquidationPoolEra.d.ts +1 -2
  25. package/{lib/types/src → declarations}/state/LiquidationPoolState.d.ts +0 -1
  26. package/{lib/types/src → declarations}/state/LiquidationPosition.d.ts +8 -10
  27. package/{lib/types/src → declarations}/state/StakingPool.d.ts +0 -1
  28. package/{lib/types/src → declarations}/state/StakingPoolPosition.d.ts +0 -1
  29. package/{lib/types/src → declarations}/state/VaultAccount.d.ts +0 -1
  30. package/{lib/types/src → declarations}/state/VaultHistoryEvent.d.ts +0 -1
  31. package/{lib/types/src → declarations}/utils/Errors.d.ts +0 -1
  32. package/lib/Constants.js +86 -0
  33. package/lib/HedgeDecimal.js +24 -0
  34. package/lib/StakingPools.js +15 -0
  35. package/lib/Vaults.js +20 -0
  36. package/lib/idl/idl.js +1475 -0
  37. package/lib/idl/vault.js +2285 -0
  38. package/lib/index.js +36 -2150
  39. package/lib/instructions/claimLiquidationPoolPosition.js +53 -0
  40. package/lib/instructions/closeLiquidationPoolPosition.js +60 -0
  41. package/lib/instructions/createStakingPool.js +52 -0
  42. package/lib/instructions/createVault.js +92 -0
  43. package/lib/instructions/depositLiquidationPool.js +55 -0
  44. package/lib/instructions/depositStakingPool.js +52 -0
  45. package/lib/instructions/depositVault.js +87 -0
  46. package/lib/instructions/initHedgeFoundation.js +55 -0
  47. package/lib/instructions/liquidateVault.js +80 -0
  48. package/lib/instructions/loanVault.js +61 -0
  49. package/lib/instructions/redeemVault.js +65 -0
  50. package/lib/instructions/refreshOraclePrice.js +65 -0
  51. package/lib/instructions/repayVault.js +62 -0
  52. package/lib/instructions/setHalted.js +37 -0
  53. package/lib/instructions/withdrawStakingPool.js +64 -0
  54. package/lib/instructions/withdrawVault.js +62 -0
  55. package/lib/state/LiquidationPoolEra.js +19 -0
  56. package/lib/state/LiquidationPoolState.js +12 -0
  57. package/lib/state/LiquidationPosition.js +39 -0
  58. package/lib/state/StakingPool.js +22 -0
  59. package/lib/state/StakingPoolPosition.js +28 -0
  60. package/lib/state/VaultAccount.js +52 -0
  61. package/lib/state/VaultHistoryEvent.js +45 -0
  62. package/lib/utils/Errors.js +14 -0
  63. package/package.json +13 -7
  64. package/src/Constants.ts +23 -18
  65. package/src/HedgeDecimal.ts +1 -1
  66. package/src/idl/idl.ts +13 -13
  67. package/src/idl/vault.ts +4565 -0
  68. package/src/index.ts +5 -0
  69. package/src/instructions/claimLiquidationPoolPosition.ts +76 -0
  70. package/src/instructions/closeLiquidationPoolPosition.ts +82 -0
  71. package/src/instructions/createStakingPool.ts +4 -4
  72. package/src/instructions/createVault.ts +101 -27
  73. package/src/instructions/depositLiquidationPool.ts +67 -0
  74. package/src/instructions/depositStakingPool.ts +5 -3
  75. package/src/instructions/depositVault.ts +97 -26
  76. package/src/instructions/initHedgeFoundation.ts +64 -0
  77. package/src/instructions/liquidateVault.ts +87 -35
  78. package/src/instructions/loanVault.ts +30 -20
  79. package/src/instructions/redeemVault.ts +37 -24
  80. package/src/instructions/refreshOraclePrice.ts +6 -3
  81. package/src/instructions/repayVault.ts +30 -17
  82. package/src/instructions/setHalted.ts +48 -0
  83. package/src/instructions/withdrawStakingPool.ts +6 -6
  84. package/src/instructions/withdrawVault.ts +50 -17
  85. package/src/state/LiquidationPoolEra.ts +2 -8
  86. package/src/state/LiquidationPosition.ts +38 -39
  87. package/tsconfig.json +3 -2
  88. package/.github/workflows/npm-publish.yml +0 -34
  89. package/README.md +0 -44
  90. package/jsconfig.json +0 -12
  91. package/lib/index.js.map +0 -1
  92. package/lib/types/src/Constants.d.ts.map +0 -1
  93. package/lib/types/src/HedgeDecimal.d.ts.map +0 -1
  94. package/lib/types/src/StakingPools.d.ts.map +0 -1
  95. package/lib/types/src/Vaults.d.ts.map +0 -1
  96. package/lib/types/src/idl/idl.d.ts.map +0 -1
  97. package/lib/types/src/index.d.ts.map +0 -1
  98. package/lib/types/src/instructions/createStakingPool.d.ts.map +0 -1
  99. package/lib/types/src/instructions/createVault.d.ts +0 -5
  100. package/lib/types/src/instructions/createVault.d.ts.map +0 -1
  101. package/lib/types/src/instructions/depositStakingPool.d.ts.map +0 -1
  102. package/lib/types/src/instructions/depositVault.d.ts +0 -5
  103. package/lib/types/src/instructions/depositVault.d.ts.map +0 -1
  104. package/lib/types/src/instructions/liquidateVault.d.ts +0 -5
  105. package/lib/types/src/instructions/liquidateVault.d.ts.map +0 -1
  106. package/lib/types/src/instructions/loanVault.d.ts.map +0 -1
  107. package/lib/types/src/instructions/redeemVault.d.ts +0 -5
  108. package/lib/types/src/instructions/redeemVault.d.ts.map +0 -1
  109. package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +0 -1
  110. package/lib/types/src/instructions/repayVault.d.ts.map +0 -1
  111. package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +0 -1
  112. package/lib/types/src/instructions/withdrawVault.d.ts +0 -5
  113. package/lib/types/src/instructions/withdrawVault.d.ts.map +0 -1
  114. package/lib/types/src/state/LiquidationPoolEra.d.ts.map +0 -1
  115. package/lib/types/src/state/LiquidationPoolState.d.ts.map +0 -1
  116. package/lib/types/src/state/LiquidationPosition.d.ts.map +0 -1
  117. package/lib/types/src/state/StakingPool.d.ts.map +0 -1
  118. package/lib/types/src/state/StakingPoolPosition.d.ts.map +0 -1
  119. package/lib/types/src/state/VaultAccount.d.ts.map +0 -1
  120. package/lib/types/src/state/VaultHistoryEvent.d.ts.map +0 -1
  121. package/lib/types/src/utils/Errors.d.ts.map +0 -1
  122. package/lib/types/tsconfig.base.tsbuildinfo +0 -1
  123. package/rollup.config.js +0 -40
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaultHistoryAction = exports.VaultStatus = exports.VaultHistoryEvent = void 0;
4
+ const HedgeDecimal_1 = require("../HedgeDecimal");
5
+ class VaultHistoryEvent {
6
+ constructor(account, publicKey) {
7
+ this.account = account;
8
+ this.publicKey = publicKey;
9
+ this.actorAccount = account.actorAccount;
10
+ this.usdSolPrice = (0, HedgeDecimal_1.DecimalFromU128)(account.usdSolPrice.toString());
11
+ this.usdhDebtBefore = account.usdhDebtBefore.toNumber();
12
+ this.usdhDebtAfter = account.usdhDebtAfter.toNumber();
13
+ this.solBalanceBefore = account.solBalanceBefore.toNumber();
14
+ this.solBalanceAfter = account.solBalanceAfter.toNumber();
15
+ this.minCollateralRatioBefore = (0, HedgeDecimal_1.DecimalFromU128)(account.minCollateralRatioBefore);
16
+ this.minCollateralRatioAfter = (0, HedgeDecimal_1.DecimalFromU128)(account.minCollateralRatioAfter);
17
+ this.vaultStateBefore = account.vaultStateBefore;
18
+ this.vaultStateAfter = account.vaultStateAfter;
19
+ this.timestamp = account.timestamp.toNumber();
20
+ this.action = account.action;
21
+ }
22
+ }
23
+ exports.VaultHistoryEvent = VaultHistoryEvent;
24
+ var VaultStatus;
25
+ (function (VaultStatus) {
26
+ VaultStatus[VaultStatus["Open"] = 0] = "Open";
27
+ VaultStatus[VaultStatus["Closed"] = 1] = "Closed";
28
+ VaultStatus[VaultStatus["Liquidated"] = 2] = "Liquidated";
29
+ VaultStatus[VaultStatus["Distributed"] = 3] = "Distributed";
30
+ VaultStatus[VaultStatus["Redeemed"] = 4] = "Redeemed";
31
+ })(VaultStatus = exports.VaultStatus || (exports.VaultStatus = {}));
32
+ var VaultHistoryAction;
33
+ (function (VaultHistoryAction) {
34
+ VaultHistoryAction[VaultHistoryAction["Create"] = 0] = "Create";
35
+ VaultHistoryAction[VaultHistoryAction["Close"] = 1] = "Close";
36
+ VaultHistoryAction[VaultHistoryAction["Liquidate"] = 2] = "Liquidate";
37
+ VaultHistoryAction[VaultHistoryAction["PartialLiquidate"] = 3] = "PartialLiquidate";
38
+ VaultHistoryAction[VaultHistoryAction["Distributed"] = 4] = "Distributed";
39
+ VaultHistoryAction[VaultHistoryAction["Redeem"] = 5] = "Redeem";
40
+ VaultHistoryAction[VaultHistoryAction["TransferOwnership"] = 6] = "TransferOwnership";
41
+ VaultHistoryAction[VaultHistoryAction["Deposit"] = 7] = "Deposit";
42
+ VaultHistoryAction[VaultHistoryAction["Withdraw"] = 8] = "Withdraw";
43
+ VaultHistoryAction[VaultHistoryAction["Loan"] = 9] = "Loan";
44
+ VaultHistoryAction[VaultHistoryAction["RepayCredit"] = 10] = "RepayCredit";
45
+ })(VaultHistoryAction = exports.VaultHistoryAction || (exports.VaultHistoryAction = {}));
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAnchorErrors = void 0;
4
+ const anchor_1 = require("@project-serum/anchor");
5
+ const idl_1 = require("../idl/idl");
6
+ function parseAnchorErrors(error) {
7
+ const idlErrors = (0, anchor_1.parseIdlErrors)(idl_1.vaultIdl);
8
+ const parsedError = anchor_1.ProgramError.parse(error, idlErrors);
9
+ if (parsedError !== null) {
10
+ throw parsedError;
11
+ }
12
+ throw error;
13
+ }
14
+ exports.parseAnchorErrors = parseAnchorErrors;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.12",
3
+ "version": "0.1.15",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
- "build": "npm run clean; rollup -c",
7
+ "build": "tsc",
8
+ "dev": "tsc --watch",
8
9
  "clean": "rimraf ./lib",
9
- "dev": "rollup -c -w",
10
10
  "docs": "set -ex; typedoc --includeVersion",
11
11
  "test": "echo \"Error: no test specified\" && exit 1"
12
12
  },
@@ -19,9 +19,15 @@
19
19
  "typedoc": "^0.22.10"
20
20
  },
21
21
  "dependencies": {
22
- "@project-serum/anchor": "^0.19.1-beta.1",
23
- "@solana/spl-token": "^0.1.8",
24
- "@solana/web3.js": "^1.31.0",
25
- "decimal.js": "^10.3.1"
22
+ "@project-serum/anchor": "^0.21.0",
23
+ "@project-serum/serum": "^0.13.61",
24
+ "@solana/buffer-layout": "^4.0.0",
25
+ "@solana/spl-token": "^0.2.0",
26
+ "@solana/web3.js": "^1.35.0",
27
+ "@types/uuid": "^8.3.4",
28
+ "bn.js": "^5.2.0",
29
+ "decimal.js": "^10.3.1",
30
+ "typescript": "^4.5.5",
31
+ "uuid": "^8.3.2"
26
32
  }
27
33
  }
package/src/Constants.ts CHANGED
@@ -6,31 +6,32 @@ export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
6
6
 
7
7
  export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
8
8
  export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
9
+
9
10
  const enc = new TextEncoder()
10
11
 
11
- export async function getLiquidationPoolStatePublicKey (): Promise<[PublicKey, number]> {
12
- const [poolPublicKey, bump] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY)
13
- return [poolPublicKey, bump]
12
+ export async function getLiquidationPoolStatePublicKey (): Promise<PublicKey> {
13
+ const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY)
14
+ return poolPublicKey
14
15
  }
15
16
 
16
- export async function getLiquidationPoolUsdhAccountPublicKey (): Promise<[PublicKey, number]> {
17
- const [poolPublicKey, bump] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY)
18
- return [poolPublicKey, bump]
17
+ export async function getLiquidationPoolUsdhAccountPublicKey (): Promise<PublicKey> {
18
+ const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY)
19
+ return poolPublicKey
19
20
  }
20
21
 
21
- export async function getUsdhMintPublicKey (): Promise<[PublicKey, number]> {
22
- const [findMintPublicKey, bump] = await PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY)
23
- return [findMintPublicKey, bump]
22
+ export async function getUsdhMintPublicKey (): Promise<PublicKey> {
23
+ const [findMintPublicKey] = await PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY)
24
+ return findMintPublicKey
24
25
  }
25
26
 
26
- export async function getVaultSystemStatePublicKey (): Promise<[PublicKey, number]> {
27
- const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY)
28
- return [publicKey, bump]
27
+ export async function getVaultSystemStatePublicKey (): Promise<PublicKey> {
28
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY)
29
+ return publicKey
29
30
  }
30
31
 
31
- export async function getHedgeMintPublicKey (): Promise<[PublicKey, number]> {
32
- const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY)
33
- return [publicKey, bump]
32
+ export async function getHedgeMintPublicKey (): Promise<PublicKey> {
33
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY)
34
+ return publicKey
34
35
  }
35
36
 
36
37
  export async function getPoolPublicKeyForMint (mintPublicKey: PublicKey): Promise<[PublicKey, number, string]> {
@@ -38,9 +39,13 @@ export async function getPoolPublicKeyForMint (mintPublicKey: PublicKey): Promis
38
39
  const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY)
39
40
  return [publicKey, bump, strToEncode]
40
41
  }
41
- export async function getSolCollateralPriceAccountPublicKey (): Promise<PublicKey> {
42
- const [collateralPriceAccount] = await PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Price')], HEDGE_PROGRAM_PUBLICKEY)
43
- return collateralPriceAccount
42
+ export async function getVaultTypeAccountPublicKey (collateralType: string): Promise<PublicKey> {
43
+ const [vaultTypeAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY)
44
+ return vaultTypeAccount
45
+ }
46
+ export async function findVaultAddress (vaultSalt: string): Promise<PublicKey> {
47
+ const [vaultAddress] = await PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], HEDGE_PROGRAM_PUBLICKEY)
48
+ return vaultAddress
44
49
  }
45
50
 
46
51
  export async function findAssociatedTokenAddress (walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey> {
@@ -14,5 +14,5 @@ import Decimal from 'decimal.js'
14
14
  */
15
15
  export function DecimalFromU128 (value: number|string): Decimal {
16
16
  const adjustedValue = new Decimal(value.toString())
17
- return adjustedValue.div(new Decimal('1e+24'))
17
+ return adjustedValue.div(new Decimal('1e+18'))
18
18
  }
package/src/idl/idl.ts CHANGED
@@ -68,12 +68,12 @@ export const vaultIdl: Idl = {
68
68
  isSigner: false
69
69
  },
70
70
  {
71
- name: 'splTokenProgramInfo',
71
+ name: 'tokenProgram',
72
72
  isMut: false,
73
73
  isSigner: false
74
74
  },
75
75
  {
76
- name: 'splAssociatedTokenProgramInfo',
76
+ name: 'associatedTokenProgram',
77
77
  isMut: false,
78
78
  isSigner: false
79
79
  },
@@ -138,12 +138,12 @@ export const vaultIdl: Idl = {
138
138
  isSigner: false
139
139
  },
140
140
  {
141
- name: 'splTokenProgramInfo',
141
+ name: 'tokenProgram',
142
142
  isMut: false,
143
143
  isSigner: false
144
144
  },
145
145
  {
146
- name: 'splAssociatedTokenProgramInfo',
146
+ name: 'associatedTokenProgram',
147
147
  isMut: false,
148
148
  isSigner: false
149
149
  },
@@ -201,7 +201,7 @@ export const vaultIdl: Idl = {
201
201
  isSigner: false
202
202
  },
203
203
  {
204
- name: 'splTokenProgramInfo',
204
+ name: 'tokenProgram',
205
205
  isMut: false,
206
206
  isSigner: false
207
207
  },
@@ -286,7 +286,7 @@ export const vaultIdl: Idl = {
286
286
  isSigner: false
287
287
  },
288
288
  {
289
- name: 'splTokenProgramInfo',
289
+ name: 'tokenProgram',
290
290
  isMut: false,
291
291
  isSigner: false
292
292
  },
@@ -473,7 +473,7 @@ export const vaultIdl: Idl = {
473
473
  isSigner: false
474
474
  },
475
475
  {
476
- name: 'splTokenProgramInfo',
476
+ name: 'tokenProgram',
477
477
  isMut: false,
478
478
  isSigner: false
479
479
  },
@@ -528,7 +528,7 @@ export const vaultIdl: Idl = {
528
528
  isSigner: false
529
529
  },
530
530
  {
531
- name: 'splTokenProgramInfo',
531
+ name: 'tokenProgram',
532
532
  isMut: false,
533
533
  isSigner: false
534
534
  },
@@ -594,7 +594,7 @@ export const vaultIdl: Idl = {
594
594
  isSigner: false
595
595
  },
596
596
  {
597
- name: 'splTokenProgramInfo',
597
+ name: 'tokenProgram',
598
598
  isMut: false,
599
599
  isSigner: false
600
600
  },
@@ -653,7 +653,7 @@ export const vaultIdl: Idl = {
653
653
  isSigner: false
654
654
  },
655
655
  {
656
- name: 'splTokenProgramInfo',
656
+ name: 'tokenProgram',
657
657
  isMut: false,
658
658
  isSigner: false
659
659
  },
@@ -733,7 +733,7 @@ export const vaultIdl: Idl = {
733
733
  isSigner: true
734
734
  },
735
735
  {
736
- name: 'splTokenProgramInfo',
736
+ name: 'tokenProgram',
737
737
  isMut: false,
738
738
  isSigner: false
739
739
  },
@@ -799,12 +799,12 @@ export const vaultIdl: Idl = {
799
799
  isSigner: false
800
800
  },
801
801
  {
802
- name: 'splTokenProgramInfo',
802
+ name: 'tokenProgram',
803
803
  isMut: false,
804
804
  isSigner: false
805
805
  },
806
806
  {
807
- name: 'splAssociatedTokenProgramInfo',
807
+ name: 'associatedTokenProgram',
808
808
  isMut: false,
809
809
  isSigner: false
810
810
  },