hedge-web3 0.2.21 → 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 +25 -12
- package/declarations/idl/pyth.d.ts +44 -24
- package/declarations/idl/switchboard.d.ts +47 -0
- package/declarations/idl/vault.d.ts +905 -155
- package/declarations/index.d.ts +26 -20
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +2 -2
- package/declarations/instructions/createReferralAccount.d.ts +17 -0
- package/declarations/instructions/createUserReferralAccount.d.ts +5 -0
- package/declarations/instructions/depositLiquidationPool.d.ts +2 -2
- package/declarations/instructions/loanVault.d.ts +2 -2
- package/declarations/instructions/psmEditAccount.d.ts +12 -0
- package/declarations/instructions/psmMintUsh.d.ts +2 -2
- package/declarations/instructions/psmRedeemUsh.d.ts +2 -2
- package/declarations/instructions/referralClaimFees.d.ts +16 -0
- package/declarations/instructions/transferVault.d.ts +3 -17
- package/declarations/instructions/updateReferralAccount.d.ts +13 -0
- package/declarations/instructions/updateReferralState.d.ts +20 -0
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
- package/lib/Constants.js +57 -28
- package/lib/idl/pyth.js +44 -24
- package/lib/idl/switchboard.js +49 -0
- package/lib/idl/vault.js +898 -148
- package/lib/index.js +26 -20
- 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 +25 -12
- package/lib/instructions/createReferralAccount.js +80 -0
- package/lib/instructions/createStakingPool.js +7 -7
- package/lib/instructions/createUserReferralAccount.js +61 -0
- package/lib/instructions/createVault.js +15 -15
- package/lib/instructions/depositLiquidationPool.js +21 -10
- 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 +23 -10
- package/lib/instructions/psmEditAccount.js +60 -0
- package/lib/instructions/psmMintUsh.js +24 -13
- package/lib/instructions/psmRedeemUsh.js +24 -13
- package/lib/instructions/redeemVault.js +7 -7
- package/lib/instructions/referralClaimFees.js +84 -0
- package/lib/instructions/refreshOraclePrice.js +3 -3
- package/lib/instructions/repayVault.js +9 -9
- package/lib/instructions/setHalted.js +1 -1
- package/lib/instructions/transferVault.js +10 -24
- package/lib/instructions/updateReferralAccount.js +50 -0
- package/lib/instructions/updateReferralState.js +57 -0
- 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 +3 -1
- package/lib/utils/getLinkedListAccounts.js +2 -3
- package/package.json +1 -1
- package/src/Constants.ts +64 -63
- package/src/idl/pyth.ts +88 -48
- package/src/idl/switchboard.ts +93 -0
- package/src/idl/vault.ts +1851 -351
- package/src/index.ts +28 -24
- 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 +36 -18
- package/src/instructions/createReferralAccount.ts +115 -0
- package/src/instructions/createStakingPool.ts +11 -13
- package/src/instructions/createUserReferralAccount.ts +75 -0
- package/src/instructions/createVault.ts +44 -26
- package/src/instructions/depositLiquidationPool.ts +34 -21
- 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 +29 -19
- package/src/instructions/{psmEditAccount.rs → psmEditAccount.ts} +10 -18
- package/src/instructions/psmMintUsh.ts +35 -38
- package/src/instructions/psmRedeemUsh.ts +35 -40
- package/src/instructions/redeemVault.ts +12 -15
- package/src/instructions/referralClaimFees.ts +145 -0
- 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 +57 -0
- package/src/instructions/updateReferralAccount.ts +70 -0
- package/src/instructions/updateReferralState.ts +86 -0
- 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 +9 -10
- package/src/utils/getLinkedListAccounts.ts +4 -7
|
@@ -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,27 +1,22 @@
|
|
|
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
12
|
getPoolPublicKeyForMint,
|
|
13
|
+
getReferralAccountPublicKey,
|
|
14
|
+
getReferralStatePublicKey,
|
|
17
15
|
getUshMintPublicKey,
|
|
18
|
-
getVaultSystemStatePublicKey
|
|
19
|
-
HEDGE_PROGRAM_PUBLICKEY,
|
|
16
|
+
getVaultSystemStatePublicKey
|
|
20
17
|
} from '../Constants'
|
|
21
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
|
22
18
|
import { Vault } from '../idl/vault'
|
|
23
|
-
import
|
|
24
|
-
import { VaultAccount } from '../state/VaultAccount'
|
|
19
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
|
25
20
|
|
|
26
21
|
export async function psmMintUsh(
|
|
27
22
|
program: Program<Vault>,
|
|
@@ -29,9 +24,10 @@ export async function psmMintUsh(
|
|
|
29
24
|
payer: Signer,
|
|
30
25
|
collateralMint: PublicKey,
|
|
31
26
|
collateralAmount: number,
|
|
32
|
-
overrideTime?: number
|
|
27
|
+
overrideTime?: number,
|
|
28
|
+
referrer?: PublicKey
|
|
33
29
|
): Promise<PublicKey> {
|
|
34
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
|
30
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
|
35
31
|
|
|
36
32
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
|
37
33
|
provider.connection,
|
|
@@ -47,20 +43,23 @@ export async function psmMintUsh(
|
|
|
47
43
|
payer.publicKey
|
|
48
44
|
)
|
|
49
45
|
|
|
50
|
-
|
|
51
46
|
const enc = new TextEncoder()
|
|
52
47
|
const [psmAccount] = await PublicKey.findProgramAddress(
|
|
53
48
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
|
54
|
-
|
|
49
|
+
program.programId
|
|
55
50
|
)
|
|
56
51
|
|
|
57
|
-
const psmAccountAta = await getOrCreateAssociatedTokenAccount(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
52
|
+
const psmAccountAta = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, psmAccount, true)
|
|
53
|
+
|
|
54
|
+
let referralAccountPublicKey
|
|
55
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
|
56
|
+
if (!referrer) {
|
|
57
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
|
|
58
|
+
} else {
|
|
59
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
|
|
64
63
|
|
|
65
64
|
const transaction = new Transaction().add(
|
|
66
65
|
await psmMintUshInstruction(
|
|
@@ -69,6 +68,8 @@ export async function psmMintUsh(
|
|
|
69
68
|
psmAccount,
|
|
70
69
|
collateralMint,
|
|
71
70
|
new BN(collateralAmount),
|
|
71
|
+
referralStatePublicKey,
|
|
72
|
+
referralAccountPublicKey,
|
|
72
73
|
overrideTime
|
|
73
74
|
)
|
|
74
75
|
)
|
|
@@ -82,29 +83,23 @@ export async function psmMintUshInstruction(
|
|
|
82
83
|
psmAccount: PublicKey,
|
|
83
84
|
collateralMint: PublicKey,
|
|
84
85
|
collateralAmount: BN,
|
|
86
|
+
referralStatePublicKey: PublicKey,
|
|
87
|
+
referralAccountPublicKey: PublicKey,
|
|
85
88
|
overrideTime?: number
|
|
86
89
|
): Promise<TransactionInstruction> {
|
|
87
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
|
88
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
|
89
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
|
90
|
-
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)
|
|
91
94
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
|
95
|
+
program.programId,
|
|
92
96
|
hedgeStakingPoolPublicKey,
|
|
93
97
|
ushMintPublickey
|
|
94
98
|
)
|
|
95
|
-
const psmAccountAta = await findAssociatedTokenAddress(
|
|
96
|
-
|
|
97
|
-
collateralMint
|
|
98
|
-
)
|
|
99
|
-
const ownerCollateralAccount = await findAssociatedTokenAddress(
|
|
100
|
-
payerPublicKey,
|
|
101
|
-
collateralMint
|
|
102
|
-
)
|
|
99
|
+
const psmAccountAta = await findAssociatedTokenAddress(program.programId, psmAccount, collateralMint)
|
|
100
|
+
const ownerCollateralAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, collateralMint)
|
|
103
101
|
|
|
104
|
-
const ownerUshAccount = await findAssociatedTokenAddress(
|
|
105
|
-
payerPublicKey,
|
|
106
|
-
ushMintPublickey
|
|
107
|
-
)
|
|
102
|
+
const ownerUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
|
|
108
103
|
|
|
109
104
|
return await program.methods
|
|
110
105
|
.psmMintUsh(
|
|
@@ -122,6 +117,8 @@ export async function psmMintUshInstruction(
|
|
|
122
117
|
ownerCollateralAccount: ownerCollateralAccount,
|
|
123
118
|
collateralMint: collateralMint,
|
|
124
119
|
ushMint: ushMintPublickey,
|
|
120
|
+
referralState: referralStatePublicKey,
|
|
121
|
+
referralAccount: referralAccountPublicKey,
|
|
125
122
|
systemProgram: SystemProgram.programId,
|
|
126
123
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
127
124
|
})
|
|
@@ -1,27 +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,
|
|
12
|
+
getPoolPublicKeyForMint, getReferralAccountPublicKey,
|
|
13
|
+
getReferralStatePublicKey, getUshMintPublicKey,
|
|
14
|
+
getVaultSystemStatePublicKey
|
|
20
15
|
} from '../Constants'
|
|
21
|
-
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
|
22
16
|
import { Vault } from '../idl/vault'
|
|
23
|
-
import
|
|
24
|
-
import { VaultAccount } from '../state/VaultAccount'
|
|
17
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
|
25
18
|
|
|
26
19
|
export async function psmRedeemUsh(
|
|
27
20
|
program: Program<Vault>,
|
|
@@ -29,9 +22,10 @@ export async function psmRedeemUsh(
|
|
|
29
22
|
payer: Signer,
|
|
30
23
|
collateralMint: PublicKey,
|
|
31
24
|
ushAmount: number,
|
|
32
|
-
overrideTime?: number
|
|
25
|
+
overrideTime?: number,
|
|
26
|
+
referrer?: PublicKey
|
|
33
27
|
): Promise<PublicKey> {
|
|
34
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
|
28
|
+
const ushMintPublickey = await getUshMintPublicKey(program.programId)
|
|
35
29
|
|
|
36
30
|
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
|
37
31
|
provider.connection,
|
|
@@ -47,20 +41,23 @@ export async function psmRedeemUsh(
|
|
|
47
41
|
payer.publicKey
|
|
48
42
|
)
|
|
49
43
|
|
|
50
|
-
|
|
51
44
|
const enc = new TextEncoder()
|
|
52
45
|
const [psmAccount] = await PublicKey.findProgramAddress(
|
|
53
46
|
[enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')],
|
|
54
|
-
|
|
47
|
+
program.programId
|
|
55
48
|
)
|
|
56
49
|
|
|
57
|
-
const psmAccountAta = await getOrCreateAssociatedTokenAccount(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const psmAccountAta = await getOrCreateAssociatedTokenAccount(provider.connection, payer, collateralMint, psmAccount, true)
|
|
51
|
+
|
|
52
|
+
let referralAccountPublicKey
|
|
53
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
|
54
|
+
if (!referrer) {
|
|
55
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, vaultSystemStatePublicKey)
|
|
56
|
+
} else {
|
|
57
|
+
referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const referralStatePublicKey = await getReferralStatePublicKey(program.programId)
|
|
64
61
|
|
|
65
62
|
const transaction = new Transaction().add(
|
|
66
63
|
await psmRedeemUshInstruction(
|
|
@@ -69,6 +66,8 @@ export async function psmRedeemUsh(
|
|
|
69
66
|
psmAccount,
|
|
70
67
|
collateralMint,
|
|
71
68
|
new BN(ushAmount),
|
|
69
|
+
referralStatePublicKey,
|
|
70
|
+
referralAccountPublicKey,
|
|
72
71
|
overrideTime
|
|
73
72
|
)
|
|
74
73
|
)
|
|
@@ -82,29 +81,23 @@ export async function psmRedeemUshInstruction(
|
|
|
82
81
|
psmAccount: PublicKey,
|
|
83
82
|
collateralMint: PublicKey,
|
|
84
83
|
ushAmount: BN,
|
|
84
|
+
referralStatePublicKey: PublicKey,
|
|
85
|
+
referralAccountPublicKey: PublicKey,
|
|
85
86
|
overrideTime?: number
|
|
86
87
|
): Promise<TransactionInstruction> {
|
|
87
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
|
88
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
|
89
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
|
90
|
-
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)
|
|
91
92
|
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
|
93
|
+
program.programId,
|
|
92
94
|
hedgeStakingPoolPublicKey,
|
|
93
95
|
ushMintPublickey
|
|
94
96
|
)
|
|
95
|
-
const psmAccountAta = await findAssociatedTokenAddress(
|
|
96
|
-
|
|
97
|
-
collateralMint
|
|
98
|
-
)
|
|
99
|
-
const ownerCollateralAccount = await findAssociatedTokenAddress(
|
|
100
|
-
payerPublicKey,
|
|
101
|
-
collateralMint
|
|
102
|
-
)
|
|
97
|
+
const psmAccountAta = await findAssociatedTokenAddress(program.programId, psmAccount, collateralMint)
|
|
98
|
+
const ownerCollateralAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, collateralMint)
|
|
103
99
|
|
|
104
|
-
const ownerUshAccount = await findAssociatedTokenAddress(
|
|
105
|
-
payerPublicKey,
|
|
106
|
-
ushMintPublickey
|
|
107
|
-
)
|
|
100
|
+
const ownerUshAccount = await findAssociatedTokenAddress(program.programId, payerPublicKey, ushMintPublickey)
|
|
108
101
|
|
|
109
102
|
return await program.methods
|
|
110
103
|
.psmRedeemUsh(
|
|
@@ -122,6 +115,8 @@ export async function psmRedeemUshInstruction(
|
|
|
122
115
|
ownerCollateralAccount: ownerCollateralAccount,
|
|
123
116
|
collateralMint: collateralMint,
|
|
124
117
|
ushMint: ushMintPublickey,
|
|
118
|
+
referralState: referralStatePublicKey,
|
|
119
|
+
referralAccount: referralAccountPublicKey,
|
|
125
120
|
systemProgram: SystemProgram.programId,
|
|
126
121
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
127
122
|
})
|
|
@@ -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
|
)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Program, Provider } from '@project-serum/anchor'
|
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
|
3
|
+
import {
|
|
4
|
+
PublicKey, Signer,
|
|
5
|
+
SystemProgram,
|
|
6
|
+
SYSVAR_RENT_PUBKEY,
|
|
7
|
+
Transaction,
|
|
8
|
+
TransactionInstruction
|
|
9
|
+
} from '@solana/web3.js'
|
|
10
|
+
import {
|
|
11
|
+
getHedgeMintPublicKey, getPoolPublicKeyForMint, getReferralAccountPublicKey, getReferralStatePublicKey,
|
|
12
|
+
getUshMintPublicKey, getVaultSystemStatePublicKey
|
|
13
|
+
} from '../Constants'
|
|
14
|
+
|
|
15
|
+
import { Vault } from '../idl/vault'
|
|
16
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
|
17
|
+
import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
|
|
18
|
+
|
|
19
|
+
/** @type {Function} - Allows a referrer to claims their fees.
|
|
20
|
+
* This checks the user has enough HDG in their wallet or staked and
|
|
21
|
+
* then allows them to claim earned fees. If they meet the PSM referral threshold,
|
|
22
|
+
* they will be eligible for PSM cut.
|
|
23
|
+
* Params:
|
|
24
|
+
* - program: Program<Vault> : The program instance of Hedge Vault program
|
|
25
|
+
* - provider: Provider : Current connection
|
|
26
|
+
* - payer: Signer : who we are creating the referral account for
|
|
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
|
|
28
|
+
* - referrer: PublicKey
|
|
29
|
+
*/
|
|
30
|
+
export async function referralClaimFees(
|
|
31
|
+
program: Program<Vault>,
|
|
32
|
+
provider: Provider,
|
|
33
|
+
payer: Signer,
|
|
34
|
+
poolPosition: PublicKey
|
|
35
|
+
): Promise<PublicKey> {
|
|
36
|
+
// setup transaction
|
|
37
|
+
const transaction = new Transaction()
|
|
38
|
+
const signers = [payer]
|
|
39
|
+
|
|
40
|
+
// General variables
|
|
41
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
|
|
42
|
+
|
|
43
|
+
// Find referrer account
|
|
44
|
+
const referrer = await payer.publicKey
|
|
45
|
+
const referralAccountPublicKey = await getReferralAccountPublicKey(program.programId, referrer)
|
|
46
|
+
|
|
47
|
+
// Derive the user referral account public key
|
|
48
|
+
const referallStatePublicKey = await getReferralStatePublicKey(program.programId)
|
|
49
|
+
|
|
50
|
+
const hedgeMintPublicKey = await getHedgeMintPublicKey(program.programId)
|
|
51
|
+
|
|
52
|
+
// Get HDG account of signer
|
|
53
|
+
const payerHdgAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
54
|
+
provider.connection,
|
|
55
|
+
payer,
|
|
56
|
+
hedgeMintPublicKey,
|
|
57
|
+
payer.publicKey
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const ushMintPublicKey = await getUshMintPublicKey(program.programId)
|
|
61
|
+
|
|
62
|
+
// Get USH account of signer
|
|
63
|
+
const payerUshAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
64
|
+
provider.connection,
|
|
65
|
+
payer,
|
|
66
|
+
ushMintPublicKey,
|
|
67
|
+
payer.publicKey
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
// Get community_associated_hedge_token_account
|
|
71
|
+
const communityAssociatedHedgeTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
72
|
+
provider.connection,
|
|
73
|
+
payer,
|
|
74
|
+
hedgeMintPublicKey,
|
|
75
|
+
vaultSystemStatePublicKey,
|
|
76
|
+
true
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
const [feePoolPublicKey] = await getPoolPublicKeyForMint(program.programId, hedgeMintPublicKey)
|
|
80
|
+
|
|
81
|
+
const feePoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
|
|
82
|
+
provider.connection,
|
|
83
|
+
payer,
|
|
84
|
+
ushMintPublicKey,
|
|
85
|
+
feePoolPublicKey,
|
|
86
|
+
true
|
|
87
|
+
)
|
|
88
|
+
transaction.add(
|
|
89
|
+
await referralClaimFeesInstruction(
|
|
90
|
+
program,
|
|
91
|
+
payer.publicKey,
|
|
92
|
+
vaultSystemStatePublicKey,
|
|
93
|
+
poolPosition,
|
|
94
|
+
referralAccountPublicKey,
|
|
95
|
+
referallStatePublicKey,
|
|
96
|
+
hedgeMintPublicKey,
|
|
97
|
+
payerHdgAssociatedTokenAccount.address,
|
|
98
|
+
ushMintPublicKey,
|
|
99
|
+
payerUshAssociatedTokenAccount.address,
|
|
100
|
+
communityAssociatedHedgeTokenAccount.address,
|
|
101
|
+
feePoolPublicKey,
|
|
102
|
+
feePoolAssociatedUshTokenAccount.address
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
await sendAndConfirmWithDebug(provider.connection, transaction, signers).catch(parseAnchorErrors)
|
|
107
|
+
return referralAccountPublicKey
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function referralClaimFeesInstruction(
|
|
111
|
+
program: Program<Vault>,
|
|
112
|
+
payerPublicKey: PublicKey,
|
|
113
|
+
vaultSystemStatePublicKey: PublicKey,
|
|
114
|
+
poolPositionPublicKey: PublicKey,
|
|
115
|
+
referralAccountPublicKey: PublicKey,
|
|
116
|
+
referralStatePublicKey: PublicKey,
|
|
117
|
+
hedgeMintPublicKey: PublicKey,
|
|
118
|
+
hdgAssociatedTokenAccountPublicKey: PublicKey,
|
|
119
|
+
ushMintPublicKey: PublicKey,
|
|
120
|
+
ushAssociatedTokenAccountPublicKey: PublicKey,
|
|
121
|
+
communityAssociatedHedgeTokenAccountPublicKey: PublicKey,
|
|
122
|
+
feePoolPublicKey: PublicKey,
|
|
123
|
+
feePoolAssociatedUshTokenAccountPublicKey: PublicKey
|
|
124
|
+
): Promise<TransactionInstruction> {
|
|
125
|
+
return await program.methods
|
|
126
|
+
.referralClaimFees()
|
|
127
|
+
.accounts({
|
|
128
|
+
signer: payerPublicKey,
|
|
129
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
|
130
|
+
referralState: referralStatePublicKey,
|
|
131
|
+
referralAccount: referralAccountPublicKey,
|
|
132
|
+
poolPosition: poolPositionPublicKey,
|
|
133
|
+
hedgeMint: hedgeMintPublicKey,
|
|
134
|
+
signerHdgAta: hdgAssociatedTokenAccountPublicKey,
|
|
135
|
+
ushMint: ushMintPublicKey,
|
|
136
|
+
signerUshAta: ushAssociatedTokenAccountPublicKey,
|
|
137
|
+
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccountPublicKey,
|
|
138
|
+
feePool: feePoolPublicKey,
|
|
139
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccountPublicKey,
|
|
140
|
+
systemProgram: SystemProgram.programId,
|
|
141
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
142
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
143
|
+
})
|
|
144
|
+
.instruction()
|
|
145
|
+
}
|
|
@@ -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
|
)
|