hedge-web3 0.2.27 → 0.2.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) 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/declarations/utils/getLinkedListAccounts.d.ts +2 -1
  16. package/lib/Constants.js +28 -1
  17. package/lib/idl/vault.js +741 -57
  18. package/lib/index.js +9 -0
  19. package/lib/instructions/adminWithdrawCol.js +60 -0
  20. package/lib/instructions/adminWithdrawUsh.js +57 -0
  21. package/lib/instructions/createCompoundStakingPool.js +58 -0
  22. package/lib/instructions/createCompoundStakingPoolPosition.js +56 -0
  23. package/lib/instructions/createReferralAccount.js +6 -3
  24. package/lib/instructions/depositCompoundStakingPoolPosition.js +55 -0
  25. package/lib/instructions/depositRewardsToCompoundPool.js +64 -0
  26. package/lib/instructions/liquidateVault.js +7 -1
  27. package/lib/instructions/loanVault.js +7 -1
  28. package/lib/instructions/referralClaimFees.js +6 -3
  29. package/lib/instructions/setCompoundPoolActive.js +43 -0
  30. package/lib/instructions/setDelegateWallet.js +43 -0
  31. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +64 -0
  32. package/lib/utils/getLinkedListAccounts.js +5 -21
  33. package/package.json +5 -2
  34. package/src/Constants.ts +30 -0
  35. package/src/idl/vault.ts +3638 -2270
  36. package/src/index.ts +9 -2
  37. package/src/instructions/adminWithdrawCol.ts +87 -0
  38. package/src/instructions/adminWithdrawUsh.ts +78 -0
  39. package/src/instructions/createCompoundStakingPool.ts +63 -0
  40. package/src/instructions/createCompoundStakingPoolPosition.ts +85 -0
  41. package/src/instructions/createReferralAccount.ts +13 -9
  42. package/src/instructions/createStakingPool.ts +2 -9
  43. package/src/instructions/depositCompoundStakingPoolPosition.ts +78 -0
  44. package/src/instructions/depositRewardsToCompoundPool.ts +110 -0
  45. package/src/instructions/liquidateVault.ts +37 -27
  46. package/src/instructions/loanVault.ts +34 -21
  47. package/src/instructions/referralClaimFees.ts +16 -10
  48. package/src/instructions/setCompoundPoolActive.ts +51 -0
  49. package/src/instructions/setDelegateWallet.ts +51 -0
  50. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +100 -0
  51. package/src/utils/getLinkedListAccounts.ts +6 -20
@@ -24,6 +24,15 @@ export * from './instructions/refreshOraclePrice';
24
24
  export * from './instructions/repayVault';
25
25
  export * from './instructions/setHalted';
26
26
  export * from './instructions/transferVault';
27
+ export * from './instructions/createCompoundStakingPool';
28
+ export * from './instructions/createCompoundStakingPoolPosition';
29
+ export * from './instructions/depositCompoundStakingPoolPosition';
30
+ export * from './instructions/withdrawCompoundStakingPoolPosition';
31
+ export * from './instructions/setDelegateWallet';
32
+ export * from './instructions/setCompoundPoolActive';
33
+ export * from './instructions/adminWithdrawCol';
34
+ export * from './instructions/adminWithdrawUsh';
35
+ export * from './instructions/depositRewardsToCompoundPool';
27
36
  export * from './instructions/updateReferralAccount';
28
37
  export * from './instructions/updateReferralState';
29
38
  export * from './instructions/updateVaultType';
