hedge-web3 0.2.21 → 0.2.25

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 (92) hide show
  1. package/declarations/Constants.d.ts +25 -12
  2. package/declarations/idl/pyth.d.ts +44 -24
  3. package/declarations/idl/switchboard.d.ts +47 -0
  4. package/declarations/idl/vault.d.ts +905 -155
  5. package/declarations/index.d.ts +26 -20
  6. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +2 -2
  7. package/declarations/instructions/createReferralAccount.d.ts +17 -0
  8. package/declarations/instructions/createUserReferralAccount.d.ts +5 -0
  9. package/declarations/instructions/depositLiquidationPool.d.ts +2 -2
  10. package/declarations/instructions/loanVault.d.ts +2 -2
  11. package/declarations/instructions/psmEditAccount.d.ts +12 -0
  12. package/declarations/instructions/psmMintUsh.d.ts +2 -2
  13. package/declarations/instructions/psmRedeemUsh.d.ts +2 -2
  14. package/declarations/instructions/referralClaimFees.d.ts +16 -0
  15. package/declarations/instructions/transferVault.d.ts +3 -17
  16. package/declarations/instructions/updateReferralAccount.d.ts +13 -0
  17. package/declarations/instructions/updateReferralState.d.ts +20 -0
  18. package/declarations/state/VaultAccount.d.ts +1 -1
  19. package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
  20. package/lib/Constants.js +57 -28
  21. package/lib/idl/pyth.js +44 -24
  22. package/lib/idl/switchboard.js +49 -0
  23. package/lib/idl/vault.js +898 -148
  24. package/lib/index.js +26 -20
  25. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  26. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  27. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  28. package/lib/instructions/closeLiquidationPoolPosition.js +25 -12
  29. package/lib/instructions/createReferralAccount.js +80 -0
  30. package/lib/instructions/createStakingPool.js +7 -7
  31. package/lib/instructions/createUserReferralAccount.js +61 -0
  32. package/lib/instructions/createVault.js +15 -15
  33. package/lib/instructions/depositLiquidationPool.js +21 -10
  34. package/lib/instructions/depositStakingPool.js +5 -5
  35. package/lib/instructions/depositVault.js +11 -9
  36. package/lib/instructions/initHedgeFoundation.js +8 -8
  37. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  38. package/lib/instructions/liquidateVault.js +8 -8
  39. package/lib/instructions/loanVault.js +23 -10
  40. package/lib/instructions/psmEditAccount.js +60 -0
  41. package/lib/instructions/psmMintUsh.js +24 -13
  42. package/lib/instructions/psmRedeemUsh.js +24 -13
  43. package/lib/instructions/redeemVault.js +7 -7
  44. package/lib/instructions/referralClaimFees.js +84 -0
  45. package/lib/instructions/refreshOraclePrice.js +3 -3
  46. package/lib/instructions/repayVault.js +9 -9
  47. package/lib/instructions/setHalted.js +1 -1
  48. package/lib/instructions/transferVault.js +10 -24
  49. package/lib/instructions/updateReferralAccount.js +50 -0
  50. package/lib/instructions/updateReferralState.js +57 -0
  51. package/lib/instructions/updateVaultType.js +1 -1
  52. package/lib/instructions/withdrawStakingPool.js +11 -11
  53. package/lib/instructions/withdrawVault.js +5 -5
  54. package/lib/state/VaultAccount.js +3 -1
  55. package/lib/utils/getLinkedListAccounts.js +2 -3
  56. package/package.json +1 -1
  57. package/src/Constants.ts +64 -63
  58. package/src/idl/pyth.ts +88 -48
  59. package/src/idl/switchboard.ts +93 -0
  60. package/src/idl/vault.ts +1851 -351
  61. package/src/index.ts +28 -24
  62. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  63. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  64. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  65. package/src/instructions/closeLiquidationPoolPosition.ts +36 -18
  66. package/src/instructions/createReferralAccount.ts +115 -0
  67. package/src/instructions/createStakingPool.ts +11 -13
  68. package/src/instructions/createUserReferralAccount.ts +75 -0
  69. package/src/instructions/createVault.ts +44 -26
  70. package/src/instructions/depositLiquidationPool.ts +34 -21
  71. package/src/instructions/depositStakingPool.ts +18 -14
  72. package/src/instructions/depositVault.ts +23 -18
  73. package/src/instructions/initHedgeFoundation.ts +16 -14
  74. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  75. package/src/instructions/liquidateVault.ts +15 -20
  76. package/src/instructions/loanVault.ts +29 -19
  77. package/src/instructions/{psmEditAccount.rs → psmEditAccount.ts} +10 -18
  78. package/src/instructions/psmMintUsh.ts +35 -38
  79. package/src/instructions/psmRedeemUsh.ts +35 -40
  80. package/src/instructions/redeemVault.ts +12 -15
  81. package/src/instructions/referralClaimFees.ts +145 -0
  82. package/src/instructions/refreshOraclePrice.ts +6 -8
  83. package/src/instructions/repayVault.ts +18 -16
  84. package/src/instructions/setHalted.ts +5 -24
  85. package/src/instructions/transferVault.ts +57 -0
  86. package/src/instructions/updateReferralAccount.ts +70 -0
  87. package/src/instructions/updateReferralState.ts +86 -0
  88. package/src/instructions/updateVaultType.ts +9 -23
  89. package/src/instructions/withdrawStakingPool.ts +17 -21
  90. package/src/instructions/withdrawVault.ts +10 -16
  91. package/src/state/VaultAccount.ts +9 -10
  92. package/src/utils/getLinkedListAccounts.ts +4 -7
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.updateReferralAccountInstruction = exports.updateReferralAccount = void 0;
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const Constants_1 = require("../Constants");
18
+ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
19
+ function updateReferralAccount(program, provider, payer, referrer, config) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
22
+ const referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
23
+ const transaction = new web3_js_1.Transaction().add(yield updateReferralAccountInstruction(program, vaultSystemStatePublicKey, referralAccountPublicKey, payer.publicKey, config));
24
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
25
+ return referralAccountPublicKey;
26
+ });
27
+ }
28
+ exports.updateReferralAccount = updateReferralAccount;
29
+ function updateReferralAccountInstruction(program, vaultSystemStatePublicKey, referralAccountPublicKey, payerPublicKey, referralAccountConfig) {
30
+ var _a, _b, _c, _d, _e;
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const config = {
33
+ setupCut: (_a = referralAccountConfig.setupCut) !== null && _a !== void 0 ? _a : null,
34
+ stabilityCut: (_b = referralAccountConfig.stabilityCut) !== null && _b !== void 0 ? _b : null,
35
+ referredUserDiscount: (_c = referralAccountConfig.referredUserDiscount) !== null && _c !== void 0 ? _c : null,
36
+ psmCut: (_d = referralAccountConfig.psmCut) !== null && _d !== void 0 ? _d : null,
37
+ hdgThreshold: (_e = referralAccountConfig.hdgThreshold) !== null && _e !== void 0 ? _e : null,
38
+ };
39
+ return yield program.methods
40
+ .updateReferralAccount(config)
41
+ .accounts({
42
+ signer: payerPublicKey,
43
+ vaultSystemState: vaultSystemStatePublicKey,
44
+ referralAccount: referralAccountPublicKey,
45
+ systemProgram: web3_js_1.SystemProgram.programId,
46
+ })
47
+ .instruction();
48
+ });
49
+ }
50
+ exports.updateReferralAccountInstruction = updateReferralAccountInstruction;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.updateReferralStateInstruction = exports.updateReferralState = void 0;
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const Constants_1 = require("../Constants");
18
+ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
19
+ function updateReferralState(program, provider, payer, config) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
22
+ const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
23
+ const transaction = new web3_js_1.Transaction().add(yield updateReferralStateInstruction(program, vaultSystemStatePublicKey, referralStatePublicKey, payer.publicKey, config));
24
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
25
+ return referralStatePublicKey;
26
+ });
27
+ }
28
+ exports.updateReferralState = updateReferralState;
29
+ function updateReferralStateInstruction(program, vaultSystemStatePublicKey, referralStatePublicKey, payerPublicKey, referralStateConfig) {
30
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const config = {
33
+ setupCut: (_a = referralStateConfig.setupCut) !== null && _a !== void 0 ? _a : null,
34
+ stabilityCut: (_b = referralStateConfig.stabilityCut) !== null && _b !== void 0 ? _b : null,
35
+ referredUserDiscount: (_c = referralStateConfig.referredUserDiscount) !== null && _c !== void 0 ? _c : null,
36
+ psmCut: (_d = referralStateConfig.psmCut) !== null && _d !== void 0 ? _d : null,
37
+ maxSetupCut: (_e = referralStateConfig.maxSetupCut) !== null && _e !== void 0 ? _e : null,
38
+ maxReferredDiscount: (_f = referralStateConfig.maxReferredDiscount) !== null && _f !== void 0 ? _f : null,
39
+ maxStabilityCut: (_g = referralStateConfig.maxStabilityCut) !== null && _g !== void 0 ? _g : null,
40
+ maxPsmCut: (_h = referralStateConfig.maxPsmCut) !== null && _h !== void 0 ? _h : null,
41
+ hdgThreshold: (_j = referralStateConfig.hdgThreshold) !== null && _j !== void 0 ? _j : null,
42
+ hdgPsmThreshold: (_k = referralStateConfig.hdgPsmThreshold) !== null && _k !== void 0 ? _k : null,
43
+ referralPromoThreshold: (_l = referralStateConfig.referralThreshold) !== null && _l !== void 0 ? _l : null,
44
+ referralEnabled: (_m = referralStateConfig.referralEnabled) !== null && _m !== void 0 ? _m : null,
45
+ };
46
+ return yield program.methods
47
+ .updateReferralState(config)
48
+ .accounts({
49
+ signer: payerPublicKey,
50
+ vaultSystemState: vaultSystemStatePublicKey,
51
+ referralState: referralStatePublicKey,
52
+ systemProgram: web3_js_1.SystemProgram.programId,
53
+ })
54
+ .instruction();
55
+ });
56
+ }
57
+ exports.updateReferralStateInstruction = updateReferralStateInstruction;
@@ -18,7 +18,7 @@ const Constants_1 = require("../Constants");
18
18
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
19
19
  function updateVaultType(program, provider, payer, vaultTypeAccount, oracleInfoAccount, config) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
