hedge-web3 0.2.2 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/declarations/idl/vault.d.ts +47 -5
  2. package/declarations/instructions/createVault.d.ts +3 -2
  3. package/declarations/instructions/depositLiquidationPool.d.ts +4 -3
  4. package/declarations/instructions/depositStakingPool.d.ts +3 -2
  5. package/declarations/instructions/depositVault.d.ts +3 -2
  6. package/declarations/instructions/loanVault.d.ts +3 -2
  7. package/declarations/instructions/redeemVault.d.ts +3 -2
  8. package/declarations/instructions/repayVault.d.ts +3 -2
  9. package/declarations/instructions/setVaultTypeStatus.d.ts +2 -3
  10. package/declarations/instructions/withdrawVault.d.ts +3 -2
  11. package/lib/idl/vault.js +47 -5
  12. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  13. package/lib/instructions/createVault.js +2 -2
  14. package/lib/instructions/depositLiquidationPool.js +2 -2
  15. package/lib/instructions/depositStakingPool.js +2 -2
  16. package/lib/instructions/depositVault.js +2 -2
  17. package/lib/instructions/loanVault.js +2 -2
  18. package/lib/instructions/redeemVault.js +2 -2
  19. package/lib/instructions/repayVault.js +2 -2
  20. package/lib/instructions/setVaultTypeStatus.js +10 -9
  21. package/lib/instructions/withdrawVault.js +2 -2
  22. package/lib/state/VaultAccount.js +10 -6
  23. package/lib/utils/getLinkedListAccounts.js +3 -3
  24. package/package.json +1 -1
  25. package/src/idl/vault.ts +94 -10
  26. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
  27. package/src/instructions/createVault.ts +3 -3
  28. package/src/instructions/depositLiquidationPool.ts +4 -4
  29. package/src/instructions/depositStakingPool.ts +3 -3
  30. package/src/instructions/depositVault.ts +3 -3
  31. package/src/instructions/loanVault.ts +3 -3
  32. package/src/instructions/redeemVault.ts +3 -3
  33. package/src/instructions/repayVault.ts +3 -3
  34. package/src/instructions/withdrawVault.ts +3 -3
  35. package/src/state/VaultAccount.ts +6 -4
  36. package/src/utils/getLinkedListAccounts.ts +3 -3
@@ -1708,7 +1708,7 @@ export declare type Vault = {
1708
1708
  "args": [];
1709
1709
  },
1710
1710
  {
1711
- "name": "closeClaimedLiquidationPool";
1711
+ "name": "closeClaimedLiquidationPoolPosition";
1712
1712
  "accounts": [
1713
1713
  {
1714
1714
  "name": "payer";
@@ -1722,6 +1722,38 @@ export declare type Vault = {
1722
1722
  }
1723
1723
  ];
1724
1724
  "args": [];
1725
+ },
1726
+ {
1727
+ "name": "closeClaimedStakingPoolPosition";
1728
+ "accounts": [
1729
+ {
1730
+ "name": "payer";
1731
+ "isMut": true;
1732
+ "isSigner": true;
1733
+ },
1734
+ {
1735
+ "name": "poolPosition";
1736
+ "isMut": true;
1737
+ "isSigner": false;
1738
+ }
1739
+ ];
1740
+ "args": [];
1741
+ },
1742
+ {
1743
+ "name": "closeUnusedPoolEra";
1744
+ "accounts": [
1745
+ {
1746
+ "name": "payer";
1747
+ "isMut": true;
1748
+ "isSigner": true;
1749
+ },
1750
+ {
1751
+ "name": "poolEra";
1752
+ "isMut": true;
1753
+ "isSigner": false;
1754
+ }
1755
+ ];
1756
+ "args": [];
1725
1757
  }
1726
1758
  ];
