hedge-web3 0.2.28 → 0.2.31

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 (48) hide show
  1. package/declarations/Constants.d.ts +12 -0
  2. package/declarations/idl/vault.d.ts +743 -59
  3. package/declarations/index.d.ts +9 -0
  4. package/declarations/instructions/adminWithdrawCol.d.ts +5 -0
  5. package/declarations/instructions/adminWithdrawUsh.d.ts +5 -0
  6. package/declarations/instructions/createCompoundStakingPool.d.ts +5 -0
  7. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +6 -0
  8. package/declarations/instructions/createReferralAccount.d.ts +2 -2
  9. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +6 -0
  10. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +6 -0
  11. package/declarations/instructions/referralClaimFees.d.ts +2 -2
  12. package/declarations/instructions/setCompoundPoolActive.d.ts +5 -0
  13. package/declarations/instructions/setDelegateWallet.d.ts +5 -0
  14. package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +6 -0
  15. package/lib/Constants.js +28 -1
  16. package/lib/idl/vault.js +741 -57
  17. package/lib/index.js +9 -0
  18. package/lib/instructions/adminWithdrawCol.js +60 -0
  19. package/lib/instructions/adminWithdrawUsh.js +57 -0
  20. package/lib/instructions/createCompoundStakingPool.js +58 -0
  21. package/lib/instructions/createCompoundStakingPoolPosition.js +56 -0
  22. package/lib/instructions/createReferralAccount.js +6 -3
  23. package/lib/instructions/depositCompoundStakingPoolPosition.js +55 -0
  24. package/lib/instructions/depositRewardsToCompoundPool.js +64 -0
  25. package/lib/instructions/liquidateVault.js +7 -1
  26. package/lib/instructions/loanVault.js +7 -1
  27. package/lib/instructions/referralClaimFees.js +6 -3
  28. package/lib/instructions/setCompoundPoolActive.js +43 -0
  29. package/lib/instructions/setDelegateWallet.js +43 -0
  30. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +64 -0
  31. package/package.json +5 -2
  32. package/src/Constants.ts +30 -0
  33. package/src/idl/vault.ts +3638 -2270
  34. package/src/index.ts +9 -2
  35. package/src/instructions/adminWithdrawCol.ts +87 -0
  36. package/src/instructions/adminWithdrawUsh.ts +78 -0
  37. package/src/instructions/createCompoundStakingPool.ts +63 -0
  38. package/src/instructions/createCompoundStakingPoolPosition.ts +85 -0
  39. package/src/instructions/createReferralAccount.ts +13 -9
  40. package/src/instructions/createStakingPool.ts +2 -9
  41. package/src/instructions/depositCompoundStakingPoolPosition.ts +78 -0
  42. package/src/instructions/depositRewardsToCompoundPool.ts +110 -0
  43. package/src/instructions/liquidateVault.ts +37 -27
  44. package/src/instructions/loanVault.ts +34 -21
  45. package/src/instructions/referralClaimFees.ts +16 -10
  46. package/src/instructions/setCompoundPoolActive.ts +51 -0
  47. package/src/instructions/setDelegateWallet.ts +51 -0
  48. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +100 -0
