hedge-web3 0.1.21 → 0.1.26
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 +3 -3
- package/declarations/idl/vault.d.ts +43 -43
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/claimStakingPoolPosition.d.ts +4 -0
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -1
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
- package/declarations/instructions/depositVault.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -1
- package/declarations/instructions/redeemVault.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -1
- package/declarations/state/LiquidationPosition.d.ts +2 -2
- package/declarations/state/StakingPool.d.ts +2 -2
- package/declarations/state/StakingPoolPosition.d.ts +2 -2
- package/declarations/state/VaultAccount.d.ts +3 -3
- package/declarations/state/VaultHistoryEvent.d.ts +4 -4
- package/lib/Constants.js +8 -8
- package/lib/idl/idl.js +30 -30
- package/lib/idl/vault.js +43 -43
- package/lib/index.js +1 -0
- package/lib/instructions/claimStakingPoolPosition.js +55 -0
- package/lib/instructions/closeLiquidationPoolPosition.js +10 -10
- package/lib/instructions/createStakingPool.js +5 -5
- package/lib/instructions/createVault.js +12 -12
- package/lib/instructions/depositLiquidationPool.js +10 -10
- package/lib/instructions/depositStakingPool.js +1 -1
- package/lib/instructions/depositVault.js +8 -8
- package/lib/instructions/initHedgeFoundation.js +4 -4
- package/lib/instructions/liquidateVault.js +9 -9
- package/lib/instructions/loanVault.js +9 -9
- package/lib/instructions/redeemVault.js +10 -10
- package/lib/instructions/refreshOraclePrice.js +1 -1
- package/lib/instructions/repayVault.js +10 -10
- package/lib/instructions/withdrawStakingPool.js +7 -7
- package/lib/instructions/withdrawVault.js +8 -8
- package/lib/state/LiquidationPosition.js +2 -2
- package/lib/state/StakingPool.js +2 -2
- package/lib/state/StakingPoolPosition.js +3 -3
- package/lib/state/VaultAccount.js +2 -2
- package/lib/state/VaultHistoryEvent.js +4 -4
- package/package.json +9 -9
- package/src/Constants.ts +5 -5
- package/src/idl/idl.ts +30 -30
- package/src/idl/vault.ts +86 -86
- package/src/index.ts +1 -0
- package/src/instructions/claimStakingPoolPosition.ts +76 -0
- package/src/instructions/closeLiquidationPoolPosition.ts +11 -11
- package/src/instructions/createStakingPool.ts +6 -6
- package/src/instructions/createVault.ts +19 -18
- package/src/instructions/depositLiquidationPool.ts +11 -11
- package/src/instructions/depositStakingPool.ts +1 -1
- package/src/instructions/depositVault.ts +12 -12
- package/src/instructions/initHedgeFoundation.ts +5 -5
- package/src/instructions/initHedgeFoundationTokens.ts +1 -1
- package/src/instructions/liquidateVault.ts +10 -10
- package/src/instructions/loanVault.ts +11 -11
- package/src/instructions/redeemVault.ts +12 -12
- package/src/instructions/refreshOraclePrice.ts +1 -1
- package/src/instructions/repayVault.ts +12 -12
- package/src/instructions/setHalted.ts +1 -1
- package/src/instructions/withdrawStakingPool.ts +8 -8
- package/src/instructions/withdrawVault.ts +12 -12
- package/src/state/LiquidationPosition.ts +3 -3
- package/src/state/StakingPool.ts +4 -4
- package/src/state/StakingPoolPosition.ts +4 -4
- package/src/state/VaultAccount.ts +3 -3
- package/src/state/VaultHistoryEvent.ts +8 -8
package/src/index.ts
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
export * from './instructions/createStakingPool'
|
3
3
|
export * from './instructions/depositStakingPool'
|
4
4
|
export * from './instructions/withdrawStakingPool'
|
5
|
+
export * from './instructions/claimStakingPoolPosition'
|
5
6
|
export * from './instructions/depositLiquidationPool'
|
6
7
|
export * from './instructions/closeLiquidationPoolPosition'
|
7
8
|
export * from './instructions/claimLiquidationPoolPosition'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
+
import { getHedgeMintPublicKey, findAssociatedTokenAddress, getVaultTypeAccountPublicKey, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
|
6
|
+
|
7
|
+
export async function claimStakingPoolPosition(
|
8
|
+
program: Program,
|
9
|
+
provider: Provider,
|
10
|
+
poolPosition: PublicKey,
|
11
|
+
payer: Signer,
|
12
|
+
collateralType: string,
|
13
|
+
): Promise<PublicKey> {
|
14
|
+
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
15
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccount)
|
16
|
+
const collateralMint = vaultTypeAccountInfo.collateralMint
|
17
|
+
const stakedTokenMint = await getHedgeMintPublicKey()
|
18
|
+
const [feePool] = await getPoolPublicKeyForMint(stakedTokenMint)
|
19
|
+
const feePoolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, feePool, true)
|
20
|
+
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
21
|
+
provider.connection,
|
22
|
+
payer,
|
23
|
+
collateralMint,
|
24
|
+
payer.publicKey
|
25
|
+
)
|
26
|
+
|
27
|
+
const transaction = new Transaction().add(
|
28
|
+
await claimStakingPoolPositionInstruction(
|
29
|
+
program,
|
30
|
+
feePool,
|
31
|
+
feePoolAssociatedTokenAccount.address,
|
32
|
+
stakedTokenMint,
|
33
|
+
vaultTypeAccount,
|
34
|
+
collateralMint,
|
35
|
+
poolPosition,
|
36
|
+
payer.publicKey,
|
37
|
+
payerAssociatedTokenAccount.address
|
38
|
+
)
|
39
|
+
)
|
40
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors)
|
41
|
+
return payerAssociatedTokenAccount.address
|
42
|
+
}
|
43
|
+
|
44
|
+
export async function claimStakingPoolPositionInstruction(
|
45
|
+
program: Program,
|
46
|
+
feePool: PublicKey,
|
47
|
+
feePoolAssociatedTokenAccount: PublicKey,
|
48
|
+
stakedTokenMint: PublicKey,
|
49
|
+
vaultTypeAccount: PublicKey,
|
50
|
+
collateralMint: PublicKey,
|
51
|
+
poolPosition: PublicKey,
|
52
|
+
payer: PublicKey,
|
53
|
+
payerAssociatedTokenAccount: PublicKey
|
54
|
+
): Promise<TransactionInstruction> {
|
55
|
+
const vaultSystemState = await getVaultSystemStatePublicKey()
|
56
|
+
|
57
|
+
return program.instruction.claimStakingPoolPosition(
|
58
|
+
{
|
59
|
+
accounts: {
|
60
|
+
vaultSystemState: vaultSystemState,
|
61
|
+
feePool: feePool,
|
62
|
+
stakedTokenMint: stakedTokenMint,
|
63
|
+
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
64
|
+
vaultTypeAccount: vaultTypeAccount,
|
65
|
+
collateralMint: collateralMint,
|
66
|
+
poolPosition: poolPosition,
|
67
|
+
payer: payer,
|
68
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
69
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
70
|
+
systemProgram: SystemProgram.programId,
|
71
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
72
|
+
rent: SYSVAR_RENT_PUBKEY
|
73
|
+
},
|
74
|
+
signers: []
|
75
|
+
})
|
76
|
+
}
|
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
4
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey,
|
5
|
+
import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
6
|
|
7
7
|
export async function closeLiquidationPoolPosition (
|
8
8
|
program: Program,
|
@@ -11,8 +11,8 @@ export async function closeLiquidationPoolPosition (
|
|
11
11
|
payer: Signer,
|
12
12
|
overrideStartTime?: number
|
13
13
|
): Promise<PublicKey> {
|
14
|
-
const
|
15
|
-
const
|
14
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
15
|
+
const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
16
16
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
17
17
|
const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition)
|
18
18
|
const poolEra = liquidationPositionAccount.era
|
@@ -27,7 +27,7 @@ export async function closeLiquidationPoolPosition (
|
|
27
27
|
poolEra,
|
28
28
|
poolPosition,
|
29
29
|
payer.publicKey,
|
30
|
-
|
30
|
+
payerUshAccount.address,
|
31
31
|
payerAssociatedHedgeAccount.address,
|
32
32
|
communityAssociatedHedgeTokenAccount.address,
|
33
33
|
overrideStartTime
|
@@ -42,31 +42,31 @@ export async function closeLiquidationPoolPositionInstruction (
|
|
42
42
|
poolEra: PublicKey,
|
43
43
|
poolPosition: PublicKey,
|
44
44
|
payerPublicKey: PublicKey,
|
45
|
-
|
45
|
+
payerUshAccount: PublicKey,
|
46
46
|
payerAssociatedHedgeAccount: PublicKey,
|
47
47
|
communityAssociatedHedgeTokenAccount: PublicKey,
|
48
48
|
overrideStartTime?: number
|
49
49
|
): Promise<TransactionInstruction> {
|
50
50
|
|
51
51
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
52
|
-
const
|
52
|
+
const ushMint = await getUshMintPublicKey()
|
53
53
|
const hedgeMint = await getHedgeMintPublicKey()
|
54
|
-
const
|
54
|
+
const poolUshAccount = await getLiquidationPoolUshAccountPublicKey()
|
55
55
|
const poolState = await getLiquidationPoolStatePublicKey()
|
56
56
|
|
57
57
|
return program.instruction.closeLiquidationPoolPosition(
|
58
|
-
new BN(overrideStartTime ?? Date.now() / 1000), // override current time
|
58
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
|
59
59
|
{
|
60
60
|
accounts: {
|
61
61
|
vaultSystemState: vaultSystemStatePublicKey,
|
62
62
|
poolState: poolState,
|
63
63
|
poolEra: poolEra,
|
64
64
|
poolPosition: poolPosition,
|
65
|
-
|
65
|
+
poolUshAccount: poolUshAccount,
|
66
66
|
payer: payerPublicKey,
|
67
|
-
|
67
|
+
ownerUshAccount: payerUshAccount,
|
68
68
|
hedgeMint: hedgeMint,
|
69
|
-
|
69
|
+
ushMint: ushMint,
|
70
70
|
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
71
71
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
72
72
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
4
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import { findAssociatedTokenAddress, getPoolPublicKeyForMint,
|
5
|
+
import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
6
|
|
7
7
|
export async function createStakingPool (
|
8
8
|
program: Program,
|
@@ -35,26 +35,26 @@ export async function createStakingPoolInstruction (
|
|
35
35
|
): Promise<TransactionInstruction> {
|
36
36
|
console.log("createStakingPoolInstruction program ID", program.programId.toString())
|
37
37
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
38
|
-
const
|
38
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
39
39
|
const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey)
|
40
40
|
|
41
41
|
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey)
|
42
|
-
const
|
42
|
+
const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
|
43
43
|
|
44
44
|
return program.instruction.createStakingPool(
|
45
45
|
poolBump,
|
46
46
|
poolSeedPhrase,
|
47
47
|
new BN(hedgeTokensToBeMinted),
|
48
|
-
new BN(overrideStartTime ?? Date.now() / 1000),
|
48
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)),
|
49
49
|
{
|
50
50
|
accounts: {
|
51
51
|
signer: payerPublicKey,
|
52
52
|
vaultSystemState: vaultSystemStatePublicKey,
|
53
53
|
pool: poolPublickey,
|
54
54
|
stakedTokenMintInfo: mintPublicKey,
|
55
|
-
|
55
|
+
ushMint: ushMintPublickey,
|
56
56
|
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
57
|
-
|
57
|
+
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
58
58
|
rent: SYSVAR_RENT_PUBKEY,
|
59
59
|
tokenProgram: TOKEN_PROGRAM_ID,
|
60
60
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -19,7 +19,7 @@ import {
|
|
19
19
|
findAssociatedTokenAddress,
|
20
20
|
findVaultAddress,
|
21
21
|
getVaultTypeAccountPublicKey,
|
22
|
-
|
22
|
+
getUshMintPublicKey,
|
23
23
|
getVaultSystemStatePublicKey,
|
24
24
|
getPoolPublicKeyForMint,
|
25
25
|
getHedgeMintPublicKey,
|
@@ -36,17 +36,17 @@ export async function createVault(
|
|
36
36
|
depositAmount: number,
|
37
37
|
overrideTime?: number
|
38
38
|
): Promise<PublicKey> {
|
39
|
-
const
|
39
|
+
const ushMintPublickey = await getUshMintPublicKey();
|
40
40
|
|
41
41
|
const salt = uuidv4().substring(0, 8);
|
42
42
|
const newVaultPublicKey = await findVaultAddress(salt);
|
43
43
|
const history = Keypair.generate();
|
44
44
|
|
45
|
-
// Prep the user to get
|
45
|
+
// Prep the user to get USH back out at some point
|
46
46
|
await getOrCreateAssociatedTokenAccount(
|
47
47
|
provider.connection,
|
48
48
|
payer,
|
49
|
-
|
49
|
+
ushMintPublickey,
|
50
50
|
payer.publicKey
|
51
51
|
);
|
52
52
|
|
@@ -78,9 +78,9 @@ export async function createVault(
|
|
78
78
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
79
79
|
await getHedgeMintPublicKey()
|
80
80
|
);
|
81
|
-
const
|
81
|
+
const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
82
82
|
hedgeStakingPoolPublicKey,
|
83
|
-
|
83
|
+
ushMintPublickey
|
84
84
|
);
|
85
85
|
|
86
86
|
if (isWrappedSol) {
|
@@ -109,11 +109,11 @@ export async function createVault(
|
|
109
109
|
newVaultPublicKey,
|
110
110
|
vaultAssociatedTokenAccount,
|
111
111
|
hedgeStakingPoolPublicKey,
|
112
|
-
|
112
|
+
feePoolAssociatedUshTokenAccount,
|
113
113
|
vaultTypeAccountPublicKey,
|
114
114
|
vaultTypeAccountInfo.collateralMint,
|
115
115
|
history.publicKey,
|
116
|
-
|
116
|
+
ushMintPublickey,
|
117
117
|
depositAmount,
|
118
118
|
overrideTime
|
119
119
|
)
|
@@ -145,7 +145,7 @@ export async function buildCreateVaultTransaction(
|
|
145
145
|
): Promise<[Transaction, Signer[], PublicKey]> {
|
146
146
|
|
147
147
|
console.log("HEDGE SDK: buildCreateVaultTransaction")
|
148
|
-
const
|
148
|
+
const ushMintPublickey = await getUshMintPublicKey();
|
149
149
|
const payerPublicKey = program.provider.wallet.publicKey;
|
150
150
|
|
151
151
|
const salt = uuidv4().substring(0, 8);
|
@@ -189,9 +189,9 @@ export async function buildCreateVaultTransaction(
|
|
189
189
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
190
190
|
await getHedgeMintPublicKey()
|
191
191
|
);
|
192
|
-
const
|
192
|
+
const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
193
193
|
hedgeStakingPoolPublicKey,
|
194
|
-
|
194
|
+
ushMintPublickey
|
195
195
|
);
|
196
196
|
|
197
197
|
console.log('about to start building transaction')
|
@@ -224,11 +224,11 @@ export async function buildCreateVaultTransaction(
|
|
224
224
|
newVaultPublicKey,
|
225
225
|
vaultAssociatedTokenAccount,
|
226
226
|
hedgeStakingPoolPublicKey,
|
227
|
-
|
227
|
+
feePoolAssociatedUshTokenAccount,
|
228
228
|
vaultTypeAccountPublicKey,
|
229
229
|
vaultTypeAccountInfo.collateralMint,
|
230
230
|
history.publicKey,
|
231
|
-
|
231
|
+
ushMintPublickey,
|
232
232
|
depositAmount,
|
233
233
|
overrideTime
|
234
234
|
)
|
@@ -241,8 +241,9 @@ export async function buildCreateVaultTransaction(
|
|
241
241
|
owner: payerPublicKey,
|
242
242
|
})
|
243
243
|
);
|
244
|
+
transaction.partialSign(wrappedSolAccount)
|
244
245
|
}
|
245
|
-
|
246
|
+
|
246
247
|
transaction.partialSign(history)
|
247
248
|
console.log("transaction", transaction)
|
248
249
|
|
@@ -257,11 +258,11 @@ export async function createVaultInstruction(
|
|
257
258
|
vaultPublicKey: PublicKey,
|
258
259
|
vaultAssociatedTokenAccount: PublicKey,
|
259
260
|
feePool: PublicKey,
|
260
|
-
|
261
|
+
feePoolAssociatedUshTokenAccount: PublicKey,
|
261
262
|
vaultTypeAccount: PublicKey,
|
262
263
|
collateralMint: PublicKey,
|
263
264
|
historyPublicKey: PublicKey,
|
264
|
-
|
265
|
+
ushMintPublickey: PublicKey,
|
265
266
|
depositAmount: number,
|
266
267
|
overrideTime?: number
|
267
268
|
): Promise<TransactionInstruction> {
|
@@ -278,12 +279,12 @@ export async function createVaultInstruction(
|
|
278
279
|
vault: vaultPublicKey,
|
279
280
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
280
281
|
feePool: feePool,
|
281
|
-
|
282
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
282
283
|
history: historyPublicKey,
|
283
284
|
payer: payerPublicKey,
|
284
285
|
payerTokenAccount: payerTokenAccountPublicKey,
|
285
286
|
collateralMint: collateralMint,
|
286
|
-
|
287
|
+
ushMint: ushMintPublickey,
|
287
288
|
systemProgram: SystemProgram.programId,
|
288
289
|
tokenProgram: TOKEN_PROGRAM_ID,
|
289
290
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
4
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import { getLiquidationPoolStatePublicKey,
|
5
|
+
import { getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
6
|
|
7
7
|
export async function depositLiquidationPool (
|
8
8
|
program: Program,
|
@@ -11,15 +11,15 @@ export async function depositLiquidationPool (
|
|
11
11
|
depositAmount: number,
|
12
12
|
overrideStartTime?: number
|
13
13
|
): Promise<PublicKey> {
|
14
|
-
const
|
15
|
-
const
|
14
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
15
|
+
const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
16
16
|
|
17
17
|
const poolPosition = Keypair.generate()
|
18
18
|
const transaction = new Transaction().add(
|
19
19
|
await depositLiquidationPoolInstruction(
|
20
20
|
program,
|
21
21
|
payer.publicKey,
|
22
|
-
|
22
|
+
payerUshAccount.address,
|
23
23
|
poolPosition.publicKey,
|
24
24
|
depositAmount,
|
25
25
|
overrideStartTime
|
@@ -32,7 +32,7 @@ export async function depositLiquidationPool (
|
|
32
32
|
export async function depositLiquidationPoolInstruction (
|
33
33
|
program: Program,
|
34
34
|
payerPublicKey: PublicKey,
|
35
|
-
|
35
|
+
payerUshAccount: PublicKey,
|
36
36
|
poolPositionPublicKey: PublicKey,
|
37
37
|
depositAmount: number,
|
38
38
|
overrideStartTime?: number
|
@@ -40,24 +40,24 @@ export async function depositLiquidationPoolInstruction (
|
|
40
40
|
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
|
41
41
|
const liquidationPoolState = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
42
42
|
|
43
|
-
const
|
44
|
-
const
|
43
|
+
const poolUSHAccount = await getLiquidationPoolUshAccountPublicKey()
|
44
|
+
const ushMint = await getUshMintPublicKey()
|
45
45
|
|
46
46
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
47
47
|
|
48
48
|
return program.instruction.depositLiquidationPool(
|
49
49
|
new BN(depositAmount),
|
50
|
-
new BN(overrideStartTime ?? Date.now() / 1000), // override current time
|
50
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
|
51
51
|
{
|
52
52
|
accounts: {
|
53
53
|
vaultSystemState: vaultSystemState,
|
54
54
|
poolState: liquidationPoolStatePublicKey,
|
55
55
|
poolEra: liquidationPoolState.currentEra,
|
56
56
|
poolPosition: poolPositionPublicKey,
|
57
|
-
|
58
|
-
|
57
|
+
poolUshAccount: poolUSHAccount,
|
58
|
+
ushMint: ushMint,
|
59
59
|
payer: payerPublicKey,
|
60
|
-
|
60
|
+
ownerUshAccount: payerUshAccount,
|
61
61
|
tokenProgram: TOKEN_PROGRAM_ID,
|
62
62
|
systemProgram: SystemProgram.programId,
|
63
63
|
rent: SYSVAR_RENT_PUBKEY
|
@@ -42,7 +42,7 @@ export async function depositStakingPoolInstruction (
|
|
42
42
|
|
43
43
|
return program.instruction.depositStakingPool(
|
44
44
|
new BN(depositAmount),
|
45
|
-
new BN(overrideStartTime ?? Date.now() / 1000), // override current time
|
45
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
|
46
46
|
{
|
47
47
|
accounts: {
|
48
48
|
payer: payerPublicKey,
|
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { TokenInstructions } from '@project-serum/serum'
|
3
3
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
4
4
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
5
|
-
import { findAssociatedTokenAddress, getVaultTypeAccountPublicKey,
|
5
|
+
import { findAssociatedTokenAddress, getVaultTypeAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey, getPoolPublicKeyForMint, getHedgeMintPublicKey } from '../Constants'
|
6
6
|
|
7
7
|
export async function depositVault(
|
8
8
|
program: Program,
|
@@ -12,10 +12,10 @@ export async function depositVault(
|
|
12
12
|
depositAmount: number,
|
13
13
|
overrideTime?: number
|
14
14
|
): Promise<PublicKey> {
|
15
|
-
const
|
15
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
16
16
|
|
17
|
-
// Prep the user to get
|
18
|
-
await getOrCreateAssociatedTokenAccount(provider.connection, payer,
|
17
|
+
// Prep the user to get USH back out at some point
|
18
|
+
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
19
19
|
|
20
20
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
21
21
|
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
@@ -31,9 +31,9 @@ export async function depositVault(
|
|
31
31
|
const wrappedSolAccount = Keypair.generate()
|
32
32
|
|
33
33
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
|
34
|
-
const
|
34
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
35
35
|
hedgeStakingPoolPublicKey,
|
36
|
-
|
36
|
+
ushMintPublickey
|
37
37
|
)
|
38
38
|
|
39
39
|
const transaction = new Transaction()
|
@@ -68,9 +68,9 @@ export async function depositVault(
|
|
68
68
|
vaultTypeAccountPublicKey,
|
69
69
|
vaultTypeAssociatedTokenAccount.address,
|
70
70
|
hedgeStakingPoolPublicKey,
|
71
|
-
|
71
|
+
hedgeStakingPoolAssociatedUshTokenAccount,
|
72
72
|
vaultTypeAccountInfo.collateralMint,
|
73
|
-
|
73
|
+
ushMintPublickey,
|
74
74
|
depositAmount,
|
75
75
|
overrideTime
|
76
76
|
)
|
@@ -100,9 +100,9 @@ export async function depositVaultInstruction(
|
|
100
100
|
vaultTypeAccountPublicKey: PublicKey,
|
101
101
|
vaultTypeAssociatedTokenAccount: PublicKey,
|
102
102
|
hedgeStakingPoolPublicKey: PublicKey,
|
103
|
-
|
103
|
+
hedgeStakingPoolAssociatedUshTokenAccount: PublicKey,
|
104
104
|
collateralMint: PublicKey,
|
105
|
-
|
105
|
+
ushMintPublickey: PublicKey,
|
106
106
|
depositAmount: number,
|
107
107
|
overrideTime?: number
|
108
108
|
): Promise<TransactionInstruction> {
|
@@ -118,11 +118,11 @@ export async function depositVaultInstruction(
|
|
118
118
|
vault: vaultPublicKey,
|
119
119
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
120
120
|
feePool: hedgeStakingPoolPublicKey,
|
121
|
-
|
121
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
122
122
|
history: historyPublicKey,
|
123
123
|
vaultOwner: vaultOwner,
|
124
124
|
vaultOwnerTokenAccount: vaultOwnerTokenAccount,
|
125
|
-
|
125
|
+
ushMint: ushMintPublickey,
|
126
126
|
systemProgram: SystemProgram.programId,
|
127
127
|
tokenProgram: TOKEN_PROGRAM_ID
|
128
128
|
},
|
@@ -2,7 +2,7 @@ import { Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
4
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey,
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
6
|
|
7
7
|
export async function initHedgeFoundation(
|
8
8
|
program: Program,
|
@@ -30,8 +30,8 @@ export async function initHedgeFoundationInstruction (
|
|
30
30
|
): Promise<TransactionInstruction> {
|
31
31
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
32
32
|
const poolStatePublickey = await getLiquidationPoolStatePublicKey()
|
33
|
-
const
|
34
|
-
const
|
33
|
+
const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey()
|
34
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
35
35
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
36
36
|
const founderHedgeTokenAccount = await findAssociatedTokenAddress(
|
37
37
|
payerPublicKey,
|
@@ -48,9 +48,9 @@ export async function initHedgeFoundationInstruction (
|
|
48
48
|
vaultSystemState: vaultSystemStatePublicKey,
|
49
49
|
poolState: poolStatePublickey,
|
50
50
|
poolEra: poolEraPublicKey,
|
51
|
-
|
51
|
+
poolUshAccount: poolUshTokenAccount,
|
52
52
|
founder: payerPublicKey,
|
53
|
-
|
53
|
+
ushMint: ushMintPublickey,
|
54
54
|
hedgeMint: hedgeMintPublickey,
|
55
55
|
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
56
56
|
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
@@ -2,7 +2,7 @@ import { Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
4
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey,
|
5
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
6
6
|
|
7
7
|
export async function initHedgeFoundationTokens(
|
8
8
|
program: Program,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
3
3
|
import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
-
import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey,
|
4
|
+
import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
5
5
|
|
6
6
|
export async function liquidateVault (
|
7
7
|
program: Program,
|
@@ -17,7 +17,7 @@ export async function liquidateVault (
|
|
17
17
|
const collateralMint = vaultTypeAccountInfo.collateralMint
|
18
18
|
|
19
19
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
20
|
-
const
|
20
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
21
21
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
22
22
|
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
|
23
23
|
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
@@ -27,7 +27,7 @@ export async function liquidateVault (
|
|
27
27
|
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, vaultPublicKey, true)
|
28
28
|
const poolAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true)
|
29
29
|
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true)
|
30
|
-
const
|
30
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true)
|
31
31
|
|
32
32
|
const history = Keypair.generate()
|
33
33
|
const newEra = Keypair.generate()
|
@@ -47,7 +47,7 @@ export async function liquidateVault (
|
|
47
47
|
newEra.publicKey,
|
48
48
|
hedgeStakingPoolPublicKey,
|
49
49
|
feePoolAssociatedTokenAccount.address,
|
50
|
-
|
50
|
+
hedgeStakingPoolAssociatedUshTokenAccount.address,
|
51
51
|
collateralMint,
|
52
52
|
vaultTypeAssociatedTokenAccount.address,
|
53
53
|
vaultAccount.collateralType,
|
@@ -71,15 +71,15 @@ export async function liquidateVaultInstruction (
|
|
71
71
|
newEraPublicKey: PublicKey,
|
72
72
|
feePool: PublicKey,
|
73
73
|
feePoolAssociatedTokenAccount: PublicKey,
|
74
|
-
|
74
|
+
hedgeStakingPoolAssociatedUshTokenAccount: PublicKey,
|
75
75
|
collateralMint: PublicKey,
|
76
76
|
vaultTypeAssociatedTokenAccount: PublicKey,
|
77
77
|
collateralType: string,
|
78
78
|
overrideTime?: number
|
79
79
|
): Promise<TransactionInstruction> {
|
80
80
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
81
|
-
const
|
82
|
-
const
|
81
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
82
|
+
const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
|
83
83
|
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
84
84
|
|
85
85
|
const payload = {
|
@@ -93,14 +93,14 @@ export async function liquidateVaultInstruction (
|
|
93
93
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
94
94
|
poolState: poolState,
|
95
95
|
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
96
|
-
|
96
|
+
ushMint: ushMintPublickey,
|
97
97
|
history: historyPublicKey,
|
98
98
|
payer: payerPublicKey,
|
99
99
|
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
100
100
|
feePool: feePool,
|
101
101
|
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
102
|
-
|
103
|
-
|
102
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
103
|
+
liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
|
104
104
|
newEra: newEraPublicKey,
|
105
105
|
tokenProgram: TOKEN_PROGRAM_ID,
|
106
106
|
systemProgram: SystemProgram.programId,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
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, getVaultTypeAccountPublicKey,
|
4
|
+
import { findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getVaultTypeAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
|
5
5
|
|
6
6
|
export async function loanVault (
|
7
7
|
program: Program,
|
@@ -11,9 +11,9 @@ export async function loanVault (
|
|
11
11
|
loanAmount: number,
|
12
12
|
overrideTime?: number
|
13
13
|
): Promise<PublicKey> {
|
14
|
-
const
|
14
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
15
15
|
|
16
|
-
const
|
16
|
+
const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
17
17
|
|
18
18
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
19
19
|
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
@@ -26,7 +26,7 @@ export async function loanVault (
|
|
26
26
|
await loanVaultInstruction(
|
27
27
|
program,
|
28
28
|
payer.publicKey,
|
29
|
-
|
29
|
+
payerUshAccount.address,
|
30
30
|
vaultPublicKey,
|
31
31
|
vaultAssociatedTokenAccount.address,
|
32
32
|
history.publicKey,
|
@@ -43,7 +43,7 @@ export async function loanVault (
|
|
43
43
|
export async function loanVaultInstruction (
|
44
44
|
program: Program,
|
45
45
|
payerPublicKey: PublicKey,
|
46
|
-
|
46
|
+
ownerUshAccount: PublicKey,
|
47
47
|
vaultPublickey: PublicKey,
|
48
48
|
vaultAssociatedTokenAccount: PublicKey,
|
49
49
|
historyPublicKey: PublicKey,
|
@@ -53,12 +53,12 @@ export async function loanVaultInstruction (
|
|
53
53
|
overrideTime?: number
|
54
54
|
): Promise<TransactionInstruction> {
|
55
55
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
56
|
-
const
|
56
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
57
57
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
58
58
|
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
59
|
-
const
|
59
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
60
60
|
hedgeStakingPoolPublicKey,
|
61
|
-
|
61
|
+
ushMintPublickey
|
62
62
|
)
|
63
63
|
|
64
64
|
return program.instruction.loanVault(
|
@@ -73,10 +73,10 @@ export async function loanVaultInstruction (
|
|
73
73
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
74
74
|
history: historyPublicKey,
|
75
75
|
feePool: hedgeStakingPoolPublicKey,
|
76
|
-
|
77
|
-
|
76
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
77
|
+
ushMint: ushMintPublickey,
|
78
78
|
vaultOwner: payerPublicKey,
|
79
|
-
|
79
|
+
ownerUshAccount: ownerUshAccount,
|
80
80
|
tokenProgram: TOKEN_PROGRAM_ID,
|
81
81
|
systemProgram: SystemProgram.programId
|
82
82
|
},
|