hedge-web3 0.2.7 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/declarations/Constants.d.ts +47 -0
  2. package/declarations/idl/pyth.d.ts +80 -0
  3. package/declarations/instructions/createVault.d.ts +3 -2
  4. package/declarations/instructions/depositLiquidationPool.d.ts +4 -3
  5. package/declarations/instructions/depositStakingPool.d.ts +3 -2
  6. package/declarations/instructions/depositVault.d.ts +3 -2
  7. package/declarations/instructions/loanVault.d.ts +3 -2
  8. package/declarations/instructions/redeemVault.d.ts +3 -2
  9. package/declarations/instructions/repayVault.d.ts +3 -2
  10. package/declarations/instructions/withdrawVault.d.ts +3 -2
  11. package/declarations/state/VaultAccount.d.ts +33 -10
  12. package/declarations/utils/getLinkedListAccounts.d.ts +17 -2
  13. package/lib/Constants.js +47 -0
  14. package/lib/idl/pyth.js +82 -0
  15. package/lib/instructions/createVault.js +2 -2
  16. package/lib/instructions/depositLiquidationPool.js +2 -2
  17. package/lib/instructions/depositStakingPool.js +2 -2
  18. package/lib/instructions/depositVault.js +3 -3
  19. package/lib/instructions/liquidateVault.js +1 -1
  20. package/lib/instructions/loanVault.js +3 -3
  21. package/lib/instructions/redeemVault.js +3 -3
  22. package/lib/instructions/refreshOraclePrice.js +6 -5
  23. package/lib/instructions/repayVault.js +3 -3
  24. package/lib/instructions/withdrawVault.js +3 -3
  25. package/lib/state/VaultAccount.js +69 -30
  26. package/lib/utils/getLinkedListAccounts.js +26 -10
  27. package/package.json +1 -1
  28. package/src/Constants.ts +50 -4
  29. package/src/idl/pyth.ts +159 -0
  30. package/src/instructions/createVault.ts +3 -3
  31. package/src/instructions/depositLiquidationPool.ts +4 -4
  32. package/src/instructions/depositStakingPool.ts +3 -3
  33. package/src/instructions/depositVault.ts +7 -6
  34. package/src/instructions/liquidateVault.ts +4 -3
  35. package/src/instructions/loanVault.ts +7 -6
  36. package/src/instructions/redeemVault.ts +7 -6
  37. package/src/instructions/refreshOraclePrice.ts +6 -5
  38. package/src/instructions/repayVault.ts +7 -6
  39. package/src/instructions/withdrawVault.ts +7 -6
  40. package/src/state/VaultAccount.ts +79 -36
  41. package/src/utils/getLinkedListAccounts.ts +31 -13
@@ -4,13 +4,60 @@ export declare const HEDGE_PROGRAM_PUBLICKEY: PublicKey;
4
4
  export declare const CHAINLINK_SOL_USD_ID = "FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf";
5
5
  export declare const CHAINLINK_SOL_USD_PUBLICKEY: PublicKey;
6
6
  export declare const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
7
+ /**
8
+ * @returns The Liquidation pool public key
9
+ */
7
10
  export declare function getLiquidationPoolStatePublicKey(): Promise<PublicKey>;
11
+ /**
12
+ *
13
+ * @returns The liquidation pool ush account public key
14
+ */
8
15
  export declare function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey>;
16
+ /**
17
+ *
18
+ * @returns The USH mint public key
19
+ */
9
20
  export declare function getUshMintPublicKey(): Promise<PublicKey>;
21
+ /**
22
+ *
23
+ * @returns The Vault System State public key
24
+ */
10
25
  export declare function getVaultSystemStatePublicKey(): Promise<PublicKey>;
26
+ /**
27
+ *
28
+ * @returns The HDG mint public key
29
+ */
11
30
  export declare function getHedgeMintPublicKey(): Promise<PublicKey>;
