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
@@ -1,27 +1,21 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { TokenInstructions } from '@project-serum/serum'
|
3
|
+
import { WRAPPED_SOL_MINT } from '@project-serum/serum/lib/token-instructions'
|
3
4
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
4
5
|
import {
|
5
6
|
Keypair,
|
6
|
-
PublicKey,
|
7
|
-
sendAndConfirmTransaction,
|
8
|
-
Signer,
|
7
|
+
PublicKey, Signer,
|
9
8
|
SystemProgram,
|
10
9
|
Transaction,
|
11
|
-
TransactionInstruction
|
10
|
+
TransactionInstruction
|
12
11
|
} from '@solana/web3.js'
|
13
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
14
12
|
import {
|
15
|
-
findAssociatedTokenAddress,
|
16
|
-
|
17
|
-
getUshMintPublicKey,
|
18
|
-
getVaultSystemStatePublicKey,
|
19
|
-
getPoolPublicKeyForMint,
|
20
|
-
getHedgeMintPublicKey,
|
13
|
+
findAssociatedTokenAddress, getHedgeMintPublicKey, getPoolPublicKeyForMint, getUshMintPublicKey,
|
14
|
+
getVaultSystemStatePublicKey
|
21
15
|
} from '../Constants'
|
22
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
16
|
import { Vault } from '../idl/vault'
|
24
|
-
import {
|
17
|
+
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
18
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
25
19
|
|
26
20
|
export async function depositVault(
|
27
21
|
program: Program<Vault>,
|
@@ -31,7 +25,7 @@ export async function depositVault(
|
|
31
25
|
depositAmount: number,
|
32
26
|
overrideTime?: number
|
33
27
|
): Promise<PublicKey> {
|
34
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
28
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
35
29
|
|
36
30
|
// Prep the user to get USH back out at some point
|
37
31
|
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
@@ -46,19 +40,28 @@ export async function depositVault(
|
|
46
40
|
true
|
47
41
|
)
|
48
42
|
|
49
|
-
const payerTokenAccount = await findAssociatedTokenAddress(
|
43
|
+
const payerTokenAccount = await findAssociatedTokenAddress(
|
44
|
+
program.programId,
|
45
|
+
payer.publicKey,
|
46
|
+
vaultTypeAccountInfo.collateralMint
|
47
|
+
)
|
50
48
|
const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(
|
49
|
+
program.programId,
|
51
50
|
vaultPublicKey,
|
52
51
|
vaultTypeAccountInfo.collateralMint
|
53
52
|
)
|
54
53
|
|
55
54
|
const history = Keypair.generate()
|
56
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
55
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
57
56
|
|
58
57
|
const wrappedSolAccount = Keypair.generate()
|
59
58
|
|
60
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
59
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
60
|
+
program.programId,
|
61
|
+
await getHedgeMintPublicKey(program.programId)
|
62
|
+
)
|
61
63
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
64
|
+
program.programId,
|
62
65
|
hedgeStakingPoolPublicKey,
|
63
66
|
ushMintPublickey
|
64
67
|
)
|
@@ -99,7 +102,9 @@ export async function depositVault(
|
|
99
102
|
program,
|
100
103
|
vaultSystemStatePublicKey,
|
101
104
|
payer.publicKey,
|
102
|
-
vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()
|
105
|
+
vaultTypeAccountInfo.collateralMint.toString() === WRAPPED_SOL_MINT.toString()
|
106
|
+
? wrappedSolAccount.publicKey
|
107
|
+
: payerTokenAccount,
|
103
108
|
vaultPublicKey,
|
104
109
|
vaultAssociatedCollateralAccountPublicKey,
|
105
110
|
history.publicKey,
|
@@ -2,25 +2,23 @@ import { Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, 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
|
SYSVAR_RENT_PUBKEY,
|
10
8
|
Transaction,
|
11
|
-
TransactionInstruction
|
9
|
+
TransactionInstruction
|
12
10
|
} from '@solana/web3.js'
|
13
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
14
11
|
import {
|
15
12
|
findAssociatedTokenAddress,
|
16
13
|
getHedgeMintPublicKey,
|
17
14
|
getLiquidationPoolStatePublicKey,
|
18
15
|
getLiquidationPoolUshAccountPublicKey,
|
19
16
|
getUshMintPublicKey,
|
20
|
-
getVaultSystemStatePublicKey
|
17
|
+
getVaultSystemStatePublicKey
|
21
18
|
} from '../Constants'
|
22
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
19
|
import { Vault } from '../idl/vault'
|
20
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
21
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
24
22
|
|
25
23
|
export async function initHedgeFoundation(program: Program<Vault>, provider: Provider, payer: Signer): Promise<PublicKey> {
|
26
24
|
const poolEra = Keypair.generate()
|
@@ -37,13 +35,17 @@ export async function initHedgeFoundationInstruction(
|
|
37
35
|
poolEraPublicKey: PublicKey,
|
38
36
|
payerPublicKey: PublicKey
|
39
37
|
): Promise<TransactionInstruction> {
|
40
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
41
|
-
const poolStatePublickey = await getLiquidationPoolStatePublicKey()
|
42
|
-
const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey()
|
43
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
44
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
45
|
-
const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
|
46
|
-
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
38
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
39
|
+
const poolStatePublickey = await getLiquidationPoolStatePublicKey(program.programId)
|
40
|
+
const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey(program.programId)
|
41
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
42
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
43
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
|
44
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
45
|
+
program.programId,
|
46
|
+
vaultSystemStatePublicKey,
|
47
|
+
hedgeMintPublickey
|
48
|
+
)
|
47
49
|
|
48
50
|
return await program.methods
|
49
51
|
.initHedgeFoundation()
|
@@ -2,23 +2,17 @@ import { Program, Provider } from '@project-serum/anchor'
|
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, 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
|
SYSVAR_RENT_PUBKEY,
|
10
8
|
Transaction,
|
11
|
-
TransactionInstruction
|
9
|
+
TransactionInstruction
|
12
10
|
} from '@solana/web3.js'
|
13
|
-
import { parseAnchorErrors } from '../utils/Errors'
|
14
11
|
import {
|
15
12
|
findAssociatedTokenAddress,
|
16
|
-
getHedgeMintPublicKey,
|
17
|
-
getLiquidationPoolStatePublicKey,
|
18
|
-
getLiquidationPoolUshAccountPublicKey,
|
19
|
-
getUshMintPublicKey,
|
20
|
-
getVaultSystemStatePublicKey,
|
13
|
+
getHedgeMintPublicKey, getVaultSystemStatePublicKey
|
21
14
|
} from '../Constants'
|
15
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
22
16
|
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
23
17
|
|
24
18
|
export async function initHedgeFoundationTokens(program: Program, provider: Provider, payer: Signer): Promise<PublicKey> {
|
@@ -33,10 +27,14 @@ export async function initHedgeFoundationTokensInstruction(
|
|
33
27
|
program: Program,
|
34
28
|
payerPublicKey: PublicKey
|
35
29
|
): Promise<TransactionInstruction> {
|
36
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
37
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
38
|
-
const founderHedgeTokenAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey)
|
39
|
-
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
30
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
31
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
32
|
+
const founderHedgeTokenAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, hedgeMintPublickey)
|
33
|
+
const communityHedgeTokenAccount = await findAssociatedTokenAddress(
|
34
|
+
program.programId,
|
35
|
+
vaultSystemStatePublicKey,
|
36
|
+
hedgeMintPublickey
|
37
|
+
)
|
40
38
|
|
41
39
|
return await program.methods
|
42
40
|
.initHedgeFoundationTokens()
|
@@ -1,28 +1,23 @@
|
|
1
|
-
import { BN, Program, Provider
|
2
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID,
|
1
|
+
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
import {
|
4
|
-
Connection,
|
5
4
|
Keypair,
|
6
|
-
PublicKey,
|
7
|
-
sendAndConfirmTransaction,
|
8
|
-
Signer,
|
5
|
+
PublicKey, Signer,
|
9
6
|
SystemProgram,
|
10
7
|
SYSVAR_RENT_PUBKEY,
|
11
8
|
Transaction,
|
12
|
-
TransactionInstruction
|
9
|
+
TransactionInstruction
|
13
10
|
} from '@solana/web3.js'
|
14
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
15
11
|
import {
|
16
12
|
getHedgeMintPublicKey,
|
17
13
|
getLiquidationPoolStatePublicKey,
|
18
14
|
getLiquidationPoolUshAccountPublicKey,
|
19
|
-
getPoolPublicKeyForMint,
|
20
|
-
|
21
|
-
getUshMintPublicKey,
|
22
|
-
getVaultSystemStatePublicKey,
|
15
|
+
getPoolPublicKeyForMint, getUshMintPublicKey,
|
16
|
+
getVaultSystemStatePublicKey
|
23
17
|
} from '../Constants'
|
24
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
25
18
|
import { Vault } from '../idl/vault'
|
19
|
+
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
20
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
26
21
|
|
27
22
|
export async function liquidateVault(
|
28
23
|
program: Program<Vault>,
|
@@ -36,10 +31,10 @@ export async function liquidateVault(
|
|
36
31
|
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultAccount.vaultType)
|
37
32
|
const collateralMint = vaultTypeAccountInfo.collateralMint
|
38
33
|
|
39
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
40
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
41
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
42
|
-
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
|
34
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
35
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
36
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
37
|
+
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey(program.programId)
|
43
38
|
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
44
39
|
|
45
40
|
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
@@ -152,9 +147,9 @@ export async function liquidateVaultInstruction(
|
|
152
147
|
vaultTypeAccount: PublicKey,
|
153
148
|
overrideTime?: number
|
154
149
|
): Promise<TransactionInstruction> {
|
155
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
156
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
157
|
-
const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
|
150
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
151
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
152
|
+
const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey(program.programId)
|
158
153
|
|
159
154
|
return await program.methods
|
160
155
|
.liquidateVault(
|
@@ -2,30 +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,
|
20
|
-
HEDGE_PROGRAM_PUBLICKEY,
|
21
|
-
getReferralStatePublicKey,
|
22
|
-
getReferralAccountPublicKey,
|
23
|
-
getUserReferralAccountPublicKey,
|
13
|
+
getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey, getUserReferralAccountPublicKey, getUshMintPublicKey,
|
14
|
+
getVaultSystemStatePublicKey
|
24
15
|
} from '../Constants'
|
25
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
26
16
|
import { Vault } from '../idl/vault'
|
27
|
-
import {
|
28
|
-
import
|
17
|
+
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
18
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
29
19
|
|
30
20
|
export async function loanVault(
|
31
21
|
program: Program<Vault>,
|
@@ -34,9 +24,9 @@ export async function loanVault(
|
|
34
24
|
vaultPublicKey: PublicKey,
|
35
25
|
loanAmount: number,
|
36
26
|
overrideTime?: number,
|
37
|
-
referrer?: PublicKey
|
27
|
+
referrer?: PublicKey
|
38
28
|
): Promise<PublicKey> {
|
39
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
29
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
40
30
|
|
41
31
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
42
32
|
provider.connection,
|
@@ -74,11 +64,11 @@ export async function loanVault(
|
|
74
64
|
)
|
75
65
|
|
76
66
|
let referralAccountPublicKey = null
|
77
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
67
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
78
68
|
if (typeof referrer === 'undefined') {
|
79
|
-
referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
|
69
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
|
80
70
|
} else {
|
81
|
-
referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
|
71
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
82
72
|
}
|
83
73
|
|
84
74
|
const history = Keypair.generate()
|
@@ -120,16 +110,17 @@ export async function loanVaultInstruction(
|
|
120
110
|
referralAccountPublicKey: PublicKey,
|
121
111
|
overrideTime?: number
|
122
112
|
): Promise<TransactionInstruction> {
|
123
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
124
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
125
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
126
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
113
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
114
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
115
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
116
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
127
117
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
118
|
+
program.programId,
|
128
119
|
hedgeStakingPoolPublicKey,
|
129
120
|
ushMintPublickey
|
130
121
|
)
|
131
|
-
const referralStatePublicKey = await getReferralStatePublicKey()
|
132
|
-
const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(payerPublicKey)
|
122
|
+
const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
|
123
|
+
const userReferralAccountPublicKey = await getUserReferralAccountPublicKey(program.programId, payerPublicKey)
|
133
124
|
|
134
125
|
return await program.methods
|
135
126
|
.loanVault(
|
@@ -1,27 +1,19 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import { getOrCreateAssociatedTokenAccount
|
2
|
+
import { getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
3
3
|
import {
|
4
|
-
|
5
|
-
PublicKey,
|
6
|
-
sendAndConfirmTransaction,
|
7
|
-
Signer,
|
4
|
+
PublicKey, Signer,
|
8
5
|
SystemProgram,
|
9
6
|
Transaction,
|
10
|
-
TransactionInstruction
|
7
|
+
TransactionInstruction
|
11
8
|
} from '@solana/web3.js'
|
12
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
13
9
|
import {
|
14
|
-
findAssociatedTokenAddress,
|
15
10
|
getHedgeMintPublicKey,
|
16
11
|
getPoolPublicKeyForMint,
|
17
12
|
getUshMintPublicKey,
|
18
|
-
getVaultSystemStatePublicKey
|
19
|
-
HEDGE_PROGRAM_PUBLICKEY,
|
13
|
+
getVaultSystemStatePublicKey
|
20
14
|
} from '../Constants'
|
21
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
22
15
|
import { Vault } from '../idl/vault'
|
23
|
-
import
|
24
|
-
import { VaultAccount } from '../state/VaultAccount'
|
16
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
25
17
|
|
26
18
|
export enum psmStatus {
|
27
19
|
PsmEnabled,
|
@@ -41,7 +33,7 @@ export async function psmEditAccount(
|
|
41
33
|
minSwap: number,
|
42
34
|
overrideTime?: number
|
43
35
|
): Promise<PublicKey> {
|
44
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
36
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId, )
|
45
37
|
|
46
38
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
47
39
|
provider.connection,
|
@@ -61,7 +53,7 @@ export async function psmEditAccount(
|
|
61
53
|
const enc = new TextEncoder()
|
62
54
|
const [psmAccount] = await PublicKey.findProgramAddress(
|
63
55
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
64
|
-
|
56
|
+
program.programId
|
65
57
|
)
|
66
58
|
|
67
59
|
const psmAccountAta = await getOrCreateAssociatedTokenAccount(
|
@@ -100,9 +92,9 @@ export async function psmEditAccountInstruction(
|
|
100
92
|
minSwap: BN,
|
101
93
|
overrideTime?: number
|
102
94
|
): Promise<TransactionInstruction> {
|
103
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
104
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
105
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
95
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId, )
|
96
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId, )
|
97
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
106
98
|
|
107
99
|
|
108
100
|
return await program.methods
|
@@ -1,15 +1,11 @@
|
|
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
|
-
|
5
|
-
PublicKey,
|
6
|
-
sendAndConfirmTransaction,
|
7
|
-
Signer,
|
4
|
+
PublicKey, Signer,
|
8
5
|
SystemProgram,
|
9
6
|
Transaction,
|
10
|
-
TransactionInstruction
|
7
|
+
TransactionInstruction
|
11
8
|
} from '@solana/web3.js'
|
12
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
13
9
|
import {
|
14
10
|
findAssociatedTokenAddress,
|
15
11
|
getHedgeMintPublicKey,
|
@@ -17,13 +13,10 @@ import {
|
|
17
13
|
getReferralAccountPublicKey,
|
18
14
|
getReferralStatePublicKey,
|
19
15
|
getUshMintPublicKey,
|
20
|
-
getVaultSystemStatePublicKey
|
21
|
-
HEDGE_PROGRAM_PUBLICKEY,
|
16
|
+
getVaultSystemStatePublicKey
|
22
17
|
} from '../Constants'
|
23
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
24
18
|
import { Vault } from '../idl/vault'
|
25
|
-
import
|
26
|
-
import { VaultAccount } from '../state/VaultAccount'
|
19
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
27
20
|
|
28
21
|
export async function psmMintUsh(
|
29
22
|
program: Program<Vault>,
|
@@ -34,7 +27,7 @@ export async function psmMintUsh(
|
|
34
27
|
overrideTime?: number,
|
35
28
|
referrer?: PublicKey
|
36
29
|
): Promise<PublicKey> {
|
37
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
30
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
38
31
|
|
39
32
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
40
33
|
provider.connection,
|
@@ -50,30 +43,23 @@ export async function psmMintUsh(
|
|
50
43
|
payer.publicKey
|
51
44
|
)
|
52
45
|
|
53
|
-
|
54
46
|
const enc = new TextEncoder()
|
55
47
|
const [psmAccount] = await PublicKey.findProgramAddress(
|
56
48
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
57
|
-
|
49
|
+
program.programId
|
58
50
|
)
|
59
51
|
|
60
|
-
const psmAccountAta = await getOrCreateAssociatedTokenAccount(
|
61
|
-
provider.connection,
|
62
|
-
payer,
|
63
|
-
collateralMint,
|
64
|
-
psmAccount,
|
65
|
-
true
|
66
|
-
)
|
52
|
+
const psmAccountAta = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, psmAccount, true)
|
67
53
|
|
68
54
|
let referralAccountPublicKey
|
69
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
55
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
70
56
|
if (!referrer) {
|
71
|
-
referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
|
57
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
|
72
58
|
} else {
|
73
|
-
referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
|
59
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
74
60
|
}
|
75
61
|
|
76
|
-
const referralStatePublicKey = await getReferralStatePublicKey()
|
62
|
+
const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
|
77
63
|
|
78
64
|
const transaction = new Transaction().add(
|
79
65
|
await psmMintUshInstruction(
|
@@ -101,27 +87,19 @@ export async function psmMintUshInstruction(
|
|
101
87
|
referralAccountPublicKey: PublicKey,
|
102
88
|
overrideTime?: number
|
103
89
|
): Promise<TransactionInstruction> {
|
104
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
105
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
106
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
107
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
90
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
91
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
92
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
93
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
108
94
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
95
|
+
program.programId,
|
109
96
|
hedgeStakingPoolPublicKey,
|
110
97
|
ushMintPublickey
|
111
98
|
)
|
112
|
-
const psmAccountAta = await findAssociatedTokenAddress(
|
113
|
-
|
114
|
-
collateralMint
|
115
|
-
)
|
116
|
-
const ownerCollateralAccount = await findAssociatedTokenAddress(
|
117
|
-
payerPublicKey,
|
118
|
-
collateralMint
|
119
|
-
)
|
99
|
+
const psmAccountAta = await findAssociatedTokenAddress(program.programId, psmAccount, collateralMint)
|
100
|
+
const ownerCollateralAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, collateralMint)
|
120
101
|
|
121
|
-
const ownerUshAccount = await findAssociatedTokenAddress(
|
122
|
-
payerPublicKey,
|
123
|
-
ushMintPublickey
|
124
|
-
)
|
102
|
+
const ownerUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
|
125
103
|
|
126
104
|
return await program.methods
|
127
105
|
.psmMintUsh(
|
@@ -1,29 +1,20 @@
|
|
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
|
-
|
5
|
-
PublicKey,
|
6
|
-
sendAndConfirmTransaction,
|
7
|
-
Signer,
|
4
|
+
PublicKey, Signer,
|
8
5
|
SystemProgram,
|
9
6
|
Transaction,
|
10
|
-
TransactionInstruction
|
7
|
+
TransactionInstruction
|
11
8
|
} from '@solana/web3.js'
|
12
|
-
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
13
9
|
import {
|
14
10
|
findAssociatedTokenAddress,
|
15
11
|
getHedgeMintPublicKey,
|
16
|
-
getPoolPublicKeyForMint,
|
17
|
-
getUshMintPublicKey,
|
18
|
-
getVaultSystemStatePublicKey
|
19
|
-
HEDGE_PROGRAM_PUBLICKEY,
|
20
|
-
getReferralAccountPublicKey,
|
21
|
-
getReferralStatePublicKey
|
12
|
+
getPoolPublicKeyForMint, getReferralAccountPublicKey,
|
13
|
+
getReferralStatePublicKey, getUshMintPublicKey,
|
14
|
+
getVaultSystemStatePublicKey
|
22
15
|
} from '../Constants'
|
23
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
24
16
|
import { Vault } from '../idl/vault'
|
25
|
-
import
|
26
|
-
import { VaultAccount } from '../state/VaultAccount'
|
17
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
27
18
|
|
28
19
|
export async function psmRedeemUsh(
|
29
20
|
program: Program<Vault>,
|
@@ -34,7 +25,7 @@ export async function psmRedeemUsh(
|
|
34
25
|
overrideTime?: number,
|
35
26
|
referrer?: PublicKey
|
36
27
|
): Promise<PublicKey> {
|
37
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
28
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
38
29
|
|
39
30
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
40
31
|
provider.connection,
|
@@ -50,30 +41,23 @@ export async function psmRedeemUsh(
|
|
50
41
|
payer.publicKey
|
51
42
|
)
|
52
43
|
|
53
|
-
|
54
44
|
const enc = new TextEncoder()
|
55
45
|
const [psmAccount] = await PublicKey.findProgramAddress(
|
56
46
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
57
|
-
|
47
|
+
program.programId
|
58
48
|
)
|
59
49
|
|
60
|
-
const psmAccountAta = await getOrCreateAssociatedTokenAccount(
|
61
|
-
provider.connection,
|
62
|
-
payer,
|
63
|
-
collateralMint,
|
64
|
-
psmAccount,
|
65
|
-
true
|
66
|
-
)
|
50
|
+
const psmAccountAta = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, psmAccount, true)
|
67
51
|
|
68
52
|
let referralAccountPublicKey
|
69
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
53
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
70
54
|
if (!referrer) {
|
71
|
-
referralAccountPublicKey = await getReferralAccountPublicKey(vaultSystemStatePublicKey)
|
55
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
|
72
56
|
} else {
|
73
|
-
referralAccountPublicKey = await getReferralAccountPublicKey(referrer)
|
57
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
74
58
|
}
|
75
59
|
|
76
|
-
const referralStatePublicKey = await getReferralStatePublicKey()
|
60
|
+
const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
|
77
61
|
|
78
62
|
const transaction = new Transaction().add(
|
79
63
|
await psmRedeemUshInstruction(
|
@@ -101,27 +85,19 @@ export async function psmRedeemUshInstruction(
|
|
101
85
|
referralAccountPublicKey: PublicKey,
|
102
86
|
overrideTime?: number
|
103
87
|
): Promise<TransactionInstruction> {
|
104
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
105
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
106
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
107
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
88
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
89
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
90
|
+
const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
|
91
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublickey)
|
108
92
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
93
|
+
program.programId,
|
109
94
|
hedgeStakingPoolPublicKey,
|
110
95
|
ushMintPublickey
|
111
96
|
)
|
112
|
-
const psmAccountAta = await findAssociatedTokenAddress(
|
113
|
-
|
114
|
-
collateralMint
|
115
|
-
)
|
116
|
-
const ownerCollateralAccount = await findAssociatedTokenAddress(
|
117
|
-
payerPublicKey,
|
118
|
-
collateralMint
|
119
|
-
)
|
97
|
+
const psmAccountAta = await findAssociatedTokenAddress(program.programId, psmAccount, collateralMint)
|
98
|
+
const ownerCollateralAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, collateralMint)
|
120
99
|
|
121
|
-
const ownerUshAccount = await findAssociatedTokenAddress(
|
122
|
-
payerPublicKey,
|
123
|
-
ushMintPublickey
|
124
|
-
)
|
100
|
+
const ownerUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
|
125
101
|
|
126
102
|
return await program.methods
|
127
103
|
.psmRedeemUsh(
|