hedge-web3 0.1.13 → 0.1.16
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/{lib/types/src → declarations}/Constants.d.ts +8 -8
- package/{lib/types/src → declarations}/HedgeDecimal.d.ts +2 -3
- package/{lib/types/src → declarations}/StakingPools.d.ts +0 -1
- package/{lib/types/src → declarations}/Vaults.d.ts +0 -1
- package/{lib/types/src → declarations}/idl/idl.d.ts +0 -1
- package/declarations/idl/vault.d.ts +2283 -0
- package/{lib/types/src → declarations}/index.d.ts +6 -1
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +4 -0
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/createStakingPool.d.ts +0 -1
- package/declarations/instructions/createVault.d.ts +4 -0
- package/declarations/instructions/depositLiquidationPool.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/depositStakingPool.d.ts +0 -1
- package/declarations/instructions/depositVault.d.ts +4 -0
- package/declarations/instructions/initHedgeFoundation.d.ts +4 -0
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +4 -0
- package/declarations/instructions/liquidateVault.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/loanVault.d.ts +2 -3
- package/declarations/instructions/redeemVault.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/refreshOraclePrice.d.ts +2 -3
- package/{lib/types/src → declarations}/instructions/repayVault.d.ts +2 -3
- package/declarations/instructions/setHalted.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/withdrawStakingPool.d.ts +0 -1
- package/declarations/instructions/withdrawVault.d.ts +4 -0
- package/{lib/types/src → declarations}/state/LiquidationPoolEra.d.ts +1 -2
- package/{lib/types/src → declarations}/state/LiquidationPoolState.d.ts +0 -1
- package/{lib/types/src → declarations}/state/LiquidationPosition.d.ts +8 -10
- package/{lib/types/src → declarations}/state/StakingPool.d.ts +0 -1
- package/{lib/types/src → declarations}/state/StakingPoolPosition.d.ts +0 -1
- package/{lib/types/src → declarations}/state/VaultAccount.d.ts +0 -1
- package/{lib/types/src → declarations}/state/VaultHistoryEvent.d.ts +0 -1
- package/{lib/types/src → declarations}/utils/Errors.d.ts +0 -1
- package/lib/Constants.js +86 -0
- package/lib/HedgeDecimal.js +24 -0
- package/lib/StakingPools.js +15 -0
- package/lib/Vaults.js +20 -0
- package/lib/idl/idl.js +1475 -0
- package/lib/idl/vault.js +2285 -0
- package/lib/index.js +37 -2156
- package/lib/instructions/claimLiquidationPoolPosition.js +53 -0
- package/lib/instructions/closeLiquidationPoolPosition.js +60 -0
- package/lib/instructions/createStakingPool.js +52 -0
- package/lib/instructions/createVault.js +92 -0
- package/lib/instructions/depositLiquidationPool.js +55 -0
- package/lib/instructions/depositStakingPool.js +52 -0
- package/lib/instructions/depositVault.js +87 -0
- package/lib/instructions/initHedgeFoundation.js +55 -0
- package/lib/instructions/initHedgeFoundationTokens.js +48 -0
- package/lib/instructions/liquidateVault.js +80 -0
- package/lib/instructions/loanVault.js +61 -0
- package/lib/instructions/redeemVault.js +65 -0
- package/lib/instructions/refreshOraclePrice.js +65 -0
- package/lib/instructions/repayVault.js +62 -0
- package/lib/instructions/setHalted.js +37 -0
- package/lib/instructions/withdrawStakingPool.js +64 -0
- package/lib/instructions/withdrawVault.js +62 -0
- package/lib/state/LiquidationPoolEra.js +19 -0
- package/lib/state/LiquidationPoolState.js +12 -0
- package/lib/state/LiquidationPosition.js +39 -0
- package/lib/state/StakingPool.js +22 -0
- package/lib/state/StakingPoolPosition.js +28 -0
- package/lib/state/VaultAccount.js +52 -0
- package/lib/state/VaultHistoryEvent.js +45 -0
- package/lib/utils/Errors.js +14 -0
- package/package.json +14 -8
- package/src/Constants.ts +24 -19
- package/src/HedgeDecimal.ts +3 -3
- package/src/idl/idl.ts +13 -13
- package/src/idl/vault.ts +4565 -0
- package/src/index.ts +6 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +76 -0
- package/src/instructions/closeLiquidationPoolPosition.ts +82 -0
- package/src/instructions/createStakingPool.ts +4 -4
- package/src/instructions/createVault.ts +98 -27
- package/src/instructions/depositLiquidationPool.ts +67 -0
- package/src/instructions/depositStakingPool.ts +5 -3
- package/src/instructions/depositVault.ts +95 -27
- package/src/instructions/initHedgeFoundation.ts +64 -0
- package/src/instructions/initHedgeFoundationTokens.ts +55 -0
- package/src/instructions/liquidateVault.ts +87 -35
- package/src/instructions/loanVault.ts +30 -20
- package/src/instructions/redeemVault.ts +37 -24
- package/src/instructions/refreshOraclePrice.ts +6 -3
- package/src/instructions/repayVault.ts +30 -20
- package/src/instructions/setHalted.ts +48 -0
- package/src/instructions/withdrawStakingPool.ts +6 -6
- package/src/instructions/withdrawVault.ts +50 -17
- package/src/state/LiquidationPoolEra.ts +2 -8
- package/src/state/LiquidationPosition.ts +38 -39
- package/tsconfig.json +3 -2
- package/.github/workflows/npm-publish.yml +0 -34
- package/README.md +0 -44
- package/jsconfig.json +0 -12
- package/lib/index.js.map +0 -1
- package/lib/types/src/Constants.d.ts.map +0 -1
- package/lib/types/src/HedgeDecimal.d.ts.map +0 -1
- package/lib/types/src/StakingPools.d.ts.map +0 -1
- package/lib/types/src/Vaults.d.ts.map +0 -1
- package/lib/types/src/idl/idl.d.ts.map +0 -1
- package/lib/types/src/index.d.ts.map +0 -1
- package/lib/types/src/instructions/createStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/createVault.d.ts +0 -5
- package/lib/types/src/instructions/createVault.d.ts.map +0 -1
- package/lib/types/src/instructions/depositStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/depositVault.d.ts +0 -5
- package/lib/types/src/instructions/depositVault.d.ts.map +0 -1
- package/lib/types/src/instructions/liquidateVault.d.ts +0 -5
- package/lib/types/src/instructions/liquidateVault.d.ts.map +0 -1
- package/lib/types/src/instructions/loanVault.d.ts.map +0 -1
- package/lib/types/src/instructions/redeemVault.d.ts +0 -5
- package/lib/types/src/instructions/redeemVault.d.ts.map +0 -1
- package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +0 -1
- package/lib/types/src/instructions/repayVault.d.ts.map +0 -1
- package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/withdrawVault.d.ts +0 -5
- package/lib/types/src/instructions/withdrawVault.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPoolEra.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPoolState.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPosition.d.ts.map +0 -1
- package/lib/types/src/state/StakingPool.d.ts.map +0 -1
- package/lib/types/src/state/StakingPoolPosition.d.ts.map +0 -1
- package/lib/types/src/state/VaultAccount.d.ts.map +0 -1
- package/lib/types/src/state/VaultHistoryEvent.d.ts.map +0 -1
- package/lib/types/src/utils/Errors.d.ts.map +0 -1
- package/lib/types/tsconfig.base.tsbuildinfo +0 -1
- package/rollup.config.js +0 -40
@@ -0,0 +1,64 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
|
+
|
7
|
+
export async function initHedgeFoundation(
|
8
|
+
program: Program,
|
9
|
+
provider: Provider,
|
10
|
+
payer: Signer
|
11
|
+
): Promise<PublicKey> {
|
12
|
+
|
13
|
+
const poolEra = Keypair.generate()
|
14
|
+
const transaction = new Transaction().add(
|
15
|
+
await initHedgeFoundationInstruction(
|
16
|
+
program,
|
17
|
+
poolEra.publicKey,
|
18
|
+
payer.publicKey,
|
19
|
+
)
|
20
|
+
)
|
21
|
+
|
22
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolEra], provider.opts).catch(parseAnchorErrors)
|
23
|
+
return payer.publicKey
|
24
|
+
}
|
25
|
+
|
26
|
+
export async function initHedgeFoundationInstruction (
|
27
|
+
program: Program,
|
28
|
+
poolEraPublicKey: PublicKey,
|
29
|
+
payerPublicKey: PublicKey,
|
30
|
+
): Promise<TransactionInstruction> {
|
31
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
32
|
+
const poolStatePublickey = await getLiquidationPoolStatePublicKey()
|
33
|
+
const poolUsdhTokenAccount = await getLiquidationPoolUsdhAccountPublicKey()
|
34
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
35
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
36
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(
|
37
|
+
payerPublicKey,
|
38
|
+
hedgeMintPublickey
|
39
|
+
)
|
40
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
41
|
+
vaultSystemStatePublicKey,
|
42
|
+
hedgeMintPublickey
|
43
|
+
)
|
44
|
+
|
45
|
+
return program.instruction.initHedgeFoundation(
|
46
|
+
{
|
47
|
+
accounts: {
|
48
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
49
|
+
poolState: poolStatePublickey,
|
50
|
+
poolEra: poolEraPublicKey,
|
51
|
+
poolUsdhAccount: poolUsdhTokenAccount,
|
52
|
+
founder: payerPublicKey,
|
53
|
+
usdhMint: usdhMintPublickey,
|
54
|
+
hedgeMint: hedgeMintPublickey,
|
55
|
+
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
56
|
+
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
57
|
+
rent: SYSVAR_RENT_PUBKEY,
|
58
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
59
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
60
|
+
systemProgram: SystemProgram.programId
|
61
|
+
},
|
62
|
+
signers: []
|
63
|
+
})
|
64
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
|
+
|
7
|
+
export async function initHedgeFoundationTokens(
|
8
|
+
program: Program,
|
9
|
+
provider: Provider,
|
10
|
+
payer: Signer
|
11
|
+
): Promise<PublicKey> {
|
12
|
+
|
13
|
+
const poolEra = Keypair.generate()
|
14
|
+
const transaction = new Transaction().add(
|
15
|
+
await initHedgeFoundationTokensInstruction(
|
16
|
+
program,
|
17
|
+
payer.publicKey,
|
18
|
+
)
|
19
|
+
)
|
20
|
+
|
21
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors)
|
22
|
+
return payer.publicKey
|
23
|
+
}
|
24
|
+
|
25
|
+
export async function initHedgeFoundationTokensInstruction (
|
26
|
+
program: Program,
|
27
|
+
payerPublicKey: PublicKey,
|
28
|
+
): Promise<TransactionInstruction> {
|
29
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
30
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
31
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(
|
32
|
+
payerPublicKey,
|
33
|
+
hedgeMintPublickey
|
34
|
+
)
|
35
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
36
|
+
vaultSystemStatePublicKey,
|
37
|
+
hedgeMintPublickey
|
38
|
+
)
|
39
|
+
|
40
|
+
return program.instruction.initHedgeFoundationTokens(
|
41
|
+
{
|
42
|
+
accounts: {
|
43
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
44
|
+
founder: payerPublicKey,
|
45
|
+
hedgeMint: hedgeMintPublickey,
|
46
|
+
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
47
|
+
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
48
|
+
rent: SYSVAR_RENT_PUBKEY,
|
49
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
50
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
51
|
+
systemProgram: SystemProgram.programId
|
52
|
+
},
|
53
|
+
signers: []
|
54
|
+
})
|
55
|
+
}
|
@@ -1,23 +1,57 @@
|
|
1
|
-
import { Program, Provider } from '@project-serum/anchor'
|
2
|
-
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getPoolPublicKeyForMint,
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
3
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
5
5
|
|
6
6
|
export async function liquidateVault (
|
7
7
|
program: Program,
|
8
8
|
provider: Provider,
|
9
9
|
payer: Signer,
|
10
|
-
vaultPublicKey: PublicKey
|
10
|
+
vaultPublicKey: PublicKey,
|
11
|
+
overrideTime?: number
|
11
12
|
): Promise<PublicKey> {
|
13
|
+
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
14
|
+
|
15
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
16
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
17
|
+
const collateralMint = vaultTypeAccountInfo.collateralMint
|
18
|
+
|
19
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
20
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
21
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
22
|
+
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
|
23
|
+
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
24
|
+
|
25
|
+
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, payer.publicKey, true)
|
26
|
+
const feePoolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true)
|
27
|
+
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, vaultPublicKey, true)
|
28
|
+
const poolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true)
|
29
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true)
|
30
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, hedgeStakingPoolPublicKey, true)
|
31
|
+
|
12
32
|
const history = Keypair.generate()
|
13
33
|
const newEra = Keypair.generate()
|
14
|
-
const transaction = new Transaction()
|
34
|
+
const transaction = new Transaction()
|
35
|
+
|
36
|
+
transaction.add(
|
15
37
|
await liquidateVaultInstruction(
|
16
38
|
program,
|
17
39
|
payer.publicKey,
|
40
|
+
payerAssociatedTokenAccount.address,
|
18
41
|
vaultPublicKey,
|
42
|
+
vaultAssociatedTokenAccount.address,
|
43
|
+
liquidationPoolStatePublicKey,
|
44
|
+
poolStateInfo.currentEra,
|
45
|
+
poolAssociatedTokenAccount.address,
|
19
46
|
history.publicKey,
|
20
|
-
newEra.publicKey
|
47
|
+
newEra.publicKey,
|
48
|
+
hedgeStakingPoolPublicKey,
|
49
|
+
feePoolAssociatedTokenAccount.address,
|
50
|
+
hedgeStakingPoolAssociatedUsdhTokenAccount.address,
|
51
|
+
collateralMint,
|
52
|
+
vaultTypeAssociatedTokenAccount.address,
|
53
|
+
vaultAccount.collateralType,
|
54
|
+
overrideTime
|
21
55
|
)
|
22
56
|
)
|
23
57
|
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra], provider.opts)
|
@@ -27,37 +61,55 @@ export async function liquidateVault (
|
|
27
61
|
export async function liquidateVaultInstruction (
|
28
62
|
program: Program,
|
29
63
|
payerPublicKey: PublicKey,
|
64
|
+
payerAssociatedTokenAccount: PublicKey,
|
30
65
|
vaultPublickey: PublicKey,
|
66
|
+
vaultAssociatedTokenAccount: PublicKey,
|
67
|
+
poolState: PublicKey,
|
68
|
+
poolEra: PublicKey,
|
69
|
+
poolAssociatedTokenAccount: PublicKey,
|
31
70
|
historyPublicKey: PublicKey,
|
32
|
-
newEraPublicKey: PublicKey
|
71
|
+
newEraPublicKey: PublicKey,
|
72
|
+
feePool: PublicKey,
|
73
|
+
feePoolAssociatedTokenAccount: PublicKey,
|
74
|
+
hedgeStakingPoolAssociatedUsdhTokenAccount: PublicKey,
|
75
|
+
collateralMint: PublicKey,
|
76
|
+
vaultTypeAssociatedTokenAccount: PublicKey,
|
77
|
+
collateralType: string,
|
78
|
+
overrideTime?: number
|
33
79
|
): Promise<TransactionInstruction> {
|
34
|
-
const
|
35
|
-
const
|
36
|
-
const
|
37
|
-
const
|
38
|
-
const [liquidationPoolStatePublicKey] = await getLiquidationPoolStatePublicKey()
|
39
|
-
const [liquidationPoolUsdhAccountPublickey] = await getLiquidationPoolUsdhAccountPublicKey()
|
40
|
-
const collateralStateAccount = await getSolCollateralStateAccountPublicKey()
|
41
|
-
|
42
|
-
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
80
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
81
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
82
|
+
const liquidationPoolUsdhAccountPublickey = await getLiquidationPoolUsdhAccountPublicKey()
|
83
|
+
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
43
84
|
|
85
|
+
const payload = {
|
86
|
+
accounts: {
|
87
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
88
|
+
vaultTypeAccount: vaultTypeAccount,
|
89
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
90
|
+
collateralMint: collateralMint,
|
91
|
+
poolEra: poolEra,
|
92
|
+
vaultAccount: vaultPublickey,
|
93
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
94
|
+
poolState: poolState,
|
95
|
+
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
96
|
+
usdhMint: usdhMintPublickey,
|
97
|
+
history: historyPublicKey,
|
98
|
+
payer: payerPublicKey,
|
99
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
100
|
+
feePool: feePool,
|
101
|
+
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
102
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
103
|
+
liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
|
104
|
+
newEra: newEraPublicKey,
|
105
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
106
|
+
systemProgram: SystemProgram.programId,
|
107
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
108
|
+
rent: SYSVAR_RENT_PUBKEY
|
109
|
+
},
|
110
|
+
signers: []
|
111
|
+
}
|
44
112
|
return program.instruction.liquidateVault(
|
45
|
-
|
46
|
-
|
47
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
48
|
-
collateralStateAccount: collateralStateAccount,
|
49
|
-
poolEra: poolStateInfo.currentEra,
|
50
|
-
vaultAccount: vaultPublickey,
|
51
|
-
poolState: liquidationPoolStatePublicKey,
|
52
|
-
usdhMint: usdhMintPublickey,
|
53
|
-
history: historyPublicKey,
|
54
|
-
payer: payerPublicKey,
|
55
|
-
splTokenProgramInfo: TOKEN_PROGRAM_ID,
|
56
|
-
systemProgram: SystemProgram.programId,
|
57
|
-
feePool: hedgeStakingPoolPublicKey,
|
58
|
-
liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
|
59
|
-
newEra: newEraPublicKey
|
60
|
-
},
|
61
|
-
signers: []
|
62
|
-
})
|
113
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
|
114
|
+
payload)
|
63
115
|
}
|
@@ -1,25 +1,25 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint,
|
4
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
5
5
|
|
6
6
|
export async function loanVault (
|
7
7
|
program: Program,
|
8
8
|
provider: Provider,
|
9
9
|
payer: Signer,
|
10
10
|
vaultPublicKey: PublicKey,
|
11
|
-
loanAmount: number
|
11
|
+
loanAmount: number,
|
12
|
+
overrideTime?: number
|
12
13
|
): Promise<PublicKey> {
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
usdhMintPublickey,
|
17
|
-
TOKEN_PROGRAM_ID,
|
18
|
-
payer
|
19
|
-
)
|
14
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
15
|
+
|
16
|
+
const payerUsdhAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
|
20
17
|
|
21
|
-
|
22
|
-
const
|
18
|
+
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
19
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
20
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
21
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true)
|
22
|
+
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true)
|
23
23
|
|
24
24
|
const history = Keypair.generate()
|
25
25
|
const transaction = new Transaction().add(
|
@@ -28,8 +28,12 @@ export async function loanVault (
|
|
28
28
|
payer.publicKey,
|
29
29
|
payerUsdhAccount.address,
|
30
30
|
vaultPublicKey,
|
31
|
+
vaultAssociatedTokenAccount.address,
|
31
32
|
history.publicKey,
|
32
|
-
|
33
|
+
vaultTypeAccountPublicKey,
|
34
|
+
vaultTypeAssociatedTokenAccount.address,
|
35
|
+
loanAmount,
|
36
|
+
overrideTime
|
33
37
|
)
|
34
38
|
)
|
35
39
|
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
|
@@ -41,33 +45,39 @@ export async function loanVaultInstruction (
|
|
41
45
|
payerPublicKey: PublicKey,
|
42
46
|
ownerUsdhAccount: PublicKey,
|
43
47
|
vaultPublickey: PublicKey,
|
48
|
+
vaultAssociatedTokenAccount: PublicKey,
|
44
49
|
historyPublicKey: PublicKey,
|
45
|
-
|
50
|
+
vaultTypeAccount: PublicKey,
|
51
|
+
vaultTypeAssociatedTokenAccount: PublicKey,
|
52
|
+
loanAmount: number,
|
53
|
+
overrideTime?: number
|
46
54
|
): Promise<TransactionInstruction> {
|
47
|
-
const
|
48
|
-
const
|
49
|
-
const
|
55
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
56
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
57
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
50
58
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
51
59
|
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(
|
52
60
|
hedgeStakingPoolPublicKey,
|
53
61
|
usdhMintPublickey
|
54
62
|
)
|
55
|
-
const collateralStateAccount = await getSolCollateralStateAccountPublicKey()
|
56
63
|
|
57
64
|
return program.instruction.loanVault(
|
58
65
|
new BN(loanAmount),
|
66
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
|
59
67
|
{
|
60
68
|
accounts: {
|
61
69
|
vaultSystemState: vaultSystemStatePublicKey,
|
62
|
-
|
70
|
+
vaultTypeAccount: vaultTypeAccount,
|
71
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
63
72
|
vaultAccount: vaultPublickey,
|
73
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
64
74
|
history: historyPublicKey,
|
65
75
|
feePool: hedgeStakingPoolPublicKey,
|
66
76
|
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
67
77
|
usdhMint: usdhMintPublickey,
|
68
78
|
vaultOwner: payerPublicKey,
|
69
79
|
ownerUsdhAccount: ownerUsdhAccount,
|
70
|
-
|
80
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
71
81
|
systemProgram: SystemProgram.programId
|
72
82
|
},
|
73
83
|
signers: []
|
@@ -1,26 +1,30 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
// import { TokenInstructions } from '@project-serum/serum'
|
3
4
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint,
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
5
6
|
|
6
7
|
export async function redeemVault (
|
7
8
|
program: Program,
|
8
9
|
provider: Provider,
|
9
10
|
payer: Signer,
|
10
11
|
vaultPublicKey: PublicKey,
|
11
|
-
|
12
|
+
redeemAmount: number,
|
12
13
|
transactionOverrideTime?: number
|
13
14
|
): Promise<PublicKey> {
|
14
|
-
const
|
15
|
-
const USDH = new Token(
|
16
|
-
provider.connection,
|
17
|
-
usdhMintPublickey,
|
18
|
-
TOKEN_PROGRAM_ID,
|
19
|
-
payer
|
20
|
-
)
|
15
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
21
16
|
|
22
17
|
// Prep the user to get USDH back out at some point
|
23
|
-
const payerUsdhAccount = await
|
18
|
+
const payerUsdhAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
|
19
|
+
|
20
|
+
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
21
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
22
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
23
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true)
|
24
|
+
|
25
|
+
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true)
|
26
|
+
|
27
|
+
const payerTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey)
|
24
28
|
|
25
29
|
const history = Keypair.generate()
|
26
30
|
const transaction = new Transaction().add(
|
@@ -28,9 +32,13 @@ export async function redeemVault (
|
|
28
32
|
program,
|
29
33
|
payer.publicKey,
|
30
34
|
payerUsdhAccount.address,
|
35
|
+
payerTokenAccount.address,
|
31
36
|
vaultPublicKey,
|
37
|
+
vaultAssociatedTokenAccount.address,
|
32
38
|
history.publicKey,
|
33
|
-
|
39
|
+
vaultTypeAccountPublicKey,
|
40
|
+
vaultTypeAssociatedTokenAccount.address,
|
41
|
+
redeemAmount,
|
34
42
|
transactionOverrideTime
|
35
43
|
)
|
36
44
|
)
|
@@ -41,37 +49,42 @@ export async function redeemVault (
|
|
41
49
|
export async function redeemVaultInstruction (
|
42
50
|
program: Program,
|
43
51
|
payerPublicKey: PublicKey,
|
44
|
-
|
52
|
+
payerUsdhAccount: PublicKey,
|
53
|
+
destinationTokenAccount: PublicKey,
|
45
54
|
vaultPublickey: PublicKey,
|
55
|
+
vaultAssociatedTokenAccount: PublicKey,
|
46
56
|
historyPublicKey: PublicKey,
|
47
|
-
|
57
|
+
vaultTypeAccount: PublicKey,
|
58
|
+
vaultTypeAssociatedTokenAccount: PublicKey,
|
59
|
+
redeemAmount: number,
|
48
60
|
transactionOverrideTime?: number
|
49
61
|
): Promise<TransactionInstruction> {
|
50
|
-
const
|
51
|
-
const
|
52
|
-
const
|
62
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
63
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
64
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
53
65
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
54
66
|
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(
|
55
67
|
hedgeStakingPoolPublicKey,
|
56
68
|
usdhMintPublickey
|
57
69
|
)
|
58
|
-
const collateralStateAccount = await getSolCollateralStateAccountPublicKey()
|
59
|
-
|
60
70
|
return program.instruction.redeemVault(
|
61
|
-
new BN(
|
71
|
+
new BN(redeemAmount),
|
62
72
|
new BN(transactionOverrideTime ?? (Date.now() / 1000)), // override start time
|
63
73
|
{
|
64
74
|
accounts: {
|
65
75
|
vaultSystemState: vaultSystemStatePublicKey,
|
66
|
-
|
67
|
-
|
76
|
+
vaultTypeAccount: vaultTypeAccount,
|
77
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
78
|
+
vault: vaultPublickey,
|
79
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
68
80
|
history: historyPublicKey,
|
69
81
|
feePool: hedgeStakingPoolPublicKey,
|
70
82
|
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
71
83
|
usdhMint: usdhMintPublickey,
|
72
84
|
payer: payerPublicKey,
|
73
|
-
payerUsdhAccount:
|
74
|
-
|
85
|
+
payerUsdhAccount: payerUsdhAccount,
|
86
|
+
destinationTokenAccount: destinationTokenAccount,
|
87
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
75
88
|
systemProgram: SystemProgram.programId
|
76
89
|
},
|
77
90
|
signers: []
|
@@ -6,6 +6,7 @@ export async function refreshOraclePrice (
|
|
6
6
|
program: Program,
|
7
7
|
provider: Provider,
|
8
8
|
payer: Signer,
|
9
|
+
collateralType: string,
|
9
10
|
network: Cluster,
|
10
11
|
overridePrice?: number,
|
11
12
|
overrideTime?: number
|
@@ -13,6 +14,7 @@ export async function refreshOraclePrice (
|
|
13
14
|
const transaction = new Transaction().add(
|
14
15
|
await refreshOraclePriceInstruction(
|
15
16
|
program,
|
17
|
+
collateralType,
|
16
18
|
network,
|
17
19
|
overridePrice,
|
18
20
|
overrideTime
|
@@ -23,13 +25,14 @@ export async function refreshOraclePrice (
|
|
23
25
|
|
24
26
|
export async function refreshOraclePriceInstruction (
|
25
27
|
program: Program,
|
28
|
+
collateralType: string,
|
26
29
|
network: Cluster,
|
27
30
|
overridePrice?: number,
|
28
31
|
overrideTime?: number
|
29
32
|
): Promise<TransactionInstruction> {
|
30
33
|
const enc = new TextEncoder()
|
31
|
-
const [oracleInfoAccount] = await PublicKey.findProgramAddress([enc.encode(
|
32
|
-
const [
|
34
|
+
const [oracleInfoAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY)
|
35
|
+
const [vaultTypeAccount] = await PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY)
|
33
36
|
|
34
37
|
return program.instruction.refreshOraclePrice(
|
35
38
|
new BN(overridePrice ?? LAMPORTS_PER_SOL * 150), // override usd/sol price
|
@@ -37,7 +40,7 @@ export async function refreshOraclePriceInstruction (
|
|
37
40
|
{
|
38
41
|
accounts: {
|
39
42
|
oracleInfoAccount: oracleInfoAccount,
|
40
|
-
|
43
|
+
vaultTypeAccount: vaultTypeAccount,
|
41
44
|
oracleChainlink: chainlinkAccunts[network],
|
42
45
|
oraclePyth: pythAccounts[network],
|
43
46
|
oracleSwitchboard: switchboardAccounts[network],
|
@@ -1,25 +1,26 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint,
|
4
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
5
5
|
|
6
6
|
export async function repayVault (
|
7
7
|
program: Program,
|
8
8
|
provider: Provider,
|
9
9
|
payer: Signer,
|
10
10
|
vaultPublicKey: PublicKey,
|
11
|
-
repayAmount: number
|
11
|
+
repayAmount: number,
|
12
|
+
overrideTime?: number
|
12
13
|
): Promise<PublicKey> {
|
13
|
-
const
|
14
|
-
const USDH = new Token(
|
15
|
-
provider.connection,
|
16
|
-
usdhMintPublickey,
|
17
|
-
TOKEN_PROGRAM_ID,
|
18
|
-
payer
|
19
|
-
)
|
14
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
20
15
|
|
21
16
|
// Prep the user to get USDH back out at some point
|
22
|
-
const payerUsdhAccount = await
|
17
|
+
const payerUsdhAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
|
18
|
+
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
19
|
+
|
20
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
21
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
22
|
+
const vaultTypeAssociatedTokenAccount = await findAssociatedTokenAddress(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint)
|
23
|
+
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, vaultTypeAccount.collateralMint)
|
23
24
|
|
24
25
|
const history = Keypair.generate()
|
25
26
|
const transaction = new Transaction().add(
|
@@ -28,8 +29,12 @@ export async function repayVault (
|
|
28
29
|
payer.publicKey,
|
29
30
|
payerUsdhAccount.address,
|
30
31
|
vaultPublicKey,
|
32
|
+
vaultAssociatedTokenAccount,
|
31
33
|
history.publicKey,
|
32
|
-
|
34
|
+
vaultTypeAccountPublicKey,
|
35
|
+
vaultTypeAssociatedTokenAccount,
|
36
|
+
repayAmount,
|
37
|
+
overrideTime
|
33
38
|
)
|
34
39
|
)
|
35
40
|
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts)
|
@@ -41,34 +46,39 @@ export async function repayVaultInstruction (
|
|
41
46
|
payerPublicKey: PublicKey,
|
42
47
|
ownerUsdhAccount: PublicKey,
|
43
48
|
vaultPublickey: PublicKey,
|
49
|
+
vaultAssociatedTokenAccount: PublicKey,
|
44
50
|
historyPublicKey: PublicKey,
|
45
|
-
|
51
|
+
vaultTypeAccount: PublicKey,
|
52
|
+
vaultTypeAssociatedTokenAccount: PublicKey,
|
53
|
+
repayAmount: number,
|
54
|
+
overrideTime?: number
|
46
55
|
): Promise<TransactionInstruction> {
|
47
|
-
const
|
48
|
-
const
|
49
|
-
const
|
56
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
57
|
+
const usdhMintPublickey = await getUsdhMintPublicKey()
|
58
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
50
59
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
51
60
|
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(
|
52
61
|
hedgeStakingPoolPublicKey,
|
53
62
|
usdhMintPublickey
|
54
63
|
)
|
55
64
|
|
56
|
-
const collateralStateAccount = await getSolCollateralStateAccountPublicKey()
|
57
|
-
|
58
65
|
return program.instruction.repayVault(
|
59
66
|
new BN(repayAmount),
|
67
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
|
60
68
|
{
|
61
69
|
accounts: {
|
62
70
|
vaultSystemState: vaultSystemStatePublicKey,
|
63
|
-
|
71
|
+
vaultTypeAccount: vaultTypeAccount,
|
72
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
64
73
|
vaultAccount: vaultPublickey,
|
74
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
65
75
|
history: historyPublicKey,
|
66
76
|
feePool: hedgeStakingPoolPublicKey,
|
67
77
|
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
68
78
|
usdhMint: usdhMintPublickey,
|
69
79
|
vaultOwner: payerPublicKey,
|
70
80
|
ownerUsdhAccount: ownerUsdhAccount,
|
71
|
-
|
81
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
72
82
|
systemProgram: SystemProgram.programId
|
73
83
|
},
|
74
84
|
signers: []
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { TokenInstructions } from '@project-serum/serum'
|
3
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
4
|
+
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
5
|
+
import { findAssociatedTokenAddress, findVaultAddress, getVaultTypeAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey, getPoolPublicKeyForMint, getHedgeMintPublicKey } from '../Constants'
|
6
|
+
|
7
|
+
import { v4 as uuidv4 } from 'uuid'
|
8
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
9
|
+
|
10
|
+
export async function setHalted (
|
11
|
+
program: Program,
|
12
|
+
provider: Provider,
|
13
|
+
payer: Signer,
|
14
|
+
halted: boolean
|
15
|
+
): Promise<PublicKey> {
|
16
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
17
|
+
|
18
|
+
|
19
|
+
const transaction = new Transaction().add(
|
20
|
+
await setHaltedInstruction(
|
21
|
+
program,
|
22
|
+
vaultSystemStatePublicKey,
|
23
|
+
payer.publicKey,
|
24
|
+
halted
|
25
|
+
)
|
26
|
+
)
|
27
|
+
|
28
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider?.opts).catch(parseAnchorErrors)
|
29
|
+
return vaultSystemStatePublicKey
|
30
|
+
}
|
31
|
+
|
32
|
+
export async function setHaltedInstruction (
|
33
|
+
program: Program,
|
34
|
+
vaultSystemStatePublicKey: PublicKey,
|
35
|
+
payerPublicKey: PublicKey,
|
36
|
+
halted: boolean
|
37
|
+
): Promise<TransactionInstruction> {
|
38
|
+
const ix = program.instruction.setHalted(
|
39
|
+
halted,
|
40
|
+
{
|
41
|
+
accounts: {
|
42
|
+
payer: payerPublicKey,
|
43
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
44
|
+
},
|
45
|
+
signers: []
|
46
|
+
})
|
47
|
+
return ix
|
48
|
+
}
|