hedge-web3 0.2.8 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/Constants.d.ts +47 -0
- package/declarations/idl/pyth.d.ts +80 -0
- package/declarations/idl/vault.d.ts +41 -3
- package/declarations/state/VaultAccount.d.ts +33 -10
- package/declarations/utils/getLinkedListAccounts.d.ts +17 -2
- package/lib/Constants.js +47 -0
- package/lib/idl/pyth.js +82 -0
- package/lib/idl/vault.js +41 -3
- package/lib/instructions/depositVault.js +1 -1
- package/lib/instructions/liquidateVault.js +1 -1
- package/lib/instructions/loanVault.js +1 -1
- package/lib/instructions/redeemVault.js +1 -1
- package/lib/instructions/refreshOraclePrice.js +6 -5
- package/lib/instructions/repayVault.js +1 -1
- package/lib/instructions/withdrawVault.js +1 -1
- package/lib/state/VaultAccount.js +69 -30
- package/lib/utils/getLinkedListAccounts.js +26 -10
- package/package.json +1 -1
- package/src/Constants.ts +50 -4
- package/src/idl/pyth.ts +159 -0
- package/src/idl/vault.ts +82 -6
- package/src/instructions/depositVault.ts +4 -3
- package/src/instructions/liquidateVault.ts +4 -3
- package/src/instructions/loanVault.ts +4 -3
- package/src/instructions/redeemVault.ts +4 -3
- package/src/instructions/refreshOraclePrice.ts +6 -5
- package/src/instructions/repayVault.ts +4 -3
- package/src/instructions/withdrawVault.ts +4 -3
- package/src/state/VaultAccount.ts +79 -36
- package/src/utils/getLinkedListAccounts.ts +31 -13
@@ -4,13 +4,60 @@ export declare const HEDGE_PROGRAM_PUBLICKEY: PublicKey;
|
|
4
4
|
export declare const CHAINLINK_SOL_USD_ID = "FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf";
|
5
5
|
export declare const CHAINLINK_SOL_USD_PUBLICKEY: PublicKey;
|
6
6
|
export declare const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
|
7
|
+
/**
|
8
|
+
* @returns The Liquidation pool public key
|
9
|
+
*/
|
7
10
|
export declare function getLiquidationPoolStatePublicKey(): Promise<PublicKey>;
|
11
|
+
/**
|
12
|
+
*
|
13
|
+
* @returns The liquidation pool ush account public key
|
14
|
+
*/
|
8
15
|
export declare function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey>;
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* @returns The USH mint public key
|
19
|
+
*/
|
9
20
|
export declare function getUshMintPublicKey(): Promise<PublicKey>;
|
21
|
+
/**
|
22
|
+
*
|
23
|
+
* @returns The Vault System State public key
|
24
|
+
*/
|
10
25
|
export declare function getVaultSystemStatePublicKey(): Promise<PublicKey>;
|
26
|
+
/**
|
27
|
+
*
|
28
|
+
* @returns The HDG mint public key
|
29
|
+
*/
|
11
30
|
export declare function getHedgeMintPublicKey(): Promise<PublicKey>;
|
31
|
+
/**
|
32
|
+
* Get the public key for any staking pool
|
33
|
+
*
|
34
|
+
* @param mintPublicKey Staked collateral mint public key
|
35
|
+
* @returns the public key for that staking pool
|
36
|
+
*/
|
12
37
|
export declare function getPoolPublicKeyForMint(mintPublicKey: PublicKey): Promise<[PublicKey, number, string]>;
|
38
|
+
/**
|
39
|
+
*
|
40
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
41
|
+
* @returns The public key for that Vault Type account
|
42
|
+
*/
|
13
43
|
export declare function getVaultTypeAccountPublicKey(collateralType: string): Promise<PublicKey>;
|
44
|
+
/**
|
45
|
+
*
|
46
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
47
|
+
* @returns The public key for that Vault Type oracle info
|
48
|
+
*/
|
14
49
|
export declare function getVaultTypeOracleAccountPublicKey(collateralType: string): Promise<PublicKey>;
|
50
|
+
/**
|
51
|
+
* Vaults are stored in PDA accounts. Use this to get the address from a salt
|
52
|
+
*
|
53
|
+
* @param vaultSalt String salt for the vault (must be 8 chars)
|
54
|
+
* @returns The public key for that Vault Type oracle info
|
55
|
+
*/
|
15
56
|
export declare function findVaultAddress(vaultSalt: string): Promise<PublicKey>;
|
57
|
+
/**
|
58
|
+
*
|
59
|
+
* @param walletAddress Owner public key
|
60
|
+
* @param tokenMintAddress Token mint
|
61
|
+
* @returns The associated token account public key
|
62
|
+
*/
|
16
63
|
export declare function findAssociatedTokenAddress(walletAddress: PublicKey, tokenMintAddress: PublicKey): Promise<PublicKey>;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
export declare type Pyth = {
|
2
|
+
"version": "0.1.0";
|
3
|
+
"name": "pyth";
|
4
|
+
"instructions": [
|
5
|
+
{
|
6
|
+
"name": "initialize";
|
7
|
+
"accounts": [
|
8
|
+
{
|
9
|
+
"name": "payer";
|
10
|
+
"isMut": true;
|
11
|
+
"isSigner": true;
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"name": "price";
|
15
|
+
"isMut": true;
|
16
|
+
"isSigner": true;
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "systemProgram";
|
20
|
+
"isMut": false;
|
21
|
+
"isSigner": false;
|
22
|
+
}
|
23
|
+
];
|
24
|
+
"args": [
|
25
|
+
{
|
26
|
+
"name": "price";
|
27
|
+
"type": "i64";
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"name": "expo";
|
31
|
+
"type": "i32";
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"name": "conf";
|
35
|
+
"type": "u64";
|
36
|
+
}
|
37
|
+
];
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"name": "setPrice";
|
41
|
+
"accounts": [
|
42
|
+
{
|
43
|
+
"name": "price";
|
44
|
+
"isMut": true;
|
45
|
+
"isSigner": false;
|
46
|
+
}
|
47
|
+
];
|
48
|
+
"args": [
|
49
|
+
{
|
50
|
+
"name": "price";
|
51
|
+
"type": "i64";
|
52
|
+
}
|
53
|
+
];
|
54
|
+
}
|
55
|
+
];
|
56
|
+
"accounts": [
|
57
|
+
{
|
58
|
+
"name": "priceWrapper";
|
59
|
+
"type": {
|
60
|
+
"kind": "struct";
|
61
|
+
"fields": [
|
62
|
+
{
|
63
|
+
"name": "price";
|
64
|
+
"type": {
|
65
|
+
"defined": "Price";
|
66
|
+
};
|
67
|
+
}
|
68
|
+
];
|
69
|
+
};
|
70
|
+
}
|
71
|
+
];
|
72
|
+
"errors": [
|
73
|
+
{
|
74
|
+
"code": 6000;
|
75
|
+
"name": "InvalidTradingStatus";
|
76
|
+
"msg": "invalid trading status";
|
77
|
+
}
|
78
|
+
];
|
79
|
+
};
|
80
|
+
export declare const IDL: Pyth;
|
@@ -1754,6 +1754,47 @@ export declare type Vault = {
|
|
1754
1754
|
}
|
1755
1755
|
];
|
1756
1756
|
"args": [];
|
1757
|
+
},
|
1758
|
+
{
|
1759
|
+
"name": "adminResetVault";
|
1760
|
+
"accounts": [
|
1761
|
+
{
|
1762
|
+
"name": "payer";
|
1763
|
+
"isMut": true;
|
1764
|
+
"isSigner": true;
|
1765
|
+
},
|
1766
|
+
{
|
1767
|
+
"name": "vaultSystemState";
|
1768
|
+
"isMut": true;
|
1769
|
+
"isSigner": false;
|
1770
|
+
},
|
1771
|
+
{
|
1772
|
+
"name": "vaultAccount";
|
1773
|
+
"isMut": true;
|
1774
|
+
"isSigner": false;
|
1775
|
+
},
|
1776
|
+
{
|
1777
|
+
"name": "vaultAssociatedTokenAccount";
|
1778
|
+
"isMut": true;
|
1779
|
+
"isSigner": false;
|
1780
|
+
},
|
1781
|
+
{
|
1782
|
+
"name": "vaultTypeAccount";
|
1783
|
+
"isMut": true;
|
1784
|
+
"isSigner": false;
|
1785
|
+
},
|
1786
|
+
{
|
1787
|
+
"name": "vaultTypeAssociatedTokenAccount";
|
1788
|
+
"isMut": true;
|
1789
|
+
"isSigner": false;
|
1790
|
+
}
|
1791
|
+
];
|
1792
|
+
"args": [
|
1793
|
+
{
|
1794
|
+
"name": "amountToSendFromVaultType";
|
1795
|
+
"type": "u64";
|
1796
|
+
}
|
1797
|
+
];
|
1757
1798
|
}
|
1758
1799
|
];
|
1759
1800
|
"accounts": [
|
@@ -2558,9 +2599,6 @@ export declare type Vault = {
|
|
2558
2599
|
},
|
2559
2600
|
{
|
2560
2601
|
"name": "Distributed";
|
2561
|
-
},
|
2562
|
-
{
|
2563
|
-
"name": "Redeemed";
|
2564
2602
|
}
|
2565
2603
|
];
|
2566
2604
|
};
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
3
3
|
import Decimal from 'decimal.js';
|
4
|
+
import BN from 'bn.js';
|
4
5
|
import VaultType from './VaultType';
|
5
6
|
/**
|
6
7
|
* A class that represents an on-chian vault.
|
@@ -13,9 +14,9 @@ export declare class VaultAccount {
|
|
13
14
|
/** The public key of the vault owner. */
|
14
15
|
pdaSalt: string;
|
15
16
|
/** The deposited collateral of the vault (in SOL Lamports). */
|
16
|
-
deposited:
|
17
|
+
deposited: BN;
|
17
18
|
/** The outstanding debt of the vault (in USH Lamports). Denormalized to time 0. */
|
18
|
-
denormalizedDebt:
|
19
|
+
denormalizedDebt: BN;
|
19
20
|
/** The ordered number of when this vault was created. */
|
20
21
|
vaultNumber: number;
|
21
22
|
/** Debt redistribution snapshot */
|
@@ -38,12 +39,6 @@ export declare class VaultAccount {
|
|
38
39
|
* @returns true if publicKey matches the owner publicKey
|
39
40
|
*/
|
40
41
|
isOwnedBy(publicKey: PublicKey): boolean;
|
41
|
-
/**
|
42
|
-
* Get the collateral value in SOL
|
43
|
-
*
|
44
|
-
* @returns collateral value in SOL
|
45
|
-
*/
|
46
|
-
inSol(): number;
|
47
42
|
/**
|
48
43
|
* Get the debt value in USH
|
49
44
|
*
|
@@ -56,8 +51,36 @@ export declare class VaultAccount {
|
|
56
51
|
* @returns example: `1b6ca...azy71s`
|
57
52
|
*/
|
58
53
|
toDisplayString(): string;
|
59
|
-
|
60
|
-
|
54
|
+
/**
|
55
|
+
* Add additional debt to the vault.
|
56
|
+
*
|
57
|
+
* @param {BN} additionalDebt - Additional normalized debt to add in (USH) lamports.
|
58
|
+
* @param {VaultType} vaultTypeAccount - Vault's vaultType
|
59
|
+
*
|
60
|
+
*/
|
61
|
+
addDebt(additionalDebt: BN, vaultTypeAccount: VaultType): void;
|
62
|
+
/**
|
63
|
+
* Repay debt on a vault
|
64
|
+
*
|
65
|
+
* @param {BN} repayAmount - Normalized debt to repay in (USH) lamports.
|
66
|
+
* @param {VaultType} vaultTypeAccount - Vault's vaultType
|
67
|
+
*
|
68
|
+
*/
|
69
|
+
repayDebt(repayAmount: BN, vaultTypeAccount: VaultType): void;
|
70
|
+
/**
|
71
|
+
* Deposit Collateral
|
72
|
+
*
|
73
|
+
* @param {BN} depositAmount - Amount to deposit in (CollateralMint) lamports
|
74
|
+
*
|
75
|
+
*/
|
76
|
+
depositCollateral(depositAmount: BN): void;
|
77
|
+
/**
|
78
|
+
* Withdraw Collateral
|
79
|
+
*
|
80
|
+
* @param {BN} withdrawAmount - Amount to withdraw in (CollateralMint) lamports
|
81
|
+
*
|
82
|
+
*/
|
83
|
+
withdrawCollateral(withdrawAmount: BN): void;
|
61
84
|
redeem(): void;
|
62
85
|
liquidate(): void;
|
63
86
|
updateDebtAndCollateral(vaultTypeAccountData: VaultType): void;
|
@@ -1,5 +1,20 @@
|
|
1
|
-
|
1
|
+
/// <reference types="bn.js" />
|
2
|
+
import { Program, BN } from '@project-serum/anchor';
|
2
3
|
import { PublicKey } from '@solana/web3.js';
|
3
4
|
import { VaultAccount } from '../state/VaultAccount';
|
4
5
|
import { Vault } from '../idl/vault';
|
5
|
-
|
6
|
+
/**
|
7
|
+
* Get the accounts the left and right for re-inserting in the linked list
|
8
|
+
*
|
9
|
+
* @param {Program<Vault>} program - Anchor program <Vault ILD>
|
10
|
+
* @param {PublicKey} vaultTypeAccountPublicKey - Vault Type Account PublicKey
|
11
|
+
* @param {PublicKey} vaultPublicKey - Vault Account PublicKey
|
12
|
+
* @param {BN} depositAmount - Amount that will be deposited into vault with instruction
|
13
|
+
* @param {BN} withdrawAmount - Amount that will be withdrawn from vault with instruction
|
14
|
+
* @param {BN} loanAmount - Amount that will be deposited into vault with transaction (sans fees)
|
15
|
+
* @param {BN} repayAmount - Amount that will be repaid into vault with transaction
|
16
|
+
* @param {boolean} redeem - True if vault is going to be redeemed fully
|
17
|
+
* @param {boolean} liquidate - True if vault is going to be liquidated fully
|
18
|
+
* @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
|
19
|
+
*/
|
20
|
+
export declare function getLinkedListAccounts(program: Program<Vault>, vaultTypeAccountPublicKey: PublicKey, vaultPublicKey: PublicKey, depositAmount: BN, withdrawAmount: BN, loanAmount: BN, repayAmount: BN, redeem: boolean, liquidate: boolean, cachedVaults?: VaultAccount[]): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]>;
|
package/lib/Constants.js
CHANGED
@@ -18,6 +18,9 @@ exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
|
|
18
18
|
exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
|
19
19
|
exports.CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
|
20
20
|
const enc = new TextEncoder();
|
21
|
+
/**
|
22
|
+
* @returns The Liquidation pool public key
|
23
|
+
*/
|
21
24
|
function getLiquidationPoolStatePublicKey() {
|
22
25
|
return __awaiter(this, void 0, void 0, function* () {
|
23
26
|
const [poolPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -25,6 +28,10 @@ function getLiquidationPoolStatePublicKey() {
|
|
25
28
|
});
|
26
29
|
}
|
27
30
|
exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
|
31
|
+
/**
|
32
|
+
*
|
33
|
+
* @returns The liquidation pool ush account public key
|
34
|
+
*/
|
28
35
|
function getLiquidationPoolUshAccountPublicKey() {
|
29
36
|
return __awaiter(this, void 0, void 0, function* () {
|
30
37
|
const [poolPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSHAccountV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -32,6 +39,10 @@ function getLiquidationPoolUshAccountPublicKey() {
|
|
32
39
|
});
|
33
40
|
}
|
34
41
|
exports.getLiquidationPoolUshAccountPublicKey = getLiquidationPoolUshAccountPublicKey;
|
42
|
+
/**
|
43
|
+
*
|
44
|
+
* @returns The USH mint public key
|
45
|
+
*/
|
35
46
|
function getUshMintPublicKey() {
|
36
47
|
return __awaiter(this, void 0, void 0, function* () {
|
37
48
|
const [findMintPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('UshMintV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -39,6 +50,10 @@ function getUshMintPublicKey() {
|
|
39
50
|
});
|
40
51
|
}
|
41
52
|
exports.getUshMintPublicKey = getUshMintPublicKey;
|
53
|
+
/**
|
54
|
+
*
|
55
|
+
* @returns The Vault System State public key
|
56
|
+
*/
|
42
57
|
function getVaultSystemStatePublicKey() {
|
43
58
|
return __awaiter(this, void 0, void 0, function* () {
|
44
59
|
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -46,6 +61,10 @@ function getVaultSystemStatePublicKey() {
|
|
46
61
|
});
|
47
62
|
}
|
48
63
|
exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
|
64
|
+
/**
|
65
|
+
*
|
66
|
+
* @returns The HDG mint public key
|
67
|
+
*/
|
49
68
|
function getHedgeMintPublicKey() {
|
50
69
|
return __awaiter(this, void 0, void 0, function* () {
|
51
70
|
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -53,6 +72,12 @@ function getHedgeMintPublicKey() {
|
|
53
72
|
});
|
54
73
|
}
|
55
74
|
exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
|
75
|
+
/**
|
76
|
+
* Get the public key for any staking pool
|
77
|
+
*
|
78
|
+
* @param mintPublicKey Staked collateral mint public key
|
79
|
+
* @returns the public key for that staking pool
|
80
|
+
*/
|
56
81
|
function getPoolPublicKeyForMint(mintPublicKey) {
|
57
82
|
return __awaiter(this, void 0, void 0, function* () {
|
58
83
|
const strToEncode = mintPublicKey.toString().substring(0, 12);
|
@@ -61,6 +86,11 @@ function getPoolPublicKeyForMint(mintPublicKey) {
|
|
61
86
|
});
|
62
87
|
}
|
63
88
|
exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
|
89
|
+
/**
|
90
|
+
*
|
91
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
92
|
+
* @returns The public key for that Vault Type account
|
93
|
+
*/
|
64
94
|
function getVaultTypeAccountPublicKey(collateralType) {
|
65
95
|
return __awaiter(this, void 0, void 0, function* () {
|
66
96
|
const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -68,6 +98,11 @@ function getVaultTypeAccountPublicKey(collateralType) {
|
|
68
98
|
});
|
69
99
|
}
|
70
100
|
exports.getVaultTypeAccountPublicKey = getVaultTypeAccountPublicKey;
|
101
|
+
/**
|
102
|
+
*
|
103
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
104
|
+
* @returns The public key for that Vault Type oracle info
|
105
|
+
*/
|
71
106
|
function getVaultTypeOracleAccountPublicKey(collateralType) {
|
72
107
|
return __awaiter(this, void 0, void 0, function* () {
|
73
108
|
const [vaultTypeOracleAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -75,6 +110,12 @@ function getVaultTypeOracleAccountPublicKey(collateralType) {
|
|
75
110
|
});
|
76
111
|
}
|
77
112
|
exports.getVaultTypeOracleAccountPublicKey = getVaultTypeOracleAccountPublicKey;
|
113
|
+
/**
|
114
|
+
* Vaults are stored in PDA accounts. Use this to get the address from a salt
|
115
|
+
*
|
116
|
+
* @param vaultSalt String salt for the vault (must be 8 chars)
|
117
|
+
* @returns The public key for that Vault Type oracle info
|
118
|
+
*/
|
78
119
|
function findVaultAddress(vaultSalt) {
|
79
120
|
return __awaiter(this, void 0, void 0, function* () {
|
80
121
|
const [vaultAddress] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], exports.HEDGE_PROGRAM_PUBLICKEY);
|
@@ -82,6 +123,12 @@ function findVaultAddress(vaultSalt) {
|
|
82
123
|
});
|
83
124
|
}
|
84
125
|
exports.findVaultAddress = findVaultAddress;
|
126
|
+
/**
|
127
|
+
*
|
128
|
+
* @param walletAddress Owner public key
|
129
|
+
* @param tokenMintAddress Token mint
|
130
|
+
* @returns The associated token account public key
|
131
|
+
*/
|
85
132
|
function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
|
86
133
|
return __awaiter(this, void 0, void 0, function* () {
|
87
134
|
return (yield web3_js_1.PublicKey.findProgramAddress([
|
package/lib/idl/pyth.js
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.IDL = void 0;
|
4
|
+
exports.IDL = {
|
5
|
+
"version": "0.1.0",
|
6
|
+
"name": "pyth",
|
7
|
+
"instructions": [
|
8
|
+
{
|
9
|
+
"name": "initialize",
|
10
|
+
"accounts": [
|
11
|
+
{
|
12
|
+
"name": "payer",
|
13
|
+
"isMut": true,
|
14
|
+
"isSigner": true
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "price",
|
18
|
+
"isMut": true,
|
19
|
+
"isSigner": true
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"name": "systemProgram",
|
23
|
+
"isMut": false,
|
24
|
+
"isSigner": false
|
25
|
+
}
|
26
|
+
],
|
27
|
+
"args": [
|
28
|
+
{
|
29
|
+
"name": "price",
|
30
|
+
"type": "i64"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"name": "expo",
|
34
|
+
"type": "i32"
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"name": "conf",
|
38
|
+
"type": "u64"
|
39
|
+
}
|
40
|
+
]
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"name": "setPrice",
|
44
|
+
"accounts": [
|
45
|
+
{
|
46
|
+
"name": "price",
|
47
|
+
"isMut": true,
|
48
|
+
"isSigner": false
|
49
|
+
}
|
50
|
+
],
|
51
|
+
"args": [
|
52
|
+
{
|
53
|
+
"name": "price",
|
54
|
+
"type": "i64"
|
55
|
+
}
|
56
|
+
]
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"accounts": [
|
60
|
+
{
|
61
|
+
"name": "priceWrapper",
|
62
|
+
"type": {
|
63
|
+
"kind": "struct",
|
64
|
+
"fields": [
|
65
|
+
{
|
66
|
+
"name": "price",
|
67
|
+
"type": {
|
68
|
+
"defined": "Price"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
]
|
72
|
+
}
|
73
|
+
}
|
74
|
+
],
|
75
|
+
"errors": [
|
76
|
+
{
|
77
|
+
"code": 6000,
|
78
|
+
"name": "InvalidTradingStatus",
|
79
|
+
"msg": "invalid trading status"
|
80
|
+
}
|
81
|
+
]
|
82
|
+
};
|
package/lib/idl/vault.js
CHANGED
@@ -1757,6 +1757,47 @@ exports.IDL = {
|
|
1757
1757
|
}
|
1758
1758
|
],
|
1759
1759
|
"args": []
|
1760
|
+
},
|
1761
|
+
{
|
1762
|
+
"name": "adminResetVault",
|
1763
|
+
"accounts": [
|
1764
|
+
{
|
1765
|
+
"name": "payer",
|
1766
|
+
"isMut": true,
|
1767
|
+
"isSigner": true
|
1768
|
+
},
|
1769
|
+
{
|
1770
|
+
"name": "vaultSystemState",
|
1771
|
+
"isMut": true,
|
1772
|
+
"isSigner": false
|
1773
|
+
},
|
1774
|
+
{
|
1775
|
+
"name": "vaultAccount",
|
1776
|
+
"isMut": true,
|
1777
|
+
"isSigner": false
|
1778
|
+
},
|
1779
|
+
{
|
1780
|
+
"name": "vaultAssociatedTokenAccount",
|
1781
|
+
"isMut": true,
|
1782
|
+
"isSigner": false
|
1783
|
+
},
|
1784
|
+
{
|
1785
|
+
"name": "vaultTypeAccount",
|
1786
|
+
"isMut": true,
|
1787
|
+
"isSigner": false
|
1788
|
+
},
|
1789
|
+
{
|
1790
|
+
"name": "vaultTypeAssociatedTokenAccount",
|
1791
|
+
"isMut": true,
|
1792
|
+
"isSigner": false
|
1793
|
+
}
|
1794
|
+
],
|
1795
|
+
"args": [
|
1796
|
+
{
|
1797
|
+
"name": "amountToSendFromVaultType",
|
1798
|
+
"type": "u64"
|
1799
|
+
}
|
1800
|
+
]
|
1760
1801
|
}
|
1761
1802
|
],
|
1762
1803
|
"accounts": [
|
@@ -2561,9 +2602,6 @@ exports.IDL = {
|
|
2561
2602
|
},
|
2562
2603
|
{
|
2563
2604
|
"name": "Distributed"
|
2564
|
-
},
|
2565
|
-
{
|
2566
|
-
"name": "Redeemed"
|
2567
2605
|
}
|
2568
2606
|
]
|
2569
2607
|
}
|
@@ -38,7 +38,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
38
38
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
39
39
|
const transaction = new web3_js_1.Transaction();
|
40
40
|
const signers = [payer, history];
|
41
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program,
|
41
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(depositAmount), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), false, false);
|
42
42
|
if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
|
43
43
|
transaction.add(web3_js_1.SystemProgram.createAccount({
|
44
44
|
fromPubkey: payer.publicKey,
|
@@ -35,7 +35,7 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
|
|
35
35
|
const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
|
36
36
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultAccount.vaultType, true);
|
37
37
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
|
38
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program,
|
38
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), false, true);
|
39
39
|
const history = web3_js_1.Keypair.generate();
|
40
40
|
const newEra = web3_js_1.Keypair.generate();
|
41
41
|
const transaction = new web3_js_1.Transaction();
|
@@ -27,7 +27,7 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
|
|
27
27
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
28
28
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultAccount.vaultType, true);
|
29
29
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
|
30
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program,
|
30
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(loanAmount), new anchor_1.BN(0), false, false);
|
31
31
|
const history = web3_js_1.Keypair.generate();
|
32
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]);
|
@@ -30,7 +30,7 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
|
|
30
30
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
|
31
31
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
|
32
32
|
const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
33
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program,
|
33
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), true, false);
|
34
34
|
const history = web3_js_1.Keypair.generate();
|
35
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]);
|
@@ -29,6 +29,7 @@ function refreshOraclePriceInstruction(program, collateralType, network, overrid
|
|
29
29
|
const enc = new TextEncoder();
|
30
30
|
const [oracleInfoAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
|
31
31
|
const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
|
32
|
+
const oracleInfo = yield program.account.oracleInfoForCollateralType.fetch(oracleInfoAccount);
|
32
33
|
return yield program.methods
|
33
34
|
.refreshOraclePrice(new anchor_1.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js_1.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
34
35
|
new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000) - 1) // override override time
|
@@ -36,9 +37,9 @@ function refreshOraclePriceInstruction(program, collateralType, network, overrid
|
|
36
37
|
.accounts({
|
37
38
|
oracleInfoAccount: oracleInfoAccount,
|
38
39
|
vaultTypeAccount: vaultTypeAccount,
|
39
|
-
oracleChainlink:
|
40
|
-
oraclePyth:
|
41
|
-
oracleSwitchboard:
|
40
|
+
oracleChainlink: oracleInfo.oracleChainlink,
|
41
|
+
oraclePyth: oracleInfo.oraclePyth,
|
42
|
+
oracleSwitchboard: oracleInfo.oracleSwitchboard,
|
42
43
|
systemProgram: web3_js_1.SystemProgram.programId,
|
43
44
|
chainlinkProgram: Constants_1.CHAINLINK_PROGRAM_ID,
|
44
45
|
})
|
@@ -59,12 +60,12 @@ const pythAccounts = {
|
|
59
60
|
};
|
60
61
|
const chainlinkAccounts = {
|
61
62
|
Testing: web3_js_1.SystemProgram.programId,
|
62
|
-
Devnet: new web3_js_1.PublicKey('
|
63
|
+
Devnet: new web3_js_1.PublicKey('HgTtcbcmp5BeThax5AU8vg4VwK79qAvAKKFMs8txMLW6'),
|
63
64
|
MainnetBeta: web3_js_1.SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
|
64
65
|
};
|
65
66
|
const switchboardAccounts = {
|
66
67
|
Testing: web3_js_1.SystemProgram.programId,
|
67
68
|
// Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
|
68
|
-
Devnet: new web3_js_1.PublicKey('
|
69
|
+
Devnet: new web3_js_1.PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
|
69
70
|
MainnetBeta: web3_js_1.SystemProgram.programId, // Switchboard V2 NOT ON MAINNET YET
|
70
71
|
};
|
@@ -28,7 +28,7 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
|
|
28
28
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
29
29
|
const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultAccount.vaultType, vaultTypeAccount.collateralMint);
|
30
30
|
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
|
31
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program,
|
31
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(Math.abs(repayAmount)), false, false);
|
32
32
|
const history = web3_js_1.Keypair.generate();
|
33
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]);
|
@@ -34,7 +34,7 @@ function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount,
|
|
34
34
|
const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
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
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program,
|
37
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(Math.abs(withdrawAmount)), new anchor_1.BN(0), new anchor_1.BN(0), false, false);
|
38
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;
|