31
+ /**
32
+ * Get the public key for any staking pool
33
+ *
34
+ * @param mintPublicKey Staked collateral mint public key
35
+ * @returns the public key for that staking pool
36
+ */
12
37
  export declare function getPoolPublicKeyForMint(mintPublicKey: PublicKey): Promise<[PublicKey, number, string]>;
38
+ /**
39
+ *
40
+ * @param collateralType String name of the collateral type (must be 16 chars)
41
+ * @returns The public key for that Vault Type account
42
+ */
13
43
  export declare function getVaultTypeAccountPublicKey(collateralType: string): Promise<PublicKey>;
44
+ /**
45
+ *
46
+ * @param collateralType String name of the collateral type (must be 16 chars)
47
+ * @returns The public key for that Vault Type oracle info
48
+ */
14
49
  export declare function getVaultTypeOracleAccountPublicKey(collateralType: string): Promise<PublicKey>;
50
+ /**
51
+ * Vaults are stored in PDA accounts. Use this to get the address from a salt
52
+ *
53
+ * @param vaultSalt String salt for the vault (must be 8 chars)
54
+ * @returns The public key for that Vault Type oracle info
55
+ */
15
56
  export declare function findVaultAddress(vaultSalt: string): Promise<PublicKey>;
57
+ /**
58
+ *
59
+ * @param walletAddress Owner public key
60
+ * @param tokenMintAddress Token mint
61
+ * @returns
62
+ */
16
63
  export declare function findAssociatedTokenAddress(walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey>;
@@ -0,0 +1,80 @@
1
+ export declare type Pyth = {
2
+ "version": "0.1.0";
3
+ "name": "pyth";
4
+ "instructions": [
5
+ {
6
+ "name": "initialize";
7
+ "accounts": [
8
+ {
9
+ "name": "payer";
10
+ "isMut": true;
11
+ "isSigner": true;
12
+ },
13
+ {
14
+ "name": "price";
15
+ "isMut": true;
16
+ "isSigner": true;
17
+ },
18
+ {
19
+ "name": "systemProgram";
20
+ "isMut": false;
21
+ "isSigner": false;
22
+ }
23
+ ];
24
+ "args": [
25
+ {
26
+ "name": "price";
27
+ "type": "i64";
28
+ },
29
+ {
30
+ "name": "expo";
31
+ "type": "i32";
32
+ },
33
+ {
34
+ "name": "conf";
35
+ "type": "u64";
36
+ }
37
+ ];
38
+ },
39
+ {
40
+ "name": "setPrice";
41
+ "accounts": [
42
+ {
43
+ "name": "price";
44
+ "isMut": true;
45
+ "isSigner": false;
46
+ }
47
+ ];
48
+ "args": [
49
+ {
50
+ "name": "price";
51
+ "type": "i64";
52
+ }
53
+ ];
54
+ }
55
+ ];
56
+ "accounts": [
57
+ {
58
+ "name": "priceWrapper";
59
+ "type": {
60
+ "kind": "struct";
61
+ "fields": [
62
+ {
63
+ "name": "price";
64
+ "type": {
65
+ "defined": "Price";
66
+ };
67
+ }
68
+ ];
69
+ };
70
+ }
71
+ ];
72
+ "errors": [
73
+ {
74
+ "code": 6000;
75
+ "name": "InvalidTradingStatus";
76
+ "msg": "invalid trading status";
77
+ }
78
+ ];
79
+ };
80
+ export declare const IDL: Pyth;
@@ -1,6 +1,7 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function createVault(program: Program<Vault>, provider: Provider, payer: Signer, collateralType: string, depositAmount: number, overrideTime?: number): Promise<PublicKey>;
5
6
  export declare function buildCreateVaultTransaction(program: Program<Vault>, payerPublicKey: PublicKey, collateralType: string, depositAmount: number, overrideTime?: number): Promise<[Transaction, Signer[], PublicKey]>;
6
- export declare function createVaultInstruction(program: Program<Vault>, salt: string, payerPublicKey: PublicKey, payerTokenAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, vaultAssociatedTokenAccount: PublicKey, feePool: PublicKey, feePoolAssociatedUshTokenAccount: PublicKey, vaultTypeAccount: PublicKey, collateralMint: PublicKey, historyPublicKey: PublicKey, ushMintPublickey: PublicKey, depositAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
7
+ export declare function createVaultInstruction(program: Program<Vault>, salt: string, payerPublicKey: PublicKey, payerTokenAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, vaultAssociatedTokenAccount: PublicKey, feePool: PublicKey, feePoolAssociatedUshTokenAccount: PublicKey, vaultTypeAccount: PublicKey, collateralMint: PublicKey, historyPublicKey: PublicKey, ushMintPublickey: PublicKey, depositAmount: BN, overrideTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
- export declare function depositLiquidationPool(program: Program<Vault>, provider: Provider, payer: Signer, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
5
- export declare function depositLiquidationPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, payerUshAccount: PublicKey, poolPositionPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<TransactionInstruction>;
5
+ export declare function depositLiquidationPool(program: Program<Vault>, provider: Provider, payer: Signer, depositAmount: BN, overrideStartTime?: number): Promise<PublicKey>;
6
+ export declare function depositLiquidationPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, payerUshAccount: PublicKey, poolPositionPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function depositStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
5
- export declare function depositStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<TransactionInstruction>;
6
+ export declare function depositStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function depositVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, depositAmount: number, overrideTime?: number): Promise<PublicKey>;
5
- export declare function depositVaultInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, vaultOwner: PublicKey, vaultOwnerTokenAccount: PublicKey, vaultPublicKey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, ushMintPublickey: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, depositAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
6
+ export declare function depositVaultInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, vaultOwner: PublicKey, vaultOwnerTokenAccount: PublicKey, vaultPublicKey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, collateralMint: PublicKey, ushMintPublickey: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, depositAmount: BN, overrideTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function loanVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, loanAmount: number, overrideTime?: number): Promise<PublicKey>;
5
- export declare function loanVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, loanAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
6
+ export declare function loanVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, loanAmount: BN, overrideTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function redeemVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, redeemAmount: number, transactionOverrideTime?: number): Promise<PublicKey>;
5
- export declare function redeemVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, payerUshAccount: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, redeemAmount: number, transactionOverrideTime?: number): Promise<TransactionInstruction>;
6
+ export declare function redeemVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, payerUshAccount: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, redeemAmount: BN, transactionOverrideTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function repayVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, repayAmount: number, overrideTime?: number): Promise<PublicKey>;
5
- export declare function repayVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, repayAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
6
+ export declare function repayVaultInstruction(program: Program<Vault>, payerPublicKey: PublicKey, ownerUshAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedTokenAccount: PublicKey, historyPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, repayAmount: BN, overrideTime?: number): Promise<TransactionInstruction>;
@@ -1,5 +1,6 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, Provider } from '@project-serum/anchor';
2
3
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
4
  import { Vault } from '../idl/vault';
