hedge-web3 0.2.27 → 0.2.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 +12 -0
- package/declarations/idl/vault.d.ts +743 -59
- package/declarations/index.d.ts +9 -0
- package/declarations/instructions/adminWithdrawCol.d.ts +5 -0
- package/declarations/instructions/adminWithdrawUsh.d.ts +5 -0
- package/declarations/instructions/createCompoundStakingPool.d.ts +5 -0
- package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +6 -0
- package/declarations/instructions/createReferralAccount.d.ts +2 -2
- package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +6 -0
- package/declarations/instructions/depositRewardsToCompoundPool.d.ts +6 -0
- package/declarations/instructions/referralClaimFees.d.ts +2 -2
- package/declarations/instructions/setCompoundPoolActive.d.ts +5 -0
- package/declarations/instructions/setDelegateWallet.d.ts +5 -0
- package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +6 -0
- package/declarations/utils/getLinkedListAccounts.d.ts +2 -1
- package/lib/Constants.js +28 -1
- package/lib/idl/vault.js +741 -57
- package/lib/index.js +9 -0
- package/lib/instructions/adminWithdrawCol.js +60 -0
- package/lib/instructions/adminWithdrawUsh.js +57 -0
- package/lib/instructions/createCompoundStakingPool.js +58 -0
- package/lib/instructions/createCompoundStakingPoolPosition.js +56 -0
- package/lib/instructions/createReferralAccount.js +6 -3
- package/lib/instructions/depositCompoundStakingPoolPosition.js +55 -0
- package/lib/instructions/depositRewardsToCompoundPool.js +64 -0
- package/lib/instructions/liquidateVault.js +7 -1
- package/lib/instructions/loanVault.js +7 -1
- package/lib/instructions/referralClaimFees.js +6 -3
- package/lib/instructions/setCompoundPoolActive.js +43 -0
- package/lib/instructions/setDelegateWallet.js +43 -0
- package/lib/instructions/withdrawCompoundStakingPoolPosition.js +64 -0
- package/lib/utils/getLinkedListAccounts.js +5 -21
- package/package.json +5 -2
- package/src/Constants.ts +30 -0
- package/src/idl/vault.ts +3638 -2270
- package/src/index.ts +9 -2
- package/src/instructions/adminWithdrawCol.ts +87 -0
- package/src/instructions/adminWithdrawUsh.ts +78 -0
- package/src/instructions/createCompoundStakingPool.ts +63 -0
- package/src/instructions/createCompoundStakingPoolPosition.ts +85 -0
- package/src/instructions/createReferralAccount.ts +13 -9
- package/src/instructions/createStakingPool.ts +2 -9
- package/src/instructions/depositCompoundStakingPoolPosition.ts +78 -0
- package/src/instructions/depositRewardsToCompoundPool.ts +110 -0
- package/src/instructions/liquidateVault.ts +37 -27
- package/src/instructions/loanVault.ts +34 -21
- package/src/instructions/referralClaimFees.ts +16 -10
- package/src/instructions/setCompoundPoolActive.ts +51 -0
- package/src/instructions/setDelegateWallet.ts +51 -0
- package/src/instructions/withdrawCompoundStakingPoolPosition.ts +100 -0
- package/src/utils/getLinkedListAccounts.ts +6 -20
@@ -1,19 +1,22 @@
|
|
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
3
|
import {
|
4
|
+
ComputeBudgetProgram,
|
4
5
|
Keypair,
|
5
|
-
PublicKey,
|
6
|
+
PublicKey,
|
7
|
+
Signer,
|
6
8
|
SystemProgram,
|
7
9
|
SYSVAR_RENT_PUBKEY,
|
8
10
|
Transaction,
|
9
|
-
TransactionInstruction
|
11
|
+
TransactionInstruction,
|
10
12
|
} from '@solana/web3.js'
|
11
13
|
import {
|
12
14
|
getHedgeMintPublicKey,
|
13
15
|
getLiquidationPoolStatePublicKey,
|
14
16
|
getLiquidationPoolUshAccountPublicKey,
|
15
|
-
getPoolPublicKeyForMint,
|
16
|
-
|
17
|
+
getPoolPublicKeyForMint,
|
18
|
+
getUshMintPublicKey,
|
19
|
+
getVaultSystemStatePublicKey,
|
17
20
|
} from '../Constants'
|
18
21
|
import { Vault } from '../idl/vault'
|
19
22
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
@@ -37,6 +40,11 @@ export async function liquidateVault(
|
|
37
40
|
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
|
38
41
|
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
39
42
|
|
43
|
+
const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
|
44
|
+
units: 300000,
|
45
|
+
additionalFee: 0,
|
46
|
+
})
|
47
|
+
|
40
48
|
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
41
49
|
provider.connection,
|
42
50
|
payer,
|
@@ -96,30 +104,32 @@ export async function liquidateVault(
|
|
96
104
|
const newEra = Keypair.generate()
|
97
105
|
const transaction = new Transaction()
|
98
106
|
|
99
|
-
transaction
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
107
|
+
transaction
|
108
|
+
.add(additionalComputationBudget)
|
109
|
+
.add(
|
110
|
+
await liquidateVaultInstruction(
|
111
|
+
program,
|
112
|
+
payer.publicKey,
|
113
|
+
payerAssociatedTokenAccount.address,
|
114
|
+
vaultPublicKey,
|
115
|
+
vaultAssociatedTokenAccount.address,
|
116
|
+
liquidationPoolStatePublicKey,
|
117
|
+
poolStateInfo.currentEra,
|
118
|
+
poolAssociatedTokenAccount.address,
|
119
|
+
history.publicKey,
|
120
|
+
newEra.publicKey,
|
121
|
+
hedgeStakingPoolPublicKey,
|
122
|
+
feePoolAssociatedTokenAccount.address,
|
123
|
+
hedgeStakingPoolAssociatedUshTokenAccount.address,
|
124
|
+
collateralMint,
|
125
|
+
vaultTypeAssociatedTokenAccount.address,
|
126
|
+
oldSmallerPublicKey,
|
127
|
+
newSmallerPublicKey,
|
128
|
+
newLargerPublicKey,
|
129
|
+
vaultAccount.vaultType,
|
130
|
+
overrideTime
|
131
|
+
)
|
121
132
|
)
|
122
|
-
)
|
123
133
|
|
124
134
|
await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history, newEra])
|
125
135
|
return vaultPublicKey
|
@@ -1,17 +1,23 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
|
+
ComputeBudgetProgram,
|
4
5
|
Keypair,
|
5
|
-
PublicKey,
|
6
|
+
PublicKey,
|
7
|
+
Signer,
|
6
8
|
SystemProgram,
|
7
9
|
Transaction,
|
8
|
-
TransactionInstruction
|
10
|
+
TransactionInstruction,
|
9
11
|
} from '@solana/web3.js'
|
10
12
|
import {
|
11
13
|
findAssociatedTokenAddress,
|
12
14
|
getHedgeMintPublicKey,
|
13
|
-
getPoolPublicKeyForMint,
|
14
|
-
|
15
|
+
getPoolPublicKeyForMint,
|
16
|
+
getReferralAccountPublicKey,
|
17
|
+
getReferralStatePublicKey,
|
18
|
+
getUserReferralAccountPublicKey,
|
19
|
+
getUshMintPublicKey,
|
20
|
+
getVaultSystemStatePublicKey,
|
15
21
|
} from '../Constants'
|
16
22
|
import { Vault } from '../idl/vault'
|
17
23
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
@@ -26,6 +32,11 @@ export async function loanVault(
|
|
26
32
|
overrideTime?: number,
|
27
33
|
referrer?: PublicKey
|
28
34
|
): Promise<PublicKey> {
|
35
|
+
const additionalComputationBudget = ComputeBudgetProgram.requestUnits({
|
36
|
+
units: 300000,
|
37
|
+
additionalFee: 0,
|
38
|
+
})
|
39
|
+
|
29
40
|
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
30
41
|
|
31
42
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -72,24 +83,26 @@ export async function loanVault(
|
|
72
83
|
}
|
73
84
|
|
74
85
|
const history = Keypair.generate()
|
75
|
-
const transaction = new Transaction()
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
const transaction = new Transaction()
|
87
|
+
.add(additionalComputationBudget)
|
88
|
+
.add(
|
89
|
+
await loanVaultInstruction(
|
90
|
+
program,
|
91
|
+
payer.publicKey,
|
92
|
+
payerUshAccount.address,
|
93
|
+
vaultPublicKey,
|
94
|
+
vaultAssociatedTokenAccount.address,
|
95
|
+
history.publicKey,
|
96
|
+
vaultAccount.vaultType,
|
97
|
+
vaultTypeAssociatedTokenAccount.address,
|
98
|
+
oldSmallerPublicKey,
|
99
|
+
newSmallerPublicKey,
|
100
|
+
newLargerPublicKey,
|
101
|
+
new BN(loanAmount),
|
102
|
+
referralAccountPublicKey,
|
103
|
+
overrideTime
|
104
|
+
)
|
91
105
|
)
|
92
|
-
)
|
93
106
|
await sendAndConfirmWithDebug(provider.connection, transaction, [payer, history])
|
94
107
|
return vaultPublicKey
|
95
108
|
}
|
@@ -1,15 +1,14 @@
|
|
1
1
|
import { Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
|
3
4
|
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
getHedgeMintPublicKey, getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey,
|
12
|
-
getUshMintPublicKey, getVaultSystemStatePublicKey
|
5
|
+
getCompoundPoolPublicKeyForMint,
|
6
|
+
getHedgeMintPublicKey,
|
7
|
+
getPoolPublicKeyForMint,
|
8
|
+
getReferralAccountPublicKey,
|
9
|
+
getReferralStatePublicKey,
|
10
|
+
getUshMintPublicKey,
|
11
|
+
getVaultSystemStatePublicKey,
|
13
12
|
} from '../Constants'
|
14
13
|
|
15
14
|
import { Vault } from '../idl/vault'
|
@@ -31,7 +30,8 @@ export async function referralClaimFees(
|
|
31
30
|
program: Program<Vault>,
|
32
31
|
provider: Provider,
|
33
32
|
payer: Signer,
|
34
|
-
poolPosition: PublicKey
|
33
|
+
poolPosition: PublicKey,
|
34
|
+
stakedTokenMintPublicKey: PublicKey
|
35
35
|
): Promise<PublicKey> {
|
36
36
|
// setup transaction
|
37
37
|
const transaction = new Transaction()
|
@@ -91,6 +91,7 @@ export async function referralClaimFees(
|
|
91
91
|
payer.publicKey,
|
92
92
|
vaultSystemStatePublicKey,
|
93
93
|
poolPosition,
|
94
|
+
stakedTokenMintPublicKey,
|
94
95
|
referralAccountPublicKey,
|
95
96
|
referallStatePublicKey,
|
96
97
|
hedgeMintPublicKey,
|
@@ -112,6 +113,7 @@ export async function referralClaimFeesInstruction(
|
|
112
113
|
payerPublicKey: PublicKey,
|
113
114
|
vaultSystemStatePublicKey: PublicKey,
|
114
115
|
poolPositionPublicKey: PublicKey,
|
116
|
+
stakedTokenMintPublicKey: PublicKey,
|
115
117
|
referralAccountPublicKey: PublicKey,
|
116
118
|
referralStatePublicKey: PublicKey,
|
117
119
|
hedgeMintPublicKey: PublicKey,
|
@@ -122,6 +124,8 @@ export async function referralClaimFeesInstruction(
|
|
122
124
|
feePoolPublicKey: PublicKey,
|
123
125
|
feePoolAssociatedUshTokenAccountPublicKey: PublicKey
|
124
126
|
): Promise<TransactionInstruction> {
|
127
|
+
const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
|
128
|
+
|
125
129
|
return await program.methods
|
126
130
|
.referralClaimFees()
|
127
131
|
.accounts({
|
@@ -135,6 +139,8 @@ export async function referralClaimFeesInstruction(
|
|
135
139
|
ushMint: ushMintPublicKey,
|
136
140
|
signerUshAta: ushAssociatedTokenAccountPublicKey,
|
137
141
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccountPublicKey,
|
142
|
+
pool: poolPublickey,
|
143
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
138
144
|
feePool: feePoolPublicKey,
|
139
145
|
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccountPublicKey,
|
140
146
|
systemProgram: SystemProgram.programId,
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
|
3
|
+
import { getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
|
4
|
+
|
5
|
+
import { Vault } from '../idl/vault'
|
6
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
7
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
8
|
+
|
9
|
+
export async function setCompoundPoolActive(
|
10
|
+
program: Program<Vault>,
|
11
|
+
provider: Provider,
|
12
|
+
payer: Signer,
|
13
|
+
mintPublicKey: PublicKey,
|
14
|
+
setActive: boolean
|
15
|
+
): Promise<PublicKey> {
|
16
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
17
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
|
18
|
+
|
19
|
+
const transaction = new Transaction().add(
|
20
|
+
await setCompoundPoolActiveInstruction(
|
21
|
+
program,
|
22
|
+
vaultSystemStatePublicKey,
|
23
|
+
payer.publicKey,
|
24
|
+
poolPublickey,
|
25
|
+
mintPublicKey,
|
26
|
+
setActive
|
27
|
+
)
|
28
|
+
)
|
29
|
+
|
30
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
31
|
+
return poolPublickey
|
32
|
+
}
|
33
|
+
|
34
|
+
export async function setCompoundPoolActiveInstruction(
|
35
|
+
program: Program<Vault>,
|
36
|
+
vaultSystemStatePublicKey: PublicKey,
|
37
|
+
payerPublicKey: PublicKey,
|
38
|
+
poolPublicKey: PublicKey,
|
39
|
+
stakedTokenMintPublicKey: PublicKey,
|
40
|
+
setActive: boolean
|
41
|
+
): Promise<TransactionInstruction> {
|
42
|
+
return await program.methods
|
43
|
+
.setCompoundPoolActive(setActive)
|
44
|
+
.accounts({
|
45
|
+
payer: payerPublicKey,
|
46
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
47
|
+
pool: poolPublicKey,
|
48
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
49
|
+
})
|
50
|
+
.instruction()
|
51
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
|
3
|
+
import { getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
|
4
|
+
|
5
|
+
import { Vault } from '../idl/vault'
|
6
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
7
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
8
|
+
|
9
|
+
export async function setDelegateWallet(
|
10
|
+
program: Program<Vault>,
|
11
|
+
provider: Provider,
|
12
|
+
payer: Signer,
|
13
|
+
mintPublicKey: PublicKey,
|
14
|
+
delegateWallet: PublicKey
|
15
|
+
): Promise<PublicKey> {
|
16
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
17
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
|
18
|
+
|
19
|
+
const transaction = new Transaction().add(
|
20
|
+
await setDelegateWalletInstruction(
|
21
|
+
program,
|
22
|
+
vaultSystemStatePublicKey,
|
23
|
+
payer.publicKey,
|
24
|
+
poolPublickey,
|
25
|
+
mintPublicKey,
|
26
|
+
delegateWallet
|
27
|
+
)
|
28
|
+
)
|
29
|
+
|
30
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
31
|
+
return delegateWallet
|
32
|
+
}
|
33
|
+
|
34
|
+
export async function setDelegateWalletInstruction(
|
35
|
+
program: Program<Vault>,
|
36
|
+
vaultSystemStatePublicKey: PublicKey,
|
37
|
+
payerPublicKey: PublicKey,
|
38
|
+
poolPublicKey: PublicKey,
|
39
|
+
stakedTokenMintPublicKey: PublicKey,
|
40
|
+
delegateWallet: PublicKey
|
41
|
+
): Promise<TransactionInstruction> {
|
42
|
+
return await program.methods
|
43
|
+
.setDelegateWallet(delegateWallet)
|
44
|
+
.accounts({
|
45
|
+
payer: payerPublicKey,
|
46
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
47
|
+
pool: poolPublicKey,
|
48
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
49
|
+
})
|
50
|
+
.instruction()
|
51
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
+
import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
|
4
|
+
import {
|
5
|
+
findAssociatedTokenAddress,
|
6
|
+
getCompoundPoolPositionAddress,
|
7
|
+
getCompoundPoolPublicKeyForMint,
|
8
|
+
getHedgeMintPublicKey,
|
9
|
+
getPoolPublicKeyForMint,
|
10
|
+
getUshMintPublicKey,
|
11
|
+
getVaultSystemStatePublicKey,
|
12
|
+
} from '../Constants'
|
13
|
+
import { Vault } from '../idl/vault'
|
14
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
15
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
16
|
+
|
17
|
+
export async function withdrawCompoundStakingPoolPosition(
|
18
|
+
program: Program<Vault>,
|
19
|
+
provider: Provider,
|
20
|
+
payer: Signer,
|
21
|
+
poolPositionPublicKey: PublicKey,
|
22
|
+
stakedTokenMintPublicKey: PublicKey,
|
23
|
+
claimAmount: number,
|
24
|
+
overrideStartTime?: number
|
25
|
+
): Promise<PublicKey> {
|
26
|
+
const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
|
27
|
+
|
28
|
+
const poolPosition = await getCompoundPoolPositionAddress(program.programId, poolPublickey, payer.publicKey)
|
29
|
+
|
30
|
+
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
31
|
+
provider.connection,
|
32
|
+
payer,
|
33
|
+
stakedTokenMintPublicKey,
|
34
|
+
payer.publicKey
|
35
|
+
)
|
36
|
+
const transaction = new Transaction().add(
|
37
|
+
await withdrawCompoundStakingPoolPositionInstruction(
|
38
|
+
program,
|
39
|
+
payer.publicKey,
|
40
|
+
poolPositionPublicKey,
|
41
|
+
stakedTokenMintPublicKey,
|
42
|
+
new BN(claimAmount),
|
43
|
+
overrideStartTime
|
44
|
+
)
|
45
|
+
)
|
46
|
+
|
47
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
|
48
|
+
return payerAssociatedTokenAccount.address
|
49
|
+
}
|
50
|
+
|
51
|
+
export async function withdrawCompoundStakingPoolPositionInstruction(
|
52
|
+
program: Program<Vault>,
|
53
|
+
payerPublicKey: PublicKey,
|
54
|
+
poolPositionPublicKey: PublicKey,
|
55
|
+
stakedTokenMintPublicKey: PublicKey,
|
56
|
+
claimAmount: BN,
|
57
|
+
overrideStartTime?: number
|
58
|
+
): Promise<TransactionInstruction> {
|
59
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
60
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
61
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
62
|
+
const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
|
63
|
+
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
|
64
|
+
program.programId,
|
65
|
+
poolPublickey,
|
66
|
+
stakedTokenMintPublicKey
|
67
|
+
)
|
68
|
+
const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
|
69
|
+
const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
|
70
|
+
program.programId,
|
71
|
+
payerPublicKey,
|
72
|
+
stakedTokenMintPublicKey
|
73
|
+
)
|
74
|
+
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
|
75
|
+
const payerAssociatedUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
|
76
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
77
|
+
program.programId,
|
78
|
+
vaultSystemStatePublicKey,
|
79
|
+
hedgeMintPublickey
|
80
|
+
)
|
81
|
+
|
82
|
+
return await program.methods
|
83
|
+
.withdrawCompoundStakingPoolPosition(
|
84
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)), // override current time
|
85
|
+
claimAmount //amount to be claimed
|
86
|
+
)
|
87
|
+
.accounts({
|
88
|
+
payer: payerPublicKey,
|
89
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
90
|
+
pool: poolPublickey,
|
91
|
+
poolPosition: poolPositionPublicKey,
|
92
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
93
|
+
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
94
|
+
hedgeMint: hedgeMintPublickey,
|
95
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
96
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
97
|
+
systemProgram: SystemProgram.programId,
|
98
|
+
})
|
99
|
+
.instruction()
|
100
|
+
}
|
@@ -22,6 +22,7 @@ import VaultType from '../state/VaultType'
|
|
22
22
|
* @param {boolean} redeem - True if vault is going to be redeemed fully
|
23
23
|
* @param {boolean} liquidate - True if vault is going to be liquidated fully
|
24
24
|
* @param {VaultAccount[]} cachedVaults - Optional list of cached vaults. Saves a request to the on-chain data.
|
25
|
+
* @param {VaultAccount} preLoadedVault - Optional vault to use as target vault. Overrides the need to load the vault from on-chain data.
|
25
26
|
*/
|
26
27
|
export async function getLinkedListAccounts(
|
27
28
|
program: Program<Vault>,
|
@@ -33,7 +34,8 @@ export async function getLinkedListAccounts(
|
|
33
34
|
repayAmount: BN,
|
34
35
|
redeem: boolean,
|
35
36
|
liquidate: boolean,
|
36
|
-
cachedVaults?: VaultAccount[]
|
37
|
+
cachedVaults?: VaultAccount[],
|
38
|
+
preLoadedVault?: VaultAccount
|
37
39
|
): Promise<[PublicKey, PublicKey, PublicKey, VaultAccount[]]> {
|
38
40
|
const vaultTypeRaw = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
39
41
|
const vaultType = new VaultType(vaultTypeRaw, vaultTypeAccountPublicKey)
|
@@ -45,25 +47,9 @@ export async function getLinkedListAccounts(
|
|
45
47
|
let newSmallerPublicKey = vaultPublicKey
|
46
48
|
let newLargerPublicKey = vaultPublicKey
|
47
49
|
|
48
|
-
const
|
49
|
-
|
50
|
-
|
51
|
-
return {
|
52
|
-
vaultOwner: new PublicKey('11111111111111111111111111111111'),
|
53
|
-
pdaSalt: 'foo',
|
54
|
-
deposited: new BN(0),
|
55
|
-
denormalizedDebt: new BN(0),
|
56
|
-
vaultNumber: new BN(0),
|
57
|
-
debtProductSnapshotBytes: new BN(1),
|
58
|
-
collateralAccumulatorSnapshotBytes: new BN(1),
|
59
|
-
vaultTypeName: vaultType.name,
|
60
|
-
nextVaultToRedeem: new PublicKey('11111111111111111111111111111111'),
|
61
|
-
vaultStatus: {open: true},
|
62
|
-
vaultType: vaultTypeAccountPublicKey
|
63
|
-
}
|
64
|
-
})
|
65
|
-
// const accountInfo = await program.provider.connection.getAccountInfo(vaultPublicKey)
|
66
|
-
const thisVault = new VaultAccount(thisVaultData, vaultPublicKey)
|
50
|
+
const thisVault = preLoadedVault
|
51
|
+
? preLoadedVault
|
52
|
+
: new VaultAccount(await program.account.vault.fetch(vaultPublicKey), vaultPublicKey)
|
67
53
|
|
68
54
|
// Load all the vaults
|
69
55
|
let vaults
|