hedge-web3 0.1.32 → 0.1.35

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- export declare const HEDGE_PROGRAM_ID = "HDG3uyafYaKxSYRW37ZBTdxaUCoyzaqbuirYucAeaPFY";
2
+ export declare const HEDGE_PROGRAM_ID = "HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ";
3
3
  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;
@@ -2,4 +2,4 @@ import { Program, Provider } from '@project-serum/anchor';
2
2
  import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
3
3
  import { Vault } from 'idl/vault';
4
4
  export declare function claimLiquidationPoolPosition(program: Program<Vault>, provider: Provider, poolPosition: PublicKey, payer: Signer, collateralType: string, overrideStartTime?: number): Promise<PublicKey>;
5
- export declare function claimLiquidationPoolPositionInstruction(program: Program<Vault>, poolState: PublicKey, poolAssociatedTokenAccount: PublicKey, vaultTypeAccount: PublicKey, collateralMint: PublicKey, poolPosition: PublicKey, payer: PublicKey, payerAssociatedTokenAccount: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
5
+ export declare function claimLiquidationPoolPositionInstruction(program: Program<Vault>, vaultTypeAccount: PublicKey, collateralMint: PublicKey, poolPosition: PublicKey, payer: PublicKey, payerAssociatedTokenAccount: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
@@ -3,9 +3,8 @@ import { Signer, TransactionInstruction } from '@solana/web3.js';
3
3
  import { Vault } from 'idl/vault';
4
4
  export declare function refreshOraclePrice(program: Program<Vault>, provider: Provider, payer: Signer, collateralType: string, network: Cluster, overridePrice?: number, overrideTime?: number): Promise<string>;
5
5
  export declare function refreshOraclePriceInstruction(program: Program<Vault>, collateralType: string, network: Cluster, overridePrice?: number, overrideTime?: number): Promise<TransactionInstruction>;
6
- declare enum Cluster {
6
+ export declare enum Cluster {
7
7
  Testing = "Testing",
8
8
  Devnet = "Devnet",
9
9
  MainnetBeta = "MainnetBeta"
10
10
  }
11
- export {};
package/lib/Constants.js CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.findAssociatedTokenAddress = exports.findVaultAddress = exports.getVaultTypeOracleAccountPublicKey = exports.getVaultTypeAccountPublicKey = exports.getPoolPublicKeyForMint = exports.getHedgeMintPublicKey = exports.getVaultSystemStatePublicKey = exports.getUshMintPublicKey = exports.getLiquidationPoolUshAccountPublicKey = exports.getLiquidationPoolStatePublicKey = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = exports.HEDGE_PROGRAM_PUBLICKEY = exports.HEDGE_PROGRAM_ID = void 0;
13
13
  const spl_token_1 = require("@solana/spl-token");
14
14
  const web3_js_1 = require("@solana/web3.js");
15
- exports.HEDGE_PROGRAM_ID = 'HDG3uyafYaKxSYRW37ZBTdxaUCoyzaqbuirYucAeaPFY';
15
+ exports.HEDGE_PROGRAM_ID = 'HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ';
16
16
  exports.HEDGE_PROGRAM_PUBLICKEY = new web3_js_1.PublicKey(exports.HEDGE_PROGRAM_ID);
17
17
  exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
18
18
  exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
@@ -19,21 +19,22 @@ function claimLiquidationPoolPosition(program, provider, poolPosition, payer, co
19
19
  const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
20
20
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
21
21
  const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint;
22
- const poolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
23
- const poolAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolStatePublicKey, collateralMintPublicKey);
24
22
  const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMintPublicKey, payer.publicKey);
25
- const transaction = new web3_js_1.Transaction().add(yield claimLiquidationPoolPositionInstruction(program, poolStatePublicKey, poolAssociatedTokenAccount, vaultTypeAccountPublicKey, collateralMintPublicKey, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address, overrideStartTime));
23
+ const transaction = new web3_js_1.Transaction().add(yield claimLiquidationPoolPositionInstruction(program, vaultTypeAccountPublicKey, collateralMintPublicKey, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address, overrideStartTime));
26
24
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
27
25
  return payerAssociatedTokenAccount.address;
28
26
  });
29
27
  }
30
28
  exports.claimLiquidationPoolPosition = claimLiquidationPoolPosition;