21
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
22
22
  const transaction = new web3_js_1.Transaction().add(yield updateVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, oracleInfoAccount, config));
23
23
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
24
24
  return vaultSystemStatePublicKey;
@@ -16,8 +16,8 @@ exports.withdrawStakingPoolInstruction = exports.withdrawStakingPool = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const Errors_1 = require("../utils/Errors");
20
19
  const Constants_1 = require("../Constants");
20
+ const Errors_1 = require("../utils/Errors");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -30,16 +30,16 @@ function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, st
30
30
  exports.withdrawStakingPool = withdrawStakingPool;
31
31
  function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
34
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
35
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
36
- const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(stakedTokenMintPublicKey);
37
- const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, stakedTokenMintPublicKey);
38
- const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
39
- const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
40
- const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
41
- const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
42
- const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
33
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
34
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
35
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
36
+ const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
37
+ const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
38
+ const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, ushMintPublickey);
39
+ const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
40
+ const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
41
+ const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
42
+ const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
43
43
  return yield program.methods
44
44
  .withdrawStakingPool(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
45
45
  )
@@ -14,26 +14,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.withdrawVaultInstruction = exports.withdrawVault = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
- const spl_token_1 = require("@solana/spl-token");
18
17
  const serum_1 = require("@project-serum/serum");
