hedge-web3 0.2.22 → 0.2.24

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 (43) hide show
  1. package/declarations/Constants.d.ts +15 -0
  2. package/declarations/idl/vault.d.ts +832 -179
  3. package/declarations/index.d.ts +26 -21
  4. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +2 -2
  5. package/declarations/instructions/createReferralAccount.d.ts +17 -0
  6. package/declarations/instructions/createUserReferralAccount.d.ts +5 -0
  7. package/declarations/instructions/depositLiquidationPool.d.ts +2 -2
  8. package/declarations/instructions/loanVault.d.ts +2 -2
  9. package/declarations/instructions/psmEditAccount.d.ts +12 -0
  10. package/declarations/instructions/psmMintUsh.d.ts +2 -2
  11. package/declarations/instructions/psmRedeemUsh.d.ts +2 -2
  12. package/declarations/instructions/referralClaimFees.d.ts +16 -0
  13. package/declarations/instructions/updateReferralAccount.d.ts +13 -0
  14. package/declarations/instructions/updateReferralState.d.ts +20 -0
  15. package/lib/Constants.js +36 -1
  16. package/lib/idl/vault.js +830 -177
  17. package/lib/index.js +26 -21
  18. package/lib/instructions/closeLiquidationPoolPosition.js +16 -3
  19. package/lib/instructions/createReferralAccount.js +80 -0
  20. package/lib/instructions/createUserReferralAccount.js +61 -0
  21. package/lib/instructions/depositLiquidationPool.js +16 -5
  22. package/lib/instructions/loanVault.js +16 -3
  23. package/lib/instructions/psmEditAccount.js +60 -0
  24. package/lib/instructions/psmMintUsh.js +14 -3
  25. package/lib/instructions/psmRedeemUsh.js +14 -3
  26. package/lib/instructions/referralClaimFees.js +84 -0
  27. package/lib/instructions/updateReferralAccount.js +50 -0
  28. package/lib/instructions/updateReferralState.js +57 -0
  29. package/package.json +1 -1
  30. package/src/Constants.ts +42 -0
  31. package/src/idl/vault.ts +1845 -539
  32. package/src/index.ts +28 -21
  33. package/src/instructions/closeLiquidationPoolPosition.ts +25 -1
  34. package/src/instructions/createReferralAccount.ts +127 -0
  35. package/src/instructions/createUserReferralAccount.ts +86 -0
  36. package/src/instructions/depositLiquidationPool.ts +24 -4
  37. package/src/instructions/loanVault.ts +20 -1
  38. package/src/instructions/{psmEditAccount.rs → psmEditAccount.ts} +0 -0
  39. package/src/instructions/psmMintUsh.ts +20 -1
  40. package/src/instructions/psmRedeemUsh.ts +20 -1
  41. package/src/instructions/referralClaimFees.ts +159 -0
  42. package/src/instructions/updateReferralAccount.ts +77 -0
  43. package/src/instructions/updateReferralState.ts +93 -0
@@ -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)();
22
+ const referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(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)();
22
+ const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)();
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
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
@@ -58,6 +58,48 @@ export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
58
58
  return publicKey
59
59
  }
60
60
 
61
+ /**
62
+ *
63
+ * @returns The Referral State public key
64
+ */
65
+ export async function getReferralStatePublicKey(): Promise<PublicKey> {
66
+ const [publicKey] = await PublicKey.findProgramAddress(
67
+ [enc.encode('ReferralStateV1')],
68
+ HEDGE_PROGRAM_PUBLICKEY
69
+ )
70
+ return publicKey
71
+ }
72
+
73
+ /**
74
+ *
75
+ * @returns The Referral State public key based off the owner's public key
76
+ */
77
+ export async function getReferralAccountPublicKey(
78
+ ownerPublicKey: PublicKey
79
+ ): Promise<PublicKey> {
80
+ const strToEncode = ownerPublicKey.toBuffer()//.substring(0, 28)
81
+ const [publicKey] = await PublicKey.findProgramAddress(
82
+ [enc.encode('refer_acct'), strToEncode],
83
+ HEDGE_PROGRAM_PUBLICKEY
84
+ )
85
+ return publicKey
86
+ }
87
+
88
+ /**
89
+ *
90
+ * @returns The user referral account public key based off the user's public key
91
+ */
92
+ export async function getUserReferralAccountPublicKey(
93
+ ownerPublicKey: PublicKey
94
+ ): Promise<PublicKey> {
95
+ const strToEncode = ownerPublicKey.toBuffer()//.substring(0, 28)
96
+ const [publicKey] = await PublicKey.findProgramAddress(
97
+ [enc.encode('user_ref'), strToEncode],
98
+ HEDGE_PROGRAM_PUBLICKEY
99
+ )
100
+ return publicKey
101
+ }
102
+
61
103
  /**
62
104
  *
63
105
  * @returns The HDG mint public key