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
@@ -11,7 +11,7 @@ const enc = new TextEncoder()
|
|
11
11
|
* @returns The Liquidation pool public key
|
12
12
|
*/
|
13
13
|
export async function getLiquidationPoolStatePublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
|
14
|
-
const [poolPublicKey] = await PublicKey.
|
14
|
+
const [poolPublicKey] = await PublicKey.findProgramAddressSync([enc.encode('LiquidationPoolStateV1')], hedgeProgramId)
|
15
15
|
return poolPublicKey
|
16
16
|
}
|
17
17
|
/**
|
@@ -19,7 +19,7 @@ export async function getLiquidationPoolStatePublicKey(hedgeProgramId: PublicKey
|
|
19
19
|
* @returns The liquidation pool ush account public key
|
20
20
|
*/
|
21
21
|
export async function getLiquidationPoolUshAccountPublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
|
22
|
-
const [poolPublicKey] = await PublicKey.
|
22
|
+
const [poolPublicKey] = await PublicKey.findProgramAddressSync([enc.encode('LiquidationPoolUSHAccountV1')], hedgeProgramId)
|
23
23
|
return poolPublicKey
|
24
24
|
}
|
25
25
|
/**
|
@@ -27,7 +27,7 @@ export async function getLiquidationPoolUshAccountPublicKey(hedgeProgramId: Publ
|
|
27
27
|
* @returns The USH mint public key
|
28
28
|
*/
|
29
29
|
export async function getUshMintPublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
|
30
|
-
const [findMintPublicKey] = await PublicKey.
|
30
|
+
const [findMintPublicKey] = await PublicKey.findProgramAddressSync([enc.encode('UshMintV1')], hedgeProgramId)
|
31
31
|
return findMintPublicKey
|
32
32
|
}
|
33
33
|
/**
|
@@ -35,7 +35,7 @@ export async function getUshMintPublicKey(hedgeProgramId: PublicKey): Promise<Pu
|
|
35
35
|
* @returns The Vault System State public key
|
36
36
|
*/
|
37
37
|
export async function getVaultSystemStatePublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
|
38
|
-
const [publicKey] = await PublicKey.
|
38
|
+
const [publicKey] = await PublicKey.findProgramAddressSync([enc.encode('VaultSystemStateV1')], hedgeProgramId)
|
39
39
|
return publicKey
|
40
40
|
}
|
41
41
|
|
@@ -44,7 +44,7 @@ export async function getVaultSystemStatePublicKey(hedgeProgramId: PublicKey): P
|
|
44
44
|
* @returns The Referral State public key
|
45
45
|
*/
|
46
46
|
export async function getReferralStatePublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
|
47
|
-
const [publicKey] = await PublicKey.
|
47
|
+
const [publicKey] = await PublicKey.findProgramAddressSync([enc.encode('ReferralStateV1')], hedgeProgramId)
|
48
48
|
return publicKey
|
49
49
|
}
|
50
50
|
|
@@ -54,7 +54,7 @@ export async function getReferralStatePublicKey(hedgeProgramId: PublicKey): Prom
|
|
54
54
|
*/
|
55
55
|
export async function getReferralAccountPublicKey(hedgeProgramId: PublicKey, ownerPublicKey: PublicKey): Promise<PublicKey> {
|
56
56
|
const strToEncode = ownerPublicKey.toBuffer() //.substring(0, 28)
|
57
|
-
const [publicKey] = await PublicKey.
|
57
|
+
const [publicKey] = await PublicKey.findProgramAddressSync([enc.encode('refer_acct'), strToEncode], hedgeProgramId)
|
58
58
|
return publicKey
|
59
59
|
}
|
60
60
|
|
@@ -67,31 +67,16 @@ export async function getUserReferralAccountPublicKey(
|
|
67
67
|
ownerPublicKey: PublicKey
|
68
68
|
): Promise<PublicKey> {
|
69
69
|
const strToEncode = ownerPublicKey.toBuffer() //.substring(0, 28)
|
70
|
-
const [publicKey] = await PublicKey.
|
70
|
+
const [publicKey] = await PublicKey.findProgramAddressSync([enc.encode('user_ref'), strToEncode], hedgeProgramId)
|
71
71
|
return publicKey
|
72
72
|
}
|
73
73
|
|
74
|
-
/**
|
75
|
-
*
|
76
|
-
* @returns The compound pool position address for the given user
|
77
|
-
*/
|
78
|
-
export async function getCompoundPoolPositionAddress(
|
79
|
-
hedgeProgramId: PublicKey,
|
80
|
-
poolPublicKey: PublicKey,
|
81
|
-
ownerPublicKey: PublicKey
|
82
|
-
): Promise<PublicKey> {
|
83
|
-
const strToEncode = poolPublicKey.toBuffer()
|
84
|
-
const strToEncode2 = ownerPublicKey.toBuffer()
|
85
|
-
const [compoundPoolPosition] = await PublicKey.findProgramAddress([strToEncode, strToEncode2], hedgeProgramId)
|
86
|
-
return compoundPoolPosition
|
87
|
-
}
|
88
|
-
|
89
74
|
/**
|
90
75
|
*
|
91
76
|
* @returns The HDG mint public key
|
92
77
|
*/
|
93
78
|
export async function getHedgeMintPublicKey(hedgeProgramId: PublicKey): Promise<PublicKey> {
|
94
|
-
const [publicKey] = await PublicKey.
|
79
|
+
const [publicKey] = await PublicKey.findProgramAddressSync([enc.encode('HEDGEMintV1')], hedgeProgramId)
|
95
80
|
return publicKey
|
96
81
|
}
|
97
82
|
/**
|
@@ -105,32 +90,17 @@ export async function getPoolPublicKeyForMint(
|
|
105
90
|
mintPublicKey: PublicKey
|
106
91
|
): Promise<[PublicKey, number, string]> {
|
107
92
|
const strToEncode = mintPublicKey.toString().substring(0, 12)
|
108
|
-
const [publicKey, bump] = await PublicKey.
|
93
|
+
const [publicKey, bump] = await PublicKey.findProgramAddressSync([enc.encode(strToEncode)], hedgeProgramId)
|
109
94
|
return [publicKey, bump, strToEncode]
|
110
95
|
}
|
111
96
|
|
112
|
-
/**
|
113
|
-
* Get the public key for any compound staking pool
|
114
|
-
*
|
115
|
-
* @param mintPublicKey Staked collateral mint public key
|
116
|
-
* @returns the public key for that compound staking pool
|
117
|
-
*/
|
118
|
-
export async function getCompoundPoolPublicKeyForMint(
|
119
|
-
hedgeProgramId: PublicKey,
|
120
|
-
mintPublicKey: PublicKey
|
121
|
-
): Promise<[PublicKey, number]> {
|
122
|
-
const strToEncode = mintPublicKey.toBuffer()
|
123
|
-
const [publicKey, bump] = await PublicKey.findProgramAddress([enc.encode('CompoundPoolV1'), strToEncode], hedgeProgramId)
|
124
|
-
return [publicKey, bump]
|
125
|
-
}
|
126
|
-
|
127
97
|
/**
|
128
98
|
*
|
129
99
|
* @param collateralType String name of the collateral type (must be 16 chars)
|
130
100
|
* @returns The public key for that Vault Type account
|
131
101
|
*/
|
132
102
|
export async function getVaultTypeAccountPublicKey(hedgeProgramId: PublicKey, collateralType: string): Promise<PublicKey> {
|
133
|
-
const [vaultTypeAccount] = await PublicKey.
|
103
|
+
const [vaultTypeAccount] = await PublicKey.findProgramAddressSync(
|
134
104
|
[enc.encode(collateralType), enc.encode('State')],
|
135
105
|
hedgeProgramId
|
136
106
|
)
|
@@ -146,7 +116,7 @@ export async function getVaultTypeOracleAccountPublicKey(
|
|
146
116
|
hedgeProgramId: PublicKey,
|
147
117
|
collateralType: string
|
148
118
|
): Promise<PublicKey> {
|
149
|
-
const [vaultTypeOracleAccount] = await PublicKey.
|
119
|
+
const [vaultTypeOracleAccount] = await PublicKey.findProgramAddressSync(
|
150
120
|
[enc.encode(collateralType), enc.encode('Oracle')],
|
151
121
|
hedgeProgramId
|
152
122
|
)
|
@@ -160,7 +130,7 @@ export async function getVaultTypeOracleAccountPublicKey(
|
|
160
130
|
* @returns The public key for that Vault Type oracle info
|
161
131
|
*/
|
162
132
|
export async function findVaultAddress(hedgeProgramId: PublicKey, vaultSalt: string): Promise<PublicKey> {
|
163
|
-
const [vaultAddress] = await PublicKey.
|
133
|
+
const [vaultAddress] = await PublicKey.findProgramAddressSync([enc.encode('Vault'), enc.encode(vaultSalt)], hedgeProgramId)
|
164
134
|
return vaultAddress
|
165
135
|
}
|
166
136
|
|
@@ -176,7 +146,7 @@ export async function findAssociatedTokenAddress(
|
|
176
146
|
tokenMintAddress: PublicKey
|
177
147
|
): Promise<PublicKey> {
|
178
148
|
return (
|
179
|
-
await PublicKey.
|
149
|
+
await PublicKey.findProgramAddressSync(
|
180
150
|
[walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
|
181
151
|
ASSOCIATED_TOKEN_PROGRAM_ID
|
182
152
|
)
|