1727
1759
  "accounts": [
@@ -2819,26 +2851,36 @@ export declare type Vault = {
2819
2851
  },
2820
2852
  {
2821
2853
  "code": 6025;
2854
+ "name": "PositionNotClaimed";
2855
+ "msg": "Not all positions claimed. Claim all before closing account to recover SOL rent.";
2856
+ },
2857
+ {
2858
+ "code": 6026;
2859
+ "name": "PoolWasUsed";
2860
+ "msg": "Era was not unused. Cannot reclaim the SOL rent.";
2861
+ },
2862
+ {
2863
+ "code": 6027;
2822
2864
  "name": "UpdateVaultTypeBadMaxDebtExtended";
2823
2865
  "msg": "New Max debt extended value is less than the current debt!";
2824
2866
  },
2825
2867
  {
2826
- "code": 6026;
2868
+ "code": 6028;
2827
2869
  "name": "UpdateVaultTypeNoEnabledOracles";
2828
2870
  "msg": "No Enabled Oracles!";
2829
2871
  },
2830
2872
  {
2831
- "code": 6027;
2873
+ "code": 6029;
2832
2874
  "name": "UpdateVaultTypeDuplicateOraclePriorities";
2833
2875
  "msg": "Duplicate Oracle Priorities";
2834
2876
  },
2835
2877
  {
2836
- "code": 6028;
2878
+ "code": 6030;
2837
2879
  "name": "UpdateVaultTypeInvalidOraclePriority";
2838
2880
  "msg": "Invalid Oracle Priority";
2839
2881
  },
2840
2882
  {
2841
- "code": 6029;
2883
+ "code": 6031;
2842
2884
  "name": "OracleUpdateFailed";
2843
2885
  "msg": "OracleUpdateFailed";
2844
2886
  }
@@ -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,4 @@
1
1
  import { Program, Provider } from '@project-serum/anchor';
2
2
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
- import { Vault } from 'idl/vault';
4
- export declare function setVaultTypeStatus(program: Program<Vault>, provider: Provider, payer: Signer, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<PublicKey>;
5
- export declare function setVaultTypeStatusInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<TransactionInstruction>;
3
+ export declare function setVaultTypeStatus(program: Program, provider: Provider, payer: Signer, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<PublicKey>;
4
+ export declare function setVaultTypeStatusInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, deprecated: boolean): 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>;
package/lib/idl/vault.js CHANGED
@@ -1711,7 +1711,7 @@ exports.IDL = {
1711
1711
  "args": []
1712
1712
  },
1713
1713
  {
1714
- "name": "closeClaimedLiquidationPool",
1714
+ "name": "closeClaimedLiquidationPoolPosition",
1715
1715
  "accounts": [
1716
1716
  {
1717
1717
  "name": "payer",
@@ -1725,6 +1725,38 @@ exports.IDL = {
1725
1725
  }
1726
1726
  ],
1727
1727
  "args": []
1728
+ },
1729
+ {
1730
+ "name": "closeClaimedStakingPoolPosition",
1731
+ "accounts": [
1732
+ {
1733
+ "name": "payer",
1734
+ "isMut": true,
1735
+ "isSigner": true
1736
+ },
1737
+ {
1738
+ "name": "poolPosition",
1739
+ "isMut": true,
1740
+ "isSigner": false
1741
+ }
1742
+ ],
1743
+ "args": []
1744
+ },
1745
+ {
1746
+ "name": "closeUnusedPoolEra",
1747
+ "accounts": [
1748
+ {
1749
+ "name": "payer",
1750
+ "isMut": true,
1751
+ "isSigner": true
1752
+ },
1753
+ {
1754
+ "name": "poolEra",
1755
+ "isMut": true,
1756
+ "isSigner": false
1757
+ }
1758
+ ],
1759
+ "args": []
1728
1760
  }
1729
1761
  ],
1730
1762
  "accounts": [
@@ -2822,26 +2854,36 @@ exports.IDL = {
2822
2854
  },
2823
2855
  {
2824
2856
  "code": 6025,
2857
+ "name": "PositionNotClaimed",
2858
+ "msg": "Not all positions claimed. Claim all before closing account to recover SOL rent."
2859
+ },
2860
+ {
2861
+ "code": 6026,
2862
+ "name": "PoolWasUsed",
2863
+ "msg": "Era was not unused. Cannot reclaim the SOL rent."
2864
+ },
2865
+ {
2866
+ "code": 6027,
2825
2867
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2826
2868
  "msg": "New Max debt extended value is less than the current debt!"
2827
2869
  },
2828
2870
  {
2829
- "code": 6026,
2871
+ "code": 6028,
2830
2872
  "name": "UpdateVaultTypeNoEnabledOracles",
2831
2873
  "msg": "No Enabled Oracles!"
2832
2874
  },
2833
2875
  {
2834
- "code": 6027,
2876
+ "code": 6029,
2835
2877
  "name": "UpdateVaultTypeDuplicateOraclePriorities",
2836
2878
  "msg": "Duplicate Oracle Priorities"
2837
2879
  },
2838
2880
  {
2839
- "code": 6028,
2881
+ "code": 6030,
2840
2882
  "name": "UpdateVaultTypeInvalidOraclePriority",
2841
2883
  "msg": "Invalid Oracle Priority"
2842
2884
  },
2843
2885
  {
2844
- "code": 6029,
2886
+ "code": 6031,
2845
2887
  "name": "OracleUpdateFailed",
2846
2888
  "msg": "OracleUpdateFailed"
2847
2889
  }
@@ -27,7 +27,7 @@ exports.closeClaimedLiquidationPoolPosition = closeClaimedLiquidationPoolPositio
27
27
  function closeClaimedLiquidationPoolPositionInstruction(program, poolPosition, payer) {
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  return program.methods
30
- .closeClaimedLiquidationPool()
30
+ .closeClaimedLiquidationPoolPosition()
31
31
  .accounts({
32
32
  poolPosition: poolPosition,
33
33
  payer: payer
@@ -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,
@@ -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,
@@ -29,7 +29,7 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
29
29
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
30
30
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, loanAmount, false, false);
31
31
  const history = web3_js_1.Keypair.generate();
32
- const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
32
+ const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(loanAmount), overrideTime));
33
33
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
34
34
  return vaultPublicKey;
35
35
  });
@@ -43,7 +43,7 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
43
43
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
44
44
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
45
45
  return yield program.methods
46
- .loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
46
+ .loanVault(loanAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
47
47
  )
48
48
  .accounts({
49
49
  vaultSystemState: vaultSystemStatePublicKey,
@@ -32,7 +32,7 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
32
32
  const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
33
33
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, 0, true, false);
34
34
  const history = web3_js_1.Keypair.generate();
35
- const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime));
35
+ const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(redeemAmount), transactionOverrideTime));
36
36
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
37
37
  return vaultPublicKey;