4
5
  export declare function withdrawVault(program: Program<Vault>, provider: Provider, payer: Signer, vaultPublicKey: PublicKey, withdrawAmount: number, overrideTime?: number): Promise<PublicKey>;
5
- export declare function withdrawVaultInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedCollateralPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, ushMint: PublicKey, historyPublicKey: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, withdrawAmount: number, overrideTime?: number): Promise<TransactionInstruction>;
6
+ export declare function withdrawVaultInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, destinationTokenAccount: PublicKey, vaultPublickey: PublicKey, vaultAssociatedCollateralPublicKey: PublicKey, vaultTypeAccount: PublicKey, vaultTypeAssociatedTokenAccount: PublicKey, hedgeStakingPoolPublicKey: PublicKey, hedgeStakingPoolAssociatedUshTokenAccount: PublicKey, ushMint: PublicKey, historyPublicKey: PublicKey, oldSmallerPublicKey: PublicKey, newSmallerPublicKey: PublicKey, newLargerPublicKey: PublicKey, withdrawAmount: BN, overrideTime?: number): Promise<TransactionInstruction>;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import Decimal from 'decimal.js';
4
+ import BN from 'bn.js';
4
5
  import VaultType from './VaultType';
5
6
  /**
6
7
  * A class that represents an on-chian vault.
@@ -13,9 +14,9 @@ export declare class VaultAccount {
13
14
  /** The public key of the vault owner. */
