hedge-web3 0.1.32 → 0.1.33
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/refreshOraclePrice.d.ts +1 -2
- package/lib/instructions/claimLiquidationPoolPosition.js +6 -5
- package/lib/instructions/createVault.js +1 -2
- package/lib/instructions/liquidateVault.js +1 -1
- package/lib/instructions/loanVault.js +1 -1
- package/lib/instructions/refreshOraclePrice.js +2 -2
- package/package.json +2 -2
- package/src/instructions/claimLiquidationPoolPosition.ts +5 -7
- package/src/instructions/createVault.ts +1 -2
- package/src/instructions/liquidateVault.ts +1 -1
- package/src/instructions/loanVault.ts +1 -1
- package/src/instructions/refreshOraclePrice.ts +1 -1
- package/tsconfig.json +1 -1
@@ -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>,
|
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 {};
|
@@ -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,
|
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,
|
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:
|
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
|
-
|
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({
|
@@ -39,7 +39,7 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
|
|
39
39
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
40
40
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
41
41
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
42
|
-
return program.methods
|
42
|
+
return yield program.methods
|
43
43
|
.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
44
|
)
|
45
45
|
.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.
|
3
|
+
"version": "0.1.33",
|
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.
|
17
|
+
"@project-serum/anchor": "^0.24.1",
|
18
18
|
"@project-serum/serum": "^0.13.61",
|
19
19
|
"@rollup/plugin-typescript": "^8.3.0",
|
20
20
|
"@solana/buffer-layout": "^4.0.0",
|
@@ -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:
|
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
|
-
|
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
|
)
|
@@ -112,7 +112,7 @@ export async function loanVaultInstruction(
|
|
112
112
|
ushMintPublickey
|
113
113
|
)
|
114
114
|
|
115
|
-
return program.methods
|
115
|
+
return await program.methods
|
116
116
|
.loanVault(
|
117
117
|
new BN(loanAmount),
|
118
118
|
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
|
package/tsconfig.json
CHANGED