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
package/src/index.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export * from './
|
1
|
+
export * from './HedgeConstants'
|
2
2
|
export * from './HedgeDecimal'
|
3
3
|
export * from './idl/vault'
|
4
4
|
export * from './instructions/claimLiquidationPoolPosition'
|
@@ -8,8 +8,6 @@ export * from './instructions/closeLiquidationPoolPosition'
|
|
8
8
|
export * from './instructions/createReferralAccount'
|
9
9
|
export * from './instructions/createStakingPool'
|
10
10
|
export * from './instructions/createUserReferralAccount'
|
11
|
-
export * from './instructions/compoundCreateReferralAccount'
|
12
|
-
export * from './instructions/compoundReferralClaimFees'
|
13
11
|
export * from './instructions/createVault'
|
14
12
|
export * from './instructions/depositLiquidationPool'
|
15
13
|
export * from './instructions/depositStakingPool'
|
@@ -26,15 +24,6 @@ export * from './instructions/refreshOraclePrice'
|
|
26
24
|
export * from './instructions/repayVault'
|
27
25
|
export * from './instructions/setHalted'
|
28
26
|
export * from './instructions/transferVault'
|
29
|
-
export * from './instructions/createCompoundStakingPool'
|
30
|
-
export * from './instructions/createCompoundStakingPoolPosition'
|
31
|
-
export * from './instructions/depositCompoundStakingPoolPosition'
|
32
|
-
export * from './instructions/withdrawCompoundStakingPoolPosition'
|
33
|
-
export * from './instructions/setDelegateWallet'
|
34
|
-
export * from './instructions/setCompoundPoolActive'
|
35
|
-
export * from './instructions/adminWithdrawCol'
|
36
|
-
export * from './instructions/adminWithdrawUsh'
|
37
|
-
export * from './instructions/depositRewardsToCompoundPool'
|
38
27
|
export * from './instructions/updateReferralAccount'
|
39
28
|
export * from './instructions/updateReferralState'
|
40
29
|
export * from './instructions/updateVaultType'
|
@@ -48,3 +37,5 @@ export * from './state/StakingPoolPosition'
|
|
48
37
|
export * from './state/VaultAccount'
|
49
38
|
export * from './state/VaultHistoryEvent'
|
50
39
|
export * from './utils/getLinkedListAccounts'
|
40
|
+
|
41
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Program, Provider } from '@
|
1
|
+
import { Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
PublicKey, Signer,
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
import {
|
11
11
|
findAssociatedTokenAddress, getLiquidationPoolStatePublicKey,
|
12
12
|
getVaultSystemStatePublicKey, getVaultTypeAccountPublicKey
|
13
|
-
} from '../
|
13
|
+
} from '../HedgeConstants'
|
14
14
|
import { Vault } from '../idl/vault'
|
15
15
|
import { parseAnchorErrors } from '../utils/Errors'
|
16
16
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Program, Provider } from '@
|
1
|
+
import { Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
PublicKey, Signer,
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
import {
|
11
11
|
getHedgeMintPublicKey, getPoolPublicKeyForMint,
|
12
12
|
getVaultSystemStatePublicKey, getVaultTypeAccountPublicKey
|
13
|
-
} from '../
|
13
|
+
} from '../HedgeConstants'
|
14
14
|
import { Vault } from '../idl/vault'
|
15
15
|
import { parseAnchorErrors } from '../utils/Errors'
|
16
16
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,4 +1,4 @@
|
|
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
3
|
import { parseAnchorErrors } from '../utils/Errors'
|
4
4
|
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 { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
PublicKey, Signer,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
getLiquidationPoolStatePublicKey,
|
13
13
|
getLiquidationPoolUshAccountPublicKey, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, 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,13 +1,16 @@
|
|
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 { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
3
|
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
} from '
|
4
|
+
PublicKey, Signer,
|
5
|
+
SystemProgram,
|
6
|
+
SYSVAR_RENT_PUBKEY,
|
7
|
+
Transaction,
|
8
|
+
TransactionInstruction
|
9
|
+
} from '@solana/web3.js'
|
10
|
+
import {
|
11
|
+
getHedgeMintPublicKey, getReferralAccountPublicKey, getReferralStatePublicKey,
|
12
|
+
getUserReferralAccountPublicKey, getVaultSystemStatePublicKey
|
13
|
+
} from '../HedgeConstants'
|
11
14
|
|
12
15
|
import { Vault } from '../idl/vault'
|
13
16
|
import { parseAnchorErrors } from '../utils/Errors'
|
@@ -1,12 +1,18 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
PublicKey, Signer,
|
5
|
+
SystemProgram,
|
6
|
+
SYSVAR_RENT_PUBKEY,
|
7
|
+
Transaction,
|
8
|
+
TransactionInstruction
|
9
|
+
} from '@solana/web3.js'
|
4
10
|
import {
|
5
11
|
findAssociatedTokenAddress,
|
6
12
|
getPoolPublicKeyForMint,
|
7
13
|
getUshMintPublicKey,
|
8
|
-
getVaultSystemStatePublicKey
|
9
|
-
} from '../
|
14
|
+
getVaultSystemStatePublicKey
|
15
|
+
} from '../HedgeConstants'
|
10
16
|
import { Vault } from '../idl/vault'
|
11
17
|
import { parseAnchorErrors } from '../utils/Errors'
|
12
18
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -37,6 +43,7 @@ export async function createStakingPoolInstruction(
|
|
37
43
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
38
44
|
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
39
45
|
const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
|
46
|
+
|
40
47
|
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, mintPublicKey)
|
41
48
|
const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
|
42
49
|
return await program.methods
|
@@ -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
|
PublicKey, Signer,
|
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
Transaction,
|
8
8
|
TransactionInstruction
|
9
9
|
} from '@solana/web3.js'
|
10
|
-
import { getReferralAccountPublicKey, getUserReferralAccountPublicKey, getVaultSystemStatePublicKey } from '../
|
10
|
+
import { getReferralAccountPublicKey, getUserReferralAccountPublicKey, getVaultSystemStatePublicKey } from '../HedgeConstants'
|
11
11
|
|
12
12
|
import { Vault } from '../idl/vault'
|
13
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
@@ -1,6 +1,10 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
2
|
-
import {
|
3
|
-
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
|
+
import {
|
3
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
4
|
+
getOrCreateAssociatedTokenAccount,
|
5
|
+
NATIVE_MINT,
|
6
|
+
TOKEN_PROGRAM_ID,
|
7
|
+
} from '@solana/spl-token'
|
4
8
|
import {
|
5
9
|
Keypair,
|
6
10
|
PublicKey,
|
@@ -18,12 +22,14 @@ import {
|
|
18
22
|
getUshMintPublicKey,
|
19
23
|
getVaultSystemStatePublicKey,
|
20
24
|
getVaultTypeAccountPublicKey,
|
21
|
-
} from '../
|
25
|
+
} from '../HedgeConstants'
|
22
26
|
|
23
27
|
import { v4 as uuidv4 } from 'uuid'
|
24
28
|
import { Vault } from '../idl/vault'
|
25
29
|
import { parseAnchorErrors } from '../utils/Errors'
|
26
30
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
31
|
+
import { createInitializeAccountInstruction } from '@solana/spl-token'
|
32
|
+
import { createCloseAccountInstruction } from '@solana/spl-token'
|
27
33
|
|
28
34
|
export async function createVault(
|
29
35
|
program: Program<Vault>,
|
@@ -61,7 +67,7 @@ export async function createVault(
|
|
61
67
|
const transaction = new Transaction()
|
62
68
|
const signers = [payer, history]
|
63
69
|
|
64
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
70
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === NATIVE_MINT.toString()
|
65
71
|
|
66
72
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
67
73
|
program.programId,
|
@@ -82,14 +88,11 @@ export async function createVault(
|
|
82
88
|
programId: TOKEN_PROGRAM_ID,
|
83
89
|
space: 165,
|
84
90
|
}),
|
85
|
-
|
86
|
-
account: wrappedSolAccount.publicKey,
|
87
|
-
mint: TokenInstructions.WRAPPED_SOL_MINT,
|
88
|
-
owner: payer.publicKey,
|
89
|
-
})
|
91
|
+
createInitializeAccountInstruction(wrappedSolAccount.publicKey, NATIVE_MINT, payer.publicKey)
|
90
92
|
)
|
91
93
|
signers.push(wrappedSolAccount)
|
92
94
|
}
|
95
|
+
|
93
96
|
transaction.add(
|
94
97
|
await createVaultInstruction(
|
95
98
|
program,
|
@@ -108,17 +111,11 @@ export async function createVault(
|
|
108
111
|
overrideTime
|
109
112
|
)
|
110
113
|
)
|
114
|
+
|
111
115
|
if (isWrappedSol) {
|
112
|
-
transaction.add(
|
113
|
-
TokenInstructions.closeAccount({
|
114
|
-
source: wrappedSolAccount.publicKey,
|
115
|
-
destination: payer.publicKey,
|
116
|
-
owner: payer.publicKey,
|
117
|
-
})
|
118
|
-
)
|
116
|
+
transaction.add(createCloseAccountInstruction(wrappedSolAccount.publicKey, payer.publicKey, payer.publicKey))
|
119
117
|
}
|
120
|
-
|
121
|
-
await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
|
118
|
+
const result = await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
|
122
119
|
return newVaultPublicKey
|
123
120
|
}
|
124
121
|
|
@@ -137,7 +134,8 @@ export async function buildCreateVaultTransaction(
|
|
137
134
|
const { blockhash, lastValidBlockHeight } = await program.provider.connection.getLatestBlockhash()
|
138
135
|
const transaction = new Transaction({
|
139
136
|
feePayer: payerPublicKey,
|
140
|
-
|
137
|
+
blockhash: blockhash,
|
138
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
141
139
|
})
|
142
140
|
const signers = [history]
|
143
141
|
const wrappedSolAccount = Keypair.generate()
|
@@ -152,7 +150,7 @@ export async function buildCreateVaultTransaction(
|
|
152
150
|
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
153
151
|
console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo)
|
154
152
|
|
155
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
153
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === NATIVE_MINT.toString()
|
156
154
|
|
157
155
|
const payerTokenAccount = await findAssociatedTokenAddress(
|
158
156
|
program.programId,
|
@@ -187,11 +185,7 @@ export async function buildCreateVaultTransaction(
|
|
187
185
|
programId: TOKEN_PROGRAM_ID,
|
188
186
|
space: 165,
|
189
187
|
}),
|
190
|
-
|
191
|
-
account: wrappedSolAccount.publicKey,
|
192
|
-
mint: TokenInstructions.WRAPPED_SOL_MINT,
|
193
|
-
owner: payerPublicKey,
|
194
|
-
})
|
188
|
+
createInitializeAccountInstruction(wrappedSolAccount.publicKey, NATIVE_MINT, payerPublicKey)
|
195
189
|
)
|
196
190
|
signers.push(wrappedSolAccount)
|
197
191
|
}
|
@@ -214,14 +208,9 @@ export async function buildCreateVaultTransaction(
|
|
214
208
|
overrideTime
|
215
209
|
)
|
216
210
|
)
|
211
|
+
|
217
212
|
if (isWrappedSol) {
|
218
|
-
transaction.add(
|
219
|
-
TokenInstructions.closeAccount({
|
220
|
-
source: wrappedSolAccount.publicKey,
|
221
|
-
destination: payerPublicKey,
|
222
|
-
owner: payerPublicKey,
|
223
|
-
})
|
224
|
-
)
|
213
|
+
transaction.add(createCloseAccountInstruction(wrappedSolAccount.publicKey, payerPublicKey, payerPublicKey))
|
225
214
|
transaction.partialSign(wrappedSolAccount)
|
226
215
|
}
|
227
216
|
|
@@ -253,20 +242,20 @@ export async function createVaultInstruction(
|
|
253
242
|
.createVault(
|
254
243
|
salt,
|
255
244
|
new BN(depositAmount),
|
256
|
-
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override
|
245
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override time
|
257
246
|
)
|
258
247
|
.accounts({
|
259
248
|
vaultSystemState: vaultSystemStatePublicKey,
|
260
249
|
vaultTypeAccount: vaultTypeAccount,
|
261
250
|
vault: vaultPublicKey,
|
262
251
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
263
|
-
feePool: feePool,
|
264
|
-
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
252
|
+
// feePool: feePool,
|
253
|
+
// feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
265
254
|
history: historyPublicKey,
|
266
255
|
payer: payerPublicKey,
|
267
256
|
payerTokenAccount: payerTokenAccountPublicKey,
|
268
257
|
collateralMint: collateralMint,
|
269
|
-
ushMint: ushMintPublickey,
|
258
|
+
// ushMint: ushMintPublickey,
|
270
259
|
systemProgram: SystemProgram.programId,
|
271
260
|
tokenProgram: TOKEN_PROGRAM_ID,
|
272
261
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -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,
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
getLiquidationPoolStatePublicKey,
|
11
11
|
getLiquidationPoolUshAccountPublicKey, getReferralAccountPublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
|
12
12
|
getVaultSystemStatePublicKey
|
13
|
-
} from '../
|
13
|
+
} from '../HedgeConstants'
|
14
14
|
import { Vault } from '../idl/vault'
|
15
15
|
import { parseAnchorErrors } from '../utils/Errors'
|
16
16
|
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,
|
@@ -6,7 +6,7 @@ import {
|
|
6
6
|
SystemProgram, Transaction,
|
7
7
|
TransactionInstruction
|
8
8
|
} from '@solana/web3.js'
|
9
|
-
import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../
|
9
|
+
import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../HedgeConstants'
|
10
10
|
import { Vault } from '../idl/vault'
|
11
11
|
import { parseAnchorErrors } from '../utils/Errors'
|
12
12
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -1,7 +1,12 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
|
+
import {
|
3
|
+
NATIVE_MINT,
|
4
|
+
TOKEN_PROGRAM_ID,
|
5
|
+
getOrCreateAssociatedTokenAccount,
|
6
|
+
createInitializeAccountInstruction,
|
7
|
+
createCloseAccountInstruction
|
8
|
+
} from '@solana/spl-token'
|
9
|
+
|
5
10
|
import {
|
6
11
|
Keypair,
|
7
12
|
PublicKey, Signer,
|
@@ -12,7 +17,7 @@ import {
|
|
12
17
|
import {
|
13
18
|
findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
|
14
19
|
getVaultSystemStatePublicKey
|
15
|
-
} from '../
|
20
|
+
} from '../HedgeConstants'
|
16
21
|
import { Vault } from '../idl/vault'
|
17
22
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
18
23
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -80,7 +85,7 @@ export async function depositVault(
|
|
80
85
|
false
|
81
86
|
)
|
82
87
|
|
83
|
-
if (vaultTypeAccountInfo.collateralMint.toString() ===
|
88
|
+
if (vaultTypeAccountInfo.collateralMint.toString() === NATIVE_MINT.toString()) {
|
84
89
|
transaction.add(
|
85
90
|
SystemProgram.createAccount({
|
86
91
|
fromPubkey: payer.publicKey,
|
@@ -89,11 +94,11 @@ export async function depositVault(
|
|
89
94
|
programId: TOKEN_PROGRAM_ID,
|
90
95
|
space: 165,
|
91
96
|
}),
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
+
createInitializeAccountInstruction(
|
98
|
+
wrappedSolAccount.publicKey,
|
99
|
+
NATIVE_MINT,
|
100
|
+
payer.publicKey
|
101
|
+
)
|
97
102
|
)
|
98
103
|
signers.push(wrappedSolAccount)
|
99
104
|
}
|
@@ -102,7 +107,7 @@ export async function depositVault(
|
|
102
107
|
program,
|
103
108
|
vaultSystemStatePublicKey,
|
104
109
|
payer.publicKey,
|
105
|
-
vaultTypeAccountInfo.collateralMint.toString() ===
|
110
|
+
vaultTypeAccountInfo.collateralMint.toString() === NATIVE_MINT.toString()
|
106
111
|
? wrappedSolAccount.publicKey
|
107
112
|
: payerTokenAccount,
|
108
113
|
vaultPublicKey,
|
@@ -121,13 +126,14 @@ export async function depositVault(
|
|
121
126
|
overrideTime
|
122
127
|
)
|
123
128
|
)
|
124
|
-
if (vaultTypeAccountInfo.collateralMint.toString() ===
|
129
|
+
if (vaultTypeAccountInfo.collateralMint.toString() === NATIVE_MINT.toString()) {
|
125
130
|
transaction.add(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
+
createCloseAccountInstruction(
|
132
|
+
wrappedSolAccount.publicKey,
|
133
|
+
payer.publicKey,
|
134
|
+
payer.publicKey,
|
135
|
+
[]
|
136
|
+
)
|
131
137
|
)
|
132
138
|
}
|
133
139
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Program, Provider } from '@
|
1
|
+
import { Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
Keypair,
|
@@ -15,18 +15,33 @@ import {
|
|
15
15
|
getLiquidationPoolUshAccountPublicKey,
|
16
16
|
getUshMintPublicKey,
|
17
17
|
getVaultSystemStatePublicKey
|
18
|
-
} from '../
|
18
|
+
} from '../HedgeConstants'
|
19
19
|
import { Vault } from '../idl/vault'
|
20
20
|
import { parseAnchorErrors } from '../utils/Errors'
|
21
21
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
22
22
|
|
23
23
|
export async function initHedgeFoundation(program: Program<Vault>, provider: Provider, payer: Signer): Promise<PublicKey> {
|
24
|
+
console.log('Initializing Hedge Foundation...')
|
24
25
|
const poolEra = Keypair.generate()
|
25
|
-
|
26
|
+
console.log('Generated poolEra:', poolEra.publicKey.toBase58())
|
27
|
+
|
28
|
+
const transaction = new Transaction()
|
29
|
+
transaction.feePayer = payer.publicKey
|
30
|
+
|
31
|
+
transaction.add(
|
26
32
|
await initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey)
|
27
33
|
)
|
34
|
+
console.log('Created transaction with initHedgeFoundationInstruction')
|
35
|
+
console.log('Payer public key:', payer.publicKey.toBase58())
|
28
36
|
|
29
|
-
|
37
|
+
console.log('Sending transaction...')
|
38
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, [payer, poolEra])
|
39
|
+
.catch(err => {
|
40
|
+
console.error('Failed to initialize Hedge Foundation:', err)
|
41
|
+
throw parseAnchorErrors(err)
|
42
|
+
})
|
43
|
+
|
44
|
+
console.log('Successfully initialized Hedge Foundation')
|
30
45
|
return payer.publicKey
|
31
46
|
}
|
32
47
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Program, Provider } from '@
|
1
|
+
import { Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
Keypair,
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
import {
|
12
12
|
findAssociatedTokenAddress,
|
13
13
|
getHedgeMintPublicKey, getVaultSystemStatePublicKey
|
14
|
-
} from '../
|
14
|
+
} from '../HedgeConstants'
|
15
15
|
import { parseAnchorErrors } from '../utils/Errors'
|
16
16
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
17
17
|
|
@@ -1,23 +1,20 @@
|
|
1
|
-
import { BN, Program, Provider } from '@
|
1
|
+
import { BN, Program, Provider } from '@coral-xyz/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, 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
|
SYSVAR_RENT_PUBKEY,
|
10
8
|
Transaction,
|
11
|
-
TransactionInstruction
|
9
|
+
TransactionInstruction
|
12
10
|
} from '@solana/web3.js'
|
13
11
|
import {
|
14
12
|
getHedgeMintPublicKey,
|
15
13
|
getLiquidationPoolStatePublicKey,
|
16
14
|
getLiquidationPoolUshAccountPublicKey,
|
17
|
-
getPoolPublicKeyForMint,
|
18
|
-
|
19
|
-
|
20
|
-
} from '../Constants'
|
15
|
+
getPoolPublicKeyForMint, getUshMintPublicKey,
|
16
|
+
getVaultSystemStatePublicKey
|
17
|
+
} from '../HedgeConstants'
|
21
18
|
import { Vault } from '../idl/vault'
|
22
19
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
23
20
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
@@ -40,11 +37,6 @@ export async function liquidateVault(
|
|
40
37
|
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
|
41
38
|
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
42
39
|
|
43
|
-
const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
|
44
|
-
units: 300000,
|
45
|
-
additionalFee: 0,
|
46
|
-
})
|
47
|
-
|
48
40
|
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
49
41
|
provider.connection,
|
50
42
|
payer,
|
@@ -104,32 +96,30 @@ export async function liquidateVault(
|
|
104
96
|
const newEra = Keypair.generate()
|
105
97
|
const transaction = new Transaction()
|
106
98
|
|
107
|
-
transaction
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
vaultAccount.vaultType,
|
130
|
-
overrideTime
|
131
|
-
)
|
99
|
+
transaction.add(
|
100
|
+
await liquidateVaultInstruction(
|
101
|
+
program,
|
102
|
+
payer.publicKey,
|
103
|
+
payerAssociatedTokenAccount.address,
|
104
|
+
vaultPublicKey,
|
105
|
+
vaultAssociatedTokenAccount.address,
|
106
|
+
liquidationPoolStatePublicKey,
|
107
|
+
poolStateInfo.currentEra,
|
108
|
+
poolAssociatedTokenAccount.address,
|
109
|
+
history.publicKey,
|
110
|
+
newEra.publicKey,
|
111
|
+
hedgeStakingPoolPublicKey,
|
112
|
+
feePoolAssociatedTokenAccount.address,
|
113
|
+
hedgeStakingPoolAssociatedUshTokenAccount.address,
|
114
|
+
collateralMint,
|
115
|
+
vaultTypeAssociatedTokenAccount.address,
|
116
|
+
oldSmallerPublicKey,
|
117
|
+
newSmallerPublicKey,
|
118
|
+
newLargerPublicKey,
|
119
|
+
vaultAccount.vaultType,
|
120
|
+
overrideTime
|
132
121
|
)
|
122
|
+
)
|
133
123
|
|
134
124
|
await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history, newEra])
|
135
125
|
return vaultPublicKey
|