14
15
  pdaSalt: string;
15
16
  /** The deposited collateral of the vault (in SOL Lamports). */
16
- deposited: number;
17
+ deposited: BN;
17
18
  /** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
18
- denormalizedDebt: number;
19
+ denormalizedDebt: BN;
19
20
  /** The ordered number of when this vault was created. */
20
21
  vaultNumber: number;
21
22
  /** Debt redistribution snapshot */
@@ -38,12 +39,6 @@ export declare class VaultAccount {
38
39
  * @returns true if publicKey matches the owner publicKey
39
40
  */
40
41
  isOwnedBy(publicKey: PublicKey): boolean;
41
- /**
42
- * Get the collateral value in SOL
43
- *
44
- * @returns collateral value in SOL
45
- */
46
- inSol(): number;
47
42
  /**
48
43
  * Get the debt value in USH
49
44
  *
@@ -56,8 +51,36 @@ export declare class VaultAccount {
56
51
  * @returns example: `1b6ca...azy71s`
57
52
  */
58
53
  toDisplayString(): string;
59
- addDebt(additionalDebt: Decimal, vaultTypeAccount: VaultType): void;
60
- addDeposit(depositAmount: number): void;
54
+ /**
55
+ * Add additional debt to the vault.
56
+ *
57
+ * @param {BN} additionalDebt - Additional normalized debt to add in (USH) lamports.
58
+ * @param {VaultType} vaultTypeAccount - Vault's vaultType
59
+ *
60
+ */
61
+ addDebt(additionalDebt: BN, vaultTypeAccount: VaultType): void;
62
+ /**
63
+ * Repay debt on a vault
64
+ *
65
+ * @param {BN} repayAmount - Normalized debt to repay in (USH) lamports.
66
+ * @param {VaultType} vaultTypeAccount - Vault's vaultType
67
+ *
68
+ */
69
+ repayDebt(repayAmount: BN, vaultTypeAccount: VaultType): void;
70
+ /**
71
+ * Deposit Collateral
72
+ *
73
+ * @param {BN} depositAmount - Amount to deposit in (CollateralMint) lamports
74
+ *
75
+ */
76
+ depositCollateral(depositAmount: BN): void;
77
+ /**
78
+ * Withdraw Collateral
79
+ *
80
+ * @param {BN} withdrawAmount - Amount to withdraw in (CollateralMint) lamports
81
+ *
82
+ */
83
+ withdrawCollateral(withdrawAmount: BN): void;
61
84
  redeem(): void;
62
85
  liquidate(): void;
63
86
  updateDebtAndCollateral(vaultTypeAccountData: VaultType): void;
@@ -1,5 +1,20 @@
1
- import { Program, Provider } from '@project-serum/anchor';
1
+ /// <reference types="bn.js" />
2
+ import { Program, BN } from '@project-serum/anchor';
2
3
  import { PublicKey } from '@solana/web3.js';
3
4
  import { VaultAccount } from '../state/VaultAccount';
4
5
  import { Vault } from '../idl/vault';
5
- export declare function getLinkedListAccounts(program: Program<Vault>, provider: Provider, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: number, loanAmount: number, redeem: boolean, liquidate: boolean, cachedVaults?: VaultAccount[]): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]>;
6
+ /**
7
+ * Get the accounts the left and right for re-inserting in the linked list
8
+ *
9
+ * @param {Program<Vault>} program - Anchor program <Vault ILD>
10
+ * @param {PublicKey} vaultTypeAccountPublicKey - Vault Type Account PublicKey
11
+ * @param {PublicKey} vaultPublicKey - Vault Account PublicKey
12
+ * @param {BN} depositAmount - Amount that will be deposited into vault with instruction
13
+ * @param {BN} withdrawAmount - Amount that will be withdrawn from vault with instruction
14
+ * @param {BN} loanAmount - Amount that will be deposited into vault with transaction (sans fees)
15
+ * @param {BN} repayAmount - Amount that will be repaid into vault with transaction
16
+ * @param {boolean} redeem - True if vault is going to be redeemed fully
17
+ * @param {boolean} liquidate - True if vault is going to be liquidated fully
18
+ * @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
19
+ */
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[]]>;
package/lib/Constants.js CHANGED
@@ -18,6 +18,9 @@ exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
18
18
  exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