18
+ const spl_token_1 = require("@solana/spl-token");
19
19
  const web3_js_1 = require("@solana/web3.js");
20
20
  const Constants_1 = require("../Constants");
21
21
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
22
22
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
23
23
  function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount, overrideTime) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
25
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
26
26
  // Prep the user to get USH back out at some point
27
27
  yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
28
28
  const history = web3_js_1.Keypair.generate();
29
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
29
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
30
30
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
31
31
  const vaultAssociatedCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, serum_1.TokenInstructions.WRAPPED_SOL_MINT, vaultPublicKey, true);
32
32
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
33
33
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
34
34
  const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
35
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
36
- const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
35
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
36
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
37
37
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(Math.abs(withdrawAmount)), new anchor_1.BN(0), new anchor_1.BN(0), false, false);
38
38
  const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMintPublickey, history.publicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(withdrawAmount), overrideTime));
39
39
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
@@ -163,7 +163,9 @@ class VaultAccount {
163
163
  .mul(new decimal_js_1.default(this.denormalizedDebt.toString()))
164
164
  .floor()
165
165
  .toString());
166
- const extraCollateralDeposited = new decimal_js_1.default(this.denormalizedDebt.toString()).mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber()).floor();
166
+ const extraCollateralDeposited = new decimal_js_1.default(this.denormalizedDebt.toString())
167
+ .mul(vaultTypeAccountData.collateralRedistributionAccumulator.sub(this.collateralAccumulatorSnapshotBytes).toNumber())
168
+ .floor();
167
169
  this.deposited = this.deposited.add(new bn_js_1.default(extraCollateralDeposited.toString()));