38
38
  });
@@ -46,7 +46,7 @@ function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destin
46
46
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
47
47
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
48
48
  return yield program.methods
49
- .redeemVault(new anchor_1.BN(redeemAmount), new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : Date.now() / 1000) // override start time
49
+ .redeemVault(redeemAmount, new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : Date.now() / 1000) // override start time
50
50
  )
51
51
  .accounts({
52
52
  vaultSystemState: vaultSystemStatePublicKey,
@@ -30,7 +30,7 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
30
30
  const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
31
31
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, 0, repayAmount * -1, false, false);
32
32
  const history = web3_js_1.Keypair.generate();
33
- const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime));
33
+ const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(repayAmount), overrideTime));
34
34
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
35
35
  return vaultPublicKey;
36
36
  });
@@ -44,7 +44,7 @@ function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPu
44
44
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
45
45
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
46
46
  return yield program.methods
47
- .repayVault(new anchor_1.BN(repayAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
47
+ .repayVault(repayAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
48
48
  )
49
49
  .accounts({
50
50
  vaultSystemState: vaultSystemStatePublicKey,
@@ -17,21 +17,22 @@ function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecat
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
19
19
  const transaction = new web3_js_1.Transaction().add(yield setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, deprecated));
20
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
20
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider === null || provider === void 0 ? void 0 : provider.opts).catch(Errors_1.parseAnchorErrors);
21
21
  return vaultSystemStatePublicKey;
22
22
  });
23
23
  }
24
24
  exports.setVaultTypeStatus = setVaultTypeStatus;
25
25
  function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
- return yield program.methods
28
- .setVaultTypeStatus(deprecated)
29
- .accounts({
30
- payer: payerPublicKey,
31
- vaultSystemState: vaultSystemStatePublicKey,
32
- vaultType: vaultTypeAccount,
33
- })
34
- .instruction();
27
+ const ix = program.instruction.setVaultTypeStatus(deprecated, {
28
+ accounts: {
29
+ payer: payerPublicKey,
30
+ vaultSystemState: vaultSystemStatePublicKey,
31
+ vaultType: vaultTypeAccount,
32
+ },
33
+ signers: []
34
+ });
35
+ return ix;
35
36
  });
36
37
  }
37
38
  exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
@@ -35,7 +35,7 @@ function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount,
35
35
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
36
36
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
37
37
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultAccount.vaultType, vaultPublicKey, withdrawAmount * -1, 0, false, false);
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, withdrawAmount, overrideTime));
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]);
40
40
  return vaultPublicKey;
41
41
  });
@@ -44,7 +44,7 @@ exports.withdrawVault = withdrawVault;
44
44
  function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMint, historyPublicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  return yield program.methods