19
19
  exports.CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
20
20
  const enc = new TextEncoder();
21
+ /**
22
+ * @returns The Liquidation pool public key
23
+ */
21
24
  function getLiquidationPoolStatePublicKey() {
22
25
  return __awaiter(this, void 0, void 0, function* () {
23
26
  const [poolPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -25,6 +28,10 @@ function getLiquidationPoolStatePublicKey() {
25
28
  });
26
29
  }
27
30
  exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
31
+ /**
32
+ *
33
+ * @returns The liquidation pool ush account public key
34
+ */
28
35
  function getLiquidationPoolUshAccountPublicKey() {
29
36
  return __awaiter(this, void 0, void 0, function* () {
30
37
  const [poolPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSHAccountV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -32,6 +39,10 @@ function getLiquidationPoolUshAccountPublicKey() {
32
39
  });
33
40
  }
34
41
  exports.getLiquidationPoolUshAccountPublicKey = getLiquidationPoolUshAccountPublicKey;
42
+ /**
43
+ *
44
+ * @returns The USH mint public key
45
+ */
35
46
  function getUshMintPublicKey() {
36
47
  return __awaiter(this, void 0, void 0, function* () {
37
48
  const [findMintPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('UshMintV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -39,6 +50,10 @@ function getUshMintPublicKey() {
39
50
  });
40
51
  }
41
52
  exports.getUshMintPublicKey = getUshMintPublicKey;
53
+ /**
54
+ *
55
+ * @returns The Vault System State public key
56
+ */
42
57
  function getVaultSystemStatePublicKey() {
43
58
  return __awaiter(this, void 0, void 0, function* () {
44
59
  const [publicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -46,6 +61,10 @@ function getVaultSystemStatePublicKey() {
46
61
  });
47
62
  }
48
63
  exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
64
+ /**
65
+ *
66
+ * @returns The HDG mint public key
67
+ */
49
68
  function getHedgeMintPublicKey() {
50
69
  return __awaiter(this, void 0, void 0, function* () {
51
70
  const [publicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -53,6 +72,12 @@ function getHedgeMintPublicKey() {
53
72
  });
54
73
  }
55
74
  exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
75
+ /**
76
+ * Get the public key for any staking pool
77
+ *
78
+ * @param mintPublicKey Staked collateral mint public key
79
+ * @returns the public key for that staking pool
80
+ */
56
81
  function getPoolPublicKeyForMint(mintPublicKey) {
57
82
  return __awaiter(this, void 0, void 0, function* () {
58
83
  const strToEncode = mintPublicKey.toString().substring(0, 12);
@@ -61,6 +86,11 @@ function getPoolPublicKeyForMint(mintPublicKey) {
61
86
  });
62
87
  }
63
88
  exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
89
+ /**
90
+ *
91
+ * @param collateralType String name of the collateral type (must be 16 chars)
92
+ * @returns The public key for that Vault Type account
93
+ */
64
94
  function getVaultTypeAccountPublicKey(collateralType) {
65
95
  return __awaiter(this, void 0, void 0, function* () {
66
96
  const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -68,6 +98,11 @@ function getVaultTypeAccountPublicKey(collateralType) {
68
98
  });
69
99
  }
70
100
  exports.getVaultTypeAccountPublicKey = getVaultTypeAccountPublicKey;
101
+ /**
102
+ *
103
+ * @param collateralType String name of the collateral type (must be 16 chars)
104
+ * @returns The public key for that Vault Type oracle info
105
+ */
71
106
  function getVaultTypeOracleAccountPublicKey(collateralType) {
72
107
  return __awaiter(this, void 0, void 0, function* () {
73
108
  const [vaultTypeOracleAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -75,6 +110,12 @@ function getVaultTypeOracleAccountPublicKey(collateralType) {
75
110
  });
76
111
  }
77
112
  exports.getVaultTypeOracleAccountPublicKey = getVaultTypeOracleAccountPublicKey;
113
+ /**
114
+ * Vaults are stored in PDA accounts. Use this to get the address from a salt
115
+ *
116
+ * @param vaultSalt String salt for the vault (must be 8 chars)
117
+ * @returns The public key for that Vault Type oracle info
118
+ */
78
119
  function findVaultAddress(vaultSalt) {
79
120
  return __awaiter(this, void 0, void 0, function* () {
80
121
  const [vaultAddress] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], exports.HEDGE_PROGRAM_PUBLICKEY);
@@ -82,6 +123,12 @@ function findVaultAddress(vaultSalt) {
82
123
  });
83
124
  }
84
125
  exports.findVaultAddress = findVaultAddress;
126
+ /**
127
+ *
128
+ * @param walletAddress Owner public key
129
+ * @param tokenMintAddress Token mint
130
+ * @returns
131
+ */
85
132
  function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
86
133
  return __awaiter(this, void 0, void 0, function* () {
87
134
  return (yield web3_js_1.PublicKey.findProgramAddress([
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IDL = void 0;
4
+ exports.IDL = {
5
+ "version": "0.1.0",
6
+ "name": "pyth",
7
+ "instructions": [
8
+ {
9
+ "name": "initialize",
10
+ "accounts": [
11
+ {
12
+ "name": "payer",
13
+ "isMut": true,
14
+ "isSigner": true
15
+ },
16
+ {
17
+ "name": "price",
18
+ "isMut": true,
19
+ "isSigner": true
20
+ },
21
+ {
22
+ "name": "systemProgram",
23
+ "isMut": false,
24
+ "isSigner": false
25
+ }
26
+ ],
27
+ "args": [
28
+ {
29
+ "name": "price",
30
+ "type": "i64"
31
+ },
32
+ {
33
+ "name": "expo",
34
+ "type": "i32"
35
+ },
36
+ {
37
+ "name": "conf",
38
+ "type": "u64"
39
+ }
40
+ ]
41
+ },
42
+ {
43
+ "name": "setPrice",
44
+ "accounts": [
45
+ {
46
+ "name": "price",
47
+ "isMut": true,
48
+ "isSigner": false
49
+ }
50
+ ],
51
+ "args": [
52
+ {
53
+ "name": "price",
54
+ "type": "i64"
55
+ }
56
+ ]
57
+ }
58
+ ],
59
+ "accounts": [
60
+ {
61
+ "name": "priceWrapper",
62
+ "type": {
63
+ "kind": "struct",
64
+ "fields": [
65
+ {
66
+ "name": "price",
67
+ "type": {
68
+ "defined": "Price"
69
+ }
70
+ }
71
+ ]
72
+ }
73
+ }
74
+ ],
75
+ "errors": [
76
+ {
77
+ "code": 6000,
78
+ "name": "InvalidTradingStatus",
79
+ "msg": "invalid trading status"
80
+ }
81
+ ]
82
+ };
@@ -53,7 +53,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
53
53
  }));
54
54
  signers.push(wrappedSolAccount);
55
55
  }
56
- transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
56
+ transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, new anchor_1.BN(depositAmount), overrideTime));
57
57
  if (isWrappedSol) {
58
58
  transaction.add(serum_1.TokenInstructions.closeAccount({
59
59
  source: wrappedSolAccount.publicKey,
@@ -108,7 +108,7 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
108
108
  signers.push(wrappedSolAccount);
109
109
  }
110
110
  console.log('hedgeStakingPoolPublicKey', hedgeStakingPoolPublicKey.toString());
111
- transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
111
+ transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, new anchor_1.BN(depositAmount), overrideTime));
112
112
  if (isWrappedSol) {
113
113
  transaction.add(serum_1.TokenInstructions.closeAccount({
114
114
  source: wrappedSolAccount.publicKey,
@@ -24,7 +24,7 @@ function depositLiquidationPool(program, provider, payer, depositAmount, overrid
24
24
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
25
25
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
26
26
  const poolPosition = web3_js_1.Keypair.generate();
27
- const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
27
+ const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, new anchor_1.BN(depositAmount), overrideStartTime));
28
28
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
29
29
  return poolPosition.publicKey;
30
30
  });
@@ -38,7 +38,7 @@ function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAcco
38
38
  const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
39
39
  const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
40
40
  return yield program.methods
41
- .depositLiquidationPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
41
+ .depositLiquidationPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
42
42
  )
43
43
  .accounts({
44
44
  vaultSystemState: vaultSystemState,
@@ -22,7 +22,7 @@ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfi
22
22
  function depositStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const poolPosition = web3_js_1.Keypair.generate();
25
- const transaction = new web3_js_1.Transaction().add(yield depositStakingPoolInstruction(program, payer.publicKey, poolPosition.publicKey, mintPublicKey, depositAmount, overrideStartTime));
25
+ const transaction = new web3_js_1.Transaction().add(yield depositStakingPoolInstruction(program, payer.publicKey, poolPosition.publicKey, mintPublicKey, new anchor_1.BN(depositAmount), overrideStartTime));
26
26
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
27
27
  return poolPosition.publicKey;
28
28
  });
@@ -35,7 +35,7 @@ function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPubl
35
35
  const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
36
36
  const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
37
37
  return yield program.methods
38
- .depositStakingPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
38
+ .depositStakingPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
39
39
  )
40
40
  .accounts({
41
41
  payer: payerPublicKey,
@@ -38,7 +38,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
38
38
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
39
39
  const transaction = new web3_js_1.Transaction();
40
40
  const signers = [payer, history];
41
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, depositAmount, 0, false, false);
41
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(depositAmount), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), false, false);
42
42
  if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
43
43
  transaction.add(web3_js_1.SystemProgram.createAccount({
44
44
  fromPubkey: payer.publicKey,
@@ -53,7 +53,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
53
53
  }));
54
54
  signers.push(wrappedSolAccount);
55
55
  }
56
- transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
56
+ transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(depositAmount), overrideTime));
57
57
  if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
58
58
  transaction.add(serum_1.TokenInstructions.closeAccount({
59
59
  source: wrappedSolAccount.publicKey,
@@ -69,7 +69,7 @@ exports.depositVault = depositVault;
69
69
  function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime) {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
71
  return yield program.methods
72
- .depositVault(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
72
+ .depositVault(depositAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
73
73
  )
74
74
  .accounts({
75
75
  vaultSystemState: vaultSystemStatePublicKey,
@@ -35,7 +35,7 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
35
35
  const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
36
36
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultAccount.vaultType, true);
37
37
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
38
- const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, 0, false, true);
38
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), false, true);
39
39
  const history = web3_js_1.Keypair.generate();
40
40
  const newEra = web3_js_1.Keypair.generate();
41
41
  const transaction = new web3_js_1.Transaction();