168
170
  this.collateralAccumulatorSnapshotBytes = vaultTypeAccountData.collateralRedistributionAccumulator;
169
171
  this.debtProductSnapshotBytes = vaultTypeAccountData.debtRedistributionProduct;
@@ -15,9 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getLinkedListAccounts = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const underscore_1 = __importDefault(require("underscore"));
18
- const Constants_1 = require("../Constants");
19
- const VaultAccount_1 = require("../state/VaultAccount");
20
18
  const decimal_js_1 = __importDefault(require("decimal.js"));
19
+ const VaultAccount_1 = require("../state/VaultAccount");
21
20
  const bs58_1 = __importDefault(require("bs58"));
22
21
  const VaultType_1 = __importDefault(require("../state/VaultType"));
23
22
  /**
@@ -200,7 +199,7 @@ function getMiniVaults(program, vaultTypePublicKey) {
200
199
  },
201
200
  },
202
201
  ];
203
- const allAccounts = yield program.provider.connection.getProgramAccounts(Constants_1.HEDGE_PROGRAM_PUBLICKEY, {
202
+ const allAccounts = yield program.provider.connection.getProgramAccounts(program.programId, {
204
203
  filters: filters,
205
204
  // Slice the data only to grab the 3 u64's of size 8 bytes each
206
205
  dataSlice: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.2.21",
3
+ "version": "0.2.25",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/Constants.ts CHANGED
@@ -1,152 +1,153 @@
1
- import {
2
- ASSOCIATED_TOKEN_PROGRAM_ID,
3
- TOKEN_PROGRAM_ID,
4
- } from '@solana/spl-token'
1
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
5
2
  import { PublicKey } from '@solana/web3.js'
6
3
 
7
- export const HEDGE_PROGRAM_ID = 'HedgeEohwU6RqokrvPU4Hb6XKPub8NuKbnPmY7FoMMtN'
8
- export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
9
-
10
- export const CHAINLINK_SOL_USD_ID =
11
- 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
4
+ export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
12
5
  export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
13
- export const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
6
+ export const CHAINLINK_PROGRAM_ID = 'HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny'
14
7
 
15
8
  const enc = new TextEncoder()
16
9
 
17
10
  /**
18
11
  * @returns The Liquidation pool public key
19
12
  */
20
- export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
21
- const [poolPublicKey] = await PublicKey.findProgramAddress(
22
- [enc.encode('LiquidationPoolStateV1')],
23
- HEDGE_PROGRAM_PUBLICKEY
24
- )
13
+ export async function getLiquidationPoolStatePublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
14
+ const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], hedgeProgramId)
25
15
  return poolPublicKey