@@ -0,0 +1,5 @@
1
+ import { Program, Provider } from '@project-serum/anchor';
2
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
+ import { Vault } from '../idl/vault';
4
+ export declare function adminWithdrawCollateral(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, collateralType: string): Promise<PublicKey>;
5
+ export declare function adminWithdrawCollateralInstruction(program: Program<Vault>, payerPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
@@ -0,0 +1,5 @@
1
+ import { Program, Provider } from '@project-serum/anchor';
2
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
+ import { Vault } from '../idl/vault';
4
+ export declare function adminWithdrawUsh(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey): Promise<PublicKey>;
5
+ export declare function adminWithdrawUshInstruction(program: Program<Vault>, payerPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, poolPublickey: PublicKey): Promise<TransactionInstruction>;
@@ -0,0 +1,5 @@
1
+ import { Program, Provider } from '@project-serum/anchor';
2
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
+ import { Vault } from '../idl/vault';
4
+ export declare function createCompoundStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, overrideStartTime?: number): Promise<PublicKey>;
5
+ export declare function createCompoundStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, mintPublicKey: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -0,0 +1,6 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
3
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
+ import { Vault } from '../idl/vault';
5
+ export declare function createCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
+ export declare function createCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -13,5 +13,5 @@ import { Vault } from '../idl/vault';
13
13
  * - referrer: PublicKey
14
14
  * - overrideTime?: number
15
15
  */
16
- export declare function createReferralAccount(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, overrideTime?: number): Promise<PublicKey>;
17
- export declare function createReferralAccountInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, userReferralAccountPublicKey: PublicKey, overrideTime?: number): Promise<TransactionInstruction>;
16
+ export declare function createReferralAccount(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, stakedTokenMintPublicKey: PublicKey, overrideTime?: number): Promise<PublicKey>;
17
+ export declare function createReferralAccountInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, userReferralAccountPublicKey: PublicKey, overrideTime?: number): Promise<TransactionInstruction>;
@@ -0,0 +1,6 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
3
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
+ import { Vault } from '../idl/vault';
5
+ export declare function depositCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
+ export declare function depositCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -0,0 +1,6 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
3
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
+ import { Vault } from '../idl/vault';
5
+ export declare function depositRewardsToCompoundStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
+ export declare function depositRewardsToCompoundStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, mintPublicKey: PublicKey, historyPublicKey: PublicKey, amount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -12,5 +12,5 @@ import { Vault } from '../idl/vault';
12
12
  * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
13
13
  * - referrer: PublicKey
14
14
  */
15
- export declare function referralClaimFees(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey): Promise<PublicKey>;
16
- export declare function referralClaimFeesInstruction(program: Program<Vault>, payerPublicKey: PublicKey, vaultSystemStatePublicKey: PublicKey, poolPositionPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, ushMintPublicKey: PublicKey, ushAssociatedTokenAccountPublicKey: PublicKey, communityAssociatedHedgeTokenAccountPublicKey: PublicKey, feePoolPublicKey: PublicKey, feePoolAssociatedUshTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
15
+ export declare function referralClaimFees(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, stakedTokenMintPublicKey: PublicKey): Promise<PublicKey>;
16
+ export declare function referralClaimFeesInstruction(program: Program<Vault>, payerPublicKey: PublicKey, vaultSystemStatePublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, ushMintPublicKey: PublicKey, ushAssociatedTokenAccountPublicKey: PublicKey, communityAssociatedHedgeTokenAccountPublicKey: PublicKey, feePoolPublicKey: PublicKey, feePoolAssociatedUshTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
@@ -0,0 +1,5 @@
1
+ import { Program, Provider } from '@project-serum/anchor';
2
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
+ import { Vault } from '../idl/vault';
4
+ export declare function setCompoundPoolActive(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, setActive: boolean): Promise<PublicKey>;
5
+ export declare function setCompoundPoolActiveInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, poolPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, setActive: boolean): Promise<TransactionInstruction>;
@@ -0,0 +1,5 @@
1
+ import { Program, Provider } from '@project-serum/anchor';
2
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
+ import { Vault } from '../idl/vault';
4
+ export declare function setDelegateWallet(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, delegateWallet: PublicKey): Promise<PublicKey>;
5
+ export declare function setDelegateWalletInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, poolPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, delegateWallet: PublicKey): Promise<TransactionInstruction>;
@@ -0,0 +1,6 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
3
+ import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
4
+ import { Vault } from '../idl/vault';
5
+ export declare function withdrawCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, claimAmount: number, overrideStartTime?: number): Promise<PublicKey>;
6
+ export declare function withdrawCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, claimAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -16,5 +16,6 @@ import { VaultAccount } from '../state/VaultAccount';
16
16
  * @param {boolean} redeem - True if vault is going to be redeemed fully
