hedge-web3 0.2.9 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/Constants.d.ts +47 -0
- package/declarations/idl/pyth.d.ts +80 -0
- package/declarations/idl/vault.d.ts +46 -3
- package/lib/Constants.js +47 -0
- package/lib/idl/pyth.js +82 -0
- package/lib/idl/vault.js +46 -3
- package/lib/instructions/refreshOraclePrice.js +4 -3
- package/package.json +1 -1
- package/src/Constants.ts +50 -4
- package/src/idl/pyth.ts +159 -0
- package/src/idl/vault.ts +92 -6
- package/src/instructions/refreshOraclePrice.ts +4 -3
@@ -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,52 @@ 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
|
+
"name": "collateralMint";
|
1793
|
+
"isMut": true;
|
1794
|
+
"isSigner": false;
|
1795
|
+
}
|
1796
|
+
];
|
1797
|
+
"args": [
|
1798
|
+
{
|
1799
|
+
"name": "amountToSendFromVaultType";
|
1800
|
+
"type": "u64";
|
1801
|
+
}
|
1802
|
+
];
|
1757
1803
|
}
|
1758
1804
|
];
|
1759
1805
|
"accounts": [
|
@@ -2558,9 +2604,6 @@ export declare type Vault = {
|
|
2558
2604
|
},
|
2559
2605
|
{
|
2560
2606
|
"name": "Distributed";
|
2561
|
-
},
|
2562
|
-
{
|
2563
|
-
"name": "Redeemed";
|
2564
2607
|
}
|
2565
2608
|
];
|
2566
2609
|
};
|
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,52 @@ 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
|
+
"name": "collateralMint",
|
1796
|
+
"isMut": true,
|
1797
|
+
"isSigner": false
|
1798
|
+
}
|
1799
|
+
],
|
1800
|
+
"args": [
|
1801
|
+
{
|
1802
|
+
"name": "amountToSendFromVaultType",
|
1803
|
+
"type": "u64"
|
1804
|
+
}
|
1805
|
+
]
|
1760
1806
|
}
|
1761
1807
|
],
|
1762
1808
|
"accounts": [
|
@@ -2561,9 +2607,6 @@ exports.IDL = {
|
|
2561
2607
|
},
|
2562
2608
|
{
|
2563
2609
|
"name": "Distributed"
|
2564
|
-
},
|
2565
|
-
{
|
2566
|
-
"name": "Redeemed"
|
2567
2610
|
}
|
2568
2611
|
]
|
2569
2612
|
}
|
@@ -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
|
})
|
package/package.json
CHANGED
package/src/Constants.ts
CHANGED
@@ -14,6 +14,9 @@ export const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHn
|
|
14
14
|
|
15
15
|
const enc = new TextEncoder()
|
16
16
|
|
17
|
+
/**
|
18
|
+
* @returns The Liquidation pool public key
|
19
|
+
*/
|
17
20
|
export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
|
18
21
|
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
19
22
|
[enc.encode('LiquidationPoolStateV1')],
|
@@ -21,7 +24,10 @@ export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
|
|
21
24
|
)
|
22
25
|
return poolPublicKey
|
23
26
|
}
|
24
|
-
|
27
|
+
/**
|
28
|
+
*
|
29
|
+
* @returns The liquidation pool ush account public key
|
30
|
+
*/
|
25
31
|
export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
|
26
32
|
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
27
33
|
[enc.encode('LiquidationPoolUSHAccountV1')],
|
@@ -29,7 +35,10 @@ export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey
|
|
29
35
|
)
|
30
36
|
return poolPublicKey
|
31
37
|
}
|
32
|
-
|
38
|
+
/**
|
39
|
+
*
|
40
|
+
* @returns The USH mint public key
|
41
|
+
*/
|
33
42
|
export async function getUshMintPublicKey(): Promise<PublicKey> {
|
34
43
|
const [findMintPublicKey] = await PublicKey.findProgramAddress(
|
35
44
|
[enc.encode('UshMintV1')],
|
@@ -37,7 +46,10 @@ export async function getUshMintPublicKey(): Promise<PublicKey> {
|
|
37
46
|
)
|
38
47
|
return findMintPublicKey
|
39
48
|
}
|
40
|
-
|
49
|
+
/**
|
50
|
+
*
|
51
|
+
* @returns The Vault System State public key
|
52
|
+
*/
|
41
53
|
export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
|
42
54
|
const [publicKey] = await PublicKey.findProgramAddress(
|
43
55
|
[enc.encode('VaultSystemStateV1')],
|
@@ -46,6 +58,10 @@ export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
|
|
46
58
|
return publicKey
|
47
59
|
}
|
48
60
|
|
61
|
+
/**
|
62
|
+
*
|
63
|
+
* @returns The HDG mint public key
|
64
|
+
*/
|
49
65
|
export async function getHedgeMintPublicKey(): Promise<PublicKey> {
|
50
66
|
const [publicKey] = await PublicKey.findProgramAddress(
|
51
67
|
[enc.encode('HEDGEMintV1')],
|
@@ -53,7 +69,12 @@ export async function getHedgeMintPublicKey(): Promise<PublicKey> {
|
|
53
69
|
)
|
54
70
|
return publicKey
|
55
71
|
}
|
56
|
-
|
72
|
+
/**
|
73
|
+
* Get the public key for any staking pool
|
74
|
+
*
|
75
|
+
* @param mintPublicKey Staked collateral mint public key
|
76
|
+
* @returns the public key for that staking pool
|
77
|
+
*/
|
57
78
|
export async function getPoolPublicKeyForMint(
|
58
79
|
mintPublicKey: PublicKey
|
59
80
|
): Promise<[PublicKey, number, string]> {
|
@@ -64,6 +85,12 @@ export async function getPoolPublicKeyForMint(
|
|
64
85
|
)
|
65
86
|
return [publicKey, bump, strToEncode]
|
66
87
|
}
|
88
|
+
|
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
|
+
*/
|
67
94
|
export async function getVaultTypeAccountPublicKey(
|
68
95
|
collateralType: string
|
69
96
|
): Promise<PublicKey> {
|
@@ -73,6 +100,12 @@ export async function getVaultTypeAccountPublicKey(
|
|
73
100
|
)
|
74
101
|
return vaultTypeAccount
|
75
102
|
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
*
|
106
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
107
|
+
* @returns The public key for that Vault Type oracle info
|
108
|
+
*/
|
76
109
|
export async function getVaultTypeOracleAccountPublicKey(
|
77
110
|
collateralType: string
|
78
111
|
): Promise<PublicKey> {
|
@@ -82,6 +115,13 @@ export async function getVaultTypeOracleAccountPublicKey(
|
|
82
115
|
)
|
83
116
|
return vaultTypeOracleAccount
|
84
117
|
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Vaults are stored in PDA accounts. Use this to get the address from a salt
|
121
|
+
*
|
122
|
+
* @param vaultSalt String salt for the vault (must be 8 chars)
|
123
|
+
* @returns The public key for that Vault Type oracle info
|
124
|
+
*/
|
85
125
|
export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
|
86
126
|
const [vaultAddress] = await PublicKey.findProgramAddress(
|
87
127
|
[enc.encode('Vault'), enc.encode(vaultSalt)],
|
@@ -90,6 +130,12 @@ export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
|
|
90
130
|
return vaultAddress
|
91
131
|
}
|
92
132
|
|
133
|
+
/**
|
134
|
+
*
|
135
|
+
* @param walletAddress Owner public key
|
136
|
+
* @param tokenMintAddress Token mint
|
137
|
+
* @returns The associated token account public key
|
138
|
+
*/
|
93
139
|
export async function findAssociatedTokenAddress(
|
94
140
|
walletAddress: PublicKey,
|
95
141
|
tokenMintAddress: PublicKey
|
package/src/idl/pyth.ts
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
export 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
|
+
|
81
|
+
export const IDL: Pyth = {
|
82
|
+
"version": "0.1.0",
|
83
|
+
"name": "pyth",
|
84
|
+
"instructions": [
|
85
|
+
{
|
86
|
+
"name": "initialize",
|
87
|
+
"accounts": [
|
88
|
+
{
|
89
|
+
"name": "payer",
|
90
|
+
"isMut": true,
|
91
|
+
"isSigner": true
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"name": "price",
|
95
|
+
"isMut": true,
|
96
|
+
"isSigner": true
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "systemProgram",
|
100
|
+
"isMut": false,
|
101
|
+
"isSigner": false
|
102
|
+
}
|
103
|
+
],
|
104
|
+
"args": [
|
105
|
+
{
|
106
|
+
"name": "price",
|
107
|
+
"type": "i64"
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"name": "expo",
|
111
|
+
"type": "i32"
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"name": "conf",
|
115
|
+
"type": "u64"
|
116
|
+
}
|
117
|
+
]
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"name": "setPrice",
|
121
|
+
"accounts": [
|
122
|
+
{
|
123
|
+
"name": "price",
|
124
|
+
"isMut": true,
|
125
|
+
"isSigner": false
|
126
|
+
}
|
127
|
+
],
|
128
|
+
"args": [
|
129
|
+
{
|
130
|
+
"name": "price",
|
131
|
+
"type": "i64"
|
132
|
+
}
|
133
|
+
]
|
134
|
+
}
|
135
|
+
],
|
136
|
+
"accounts": [
|
137
|
+
{
|
138
|
+
"name": "priceWrapper",
|
139
|
+
"type": {
|
140
|
+
"kind": "struct",
|
141
|
+
"fields": [
|
142
|
+
{
|
143
|
+
"name": "price",
|
144
|
+
"type": {
|
145
|
+
"defined": "Price"
|
146
|
+
}
|
147
|
+
}
|
148
|
+
]
|
149
|
+
}
|
150
|
+
}
|
151
|
+
],
|
152
|
+
"errors": [
|
153
|
+
{
|
154
|
+
"code": 6000,
|
155
|
+
"name": "InvalidTradingStatus",
|
156
|
+
"msg": "invalid trading status"
|
157
|
+
}
|
158
|
+
]
|
159
|
+
};
|
package/src/idl/vault.ts
CHANGED
@@ -1754,6 +1754,52 @@ export 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
|
+
"name": "collateralMint",
|
1793
|
+
"isMut": true,
|
1794
|
+
"isSigner": false
|
1795
|
+
}
|
1796
|
+
],
|
1797
|
+
"args": [
|
1798
|
+
{
|
1799
|
+
"name": "amountToSendFromVaultType",
|
1800
|
+
"type": "u64"
|
1801
|
+
}
|
1802
|
+
]
|
1757
1803
|
}
|
1758
1804
|
],
|
1759
1805
|
"accounts": [
|
@@ -2558,9 +2604,6 @@ export type Vault = {
|
|
2558
2604
|
},
|
2559
2605
|
{
|
2560
2606
|
"name": "Distributed"
|
2561
|
-
},
|
2562
|
-
{
|
2563
|
-
"name": "Redeemed"
|
2564
2607
|
}
|
2565
2608
|
]
|
2566
2609
|
}
|
@@ -4643,6 +4686,52 @@ export const IDL: Vault = {
|
|
4643
4686
|
}
|
4644
4687
|
],
|
4645
4688
|
"args": []
|
4689
|
+
},
|
4690
|
+
{
|
4691
|
+
"name": "adminResetVault",
|
4692
|
+
"accounts": [
|
4693
|
+
{
|
4694
|
+
"name": "payer",
|
4695
|
+
"isMut": true,
|
4696
|
+
"isSigner": true
|
4697
|
+
},
|
4698
|
+
{
|
4699
|
+
"name": "vaultSystemState",
|
4700
|
+
"isMut": true,
|
4701
|
+
"isSigner": false
|
4702
|
+
},
|
4703
|
+
{
|
4704
|
+
"name": "vaultAccount",
|
4705
|
+
"isMut": true,
|
4706
|
+
"isSigner": false
|
4707
|
+
},
|
4708
|
+
{
|
4709
|
+
"name": "vaultAssociatedTokenAccount",
|
4710
|
+
"isMut": true,
|
4711
|
+
"isSigner": false
|
4712
|
+
},
|
4713
|
+
{
|
4714
|
+
"name": "vaultTypeAccount",
|
4715
|
+
"isMut": true,
|
4716
|
+
"isSigner": false
|
4717
|
+
},
|
4718
|
+
{
|
4719
|
+
"name": "vaultTypeAssociatedTokenAccount",
|
4720
|
+
"isMut": true,
|
4721
|
+
"isSigner": false
|
4722
|
+
},
|
4723
|
+
{
|
4724
|
+
"name": "collateralMint",
|
4725
|
+
"isMut": true,
|
4726
|
+
"isSigner": false
|
4727
|
+
}
|
4728
|
+
],
|
4729
|
+
"args": [
|
4730
|
+
{
|
4731
|
+
"name": "amountToSendFromVaultType",
|
4732
|
+
"type": "u64"
|
4733
|
+
}
|
4734
|
+
]
|
4646
4735
|
}
|
4647
4736
|
],
|
4648
4737
|
"accounts": [
|
@@ -5447,9 +5536,6 @@ export const IDL: Vault = {
|
|
5447
5536
|
},
|
5448
5537
|
{
|
5449
5538
|
"name": "Distributed"
|
5450
|
-
},
|
5451
|
-
{
|
5452
|
-
"name": "Redeemed"
|
5453
5539
|
}
|
5454
5540
|
]
|
5455
5541
|
}
|
@@ -44,6 +44,7 @@ export async function refreshOraclePriceInstruction(
|
|
44
44
|
[enc.encode(collateralType), enc.encode('State')],
|
45
45
|
HEDGE_PROGRAM_PUBLICKEY
|
46
46
|
)
|
47
|
+
const oracleInfo = await program.account.oracleInfoForCollateralType.fetch(oracleInfoAccount)
|
47
48
|
|
48
49
|
return await program.methods
|
49
50
|
.refreshOraclePrice(
|
@@ -53,9 +54,9 @@ export async function refreshOraclePriceInstruction(
|
|
53
54
|
.accounts({
|
54
55
|
oracleInfoAccount: oracleInfoAccount,
|
55
56
|
vaultTypeAccount: vaultTypeAccount,
|
56
|
-
oracleChainlink:
|
57
|
-
oraclePyth:
|
58
|
-
oracleSwitchboard:
|
57
|
+
oracleChainlink: oracleInfo.oracleChainlink,
|
58
|
+
oraclePyth: oracleInfo.oraclePyth,
|
59
|
+
oracleSwitchboard: oracleInfo.oracleSwitchboard,
|
59
60
|
systemProgram: SystemProgram.programId,
|
60
61
|
chainlinkProgram: CHAINLINK_PROGRAM_ID,
|
61
62
|
})
|