26
16
  }
27
17
  /**
28
- *
18
+ *
29
19
  * @returns The liquidation pool ush account public key
30
20
  */
31
- export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
32
- const [poolPublicKey] = await PublicKey.findProgramAddress(
33
- [enc.encode('LiquidationPoolUSHAccountV1')],
34
- HEDGE_PROGRAM_PUBLICKEY
35
- )
21
+ export async function getLiquidationPoolUshAccountPublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
22
+ const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSHAccountV1')], hedgeProgramId)
36
23
  return poolPublicKey
37
24
  }
38
25
  /**
39
- *
26
+ *
40
27
  * @returns The USH mint public key
41
28
  */
42
- export async function getUshMintPublicKey(): Promise<PublicKey> {
43
- const [findMintPublicKey] = await PublicKey.findProgramAddress(
44
- [enc.encode('UshMintV1')],
45
- HEDGE_PROGRAM_PUBLICKEY
46
- )
29
+ export async function getUshMintPublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
30
+ const [findMintPublicKey] = await PublicKey.findProgramAddress([enc.encode('UshMintV1')], hedgeProgramId)
47
31
  return findMintPublicKey
48
32
  }
49
33
  /**
50
- *
34
+ *
51
35
  * @returns The Vault System State public key
52
36
  */
53
- export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
54
- const [publicKey] = await PublicKey.findProgramAddress(
55
- [enc.encode('VaultSystemStateV1')],
56
- HEDGE_PROGRAM_PUBLICKEY
57
- )
37
+ export async function getVaultSystemStatePublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
38
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], hedgeProgramId)
39
+ return publicKey
40
+ }
41
+
42
+ /**
43
+ *
44
+ * @returns The Referral State public key
45
+ */
46
+ export async function getReferralStatePublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
47
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('ReferralStateV1')], hedgeProgramId)
48
+ return publicKey
49
+ }
50
+
51
+ /**
52
+ *
53
+ * @returns The Referral State public key based off the owner's public key
54
+ */
55
+ export async function getReferralAccountPublicKey(hedgeProgramId: PublicKey, ownerPublicKey: PublicKey): Promise<PublicKey> {
56
+ const strToEncode = ownerPublicKey.toBuffer() //.substring(0, 28)
57
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('refer_acct'), strToEncode], hedgeProgramId)
58
58
  return publicKey
59
59
  }
60
60
 
61
61
  /**
62
- *
62
+ *
63
+ * @returns The user referral account public key based off the user's public key
64
+ */
65
+ export async function getUserReferralAccountPublicKey(
66
+ hedgeProgramId: PublicKey,
67
+ ownerPublicKey: PublicKey
68
+ ): Promise<PublicKey> {
69
+ const strToEncode = ownerPublicKey.toBuffer() //.substring(0, 28)
70
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('user_ref'), strToEncode], hedgeProgramId)
71
+ return publicKey
72
+ }
73
+
74
+ /**
75
+ *
63
76
  * @returns The HDG mint public key
64
77
  */
65
- export async function getHedgeMintPublicKey(): Promise<PublicKey> {
66
- const [publicKey] = await PublicKey.findProgramAddress(
67
- [enc.encode('HEDGEMintV1')],
68
- HEDGE_PROGRAM_PUBLICKEY
69
- )
78
+ export async function getHedgeMintPublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
79
+ const [publicKey] = await PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], hedgeProgramId)
70
80
  return publicKey
71
81
  }
72
82
  /**
73
83
  * Get the public key for any staking pool
74
- *
84
+ *
75
85
  * @param mintPublicKey Staked collateral mint public key
76
86
  * @returns the public key for that staking pool
77
87
  */
