hedge-web3 0.1.23 → 0.1.27
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 +3 -3
- package/declarations/idl/vault.d.ts +889 -752
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -1
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
- package/declarations/instructions/depositVault.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -1
- package/declarations/instructions/redeemVault.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -1
- package/declarations/state/LiquidationPosition.d.ts +2 -2
- package/declarations/state/StakingPool.d.ts +1 -1
- package/declarations/state/StakingPoolPosition.d.ts +2 -2
- package/declarations/state/VaultAccount.d.ts +3 -3
- package/declarations/state/VaultHistoryEvent.d.ts +2 -2
- package/lib/Constants.js +10 -10
- package/lib/idl/vault.js +922 -785
- package/lib/instructions/closeLiquidationPoolPosition.js +9 -9
- package/lib/instructions/createStakingPool.js +4 -4
- package/lib/instructions/createVault.js +11 -11
- package/lib/instructions/depositLiquidationPool.js +9 -9
- package/lib/instructions/depositVault.js +8 -8
- package/lib/instructions/initHedgeFoundation.js +4 -4
- package/lib/instructions/liquidateVault.js +9 -9
- package/lib/instructions/loanVault.js +9 -9
- package/lib/instructions/redeemVault.js +10 -10
- package/lib/instructions/repayVault.js +10 -10
- package/lib/instructions/withdrawStakingPool.js +6 -6
- package/lib/instructions/withdrawVault.js +8 -8
- package/lib/state/LiquidationPosition.js +2 -2
- package/lib/state/StakingPool.js +1 -1
- package/lib/state/StakingPoolPosition.js +3 -3
- package/lib/state/VaultAccount.js +2 -2
- package/lib/state/VaultHistoryEvent.js +2 -2
- package/lib/utils/Errors.js +2 -2
- package/package.json +8 -9
- package/src/Constants.ts +73 -31
- package/src/idl/vault.ts +1848 -1574
- package/src/instructions/closeLiquidationPoolPosition.ts +10 -10
- package/src/instructions/createStakingPool.ts +5 -5
- package/src/instructions/createVault.ts +17 -17
- package/src/instructions/depositLiquidationPool.ts +10 -10
- package/src/instructions/depositVault.ts +12 -12
- package/src/instructions/initHedgeFoundation.ts +5 -5
- package/src/instructions/initHedgeFoundationTokens.ts +1 -1
- package/src/instructions/liquidateVault.ts +10 -10
- package/src/instructions/loanVault.ts +11 -11
- package/src/instructions/redeemVault.ts +12 -12
- package/src/instructions/repayVault.ts +12 -12
- package/src/instructions/setHalted.ts +1 -1
- package/src/instructions/withdrawStakingPool.ts +7 -7
- package/src/instructions/withdrawVault.ts +12 -12
- package/src/state/LiquidationPosition.ts +3 -3
- package/src/state/StakingPool.ts +2 -6
- package/src/state/StakingPoolPosition.ts +4 -4
- package/src/state/VaultAccount.ts +3 -3
- package/src/state/VaultHistoryEvent.ts +4 -4
- package/src/utils/Errors.ts +2 -2
- package/declarations/idl/idl.d.ts +0 -2
- package/lib/idl/idl.js +0 -1475
- package/src/idl/idl.ts +0 -1474
package/lib/state/StakingPool.js
CHANGED
@@ -14,7 +14,7 @@ class StakingPool {
|
|
14
14
|
this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber();
|
15
15
|
this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber();
|
16
16
|
this.hedgeRewardAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.hedgeRewardAccumulator);
|
17
|
-
this.
|
17
|
+
this.ushFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolInfo.ushFeeAccumulator);
|
18
18
|
this.collateralFeeAccumulator = poolInfo.collateralFeeAccumulator.map((sum) => { return (0, HedgeDecimal_1.DecimalFromU128)(sum); });
|
19
19
|
// this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
|
20
20
|
}
|
@@ -17,12 +17,12 @@ class StakingPoolPosition {
|
|
17
17
|
this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
|
18
18
|
this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber();
|
19
19
|
this.startHedgeRewardAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startHedgeRewardAccumulator);
|
20
|
-
this.
|
20
|
+
this.startUshFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startUshFeeAccumulator);
|
21
21
|
this.startSolFeeAccumulator = (0, HedgeDecimal_1.DecimalFromU128)(poolPositionInfo.startSolFeeAccumulator);
|
22
22
|
this.open = poolPositionInfo.state.open !== undefined;
|
23
23
|
}
|
24
|
-
|
25
|
-
return this.pool.
|
24
|
+
getCurrentUshFeeReward() {
|
25
|
+
return this.pool.ushFeeAccumulator.minus(this.startUshFeeAccumulator).times(new decimal_js_1.default(this.deposited));
|
26
26
|
}
|
27
27
|
}
|
28
28
|
exports.StakingPoolPosition = StakingPoolPosition;
|
@@ -36,9 +36,9 @@ class VaultAccount {
|
|
36
36
|
return this.deposited / web3_js_1.LAMPORTS_PER_SOL;
|
37
37
|
}
|
38
38
|
/**
|
39
|
-
* Get the debt value in
|
39
|
+
* Get the debt value in USH
|
40
40
|
*
|
41
|
-
* @returns debt value in
|
41
|
+
* @returns debt value in USH
|
42
42
|
*/
|
43
43
|
inUsd() {
|
44
44
|
return this.denormalizedDebt / web3_js_1.LAMPORTS_PER_SOL;
|
@@ -8,8 +8,8 @@ class VaultHistoryEvent {
|
|
8
8
|
this.publicKey = publicKey;
|
9
9
|
this.actorAccount = account.actorAccount;
|
10
10
|
this.usdSolPrice = (0, HedgeDecimal_1.DecimalFromU128)(account.usdSolPrice.toString());
|
11
|
-
this.
|
12
|
-
this.
|
11
|
+
this.ushDebtBefore = account.ushDebtBefore.toNumber();
|
12
|
+
this.ushDebtAfter = account.ushDebtAfter.toNumber();
|
13
13
|
this.collateralBalanceBefore = account.collateralBalanceBefore.toNumber();
|
14
14
|
this.collateralBalanceAfter = account.collateralBalanceAfter.toNumber();
|
15
15
|
this.minCollateralRatioBefore = (0, HedgeDecimal_1.DecimalFromU128)(account.minCollateralRatioBefore);
|
package/lib/utils/Errors.js
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.parseAnchorErrors = void 0;
|
4
4
|
const anchor_1 = require("@project-serum/anchor");
|
5
|
-
const
|
5
|
+
const vault_1 = require("../idl/vault");
|
6
6
|
function parseAnchorErrors(error) {
|
7
|
-
const idlErrors = (0, anchor_1.parseIdlErrors)(
|
7
|
+
const idlErrors = (0, anchor_1.parseIdlErrors)(vault_1.IDL);
|
8
8
|
const parsedError = anchor_1.ProgramError.parse(error, idlErrors);
|
9
9
|
if (parsedError !== null) {
|
10
10
|
throw parsedError;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hedge-web3",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.27",
|
4
4
|
"description": "Hedge Javascript Web3 API",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "declarations/index.d.ts",
|
@@ -13,21 +13,20 @@
|
|
13
13
|
},
|
14
14
|
"author": "Chris Coudron <coudron@hedge.so>",
|
15
15
|
"license": "ISC",
|
16
|
-
"devDependencies": {
|
17
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
18
|
-
"rollup": "^2.62.0",
|
19
|
-
"ts-standard": "^11.0.0",
|
20
|
-
"typedoc": "^0.22.10"
|
21
|
-
},
|
22
16
|
"dependencies": {
|
23
|
-
"@project-serum/anchor": "^0.
|
17
|
+
"@project-serum/anchor": "^0.23.0",
|
24
18
|
"@project-serum/serum": "^0.13.61",
|
19
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
25
20
|
"@solana/buffer-layout": "^4.0.0",
|
26
21
|
"@solana/spl-token": "^0.2.0",
|
27
|
-
"@solana/web3.js": "^1.
|
22
|
+
"@solana/web3.js": "^1.37.0",
|
23
|
+
"@types/bn.js": "^5.1.0",
|
28
24
|
"@types/uuid": "^8.3.4",
|
29
25
|
"bn.js": "^5.2.0",
|
30
26
|
"decimal.js": "^10.3.1",
|
27
|
+
"rollup": "^2.62.0",
|
28
|
+
"ts-standard": "^11.0.0",
|
29
|
+
"typedoc": "^0.22.10",
|
31
30
|
"typescript": "^4.5.5",
|
32
31
|
"uuid": "^8.3.2"
|
33
32
|
}
|
package/src/Constants.ts
CHANGED
@@ -1,64 +1,106 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
3
|
+
TOKEN_PROGRAM_ID,
|
4
|
+
} from '@solana/spl-token'
|
2
5
|
import { PublicKey } from '@solana/web3.js'
|
3
6
|
|
4
|
-
export const HEDGE_PROGRAM_ID = '
|
7
|
+
export const HEDGE_PROGRAM_ID = 'HDG2DRczYGkTuYTwTYy1UUhXXucT2Ujede2j4bWEoE6p'
|
5
8
|
export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
|
6
9
|
|
7
|
-
export const CHAINLINK_SOL_USD_ID =
|
10
|
+
export const CHAINLINK_SOL_USD_ID =
|
11
|
+
'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
|
8
12
|
export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
|
9
13
|
|
10
14
|
const enc = new TextEncoder()
|
11
15
|
|
12
|
-
export async function getLiquidationPoolStatePublicKey
|
13
|
-
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
16
|
+
export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
|
17
|
+
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
18
|
+
[enc.encode('LiquidationPoolStateV1')],
|
19
|
+
HEDGE_PROGRAM_PUBLICKEY
|
20
|
+
)
|
14
21
|
return poolPublicKey
|
15
22
|
}
|
16
23
|
|
17
|
-
export async function
|
18
|
-
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
24
|
+
export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
|
25
|
+
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
26
|
+
[enc.encode('LiquidationPoolUSHAccountV1')],
|
27
|
+
HEDGE_PROGRAM_PUBLICKEY
|
28
|
+
)
|
19
29
|
return poolPublicKey
|
20
30
|
}
|
21
31
|
|
22
|
-
export async function
|
23
|
-
const [findMintPublicKey] = await PublicKey.findProgramAddress(
|
32
|
+
export async function getUshMintPublicKey(): Promise<PublicKey> {
|
33
|
+
const [findMintPublicKey] = await PublicKey.findProgramAddress(
|
34
|
+
[enc.encode('UshMintV1')],
|
35
|
+
HEDGE_PROGRAM_PUBLICKEY
|
36
|
+
)
|
24
37
|
return findMintPublicKey
|
25
38
|
}
|
26
39
|
|
27
|
-
export async function getVaultSystemStatePublicKey
|
28
|
-
const [publicKey] = await PublicKey.findProgramAddress(
|
40
|
+
export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
|
41
|
+
const [publicKey] = await PublicKey.findProgramAddress(
|
42
|
+
[enc.encode('VaultSystemStateV1')],
|
43
|
+
HEDGE_PROGRAM_PUBLICKEY
|
44
|
+
)
|
29
45
|
return publicKey
|
30
46
|
}
|
31
47
|
|
32
|
-
export async function getHedgeMintPublicKey
|
33
|
-
const [publicKey] = await PublicKey.findProgramAddress(
|
48
|
+
export async function getHedgeMintPublicKey(): Promise<PublicKey> {
|
49
|
+
const [publicKey] = await PublicKey.findProgramAddress(
|
50
|
+
[enc.encode('HEDGEMintV1')],
|
51
|
+
HEDGE_PROGRAM_PUBLICKEY
|
52
|
+
)
|
34
53
|
return publicKey
|
35
54
|
}
|
36
55
|
|
37
|
-
export async function getPoolPublicKeyForMint
|
38
|
-
|
39
|
-
|
56
|
+
export async function getPoolPublicKeyForMint(
|
57
|
+
mintPublicKey: PublicKey
|
58
|
+
): Promise<[PublicKey, number, string]> {
|
59
|
+
const strToEncode = mintPublicKey.toString().substring(0, 12)
|
60
|
+
const [publicKey, bump] = await PublicKey.findProgramAddress(
|
61
|
+
[enc.encode(strToEncode)],
|
62
|
+
HEDGE_PROGRAM_PUBLICKEY
|
63
|
+
)
|
40
64
|
return [publicKey, bump, strToEncode]
|
41
65
|
}
|
42
|
-
export async function getVaultTypeAccountPublicKey
|
43
|
-
|
66
|
+
export async function getVaultTypeAccountPublicKey(
|
67
|
+
collateralType: string
|
68
|
+
): Promise<PublicKey> {
|
69
|
+
const [vaultTypeAccount] = await PublicKey.findProgramAddress(
|
70
|
+
[enc.encode(collateralType), enc.encode('State')],
|
71
|
+
HEDGE_PROGRAM_PUBLICKEY
|
72
|
+
)
|
44
73
|
return vaultTypeAccount
|
45
74
|
}
|
46
|
-
export async function getVaultTypeOracleAccountPublicKey
|
47
|
-
|
75
|
+
export async function getVaultTypeOracleAccountPublicKey(
|
76
|
+
collateralType: string
|
77
|
+
): Promise<PublicKey> {
|
78
|
+
const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress(
|
79
|
+
[enc.encode(collateralType), enc.encode('Oracle')],
|
80
|
+
HEDGE_PROGRAM_PUBLICKEY
|
81
|
+
)
|
48
82
|
return vaultTypeOracleAccount
|
49
83
|
}
|
50
|
-
export async function findVaultAddress
|
51
|
-
const [vaultAddress] = await PublicKey.findProgramAddress(
|
84
|
+
export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
|
85
|
+
const [vaultAddress] = await PublicKey.findProgramAddress(
|
86
|
+
[enc.encode('Vault'), enc.encode(vaultSalt)],
|
87
|
+
HEDGE_PROGRAM_PUBLICKEY
|
88
|
+
)
|
52
89
|
return vaultAddress
|
53
90
|
}
|
54
91
|
|
55
|
-
export async function findAssociatedTokenAddress
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
92
|
+
export async function findAssociatedTokenAddress(
|
93
|
+
walletAddress: PublicKey,
|
94
|
+
tokenMintAddress: PublicKey
|
95
|
+
): Promise<PublicKey> {
|
96
|
+
return (
|
97
|
+
await PublicKey.findProgramAddress(
|
98
|
+
[
|
99
|
+
walletAddress.toBuffer(),
|
100
|
+
TOKEN_PROGRAM_ID.toBuffer(),
|
101
|
+
tokenMintAddress.toBuffer(),
|
102
|
+
],
|
103
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
104
|
+
)
|
105
|
+
)[0]
|
64
106
|
}
|