hedge-web3 0.2.24 → 0.2.25
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/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 +15 -15
- 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/utils/getLinkedListAccounts.js +2 -3
- 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 -26
- 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/utils/getLinkedListAccounts.ts +4 -7
@@ -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(
|
@@ -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
|
)
|