78
88
  export async function getPoolPublicKeyForMint(
89
+ hedgeProgramId: PublicKey,
79
90
  mintPublicKey: PublicKey
80
91
  ): Promise<[PublicKey, number, string]> {
81
92
  const strToEncode = mintPublicKey.toString().substring(0, 12)
82
- const [publicKey, bump] = await PublicKey.findProgramAddress(
83
- [enc.encode(strToEncode)],
84
- HEDGE_PROGRAM_PUBLICKEY
85
- )
93
+ const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode(strToEncode)], hedgeProgramId)
86
94
  return [publicKey, bump, strToEncode]
87
95
  }
88
96
 
89
97
  /**
90
- *
98
+ *
91
99
  * @param collateralType String name of the collateral type (must be 16 chars)
92
100
  * @returns The public key for that Vault Type account
93
101
  */
94
- export async function getVaultTypeAccountPublicKey(
95
- collateralType: string
96
- ): Promise<PublicKey> {
102
+ export async function getVaultTypeAccountPublicKey(hedgeProgramId: PublicKey, collateralType: string): Promise<PublicKey> {
97
103
  const [vaultTypeAccount] = await PublicKey.findProgramAddress(
98
104
  [enc.encode(collateralType), enc.encode('State')],
99
- HEDGE_PROGRAM_PUBLICKEY
105
+ hedgeProgramId
100
106
  )
101
107
  return vaultTypeAccount
102
108
  }
103
109
 
104
110
  /**
105
- *
111
+ *
106
112
  * @param collateralType String name of the collateral type (must be 16 chars)
107
113
  * @returns The public key for that Vault Type oracle info
108
114
  */
109
115
  export async function getVaultTypeOracleAccountPublicKey(
116
+ hedgeProgramId: PublicKey,
110
117
  collateralType: string
111
118
  ): Promise<PublicKey> {
112
119
  const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress(
113
120
  [enc.encode(collateralType), enc.encode('Oracle')],
114
- HEDGE_PROGRAM_PUBLICKEY
121
+ hedgeProgramId
115
122
  )
116
123
  return vaultTypeOracleAccount
117
124
  }
118
125
 
119
126
  /**
120
127
  * Vaults are stored in PDA accounts. Use this to get the address from a salt
121
- *
128
+ *
122
129
  * @param vaultSalt String salt for the vault (must be 8 chars)
123
130
  * @returns The public key for that Vault Type oracle info
124
131
  */
125
- export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
126
- const [vaultAddress] = await PublicKey.findProgramAddress(
127
- [enc.encode('Vault'), enc.encode(vaultSalt)],
128
- HEDGE_PROGRAM_PUBLICKEY
129
- )
132
+ export async function findVaultAddress(hedgeProgramId: PublicKey, vaultSalt: string): Promise<PublicKey> {
133
+ const [vaultAddress] = await PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], hedgeProgramId)
130
134
  return vaultAddress
131
135
  }
132
136
 
133
137
  /**
134
- *
138
+ *
135
139
  * @param walletAddress Owner public key
136
140
  * @param tokenMintAddress Token mint
137
141
  * @returns The associated token account public key
138
142
  */