47
- .withdrawVault(new anchor_1.BN(withdrawAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
47
+ .withdrawVault(withdrawAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
48
48
  )
49
49
  .accounts({
50
50
  vaultSystemState: vaultSystemStatePublicKey,
@@ -32,7 +32,9 @@ const borsh = __importStar(require("@project-serum/borsh"));
32
32
  */
33
33
  class VaultAccount {
34
34
  constructor(vault, publicKey) {
35
- var _a, _b, _c;
35
+ var _a, _b;
36
+ /** The ordered number of when this vault was created. */
37
+ this.vaultNumber = 0;
36
38
  /** Debt redistribution snapshot */
37
39
  this.debtProductSnapshotBytes = new decimal_js_1.default(0);
38
40
  /** Collateral redistribution snapshot' */
@@ -41,10 +43,12 @@ class VaultAccount {
41
43
  this.vaultStatus = '';
42
44
  this.publicKey = publicKey;
43
45
  this.vaultOwner = vault.vaultOwner;
44
- this.vaultNumber = (_a = vault.vaultNumber) === null || _a === void 0 ? void 0 : _a.toNumber();
45
46
  this.pdaSalt = vault.pdaSalt;
46
- this.deposited = (_b = vault.deposited) === null || _b === void 0 ? void 0 : _b.toNumber();
47
- this.denormalizedDebt = (_c = vault.denormalizedDebt) === null || _c === void 0 ? void 0 : _c.toNumber();
47
+ this.deposited = (_a = vault.deposited) === null || _a === void 0 ? void 0 : _a.toNumber();
48
+ this.denormalizedDebt = (_b = vault.denormalizedDebt) === null || _b === void 0 ? void 0 : _b.toNumber();
49
+ if (vault.vaultNumber) {
50
+ this.vaultNumber = vault.vaultNumber.toNumber();
51
+ }
48
52
  if (vault.debtProductSnapshotBytes) {
49
53
  this.debtProductSnapshotBytes = (0, HedgeDecimal_1.DecimalFromU128)(vault.debtProductSnapshotBytes.toString());
50
54
  }
@@ -138,7 +142,7 @@ class VaultAccount {
138
142
  if (this.nextVaultToRedeem) {
139
143
  nextVault = this.nextVaultToRedeem.toString().substring(0, 6);
140
144
  }
141
- return `Vault(${this.vaultNumber}): ${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `;
145
+ return `${this.publicKey.toString().substring(0, 6)}. Debt: ${this.denormalizedDebt} Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `;
142
146
  }
143
147
  /**
144
148
  * Creates a VaultAccount from a slice of data
@@ -153,7 +157,7 @@ class VaultAccount {
153
157
  * @returns a new VaultAccount
154
158
  */
155
159
  static FromMiniSlice(data, pubkey) {
156
- const props = [borsh.u64('vaultNumber'), borsh.u64('deposited'), borsh.u64('denormalizedDebt')];
160
+ const props = [borsh.u64('deposited'), borsh.u64('denormalizedDebt')];
157
161
  const miniVaultLayout = borsh.struct(props, 'minVaultLayout');
158
162
  const decodedData = miniVaultLayout.decode(data);
159
163
  return new VaultAccount(decodedData, pubkey);
@@ -157,7 +157,7 @@ function sortVaults(a, b) {
157
157
  const aRatio = a.deposited / a.denormalizedDebt;
158
158
  const bRatio = b.deposited / b.denormalizedDebt;
159
159
  if (aRatio === bRatio) {
160
- return b.vaultNumber - a.vaultNumber;
160
+ return a.publicKey.toString() > b.publicKey.toString() ? 1 : -1;
161
161
  }
162
162
  return aRatio - bRatio;
163
163
  }
@@ -189,8 +189,8 @@ function getMiniVaults(program, vaultTypePublicKey) {
189
189
  // Slice the data only to grab the 3 u64's of size 8 bytes each
190
190
  dataSlice: {
191
191
  // See programs/hedge-vault/src/account_data/vault.rs for struct layout
192
- offset: 8 + 32,
193
- length: 24,
192
+ offset: 8 + 32 + 8,
193
+ length: 16,
194
194
  },
195
195
  });
196
196
  return allAccounts.map((vaultData) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.2.2",
3
+ "version": "0.2.8",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/idl/vault.ts CHANGED
@@ -1708,7 +1708,7 @@ export type Vault = {
1708
1708
  "args": []
1709
1709
  },
1710
1710
  {
1711
- "name": "closeClaimedLiquidationPool",
1711
+ "name": "closeClaimedLiquidationPoolPosition",
1712
1712
  "accounts": [
1713
1713
  {
1714
1714
  "name": "payer",
@@ -1722,6 +1722,38 @@ export type Vault = {
1722
1722
  }
1723
1723
  ],
1724
1724
  "args": []
1725
+ },
1726
+ {
1727
+ "name": "closeClaimedStakingPoolPosition",
1728
+ "accounts": [
1729
+ {
1730
+ "name": "payer",
1731
+ "isMut": true,
1732
+ "isSigner": true
1733
+ },
1734
+ {
1735
+ "name": "poolPosition",
1736
+ "isMut": true,
1737
+ "isSigner": false
1738
+ }
1739
+ ],
1740
+ "args": []
1741
+ },
1742
+ {
1743
+ "name": "closeUnusedPoolEra",
1744
+ "accounts": [
1745
+ {
1746
+ "name": "payer",
1747
+ "isMut": true,
1748
+ "isSigner": true
1749
+ },
1750
+ {
1751
+ "name": "poolEra",
1752
+ "isMut": true,
1753
+ "isSigner": false
1754
+ }
1755
+ ],
1756
+ "args": []
1725
1757
  }
1726
1758
  ],
1727
1759
  "accounts": [
@@ -2819,26 +2851,36 @@ export type Vault = {
2819
2851
  },
2820
2852
  {
2821
2853
  "code": 6025,
2854
+ "name": "PositionNotClaimed",
2855
+ "msg": "Not all positions claimed. Claim all before closing account to recover SOL rent."
2856
+ },
2857
+ {
2858
+ "code": 6026,
2859
+ "name": "PoolWasUsed",
2860
+ "msg": "Era was not unused. Cannot reclaim the SOL rent."
2861
+ },
2862
+ {
2863
+ "code": 6027,
2822
2864
  "name": "UpdateVaultTypeBadMaxDebtExtended",
2823
2865
  "msg": "New Max debt extended value is less than the current debt!"
2824
2866
  },
2825
2867
  {
2826
- "code": 6026,
2868
+ "code": 6028,
2827
2869
  "name": "UpdateVaultTypeNoEnabledOracles",
2828
2870
  "msg": "No Enabled Oracles!"
2829
2871
  },
2830
2872
  {
2831
- "code": 6027,
2873
+ "code": 6029,
2832
2874
  "name": "UpdateVaultTypeDuplicateOraclePriorities",
2833
2875
  "msg": "Duplicate Oracle Priorities"
2834
2876
  },
2835
2877
  {
2836
- "code": 6028,
2878
+ "code": 6030,
2837
2879
  "name": "UpdateVaultTypeInvalidOraclePriority",
2838
2880
  "msg": "Invalid Oracle Priority"
2839
2881
  },
2840
2882
  {
2841
- "code": 6029,
2883
+ "code": 6031,
2842
2884
  "name": "OracleUpdateFailed",
2843
2885
  "msg": "OracleUpdateFailed"
2844
2886
  }
@@ -4555,7 +4597,7 @@ export const IDL: Vault = {
4555
4597
  "args": []
4556
4598
  },
4557
4599
  {
4558
- "name": "closeClaimedLiquidationPool",
4600
+ "name": "closeClaimedLiquidationPoolPosition",
4559
4601
  "accounts": [
4560
4602
  {
4561
4603
  "name": "payer",
@@ -4569,6 +4611,38 @@ export const IDL: Vault = {
4569
4611
  }
4570
4612
  ],
4571
4613
  "args": []
4614
+ },
4615
+ {
4616
+ "name": "closeClaimedStakingPoolPosition",
4617
+ "accounts": [
4618
+ {
4619
+ "name": "payer",
4620
+ "isMut": true,
4621
+ "isSigner": true
4622
+ },
4623
+ {
4624
+ "name": "poolPosition",
4625
+ "isMut": true,
4626
+ "isSigner": false
4627
+ }
4628
+ ],
4629
+ "args": []
4630
+ },
4631
+ {
4632
+ "name": "closeUnusedPoolEra",
4633
+ "accounts": [
4634
+ {
4635
+ "name": "payer",
4636
+ "isMut": true,
4637
+ "isSigner": true
4638
+ },
4639
+ {
4640
+ "name": "poolEra",
4641
+ "isMut": true,
4642
+ "isSigner": false
4643
+ }
4644
+ ],
4645
+ "args": []
4572
4646
  }
4573
4647
  ],
4574
4648
  "accounts": [
@@ -5666,26 +5740,36 @@ export const IDL: Vault = {
5666
5740
  },
5667
5741
  {
5668
5742
  "code": 6025,
5743
+ "name": "PositionNotClaimed",
5744
+ "msg": "Not all positions claimed. Claim all before closing account to recover SOL rent."
5745
+ },
5746
+ {
5747
+ "code": 6026,
5748
+ "name": "PoolWasUsed",
5749
+ "msg": "Era was not unused. Cannot reclaim the SOL rent."
5750
+ },
5751
+ {
5752
+ "code": 6027,
5669
5753
  "name": "UpdateVaultTypeBadMaxDebtExtended",
5670
5754
  "msg": "New Max debt extended value is less than the current debt!"
5671
5755
  },
5672
5756
  {
5673
- "code": 6026,
5757
+ "code": 6028,
5674
5758
  "name": "UpdateVaultTypeNoEnabledOracles",
5675
5759
  "msg": "No Enabled Oracles!"
5676
5760
  },
5677
5761
  {
5678
- "code": 6027,
5762
+ "code": 6029,
5679
5763
  "name": "UpdateVaultTypeDuplicateOraclePriorities",
5680
5764
  "msg": "Duplicate Oracle Priorities"
5681
5765
  },
5682
5766
  {
5683
- "code": 6028,
5767
+ "code": 6030,
5684
5768
  "name": "UpdateVaultTypeInvalidOraclePriority",
5685
5769
  "msg": "Invalid Oracle Priority"
5686
5770
  },
5687
5771
  {
5688
- "code": 6029,
5772
+ "code": 6031,
5689
5773
  "name": "OracleUpdateFailed",
5690
5774
  "msg": "OracleUpdateFailed"
5691
5775
  }
@@ -22,7 +22,7 @@ export async function closeClaimedLiquidationPoolPositionInstruction(
22
22
  payer: PublicKey
23
23
  ): Promise<TransactionInstruction> {
24
24
  return program.methods
25
- .closeClaimedLiquidationPool()
25
+ .closeClaimedLiquidationPoolPosition()
26
26
  .accounts({
27
27
  poolPosition: poolPosition,
28
28
  payer: payer
@@ -93,7 +93,7 @@ export async function createVault(
93
93
  vaultTypeAccountInfo.collateralMint,
94
94
  history.publicKey,
95
95
  ushMintPublickey,
96
- depositAmount,
96
+ new BN(depositAmount),
97
97
  overrideTime
98
98
  )
99
99
  )
@@ -187,7 +187,7 @@ export async function buildCreateVaultTransaction(
187
187
  vaultTypeAccountInfo.collateralMint,
188
188
  history.publicKey,
189
189
  ushMintPublickey,
190
- depositAmount,
190
+ new BN(depositAmount),
191
191
  overrideTime
192
192
  )
193
193
  )
@@ -221,7 +221,7 @@ export async function createVaultInstruction(
221
221
  collateralMint: PublicKey,
222
222
  historyPublicKey: PublicKey,
223
223
  ushMintPublickey: PublicKey,
224
- depositAmount: number,
224
+ depositAmount: BN,
225
225
  overrideTime?: number
226
226
  ): Promise<TransactionInstruction> {
227
227
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
@@ -24,7 +24,7 @@ export async function depositLiquidationPool(
24
24
  program: Program<Vault>,
25
25
  provider: Provider,
26
26
  payer: Signer,
27
- depositAmount: number,
27
+ depositAmount: BN,
28
28
  overrideStartTime?: number
29
29
  ): Promise<PublicKey> {
30
30
  const ushMintPublickey = await getUshMintPublicKey()
@@ -42,7 +42,7 @@ export async function depositLiquidationPool(
42
42
  payer.publicKey,
43
43
  payerUshAccount.address,
44
44
  poolPosition.publicKey,
45
- depositAmount,
45
+ new BN(depositAmount),
46
46
  overrideStartTime
47
47
  )
48
48
  )
@@ -55,7 +55,7 @@ export async function depositLiquidationPoolInstruction(
55
55
  payerPublicKey: PublicKey,
56
56
  payerUshAccount: PublicKey,
57
57
  poolPositionPublicKey: PublicKey,
58
- depositAmount: number,
58
+ depositAmount: BN,
59
59
  overrideStartTime?: number
60
60
  ): Promise<TransactionInstruction> {
61
61
  const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
@@ -68,7 +68,7 @@ export async function depositLiquidationPoolInstruction(
68
68
 
69
69
  return await program.methods
70
70
  .depositLiquidationPool(
71
- new BN(depositAmount),
71
+ depositAmount,
72
72
  new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
73
73
  )
74
74
  .accounts({
@@ -30,7 +30,7 @@ export async function depositStakingPool(
30
30
  payer.publicKey,
31
31
  poolPosition.publicKey,
32
32
  mintPublicKey,
33
- depositAmount,
33
+ new BN(depositAmount),
34
34
  overrideStartTime
35
35
  )
36
36
  )
@@ -43,7 +43,7 @@ export async function depositStakingPoolInstruction(
43
43
  payerPublicKey: PublicKey,
44
44
  poolPositionPublicKey: PublicKey,
45
45
  stakedTokenMintPublicKey: PublicKey,
46
- depositAmount: number,
46
+ depositAmount: BN,
47
47
  overrideStartTime?: number
48
48
  ): Promise<TransactionInstruction> {
49
49
  const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey)
@@ -53,7 +53,7 @@ export async function depositStakingPoolInstruction(
53
53
 
54
54
  return await program.methods
55
55
  .depositStakingPool(
56
- new BN(depositAmount),
56
+ depositAmount,
57
57
  new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
58
58
  )
59
59
  .accounts({
@@ -111,7 +111,7 @@ export async function depositVault(
111
111
  oldSmallerPublicKey,
112
112
  newSmallerPublicKey,
113
113
  newLargerPublicKey,
114
- depositAmount,
114
+ new BN(depositAmount),
115
115
  overrideTime
116
116
  )
117
117
  )
@@ -146,12 +146,12 @@ export async function depositVaultInstruction(
146
146
  oldSmallerPublicKey: PublicKey,
147
147
  newSmallerPublicKey: PublicKey,
148
148
  newLargerPublicKey: PublicKey,
149
- depositAmount: number,
149
+ depositAmount: BN,
150
150
  overrideTime?: number
151
151
  ): Promise<TransactionInstruction> {
152
152
  return await program.methods
153
153
  .depositVault(
154
- new BN(depositAmount),
154
+ depositAmount,
155
155
  new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
156
156
  )
157
157
  .accounts({
@@ -82,7 +82,7 @@ export async function loanVault(
82
82
  oldSmallerPublicKey,
83
83
  newSmallerPublicKey,
84
84
  newLargerPublicKey,
85
- loanAmount,
85
+ new BN(loanAmount),
86
86
  overrideTime
87
87
  )
88
88
  )
@@ -102,7 +102,7 @@ export async function loanVaultInstruction(
102
102
  oldSmallerPublicKey: PublicKey,
103
103
  newSmallerPublicKey: PublicKey,
104
104
  newLargerPublicKey: PublicKey,
105
- loanAmount: number,
105
+ loanAmount: BN,
106
106
  overrideTime?: number
107
107
  ): Promise<TransactionInstruction> {
108
108
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
@@ -116,7 +116,7 @@ export async function loanVaultInstruction(
116
116
 
117
117
  return await program.methods
118
118
  .loanVault(
119
- new BN(loanAmount),
119
+ loanAmount,
120
120
  new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
121
121
  )
122
122
  .accounts({
@@ -91,7 +91,7 @@ export async function redeemVault(
91
91
  oldSmallerPublicKey,
92
92
  newSmallerPublicKey,
93
93
  newLargerPublicKey,
94
- redeemAmount,
94
+ new BN(redeemAmount),
95
95
  transactionOverrideTime
96
96
  )
97
97
  )
@@ -112,7 +112,7 @@ export async function redeemVaultInstruction(
112
112
  oldSmallerPublicKey: PublicKey,
113
113
  newSmallerPublicKey: PublicKey,
114
114
  newLargerPublicKey: PublicKey,
115
- redeemAmount: number,
115
+ redeemAmount: BN,
116
116
  transactionOverrideTime?: number
117
117
  ): Promise<TransactionInstruction> {
118
118
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
@@ -125,7 +125,7 @@ export async function redeemVaultInstruction(
125
125
  )
126
126
  return await program.methods
127
127
  .redeemVault(
128
- new BN(redeemAmount),
128
+ redeemAmount,
129
129
  new BN(transactionOverrideTime ?? Date.now() / 1000) // override start time
130
130
  )
131
131
  .accounts({
@@ -72,7 +72,7 @@ export async function repayVault(
72
72
  oldSmallerPublicKey,
73
73
  newSmallerPublicKey,
74
74
  newLargerPublicKey,
75
- repayAmount,
75
+ new BN(repayAmount),
76
76
  overrideTime
77
77
  )
78
78
  )
@@ -92,7 +92,7 @@ export async function repayVaultInstruction(
92
92
  oldSmallerPublicKey: PublicKey,
93
93
  newSmallerPublicKey: PublicKey,
94
94
  newLargerPublicKey: PublicKey,
95
- repayAmount: number,
95
+ repayAmount: BN,
96
96
  overrideTime?: number
97
97
  ): Promise<TransactionInstruction> {
98
98
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
@@ -106,7 +106,7 @@ export async function repayVaultInstruction(
106
106
 
107
107
  return await program.methods
108
108
  .repayVault(
109
- new BN(repayAmount),
109
+ repayAmount,
110
110
  new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
111
111
  )
112
112
  .accounts({
@@ -95,7 +95,7 @@ export async function withdrawVault(
95
95
  oldSmallerPublicKey,
96
96
  newSmallerPublicKey,
97
97
  newLargerPublicKey,
98
- withdrawAmount,
98
+ new BN(withdrawAmount),
99
99
  overrideTime
100
100
  )
101
101
  )
@@ -119,12 +119,12 @@ export async function withdrawVaultInstruction(
119
119
  oldSmallerPublicKey: PublicKey,
120
120
  newSmallerPublicKey: PublicKey,
121
121
  newLargerPublicKey: PublicKey,
122
- withdrawAmount: number,
122
+ withdrawAmount: BN,
123
123
  overrideTime?: number
124
124
  ): Promise<TransactionInstruction> {
125
125
  return await program.methods
126
126
  .withdrawVault(
127
- new BN(withdrawAmount),
127
+ withdrawAmount,
128
128
  new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
129
129
  )
130
130
  .accounts({
@@ -26,7 +26,7 @@ export class VaultAccount {
26
26
  denormalizedDebt: number
27
27
 
28
28
  /** The ordered number of when this vault was created. */
29
- vaultNumber: number
29
+ vaultNumber = 0
30
30
 
31
31
  /** Debt redistribution snapshot */
32
32
  debtProductSnapshotBytes = new Decimal(0)
@@ -49,10 +49,12 @@ export class VaultAccount {
49
49
  constructor(vault: any, publicKey: PublicKey) {
50
50
  this.publicKey = publicKey
51
51
  this.vaultOwner = vault.vaultOwner
52
- this.vaultNumber = vault.vaultNumber?.toNumber()
53
52
  this.pdaSalt = vault.pdaSalt
54
53
  this.deposited = vault.deposited?.toNumber()
55
54
  this.denormalizedDebt = vault.denormalizedDebt?.toNumber()
55
+ if (vault.vaultNumber) {
56
+ this.vaultNumber = vault.vaultNumber.toNumber()
57
+ }
56
58
  if (vault.debtProductSnapshotBytes) {
57
59
  this.debtProductSnapshotBytes = DecimalFromU128(vault.debtProductSnapshotBytes.toString())
58
60
  }
@@ -163,7 +165,7 @@ export class VaultAccount {
163
165
  nextVault = this.nextVaultToRedeem.toString().substring(0, 6)
164
166
  }
165
167
 
166
- return `Vault(${this.vaultNumber}): ${this.publicKey.toString().substring(0, 6)}. Debt: ${
168
+ return `${this.publicKey.toString().substring(0, 6)}. Debt: ${
167
169
  this.denormalizedDebt
168
170
  } Collat: ${this.deposited} Ratio: ${collateralRatio} ${arrow} `
169
171
  }
@@ -180,7 +182,7 @@ export class VaultAccount {
180
182
  * @returns a new VaultAccount
181
183
  */
182
184
  static FromMiniSlice(data: Buffer, pubkey: PublicKey) {
183
- const props = [borsh.u64('vaultNumber'), borsh.u64('deposited'), borsh.u64('denormalizedDebt')]
185
+ const props = [borsh.u64('deposited'), borsh.u64('denormalizedDebt')]
184
186
  const miniVaultLayout = borsh.struct(props, 'minVaultLayout')
185
187
  const decodedData: any = miniVaultLayout.decode(data)
186
188
 
@@ -183,7 +183,7 @@ function sortVaults(a: VaultAccount, b: VaultAccount) {
183
183
  const aRatio = a.deposited / a.denormalizedDebt
184
184
  const bRatio = b.deposited / b.denormalizedDebt
185
185
  if (aRatio === bRatio) {
186
- return b.vaultNumber - a.vaultNumber
186
+ return a.publicKey.toString() > b.publicKey.toString() ? 1 : -1
187
187
  }
188
188
  return aRatio - bRatio
189
189
  }
@@ -215,8 +215,8 @@ async function getMiniVaults(program: Program<Vault>, vaultTypePublicKey: Public
215
215
  // Slice the data only to grab the 3 u64's of size 8 bytes each
216
216
  dataSlice: {
217
217
  // See programs/hedge-vault/src/account_data/vault.rs for struct layout
218
- offset: 8 + 32,
219
- length: 24,
218
+ offset: 8 + 32 + 8,
219
+ length: 16,
220
220
  },
221
221
  })
222
222