@@ -0,0 +1,64 @@
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.withdrawCompoundStakingPoolPositionInstruction = exports.withdrawCompoundStakingPoolPosition = void 0;
16
+ const anchor_1 = require("@project-serum/anchor");
17
+ const spl_token_1 = require("@solana/spl-token");
18
+ const web3_js_1 = require("@solana/web3.js");
19
+ const Constants_1 = require("../Constants");
20
+ const Errors_1 = require("../utils/Errors");
21
+ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
+ function withdrawCompoundStakingPoolPosition(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, claimAmount, overrideStartTime) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
25
+ const poolPosition = yield (0, Constants_1.getCompoundPoolPositionAddress)(program.programId, poolPublickey, payer.publicKey);
26
+ const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, stakedTokenMintPublicKey, payer.publicKey);
27
+ const transaction = new web3_js_1.Transaction().add(yield withdrawCompoundStakingPoolPositionInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, new anchor_1.BN(claimAmount), overrideStartTime));
28
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
29
+ return payerAssociatedTokenAccount.address;
30
+ });
31
+ }
32
+ exports.withdrawCompoundStakingPoolPosition = withdrawCompoundStakingPoolPosition;
33
+ function withdrawCompoundStakingPoolPositionInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, claimAmount, overrideStartTime) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
36
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
37
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
38
+ const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
39
+ const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
40
+ const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, ushMintPublickey);
41
+ const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
42
+ const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
43
+ const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
44
+ const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
45
+ return yield program.methods
46
+ .withdrawCompoundStakingPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
47
+ claimAmount //amount to be claimed
48
+ )
49
+ .accounts({
50
+ payer: payerPublicKey,
51
+ vaultSystemState: vaultSystemStatePublicKey,
52
+ pool: poolPublickey,
53
+ poolPosition: poolPositionPublicKey,
54
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
55
+ payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
56
+ hedgeMint: hedgeMintPublickey,
57
+ stakedTokenMint: stakedTokenMintPublicKey,
58
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
59
+ systemProgram: web3_js_1.SystemProgram.programId,
60
+ })
61
+ .instruction();
62
+ });
63
+ }
64
+ exports.withdrawCompoundStakingPoolPositionInstruction = withdrawCompoundStakingPoolPositionInstruction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.2.28",
3
+ "version": "0.2.31",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "@rollup/plugin-typescript": "^8.3.0",
20
20
  "@solana/buffer-layout": "^4.0.0",
21
21
  "@solana/spl-token": "^0.2.0",
22
- "@solana/web3.js": "^1.37.0",
22
+ "@solana/web3.js": "^1.63.1",
23
23
  "@types/bn.js": "^5.1.0",
24
24
  "@types/underscore": "^1.11.4",
25
25
  "@types/uuid": "^8.3.4",
@@ -32,5 +32,8 @@
32
32
  "typescript": "^4.5.5",
33
33
  "underscore": "^1.13.2",
34
34
  "uuid": "^8.3.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node-fetch": "^2.6.2"
35
38
  }
36
39
  }
package/src/Constants.ts CHANGED
@@ -71,6 +71,21 @@ export async function getUserReferralAccountPublicKey(
71
71
  return publicKey
72
72
  }
73
73
 
74
+ /**
75
+ *
76
+ * @returns The compound pool position address for the given user
77
+ */
78
+ export async function getCompoundPoolPositionAddress(
79
+ hedgeProgramId: PublicKey,
80
+ poolPublicKey: PublicKey,
81
+ ownerPublicKey: PublicKey
82
+ ): Promise<PublicKey> {
83
+ const strToEncode = poolPublicKey.toBuffer()
84
+ const strToEncode2 = ownerPublicKey.toBuffer()
85
+ const [compoundPoolPosition] = await PublicKey.findProgramAddress([strToEncode, strToEncode2], hedgeProgramId)
86
+ return compoundPoolPosition
87
+ }
88
+
74
89
  /**
75
90
  *
76
91
  * @returns The HDG mint public key
@@ -94,6 +109,21 @@ export async function getPoolPublicKeyForMint(
94
109
  return [publicKey, bump, strToEncode]
95
110
  }
96
111
 
112
+ /**
113
+ * Get the public key for any compound staking pool
114
+ *
115
+ * @param mintPublicKey Staked collateral mint public key
116
+ * @returns the public key for that compound staking pool
117
+ */
118
+ export async function getCompoundPoolPublicKeyForMint(
119
+ hedgeProgramId: PublicKey,
120
+ mintPublicKey: PublicKey
121
+ ): Promise<[PublicKey, number]> {
122
+ const strToEncode = mintPublicKey.toBuffer()
123
+ const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode('CompoundPoolV1'), strToEncode], hedgeProgramId)
124
+ return [publicKey, bump]
125
+ }
126
+
97
127
  /**
98
128
  *
99
129
  * @param collateralType String name of the collateral type (must be 16 chars)