hedge-web3 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/idl/vault.d.ts +99 -99
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/claimStakingPoolPosition.d.ts +3 -2
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +3 -2
- package/declarations/instructions/createStakingPool.d.ts +3 -2
- package/declarations/instructions/createVault.d.ts +6 -5
- package/declarations/instructions/depositLiquidationPool.d.ts +3 -2
- package/declarations/instructions/depositStakingPool.d.ts +3 -2
- package/declarations/instructions/depositVault.d.ts +3 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +3 -2
- package/declarations/instructions/liquidateVault.d.ts +3 -2
- package/declarations/instructions/loanVault.d.ts +3 -2
- package/declarations/instructions/redeemVault.d.ts +3 -2
- package/declarations/instructions/refreshOraclePrice.d.ts +3 -2
- package/declarations/instructions/repayVault.d.ts +3 -2
- package/declarations/instructions/setHalted.d.ts +3 -2
- package/declarations/instructions/setVaultTypeStatus.d.ts +3 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
- package/declarations/instructions/withdrawVault.d.ts +3 -2
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -1
- package/lib/idl/vault.js +99 -99
- package/lib/index.js +1 -0
- package/lib/instructions/claimLiquidationPoolPosition.js +19 -22
- package/lib/instructions/claimStakingPoolPosition.js +19 -19
- package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
- package/lib/instructions/createStakingPool.js +17 -18
- package/lib/instructions/createVault.js +28 -31
- package/lib/instructions/depositLiquidationPool.js +17 -18
- package/lib/instructions/depositStakingPool.js +16 -18
- package/lib/instructions/depositVault.js +25 -27
- package/lib/instructions/initHedgeFoundation.js +17 -19
- package/lib/instructions/initHedgeFoundationTokens.js +15 -15
- package/lib/instructions/liquidateVault.js +32 -33
- package/lib/instructions/loanVault.js +23 -23
- package/lib/instructions/redeemVault.js +24 -24
- package/lib/instructions/refreshOraclePrice.js +17 -17
- package/lib/instructions/repayVault.js +23 -23
- package/lib/instructions/setHalted.js +8 -9
- package/lib/instructions/setVaultTypeStatus.js +9 -10
- package/lib/instructions/withdrawStakingPool.js +22 -24
- package/lib/instructions/withdrawVault.js +23 -23
- package/lib/state/LiquidationPoolEra.js +3 -1
- package/lib/state/LiquidationPosition.js +0 -7
- package/lib/state/StakingPool.js +3 -4
- package/lib/state/VaultAccount.js +2 -5
- package/lib/utils/getLinkedListAccounts.js +24 -16
- package/package.json +2 -2
- package/src/idl/vault.ts +198 -198
- package/src/index.ts +1 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +39 -29
- package/src/instructions/claimStakingPoolPosition.ts +45 -25
- package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
- package/src/instructions/createStakingPool.ts +37 -35
- package/src/instructions/createVault.ts +81 -125
- package/src/instructions/depositLiquidationPool.ts +45 -26
- package/src/instructions/depositStakingPool.ts +32 -24
- package/src/instructions/depositVault.ts +57 -86
- package/src/instructions/initHedgeFoundation.ts +42 -43
- package/src/instructions/initHedgeFoundationTokens.ts +38 -39
- package/src/instructions/liquidateVault.ts +42 -65
- package/src/instructions/loanVault.ts +51 -69
- package/src/instructions/redeemVault.ts +83 -47
- package/src/instructions/refreshOraclePrice.ts +41 -32
- package/src/instructions/repayVault.ts +45 -65
- package/src/instructions/setHalted.ts +32 -24
- package/src/instructions/setVaultTypeStatus.ts +32 -24
- package/src/instructions/withdrawStakingPool.ts +44 -30
- package/src/instructions/withdrawVault.ts +58 -82
- package/src/state/LiquidationPoolEra.ts +4 -3
- package/src/state/LiquidationPosition.ts +0 -27
- package/src/state/StakingPool.ts +4 -7
- package/src/state/StakingPoolPosition.ts +2 -3
- package/src/state/VaultAccount.ts +9 -28
- package/src/state/VaultHistoryEvent.ts +1 -2
- package/src/utils/getLinkedListAccounts.ts +31 -30
@@ -1,9 +1,5 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
3
|
-
ASSOCIATED_TOKEN_PROGRAM_ID,
|
4
|
-
TOKEN_PROGRAM_ID,
|
5
|
-
getOrCreateAssociatedTokenAccount,
|
6
|
-
} from '@solana/spl-token'
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
7
3
|
import {
|
8
4
|
Keypair,
|
9
5
|
PublicKey,
|
@@ -24,9 +20,10 @@ import {
|
|
24
20
|
getUshMintPublicKey,
|
25
21
|
getVaultSystemStatePublicKey,
|
26
22
|
} from '../Constants'
|
23
|
+
import { Vault } from 'idl/vault'
|
27
24
|
|
28
25
|
export async function liquidateVault(
|
29
|
-
program: Program
|
26
|
+
program: Program<Vault>,
|
30
27
|
provider: Provider,
|
31
28
|
payer: Signer,
|
32
29
|
vaultPublicKey: PublicKey,
|
@@ -34,23 +31,15 @@ export async function liquidateVault(
|
|
34
31
|
): Promise<PublicKey> {
|
35
32
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
36
33
|
|
37
|
-
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
|
38
|
-
|
39
|
-
)
|
40
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(
|
41
|
-
vaultTypeAccountPublicKey
|
42
|
-
)
|
34
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
35
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
43
36
|
const collateralMint = vaultTypeAccountInfo.collateralMint
|
44
37
|
|
45
38
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
46
39
|
const ushMintPublickey = await getUshMintPublicKey()
|
47
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
48
|
-
hedgeMintPublickey
|
49
|
-
)
|
40
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
50
41
|
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
|
51
|
-
const poolStateInfo = await program.account.liquidationPoolState.fetch(
|
52
|
-
liquidationPoolStatePublicKey
|
53
|
-
)
|
42
|
+
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
|
54
43
|
|
55
44
|
const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
56
45
|
provider.connection,
|
@@ -80,34 +69,31 @@ export async function liquidateVault(
|
|
80
69
|
liquidationPoolStatePublicKey,
|
81
70
|
true
|
82
71
|
)
|
83
|
-
const vaultTypeAssociatedTokenAccount =
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
true
|
98
|
-
)
|
72
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
73
|
+
provider.connection,
|
74
|
+
payer,
|
75
|
+
collateralMint,
|
76
|
+
vaultTypeAccountPublicKey,
|
77
|
+
true
|
78
|
+
)
|
79
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await getOrCreateAssociatedTokenAccount(
|
80
|
+
provider.connection,
|
81
|
+
payer,
|
82
|
+
ushMintPublickey,
|
83
|
+
hedgeStakingPoolPublicKey,
|
84
|
+
true
|
85
|
+
)
|
99
86
|
|
100
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
)
|
87
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
88
|
+
program,
|
89
|
+
provider,
|
90
|
+
vaultTypeAccountPublicKey,
|
91
|
+
vaultPublicKey,
|
92
|
+
0,
|
93
|
+
0,
|
94
|
+
false,
|
95
|
+
true
|
96
|
+
)
|
111
97
|
|
112
98
|
const history = Keypair.generate()
|
113
99
|
const newEra = Keypair.generate()
|
@@ -137,17 +123,12 @@ export async function liquidateVault(
|
|
137
123
|
overrideTime
|
138
124
|
)
|
139
125
|
)
|
140
|
-
await sendAndConfirmTransaction(
|
141
|
-
provider.connection,
|
142
|
-
transaction,
|
143
|
-
[payer, history, newEra],
|
144
|
-
provider.opts
|
145
|
-
)
|
126
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra])
|
146
127
|
return vaultPublicKey
|
147
128
|
}
|
148
129
|
|
149
130
|
export async function liquidateVaultInstruction(
|
150
|
-
program: Program
|
131
|
+
program: Program<Vault>,
|
151
132
|
payerPublicKey: PublicKey,
|
152
133
|
payerAssociatedTokenAccount: PublicKey,
|
153
134
|
vaultPublickey: PublicKey,
|
@@ -170,12 +151,14 @@ export async function liquidateVaultInstruction(
|
|
170
151
|
): Promise<TransactionInstruction> {
|
171
152
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
172
153
|
const ushMintPublickey = await getUshMintPublicKey()
|
173
|
-
const liquidationPoolUshAccountPublickey =
|
174
|
-
await getLiquidationPoolUshAccountPublicKey()
|
154
|
+
const liquidationPoolUshAccountPublickey = await getLiquidationPoolUshAccountPublicKey()
|
175
155
|
const vaultTypeAccount = await getVaultTypeAccountPublicKey(collateralType)
|
176
156
|
|
177
|
-
|
178
|
-
|
157
|
+
return program.methods
|
158
|
+
.liquidateVault(
|
159
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
|
160
|
+
)
|
161
|
+
.accounts({
|
179
162
|
vaultSystemState: vaultSystemStatePublicKey,
|
180
163
|
vaultTypeAccount: vaultTypeAccount,
|
181
164
|
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
@@ -191,8 +174,7 @@ export async function liquidateVaultInstruction(
|
|
191
174
|
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
192
175
|
feePool: feePool,
|
193
176
|
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
194
|
-
feePoolAssociatedUshTokenAccount:
|
195
|
-
hedgeStakingPoolAssociatedUshTokenAccount,
|
177
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
196
178
|
liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
|
197
179
|
newEra: newEraPublicKey,
|
198
180
|
oldSmallerVaultInfo: oldSmallerPublicKey,
|
@@ -202,11 +184,6 @@ export async function liquidateVaultInstruction(
|
|
202
184
|
systemProgram: SystemProgram.programId,
|
203
185
|
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
204
186
|
rent: SYSVAR_RENT_PUBKEY,
|
205
|
-
}
|
206
|
-
|
207
|
-
}
|
208
|
-
return program.instruction.liquidateVault(
|
209
|
-
new BN(overrideTime ?? Math.floor(Date.now() / 1000)), // override override time
|
210
|
-
payload
|
211
|
-
)
|
187
|
+
})
|
188
|
+
.instruction()
|
212
189
|
}
|
@@ -1,8 +1,5 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
3
|
-
getOrCreateAssociatedTokenAccount,
|
4
|
-
TOKEN_PROGRAM_ID,
|
5
|
-
} from '@solana/spl-token'
|
2
|
+
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
6
3
|
import {
|
7
4
|
Keypair,
|
8
5
|
PublicKey,
|
@@ -21,9 +18,10 @@ import {
|
|
21
18
|
getUshMintPublicKey,
|
22
19
|
getVaultSystemStatePublicKey,
|
23
20
|
} from '../Constants'
|
21
|
+
import { Vault } from 'idl/vault'
|
24
22
|
|
25
23
|
export async function loanVault(
|
26
|
-
program: Program
|
24
|
+
program: Program<Vault>,
|
27
25
|
provider: Provider,
|
28
26
|
payer: Signer,
|
29
27
|
vaultPublicKey: PublicKey,
|
@@ -40,20 +38,15 @@ export async function loanVault(
|
|
40
38
|
)
|
41
39
|
|
42
40
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
43
|
-
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
42
|
+
const vaultTypeAccount = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
43
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
44
|
+
provider.connection,
|
45
|
+
payer,
|
46
|
+
vaultTypeAccount.collateralMint,
|
47
|
+
vaultTypeAccountPublicKey,
|
48
|
+
true
|
48
49
|
)
|
49
|
-
const vaultTypeAssociatedTokenAccount =
|
50
|
-
await getOrCreateAssociatedTokenAccount(
|
51
|
-
provider.connection,
|
52
|
-
payer,
|
53
|
-
vaultTypeAccount.collateralMint,
|
54
|
-
vaultTypeAccountPublicKey,
|
55
|
-
true
|
56
|
-
)
|
57
50
|
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
58
51
|
provider.connection,
|
59
52
|
payer,
|
@@ -62,17 +55,16 @@ export async function loanVault(
|
|
62
55
|
true
|
63
56
|
)
|
64
57
|
|
65
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
)
|
58
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
59
|
+
program,
|
60
|
+
provider,
|
61
|
+
vaultTypeAccountPublicKey,
|
62
|
+
vaultPublicKey,
|
63
|
+
0,
|
64
|
+
loanAmount,
|
65
|
+
false,
|
66
|
+
false
|
67
|
+
)
|
76
68
|
|
77
69
|
const history = Keypair.generate()
|
78
70
|
const transaction = new Transaction().add(
|
@@ -92,17 +84,12 @@ export async function loanVault(
|
|
92
84
|
overrideTime
|
93
85
|
)
|
94
86
|
)
|
95
|
-
await sendAndConfirmTransaction(
|
96
|
-
provider.connection,
|
97
|
-
transaction,
|
98
|
-
[payer, history],
|
99
|
-
provider.opts
|
100
|
-
)
|
87
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
|
101
88
|
return vaultPublicKey
|
102
89
|
}
|
103
90
|
|
104
91
|
export async function loanVaultInstruction(
|
105
|
-
program: Program
|
92
|
+
program: Program<Vault>,
|
106
93
|
payerPublicKey: PublicKey,
|
107
94
|
ownerUshAccount: PublicKey,
|
108
95
|
vaultPublickey: PublicKey,
|
@@ -119,39 +106,34 @@ export async function loanVaultInstruction(
|
|
119
106
|
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
120
107
|
const ushMintPublickey = await getUshMintPublicKey()
|
121
108
|
const hedgeMintPublickey = await getHedgeMintPublicKey()
|
122
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
123
|
-
|
109
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey)
|
110
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
111
|
+
hedgeStakingPoolPublicKey,
|
112
|
+
ushMintPublickey
|
124
113
|
)
|
125
|
-
const hedgeStakingPoolAssociatedUshTokenAccount =
|
126
|
-
await findAssociatedTokenAddress(
|
127
|
-
hedgeStakingPoolPublicKey,
|
128
|
-
ushMintPublickey
|
129
|
-
)
|
130
114
|
|
131
|
-
return program.
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
}
|
156
|
-
)
|
115
|
+
return program.methods
|
116
|
+
.loanVault(
|
117
|
+
new BN(loanAmount),
|
118
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
|
119
|
+
)
|
120
|
+
.accounts({
|
121
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
122
|
+
vaultTypeAccount: vaultTypeAccount,
|
123
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
124
|
+
vaultAccount: vaultPublickey,
|
125
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
126
|
+
history: historyPublicKey,
|
127
|
+
feePool: hedgeStakingPoolPublicKey,
|
128
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
129
|
+
ushMint: ushMintPublickey,
|
130
|
+
vaultOwner: payerPublicKey,
|
131
|
+
ownerUshAccount: ownerUshAccount,
|
132
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
133
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
134
|
+
newLargerVaultInfo: newLargerPublicKey,
|
135
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
136
|
+
systemProgram: SystemProgram.programId,
|
137
|
+
})
|
138
|
+
.instruction()
|
157
139
|
}
|
@@ -1,12 +1,28 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
3
|
// import { TokenInstructions } from '@project-serum/serum'
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
Keypair,
|
6
|
+
PublicKey,
|
7
|
+
sendAndConfirmTransaction,
|
8
|
+
Signer,
|
9
|
+
SystemProgram,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
5
13
|
import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
|
6
|
-
import {
|
14
|
+
import {
|
15
|
+
findAssociatedTokenAddress,
|
16
|
+
getHedgeMintPublicKey,
|
17
|
+
getPoolPublicKeyForMint,
|
18
|
+
getVaultTypeAccountPublicKey,
|
19
|
+
getUshMintPublicKey,
|
20
|
+
getVaultSystemStatePublicKey,
|
21
|
+
} from '../Constants'
|
22
|
+
import { Vault } from 'idl/vault'
|
7
23
|
|
8
|
-
export async function redeemVault
|
9
|
-
program: Program
|
24
|
+
export async function redeemVault(
|
25
|
+
program: Program<Vault>,
|
10
26
|
provider: Provider,
|
11
27
|
payer: Signer,
|
12
28
|
vaultPublicKey: PublicKey,
|
@@ -16,29 +32,49 @@ export async function redeemVault (
|
|
16
32
|
const ushMintPublickey = await getUshMintPublicKey()
|
17
33
|
|
18
34
|
// Prep the user to get USH back out at some point
|
19
|
-
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
35
|
+
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
36
|
+
provider.connection,
|
37
|
+
payer,
|
38
|
+
ushMintPublickey,
|
39
|
+
payer.publicKey
|
40
|
+
)
|
20
41
|
|
21
42
|
const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
|
22
43
|
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
|
23
44
|
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
24
|
-
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
25
|
-
|
26
|
-
|
45
|
+
const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
46
|
+
provider.connection,
|
47
|
+
payer,
|
48
|
+
vaultTypeAccountInfo.collateralMint,
|
49
|
+
vaultTypeAccountPublicKey,
|
50
|
+
true
|
51
|
+
)
|
27
52
|
|
28
|
-
const
|
53
|
+
const vaultAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
|
54
|
+
provider.connection,
|
55
|
+
payer,
|
56
|
+
vaultTypeAccountInfo.collateralMint,
|
57
|
+
vaultPublicKey,
|
58
|
+
true
|
59
|
+
)
|
29
60
|
|
61
|
+
const payerTokenAccount = await getOrCreateAssociatedTokenAccount(
|
62
|
+
provider.connection,
|
63
|
+
payer,
|
64
|
+
vaultTypeAccountInfo.collateralMint,
|
65
|
+
payer.publicKey
|
66
|
+
)
|
30
67
|
|
31
|
-
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
)
|
68
|
+
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = await getLinkedListAccounts(
|
69
|
+
program,
|
70
|
+
provider,
|
71
|
+
vaultTypeAccountPublicKey,
|
72
|
+
vaultPublicKey,
|
73
|
+
0,
|
74
|
+
0,
|
75
|
+
true,
|
76
|
+
false
|
77
|
+
)
|
42
78
|
|
43
79
|
const history = Keypair.generate()
|
44
80
|
const transaction = new Transaction().add(
|
@@ -59,12 +95,12 @@ export async function redeemVault (
|
|
59
95
|
transactionOverrideTime
|
60
96
|
)
|
61
97
|
)
|
62
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history]
|
98
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, history])
|
63
99
|
return vaultPublicKey
|
64
100
|
}
|
65
101
|
|
66
|
-
export async function redeemVaultInstruction
|
67
|
-
program: Program
|
102
|
+
export async function redeemVaultInstruction(
|
103
|
+
program: Program<Vault>,
|
68
104
|
payerPublicKey: PublicKey,
|
69
105
|
payerUshAccount: PublicKey,
|
70
106
|
destinationTokenAccount: PublicKey,
|
@@ -87,29 +123,29 @@ export async function redeemVaultInstruction (
|
|
87
123
|
hedgeStakingPoolPublicKey,
|
88
124
|
ushMintPublickey
|
89
125
|
)
|
90
|
-
return program.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
signers: []
|
126
|
+
return await program.methods
|
127
|
+
.redeemVault(
|
128
|
+
new BN(redeemAmount),
|
129
|
+
new BN(transactionOverrideTime ?? Date.now() / 1000) // override start time
|
130
|
+
)
|
131
|
+
.accounts({
|
132
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
133
|
+
vaultTypeAccount: vaultTypeAccount,
|
134
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
135
|
+
vault: vaultPublickey,
|
136
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
137
|
+
history: historyPublicKey,
|
138
|
+
feePool: hedgeStakingPoolPublicKey,
|
139
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
140
|
+
ushMint: ushMintPublickey,
|
141
|
+
payer: payerPublicKey,
|
142
|
+
payerUshAccount: payerUshAccount,
|
143
|
+
destinationTokenAccount: destinationTokenAccount,
|
144
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
145
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
146
|
+
newLargerVaultInfo: newLargerPublicKey,
|
147
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
148
|
+
systemProgram: SystemProgram.programId,
|
114
149
|
})
|
150
|
+
.instruction()
|
115
151
|
}
|
@@ -1,9 +1,18 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
LAMPORTS_PER_SOL,
|
4
|
+
PublicKey,
|
5
|
+
sendAndConfirmTransaction,
|
6
|
+
Signer,
|
7
|
+
SystemProgram,
|
8
|
+
Transaction,
|
9
|
+
TransactionInstruction,
|
10
|
+
} from '@solana/web3.js'
|
11
|
+
import { Vault } from 'idl/vault'
|
3
12
|
import { HEDGE_PROGRAM_PUBLICKEY } from '../Constants'
|
4
13
|
|
5
|
-
export async function refreshOraclePrice
|
6
|
-
program: Program
|
14
|
+
export async function refreshOraclePrice(
|
15
|
+
program: Program<Vault>,
|
7
16
|
provider: Provider,
|
8
17
|
payer: Signer,
|
9
18
|
collateralType: string,
|
@@ -12,63 +21,63 @@ export async function refreshOraclePrice (
|
|
12
21
|
overrideTime?: number
|
13
22
|
): Promise<string> {
|
14
23
|
const transaction = new Transaction().add(
|
15
|
-
await refreshOraclePriceInstruction(
|
16
|
-
program,
|
17
|
-
collateralType,
|
18
|
-
network,
|
19
|
-
overridePrice,
|
20
|
-
overrideTime
|
21
|
-
)
|
24
|
+
await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime)
|
22
25
|
)
|
23
|
-
return await sendAndConfirmTransaction(provider.connection, transaction, [payer]
|
26
|
+
return await sendAndConfirmTransaction(provider.connection, transaction, [payer])
|
24
27
|
}
|
25
28
|
|
26
|
-
export async function refreshOraclePriceInstruction
|
27
|
-
program: Program
|
29
|
+
export async function refreshOraclePriceInstruction(
|
30
|
+
program: Program<Vault>,
|
28
31
|
collateralType: string,
|
29
32
|
network: Cluster,
|
30
33
|
overridePrice?: number,
|
31
34
|
overrideTime?: number
|
32
35
|
): Promise<TransactionInstruction> {
|
33
36
|
const enc = new TextEncoder()
|
34
|
-
const [oracleInfoAccount] = await PublicKey.findProgramAddress(
|
35
|
-
|
37
|
+
const [oracleInfoAccount] = await PublicKey.findProgramAddress(
|
38
|
+
[enc.encode(collateralType), enc.encode('Oracle')],
|
39
|
+
HEDGE_PROGRAM_PUBLICKEY
|
40
|
+
)
|
41
|
+
const [vaultTypeAccount] = await PublicKey.findProgramAddress(
|
42
|
+
[enc.encode(collateralType), enc.encode('State')],
|
43
|
+
HEDGE_PROGRAM_PUBLICKEY
|
44
|
+
)
|
36
45
|
|
37
|
-
return program.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
signers: []
|
46
|
+
return await program.methods
|
47
|
+
.refreshOraclePrice(
|
48
|
+
new BN(overridePrice ?? LAMPORTS_PER_SOL * 150), // override usd/sol price
|
49
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000) - 1) // override override time
|
50
|
+
)
|
51
|
+
.accounts({
|
52
|
+
oracleInfoAccount: oracleInfoAccount,
|
53
|
+
vaultTypeAccount: vaultTypeAccount,
|
54
|
+
oracleChainlink: chainlinkAccunts[network],
|
55
|
+
oraclePyth: pythAccounts[network],
|
56
|
+
oracleSwitchboard: switchboardAccounts[network],
|
57
|
+
systemProgram: SystemProgram.programId,
|
50
58
|
})
|
59
|
+
.instruction()
|
51
60
|
}
|
52
61
|
|
53
62
|
enum Cluster {
|
54
63
|
Testing = 'Testing',
|
55
64
|
Devnet = 'Devnet',
|
56
|
-
MainnetBeta = 'MainnetBeta'
|
65
|
+
MainnetBeta = 'MainnetBeta',
|
57
66
|
}
|
58
67
|
|
59
68
|
const pythAccounts = {
|
60
69
|
Testing: SystemProgram.programId,
|
61
70
|
Devnet: new PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
62
|
-
MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
|
71
|
+
MainnetBeta: new PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
|
63
72
|
}
|
64
73
|
const chainlinkAccunts = {
|
65
74
|
Testing: SystemProgram.programId,
|
66
75
|
Devnet: new PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
|
67
|
-
MainnetBeta: SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
|
76
|
+
MainnetBeta: SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
|
68
77
|
}
|
69
78
|
const switchboardAccounts = {
|
70
79
|
Testing: SystemProgram.programId,
|
71
80
|
// Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
|
72
81
|
Devnet: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
|
73
|
-
MainnetBeta: SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
|
82
|
+
MainnetBeta: SystemProgram.programId, // Switchboard V2 NOT ON MAINNET YET
|
74
83
|
}
|