31
- function claimLiquidationPoolPositionInstruction(program, poolState, poolAssociatedTokenAccount, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount, overrideStartTime) {
29
+ function claimLiquidationPoolPositionInstruction(program, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount, overrideStartTime) {
32
30
  return __awaiter(this, void 0, void 0, function* () {
31
+ console.log("inside function");
33
32
  const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
33
+ const poolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
34
+ const poolAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolStatePublicKey, collateralMint);
34
35
  return yield program.methods.claimLiquidationPoolPosition().accounts({
35
36
  vaultSystemState: vaultSystemState,
36
- poolState: poolState,
37
+ poolState: poolStatePublicKey,
37
38
  poolAssociatedTokenAccount: poolAssociatedTokenAccount,
38
39
  vaultTypeAccount: vaultTypeAccount,
39
40
  collateralMint: collateralMint,
@@ -122,7 +122,7 @@ exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
122
122
  function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
123
123
  return __awaiter(this, void 0, void 0, function* () {
124
124
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
125
- const ix = program.methods
125
+ return yield program.methods
126
126
  .createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
127
127
  )
128
128
  .accounts({
@@ -143,7 +143,6 @@ function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccount
143
143
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
144
144
  })
145
145
  .instruction();
146
- return ix;
147
146
  });
148
147
  }
149
148
  exports.createVaultInstruction = createVaultInstruction;
@@ -48,7 +48,7 @@ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedToken
48
48
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
49
49
  const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
50
50
  const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
51
- return program.methods
51
+ return yield program.methods
52
52
  .liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
53
53
  )
54
54
  .accounts({
@@ -15,6 +15,7 @@ const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
16
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
17
17
  const Constants_1 = require("../Constants");
18
+ const Errors_1 = require("utils/Errors");
18
19
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
21
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
@@ -27,7 +28,7 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
27
28
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
28
29
  const history = web3_js_1.Keypair.generate();
29
30
  const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
30
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
31
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]).catch(Errors_1.parseAnchorErrors);
31
32
  return vaultPublicKey;
32
33
  });
33
34
  }
@@ -39,7 +40,7 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
39
40
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
40
41
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
41
42
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
42
- return program.methods
43
+ return yield program.methods
43
44
  .loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
44
45
  )
