hedge-web3 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseAnchorErrors = void 0;
4
4
  const anchor_1 = require("@project-serum/anchor");
5
- const idl_1 = require("../idl/idl");
5
+ const vault_1 = require("../idl/vault");
6
6
  function parseAnchorErrors(error) {
7
- const idlErrors = (0, anchor_1.parseIdlErrors)(idl_1.vaultIdl);
7
+ const idlErrors = (0, anchor_1.parseIdlErrors)(vault_1.IDL);
8
8
  const parsedError = anchor_1.ProgramError.parse(error, idlErrors);
9
9
  if (parsedError !== null) {
10
10
  throw parsedError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
package/src/Constants.ts CHANGED
@@ -1,64 +1,106 @@
1
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
1
+ import {
2
+ ASSOCIATED_TOKEN_PROGRAM_ID,
3
+ TOKEN_PROGRAM_ID,
4
+ } from '@solana/spl-token'
2
5
  import { PublicKey } from '@solana/web3.js'
3
6
 
4
- export const HEDGE_PROGRAM_ID = 'HDG1wzAC1G1XEHRBoQZGJBW4rVmxLZrPbk5ZHRxPWbXi'
7
+ export const HEDGE_PROGRAM_ID = 'HDG2DRczYGkTuYTwTYy1UUhXXucT2Ujede2j4bWEoE6p'
5
8
  export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
6
9
 
7
- export const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
10
+ export const CHAINLINK_SOL_USD_ID =
11
+ 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
8
12
  export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
9
13
 
10
14
  const enc = new TextEncoder()
11
15
 
12
- export async function getLiquidationPoolStatePublicKey (): Promise<PublicKey> {
13
- const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY)
16
+ export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
17
+ const [poolPublicKey] = await PublicKey.findProgramAddress(
18
+ [enc.encode('LiquidationPoolStateV1')],
19
+ HEDGE_PROGRAM_PUBLICKEY
20
+ )
14
21
  return poolPublicKey
15
22
  }
16
23
 
17
- export async function getLiquidationPoolUshAccountPublicKey (): Promise<PublicKey> {
18
- const [poolPublicKey] = await PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSHAccountV1')], HEDGE_PROGRAM_PUBLICKEY)
24
+ export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
25
+ const [poolPublicKey] = await PublicKey.findProgramAddress(
26
+ [enc.encode('LiquidationPoolUSHAccountV1')],
27
+ HEDGE_PROGRAM_PUBLICKEY
28
+ )
19
29
  return poolPublicKey
20
30
  }
21
31
 
22
- export async function getUshMintPublicKey (): Promise<PublicKey> {
23
- const [findMintPublicKey] = await PublicKey.findProgramAddress([enc.encode('UshMintV1')], HEDGE_PROGRAM_PUBLICKEY)
32
+ export async function getUshMintPublicKey(): Promise<PublicKey> {
33
+ const [findMintPublicKey] = await PublicKey.findProgramAddress(
34
+ [enc.encode('UshMintV1')],
35
+ HEDGE_PROGRAM_PUBLICKEY
36
+ )
24
37
  return findMintPublicKey
25
38
  }
26
39
 
27
- export async function getVaultSystemStatePublicKey (): Promise<PublicKey> {
28
- const [publicKey] = await PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY)
40
+ export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
41
+ const [publicKey] = await PublicKey.findProgramAddress(
42
+ [enc.encode('VaultSystemStateV1')],
43
+ HEDGE_PROGRAM_PUBLICKEY
44
+ )
29
45
  return publicKey
30
46
  }
31
47
 
32
- export async function getHedgeMintPublicKey (): Promise<PublicKey> {
33
- const [publicKey] = await PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY)
48
+ export async function getHedgeMintPublicKey(): Promise<PublicKey> {
49
+ const [publicKey] = await PublicKey.findProgramAddress(
50
+ [enc.encode('HEDGEMintV1')],
51
+ HEDGE_PROGRAM_PUBLICKEY
52
+ )
34
53
  return publicKey
35
54
  }
36
55
 
37
- export async function getPoolPublicKeyForMint (mintPublicKey: PublicKey): Promise<[PublicKey, number, string]> {
38
- const strToEncode = (mintPublicKey.toString().substring(0, 12))
39
- const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY)
56
+ export async function getPoolPublicKeyForMint(
57
+ mintPublicKey: PublicKey
58
+ ): Promise<[PublicKey, number, string]> {
59
+ const strToEncode = mintPublicKey.toString().substring(0, 12)
60
+ const [publicKey, bump] = await PublicKey.findProgramAddress(
61
+ [enc.encode(strToEncode)],
62
+ HEDGE_PROGRAM_PUBLICKEY
63
+ )
40
64
  return [publicKey, bump, strToEncode]
41
65
  }
42
- export async function getVaultTypeAccountPublicKey (collateralType: string): Promise<PublicKey> {
43
- const [vaultTypeAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY)
66
+ export async function getVaultTypeAccountPublicKey(
67
+ collateralType: string
68
+ ): Promise<PublicKey> {
69
+ const [vaultTypeAccount] = await PublicKey.findProgramAddress(
70
+ [enc.encode(collateralType), enc.encode('State')],
71
+ HEDGE_PROGRAM_PUBLICKEY
72
+ )
44
73
  return vaultTypeAccount
45
74
  }
46
- export async function getVaultTypeOracleAccountPublicKey (collateralType: string): Promise<PublicKey> {
47
- const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY)
75
+ export async function getVaultTypeOracleAccountPublicKey(
76
+ collateralType: string
77
+ ): Promise<PublicKey> {
78
+ const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress(
79
+ [enc.encode(collateralType), enc.encode('Oracle')],
80
+ HEDGE_PROGRAM_PUBLICKEY
81
+ )
48
82
  return vaultTypeOracleAccount
49
83
  }
50
- export async function findVaultAddress (vaultSalt: string): Promise<PublicKey> {
51
- const [vaultAddress] = await PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], HEDGE_PROGRAM_PUBLICKEY)
84
+ export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
85
+ const [vaultAddress] = await PublicKey.findProgramAddress(
86
+ [enc.encode('Vault'), enc.encode(vaultSalt)],
87
+ HEDGE_PROGRAM_PUBLICKEY
88
+ )
52
89
  return vaultAddress
53
90
  }
54
91
 
55
- export async function findAssociatedTokenAddress (walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey> {
56
- return (await PublicKey.findProgramAddress(
57
- [
58
- walletAddress.toBuffer(),
59
- TOKEN_PROGRAM_ID.toBuffer(),
60
- tokenMintAddress.toBuffer()
61
- ],
62
- ASSOCIATED_TOKEN_PROGRAM_ID
63
- ))[0]
92
+ export async function findAssociatedTokenAddress(
93
+ walletAddress: PublicKey,
94
+ tokenMintAddress: PublicKey
95
+ ): Promise<PublicKey> {
96
+ return (
97
+ await PublicKey.findProgramAddress(
98
+ [
99
+ walletAddress.toBuffer(),
100
+ TOKEN_PROGRAM_ID.toBuffer(),
101
+ tokenMintAddress.toBuffer(),
102
+ ],
103
+ ASSOCIATED_TOKEN_PROGRAM_ID
104
+ )
105
+ )[0]
64
106
  }