hedge-web3 0.2.24 → 0.2.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 +13 -15
- package/declarations/idl/vault.d.ts +36 -0
- package/declarations/instructions/createReferralAccount.d.ts +1 -1
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
- package/declarations/instructions/referralClaimFees.d.ts +1 -1
- package/declarations/state/VaultAccount.d.ts +15 -2
- package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
- package/lib/Constants.js +28 -34
- package/lib/idl/vault.js +36 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
- package/lib/instructions/claimStakingPoolPosition.js +5 -5
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
- package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
- package/lib/instructions/createReferralAccount.js +8 -8
- package/lib/instructions/createStakingPool.js +7 -7
- package/lib/instructions/createUserReferralAccount.js +6 -6
- package/lib/instructions/createVault.js +16 -16
- package/lib/instructions/depositLiquidationPool.js +9 -9
- package/lib/instructions/depositStakingPool.js +5 -5
- package/lib/instructions/depositVault.js +11 -9
- package/lib/instructions/initHedgeFoundation.js +8 -8
- package/lib/instructions/initHedgeFoundationTokens.js +5 -5
- package/lib/instructions/liquidateVault.js +8 -8
- package/lib/instructions/loanVault.js +12 -12
- package/lib/instructions/psmEditAccount.js +5 -5
- package/lib/instructions/psmMintUsh.js +14 -14
- package/lib/instructions/psmRedeemUsh.js +14 -14
- package/lib/instructions/redeemVault.js +7 -7
- package/lib/instructions/referralClaimFees.js +8 -8
- package/lib/instructions/refreshOraclePrice.js +3 -3
- package/lib/instructions/repayVault.js +9 -9
- package/lib/instructions/setHalted.js +1 -1
- package/lib/instructions/updateReferralAccount.js +2 -2
- package/lib/instructions/updateReferralState.js +2 -2
- package/lib/instructions/updateVaultType.js +1 -1
- package/lib/instructions/withdrawStakingPool.js +11 -11
- package/lib/instructions/withdrawVault.js +5 -5
- package/lib/state/VaultAccount.js +16 -16
- package/lib/utils/getLinkedListAccounts.js +20 -4
- package/package.json +1 -1
- package/src/Constants.ts +44 -85
- package/src/idl/vault.ts +72 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
- package/src/instructions/claimStakingPoolPosition.ts +10 -15
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
- package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
- package/src/instructions/createReferralAccount.ts +17 -29
- package/src/instructions/createStakingPool.ts +11 -13
- package/src/instructions/createUserReferralAccount.ts +13 -24
- package/src/instructions/createVault.ts +44 -21
- package/src/instructions/depositLiquidationPool.ts +16 -23
- package/src/instructions/depositStakingPool.ts +18 -14
- package/src/instructions/depositVault.ts +23 -18
- package/src/instructions/initHedgeFoundation.ts +16 -14
- package/src/instructions/initHedgeFoundationTokens.ts +12 -14
- package/src/instructions/liquidateVault.ts +15 -20
- package/src/instructions/loanVault.ts +18 -27
- package/src/instructions/psmEditAccount.ts +10 -18
- package/src/instructions/psmMintUsh.ts +19 -41
- package/src/instructions/psmRedeemUsh.ts +21 -45
- package/src/instructions/redeemVault.ts +12 -15
- package/src/instructions/referralClaimFees.ts +17 -31
- package/src/instructions/refreshOraclePrice.ts +6 -8
- package/src/instructions/repayVault.ts +18 -16
- package/src/instructions/setHalted.ts +5 -24
- package/src/instructions/transferVault.ts +4 -9
- package/src/instructions/updateReferralAccount.ts +7 -14
- package/src/instructions/updateReferralState.ts +7 -14
- package/src/instructions/updateVaultType.ts +9 -23
- package/src/instructions/withdrawStakingPool.ts +17 -21
- package/src/instructions/withdrawVault.ts +10 -16
- package/src/state/VaultAccount.ts +31 -17
- package/src/utils/getLinkedListAccounts.ts +20 -7
@@ -3,24 +3,20 @@ import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl
|
|
3
3
|
// import { TokenInstructions } from '@project-serum/serum'
|
4
4
|
import {
|
5
5
|
Keypair,
|
6
|
-
PublicKey,
|
7
|
-
sendAndConfirmTransaction,
|
8
|
-
Signer,
|
6
|
+
PublicKey, Signer,
|
9
7
|
SystemProgram,
|
10
8
|
Transaction,
|
11
|
-
TransactionInstruction
|
9
|
+
TransactionInstruction
|
12
10
|
} from '@solana/web3.js'
|
13
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
14
11
|
import {
|
15
12
|
findAssociatedTokenAddress,
|
16
13
|
getHedgeMintPublicKey,
|
17
|
-
getPoolPublicKeyForMint,
|
18
|
-
|
19
|
-
getUshMintPublicKey,
|
20
|
-
getVaultSystemStatePublicKey,
|
14
|
+
getPoolPublicKeyForMint, getUshMintPublicKey,
|
15
|
+
getVaultSystemStatePublicKey
|
21
16
|
} from '../Constants'
|
22
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
17
|
import { Vault } from '../idl/vault'
|
18
|
+
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
19
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
24
20
|
|
25
21
|
export async function redeemVault(
|
26
22
|
program: Program<Vault>,
|
@@ -30,7 +26,7 @@ export async function redeemVault(
|
|
30
26
|
redeemAmount: number,
|
31
27
|
transactionOverrideTime?: number
|
32
28
|
): Promise<PublicKey> {
|
33
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
29
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
34
30
|
|
35
31
|
// Prep the user to get USH back out at some point
|
36
32
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -116,11 +112,12 @@ export async function redeemVaultInstruction(
|
|
116
112
|
redeemAmount: BN,
|
117
113
|
transactionOverrideTime?: number
|
118
114
|
): Promise<TransactionInstruction> {
|
119
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
120
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
121
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
122
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
115
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
116
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
117
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
118
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
123
119
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
120
|
+
program.programId,
|
124
121
|
hedgeStakingPoolPublicKey,
|
125
122
|
ushMintPublickey
|
126
123
|
)
|
@@ -1,30 +1,20 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
4
3
|
import {
|
5
|
-
|
6
|
-
PublicKey,
|
7
|
-
sendAndConfirmTransaction,
|
8
|
-
Signer,
|
4
|
+
PublicKey, Signer,
|
9
5
|
SystemProgram,
|
10
6
|
SYSVAR_RENT_PUBKEY,
|
11
7
|
Transaction,
|
12
|
-
TransactionInstruction
|
8
|
+
TransactionInstruction
|
13
9
|
} from '@solana/web3.js'
|
14
10
|
import {
|
15
|
-
|
16
|
-
|
17
|
-
getHedgeMintPublicKey,
|
18
|
-
getReferralStatePublicKey,
|
19
|
-
getUshMintPublicKey,
|
20
|
-
getPoolPublicKeyForMint
|
11
|
+
getHedgeMintPublicKey, getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey,
|
12
|
+
getUshMintPublicKey, getVaultSystemStatePublicKey
|
21
13
|
} from '../Constants'
|
22
14
|
|
15
|
+
import { Vault } from '../idl/vault'
|
23
16
|
import { parseAnchorErrors } from '../utils/Errors'
|
24
17
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
25
|
-
import { Vault } from '../idl/vault'
|
26
|
-
|
27
|
-
|
28
18
|
|
29
19
|
/** @type {Function} - Allows a referrer to claims their fees.
|
30
20
|
* This checks the user has enough HDG in their wallet or staked and
|
@@ -36,30 +26,29 @@ import { Vault } from '../idl/vault'
|
|
36
26
|
* - payer: Signer : who we are creating the referral account for
|
37
27
|
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
38
28
|
* - referrer: PublicKey
|
39
|
-
*/
|
29
|
+
*/
|
40
30
|
export async function referralClaimFees(
|
41
31
|
program: Program<Vault>,
|
42
32
|
provider: Provider,
|
43
33
|
payer: Signer,
|
44
34
|
poolPosition: PublicKey
|
45
35
|
): Promise<PublicKey> {
|
46
|
-
// setup transaction
|
36
|
+
// setup transaction
|
47
37
|
const transaction = new Transaction()
|
48
38
|
const signers = [payer]
|
49
39
|
|
50
40
|
// General variables
|
51
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
41
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
52
42
|
|
53
43
|
// Find referrer account
|
54
44
|
const referrer = await payer.publicKey
|
55
|
-
const referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
|
56
|
-
|
45
|
+
const referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
57
46
|
|
58
47
|
// Derive the user referral account public key
|
59
|
-
const referallStatePublicKey = await getReferralStatePublicKey()
|
48
|
+
const referallStatePublicKey = await getReferralStatePublicKey(program.programId)
|
49
|
+
|
50
|
+
const hedgeMintPublicKey = await getHedgeMintPublicKey(program.programId)
|
60
51
|
|
61
|
-
const hedgeMintPublicKey = await getHedgeMintPublicKey()
|
62
|
-
|
63
52
|
// Get HDG account of signer
|
64
53
|
const payerHdgAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
65
54
|
provider.connection,
|
@@ -68,7 +57,7 @@ export async function referralClaimFees(
|
|
68
57
|
payer.publicKey
|
69
58
|
)
|
70
59
|
|
71
|
-
const ushMintPublicKey = await getUshMintPublicKey()
|
60
|
+
const ushMintPublicKey = await getUshMintPublicKey(program.programId)
|
72
61
|
|
73
62
|
// Get USH account of signer
|
74
63
|
const payerUshAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -87,8 +76,8 @@ export async function referralClaimFees(
|
|
87
76
|
true
|
88
77
|
)
|
89
78
|
|
90
|
-
const [feePoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublicKey)
|
91
|
-
|
79
|
+
const [feePoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublicKey)
|
80
|
+
|
92
81
|
const feePoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
|
93
82
|
provider.connection,
|
94
83
|
payer,
|
@@ -114,12 +103,10 @@ export async function referralClaimFees(
|
|
114
103
|
)
|
115
104
|
)
|
116
105
|
|
117
|
-
|
118
106
|
await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
|
119
107
|
return referralAccountPublicKey
|
120
108
|
}
|
121
109
|
|
122
|
-
|
123
110
|
export async function referralClaimFeesInstruction(
|
124
111
|
program: Program<Vault>,
|
125
112
|
payerPublicKey: PublicKey,
|
@@ -135,7 +122,6 @@ export async function referralClaimFeesInstruction(
|
|
135
122
|
feePoolPublicKey: PublicKey,
|
136
123
|
feePoolAssociatedUshTokenAccountPublicKey: PublicKey
|
137
124
|
): Promise<TransactionInstruction> {
|
138
|
-
|
139
125
|
return await program.methods
|
140
126
|
.referralClaimFees()
|
141
127
|
.accounts({
|
@@ -1,17 +1,15 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import {
|
3
3
|
LAMPORTS_PER_SOL,
|
4
|
-
PublicKey,
|
5
|
-
sendAndConfirmTransaction,
|
6
|
-
Signer,
|
4
|
+
PublicKey, Signer,
|
7
5
|
SystemProgram,
|
8
6
|
Transaction,
|
9
7
|
TransactionInstruction,
|
10
|
-
TransactionSignature
|
8
|
+
TransactionSignature
|
11
9
|
} from '@solana/web3.js'
|
12
|
-
import
|
10
|
+
import { CHAINLINK_PROGRAM_ID } from '../Constants'
|
13
11
|
import { Vault } from '../idl/vault'
|
14
|
-
import
|
12
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
15
13
|
|
16
14
|
export async function refreshOraclePrice(
|
17
15
|
program: Program<Vault>,
|
@@ -38,11 +36,11 @@ export async function refreshOraclePriceInstruction(
|
|
38
36
|
const enc = new TextEncoder()
|
39
37
|
const [oracleInfoAccount] = await PublicKey.findProgramAddress(
|
40
38
|
[enc.encode(collateralType), enc.encode('Oracle')],
|
41
|
-
|
39
|
+
program.programId
|
42
40
|
)
|
43
41
|
const [vaultTypeAccount] = await PublicKey.findProgramAddress(
|
44
42
|
[enc.encode(collateralType), enc.encode('State')],
|
45
|
-
|
43
|
+
program.programId
|
46
44
|
)
|
47
45
|
const oracleInfo = await program.account.oracleInfoForCollateralType.fetch(oracleInfoAccount)
|
48
46
|
|
@@ -2,24 +2,20 @@ import { BN, Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
Keypair,
|
5
|
-
PublicKey,
|
6
|
-
sendAndConfirmTransaction,
|
7
|
-
Signer,
|
5
|
+
PublicKey, Signer,
|
8
6
|
SystemProgram,
|
9
7
|
Transaction,
|
10
|
-
TransactionInstruction
|
8
|
+
TransactionInstruction
|
11
9
|
} from '@solana/web3.js'
|
12
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
13
10
|
import {
|
14
11
|
findAssociatedTokenAddress,
|
15
12
|
getHedgeMintPublicKey,
|
16
|
-
getPoolPublicKeyForMint,
|
17
|
-
|
18
|
-
getUshMintPublicKey,
|
19
|
-
getVaultSystemStatePublicKey,
|
13
|
+
getPoolPublicKeyForMint, getUshMintPublicKey,
|
14
|
+
getVaultSystemStatePublicKey
|
20
15
|
} from '../Constants'
|
21
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
22
16
|
import { Vault } from '../idl/vault'
|
17
|
+
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
18
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
19
|
|
24
20
|
export async function repayVault(
|
25
21
|
program: Program<Vault>,
|
@@ -29,7 +25,7 @@ export async function repayVault(
|
|
29
25
|
repayAmount: number,
|
30
26
|
overrideTime?: number
|
31
27
|
): Promise<PublicKey> {
|
32
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
28
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
33
29
|
|
34
30
|
// Prep the user to get USH back out at some point
|
35
31
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -42,10 +38,15 @@ export async function repayVault(
|
|
42
38
|
|
43
39
|
const vaultTypeAccount = await program.account.vaultType.fetch(vaultAccount.vaultType)
|
44
40
|
const vaultTypeAssociatedTokenAccount = await findAssociatedTokenAddress(
|
41
|
+
program.programId,
|
45
42
|
vaultAccount.vaultType,
|
46
43
|
vaultTypeAccount.collateralMint
|
47
44
|
)
|
48
|
-
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
|
45
|
+
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
|
46
|
+
program.programId,
|
47
|
+
vaultPublicKey,
|
48
|
+
vaultTypeAccount.collateralMint
|
49
|
+
)
|
49
50
|
|
50
51
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
51
52
|
program,
|
@@ -96,11 +97,12 @@ export async function repayVaultInstruction(
|
|
96
97
|
repayAmount: BN,
|
97
98
|
overrideTime?: number
|
98
99
|
): Promise<TransactionInstruction> {
|
99
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
100
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
101
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
102
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
100
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
101
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
102
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
103
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
103
104
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
105
|
+
program.programId,
|
104
106
|
hedgeStakingPoolPublicKey,
|
105
107
|
ushMintPublickey
|
106
108
|
)
|
@@ -1,29 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
Keypair,
|
6
|
-
PublicKey,
|
7
|
-
sendAndConfirmTransaction,
|
8
|
-
Signer,
|
9
|
-
SystemProgram,
|
10
|
-
SYSVAR_RENT_PUBKEY,
|
11
|
-
Transaction,
|
12
|
-
TransactionInstruction,
|
13
|
-
} from '@solana/web3.js'
|
14
|
-
import {
|
15
|
-
findAssociatedTokenAddress,
|
16
|
-
findVaultAddress,
|
17
|
-
getVaultTypeAccountPublicKey,
|
18
|
-
getUshMintPublicKey,
|
19
|
-
getVaultSystemStatePublicKey,
|
20
|
-
getPoolPublicKeyForMint,
|
21
|
-
getHedgeMintPublicKey,
|
22
|
-
} from '../Constants'
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { PublicKey, Signer, Transaction, TransactionInstruction } from '@solana/web3.js'
|
3
|
+
import { getVaultSystemStatePublicKey } from '../Constants'
|
23
4
|
|
5
|
+
import { Vault } from '../idl/vault'
|
24
6
|
import { parseAnchorErrors } from '../utils/Errors'
|
25
7
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
26
|
-
import { Vault } from '../idl/vault'
|
27
8
|
|
28
9
|
export async function setHalted(
|
29
10
|
program: Program<Vault>,
|
@@ -31,7 +12,7 @@ export async function setHalted(
|
|
31
12
|
payer: Signer,
|
32
13
|
halted: boolean
|
33
14
|
): Promise<PublicKey> {
|
34
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
15
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
35
16
|
|
36
17
|
const transaction = new Transaction().add(
|
37
18
|
await setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted)
|
@@ -1,17 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
2
2
|
import {
|
3
3
|
Keypair,
|
4
|
-
PublicKey,
|
5
|
-
|
6
|
-
Signer,
|
7
|
-
SystemProgram,
|
8
|
-
SYSVAR_RENT_PUBKEY,
|
9
|
-
Transaction,
|
10
|
-
TransactionInstruction,
|
4
|
+
PublicKey, Signer, Transaction,
|
5
|
+
TransactionInstruction
|
11
6
|
} from '@solana/web3.js'
|
12
7
|
|
13
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
14
8
|
import { Vault } from '../idl/vault'
|
9
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
15
10
|
|
16
11
|
export async function transferVault(
|
17
12
|
program: Program<Vault>,
|
@@ -1,22 +1,15 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Signer,
|
7
|
-
SystemProgram,
|
8
|
-
SYSVAR_RENT_PUBKEY,
|
9
|
-
Transaction,
|
10
|
-
TransactionInstruction,
|
3
|
+
PublicKey, Signer,
|
4
|
+
SystemProgram, Transaction,
|
5
|
+
TransactionInstruction
|
11
6
|
} from '@solana/web3.js'
|
12
7
|
import {
|
13
|
-
getVaultSystemStatePublicKey
|
14
|
-
getReferralAccountPublicKey,
|
8
|
+
getReferralAccountPublicKey, getVaultSystemStatePublicKey
|
15
9
|
} from '../Constants'
|
16
10
|
|
17
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
18
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
19
11
|
import { Vault } from '../idl/vault'
|
12
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
20
13
|
|
21
14
|
export interface ReferralAccountConfig {
|
22
15
|
setupCut?: BN
|
@@ -34,8 +27,8 @@ export async function updateReferralAccount(
|
|
34
27
|
referrer: PublicKey,
|
35
28
|
config: ReferralAccountConfig
|
36
29
|
): Promise<PublicKey> {
|
37
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
38
|
-
const referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
|
30
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
|
31
|
+
const referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
39
32
|
const transaction = new Transaction().add(
|
40
33
|
await updateReferralAccountInstruction(
|
41
34
|
program,
|
@@ -1,22 +1,15 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
Signer,
|
7
|
-
SystemProgram,
|
8
|
-
SYSVAR_RENT_PUBKEY,
|
9
|
-
Transaction,
|
10
|
-
TransactionInstruction,
|
3
|
+
PublicKey, Signer,
|
4
|
+
SystemProgram, Transaction,
|
5
|
+
TransactionInstruction
|
11
6
|
} from '@solana/web3.js'
|
12
7
|
import {
|
13
|
-
getVaultSystemStatePublicKey
|
14
|
-
getReferralStatePublicKey,
|
8
|
+
getReferralStatePublicKey, getVaultSystemStatePublicKey
|
15
9
|
} from '../Constants'
|
16
10
|
|
17
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
18
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
19
11
|
import { Vault } from '../idl/vault'
|
12
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
20
13
|
|
21
14
|
export interface ReferralStateConfig {
|
22
15
|
setupCut?: BN
|
@@ -43,8 +36,8 @@ export async function updateReferralState(
|
|
43
36
|
payer: Signer,
|
44
37
|
config: ReferralStateConfig
|
45
38
|
): Promise<PublicKey> {
|
46
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
47
|
-
const referralStatePublicKey = await getReferralStatePublicKey()
|
39
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
|
40
|
+
const referralStatePublicKey = await getReferralStatePublicKey(program.programId, )
|
48
41
|
const transaction = new Transaction().add(
|
49
42
|
await updateReferralStateInstruction(
|
50
43
|
program,
|
@@ -1,44 +1,30 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
sendAndConfirmTransaction,
|
6
|
-
Signer,
|
7
|
-
SystemProgram,
|
8
|
-
SYSVAR_RENT_PUBKEY,
|
9
|
-
Transaction,
|
10
|
-
TransactionInstruction,
|
3
|
+
PublicKey, Signer, Transaction,
|
4
|
+
TransactionInstruction
|
11
5
|
} from '@solana/web3.js'
|
12
6
|
import {
|
13
|
-
|
14
|
-
findVaultAddress,
|
15
|
-
getVaultTypeAccountPublicKey,
|
16
|
-
getUshMintPublicKey,
|
17
|
-
getVaultSystemStatePublicKey,
|
18
|
-
getPoolPublicKeyForMint,
|
19
|
-
getHedgeMintPublicKey,
|
7
|
+
getVaultSystemStatePublicKey
|
20
8
|
} from '../Constants'
|
21
9
|
|
22
|
-
import { v4 as uuidv4 } from 'uuid'
|
23
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
24
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
25
10
|
import { Vault } from '../idl/vault'
|
11
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
26
12
|
|
27
13
|
export interface VaultTypeConfig {
|
28
14
|
maxDebtExtended?: BN
|
29
15
|
minDebtPerVault?: BN
|
30
16
|
loanInitFee?: BN
|
31
17
|
interestRatePerSecond?: BN
|
32
|
-
|
18
|
+
|
33
19
|
emergencyModeThreshold?: BN
|
34
20
|
|
35
21
|
oracleChainlink?: PublicKey
|
36
22
|
oraclePyth?: PublicKey
|
37
23
|
oracleSwitchboard?: PublicKey
|
38
24
|
|
39
|
-
priorityPyth?: number
|
40
|
-
priorityChainlink?: number
|
41
|
-
prioritySwitchboard?: number
|
25
|
+
priorityPyth?: number
|
26
|
+
priorityChainlink?: number
|
27
|
+
prioritySwitchboard?: number
|
42
28
|
|
43
29
|
deprecated?: boolean
|
44
30
|
}
|
@@ -51,7 +37,7 @@ export async function updateVaultType(
|
|
51
37
|
oracleInfoAccount: PublicKey,
|
52
38
|
config: VaultTypeConfig
|
53
39
|
): Promise<PublicKey> {
|
54
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
40
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
55
41
|
const transaction = new Transaction().add(
|
56
42
|
await updateVaultTypeStatusInstruction(
|
57
43
|
program,
|
@@ -1,25 +1,21 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
2
|
+
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
4
|
Keypair,
|
5
|
-
PublicKey,
|
6
|
-
|
7
|
-
|
8
|
-
SystemProgram,
|
9
|
-
SYSVAR_RENT_PUBKEY,
|
10
|
-
Transaction,
|
11
|
-
TransactionInstruction,
|
5
|
+
PublicKey, Signer,
|
6
|
+
SystemProgram, Transaction,
|
7
|
+
TransactionInstruction
|
12
8
|
} from '@solana/web3.js'
|
13
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
14
9
|
import {
|
15
10
|
findAssociatedTokenAddress,
|
16
11
|
getHedgeMintPublicKey,
|
17
12
|
getPoolPublicKeyForMint,
|
18
13
|
getUshMintPublicKey,
|
19
|
-
getVaultSystemStatePublicKey
|
14
|
+
getVaultSystemStatePublicKey
|
20
15
|
} from '../Constants'
|
21
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
22
16
|
import { Vault } from '../idl/vault'
|
17
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
18
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
19
|
|
24
20
|
export async function withdrawStakingPool(
|
25
21
|
program: Program<Vault>,
|
@@ -51,16 +47,16 @@ export async function withdrawStakingPoolInstruction(
|
|
51
47
|
stakedTokenMintPublicKey: PublicKey,
|
52
48
|
overrideStartTime?: number
|
53
49
|
): Promise<TransactionInstruction> {
|
54
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
55
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
56
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
57
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey)
|
58
|
-
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey)
|
59
|
-
const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
|
60
|
-
const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
|
61
|
-
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
|
62
|
-
const payerAssociatedUshAccount = await findAssociatedTokenAddress(payerPublicKey, ushMintPublickey)
|
63
|
-
const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey)
|
50
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
|
51
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId, )
|
52
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId, )
|
53
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
|
54
|
+
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, stakedTokenMintPublicKey)
|
55
|
+
const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
|
56
|
+
const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, stakedTokenMintPublicKey)
|
57
|
+
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
|
58
|
+
const payerAssociatedUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
|
59
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey)
|
64
60
|
|
65
61
|
return await program.methods
|
66
62
|
.withdrawStakingPool(
|
@@ -1,26 +1,20 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
2
|
import { TokenInstructions } from '@project-serum/serum'
|
3
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
4
4
|
import {
|
5
5
|
Keypair,
|
6
|
-
PublicKey,
|
7
|
-
sendAndConfirmTransaction,
|
8
|
-
Signer,
|
6
|
+
PublicKey, Signer,
|
9
7
|
SystemProgram,
|
10
8
|
Transaction,
|
11
|
-
TransactionInstruction
|
9
|
+
TransactionInstruction
|
12
10
|
} from '@solana/web3.js'
|
13
11
|
import {
|
14
|
-
findAssociatedTokenAddress,
|
15
|
-
|
16
|
-
getUshMintPublicKey,
|
17
|
-
getVaultSystemStatePublicKey,
|
18
|
-
getPoolPublicKeyForMint,
|
19
|
-
getHedgeMintPublicKey,
|
12
|
+
findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
|
13
|
+
getVaultSystemStatePublicKey
|
20
14
|
} from '../Constants'
|
15
|
+
import { Vault } from '../idl/vault'
|
21
16
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
22
17
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
|
-
import { Vault } from '../idl/vault'
|
24
18
|
|
25
19
|
export async function withdrawVault(
|
26
20
|
program: Program<Vault>,
|
@@ -30,13 +24,13 @@ export async function withdrawVault(
|
|
30
24
|
withdrawAmount: number,
|
31
25
|
overrideTime?: number
|
32
26
|
): Promise<PublicKey> {
|
33
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
27
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId, )
|
34
28
|
|
35
29
|
// Prep the user to get USH back out at some point
|
36
30
|
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
37
31
|
|
38
32
|
const history = Keypair.generate()
|
39
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
33
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
|
40
34
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
41
35
|
const vaultAssociatedCollateralAccount = await getOrCreateAssociatedTokenAccount(
|
42
36
|
provider.connection,
|
@@ -61,8 +55,8 @@ export async function withdrawVault(
|
|
61
55
|
vaultTypeAccountInfo.collateralMint,
|
62
56
|
payer.publicKey
|
63
57
|
)
|
64
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
|
65
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
58
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, await getHedgeMintPublicKey(program.programId, ))
|
59
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId,
|
66
60
|
hedgeStakingPoolPublicKey,
|
67
61
|
ushMintPublickey
|
68
62
|
)
|