45
46
  .accounts({
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.refreshOraclePriceInstruction = exports.refreshOraclePrice = void 0;
12
+ exports.Cluster = exports.refreshOraclePriceInstruction = exports.refreshOraclePrice = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const web3_js_1 = require("@solana/web3.js");
15
15
  const Constants_1 = require("../Constants");
@@ -46,7 +46,7 @@ var Cluster;
46
46
  Cluster["Testing"] = "Testing";
47
47
  Cluster["Devnet"] = "Devnet";
48
48
  Cluster["MainnetBeta"] = "MainnetBeta";
49
- })(Cluster || (Cluster = {}));
49
+ })(Cluster = exports.Cluster || (exports.Cluster = {}));
50
50
  const pythAccounts = {
51
51
  Testing: web3_js_1.SystemProgram.programId,
52
52
  Devnet: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.32",
3
+ "version": "0.1.35",
4
4
  "description": "Hedge Javascript Web3 API",
5
5
  "main": "lib/index.js",
6
6
  "types": "declarations/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "author": "Chris Coudron <coudron@hedge.so>",
15
15
  "license": "ISC",
16
16
  "dependencies": {
17
- "@project-serum/anchor": "^0.23.0",
17
+ "@project-serum/anchor": "^0.24.2",
18
18
  "@project-serum/serum": "^0.13.61",
19
19
  "@rollup/plugin-typescript": "^8.3.0",
20
20
  "@solana/buffer-layout": "^4.0.0",
package/src/Constants.ts CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from '@solana/spl-token'
5
5
  import { PublicKey } from '@solana/web3.js'
6
6
 
7
- export const HEDGE_PROGRAM_ID = 'HDG3uyafYaKxSYRW37ZBTdxaUCoyzaqbuirYucAeaPFY'
7
+ export const HEDGE_PROGRAM_ID = 'HDG4FDos8fyrB79qMCe98gaFjNEy5kpxGNjMc5V8M6TJ'
8
8
  export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
9
9
 
10
10
  export const CHAINLINK_SOL_USD_ID =
@@ -30,8 +30,6 @@ export async function claimLiquidationPoolPosition(
30
30
  const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
31
31
  const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint
32
32
 
33
- const poolStatePublicKey = await getLiquidationPoolStatePublicKey()
34
- const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey, collateralMintPublicKey)
35
33
  const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
36
34
  provider.connection,
37
35
  payer,
@@ -42,8 +40,6 @@ export async function claimLiquidationPoolPosition(
42
40
  const transaction = new Transaction().add(
43
41
  await claimLiquidationPoolPositionInstruction(
44
42
  program,
45
- poolStatePublicKey,
46
- poolAssociatedTokenAccount,
47
43
  vaultTypeAccountPublicKey,
48
44
  collateralMintPublicKey,
49
45
  poolPosition,
@@ -58,8 +54,6 @@ export async function claimLiquidationPoolPosition(
58
54
 
59
55
  export async function claimLiquidationPoolPositionInstruction(
60
56
  program: Program<Vault>,
61
- poolState: PublicKey,
62
- poolAssociatedTokenAccount: PublicKey,
63
57
  vaultTypeAccount: PublicKey,
64
58
  collateralMint: PublicKey,
65
59
  poolPosition: PublicKey,
@@ -67,11 +61,15 @@ export async function claimLiquidationPoolPositionInstruction(
67
61
  payerAssociatedTokenAccount: PublicKey,
68
62
  overrideStartTime?: number
69
63
  ): Promise<TransactionInstruction> {
64
+
65
+ console.log("inside function")
70
66
  const vaultSystemState = await getVaultSystemStatePublicKey()
67
+ const poolStatePublicKey = await getLiquidationPoolStatePublicKey()
68
+ const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey, collateralMint)
71
69
 
72
70
  return await program.methods.claimLiquidationPoolPosition().accounts({
73
71
  vaultSystemState: vaultSystemState,
74
- poolState: poolState,
72
+ poolState: poolStatePublicKey,
75
73
  poolAssociatedTokenAccount: poolAssociatedTokenAccount,
76
74
  vaultTypeAccount: vaultTypeAccount,
77
75
  collateralMint: collateralMint,
@@ -225,7 +225,7 @@ export async function createVaultInstruction(
225
225
  ): Promise<TransactionInstruction> {
226
226
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
227
227
 
228
- const ix = program.methods
228
+ return await program.methods
229
229
  .createVault(
230
230
  salt,
231
231
  new BN(depositAmount),
@@ -249,5 +249,4 @@ export async function createVaultInstruction(
249
249
  rent: SYSVAR_RENT_PUBKEY,
250
250
  })
251
251
  .instruction()
252
- return ix
253
252
  }
@@ -154,7 +154,7 @@ export async function liquidateVaultInstruction(
154
154
  const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
155
155
  const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
156
156
 
157
- return program.methods
157
+ return await program.methods
158
158
  .liquidateVault(
159
159
  new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
160
160
  )
@@ -19,6 +19,7 @@ import {
19
19
  getVaultSystemStatePublicKey,
20
20
  } from '../Constants'
21
21
  import { Vault } from 'idl/vault'
22
+ import { parseAnchorErrors } from 'utils/Errors'
22
23
 
23
24
  export async function loanVault(
24
25
  program: Program<Vault>,
@@ -84,7 +85,7 @@ export async function loanVault(
84
85
  overrideTime
85
86
  )
86
87
  )
87
- await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
88
+ await sendAndConfirmTransaction(provider.connection, transaction, [payer, history]).catch(parseAnchorErrors)
88
89
  return vaultPublicKey
89
90
  }
90
91
 
@@ -112,7 +113,7 @@ export async function loanVaultInstruction(
112
113
  ushMintPublickey
113
114
  )
114
115
 
115
- return program.methods
116
+ return await program.methods
116
117
  .loanVault(
117
118
  new BN(loanAmount),
118
119
  new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
@@ -59,7 +59,7 @@ export async function refreshOraclePriceInstruction(
59
59
  .instruction()
60
60
  }
61
61
 
62
- enum Cluster {
62
+ export enum Cluster {
63
63
  Testing = 'Testing',
64
64
  Devnet = 'Devnet',
65
65
  MainnetBeta = 'MainnetBeta',
package/tsconfig.json CHANGED
@@ -18,4 +18,4 @@
18
18
  "outDir": "./lib",
19
19
  },
20
20
  "include": ["src"]
21
- }
21
+ }