hedge-web3 0.2.33 → 0.3.0
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 +0 -12
- package/declarations/HedgeConstants.d.ts +76 -0
- package/declarations/idl/pyth.d.ts +1 -1
- package/declarations/idl/switchboard.d.ts +1 -1
- package/declarations/idl/vault.d.ts +2 -843
- package/declarations/index.d.ts +1 -12
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createReferralAccount.d.ts +1 -1
- package/declarations/instructions/createStakingPool.d.ts +1 -1
- package/declarations/instructions/createUserReferralAccount.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -2
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -2
- package/declarations/instructions/depositStakingPool.d.ts +1 -2
- package/declarations/instructions/depositVault.d.ts +1 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -2
- package/declarations/instructions/psmEditAccount.d.ts +1 -2
- package/declarations/instructions/psmMintUsh.d.ts +1 -2
- package/declarations/instructions/psmRedeemUsh.d.ts +1 -2
- package/declarations/instructions/redeemVault.d.ts +1 -2
- package/declarations/instructions/referralClaimFees.d.ts +1 -1
- package/declarations/instructions/refreshOraclePrice.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -2
- package/declarations/instructions/setHalted.d.ts +1 -1
- package/declarations/instructions/transferVault.d.ts +1 -1
- package/declarations/instructions/updateReferralAccount.d.ts +1 -2
- package/declarations/instructions/updateReferralState.d.ts +1 -2
- package/declarations/instructions/updateVaultType.d.ts +1 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -2
- package/declarations/state/VaultAccount.d.ts +2 -3
- package/declarations/utils/getLinkedListAccounts.d.ts +1 -2
- package/lib/Constants.js +27 -54
- package/lib/HedgeConstants.js +170 -0
- package/lib/HedgeDecimal.js +1 -2
- package/lib/StakingPools.js +5 -1
- package/lib/Vaults.js +5 -1
- package/lib/idl/vault.js +1 -842
- package/lib/index.js +6 -13
- package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
- package/lib/instructions/claimStakingPoolPosition.js +7 -8
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
- package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
- package/lib/instructions/createReferralAccount.js +10 -11
- package/lib/instructions/createStakingPool.js +10 -11
- package/lib/instructions/createUserReferralAccount.js +9 -10
- package/lib/instructions/createVault.js +20 -21
- package/lib/instructions/depositLiquidationPool.js +12 -13
- package/lib/instructions/depositStakingPool.js +8 -9
- package/lib/instructions/depositVault.js +10 -11
- package/lib/instructions/initHedgeFoundation.js +10 -11
- package/lib/instructions/initHedgeFoundationTokens.js +7 -8
- package/lib/instructions/liquidateVault.js +12 -19
- package/lib/instructions/loanVault.js +16 -23
- package/lib/instructions/psmEditAccount.js +11 -11
- package/lib/instructions/psmMintUsh.js +18 -19
- package/lib/instructions/psmRedeemUsh.js +18 -19
- package/lib/instructions/redeemVault.js +10 -11
- package/lib/instructions/referralClaimFees.js +9 -10
- package/lib/instructions/refreshOraclePrice.js +9 -9
- package/lib/instructions/repayVault.js +12 -13
- package/lib/instructions/setHalted.js +4 -5
- package/lib/instructions/transferVault.js +2 -3
- package/lib/instructions/updateReferralAccount.js +6 -7
- package/lib/instructions/updateReferralState.js +6 -7
- package/lib/instructions/updateVaultType.js +5 -6
- package/lib/instructions/withdrawStakingPool.js +14 -15
- package/lib/instructions/withdrawVault.js +8 -9
- package/lib/state/VaultAccount.js +22 -8
- package/lib/state/VaultHistoryEvent.js +2 -2
- package/lib/utils/Errors.js +2 -3
- package/lib/utils/getLinkedListAccounts.js +2 -3
- package/lib/utils/sendAndConfirmWithDebug.js +1 -1
- package/package.json +9 -8
- package/src/{Constants.ts → HedgeConstants.ts} +13 -43
- package/src/idl/vault.ts +2342 -4024
- package/src/index.ts +3 -12
- package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
- package/src/instructions/claimStakingPoolPosition.ts +2 -2
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
- package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
- package/src/instructions/createReferralAccount.ts +11 -8
- package/src/instructions/createStakingPool.ts +11 -4
- package/src/instructions/createUserReferralAccount.ts +2 -2
- package/src/instructions/createVault.ts +2 -2
- package/src/instructions/depositLiquidationPool.ts +2 -2
- package/src/instructions/depositStakingPool.ts +2 -2
- package/src/instructions/depositVault.ts +2 -2
- package/src/instructions/initHedgeFoundation.ts +2 -2
- package/src/instructions/initHedgeFoundationTokens.ts +2 -2
- package/src/instructions/liquidateVault.ts +29 -39
- package/src/instructions/loanVault.ts +23 -36
- package/src/instructions/psmEditAccount.ts +3 -3
- package/src/instructions/psmMintUsh.ts +3 -3
- package/src/instructions/psmRedeemUsh.ts +3 -3
- package/src/instructions/redeemVault.ts +2 -2
- package/src/instructions/referralClaimFees.ts +11 -9
- package/src/instructions/refreshOraclePrice.ts +4 -4
- package/src/instructions/repayVault.ts +2 -2
- package/src/instructions/setHalted.ts +2 -2
- package/src/instructions/transferVault.ts +1 -1
- package/src/instructions/updateReferralAccount.ts +2 -2
- package/src/instructions/updateReferralState.ts +2 -2
- package/src/instructions/updateVaultType.ts +2 -2
- package/src/instructions/withdrawStakingPool.ts +2 -2
- package/src/instructions/withdrawVault.ts +2 -2
- package/src/utils/Errors.ts +1 -1
- package/src/utils/getLinkedListAccounts.ts +1 -1
- package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
- package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
- package/declarations/instructions/compoundCreateReferralAccount.d.ts +0 -17
- package/declarations/instructions/compoundReferralClaimFees.d.ts +0 -16
- package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
- package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
- package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
- package/declarations/instructions/setDelegateWallet.d.ts +0 -5
- package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
- package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/utils/Sender.d.ts +0 -2
- package/lib/instructions/adminWithdrawCol.js +0 -60
- package/lib/instructions/adminWithdrawUsh.js +0 -57
- package/lib/instructions/compoundCreateReferralAccount.js +0 -83
- package/lib/instructions/compoundReferralClaimFees.js +0 -87
- package/lib/instructions/createCompoundStakingPool.js +0 -58
- package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
- package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
- package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
- package/lib/instructions/setCompoundPoolActive.js +0 -43
- package/lib/instructions/setDelegateWallet.js +0 -43
- package/lib/instructions/setVaultTypeStatus.js +0 -38
- package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
- package/lib/utils/Sender.js +0 -32
- package/src/instructions/adminWithdrawCol.ts +0 -87
- package/src/instructions/adminWithdrawUsh.ts +0 -78
- package/src/instructions/compoundCreateReferralAccount.ts +0 -119
- package/src/instructions/compoundReferralClaimFees.ts +0 -151
- package/src/instructions/createCompoundStakingPool.ts +0 -63
- package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
- package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
- package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
- package/src/instructions/setCompoundPoolActive.ts +0 -51
- package/src/instructions/setDelegateWallet.ts +0 -51
- package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
@@ -0,0 +1,170 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.CHAINLINK_PROGRAM_ID = exports.CHAINLINK_SOL_USD_PUBLICKEY = exports.CHAINLINK_SOL_USD_ID = void 0;
|
13
|
+
exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
|
14
|
+
exports.getLiquidationPoolUshAccountPublicKey = getLiquidationPoolUshAccountPublicKey;
|
15
|
+
exports.getUshMintPublicKey = getUshMintPublicKey;
|
16
|
+
exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
|
17
|
+
exports.getReferralStatePublicKey = getReferralStatePublicKey;
|
18
|
+
exports.getReferralAccountPublicKey = getReferralAccountPublicKey;
|
19
|
+
exports.getUserReferralAccountPublicKey = getUserReferralAccountPublicKey;
|
20
|
+
exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
|
21
|
+
exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
|
22
|
+
exports.getVaultTypeAccountPublicKey = getVaultTypeAccountPublicKey;
|
23
|
+
exports.getVaultTypeOracleAccountPublicKey = getVaultTypeOracleAccountPublicKey;
|
24
|
+
exports.findVaultAddress = findVaultAddress;
|
25
|
+
exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
|
26
|
+
const spl_token_1 = require("@solana/spl-token");
|
27
|
+
const web3_js_1 = require("@solana/web3.js");
|
28
|
+
exports.CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
|
29
|
+
exports.CHAINLINK_SOL_USD_PUBLICKEY = new web3_js_1.PublicKey(exports.CHAINLINK_SOL_USD_ID);
|
30
|
+
exports.CHAINLINK_PROGRAM_ID = 'HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny';
|
31
|
+
const enc = new TextEncoder();
|
32
|
+
/**
|
33
|
+
* @returns The Liquidation pool public key
|
34
|
+
*/
|
35
|
+
function getLiquidationPoolStatePublicKey(hedgeProgramId) {
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
37
|
+
const [poolPublicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('LiquidationPoolStateV1')], hedgeProgramId);
|
38
|
+
return poolPublicKey;
|
39
|
+
});
|
40
|
+
}
|
41
|
+
/**
|
42
|
+
*
|
43
|
+
* @returns The liquidation pool ush account public key
|
44
|
+
*/
|
45
|
+
function getLiquidationPoolUshAccountPublicKey(hedgeProgramId) {
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
47
|
+
const [poolPublicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('LiquidationPoolUSHAccountV1')], hedgeProgramId);
|
48
|
+
return poolPublicKey;
|
49
|
+
});
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* @returns The USH mint public key
|
54
|
+
*/
|
55
|
+
function getUshMintPublicKey(hedgeProgramId) {
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
57
|
+
const [findMintPublicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('UshMintV1')], hedgeProgramId);
|
58
|
+
return findMintPublicKey;
|
59
|
+
});
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
*
|
63
|
+
* @returns The Vault System State public key
|
64
|
+
*/
|
65
|
+
function getVaultSystemStatePublicKey(hedgeProgramId) {
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
67
|
+
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('VaultSystemStateV1')], hedgeProgramId);
|
68
|
+
return publicKey;
|
69
|
+
});
|
70
|
+
}
|
71
|
+
/**
|
72
|
+
*
|
73
|
+
* @returns The Referral State public key
|
74
|
+
*/
|
75
|
+
function getReferralStatePublicKey(hedgeProgramId) {
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
77
|
+
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('ReferralStateV1')], hedgeProgramId);
|
78
|
+
return publicKey;
|
79
|
+
});
|
80
|
+
}
|
81
|
+
/**
|
82
|
+
*
|
83
|
+
* @returns The Referral State public key based off the owner's public key
|
84
|
+
*/
|
85
|
+
function getReferralAccountPublicKey(hedgeProgramId, ownerPublicKey) {
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
87
|
+
const strToEncode = ownerPublicKey.toBuffer(); //.substring(0, 28)
|
88
|
+
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('refer_acct'), strToEncode], hedgeProgramId);
|
89
|
+
return publicKey;
|
90
|
+
});
|
91
|
+
}
|
92
|
+
/**
|
93
|
+
*
|
94
|
+
* @returns The user referral account public key based off the user's public key
|
95
|
+
*/
|
96
|
+
function getUserReferralAccountPublicKey(hedgeProgramId, ownerPublicKey) {
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
98
|
+
const strToEncode = ownerPublicKey.toBuffer(); //.substring(0, 28)
|
99
|
+
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('user_ref'), strToEncode], hedgeProgramId);
|
100
|
+
return publicKey;
|
101
|
+
});
|
102
|
+
}
|
103
|
+
/**
|
104
|
+
*
|
105
|
+
* @returns The HDG mint public key
|
106
|
+
*/
|
107
|
+
function getHedgeMintPublicKey(hedgeProgramId) {
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
109
|
+
const [publicKey] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('HEDGEMintV1')], hedgeProgramId);
|
110
|
+
return publicKey;
|
111
|
+
});
|
112
|
+
}
|
113
|
+
/**
|
114
|
+
* Get the public key for any staking pool
|
115
|
+
*
|
116
|
+
* @param mintPublicKey Staked collateral mint public key
|
117
|
+
* @returns the public key for that staking pool
|
118
|
+
*/
|
119
|
+
function getPoolPublicKeyForMint(hedgeProgramId, mintPublicKey) {
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
121
|
+
const strToEncode = mintPublicKey.toString().substring(0, 12);
|
122
|
+
const [publicKey, bump] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode(strToEncode)], hedgeProgramId);
|
123
|
+
return [publicKey, bump, strToEncode];
|
124
|
+
});
|
125
|
+
}
|
126
|
+
/**
|
127
|
+
*
|
128
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
129
|
+
* @returns The public key for that Vault Type account
|
130
|
+
*/
|
131
|
+
function getVaultTypeAccountPublicKey(hedgeProgramId, collateralType) {
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
133
|
+
const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode(collateralType), enc.encode('State')], hedgeProgramId);
|
134
|
+
return vaultTypeAccount;
|
135
|
+
});
|
136
|
+
}
|
137
|
+
/**
|
138
|
+
*
|
139
|
+
* @param collateralType String name of the collateral type (must be 16 chars)
|
140
|
+
* @returns The public key for that Vault Type oracle info
|
141
|
+
*/
|
142
|
+
function getVaultTypeOracleAccountPublicKey(hedgeProgramId, collateralType) {
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
144
|
+
const [vaultTypeOracleAccount] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode(collateralType), enc.encode('Oracle')], hedgeProgramId);
|
145
|
+
return vaultTypeOracleAccount;
|
146
|
+
});
|
147
|
+
}
|
148
|
+
/**
|
149
|
+
* Vaults are stored in PDA accounts. Use this to get the address from a salt
|
150
|
+
*
|
151
|
+
* @param vaultSalt String salt for the vault (must be 8 chars)
|
152
|
+
* @returns The public key for that Vault Type oracle info
|
153
|
+
*/
|
154
|
+
function findVaultAddress(hedgeProgramId, vaultSalt) {
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
156
|
+
const [vaultAddress] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode('Vault'), enc.encode(vaultSalt)], hedgeProgramId);
|
157
|
+
return vaultAddress;
|
158
|
+
});
|
159
|
+
}
|
160
|
+
/**
|
161
|
+
*
|
162
|
+
* @param walletAddress Owner public key
|
163
|
+
* @param tokenMintAddress Token mint
|
164
|
+
* @returns The associated token account public key
|
165
|
+
*/
|
166
|
+
function findAssociatedTokenAddress(hedgeProgramId, walletAddress, tokenMintAddress) {
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
168
|
+
return (yield web3_js_1.PublicKey.findProgramAddressSync([walletAddress.toBuffer(), spl_token_1.TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
169
|
+
});
|
170
|
+
}
|
package/lib/HedgeDecimal.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.DecimalFromU128 =
|
6
|
+
exports.DecimalFromU128 = DecimalFromU128;
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
8
8
|
/**
|
9
9
|
* Convert a U128 to a Decimal
|
@@ -21,4 +21,3 @@ function DecimalFromU128(value) {
|
|
21
21
|
const adjustedValue = new decimal_js_1.default(value.toString());
|
22
22
|
return adjustedValue.div(new decimal_js_1.default('1e+18'));
|
23
23
|
}
|
24
|
-
exports.DecimalFromU128 = DecimalFromU128;
|
package/lib/StakingPools.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
package/lib/Vaults.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|