hedge-web3 0.2.33 → 0.3.2
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 +278 -1259
- 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/declarations/utils/sendAndConfirmWithDebug.d.ts +2 -2
- package/lib/Constants.js +14 -41
- 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 +277 -1258
- 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 +35 -50
- package/lib/instructions/depositLiquidationPool.js +12 -13
- package/lib/instructions/depositStakingPool.js +8 -9
- package/lib/instructions/depositVault.js +15 -26
- package/lib/instructions/initHedgeFoundation.js +24 -13
- package/lib/instructions/initHedgeFoundationTokens.js +7 -8
- package/lib/instructions/liquidateVault.js +12 -19
- package/lib/instructions/loanVault.js +17 -24
- 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 -12
- package/lib/instructions/referralClaimFees.js +9 -10
- package/lib/instructions/refreshOraclePrice.js +10 -10
- 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 +10 -11
- package/lib/state/VaultAccount.js +23 -9
- 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 +50 -14
- package/package.json +9 -8
- package/src/{Constants.ts → HedgeConstants.ts} +13 -43
- package/src/idl/vault.ts +2004 -3966
- 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 +26 -37
- package/src/instructions/depositLiquidationPool.ts +2 -2
- package/src/instructions/depositStakingPool.ts +2 -2
- package/src/instructions/depositVault.ts +24 -18
- package/src/instructions/initHedgeFoundation.ts +19 -4
- package/src/instructions/initHedgeFoundationTokens.ts +2 -2
- package/src/instructions/liquidateVault.ts +29 -39
- package/src/instructions/loanVault.ts +24 -37
- 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 -3
- package/src/instructions/referralClaimFees.ts +11 -9
- package/src/instructions/refreshOraclePrice.ts +5 -5
- 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 +4 -4
- package/src/state/VaultAccount.ts +1 -1
- package/src/utils/Errors.ts +1 -1
- package/src/utils/getLinkedListAccounts.ts +1 -1
- package/src/utils/sendAndConfirmWithDebug.ts +72 -23
- 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
@@ -1,24 +1,18 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
|
-
ComputeBudgetProgram,
|
5
4
|
Keypair,
|
6
|
-
PublicKey,
|
7
|
-
Signer,
|
5
|
+
PublicKey, Signer,
|
8
6
|
SystemProgram,
|
9
7
|
Transaction,
|
10
|
-
TransactionInstruction
|
8
|
+
TransactionInstruction
|
11
9
|
} from '@solana/web3.js'
|
12
10
|
import {
|
13
11
|
findAssociatedTokenAddress,
|
14
12
|
getHedgeMintPublicKey,
|
15
|
-
getPoolPublicKeyForMint,
|
16
|
-
|
17
|
-
|
18
|
-
getUserReferralAccountPublicKey,
|
19
|
-
getUshMintPublicKey,
|
20
|
-
getVaultSystemStatePublicKey,
|
21
|
-
} from '../Constants'
|
13
|
+
getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
|
14
|
+
getVaultSystemStatePublicKey
|
15
|
+
} from '../HedgeConstants'
|
22
16
|
import { Vault } from '../idl/vault'
|
23
17
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
24
18
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -32,11 +26,6 @@ export async function loanVault(
|
|
32
26
|
overrideTime?: number,
|
33
27
|
referrer?: PublicKey
|
34
28
|
): Promise<PublicKey> {
|
35
|
-
const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
|
36
|
-
units: 300000,
|
37
|
-
additionalFee: 0,
|
38
|
-
})
|
39
|
-
|
40
29
|
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
41
30
|
|
42
31
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -83,27 +72,25 @@ export async function loanVault(
|
|
83
72
|
}
|
84
73
|
|
85
74
|
const history = Keypair.generate()
|
86
|
-
const transaction = new Transaction()
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
referralAccountPublicKey,
|
103
|
-
overrideTime
|
104
|
-
)
|
75
|
+
const transaction = new Transaction().add(
|
76
|
+
await loanVaultInstruction(
|
77
|
+
program,
|
78
|
+
payer.publicKey,
|
79
|
+
payerUshAccount.address,
|
80
|
+
vaultPublicKey,
|
81
|
+
vaultAssociatedTokenAccount.address,
|
82
|
+
history.publicKey,
|
83
|
+
vaultAccount.vaultType,
|
84
|
+
vaultTypeAssociatedTokenAccount.address,
|
85
|
+
oldSmallerPublicKey,
|
86
|
+
newSmallerPublicKey,
|
87
|
+
newLargerPublicKey,
|
88
|
+
new BN(loanAmount),
|
89
|
+
referralAccountPublicKey,
|
90
|
+
overrideTime
|
105
91
|
)
|
106
|
-
|
92
|
+
)
|
93
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history], 300000)
|
107
94
|
return vaultPublicKey
|
108
95
|
}
|
109
96
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
PublicKey, Signer,
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
getPoolPublicKeyForMint,
|
12
12
|
getUshMintPublicKey,
|
13
13
|
getVaultSystemStatePublicKey
|
14
|
-
} from '../
|
14
|
+
} from '../HedgeConstants'
|
15
15
|
import { Vault } from '../idl/vault'
|
16
16
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
17
17
|
|
@@ -51,7 +51,7 @@ export async function psmEditAccount(
|
|
51
51
|
|
52
52
|
|
53
53
|
const enc = new TextEncoder()
|
54
|
-
const [psmAccount] = await PublicKey.
|
54
|
+
const [psmAccount] = await PublicKey.findProgramAddressSync(
|
55
55
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
56
56
|
program.programId
|
57
57
|
)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
PublicKey, Signer,
|
@@ -14,7 +14,7 @@ import {
|
|
14
14
|
getReferralStatePublicKey,
|
15
15
|
getUshMintPublicKey,
|
16
16
|
getVaultSystemStatePublicKey
|
17
|
-
} from '../
|
17
|
+
} from '../HedgeConstants'
|
18
18
|
import { Vault } from '../idl/vault'
|
19
19
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
20
20
|
|
@@ -44,7 +44,7 @@ export async function psmMintUsh(
|
|
44
44
|
)
|
45
45
|
|
46
46
|
const enc = new TextEncoder()
|
47
|
-
const [psmAccount] = await PublicKey.
|
47
|
+
const [psmAccount] = await PublicKey.findProgramAddressSync(
|
48
48
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
49
49
|
program.programId
|
50
50
|
)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
PublicKey, Signer,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
getPoolPublicKeyForMint, getReferralAccountPublicKey,
|
13
13
|
getReferralStatePublicKey, getUshMintPublicKey,
|
14
14
|
getVaultSystemStatePublicKey
|
15
|
-
} from '../
|
15
|
+
} from '../HedgeConstants'
|
16
16
|
import { Vault } from '../idl/vault'
|
17
17
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
18
18
|
|
@@ -42,7 +42,7 @@ export async function psmRedeemUsh(
|
|
42
42
|
)
|
43
43
|
|
44
44
|
const enc = new TextEncoder()
|
45
|
-
const [psmAccount] = await PublicKey.
|
45
|
+
const [psmAccount] = await PublicKey.findProgramAddressSync(
|
46
46
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
47
47
|
program.programId
|
48
48
|
)
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
// import { TokenInstructions } from '@project-serum/serum'
|
4
3
|
import {
|
5
4
|
Keypair,
|
6
5
|
PublicKey, Signer,
|
@@ -13,7 +12,7 @@ import {
|
|
13
12
|
getHedgeMintPublicKey,
|
14
13
|
getPoolPublicKeyForMint, getUshMintPublicKey,
|
15
14
|
getVaultSystemStatePublicKey
|
16
|
-
} from '../
|
15
|
+
} from '../HedgeConstants'
|
17
16
|
import { Vault } from '../idl/vault'
|
18
17
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
19
18
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,14 +1,16 @@
|
|
1
|
-
import { Program, Provider } from '@
|
1
|
+
import { Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
3
|
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
PublicKey, Signer,
|
5
|
+
SystemProgram,
|
6
|
+
SYSVAR_RENT_PUBKEY,
|
7
|
+
Transaction,
|
8
|
+
TransactionInstruction
|
9
|
+
} from '@solana/web3.js'
|
10
|
+
import {
|
11
|
+
getHedgeMintPublicKey, getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey,
|
12
|
+
getUshMintPublicKey, getVaultSystemStatePublicKey
|
13
|
+
} from '../HedgeConstants'
|
12
14
|
|
13
15
|
import { Vault } from '../idl/vault'
|
14
16
|
import { parseAnchorErrors } from '../utils/Errors'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import {
|
3
3
|
LAMPORTS_PER_SOL,
|
4
4
|
PublicKey, Signer,
|
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
TransactionInstruction,
|
8
8
|
TransactionSignature
|
9
9
|
} from '@solana/web3.js'
|
10
|
-
import { CHAINLINK_PROGRAM_ID } from '../
|
10
|
+
import { CHAINLINK_PROGRAM_ID } from '../HedgeConstants'
|
11
11
|
import { Vault } from '../idl/vault'
|
12
12
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
13
13
|
|
@@ -23,7 +23,7 @@ export async function refreshOraclePrice(
|
|
23
23
|
const transaction = new Transaction().add(
|
24
24
|
await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime)
|
25
25
|
)
|
26
|
-
return await sendAndConfirmWithDebug(provider.connection, transaction, [payer])
|
26
|
+
return await sendAndConfirmWithDebug(provider.connection, transaction, [payer], 800000)
|
27
27
|
}
|
28
28
|
|
29
29
|
export async function refreshOraclePriceInstruction(
|
@@ -34,11 +34,11 @@ export async function refreshOraclePriceInstruction(
|
|
34
34
|
overrideTime?: number
|
35
35
|
): Promise<TransactionInstruction> {
|
36
36
|
const enc = new TextEncoder()
|
37
|
-
const [oracleInfoAccount] = await PublicKey.
|
37
|
+
const [oracleInfoAccount] = await PublicKey.findProgramAddressSync(
|
38
38
|
[enc.encode(collateralType), enc.encode('Oracle')],
|
39
39
|
program.programId
|
40
40
|
)
|
41
|
-
const [vaultTypeAccount] = await PublicKey.
|
41
|
+
const [vaultTypeAccount] = await PublicKey.findProgramAddressSync(
|
42
42
|
[enc.encode(collateralType), enc.encode('State')],
|
43
43
|
program.programId
|
44
44
|
)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
Keypair,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
getHedgeMintPublicKey,
|
13
13
|
getPoolPublicKeyForMint, getUshMintPublicKey,
|
14
14
|
getVaultSystemStatePublicKey
|
15
|
-
} from '../
|
15
|
+
} from '../HedgeConstants'
|
16
16
|
import { Vault } from '../idl/vault'
|
17
17
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
18
18
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { Program, Provider } from '@
|
1
|
+
import { Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
|
3
|
-
import { getVaultSystemStatePublicKey } from '../
|
3
|
+
import { getVaultSystemStatePublicKey } from '../HedgeConstants'
|
4
4
|
|
5
5
|
import { Vault } from '../idl/vault'
|
6
6
|
import { parseAnchorErrors } from '../utils/Errors'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import {
|
3
3
|
PublicKey, Signer,
|
4
4
|
SystemProgram, Transaction,
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
} from '@solana/web3.js'
|
7
7
|
import {
|
8
8
|
getReferralAccountPublicKey, getVaultSystemStatePublicKey
|
9
|
-
} from '../
|
9
|
+
} from '../HedgeConstants'
|
10
10
|
|
11
11
|
import { Vault } from '../idl/vault'
|
12
12
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import {
|
3
3
|
PublicKey, Signer,
|
4
4
|
SystemProgram, Transaction,
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
} from '@solana/web3.js'
|
7
7
|
import {
|
8
8
|
getReferralStatePublicKey, getVaultSystemStatePublicKey
|
9
|
-
} from '../
|
9
|
+
} from '../HedgeConstants'
|
10
10
|
|
11
11
|
import { Vault } from '../idl/vault'
|
12
12
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import {
|
3
3
|
PublicKey, Signer, Transaction,
|
4
4
|
TransactionInstruction
|
5
5
|
} from '@solana/web3.js'
|
6
6
|
import {
|
7
7
|
getVaultSystemStatePublicKey
|
8
|
-
} from '../
|
8
|
+
} from '../HedgeConstants'
|
9
9
|
|
10
10
|
import { Vault } from '../idl/vault'
|
11
11
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
Keypair,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
getPoolPublicKeyForMint,
|
13
13
|
getUshMintPublicKey,
|
14
14
|
getVaultSystemStatePublicKey
|
15
|
-
} from '../
|
15
|
+
} from '../HedgeConstants'
|
16
16
|
import { Vault } from '../idl/vault'
|
17
17
|
import { parseAnchorErrors } from '../utils/Errors'
|
18
18
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
2
|
-
import { TokenInstructions } from '@project-serum/serum'
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
3
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { NATIVE_MINT } from '@solana/spl-token'
|
4
4
|
import {
|
5
5
|
Keypair,
|
6
6
|
PublicKey, Signer,
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
import {
|
12
12
|
findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
|
13
13
|
getVaultSystemStatePublicKey
|
14
|
-
} from '../
|
14
|
+
} from '../HedgeConstants'
|
15
15
|
import { Vault } from '../idl/vault'
|
16
16
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
17
17
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -35,7 +35,7 @@ export async function withdrawVault(
|
|
35
35
|
const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
|
36
36
|
provider.connection,
|
37
37
|
payer,
|
38
|
-
|
38
|
+
NATIVE_MINT,
|
39
39
|
vaultPublicKey,
|
40
40
|
true
|
41
41
|
)
|
@@ -2,7 +2,7 @@ import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
|
|
2
2
|
import Decimal from 'decimal.js'
|
3
3
|
import { DecimalFromU128 } from '../HedgeDecimal'
|
4
4
|
|
5
|
-
import * as borsh from '@
|
5
|
+
import * as borsh from '@coral-xyz/borsh'
|
6
6
|
import BN from 'bn.js'
|
7
7
|
import VaultType from './VaultType'
|
8
8
|
|
package/src/utils/Errors.ts
CHANGED
@@ -1,27 +1,76 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
Connection,
|
3
|
+
Signer,
|
4
|
+
Transaction,
|
5
|
+
TransactionSignature,
|
6
|
+
VersionedTransaction,
|
7
|
+
ComputeBudgetProgram,
|
8
|
+
Keypair,
|
9
|
+
LAMPORTS_PER_SOL
|
10
|
+
} from '@solana/web3.js'
|
2
11
|
|
3
12
|
export default async function sendAndConfirmWithDebug(
|
4
13
|
connection: Connection,
|
5
|
-
transaction: Transaction,
|
6
|
-
signers: Signer[]
|
14
|
+
transaction: Transaction | VersionedTransaction,
|
15
|
+
signers: Signer[],
|
16
|
+
computeUnits?: number
|
7
17
|
): Promise<TransactionSignature | void> {
|
8
|
-
|
9
|
-
|
10
|
-
.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
throw
|
26
|
-
}
|
27
|
-
|
18
|
+
try {
|
19
|
+
// Get the latest blockhash before sending
|
20
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
|
21
|
+
|
22
|
+
// Set blockhash AND feePayer BEFORE converting to VersionedTransaction
|
23
|
+
if (transaction instanceof Transaction) {
|
24
|
+
// Add compute unit instruction FIRST if requested
|
25
|
+
if (computeUnits) {
|
26
|
+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnits });
|
27
|
+
transaction.instructions.unshift(computeIx);
|
28
|
+
}
|
29
|
+
transaction.recentBlockhash = blockhash;
|
30
|
+
// Ensure feePayer is explicitly set on legacy transaction
|
31
|
+
if (!transaction.feePayer) {
|
32
|
+
transaction.feePayer = signers[0].publicKey;
|
33
|
+
}
|
34
|
+
} else if (computeUnits) {
|
35
|
+
throw new Error('Compute units must be added before creating VersionedTransaction');
|
36
|
+
}
|
37
|
+
|
38
|
+
// Convert legacy Transaction to VersionedTransaction if needed
|
39
|
+
const versionedTx = transaction instanceof Transaction
|
40
|
+
? new VersionedTransaction(transaction.compileMessage())
|
41
|
+
: transaction;
|
42
|
+
|
43
|
+
// For VersionedTransaction, verify blockhash is set
|
44
|
+
if (!(transaction instanceof Transaction) && !versionedTx.message.recentBlockhash) {
|
45
|
+
throw new Error('Versioned transaction requires recent blockhash');
|
46
|
+
}
|
47
|
+
|
48
|
+
// Sign the transaction if signers are provided
|
49
|
+
if (signers.length > 0) {
|
50
|
+
versionedTx.sign(signers);
|
51
|
+
}
|
52
|
+
|
53
|
+
// Send the transaction
|
54
|
+
const signature = await connection.sendTransaction(versionedTx);
|
55
|
+
|
56
|
+
// Confirm using the newer confirmation strategy
|
57
|
+
const confirmationStrategy = {
|
58
|
+
signature,
|
59
|
+
blockhash,
|
60
|
+
lastValidBlockHeight
|
61
|
+
};
|
62
|
+
|
63
|
+
try {
|
64
|
+
await connection.confirmTransaction(confirmationStrategy);
|
65
|
+
return signature;
|
66
|
+
} catch (error) {
|
67
|
+
console.log('There was an error confirming the transaction', error);
|
68
|
+
console.trace();
|
69
|
+
throw error;
|
70
|
+
}
|
71
|
+
} catch (error) {
|
72
|
+
console.log('There was an error sending the transaction', error);
|
73
|
+
console.trace();
|
74
|
+
throw error;
|
75
|
+
}
|
76
|
+
}
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
export declare function adminWithdrawCollateral(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, collateralType: string): Promise<PublicKey>;
|
5
|
-
export declare function adminWithdrawCollateralInstruction(program: Program<Vault>, payerPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, vaultTypeAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
export declare function adminWithdrawUsh(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey): Promise<PublicKey>;
|
5
|
-
export declare function adminWithdrawUshInstruction(program: Program<Vault>, payerPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, poolPublickey: PublicKey): Promise<TransactionInstruction>;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
/** @type {Function} - Creates a new referral account.
|
5
|
-
* This checks the user has enough HDG in their wallet or staked and
|
6
|
-
* then allows them to create a referral account. If they meet the PSM referral threshold,
|
7
|
-
* they will be eligible for PSM cut.
|
8
|
-
* Params:
|
9
|
-
* - program: Program<Vault> : The program instance of Hedge Vault program
|
10
|
-
* - provider: Provider : Current connection
|
11
|
-
* - payer: Signer : who we are creating the referral account for
|
12
|
-
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
13
|
-
* - referrer: PublicKey
|
14
|
-
* - overrideTime?: number
|
15
|
-
*/
|
16
|
-
export declare function compoundCreateReferralAccount(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, stakedTokenMintPublicKey: PublicKey, overrideTime?: number): Promise<PublicKey>;
|
17
|
-
export declare function compoundCreateReferralAccountInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, userReferralAccountPublicKey: PublicKey, overrideTime?: number): Promise<TransactionInstruction>;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
/** @type {Function} - Allows a referrer to claims their fees.
|
5
|
-
* This checks the user has enough HDG in their wallet or staked and
|
6
|
-
* then allows them to claim earned fees. If they meet the PSM referral threshold,
|
7
|
-
* they will be eligible for PSM cut.
|
8
|
-
* Params:
|
9
|
-
* - program: Program<Vault> : The program instance of Hedge Vault program
|
10
|
-
* - provider: Provider : Current connection
|
11
|
-
* - payer: Signer : who we are creating the referral account for
|
12
|
-
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
13
|
-
* - referrer: PublicKey
|
14
|
-
*/
|
15
|
-
export declare function compoundReferralClaimFees(program: Program<Vault>, provider: Provider, payer: Signer, poolPosition: PublicKey, stakedTokenMintPublicKey: PublicKey): Promise<PublicKey>;
|
16
|
-
export declare function compoundReferralClaimFeesInstruction(program: Program<Vault>, payerPublicKey: PublicKey, vaultSystemStatePublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, referralAccountPublicKey: PublicKey, referralStatePublicKey: PublicKey, hedgeMintPublicKey: PublicKey, hdgAssociatedTokenAccountPublicKey: PublicKey, ushMintPublicKey: PublicKey, ushAssociatedTokenAccountPublicKey: PublicKey, communityAssociatedHedgeTokenAccountPublicKey: PublicKey, feePoolPublicKey: PublicKey, feePoolAssociatedUshTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
export declare function createCompoundStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, overrideStartTime?: number): Promise<PublicKey>;
|
5
|
-
export declare function createCompoundStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, mintPublicKey: PublicKey, overrideStartTime?: number): Promise<TransactionInstruction>;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
/// <reference types="bn.js" />
|
2
|
-
import { BN, Program, Provider } from '@project-serum/anchor';
|
3
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
4
|
-
import { Vault } from '../idl/vault';
|
5
|
-
export declare function createCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
|
6
|
-
export declare function createCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
/// <reference types="bn.js" />
|
2
|
-
import { BN, Program, Provider } from '@project-serum/anchor';
|
3
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
4
|
-
import { Vault } from '../idl/vault';
|
5
|
-
export declare function depositCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
|
6
|
-
export declare function depositCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, depositAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
/// <reference types="bn.js" />
|
2
|
-
import { BN, Program, Provider } from '@project-serum/anchor';
|
3
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
4
|
-
import { Vault } from '../idl/vault';
|
5
|
-
export declare function depositRewardsToCompoundStakingPool(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, depositAmount: number, overrideStartTime?: number): Promise<PublicKey>;
|
6
|
-
export declare function depositRewardsToCompoundStakingPoolInstruction(program: Program<Vault>, payerPublicKey: PublicKey, mintPublicKey: PublicKey, historyPublicKey: PublicKey, amount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
export declare function setCompoundPoolActive(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, setActive: boolean): Promise<PublicKey>;
|
5
|
-
export declare function setCompoundPoolActiveInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, poolPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, setActive: boolean): Promise<TransactionInstruction>;
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
import { Vault } from '../idl/vault';
|
4
|
-
export declare function setDelegateWallet(program: Program<Vault>, provider: Provider, payer: Signer, mintPublicKey: PublicKey, delegateWallet: PublicKey): Promise<PublicKey>;
|
5
|
-
export declare function setDelegateWalletInstruction(program: Program<Vault>, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, poolPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, delegateWallet: PublicKey): Promise<TransactionInstruction>;
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor';
|
2
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
3
|
-
export declare function setVaultTypeStatus(program: Program, provider: Provider, payer: Signer, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<PublicKey>;
|
4
|
-
export declare function setVaultTypeStatusInstruction(program: Program, vaultSystemStatePublicKey: PublicKey, payerPublicKey: PublicKey, vaultTypeAccount: PublicKey, deprecated: boolean): Promise<TransactionInstruction>;
|
@@ -1,6 +0,0 @@
|
|
1
|
-
/// <reference types="bn.js" />
|
2
|
-
import { BN, Program, Provider } from '@project-serum/anchor';
|
3
|
-
import { PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
|
4
|
-
import { Vault } from '../idl/vault';
|
5
|
-
export declare function withdrawCompoundStakingPoolPosition(program: Program<Vault>, provider: Provider, payer: Signer, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, claimAmount: number, overrideStartTime?: number): Promise<PublicKey>;
|
6
|
-
export declare function withdrawCompoundStakingPoolPositionInstruction(program: Program<Vault>, payerPublicKey: PublicKey, poolPositionPublicKey: PublicKey, stakedTokenMintPublicKey: PublicKey, claimAmount: BN, overrideStartTime?: number): Promise<TransactionInstruction>;
|