hedge-web3 0.1.29 → 0.1.33
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/idl/vault.d.ts +99 -99
- package/declarations/index.d.ts +1 -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 +4 -4
- package/declarations/instructions/repayVault.d.ts +3 -2
- package/declarations/instructions/setHalted.d.ts +3 -2
- package/declarations/instructions/setVaultTypeStatus.d.ts +3 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
- package/declarations/instructions/withdrawVault.d.ts +3 -2
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -1
- package/lib/idl/vault.js +99 -99
- package/lib/index.js +1 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +22 -24
- package/lib/instructions/claimStakingPoolPosition.js +19 -19
- package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
- package/lib/instructions/createStakingPool.js +17 -18
- package/lib/instructions/createVault.js +28 -32
- package/lib/instructions/depositLiquidationPool.js +17 -18
- package/lib/instructions/depositStakingPool.js +16 -18
- package/lib/instructions/depositVault.js +25 -27
- package/lib/instructions/initHedgeFoundation.js +17 -19
- package/lib/instructions/initHedgeFoundationTokens.js +15 -15
- package/lib/instructions/liquidateVault.js +32 -33
- package/lib/instructions/loanVault.js +23 -23
- package/lib/instructions/redeemVault.js +24 -24
- package/lib/instructions/refreshOraclePrice.js +19 -19
- package/lib/instructions/repayVault.js +23 -23
- package/lib/instructions/setHalted.js +8 -9
- package/lib/instructions/setVaultTypeStatus.js +9 -10
- package/lib/instructions/withdrawStakingPool.js +22 -24
- package/lib/instructions/withdrawVault.js +23 -23
- 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 +2 -5
- package/lib/utils/getLinkedListAccounts.js +24 -16
- package/package.json +2 -2
- package/src/idl/vault.ts +198 -198
- package/src/index.ts +1 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +42 -34
- package/src/instructions/claimStakingPoolPosition.ts +45 -25
- package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
- package/src/instructions/createStakingPool.ts +37 -35
- package/src/instructions/createVault.ts +80 -125
- package/src/instructions/depositLiquidationPool.ts +45 -26
- package/src/instructions/depositStakingPool.ts +32 -24
- package/src/instructions/depositVault.ts +57 -86
- package/src/instructions/initHedgeFoundation.ts +42 -43
- package/src/instructions/initHedgeFoundationTokens.ts +38 -39
- package/src/instructions/liquidateVault.ts +42 -65
- package/src/instructions/loanVault.ts +51 -69
- package/src/instructions/redeemVault.ts +83 -47
- package/src/instructions/refreshOraclePrice.ts +42 -33
- package/src/instructions/repayVault.ts +45 -65
- package/src/instructions/setHalted.ts +32 -24
- package/src/instructions/setVaultTypeStatus.ts +32 -24
- package/src/instructions/withdrawStakingPool.ts +44 -30
- package/src/instructions/withdrawVault.ts +58 -82
- 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 +9 -28
- package/src/state/VaultHistoryEvent.ts +1 -2
- package/src/utils/getLinkedListAccounts.ts +31 -30
- package/tsconfig.json +1 -1
@@ -1,18 +1,38 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
Keypair,
|
5
|
+
PublicKey,
|
6
|
+
sendAndConfirmTransaction,
|
7
|
+
Signer,
|
8
|
+
SystemProgram,
|
9
|
+
SYSVAR_RENT_PUBKEY,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
4
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
14
|
+
import {
|
15
|
+
getLiquidationPoolStatePublicKey,
|
16
|
+
getLiquidationPoolUshAccountPublicKey,
|
17
|
+
getUshMintPublicKey,
|
18
|
+
getVaultSystemStatePublicKey,
|
19
|
+
} from '../Constants'
|
20
|
+
import { Vault } from 'idl/vault'
|
6
21
|
|
7
|
-
export async function depositLiquidationPool
|
8
|
-
program: Program
|
22
|
+
export async function depositLiquidationPool(
|
23
|
+
program: Program<Vault>,
|
9
24
|
provider: Provider,
|
10
25
|
payer: Signer,
|
11
26
|
depositAmount: number,
|
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
|
|
17
37
|
const poolPosition = Keypair.generate()
|
18
38
|
const transaction = new Transaction().add(
|
@@ -25,12 +45,12 @@ export async function depositLiquidationPool (
|
|
25
45
|
overrideStartTime
|
26
46
|
)
|
27
47
|
)
|
28
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]
|
48
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
|
29
49
|
return poolPosition.publicKey
|
30
50
|
}
|
31
51
|
|
32
|
-
export async function depositLiquidationPoolInstruction
|
33
|
-
program: Program
|
52
|
+
export async function depositLiquidationPoolInstruction(
|
53
|
+
program: Program<Vault>,
|
34
54
|
payerPublicKey: PublicKey,
|
35
55
|
payerUshAccount: PublicKey,
|
36
56
|
poolPositionPublicKey: PublicKey,
|
@@ -45,23 +65,22 @@ export async function depositLiquidationPoolInstruction (
|
|
45
65
|
|
46
66
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
47
67
|
|
48
|
-
return program.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
},
|
65
|
-
signers: []
|
68
|
+
return await program.methods
|
69
|
+
.depositLiquidationPool(
|
70
|
+
new BN(depositAmount),
|
71
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
|
72
|
+
)
|
73
|
+
.accounts({
|
74
|
+
vaultSystemState: vaultSystemState,
|
75
|
+
poolState: liquidationPoolStatePublicKey,
|
76
|
+
poolUshAccount: poolUSHAccount,
|
77
|
+
poolEra: liquidationPoolState.currentEra,
|
78
|
+
poolPosition: poolPositionPublicKey,
|
79
|
+
ushMint: ushMint,
|
80
|
+
payer: payerPublicKey,
|
81
|
+
ownerUshAccount: payerUshAccount,
|
82
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
83
|
+
systemProgram: SystemProgram.programId,
|
66
84
|
})
|
85
|
+
.instruction()
|
67
86
|
}
|
@@ -1,11 +1,21 @@
|
|
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
|
+
Keypair,
|
5
|
+
PublicKey,
|
6
|
+
sendAndConfirmTransaction,
|
7
|
+
Signer,
|
8
|
+
SystemProgram,
|
9
|
+
SYSVAR_RENT_PUBKEY,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
4
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
14
|
import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
|
15
|
+
import { Vault } from 'idl/vault'
|
6
16
|
|
7
|
-
export async function depositStakingPool
|
8
|
-
program: Program
|
17
|
+
export async function depositStakingPool(
|
18
|
+
program: Program<Vault>,
|
9
19
|
provider: Provider,
|
10
20
|
payer: Signer,
|
11
21
|
mintPublicKey: PublicKey,
|
@@ -23,12 +33,12 @@ export async function depositStakingPool (
|
|
23
33
|
overrideStartTime
|
24
34
|
)
|
25
35
|
)
|
26
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]
|
36
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
|
27
37
|
return poolPosition.publicKey
|
28
38
|
}
|
29
39
|
|
30
|
-
export async function depositStakingPoolInstruction
|
31
|
-
program: Program
|
40
|
+
export async function depositStakingPoolInstruction(
|
41
|
+
program: Program<Vault>,
|
32
42
|
payerPublicKey: PublicKey,
|
33
43
|
poolPositionPublicKey: PublicKey,
|
34
44
|
stakedTokenMintPublicKey: PublicKey,
|
@@ -40,23 +50,21 @@ export async function depositStakingPoolInstruction (
|
|
40
50
|
const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
|
41
51
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
42
52
|
|
43
|
-
return program.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
systemProgram: SystemProgram.programId
|
59
|
-
},
|
60
|
-
signers: []
|
53
|
+
return await program.methods
|
54
|
+
.depositStakingPool(
|
55
|
+
new BN(depositAmount),
|
56
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
|
57
|
+
)
|
58
|
+
.accounts({
|
59
|
+
payer: payerPublicKey,
|
60
|
+
vaultSystemState: vaultSystemState,
|
61
|
+
pool: poolPublickey,
|
62
|
+
poolPosition: poolPositionPublicKey,
|
63
|
+
stakedTokenMintInfo: stakedTokenMintPublicKey,
|
64
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
65
|
+
payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
|
66
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
67
|
+
systemProgram: SystemProgram.programId,
|
61
68
|
})
|
69
|
+
.instruction()
|
62
70
|
}
|
@@ -1,9 +1,6 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { TokenInstructions } from '@project-serum/serum'
|
3
|
-
import {
|
4
|
-
getOrCreateAssociatedTokenAccount,
|
5
|
-
TOKEN_PROGRAM_ID,
|
6
|
-
} from '@solana/spl-token'
|
3
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
7
4
|
import {
|
8
5
|
Keypair,
|
9
6
|
PublicKey,
|
@@ -22,9 +19,10 @@ import {
|
|
22
19
|
getPoolPublicKeyForMint,
|
23
20
|
getHedgeMintPublicKey,
|
24
21
|
} from '../Constants'
|
22
|
+
import { Vault } from 'idl/vault'
|
25
23
|
|
26
24
|
export async function depositVault(
|
27
|
-
program: Program
|
25
|
+
program: Program<Vault>,
|
28
26
|
provider: Provider,
|
29
27
|
payer: Signer,
|
30
28
|
vaultPublicKey: PublicKey,
|
@@ -34,67 +32,49 @@ export async function depositVault(
|
|
34
32
|
const ushMintPublickey = await getUshMintPublicKey()
|
35
33
|
|
36
34
|
// Prep the user to get USH back out at some point
|
37
|
-
await getOrCreateAssociatedTokenAccount(
|
38
|
-
provider.connection,
|
39
|
-
payer,
|
40
|
-
ushMintPublickey,
|
41
|
-
payer.publicKey
|
42
|
-
)
|
35
|
+
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
43
36
|
|
44
37
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
45
|
-
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
38
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
39
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
40
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
41
|
+
provider.connection,
|
42
|
+
payer,
|
43
|
+
vaultTypeAccountInfo.collateralMint,
|
44
|
+
vaultTypeAccountPublicKey,
|
45
|
+
true
|
50
46
|
)
|
51
|
-
const vaultTypeAssociatedTokenAccount =
|
52
|
-
await getOrCreateAssociatedTokenAccount(
|
53
|
-
provider.connection,
|
54
|
-
payer,
|
55
|
-
vaultTypeAccountInfo.collateralMint,
|
56
|
-
vaultTypeAccountPublicKey,
|
57
|
-
true
|
58
|
-
)
|
59
47
|
|
60
|
-
const payerTokenAccount = await findAssociatedTokenAddress(
|
61
|
-
|
48
|
+
const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
|
49
|
+
const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(
|
50
|
+
vaultPublicKey,
|
62
51
|
vaultTypeAccountInfo.collateralMint
|
63
52
|
)
|
64
|
-
const vaultAssociatedCollateralAccountPublicKey =
|
65
|
-
await findAssociatedTokenAddress(
|
66
|
-
vaultPublicKey,
|
67
|
-
vaultTypeAccountInfo.collateralMint
|
68
|
-
)
|
69
53
|
|
70
54
|
const history = Keypair.generate()
|
71
55
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
72
56
|
|
73
57
|
const wrappedSolAccount = Keypair.generate()
|
74
58
|
|
75
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
76
|
-
|
59
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
|
60
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
61
|
+
hedgeStakingPoolPublicKey,
|
62
|
+
ushMintPublickey
|
77
63
|
)
|
78
|
-
const hedgeStakingPoolAssociatedUshTokenAccount =
|
79
|
-
await findAssociatedTokenAddress(
|
80
|
-
hedgeStakingPoolPublicKey,
|
81
|
-
ushMintPublickey
|
82
|
-
)
|
83
64
|
|
84
65
|
const transaction = new Transaction()
|
85
66
|
const signers = [payer, history]
|
86
67
|
|
87
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
)
|
68
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
69
|
+
program,
|
70
|
+
provider,
|
71
|
+
vaultTypeAccountPublicKey,
|
72
|
+
vaultPublicKey,
|
73
|
+
depositAmount,
|
74
|
+
0,
|
75
|
+
false,
|
76
|
+
false
|
77
|
+
)
|
98
78
|
|
99
79
|
if (vaultAccount.collateralType === 'SOL') {
|
100
80
|
transaction.add(
|
@@ -118,9 +98,7 @@ export async function depositVault(
|
|
118
98
|
program,
|
119
99
|
vaultSystemStatePublicKey,
|
120
100
|
payer.publicKey,
|
121
|
-
vaultAccount.collateralType === 'SOL'
|
122
|
-
? wrappedSolAccount.publicKey
|
123
|
-
: payerTokenAccount,
|
101
|
+
vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount,
|
124
102
|
vaultPublicKey,
|
125
103
|
vaultAssociatedCollateralAccountPublicKey,
|
126
104
|
history.publicKey,
|
@@ -147,17 +125,12 @@ export async function depositVault(
|
|
147
125
|
)
|
148
126
|
}
|
149
127
|
|
150
|
-
await sendAndConfirmTransaction(
|
151
|
-
provider.connection,
|
152
|
-
transaction,
|
153
|
-
signers,
|
154
|
-
provider.opts
|
155
|
-
)
|
128
|
+
await sendAndConfirmTransaction(provider.connection, transaction, signers)
|
156
129
|
return vaultPublicKey
|
157
130
|
}
|
158
131
|
|
159
132
|
export async function depositVaultInstruction(
|
160
|
-
program: Program
|
133
|
+
program: Program<Vault>,
|
161
134
|
vaultSystemStatePublicKey: PublicKey,
|
162
135
|
vaultOwner: PublicKey,
|
163
136
|
vaultOwnerTokenAccount: PublicKey,
|
@@ -176,31 +149,29 @@ export async function depositVaultInstruction(
|
|
176
149
|
depositAmount: number,
|
177
150
|
overrideTime?: number
|
178
151
|
): Promise<TransactionInstruction> {
|
179
|
-
return program.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
}
|
205
|
-
)
|
152
|
+
return await program.methods
|
153
|
+
.depositVault(
|
154
|
+
new BN(depositAmount),
|
155
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
|
156
|
+
)
|
157
|
+
.accounts({
|
158
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
159
|
+
vaultTypeAccount: vaultTypeAccountPublicKey,
|
160
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
161
|
+
collateralTokenMint: collateralMint,
|
162
|
+
vault: vaultPublicKey,
|
163
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
164
|
+
feePool: hedgeStakingPoolPublicKey,
|
165
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
166
|
+
history: historyPublicKey,
|
167
|
+
vaultOwner: vaultOwner,
|
168
|
+
vaultOwnerTokenAccount: vaultOwnerTokenAccount,
|
169
|
+
ushMint: ushMintPublickey,
|
170
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
171
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
172
|
+
newLargerVaultInfo: newLargerPublicKey,
|
173
|
+
systemProgram: SystemProgram.programId,
|
174
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
175
|
+
})
|
176
|
+
.instruction()
|
206
177
|
}
|
@@ -1,64 +1,63 @@
|
|
1
1
|
import { 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
|
+
Keypair,
|
5
|
+
PublicKey,
|
6
|
+
sendAndConfirmTransaction,
|
7
|
+
Signer,
|
8
|
+
SystemProgram,
|
9
|
+
SYSVAR_RENT_PUBKEY,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
4
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
import {
|
15
|
+
findAssociatedTokenAddress,
|
16
|
+
getHedgeMintPublicKey,
|
17
|
+
getLiquidationPoolStatePublicKey,
|
18
|
+
getLiquidationPoolUshAccountPublicKey,
|
19
|
+
getUshMintPublicKey,
|
20
|
+
getVaultSystemStatePublicKey,
|
21
|
+
} from '../Constants'
|
22
|
+
import { Vault } from 'idl/vault'
|
12
23
|
|
24
|
+
export async function initHedgeFoundation(program: Program<Vault>, provider: Provider, payer: Signer): Promise<PublicKey> {
|
13
25
|
const poolEra = Keypair.generate()
|
14
26
|
const transaction = new Transaction().add(
|
15
|
-
await initHedgeFoundationInstruction(
|
16
|
-
program,
|
17
|
-
poolEra.publicKey,
|
18
|
-
payer.publicKey,
|
19
|
-
)
|
27
|
+
await initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey)
|
20
28
|
)
|
21
29
|
|
22
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolEra]
|
30
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolEra]).catch(parseAnchorErrors)
|
23
31
|
return payer.publicKey
|
24
32
|
}
|
25
33
|
|
26
|
-
export async function initHedgeFoundationInstruction
|
27
|
-
program: Program
|
34
|
+
export async function initHedgeFoundationInstruction(
|
35
|
+
program: Program<Vault>,
|
28
36
|
poolEraPublicKey: PublicKey,
|
29
|
-
payerPublicKey: PublicKey
|
37
|
+
payerPublicKey: PublicKey
|
30
38
|
): Promise<TransactionInstruction> {
|
31
39
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
32
40
|
const poolStatePublickey = await getLiquidationPoolStatePublicKey()
|
33
41
|
const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey()
|
34
42
|
const ushMintPublickey = await getUshMintPublicKey()
|
35
43
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
36
|
-
const founderHedgeTokenAccount = await findAssociatedTokenAddress(
|
37
|
-
|
38
|
-
hedgeMintPublickey
|
39
|
-
)
|
40
|
-
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
41
|
-
vaultSystemStatePublicKey,
|
42
|
-
hedgeMintPublickey
|
43
|
-
)
|
44
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
|
45
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
|
44
46
|
|
45
|
-
return program.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
60
|
-
systemProgram: SystemProgram.programId
|
61
|
-
},
|
62
|
-
signers: []
|
47
|
+
return await program.methods
|
48
|
+
.initHedgeFoundation()
|
49
|
+
.accounts({
|
50
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
51
|
+
poolState: poolStatePublickey,
|
52
|
+
poolEra: poolEraPublicKey,
|
53
|
+
poolUshAccount: poolUshTokenAccount,
|
54
|
+
founder: payerPublicKey,
|
55
|
+
ushMint: ushMintPublickey,
|
56
|
+
hedgeMint: hedgeMintPublickey,
|
57
|
+
rent: SYSVAR_RENT_PUBKEY,
|
58
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
59
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
60
|
+
systemProgram: SystemProgram.programId,
|
63
61
|
})
|
62
|
+
.instruction()
|
64
63
|
}
|
@@ -1,55 +1,54 @@
|
|
1
1
|
import { 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
|
+
Keypair,
|
5
|
+
PublicKey,
|
6
|
+
sendAndConfirmTransaction,
|
7
|
+
Signer,
|
8
|
+
SystemProgram,
|
9
|
+
SYSVAR_RENT_PUBKEY,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
4
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
import {
|
15
|
+
findAssociatedTokenAddress,
|
16
|
+
getHedgeMintPublicKey,
|
17
|
+
getLiquidationPoolStatePublicKey,
|
18
|
+
getLiquidationPoolUshAccountPublicKey,
|
19
|
+
getUshMintPublicKey,
|
20
|
+
getVaultSystemStatePublicKey,
|
21
|
+
} from '../Constants'
|
12
22
|
|
23
|
+
export async function initHedgeFoundationTokens(program: Program, provider: Provider, payer: Signer): Promise<PublicKey> {
|
13
24
|
const poolEra = Keypair.generate()
|
14
|
-
const transaction = new Transaction().add(
|
15
|
-
await initHedgeFoundationTokensInstruction(
|
16
|
-
program,
|
17
|
-
payer.publicKey,
|
18
|
-
)
|
19
|
-
)
|
25
|
+
const transaction = new Transaction().add(await initHedgeFoundationTokensInstruction(program, payer.publicKey))
|
20
26
|
|
21
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer]
|
27
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
22
28
|
return payer.publicKey
|
23
29
|
}
|
24
30
|
|
25
|
-
export async function initHedgeFoundationTokensInstruction
|
31
|
+
export async function initHedgeFoundationTokensInstruction(
|
26
32
|
program: Program,
|
27
|
-
payerPublicKey: PublicKey
|
33
|
+
payerPublicKey: PublicKey
|
28
34
|
): Promise<TransactionInstruction> {
|
29
35
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
30
36
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
31
|
-
const founderHedgeTokenAccount = await findAssociatedTokenAddress(
|
32
|
-
|
33
|
-
hedgeMintPublickey
|
34
|
-
)
|
35
|
-
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
36
|
-
vaultSystemStatePublicKey,
|
37
|
-
hedgeMintPublickey
|
38
|
-
)
|
37
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
|
38
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
|
39
39
|
|
40
|
-
return program.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
},
|
53
|
-
signers: []
|
40
|
+
return await program.methods
|
41
|
+
.initHedgeFoundationTokens()
|
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,
|
54
52
|
})
|
53
|
+
.instruction()
|
55
54
|
}
|