139
143
  export async function findAssociatedTokenAddress(
144
+ hedgeProgramId: PublicKey,
140
145
  walletAddress: PublicKey,
141
146
  tokenMintAddress: PublicKey
142
147
  ): Promise<PublicKey> {
143
148
  return (
144
149
  await PublicKey.findProgramAddress(
145
- [
146
- walletAddress.toBuffer(),
147
- TOKEN_PROGRAM_ID.toBuffer(),
148
- tokenMintAddress.toBuffer(),
149
- ],
150
+ [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
150
151
  ASSOCIATED_TOKEN_PROGRAM_ID
151
152
  )
152
153
  )[0]
package/src/idl/pyth.ts CHANGED
@@ -5,19 +5,9 @@ export type Pyth = {
5
5
  {
6
6
  "name": "initialize",
7
7
  "accounts": [
8
- {
9
- "name": "payer",
10
- "isMut": true,
11
- "isSigner": true
12
- },
13
8
  {
14
9
  "name": "price",
15
10
  "isMut": true,
16
- "isSigner": true
17
- },
18
- {
19
- "name": "systemProgram",
20
- "isMut": false,
21
11
  "isSigner": false
22
12
  }
23
13
  ],
@@ -53,27 +43,57 @@ export type Pyth = {
53
43
  ]
54
44
  }
55
45
  ],
56
- "accounts": [
46
+ "types": [
57
47
  {
58
- "name": "priceWrapper",
48
+ "name": "PriceStatus",
59
49
  "type": {
60
- "kind": "struct",
61
- "fields": [
50
+ "kind": "enum",
51
+ "variants": [
52
+ {
53
+ "name": "Unknown"
54
+ },
55
+ {
56
+ "name": "Trading"
57
+ },
62
58
  {
63
- "name": "price",
64
- "type": {
65
- "defined": "Price"
66
- }
59
+ "name": "Halted"
60
+ },
61
+ {
62
+ "name": "Auction"
67
63
  }
68
64
  ]
69
65
  }
70
- }
71
- ],
72
- "errors": [
66
+ },
67
+ {
68
+ "name": "CorpAction",
69
+ "type": {
70
+ "kind": "enum",
71
+ "variants": [
72
+ {
73
+ "name": "NoCorpAct"
74
+ }
75
+ ]
76
+ }
77
+ },
73
78
  {
74
- "code": 6000,
75
- "name": "InvalidTradingStatus",
76
- "msg": "invalid trading status"
79
+ "name": "PriceType",
80
+ "type": {
81
+ "kind": "enum",
82
+ "variants": [
83
+ {
84
+ "name": "Unknown"
85
+ },
86
+ {
87
+ "name": "Price"
88
+ },
89
+ {
90
+ "name": "TWAP"
91
+ },
92
+ {
93
+ "name": "Volatility"
94
+ }
95
+ ]
96
+ }
77
97
  }
78
98
  ]
79
99
  };
@@ -85,19 +105,9 @@ export const IDL: Pyth = {
85
105
  {
86
106
  "name": "initialize",
87
107
  "accounts": [
88
- {
89
- "name": "payer",
90
- "isMut": true,
91
- "isSigner": true
92
- },
93
108
  {
94
109
  "name": "price",
95
110
  "isMut": true,
96
- "isSigner": true
97
- },
98
- {
99
- "name": "systemProgram",
100
- "isMut": false,
101
111
  "isSigner": false
102
112
  }
103
113
  ],
@@ -133,27 +143,57 @@ export const IDL: Pyth = {
133
143
  ]
134
144
  }
135
145
  ],
136
- "accounts": [
146
+ "types": [
137
147
  {
138
- "name": "priceWrapper",
148
+ "name": "PriceStatus",
139
149
  "type": {
140
- "kind": "struct",
141
- "fields": [
150
+ "kind": "enum",
151
+ "variants": [
152
+ {
153
+ "name": "Unknown"
154
+ },
155
+ {
156
+ "name": "Trading"
157
+ },
142
158
  {
143
- "name": "price",
144
- "type": {
145
- "defined": "Price"
146
- }
159
+ "name": "Halted"
160
+ },
161
+ {
162
+ "name": "Auction"
147
163
  }
148
164
  ]
149
165
  }
150
- }
151
- ],
152
- "errors": [
166
+ },
167
+ {
168
+ "name": "CorpAction",
169
+ "type": {
170
+ "kind": "enum",
171
+ "variants": [
172
+ {
173
+ "name": "NoCorpAct"
174
+ }
175
+ ]
176
+ }
177
+ },
153
178
  {
154
- "code": 6000,
155
- "name": "InvalidTradingStatus",
156
- "msg": "invalid trading status"
179
+ "name": "PriceType",
180
+ "type": {
181
+ "kind": "enum",
182
+ "variants": [
183
+ {
184
+ "name": "Unknown"
185
+ },
186
+ {
187
+ "name": "Price"
188
+ },
189
+ {
190
+ "name": "TWAP"
191
+ },
192
+ {
193
+ "name": "Volatility"
194
+ }
195
+ ]
196
+ }
157
197
  }
158
198
  ]
159
199
  };