17
17
  * @param {boolean} liquidate - True if vault is going to be liquidated fully
18
18
  * @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
19
+ * @param {VaultAccount} preLoadedVault - Optional vault to use as target vault. Overrides the need to load the vault from on-chain data.
19
20
  */
20
- export declare function getLinkedListAccounts(program: Program<Vault>, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: BN, withdrawAmount: BN, loanAmount: BN, repayAmount: BN, redeem: boolean, liquidate: boolean, cachedVaults?: VaultAccount[]): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]>;
21
+ export declare function getLinkedListAccounts(program: Program<Vault>, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: BN, withdrawAmount: BN, loanAmount: BN, repayAmount: BN, redeem: boolean, liquidate: boolean, cachedVaults?: VaultAccount[], preLoadedVault?: VaultAccount): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]>;
package/lib/Constants.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeOracleAccountPublicKey = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getUserReferralAccountPublicKey = exports.getReferralAccountPublicKey = exports.getReferralStatePublicKey = exports.getVaultSystemStatePublicKey = exports.getUshMintPublicKey = exports.getLiquidationPoolUshAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_PROGRAM_ID = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = void 0;
12
+ exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeOracleAccountPublicKey = exports.getVaultTypeAccountPublicKey = exports.getCompoundPoolPublicKeyForMint = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getCompoundPoolPositionAddress = exports.getUserReferralAccountPublicKey = exports.getReferralAccountPublicKey = exports.getReferralStatePublicKey = exports.getVaultSystemStatePublicKey = exports.getUshMintPublicKey = exports.getLiquidationPoolUshAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_PROGRAM_ID = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = void 0;
13
13
  const spl_token_1 = require("@solana/spl-token");
14
14
  const web3_js_1 = require("@solana/web3.js");
15
15
  exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
@@ -94,6 +94,19 @@ function getUserReferralAccountPublicKey(hedgeProgramId, ownerPublicKey) {
94
94
  });
95
95
  }
96
96
  exports.getUserReferralAccountPublicKey = getUserReferralAccountPublicKey;
97
+ /**
98
+ *
99
+ * @returns The compound pool position address for the given user
100
+ */
101
+ function getCompoundPoolPositionAddress(hedgeProgramId, poolPublicKey, ownerPublicKey) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const strToEncode = poolPublicKey.toBuffer();
104
+ const strToEncode2 = ownerPublicKey.toBuffer();
105
+ const [compoundPoolPosition] = yield web3_js_1.PublicKey.findProgramAddress([strToEncode, strToEncode2], hedgeProgramId);
106
+ return compoundPoolPosition;
107
+ });
108
+ }
109
+ exports.getCompoundPoolPositionAddress = getCompoundPoolPositionAddress;
97
110
  /**
98
111
  *
99
112
  * @returns The HDG mint public key
@@ -119,6 +132,20 @@ function getPoolPublicKeyForMint(hedgeProgramId, mintPublicKey) {
119
132
  });
120
133
  }
121
134
  exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
135
+ /**
136
+ * Get the public key for any compound staking pool
137
+ *
138
+ * @param mintPublicKey Staked collateral mint public key
139
+ * @returns the public key for that compound staking pool
140
+ */
141
+ function getCompoundPoolPublicKeyForMint(hedgeProgramId, mintPublicKey) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ const strToEncode = mintPublicKey.toBuffer();
144
+ const [publicKey, bump] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('CompoundPoolV1'), strToEncode], hedgeProgramId);
145
+ return [publicKey, bump];
146
+ });
147
+ }
148
+ exports.getCompoundPoolPublicKeyForMint = getCompoundPoolPublicKeyForMint;
122
149
  /**
123
150
  *
124
151
  * @param collateralType String name of the collateral type (must be 16 chars)