hedge-web3 0.1.27 → 0.1.31
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 +1 -1
- package/declarations/idl/vault.d.ts +277 -126
- package/declarations/index.d.ts +3 -0
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/claimStakingPoolPosition.d.ts +3 -2
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/createStakingPool.d.ts +3 -2
- package/declarations/instructions/createVault.d.ts +6 -5
- package/declarations/instructions/depositLiquidationPool.d.ts +3 -2
- package/declarations/instructions/depositStakingPool.d.ts +3 -2
- package/declarations/instructions/depositVault.d.ts +3 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +3 -2
- package/declarations/instructions/liquidateVault.d.ts +3 -2
- package/declarations/instructions/loanVault.d.ts +3 -2
- package/declarations/instructions/redeemVault.d.ts +3 -2
- package/declarations/instructions/refreshOraclePrice.d.ts +3 -2
- package/declarations/instructions/repayVault.d.ts +3 -2
- package/declarations/instructions/setHalted.d.ts +3 -2
- package/declarations/instructions/setVaultTypeStatus.d.ts +5 -0
- package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
- package/declarations/instructions/withdrawVault.d.ts +3 -2
- package/declarations/state/VaultAccount.d.ts +8 -0
- package/declarations/utils/getLinkedListAccounts.d.ts +5 -0
- package/lib/Constants.js +1 -1
- package/lib/idl/vault.js +277 -126
- package/lib/index.js +3 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +19 -22
- package/lib/instructions/claimStakingPoolPosition.js +19 -19
- package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
- package/lib/instructions/createStakingPool.js +18 -19
- package/lib/instructions/createVault.js +28 -31
- package/lib/instructions/depositLiquidationPool.js +17 -18
- package/lib/instructions/depositStakingPool.js +16 -18
- package/lib/instructions/depositVault.js +31 -26
- package/lib/instructions/initHedgeFoundation.js +17 -19
- package/lib/instructions/initHedgeFoundationTokens.js +15 -15
- package/lib/instructions/liquidateVault.js +36 -32
- package/lib/instructions/loanVault.js +27 -22
- package/lib/instructions/redeemVault.js +28 -23
- package/lib/instructions/refreshOraclePrice.js +17 -17
- package/lib/instructions/repayVault.js +27 -22
- package/lib/instructions/setHalted.js +8 -9
- package/lib/instructions/setVaultTypeStatus.js +37 -0
- package/lib/instructions/withdrawStakingPool.js +22 -24
- package/lib/instructions/withdrawVault.js +30 -25
- package/lib/state/LiquidationPoolEra.js +3 -1
- package/lib/state/LiquidationPosition.js +0 -7
- package/lib/state/StakingPool.js +3 -4
- package/lib/state/VaultAccount.js +51 -1
- package/lib/utils/getLinkedListAccounts.js +139 -0
- package/package.json +4 -2
- package/src/Constants.ts +1 -1
- package/src/idl/vault.ts +554 -252
- package/src/index.ts +4 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +39 -29
- package/src/instructions/claimStakingPoolPosition.ts +45 -25
- package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
- package/src/instructions/createStakingPool.ts +38 -37
- package/src/instructions/createVault.ts +81 -125
- package/src/instructions/depositLiquidationPool.ts +45 -26
- package/src/instructions/depositStakingPool.ts +32 -24
- package/src/instructions/depositVault.ts +77 -31
- package/src/instructions/initHedgeFoundation.ts +42 -43
- package/src/instructions/initHedgeFoundationTokens.ts +38 -39
- package/src/instructions/liquidateVault.ts +96 -22
- package/src/instructions/loanVault.ts +84 -30
- package/src/instructions/redeemVault.ts +91 -32
- package/src/instructions/refreshOraclePrice.ts +41 -32
- package/src/instructions/repayVault.ts +74 -29
- package/src/instructions/setHalted.ts +32 -24
- package/src/instructions/setVaultTypeStatus.ts +58 -0
- package/src/instructions/withdrawStakingPool.ts +44 -30
- package/src/instructions/withdrawVault.ts +87 -33
- package/src/state/LiquidationPoolEra.ts +4 -3
- package/src/state/LiquidationPosition.ts +0 -27
- package/src/state/StakingPool.ts +4 -7
- package/src/state/StakingPoolPosition.ts +2 -3
- package/src/state/VaultAccount.ts +65 -8
- package/src/state/VaultHistoryEvent.ts +1 -2
- package/src/utils/getLinkedListAccounts.ts +157 -0
package/src/index.ts
CHANGED
@@ -17,6 +17,7 @@ export * from './instructions/refreshOraclePrice'
|
|
17
17
|
export * from './instructions/initHedgeFoundation'
|
18
18
|
export * from './instructions/initHedgeFoundationTokens'
|
19
19
|
export * from './instructions/setHalted'
|
20
|
+
export * from './instructions/setVaultTypeStatus'
|
20
21
|
|
21
22
|
export * from './HedgeDecimal'
|
22
23
|
export * from './Constants'
|
@@ -28,3 +29,6 @@ export * from './state/StakingPoolPosition'
|
|
28
29
|
export * from './state/LiquidationPoolEra'
|
29
30
|
export * from './state/LiquidationPoolState'
|
30
31
|
export * from './state/LiquidationPosition'
|
32
|
+
|
33
|
+
export * from './utils/getLinkedListAccounts'
|
34
|
+
export * from './idl/vault'
|
@@ -1,11 +1,25 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
PublicKey,
|
5
|
+
sendAndConfirmTransaction,
|
6
|
+
Signer,
|
7
|
+
SystemProgram,
|
8
|
+
SYSVAR_RENT_PUBKEY,
|
9
|
+
Transaction,
|
10
|
+
TransactionInstruction,
|
11
|
+
} from '@solana/web3.js'
|
4
12
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
13
|
+
import {
|
14
|
+
findAssociatedTokenAddress,
|
15
|
+
getVaultTypeAccountPublicKey,
|
16
|
+
getLiquidationPoolStatePublicKey,
|
17
|
+
getVaultSystemStatePublicKey,
|
18
|
+
} from '../Constants'
|
19
|
+
import { Vault } from 'idl/vault'
|
6
20
|
|
7
|
-
export async function claimLiquidationPoolPosition
|
8
|
-
program: Program
|
21
|
+
export async function claimLiquidationPoolPosition(
|
22
|
+
program: Program<Vault>,
|
9
23
|
provider: Provider,
|
10
24
|
poolPosition: PublicKey,
|
11
25
|
payer: Signer,
|
@@ -14,14 +28,14 @@ export async function claimLiquidationPoolPosition (
|
|
14
28
|
): Promise<PublicKey> {
|
15
29
|
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
|
16
30
|
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
17
|
-
const
|
31
|
+
const collateralMintPublicKey = vaultTypeAccountInfo.collateralMint
|
18
32
|
|
19
33
|
const poolStatePublicKey = await getLiquidationPoolStatePublicKey()
|
20
|
-
const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey,
|
34
|
+
const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey, collateralMintPublicKey)
|
21
35
|
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
22
36
|
provider.connection,
|
23
37
|
payer,
|
24
|
-
|
38
|
+
collateralMintPublicKey,
|
25
39
|
payer.publicKey
|
26
40
|
)
|
27
41
|
|
@@ -31,19 +45,19 @@ export async function claimLiquidationPoolPosition (
|
|
31
45
|
poolStatePublicKey,
|
32
46
|
poolAssociatedTokenAccount,
|
33
47
|
vaultTypeAccountPublicKey,
|
34
|
-
|
48
|
+
collateralMintPublicKey,
|
35
49
|
poolPosition,
|
36
50
|
payer.publicKey,
|
37
51
|
payerAssociatedTokenAccount.address,
|
38
52
|
overrideStartTime
|
39
53
|
)
|
40
54
|
)
|
41
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer]
|
55
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
42
56
|
return payerAssociatedTokenAccount.address
|
43
57
|
}
|
44
58
|
|
45
|
-
export async function claimLiquidationPoolPositionInstruction
|
46
|
-
program: Program
|
59
|
+
export async function claimLiquidationPoolPositionInstruction(
|
60
|
+
program: Program<Vault>,
|
47
61
|
poolState: PublicKey,
|
48
62
|
poolAssociatedTokenAccount: PublicKey,
|
49
63
|
vaultTypeAccount: PublicKey,
|
@@ -55,22 +69,18 @@ export async function claimLiquidationPoolPositionInstruction (
|
|
55
69
|
): Promise<TransactionInstruction> {
|
56
70
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
57
71
|
|
58
|
-
return program.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
rent: SYSVAR_RENT_PUBKEY
|
73
|
-
},
|
74
|
-
signers: []
|
75
|
-
})
|
72
|
+
return await program.methods.claimLiquidationPoolPosition().accounts({
|
73
|
+
vaultSystemState: vaultSystemState,
|
74
|
+
poolState: poolState,
|
75
|
+
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
76
|
+
vaultTypeAccount: vaultTypeAccount,
|
77
|
+
collateralMint: collateralMint,
|
78
|
+
poolPosition: poolPosition,
|
79
|
+
payer: payer,
|
80
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
81
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
82
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
83
|
+
systemProgram: SystemProgram.programId,
|
84
|
+
rent: SYSVAR_RENT_PUBKEY,
|
85
|
+
}).instruction()
|
76
86
|
}
|
@@ -1,22 +1,43 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
PublicKey,
|
5
|
+
sendAndConfirmTransaction,
|
6
|
+
Signer,
|
7
|
+
SystemProgram,
|
8
|
+
SYSVAR_RENT_PUBKEY,
|
9
|
+
Transaction,
|
10
|
+
TransactionInstruction,
|
11
|
+
} from '@solana/web3.js'
|
4
12
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
13
|
+
import {
|
14
|
+
getHedgeMintPublicKey,
|
15
|
+
findAssociatedTokenAddress,
|
16
|
+
getVaultTypeAccountPublicKey,
|
17
|
+
getPoolPublicKeyForMint,
|
18
|
+
getVaultSystemStatePublicKey,
|
19
|
+
} from '../Constants'
|
20
|
+
import { Vault } from 'idl/vault'
|
6
21
|
|
7
22
|
export async function claimStakingPoolPosition(
|
8
|
-
program: Program
|
23
|
+
program: Program<Vault>,
|
9
24
|
provider: Provider,
|
10
25
|
poolPosition: PublicKey,
|
11
26
|
payer: Signer,
|
12
|
-
collateralType: string
|
27
|
+
collateralType: string
|
13
28
|
): Promise<PublicKey> {
|
14
29
|
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
15
30
|
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccount)
|
16
31
|
const collateralMint = vaultTypeAccountInfo.collateralMint
|
17
32
|
const stakedTokenMint = await getHedgeMintPublicKey()
|
18
33
|
const [feePool] = await getPoolPublicKeyForMint(stakedTokenMint)
|
19
|
-
const feePoolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
34
|
+
const feePoolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
35
|
+
provider.connection,
|
36
|
+
payer,
|
37
|
+
collateralMint,
|
38
|
+
feePool,
|
39
|
+
true
|
40
|
+
)
|
20
41
|
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
21
42
|
provider.connection,
|
22
43
|
payer,
|
@@ -37,12 +58,12 @@ export async function claimStakingPoolPosition(
|
|
37
58
|
payerAssociatedTokenAccount.address
|
38
59
|
)
|
39
60
|
)
|
40
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer]
|
61
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
41
62
|
return payerAssociatedTokenAccount.address
|
42
63
|
}
|
43
64
|
|
44
65
|
export async function claimStakingPoolPositionInstruction(
|
45
|
-
program: Program
|
66
|
+
program: Program<Vault>,
|
46
67
|
feePool: PublicKey,
|
47
68
|
feePoolAssociatedTokenAccount: PublicKey,
|
48
69
|
stakedTokenMint: PublicKey,
|
@@ -54,23 +75,22 @@ export async function claimStakingPoolPositionInstruction(
|
|
54
75
|
): Promise<TransactionInstruction> {
|
55
76
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
56
77
|
|
57
|
-
return program.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
},
|
74
|
-
signers: []
|
78
|
+
return await program.methods
|
79
|
+
.claimStakingPoolPosition()
|
80
|
+
.accounts({
|
81
|
+
vaultSystemState: vaultSystemState,
|
82
|
+
feePool: feePool,
|
83
|
+
stakedTokenMint: stakedTokenMint,
|
84
|
+
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
85
|
+
vaultTypeAccount: vaultTypeAccount,
|
86
|
+
collateralMint: collateralMint,
|
87
|
+
poolPosition: poolPosition,
|
88
|
+
payer: payer,
|
89
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
90
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
91
|
+
systemProgram: SystemProgram.programId,
|
92
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
93
|
+
rent: SYSVAR_RENT_PUBKEY,
|
75
94
|
})
|
95
|
+
.instruction()
|
76
96
|
}
|
@@ -1,25 +1,56 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
PublicKey,
|
5
|
+
sendAndConfirmTransaction,
|
6
|
+
Signer,
|
7
|
+
SystemProgram,
|
8
|
+
SYSVAR_RENT_PUBKEY,
|
9
|
+
Transaction,
|
10
|
+
TransactionInstruction,
|
11
|
+
} from '@solana/web3.js'
|
4
12
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
13
|
+
import {
|
14
|
+
getHedgeMintPublicKey,
|
15
|
+
getLiquidationPoolStatePublicKey,
|
16
|
+
getLiquidationPoolUshAccountPublicKey,
|
17
|
+
getUshMintPublicKey,
|
18
|
+
getVaultSystemStatePublicKey,
|
19
|
+
} from '../Constants'
|
20
|
+
import { Vault } from 'idl/vault'
|
6
21
|
|
7
|
-
export async function closeLiquidationPoolPosition
|
8
|
-
program: Program
|
22
|
+
export async function closeLiquidationPoolPosition(
|
23
|
+
program: Program<Vault>,
|
9
24
|
provider: Provider,
|
10
25
|
poolPosition: PublicKey,
|
11
26
|
payer: Signer,
|
12
27
|
overrideStartTime?: number
|
13
28
|
): Promise<PublicKey> {
|
14
29
|
const ushMintPublickey = await getUshMintPublicKey()
|
15
|
-
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
30
|
+
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
31
|
+
provider.connection,
|
32
|
+
payer,
|
33
|
+
ushMintPublickey,
|
34
|
+
payer.publicKey
|
35
|
+
)
|
16
36
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
17
37
|
const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition)
|
18
38
|
const poolEra = liquidationPositionAccount.era
|
19
39
|
|
20
40
|
const hedgeMint = await getHedgeMintPublicKey()
|
21
|
-
const payerAssociatedHedgeAccount = await getOrCreateAssociatedTokenAccount(
|
22
|
-
|
41
|
+
const payerAssociatedHedgeAccount = await getOrCreateAssociatedTokenAccount(
|
42
|
+
provider.connection,
|
43
|
+
payer,
|
44
|
+
hedgeMint,
|
45
|
+
payer.publicKey
|
46
|
+
)
|
47
|
+
const communityAssociatedHedgeTokenAccount = await getOrCreateAssociatedTokenAccount(
|
48
|
+
provider.connection,
|
49
|
+
payer,
|
50
|
+
hedgeMint,
|
51
|
+
vaultSystemStatePublicKey,
|
52
|
+
true
|
53
|
+
)
|
23
54
|
|
24
55
|
const transaction = new Transaction().add(
|
25
56
|
await closeLiquidationPoolPositionInstruction(
|
@@ -33,12 +64,12 @@ export async function closeLiquidationPoolPosition (
|
|
33
64
|
overrideStartTime
|
34
65
|
)
|
35
66
|
)
|
36
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer]
|
67
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
37
68
|
return poolPosition
|
38
69
|
}
|
39
70
|
|
40
|
-
export async function closeLiquidationPoolPositionInstruction
|
41
|
-
program: Program
|
71
|
+
export async function closeLiquidationPoolPositionInstruction(
|
72
|
+
program: Program<Vault>,
|
42
73
|
poolEra: PublicKey,
|
43
74
|
poolPosition: PublicKey,
|
44
75
|
payerPublicKey: PublicKey,
|
@@ -47,33 +78,32 @@ export async function closeLiquidationPoolPositionInstruction (
|
|
47
78
|
communityAssociatedHedgeTokenAccount: PublicKey,
|
48
79
|
overrideStartTime?: number
|
49
80
|
): Promise<TransactionInstruction> {
|
50
|
-
|
51
81
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
52
82
|
const ushMint = await getUshMintPublicKey()
|
53
83
|
const hedgeMint = await getHedgeMintPublicKey()
|
54
84
|
const poolUshAccount = await getLiquidationPoolUshAccountPublicKey()
|
55
85
|
const poolState = await getLiquidationPoolStatePublicKey()
|
56
86
|
|
57
|
-
return program.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
signers: []
|
87
|
+
return await program.methods
|
88
|
+
.closeLiquidationPoolPosition(
|
89
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
|
90
|
+
)
|
91
|
+
.accounts({
|
92
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
93
|
+
poolState: poolState,
|
94
|
+
poolEra: poolEra,
|
95
|
+
poolPosition: poolPosition,
|
96
|
+
poolUshAccount: poolUshAccount,
|
97
|
+
payer: payerPublicKey,
|
98
|
+
ownerUshAccount: payerUshAccount,
|
99
|
+
hedgeMint: hedgeMint,
|
100
|
+
ushMint: ushMint,
|
101
|
+
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
102
|
+
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
103
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
104
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
105
|
+
systemProgram: SystemProgram.programId,
|
106
|
+
rent: SYSVAR_RENT_PUBKEY,
|
78
107
|
})
|
108
|
+
.instruction()
|
79
109
|
}
|
@@ -1,11 +1,25 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
PublicKey,
|
5
|
+
sendAndConfirmTransaction,
|
6
|
+
Signer,
|
7
|
+
SystemProgram,
|
8
|
+
SYSVAR_RENT_PUBKEY,
|
9
|
+
Transaction,
|
10
|
+
TransactionInstruction,
|
11
|
+
} from '@solana/web3.js'
|
4
12
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
13
|
+
import {
|
14
|
+
findAssociatedTokenAddress,
|
15
|
+
getPoolPublicKeyForMint,
|
16
|
+
getUshMintPublicKey,
|
17
|
+
getVaultSystemStatePublicKey,
|
18
|
+
} from '../Constants'
|
19
|
+
import { Vault } from 'idl/vault'
|
6
20
|
|
7
|
-
export async function createStakingPool
|
8
|
-
program: Program
|
21
|
+
export async function createStakingPool(
|
22
|
+
program: Program<Vault>,
|
9
23
|
provider: Provider,
|
10
24
|
payer: Signer,
|
11
25
|
mintPublicKey: PublicKey,
|
@@ -13,53 +27,40 @@ export async function createStakingPool (
|
|
13
27
|
overrideStartTime?: number
|
14
28
|
): Promise<PublicKey> {
|
15
29
|
const transaction = new Transaction().add(
|
16
|
-
await createStakingPoolInstruction(
|
17
|
-
program,
|
18
|
-
payer.publicKey,
|
19
|
-
mintPublicKey,
|
20
|
-
hedgeTokensToBeMinted,
|
21
|
-
overrideStartTime
|
22
|
-
)
|
30
|
+
await createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime)
|
23
31
|
)
|
24
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer]
|
32
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
25
33
|
const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey)
|
26
34
|
return poolPublickey
|
27
35
|
}
|
28
36
|
|
29
|
-
export async function createStakingPoolInstruction
|
30
|
-
program: Program
|
37
|
+
export async function createStakingPoolInstruction(
|
38
|
+
program: Program<Vault>,
|
31
39
|
payerPublicKey: PublicKey,
|
32
40
|
mintPublicKey: PublicKey,
|
33
41
|
hedgeTokensToBeMinted: number,
|
34
42
|
overrideStartTime?: number
|
35
43
|
): Promise<TransactionInstruction> {
|
36
|
-
console.log("createStakingPoolInstruction program ID", program.programId.toString())
|
37
44
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
38
45
|
const ushMintPublickey = await getUshMintPublicKey()
|
39
|
-
const [poolPublickey, poolBump
|
46
|
+
const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
|
40
47
|
|
41
48
|
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey)
|
42
49
|
const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
58
|
-
rent: SYSVAR_RENT_PUBKEY,
|
59
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
60
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
61
|
-
systemProgram: SystemProgram.programId
|
62
|
-
},
|
63
|
-
signers: []
|
50
|
+
return await program.methods
|
51
|
+
.createStakingPool(poolBump, new BN(hedgeTokensToBeMinted), new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)))
|
52
|
+
.accounts({
|
53
|
+
signer: payerPublicKey,
|
54
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
55
|
+
pool: poolPublickey,
|
56
|
+
stakedTokenMintInfo: mintPublicKey,
|
57
|
+
ushMint: ushMintPublickey,
|
58
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
59
|
+
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
60
|
+
rent: SYSVAR_RENT_PUBKEY,
|
61
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
62
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
63
|
+
systemProgram: SystemProgram.programId,
|
64
64
|
})
|
65
|
+
.instruction()
|
65
66
|
}
|