hedge-web3 0.1.0 → 0.1.4
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/.github/workflows/npm-publish.yml +34 -0
- package/README.md +44 -0
- package/lib/index.js +1976 -0
- package/lib/index.js.map +1 -0
- package/lib/types/src/Constants.d.ts +13 -0
- package/lib/types/src/Constants.d.ts.map +1 -0
- package/lib/types/src/HedgeDecimal.d.ts +15 -0
- package/lib/types/src/HedgeDecimal.d.ts.map +1 -0
- package/lib/types/src/StakingPools.d.ts +4 -0
- package/lib/types/src/StakingPools.d.ts.map +1 -0
- package/lib/types/src/Vaults.d.ts +9 -0
- package/lib/types/src/Vaults.d.ts.map +1 -0
- package/lib/types/src/idl/idl.d.ts +3 -0
- package/lib/types/src/idl/idl.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +5 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/instructions/createStakingPool.d.ts +4 -0
- package/lib/types/src/instructions/createStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/createVault.d.ts +4 -0
- package/lib/types/src/instructions/createVault.d.ts.map +1 -0
- package/lib/types/src/instructions/depositStakingPool.d.ts +4 -0
- package/lib/types/src/instructions/depositStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/depositVault.d.ts +4 -0
- package/lib/types/src/instructions/depositVault.d.ts.map +1 -0
- package/lib/types/src/instructions/liquidateVault.d.ts +4 -0
- package/lib/types/src/instructions/liquidateVault.d.ts.map +1 -0
- package/lib/types/src/instructions/loanVault.d.ts +4 -0
- package/lib/types/src/instructions/loanVault.d.ts.map +1 -0
- package/lib/types/src/instructions/redeemVault.d.ts +4 -0
- package/lib/types/src/instructions/redeemVault.d.ts.map +1 -0
- package/lib/types/src/instructions/repayVault.d.ts +4 -0
- package/lib/types/src/instructions/repayVault.d.ts.map +1 -0
- package/lib/types/src/instructions/withdrawStakingPool.d.ts +4 -0
- package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +1 -0
- package/lib/types/src/instructions/withdrawVault.d.ts +4 -0
- package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -0
- package/lib/types/src/state/LiquidationPoolEra.d.ts +15 -0
- package/lib/types/src/state/LiquidationPoolEra.d.ts.map +1 -0
- package/lib/types/src/state/LiquidationPoolState.d.ts +7 -0
- package/lib/types/src/state/LiquidationPoolState.d.ts.map +1 -0
- package/lib/types/src/state/LiquidationPosition.d.ts +24 -0
- package/lib/types/src/state/LiquidationPosition.d.ts.map +1 -0
- package/lib/types/src/state/StakingPool.d.ts +17 -0
- package/lib/types/src/state/StakingPool.d.ts.map +1 -0
- package/lib/types/src/state/StakingPoolPosition.d.ts +19 -0
- package/lib/types/src/state/StakingPoolPosition.d.ts.map +1 -0
- package/lib/types/src/state/VaultAccount.d.ts +48 -0
- package/lib/types/src/state/VaultAccount.d.ts.map +1 -0
- package/lib/types/src/state/VaultHistoryEvent.d.ts +40 -0
- package/lib/types/src/state/VaultHistoryEvent.d.ts.map +1 -0
- package/lib/types/src/utils/Errors.d.ts +2 -0
- package/lib/types/src/utils/Errors.d.ts.map +1 -0
- package/lib/types/tsconfig.base.tsbuildinfo +1 -0
- package/package.json +6 -6
- package/rollup.config.js +14 -8
- package/src/Constants.ts +56 -0
- package/src/HedgeDecimal.ts +15 -7
- package/src/StakingPools.ts +3 -0
- package/src/Vaults.ts +8 -0
- package/src/idl/idl.ts +1474 -0
- package/src/index.ts +3 -5
- package/src/instructions/createStakingPool.ts +65 -0
- package/src/instructions/createVault.ts +66 -0
- package/src/instructions/depositStakingPool.ts +61 -0
- package/src/instructions/depositVault.ts +61 -0
- package/src/instructions/liquidateVault.ts +67 -0
- package/src/instructions/loanVault.ts +79 -0
- package/src/instructions/redeemVault.ts +83 -0
- package/src/instructions/repayVault.ts +74 -0
- package/src/instructions/withdrawStakingPool.ts +70 -0
- package/src/instructions/withdrawVault.ts +66 -0
- package/src/state/LiquidationPoolEra.ts +29 -0
- package/src/state/LiquidationPoolState.ts +10 -0
- package/src/state/LiquidationPosition.ts +69 -0
- package/src/state/StakingPool.ts +39 -0
- package/src/state/StakingPoolPosition.ts +40 -0
- package/src/state/VaultAccount.ts +77 -0
- package/src/state/VaultHistoryEvent.ts +61 -0
- package/src/types/buffer-layout/index.d.ts +88 -0
- package/src/utils/Errors.ts +11 -0
- package/tsconfig.base.json +3 -3
- package/tsconfig.d.json +3 -1
- package/tsconfig.json +1 -1
- package/src/accounts/LiquidationPoolEra.ts +0 -16
- package/src/accounts/LiquidationPoolState.ts +0 -22
- package/src/accounts/LiquidationPosition.ts +0 -72
- package/src/accounts/StakingPool.ts +0 -31
- package/src/accounts/StakingPoolPosition.ts +0 -29
- package/src/accounts/VaultAccount.ts +0 -40
- package/src/accounts/VaultHistoryEvent.ts +0 -27
package/lib/index.js
ADDED
@@ -0,0 +1,1976 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
5
|
+
var anchor = require('@project-serum/anchor');
|
6
|
+
var splToken = require('@solana/spl-token');
|
7
|
+
var web3_js = require('@solana/web3.js');
|
8
|
+
var Decimal = require('decimal.js');
|
9
|
+
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
11
|
+
|
12
|
+
var Decimal__default = /*#__PURE__*/_interopDefaultLegacy(Decimal);
|
13
|
+
|
14
|
+
const HEDGE_PROGRAM_ID = 'fff6FuPWrBPzFHeWwtBQaPjKvMvW27w8Jf4P7SSoueX';
|
15
|
+
const HEDGE_PROGRAM_PUBLICKEY = new web3_js.PublicKey(HEDGE_PROGRAM_ID);
|
16
|
+
const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
|
17
|
+
const CHAINLINK_SOL_USD_PUBLICKEY = new web3_js.PublicKey(CHAINLINK_SOL_USD_ID);
|
18
|
+
async function getLiquidationPoolStatePublicKey() {
|
19
|
+
const enc = new TextEncoder();
|
20
|
+
const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY);
|
21
|
+
return [poolPublicKey, bump];
|
22
|
+
}
|
23
|
+
async function getLiquidationPoolUsdhAccountPublicKey() {
|
24
|
+
const enc = new TextEncoder();
|
25
|
+
const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY);
|
26
|
+
return [poolPublicKey, bump];
|
27
|
+
}
|
28
|
+
async function getUsdhMintPublicKey() {
|
29
|
+
const enc = new TextEncoder();
|
30
|
+
const [findMintPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY);
|
31
|
+
return [findMintPublicKey, bump];
|
32
|
+
}
|
33
|
+
async function getVaultSystemStatePublicKey() {
|
34
|
+
const enc = new TextEncoder();
|
35
|
+
const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY);
|
36
|
+
return [publicKey, bump];
|
37
|
+
}
|
38
|
+
async function getHedgeMintPublicKey() {
|
39
|
+
const enc = new TextEncoder();
|
40
|
+
const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY);
|
41
|
+
return [publicKey, bump];
|
42
|
+
}
|
43
|
+
async function getPoolPublicKeyForMint(mintPublicKey) {
|
44
|
+
const enc = new TextEncoder();
|
45
|
+
const strToEncode = (mintPublicKey.toString().substring(0, 12));
|
46
|
+
const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY);
|
47
|
+
return [publicKey, bump, strToEncode];
|
48
|
+
}
|
49
|
+
async function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
|
50
|
+
return (await web3_js.PublicKey.findProgramAddress([
|
51
|
+
walletAddress.toBuffer(),
|
52
|
+
splToken.TOKEN_PROGRAM_ID.toBuffer(),
|
53
|
+
tokenMintAddress.toBuffer()
|
54
|
+
], splToken.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
55
|
+
}
|
56
|
+
|
57
|
+
var Constants = /*#__PURE__*/Object.freeze({
|
58
|
+
__proto__: null,
|
59
|
+
HEDGE_PROGRAM_ID: HEDGE_PROGRAM_ID,
|
60
|
+
HEDGE_PROGRAM_PUBLICKEY: HEDGE_PROGRAM_PUBLICKEY,
|
61
|
+
CHAINLINK_SOL_USD_ID: CHAINLINK_SOL_USD_ID,
|
62
|
+
CHAINLINK_SOL_USD_PUBLICKEY: CHAINLINK_SOL_USD_PUBLICKEY,
|
63
|
+
getLiquidationPoolStatePublicKey: getLiquidationPoolStatePublicKey,
|
64
|
+
getLiquidationPoolUsdhAccountPublicKey: getLiquidationPoolUsdhAccountPublicKey,
|
65
|
+
getUsdhMintPublicKey: getUsdhMintPublicKey,
|
66
|
+
getVaultSystemStatePublicKey: getVaultSystemStatePublicKey,
|
67
|
+
getHedgeMintPublicKey: getHedgeMintPublicKey,
|
68
|
+
getPoolPublicKeyForMint: getPoolPublicKeyForMint,
|
69
|
+
findAssociatedTokenAddress: findAssociatedTokenAddress
|
70
|
+
});
|
71
|
+
|
72
|
+
const vaultIdl = {
|
73
|
+
version: '0.1.0',
|
74
|
+
name: 'vault',
|
75
|
+
instructions: [
|
76
|
+
{
|
77
|
+
name: 'initHedgeFoundation',
|
78
|
+
accounts: [
|
79
|
+
{
|
80
|
+
name: 'vaultSystemState',
|
81
|
+
isMut: true,
|
82
|
+
isSigner: false
|
83
|
+
},
|
84
|
+
{
|
85
|
+
name: 'poolState',
|
86
|
+
isMut: true,
|
87
|
+
isSigner: false
|
88
|
+
},
|
89
|
+
{
|
90
|
+
name: 'poolEra',
|
91
|
+
isMut: true,
|
92
|
+
isSigner: true
|
93
|
+
},
|
94
|
+
{
|
95
|
+
name: 'poolUsdhAccount',
|
96
|
+
isMut: true,
|
97
|
+
isSigner: false
|
98
|
+
},
|
99
|
+
{
|
100
|
+
name: 'founder',
|
101
|
+
isMut: true,
|
102
|
+
isSigner: true
|
103
|
+
},
|
104
|
+
{
|
105
|
+
name: 'usdhMint',
|
106
|
+
isMut: true,
|
107
|
+
isSigner: false
|
108
|
+
},
|
109
|
+
{
|
110
|
+
name: 'hedgeMint',
|
111
|
+
isMut: true,
|
112
|
+
isSigner: false
|
113
|
+
},
|
114
|
+
{
|
115
|
+
name: 'founderAssociatedHedgeTokenAccount',
|
116
|
+
isMut: true,
|
117
|
+
isSigner: false
|
118
|
+
},
|
119
|
+
{
|
120
|
+
name: 'oracleChainlink',
|
121
|
+
isMut: false,
|
122
|
+
isSigner: false
|
123
|
+
},
|
124
|
+
{
|
125
|
+
name: 'oraclePyth',
|
126
|
+
isMut: false,
|
127
|
+
isSigner: false
|
128
|
+
},
|
129
|
+
{
|
130
|
+
name: 'oracleSwitchboard',
|
131
|
+
isMut: false,
|
132
|
+
isSigner: false
|
133
|
+
},
|
134
|
+
{
|
135
|
+
name: 'rent',
|
136
|
+
isMut: false,
|
137
|
+
isSigner: false
|
138
|
+
},
|
139
|
+
{
|
140
|
+
name: 'splTokenProgramInfo',
|
141
|
+
isMut: false,
|
142
|
+
isSigner: false
|
143
|
+
},
|
144
|
+
{
|
145
|
+
name: 'splAssociatedTokenProgramInfo',
|
146
|
+
isMut: false,
|
147
|
+
isSigner: false
|
148
|
+
},
|
149
|
+
{
|
150
|
+
name: 'systemProgram',
|
151
|
+
isMut: false,
|
152
|
+
isSigner: false
|
153
|
+
}
|
154
|
+
],
|
155
|
+
args: [
|
156
|
+
{
|
157
|
+
name: 'bump1',
|
158
|
+
type: 'u8'
|
159
|
+
},
|
160
|
+
{
|
161
|
+
name: 'bump2',
|
162
|
+
type: 'u8'
|
163
|
+
}
|
164
|
+
]
|
165
|
+
},
|
166
|
+
{
|
167
|
+
name: 'createStakingPool',
|
168
|
+
accounts: [
|
169
|
+
{
|
170
|
+
name: 'signer',
|
171
|
+
isMut: true,
|
172
|
+
isSigner: true
|
173
|
+
},
|
174
|
+
{
|
175
|
+
name: 'vaultSystemState',
|
176
|
+
isMut: true,
|
177
|
+
isSigner: false
|
178
|
+
},
|
179
|
+
{
|
180
|
+
name: 'pool',
|
181
|
+
isMut: true,
|
182
|
+
isSigner: false
|
183
|
+
},
|
184
|
+
{
|
185
|
+
name: 'stakedTokenMintInfo',
|
186
|
+
isMut: false,
|
187
|
+
isSigner: false
|
188
|
+
},
|
189
|
+
{
|
190
|
+
name: 'usdhMint',
|
191
|
+
isMut: false,
|
192
|
+
isSigner: false
|
193
|
+
},
|
194
|
+
{
|
195
|
+
name: 'poolAssociatedStakedTokenAccount',
|
196
|
+
isMut: true,
|
197
|
+
isSigner: false
|
198
|
+
},
|
199
|
+
{
|
200
|
+
name: 'poolAssociatedUsdhTokenAccount',
|
201
|
+
isMut: true,
|
202
|
+
isSigner: false
|
203
|
+
},
|
204
|
+
{
|
205
|
+
name: 'rent',
|
206
|
+
isMut: false,
|
207
|
+
isSigner: false
|
208
|
+
},
|
209
|
+
{
|
210
|
+
name: 'splTokenProgramInfo',
|
211
|
+
isMut: false,
|
212
|
+
isSigner: false
|
213
|
+
},
|
214
|
+
{
|
215
|
+
name: 'splAssociatedTokenProgramInfo',
|
216
|
+
isMut: false,
|
217
|
+
isSigner: false
|
218
|
+
},
|
219
|
+
{
|
220
|
+
name: 'systemProgram',
|
221
|
+
isMut: false,
|
222
|
+
isSigner: false
|
223
|
+
}
|
224
|
+
],
|
225
|
+
args: [
|
226
|
+
{
|
227
|
+
name: 'bump1',
|
228
|
+
type: 'u8'
|
229
|
+
},
|
230
|
+
{
|
231
|
+
name: 'poolSeedPhraseInput',
|
232
|
+
type: 'string'
|
233
|
+
},
|
234
|
+
{
|
235
|
+
name: 'totalRewards',
|
236
|
+
type: 'u64'
|
237
|
+
},
|
238
|
+
{
|
239
|
+
name: 'overrideCurrentTime',
|
240
|
+
type: 'i64'
|
241
|
+
}
|
242
|
+
]
|
243
|
+
},
|
244
|
+
{
|
245
|
+
name: 'depositStakingPool',
|
246
|
+
accounts: [
|
247
|
+
{
|
248
|
+
name: 'payer',
|
249
|
+
isMut: true,
|
250
|
+
isSigner: true
|
251
|
+
},
|
252
|
+
{
|
253
|
+
name: 'pool',
|
254
|
+
isMut: true,
|
255
|
+
isSigner: false
|
256
|
+
},
|
257
|
+
{
|
258
|
+
name: 'poolPosition',
|
259
|
+
isMut: true,
|
260
|
+
isSigner: true
|
261
|
+
},
|
262
|
+
{
|
263
|
+
name: 'payerAssociatedStakedTokenAccount',
|
264
|
+
isMut: true,
|
265
|
+
isSigner: false
|
266
|
+
},
|
267
|
+
{
|
268
|
+
name: 'poolAssociatedStakedTokenAccount',
|
269
|
+
isMut: true,
|
270
|
+
isSigner: false
|
271
|
+
},
|
272
|
+
{
|
273
|
+
name: 'splTokenProgramInfo',
|
274
|
+
isMut: false,
|
275
|
+
isSigner: false
|
276
|
+
},
|
277
|
+
{
|
278
|
+
name: 'systemProgram',
|
279
|
+
isMut: false,
|
280
|
+
isSigner: false
|
281
|
+
}
|
282
|
+
],
|
283
|
+
args: [
|
284
|
+
{
|
285
|
+
name: 'stakeAmount',
|
286
|
+
type: 'u64'
|
287
|
+
},
|
288
|
+
{
|
289
|
+
name: 'overrideCurrentTime',
|
290
|
+
type: 'i64'
|
291
|
+
}
|
292
|
+
]
|
293
|
+
},
|
294
|
+
{
|
295
|
+
name: 'withdrawStakingPool',
|
296
|
+
accounts: [
|
297
|
+
{
|
298
|
+
name: 'payer',
|
299
|
+
isMut: true,
|
300
|
+
isSigner: true
|
301
|
+
},
|
302
|
+
{
|
303
|
+
name: 'vaultSystemState',
|
304
|
+
isMut: true,
|
305
|
+
isSigner: false
|
306
|
+
},
|
307
|
+
{
|
308
|
+
name: 'pool',
|
309
|
+
isMut: true,
|
310
|
+
isSigner: false
|
311
|
+
},
|
312
|
+
{
|
313
|
+
name: 'poolPosition',
|
314
|
+
isMut: true,
|
315
|
+
isSigner: false
|
316
|
+
},
|
317
|
+
{
|
318
|
+
name: 'hedgeMint',
|
319
|
+
isMut: true,
|
320
|
+
isSigner: false
|
321
|
+
},
|
322
|
+
{
|
323
|
+
name: 'stakedTokenMint',
|
324
|
+
isMut: true,
|
325
|
+
isSigner: false
|
326
|
+
},
|
327
|
+
{
|
328
|
+
name: 'usdhMint',
|
329
|
+
isMut: false,
|
330
|
+
isSigner: false
|
331
|
+
},
|
332
|
+
{
|
333
|
+
name: 'payerAssociatedStakedTokenAccount',
|
334
|
+
isMut: true,
|
335
|
+
isSigner: false
|
336
|
+
},
|
337
|
+
{
|
338
|
+
name: 'payerAssociatedHedgeAccount',
|
339
|
+
isMut: true,
|
340
|
+
isSigner: false
|
341
|
+
},
|
342
|
+
{
|
343
|
+
name: 'payerAssociatedUsdhAccount',
|
344
|
+
isMut: true,
|
345
|
+
isSigner: false
|
346
|
+
},
|
347
|
+
{
|
348
|
+
name: 'poolAssociatedStakedTokenAccount',
|
349
|
+
isMut: true,
|
350
|
+
isSigner: false
|
351
|
+
},
|
352
|
+
{
|
353
|
+
name: 'poolAssociatedUsdhTokenAccount',
|
354
|
+
isMut: true,
|
355
|
+
isSigner: false
|
356
|
+
},
|
357
|
+
{
|
358
|
+
name: 'splTokenProgramInfo',
|
359
|
+
isMut: false,
|
360
|
+
isSigner: false
|
361
|
+
},
|
362
|
+
{
|
363
|
+
name: 'systemProgram',
|
364
|
+
isMut: false,
|
365
|
+
isSigner: false
|
366
|
+
}
|
367
|
+
],
|
368
|
+
args: [
|
369
|
+
{
|
370
|
+
name: 'overrideCurrentTime',
|
371
|
+
type: 'i64'
|
372
|
+
}
|
373
|
+
]
|
374
|
+
},
|
375
|
+
{
|
376
|
+
name: 'createVault',
|
377
|
+
accounts: [
|
378
|
+
{
|
379
|
+
name: 'vaultSystemState',
|
380
|
+
isMut: true,
|
381
|
+
isSigner: false
|
382
|
+
},
|
383
|
+
{
|
384
|
+
name: 'vault',
|
385
|
+
isMut: true,
|
386
|
+
isSigner: true
|
387
|
+
},
|
388
|
+
{
|
389
|
+
name: 'history',
|
390
|
+
isMut: true,
|
391
|
+
isSigner: true
|
392
|
+
},
|
393
|
+
{
|
394
|
+
name: 'payer',
|
395
|
+
isMut: true,
|
396
|
+
isSigner: true
|
397
|
+
},
|
398
|
+
{
|
399
|
+
name: 'systemProgram',
|
400
|
+
isMut: false,
|
401
|
+
isSigner: false
|
402
|
+
}
|
403
|
+
],
|
404
|
+
args: [
|
405
|
+
{
|
406
|
+
name: 'depositAmount',
|
407
|
+
type: 'u64'
|
408
|
+
},
|
409
|
+
{
|
410
|
+
name: 'minCollateralRatio',
|
411
|
+
type: 'u64'
|
412
|
+
}
|
413
|
+
]
|
414
|
+
},
|
415
|
+
{
|
416
|
+
name: 'depositVault',
|
417
|
+
accounts: [
|
418
|
+
{
|
419
|
+
name: 'vaultSystemState',
|
420
|
+
isMut: true,
|
421
|
+
isSigner: false
|
422
|
+
},
|
423
|
+
{
|
424
|
+
name: 'vaultAccount',
|
425
|
+
isMut: true,
|
426
|
+
isSigner: false
|
427
|
+
},
|
428
|
+
{
|
429
|
+
name: 'history',
|
430
|
+
isMut: true,
|
431
|
+
isSigner: true
|
432
|
+
},
|
433
|
+
{
|
434
|
+
name: 'vaultOwner',
|
435
|
+
isMut: true,
|
436
|
+
isSigner: true
|
437
|
+
},
|
438
|
+
{
|
439
|
+
name: 'systemProgram',
|
440
|
+
isMut: false,
|
441
|
+
isSigner: false
|
442
|
+
}
|
443
|
+
],
|
444
|
+
args: [
|
445
|
+
{
|
446
|
+
name: 'depositAmount',
|
447
|
+
type: 'u64'
|
448
|
+
}
|
449
|
+
]
|
450
|
+
},
|
451
|
+
{
|
452
|
+
name: 'withdrawVault',
|
453
|
+
accounts: [
|
454
|
+
{
|
455
|
+
name: 'vaultSystemState',
|
456
|
+
isMut: true,
|
457
|
+
isSigner: false
|
458
|
+
},
|
459
|
+
{
|
460
|
+
name: 'vaultAccount',
|
461
|
+
isMut: true,
|
462
|
+
isSigner: false
|
463
|
+
},
|
464
|
+
{
|
465
|
+
name: 'history',
|
466
|
+
isMut: true,
|
467
|
+
isSigner: true
|
468
|
+
},
|
469
|
+
{
|
470
|
+
name: 'chainlinkFeedAccount',
|
471
|
+
isMut: false,
|
472
|
+
isSigner: false
|
473
|
+
},
|
474
|
+
{
|
475
|
+
name: 'vaultOwner',
|
476
|
+
isMut: true,
|
477
|
+
isSigner: true
|
478
|
+
},
|
479
|
+
{
|
480
|
+
name: 'systemProgram',
|
481
|
+
isMut: false,
|
482
|
+
isSigner: false
|
483
|
+
}
|
484
|
+
],
|
485
|
+
args: [
|
486
|
+
{
|
487
|
+
name: 'withdrawAmount',
|
488
|
+
type: 'u64'
|
489
|
+
},
|
490
|
+
{
|
491
|
+
name: 'overrideSolPrice',
|
492
|
+
type: 'u64'
|
493
|
+
}
|
494
|
+
]
|
495
|
+
},
|
496
|
+
{
|
497
|
+
name: 'loanVault',
|
498
|
+
accounts: [
|
499
|
+
{
|
500
|
+
name: 'vaultSystemState',
|
501
|
+
isMut: true,
|
502
|
+
isSigner: false
|
503
|
+
},
|
504
|
+
{
|
505
|
+
name: 'vaultAccount',
|
506
|
+
isMut: true,
|
507
|
+
isSigner: false
|
508
|
+
},
|
509
|
+
{
|
510
|
+
name: 'history',
|
511
|
+
isMut: true,
|
512
|
+
isSigner: true
|
513
|
+
},
|
514
|
+
{
|
515
|
+
name: 'feePool',
|
516
|
+
isMut: true,
|
517
|
+
isSigner: false
|
518
|
+
},
|
519
|
+
{
|
520
|
+
name: 'feePoolAssociatedUsdhTokenAccount',
|
521
|
+
isMut: true,
|
522
|
+
isSigner: false
|
523
|
+
},
|
524
|
+
{
|
525
|
+
name: 'usdhMint',
|
526
|
+
isMut: true,
|
527
|
+
isSigner: false
|
528
|
+
},
|
529
|
+
{
|
530
|
+
name: 'vaultOwner',
|
531
|
+
isMut: true,
|
532
|
+
isSigner: true
|
533
|
+
},
|
534
|
+
{
|
535
|
+
name: 'ownerUsdhAccount',
|
536
|
+
isMut: true,
|
537
|
+
isSigner: false
|
538
|
+
},
|
539
|
+
{
|
540
|
+
name: 'chainlinkFeedAccount',
|
541
|
+
isMut: false,
|
542
|
+
isSigner: false
|
543
|
+
},
|
544
|
+
{
|
545
|
+
name: 'splTokenProgramInfo',
|
546
|
+
isMut: false,
|
547
|
+
isSigner: false
|
548
|
+
},
|
549
|
+
{
|
550
|
+
name: 'systemProgram',
|
551
|
+
isMut: false,
|
552
|
+
isSigner: false
|
553
|
+
}
|
554
|
+
],
|
555
|
+
args: [
|
556
|
+
{
|
557
|
+
name: 'loanAmount',
|
558
|
+
type: 'u64'
|
559
|
+
},
|
560
|
+
{
|
561
|
+
name: 'overrideSolPrice',
|
562
|
+
type: 'u64'
|
563
|
+
}
|
564
|
+
]
|
565
|
+
},
|
566
|
+
{
|
567
|
+
name: 'repayVault',
|
568
|
+
accounts: [
|
569
|
+
{
|
570
|
+
name: 'vaultSystemState',
|
571
|
+
isMut: true,
|
572
|
+
isSigner: false
|
573
|
+
},
|
574
|
+
{
|
575
|
+
name: 'vaultAccount',
|
576
|
+
isMut: true,
|
577
|
+
isSigner: false
|
578
|
+
},
|
579
|
+
{
|
580
|
+
name: 'history',
|
581
|
+
isMut: true,
|
582
|
+
isSigner: true
|
583
|
+
},
|
584
|
+
{
|
585
|
+
name: 'usdhMint',
|
586
|
+
isMut: true,
|
587
|
+
isSigner: false
|
588
|
+
},
|
589
|
+
{
|
590
|
+
name: 'vaultOwner',
|
591
|
+
isMut: true,
|
592
|
+
isSigner: true
|
593
|
+
},
|
594
|
+
{
|
595
|
+
name: 'ownerUsdhAccount',
|
596
|
+
isMut: true,
|
597
|
+
isSigner: false
|
598
|
+
},
|
599
|
+
{
|
600
|
+
name: 'splTokenProgramInfo',
|
601
|
+
isMut: false,
|
602
|
+
isSigner: false
|
603
|
+
},
|
604
|
+
{
|
605
|
+
name: 'systemProgram',
|
606
|
+
isMut: false,
|
607
|
+
isSigner: false
|
608
|
+
}
|
609
|
+
],
|
610
|
+
args: [
|
611
|
+
{
|
612
|
+
name: 'repayAmount',
|
613
|
+
type: 'u64'
|
614
|
+
}
|
615
|
+
]
|
616
|
+
},
|
617
|
+
{
|
618
|
+
name: 'redeemVault',
|
619
|
+
accounts: [
|
620
|
+
{
|
621
|
+
name: 'vaultSystemState',
|
622
|
+
isMut: true,
|
623
|
+
isSigner: false
|
624
|
+
},
|
625
|
+
{
|
626
|
+
name: 'vaultAccount',
|
627
|
+
isMut: true,
|
628
|
+
isSigner: false
|
629
|
+
},
|
630
|
+
{
|
631
|
+
name: 'history',
|
632
|
+
isMut: true,
|
633
|
+
isSigner: true
|
634
|
+
},
|
635
|
+
{
|
636
|
+
name: 'usdhMint',
|
637
|
+
isMut: true,
|
638
|
+
isSigner: false
|
639
|
+
},
|
640
|
+
{
|
641
|
+
name: 'feePool',
|
642
|
+
isMut: true,
|
643
|
+
isSigner: false
|
644
|
+
},
|
645
|
+
{
|
646
|
+
name: 'feePoolAssociatedUsdhTokenAccount',
|
647
|
+
isMut: true,
|
648
|
+
isSigner: false
|
649
|
+
},
|
650
|
+
{
|
651
|
+
name: 'payer',
|
652
|
+
isMut: true,
|
653
|
+
isSigner: true
|
654
|
+
},
|
655
|
+
{
|
656
|
+
name: 'payerUsdhAccount',
|
657
|
+
isMut: true,
|
658
|
+
isSigner: false
|
659
|
+
},
|
660
|
+
{
|
661
|
+
name: 'chainlinkFeedAccount',
|
662
|
+
isMut: false,
|
663
|
+
isSigner: false
|
664
|
+
},
|
665
|
+
{
|
666
|
+
name: 'splTokenProgramInfo',
|
667
|
+
isMut: false,
|
668
|
+
isSigner: false
|
669
|
+
},
|
670
|
+
{
|
671
|
+
name: 'systemProgram',
|
672
|
+
isMut: false,
|
673
|
+
isSigner: false
|
674
|
+
}
|
675
|
+
],
|
676
|
+
args: [
|
677
|
+
{
|
678
|
+
name: 'redeemPayUsdh',
|
679
|
+
type: 'u64'
|
680
|
+
},
|
681
|
+
{
|
682
|
+
name: 'overrideSolPrice',
|
683
|
+
type: 'u64'
|
684
|
+
},
|
685
|
+
{
|
686
|
+
name: 'overrideCurrentTime',
|
687
|
+
type: 'i64'
|
688
|
+
}
|
689
|
+
]
|
690
|
+
},
|
691
|
+
{
|
692
|
+
name: 'depositLiquidityPool',
|
693
|
+
accounts: [
|
694
|
+
{
|
695
|
+
name: 'poolState',
|
696
|
+
isMut: true,
|
697
|
+
isSigner: false
|
698
|
+
},
|
699
|
+
{
|
700
|
+
name: 'poolUsdhAccount',
|
701
|
+
isMut: true,
|
702
|
+
isSigner: false
|
703
|
+
},
|
704
|
+
{
|
705
|
+
name: 'poolEra',
|
706
|
+
isMut: true,
|
707
|
+
isSigner: false
|
708
|
+
},
|
709
|
+
{
|
710
|
+
name: 'poolPosition',
|
711
|
+
isMut: true,
|
712
|
+
isSigner: true
|
713
|
+
},
|
714
|
+
{
|
715
|
+
name: 'payer',
|
716
|
+
isMut: true,
|
717
|
+
isSigner: true
|
718
|
+
},
|
719
|
+
{
|
720
|
+
name: 'ownerUsdhAccount',
|
721
|
+
isMut: true,
|
722
|
+
isSigner: false
|
723
|
+
},
|
724
|
+
{
|
725
|
+
name: 'splTokenProgramInfo',
|
726
|
+
isMut: false,
|
727
|
+
isSigner: false
|
728
|
+
},
|
729
|
+
{
|
730
|
+
name: 'systemProgram',
|
731
|
+
isMut: false,
|
732
|
+
isSigner: false
|
733
|
+
}
|
734
|
+
],
|
735
|
+
args: [
|
736
|
+
{
|
737
|
+
name: 'depositAmount',
|
738
|
+
type: 'u64'
|
739
|
+
},
|
740
|
+
{
|
741
|
+
name: 'overrideCurrentTime',
|
742
|
+
type: 'i64'
|
743
|
+
}
|
744
|
+
]
|
745
|
+
},
|
746
|
+
{
|
747
|
+
name: 'liquidateVault',
|
748
|
+
accounts: [
|
749
|
+
{
|
750
|
+
name: 'vaultSystemState',
|
751
|
+
isMut: true,
|
752
|
+
isSigner: false
|
753
|
+
},
|
754
|
+
{
|
755
|
+
name: 'vaultAccount',
|
756
|
+
isMut: true,
|
757
|
+
isSigner: false
|
758
|
+
},
|
759
|
+
{
|
760
|
+
name: 'poolState',
|
761
|
+
isMut: true,
|
762
|
+
isSigner: false
|
763
|
+
},
|
764
|
+
{
|
765
|
+
name: 'feePool',
|
766
|
+
isMut: true,
|
767
|
+
isSigner: false
|
768
|
+
},
|
769
|
+
{
|
770
|
+
name: 'poolUsdhAccount',
|
771
|
+
isMut: true,
|
772
|
+
isSigner: false
|
773
|
+
},
|
774
|
+
{
|
775
|
+
name: 'usdhMint',
|
776
|
+
isMut: true,
|
777
|
+
isSigner: false
|
778
|
+
},
|
779
|
+
{
|
780
|
+
name: 'poolEra',
|
781
|
+
isMut: true,
|
782
|
+
isSigner: false
|
783
|
+
},
|
784
|
+
{
|
785
|
+
name: 'newEra',
|
786
|
+
isMut: true,
|
787
|
+
isSigner: true
|
788
|
+
},
|
789
|
+
{
|
790
|
+
name: 'chainlinkFeedAccount',
|
791
|
+
isMut: false,
|
792
|
+
isSigner: false
|
793
|
+
},
|
794
|
+
{
|
795
|
+
name: 'history',
|
796
|
+
isMut: true,
|
797
|
+
isSigner: true
|
798
|
+
},
|
799
|
+
{
|
800
|
+
name: 'payer',
|
801
|
+
isMut: true,
|
802
|
+
isSigner: true
|
803
|
+
},
|
804
|
+
{
|
805
|
+
name: 'splTokenProgramInfo',
|
806
|
+
isMut: false,
|
807
|
+
isSigner: false
|
808
|
+
},
|
809
|
+
{
|
810
|
+
name: 'systemProgram',
|
811
|
+
isMut: false,
|
812
|
+
isSigner: false
|
813
|
+
}
|
814
|
+
],
|
815
|
+
args: [
|
816
|
+
{
|
817
|
+
name: 'overrideSolPrice',
|
818
|
+
type: 'u64'
|
819
|
+
}
|
820
|
+
]
|
821
|
+
},
|
822
|
+
{
|
823
|
+
name: 'withdrawLiquidity',
|
824
|
+
accounts: [
|
825
|
+
{
|
826
|
+
name: 'poolState',
|
827
|
+
isMut: true,
|
828
|
+
isSigner: false
|
829
|
+
},
|
830
|
+
{
|
831
|
+
name: 'poolEra',
|
832
|
+
isMut: true,
|
833
|
+
isSigner: false
|
834
|
+
},
|
835
|
+
{
|
836
|
+
name: 'poolPosition',
|
837
|
+
isMut: true,
|
838
|
+
isSigner: false
|
839
|
+
},
|
840
|
+
{
|
841
|
+
name: 'poolUsdhAccount',
|
842
|
+
isMut: true,
|
843
|
+
isSigner: false
|
844
|
+
},
|
845
|
+
{
|
846
|
+
name: 'payer',
|
847
|
+
isMut: true,
|
848
|
+
isSigner: true
|
849
|
+
},
|
850
|
+
{
|
851
|
+
name: 'ownerUsdhAccount',
|
852
|
+
isMut: true,
|
853
|
+
isSigner: false
|
854
|
+
},
|
855
|
+
{
|
856
|
+
name: 'hedgeMint',
|
857
|
+
isMut: true,
|
858
|
+
isSigner: false
|
859
|
+
},
|
860
|
+
{
|
861
|
+
name: 'payerAssociatedHedgeAccount',
|
862
|
+
isMut: true,
|
863
|
+
isSigner: false
|
864
|
+
},
|
865
|
+
{
|
866
|
+
name: 'rent',
|
867
|
+
isMut: false,
|
868
|
+
isSigner: false
|
869
|
+
},
|
870
|
+
{
|
871
|
+
name: 'splTokenProgramInfo',
|
872
|
+
isMut: false,
|
873
|
+
isSigner: false
|
874
|
+
},
|
875
|
+
{
|
876
|
+
name: 'splAssociatedTokenProgramInfo',
|
877
|
+
isMut: false,
|
878
|
+
isSigner: false
|
879
|
+
},
|
880
|
+
{
|
881
|
+
name: 'systemProgram',
|
882
|
+
isMut: false,
|
883
|
+
isSigner: false
|
884
|
+
}
|
885
|
+
],
|
886
|
+
args: [
|
887
|
+
{
|
888
|
+
name: 'overrideCurrentTime',
|
889
|
+
type: 'i64'
|
890
|
+
}
|
891
|
+
]
|
892
|
+
}
|
893
|
+
],
|
894
|
+
accounts: [
|
895
|
+
{
|
896
|
+
name: 'StakingPool',
|
897
|
+
type: {
|
898
|
+
kind: 'struct',
|
899
|
+
fields: [
|
900
|
+
{
|
901
|
+
name: 'deposits',
|
902
|
+
type: 'u64'
|
903
|
+
},
|
904
|
+
{
|
905
|
+
name: 'bump',
|
906
|
+
type: 'u8'
|
907
|
+
},
|
908
|
+
{
|
909
|
+
name: 'seedPhrase',
|
910
|
+
type: 'string'
|
911
|
+
},
|
912
|
+
{
|
913
|
+
name: 'hedgeRewardAccumulator',
|
914
|
+
type: 'u128'
|
915
|
+
},
|
916
|
+
{
|
917
|
+
name: 'usdhFeeAccumulator',
|
918
|
+
type: 'u128'
|
919
|
+
},
|
920
|
+
{
|
921
|
+
name: 'solFeeAccumulator',
|
922
|
+
type: 'u128'
|
923
|
+
},
|
924
|
+
{
|
925
|
+
name: 'startTime',
|
926
|
+
type: 'i64'
|
927
|
+
},
|
928
|
+
{
|
929
|
+
name: 'lastTransactionTime',
|
930
|
+
type: 'i64'
|
931
|
+
},
|
932
|
+
{
|
933
|
+
name: 'halfLifeInDays',
|
934
|
+
type: 'u64'
|
935
|
+
},
|
936
|
+
{
|
937
|
+
name: 'totalHedgeReward',
|
938
|
+
type: 'u64'
|
939
|
+
},
|
940
|
+
{
|
941
|
+
name: 'stakedTokenMint',
|
942
|
+
type: 'publicKey'
|
943
|
+
}
|
944
|
+
]
|
945
|
+
}
|
946
|
+
},
|
947
|
+
{
|
948
|
+
name: 'StakingPoolPosition',
|
949
|
+
type: {
|
950
|
+
kind: 'struct',
|
951
|
+
fields: [
|
952
|
+
{
|
953
|
+
name: 'state',
|
954
|
+
type: {
|
955
|
+
defined: 'PositionState'
|
956
|
+
}
|
957
|
+
},
|
958
|
+
{
|
959
|
+
name: 'owner',
|
960
|
+
type: 'publicKey'
|
961
|
+
},
|
962
|
+
{
|
963
|
+
name: 'pool',
|
964
|
+
type: 'publicKey'
|
965
|
+
},
|
966
|
+
{
|
967
|
+
name: 'deposited',
|
968
|
+
type: 'u64'
|
969
|
+
},
|
970
|
+
{
|
971
|
+
name: 'startHedgeRewardAccumulator',
|
972
|
+
type: 'u128'
|
973
|
+
},
|
974
|
+
{
|
975
|
+
name: 'startUsdhFeeAccumulator',
|
976
|
+
type: 'u128'
|
977
|
+
},
|
978
|
+
{
|
979
|
+
name: 'startSolFeeAccumulator',
|
980
|
+
type: 'u128'
|
981
|
+
},
|
982
|
+
{
|
983
|
+
name: 'timestampOpened',
|
984
|
+
type: 'i64'
|
985
|
+
},
|
986
|
+
{
|
987
|
+
name: 'timestampClosed',
|
988
|
+
type: 'i64'
|
989
|
+
},
|
990
|
+
{
|
991
|
+
name: 'closedRewardedTokens',
|
992
|
+
type: 'u64'
|
993
|
+
}
|
994
|
+
]
|
995
|
+
}
|
996
|
+
},
|
997
|
+
{
|
998
|
+
name: 'VaultSystemState',
|
999
|
+
type: {
|
1000
|
+
kind: 'struct',
|
1001
|
+
fields: [
|
1002
|
+
{
|
1003
|
+
name: 'lastRedeemFeeBytes',
|
1004
|
+
type: 'u128'
|
1005
|
+
},
|
1006
|
+
{
|
1007
|
+
name: 'lastRedeemTimestamp',
|
1008
|
+
type: 'i64'
|
1009
|
+
},
|
1010
|
+
{
|
1011
|
+
name: 'totalCollateral',
|
1012
|
+
type: 'u64'
|
1013
|
+
},
|
1014
|
+
{
|
1015
|
+
name: 'totalUsdhSupply',
|
1016
|
+
type: 'u64'
|
1017
|
+
},
|
1018
|
+
{
|
1019
|
+
name: 'totalVaults',
|
1020
|
+
type: 'u64'
|
1021
|
+
},
|
1022
|
+
{
|
1023
|
+
name: 'totalVaultsClosed',
|
1024
|
+
type: 'u64'
|
1025
|
+
},
|
1026
|
+
{
|
1027
|
+
name: 'debtRedistributionProduct',
|
1028
|
+
type: 'u128'
|
1029
|
+
},
|
1030
|
+
{
|
1031
|
+
name: 'collateralRedistributionAccumulator',
|
1032
|
+
type: 'u128'
|
1033
|
+
},
|
1034
|
+
{
|
1035
|
+
name: 'debtRedistributionError',
|
1036
|
+
type: 'u64'
|
1037
|
+
},
|
1038
|
+
{
|
1039
|
+
name: 'bumpVaultState',
|
1040
|
+
type: 'u8'
|
1041
|
+
},
|
1042
|
+
{
|
1043
|
+
name: 'bumpPoolState',
|
1044
|
+
type: 'u8'
|
1045
|
+
},
|
1046
|
+
{
|
1047
|
+
name: 'bumpMint',
|
1048
|
+
type: 'u8'
|
1049
|
+
},
|
1050
|
+
{
|
1051
|
+
name: 'bumpUsdhPoolAccount',
|
1052
|
+
type: 'u8'
|
1053
|
+
},
|
1054
|
+
{
|
1055
|
+
name: 'authority',
|
1056
|
+
type: 'publicKey'
|
1057
|
+
},
|
1058
|
+
{
|
1059
|
+
name: 'oracleChainlink',
|
1060
|
+
type: 'publicKey'
|
1061
|
+
},
|
1062
|
+
{
|
1063
|
+
name: 'oraclePyth',
|
1064
|
+
type: 'publicKey'
|
1065
|
+
},
|
1066
|
+
{
|
1067
|
+
name: 'oracleSwitchboard',
|
1068
|
+
type: 'publicKey'
|
1069
|
+
},
|
1070
|
+
{
|
1071
|
+
name: 'hedgeStakingPool',
|
1072
|
+
type: 'publicKey'
|
1073
|
+
}
|
1074
|
+
]
|
1075
|
+
}
|
1076
|
+
},
|
1077
|
+
{
|
1078
|
+
name: 'Vault',
|
1079
|
+
type: {
|
1080
|
+
kind: 'struct',
|
1081
|
+
fields: [
|
1082
|
+
{
|
1083
|
+
name: 'vaultOwner',
|
1084
|
+
type: 'publicKey'
|
1085
|
+
},
|
1086
|
+
{
|
1087
|
+
name: 'deposited',
|
1088
|
+
type: 'u64'
|
1089
|
+
},
|
1090
|
+
{
|
1091
|
+
name: 'debt',
|
1092
|
+
type: 'u64'
|
1093
|
+
},
|
1094
|
+
{
|
1095
|
+
name: 'vaultVersion',
|
1096
|
+
type: 'u64'
|
1097
|
+
},
|
1098
|
+
{
|
1099
|
+
name: 'liquidationPrice',
|
1100
|
+
type: 'u64'
|
1101
|
+
},
|
1102
|
+
{
|
1103
|
+
name: 'minCollateralRatio',
|
1104
|
+
type: 'u128'
|
1105
|
+
},
|
1106
|
+
{
|
1107
|
+
name: 'debtProductSnapshotBytes',
|
1108
|
+
type: 'u128'
|
1109
|
+
},
|
1110
|
+
{
|
1111
|
+
name: 'collateralAccumulatorSnapshotBytes',
|
1112
|
+
type: 'u128'
|
1113
|
+
},
|
1114
|
+
{
|
1115
|
+
name: 'collateralType',
|
1116
|
+
type: {
|
1117
|
+
defined: 'CurrencyType'
|
1118
|
+
}
|
1119
|
+
},
|
1120
|
+
{
|
1121
|
+
name: 'debtType',
|
1122
|
+
type: {
|
1123
|
+
defined: 'CurrencyType'
|
1124
|
+
}
|
1125
|
+
},
|
1126
|
+
{
|
1127
|
+
name: 'vaultStatus',
|
1128
|
+
type: {
|
1129
|
+
defined: 'VaultStatus'
|
1130
|
+
}
|
1131
|
+
}
|
1132
|
+
]
|
1133
|
+
}
|
1134
|
+
},
|
1135
|
+
{
|
1136
|
+
name: 'VaultHistoryEvent',
|
1137
|
+
type: {
|
1138
|
+
kind: 'struct',
|
1139
|
+
fields: [
|
1140
|
+
{
|
1141
|
+
name: 'vaultAccount',
|
1142
|
+
type: 'publicKey'
|
1143
|
+
},
|
1144
|
+
{
|
1145
|
+
name: 'actorAccount',
|
1146
|
+
type: 'publicKey'
|
1147
|
+
},
|
1148
|
+
{
|
1149
|
+
name: 'usdSolPrice',
|
1150
|
+
type: 'u128'
|
1151
|
+
},
|
1152
|
+
{
|
1153
|
+
name: 'usdhDebtBefore',
|
1154
|
+
type: 'u64'
|
1155
|
+
},
|
1156
|
+
{
|
1157
|
+
name: 'usdhDebtAfter',
|
1158
|
+
type: 'u64'
|
1159
|
+
},
|
1160
|
+
{
|
1161
|
+
name: 'solBalanceBefore',
|
1162
|
+
type: 'u64'
|
1163
|
+
},
|
1164
|
+
{
|
1165
|
+
name: 'solBalanceAfter',
|
1166
|
+
type: 'u64'
|
1167
|
+
},
|
1168
|
+
{
|
1169
|
+
name: 'minCollateralRatioBefore',
|
1170
|
+
type: 'u128'
|
1171
|
+
},
|
1172
|
+
{
|
1173
|
+
name: 'minCollateralRatioAfter',
|
1174
|
+
type: 'u128'
|
1175
|
+
},
|
1176
|
+
{
|
1177
|
+
name: 'vaultStateBefore',
|
1178
|
+
type: {
|
1179
|
+
defined: 'VaultStatus'
|
1180
|
+
}
|
1181
|
+
},
|
1182
|
+
{
|
1183
|
+
name: 'vaultStateAfter',
|
1184
|
+
type: {
|
1185
|
+
defined: 'VaultStatus'
|
1186
|
+
}
|
1187
|
+
},
|
1188
|
+
{
|
1189
|
+
name: 'timestamp',
|
1190
|
+
type: 'i64'
|
1191
|
+
},
|
1192
|
+
{
|
1193
|
+
name: 'action',
|
1194
|
+
type: {
|
1195
|
+
defined: 'VaultHistoryAction'
|
1196
|
+
}
|
1197
|
+
}
|
1198
|
+
]
|
1199
|
+
}
|
1200
|
+
},
|
1201
|
+
{
|
1202
|
+
name: 'LiquidationPoolState',
|
1203
|
+
type: {
|
1204
|
+
kind: 'struct',
|
1205
|
+
fields: [
|
1206
|
+
{
|
1207
|
+
name: 'currentEra',
|
1208
|
+
type: 'publicKey'
|
1209
|
+
},
|
1210
|
+
{
|
1211
|
+
name: 'lifetimeDeposits',
|
1212
|
+
type: 'u64'
|
1213
|
+
},
|
1214
|
+
{
|
1215
|
+
name: 'lifetimeOpenedPositions',
|
1216
|
+
type: 'u64'
|
1217
|
+
},
|
1218
|
+
{
|
1219
|
+
name: 'lifetimeClosedPositions',
|
1220
|
+
type: 'u64'
|
1221
|
+
},
|
1222
|
+
{
|
1223
|
+
name: 'lifetimeVaultsLiquidated',
|
1224
|
+
type: 'u64'
|
1225
|
+
},
|
1226
|
+
{
|
1227
|
+
name: 'lifetimeVaultsRedistributed',
|
1228
|
+
type: 'u64'
|
1229
|
+
},
|
1230
|
+
{
|
1231
|
+
name: 'lifetimeSolPurchased',
|
1232
|
+
type: 'u64'
|
1233
|
+
},
|
1234
|
+
{
|
1235
|
+
name: 'lifetimeSolClaimed',
|
1236
|
+
type: 'u64'
|
1237
|
+
},
|
1238
|
+
{
|
1239
|
+
name: 'hedgeInitRewardsTimestamp',
|
1240
|
+
type: 'i64'
|
1241
|
+
}
|
1242
|
+
]
|
1243
|
+
}
|
1244
|
+
},
|
1245
|
+
{
|
1246
|
+
name: 'LiquidationPoolEra',
|
1247
|
+
type: {
|
1248
|
+
kind: 'struct',
|
1249
|
+
fields: [
|
1250
|
+
{
|
1251
|
+
name: 'totalDeposits',
|
1252
|
+
type: 'u64'
|
1253
|
+
},
|
1254
|
+
{
|
1255
|
+
name: 'productBytes',
|
1256
|
+
type: 'u128'
|
1257
|
+
},
|
1258
|
+
{
|
1259
|
+
name: 'sumBytes',
|
1260
|
+
type: 'u128'
|
1261
|
+
},
|
1262
|
+
{
|
1263
|
+
name: 'hedgeRewardsAccumulatorBytes',
|
1264
|
+
type: 'u128'
|
1265
|
+
},
|
1266
|
+
{
|
1267
|
+
name: 'hedgeRewardsTimestamp',
|
1268
|
+
type: 'i64'
|
1269
|
+
}
|
1270
|
+
]
|
1271
|
+
}
|
1272
|
+
},
|
1273
|
+
{
|
1274
|
+
name: 'LiquidationPosition',
|
1275
|
+
type: {
|
1276
|
+
kind: 'struct',
|
1277
|
+
fields: [
|
1278
|
+
{
|
1279
|
+
name: 'state',
|
1280
|
+
type: {
|
1281
|
+
defined: 'PositionState'
|
1282
|
+
}
|
1283
|
+
},
|
1284
|
+
{
|
1285
|
+
name: 'era',
|
1286
|
+
type: 'publicKey'
|
1287
|
+
},
|
1288
|
+
{
|
1289
|
+
name: 'ownerAccount',
|
1290
|
+
type: 'publicKey'
|
1291
|
+
},
|
1292
|
+
{
|
1293
|
+
name: 'deposit',
|
1294
|
+
type: 'u64'
|
1295
|
+
},
|
1296
|
+
{
|
1297
|
+
name: 'closedSol',
|
1298
|
+
type: 'u64'
|
1299
|
+
},
|
1300
|
+
{
|
1301
|
+
name: 'closedUsdh',
|
1302
|
+
type: 'u64'
|
1303
|
+
},
|
1304
|
+
{
|
1305
|
+
name: 'productSnapshotBytes',
|
1306
|
+
type: 'u128'
|
1307
|
+
},
|
1308
|
+
{
|
1309
|
+
name: 'sumSnapshotBytes',
|
1310
|
+
type: 'u128'
|
1311
|
+
},
|
1312
|
+
{
|
1313
|
+
name: 'hedgeRewardsSnapshotAccum',
|
1314
|
+
type: 'u128'
|
1315
|
+
},
|
1316
|
+
{
|
1317
|
+
name: 'timestampOpened',
|
1318
|
+
type: 'i64'
|
1319
|
+
},
|
1320
|
+
{
|
1321
|
+
name: 'timestampClosed',
|
1322
|
+
type: 'i64'
|
1323
|
+
}
|
1324
|
+
]
|
1325
|
+
}
|
1326
|
+
},
|
1327
|
+
{
|
1328
|
+
name: 'Aggregator',
|
1329
|
+
type: {
|
1330
|
+
kind: 'struct',
|
1331
|
+
fields: [
|
1332
|
+
{
|
1333
|
+
name: 'isInitialized',
|
1334
|
+
type: 'bool'
|
1335
|
+
},
|
1336
|
+
{
|
1337
|
+
name: 'version',
|
1338
|
+
type: 'u32'
|
1339
|
+
},
|
1340
|
+
{
|
1341
|
+
name: 'config',
|
1342
|
+
type: {
|
1343
|
+
defined: 'Config'
|
1344
|
+
}
|
1345
|
+
},
|
1346
|
+
{
|
1347
|
+
name: 'updatedAt',
|
1348
|
+
type: 'i64'
|
1349
|
+
},
|
1350
|
+
{
|
1351
|
+
name: 'owner',
|
1352
|
+
type: 'publicKey'
|
1353
|
+
},
|
1354
|
+
{
|
1355
|
+
name: 'submissions',
|
1356
|
+
type: {
|
1357
|
+
array: [
|
1358
|
+
{
|
1359
|
+
defined: 'Submission'
|
1360
|
+
},
|
1361
|
+
8
|
1362
|
+
]
|
1363
|
+
}
|
1364
|
+
},
|
1365
|
+
{
|
1366
|
+
name: 'answer',
|
1367
|
+
type: {
|
1368
|
+
option: 'u128'
|
1369
|
+
}
|
1370
|
+
}
|
1371
|
+
]
|
1372
|
+
}
|
1373
|
+
}
|
1374
|
+
],
|
1375
|
+
types: [
|
1376
|
+
{
|
1377
|
+
name: 'Config',
|
1378
|
+
type: {
|
1379
|
+
kind: 'struct',
|
1380
|
+
fields: [
|
1381
|
+
{
|
1382
|
+
name: 'oracles',
|
1383
|
+
type: {
|
1384
|
+
vec: 'publicKey'
|
1385
|
+
}
|
1386
|
+
},
|
1387
|
+
{
|
1388
|
+
name: 'minAnswerThreshold',
|
1389
|
+
type: 'u8'
|
1390
|
+
},
|
1391
|
+
{
|
1392
|
+
name: 'stalenessThreshold',
|
1393
|
+
type: 'u8'
|
1394
|
+
},
|
1395
|
+
{
|
1396
|
+
name: 'decimals',
|
1397
|
+
type: 'u8'
|
1398
|
+
}
|
1399
|
+
]
|
1400
|
+
}
|
1401
|
+
},
|
1402
|
+
{
|
1403
|
+
name: 'Submission',
|
1404
|
+
type: {
|
1405
|
+
kind: 'struct',
|
1406
|
+
fields: [
|
1407
|
+
{
|
1408
|
+
name: 'timestamp',
|
1409
|
+
type: 'i64'
|
1410
|
+
},
|
1411
|
+
{
|
1412
|
+
name: 'value',
|
1413
|
+
type: 'u128'
|
1414
|
+
}
|
1415
|
+
]
|
1416
|
+
}
|
1417
|
+
},
|
1418
|
+
{
|
1419
|
+
name: 'PositionState',
|
1420
|
+
type: {
|
1421
|
+
kind: 'enum',
|
1422
|
+
variants: [
|
1423
|
+
{
|
1424
|
+
name: 'Open'
|
1425
|
+
},
|
1426
|
+
{
|
1427
|
+
name: 'Closed'
|
1428
|
+
}
|
1429
|
+
]
|
1430
|
+
}
|
1431
|
+
},
|
1432
|
+
{
|
1433
|
+
name: 'CurrencyType',
|
1434
|
+
type: {
|
1435
|
+
kind: 'enum',
|
1436
|
+
variants: [
|
1437
|
+
{
|
1438
|
+
name: 'Solana'
|
1439
|
+
},
|
1440
|
+
{
|
1441
|
+
name: 'Usdh'
|
1442
|
+
}
|
1443
|
+
]
|
1444
|
+
}
|
1445
|
+
},
|
1446
|
+
{
|
1447
|
+
name: 'VaultStatus',
|
1448
|
+
type: {
|
1449
|
+
kind: 'enum',
|
1450
|
+
variants: [
|
1451
|
+
{
|
1452
|
+
name: 'Open'
|
1453
|
+
},
|
1454
|
+
{
|
1455
|
+
name: 'Closed'
|
1456
|
+
},
|
1457
|
+
{
|
1458
|
+
name: 'Liquidated'
|
1459
|
+
},
|
1460
|
+
{
|
1461
|
+
name: 'Distributed'
|
1462
|
+
},
|
1463
|
+
{
|
1464
|
+
name: 'Redeemed'
|
1465
|
+
}
|
1466
|
+
]
|
1467
|
+
}
|
1468
|
+
},
|
1469
|
+
{
|
1470
|
+
name: 'VaultHistoryAction',
|
1471
|
+
type: {
|
1472
|
+
kind: 'enum',
|
1473
|
+
variants: [
|
1474
|
+
{
|
1475
|
+
name: 'Create'
|
1476
|
+
},
|
1477
|
+
{
|
1478
|
+
name: 'Close'
|
1479
|
+
},
|
1480
|
+
{
|
1481
|
+
name: 'Liquidate'
|
1482
|
+
},
|
1483
|
+
{
|
1484
|
+
name: 'PartialLiquidate'
|
1485
|
+
},
|
1486
|
+
{
|
1487
|
+
name: 'Distributed'
|
1488
|
+
},
|
1489
|
+
{
|
1490
|
+
name: 'Redeem'
|
1491
|
+
},
|
1492
|
+
{
|
1493
|
+
name: 'TransferOwnership'
|
1494
|
+
},
|
1495
|
+
{
|
1496
|
+
name: 'Deposit'
|
1497
|
+
},
|
1498
|
+
{
|
1499
|
+
name: 'Withdraw'
|
1500
|
+
},
|
1501
|
+
{
|
1502
|
+
name: 'Loan'
|
1503
|
+
},
|
1504
|
+
{
|
1505
|
+
name: 'RepayCredit'
|
1506
|
+
}
|
1507
|
+
]
|
1508
|
+
}
|
1509
|
+
}
|
1510
|
+
],
|
1511
|
+
errors: [
|
1512
|
+
{
|
1513
|
+
code: 6000,
|
1514
|
+
name: 'AlreadyInitialized',
|
1515
|
+
msg: 'This vault was already initialized'
|
1516
|
+
},
|
1517
|
+
{
|
1518
|
+
code: 6001,
|
1519
|
+
name: 'NotInitialized',
|
1520
|
+
msg: 'This vault was not initialized'
|
1521
|
+
},
|
1522
|
+
{
|
1523
|
+
code: 6002,
|
1524
|
+
name: 'Overdraw',
|
1525
|
+
msg: 'Cannot withdraw more than deposited'
|
1526
|
+
},
|
1527
|
+
{
|
1528
|
+
code: 6003,
|
1529
|
+
name: 'Overpaid',
|
1530
|
+
msg: 'Cannot repay more than loaned'
|
1531
|
+
},
|
1532
|
+
{
|
1533
|
+
code: 6004,
|
1534
|
+
name: 'NotAuthorizedToCreateStakingPools',
|
1535
|
+
msg: 'Signer not authorized to create new staking pools'
|
1536
|
+
},
|
1537
|
+
{
|
1538
|
+
code: 6005,
|
1539
|
+
name: 'BadSeed',
|
1540
|
+
msg: 'Bad Seed'
|
1541
|
+
}
|
1542
|
+
]
|
1543
|
+
};
|
1544
|
+
|
1545
|
+
async function createVault(connection, payer, depositAmount, collateralRatio, confirmOptions) {
|
1546
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1547
|
+
const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1548
|
+
// Prep the user to get USDH back out at some point
|
1549
|
+
await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1550
|
+
const newVault = web3_js.Keypair.generate();
|
1551
|
+
const history = web3_js.Keypair.generate();
|
1552
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1553
|
+
const transaction = new web3_js.Transaction().add(createVaultInstruction(vaultSystemStatePublicKey, payer.publicKey, newVault.publicKey, history.publicKey, depositAmount, collateralRatio));
|
1554
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, newVault, history], confirmOptions);
|
1555
|
+
return newVault.publicKey;
|
1556
|
+
}
|
1557
|
+
function createVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount, collateralRatio) {
|
1558
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1559
|
+
const ix = program.instruction.createVault(new anchor.BN(depositAmount), new anchor.BN(collateralRatio), {
|
1560
|
+
accounts: {
|
1561
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1562
|
+
vault: vaultPublicKey,
|
1563
|
+
history: historyPublicKey,
|
1564
|
+
payer: payerPublicKey,
|
1565
|
+
systemProgram: web3_js.SystemProgram.programId
|
1566
|
+
},
|
1567
|
+
signers: []
|
1568
|
+
});
|
1569
|
+
return ix;
|
1570
|
+
}
|
1571
|
+
|
1572
|
+
async function depositVault(connection, payer, vaultPublicKey, depositAmount, confirmOptions) {
|
1573
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1574
|
+
const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1575
|
+
// Prep the user to get USDH back out at some point
|
1576
|
+
await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1577
|
+
const history = web3_js.Keypair.generate();
|
1578
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1579
|
+
const transaction = new web3_js.Transaction().add(depositVaultInstruction(vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, depositAmount));
|
1580
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
|
1581
|
+
return vaultPublicKey;
|
1582
|
+
}
|
1583
|
+
function depositVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount) {
|
1584
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1585
|
+
return program.instruction.depositVault(new anchor.BN(depositAmount), {
|
1586
|
+
accounts: {
|
1587
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1588
|
+
vaultAccount: vaultPublicKey,
|
1589
|
+
history: historyPublicKey,
|
1590
|
+
vaultOwner: payerPublicKey,
|
1591
|
+
systemProgram: web3_js.SystemProgram.programId
|
1592
|
+
},
|
1593
|
+
signers: []
|
1594
|
+
});
|
1595
|
+
}
|
1596
|
+
|
1597
|
+
async function withdrawVault(connection, payer, vaultPublicKey, withdrawAmount, chainlinkOverridePrice, confirmOptions) {
|
1598
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1599
|
+
const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1600
|
+
// Prep the user to get USDH back out at some point
|
1601
|
+
await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1602
|
+
const history = web3_js.Keypair.generate();
|
1603
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1604
|
+
const transaction = new web3_js.Transaction().add(withdrawVaultInstruction(vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, withdrawAmount, chainlinkOverridePrice));
|
1605
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
|
1606
|
+
return vaultPublicKey;
|
1607
|
+
}
|
1608
|
+
function withdrawVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaultPublickey, historyPublicKey, withdrawAmount, chainlinkOverridePrice) {
|
1609
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1610
|
+
return program.instruction.withdrawVault(new anchor.BN(withdrawAmount), new anchor.BN(chainlinkOverridePrice !== null && chainlinkOverridePrice !== void 0 ? chainlinkOverridePrice : 200 * web3_js.LAMPORTS_PER_SOL), {
|
1611
|
+
accounts: {
|
1612
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1613
|
+
vaultAccount: vaultPublickey,
|
1614
|
+
history: historyPublicKey,
|
1615
|
+
vaultOwner: payerPublicKey,
|
1616
|
+
chainlinkFeedAccount: CHAINLINK_SOL_USD_PUBLICKEY,
|
1617
|
+
systemProgram: web3_js.SystemProgram.programId
|
1618
|
+
},
|
1619
|
+
signers: []
|
1620
|
+
});
|
1621
|
+
}
|
1622
|
+
|
1623
|
+
async function loanVault(connection, payer, vaultPublicKey, loanAmount, chainlinkOverridePrice, confirmOptions) {
|
1624
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1625
|
+
const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1626
|
+
// Prep the user to get USDH back out at some point
|
1627
|
+
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1628
|
+
const history = web3_js.Keypair.generate();
|
1629
|
+
const transaction = new web3_js.Transaction().add(await loanVaultInstruction(payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, loanAmount, chainlinkOverridePrice));
|
1630
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
|
1631
|
+
return vaultPublicKey;
|
1632
|
+
}
|
1633
|
+
async function loanVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, loanAmount, chainlinkOverridePrice) {
|
1634
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1635
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1636
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1637
|
+
const [hedgeMintPublickey] = await getHedgeMintPublicKey();
|
1638
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
1639
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
1640
|
+
return program.instruction.loanVault(new anchor.BN(loanAmount), new anchor.BN(chainlinkOverridePrice !== null && chainlinkOverridePrice !== void 0 ? chainlinkOverridePrice : web3_js.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
1641
|
+
{
|
1642
|
+
accounts: {
|
1643
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1644
|
+
vaultAccount: vaultPublickey,
|
1645
|
+
history: historyPublicKey,
|
1646
|
+
feePool: hedgeStakingPoolPublicKey,
|
1647
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
1648
|
+
usdhMint: usdhMintPublickey,
|
1649
|
+
vaultOwner: payerPublicKey,
|
1650
|
+
ownerUsdhAccount: ownerUsdhAccount,
|
1651
|
+
chainlinkFeedAccount: CHAINLINK_SOL_USD_PUBLICKEY,
|
1652
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1653
|
+
systemProgram: web3_js.SystemProgram.programId
|
1654
|
+
},
|
1655
|
+
signers: []
|
1656
|
+
});
|
1657
|
+
}
|
1658
|
+
|
1659
|
+
async function repayVault(connection, payer, vaultPublicKey, repayAmount, confirmOptions) {
|
1660
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1661
|
+
const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1662
|
+
// Prep the user to get USDH back out at some point
|
1663
|
+
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1664
|
+
const history = web3_js.Keypair.generate();
|
1665
|
+
const transaction = new web3_js.Transaction().add(await repayVaultInstruction(payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount));
|
1666
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
|
1667
|
+
return vaultPublicKey;
|
1668
|
+
}
|
1669
|
+
async function repayVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount) {
|
1670
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1671
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1672
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1673
|
+
const [hedgeMintPublickey] = await getHedgeMintPublicKey();
|
1674
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
1675
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
1676
|
+
return program.instruction.repayVault(new anchor.BN(repayAmount), {
|
1677
|
+
accounts: {
|
1678
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1679
|
+
vaultAccount: vaultPublickey,
|
1680
|
+
history: historyPublicKey,
|
1681
|
+
feePool: hedgeStakingPoolPublicKey,
|
1682
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
1683
|
+
usdhMint: usdhMintPublickey,
|
1684
|
+
vaultOwner: payerPublicKey,
|
1685
|
+
ownerUsdhAccount: ownerUsdhAccount,
|
1686
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1687
|
+
systemProgram: web3_js.SystemProgram.programId
|
1688
|
+
},
|
1689
|
+
signers: []
|
1690
|
+
});
|
1691
|
+
}
|
1692
|
+
|
1693
|
+
async function redeemVault(connection, payer, vaultPublicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime, confirmOptions) {
|
1694
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1695
|
+
const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1696
|
+
// Prep the user to get USDH back out at some point
|
1697
|
+
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1698
|
+
const history = web3_js.Keypair.generate();
|
1699
|
+
const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime));
|
1700
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
|
1701
|
+
return vaultPublicKey;
|
1702
|
+
}
|
1703
|
+
async function redeemVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime) {
|
1704
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1705
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1706
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1707
|
+
const [hedgeMintPublickey] = await getHedgeMintPublicKey();
|
1708
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
1709
|
+
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
1710
|
+
return program.instruction.redeemVault(new anchor.BN(repayAmount), new anchor.BN(chainlinkOverridePrice !== null && chainlinkOverridePrice !== void 0 ? chainlinkOverridePrice : 150 * web3_js.LAMPORTS_PER_SOL), // override usd/sol price
|
1711
|
+
new anchor.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
|
1712
|
+
{
|
1713
|
+
accounts: {
|
1714
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1715
|
+
vaultAccount: vaultPublickey,
|
1716
|
+
history: historyPublicKey,
|
1717
|
+
feePool: hedgeStakingPoolPublicKey,
|
1718
|
+
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
1719
|
+
usdhMint: usdhMintPublickey,
|
1720
|
+
payer: payerPublicKey,
|
1721
|
+
payerUsdhAccount: ownerUsdhAccount,
|
1722
|
+
chainlinkFeedAccount: CHAINLINK_SOL_USD_PUBLICKEY,
|
1723
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1724
|
+
systemProgram: web3_js.SystemProgram.programId
|
1725
|
+
},
|
1726
|
+
signers: []
|
1727
|
+
});
|
1728
|
+
}
|
1729
|
+
|
1730
|
+
async function liquidateVault(connection, payer, vaultPublicKey, chainlinkOverridePrice, confirmOptions) {
|
1731
|
+
const history = web3_js.Keypair.generate();
|
1732
|
+
const newEra = web3_js.Keypair.generate();
|
1733
|
+
const transaction = new web3_js.Transaction().add(await liquidateVaultInstruction(payer.publicKey, vaultPublicKey, history.publicKey, newEra.publicKey, chainlinkOverridePrice));
|
1734
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history, newEra], confirmOptions);
|
1735
|
+
return vaultPublicKey;
|
1736
|
+
}
|
1737
|
+
async function liquidateVaultInstruction(payerPublicKey, vaultPublickey, historyPublicKey, newEraPublicKey, chainlinkOverridePrice) {
|
1738
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1739
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1740
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1741
|
+
const [hedgeMintPublickey] = await getHedgeMintPublicKey();
|
1742
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
1743
|
+
const [liquidationPoolStatePublicKey] = await getLiquidationPoolStatePublicKey();
|
1744
|
+
const [liquidationPoolUsdhAccountPublickey] = await getLiquidationPoolUsdhAccountPublicKey();
|
1745
|
+
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
1746
|
+
return program.instruction.liquidateVault(new anchor.BN(chainlinkOverridePrice !== null && chainlinkOverridePrice !== void 0 ? chainlinkOverridePrice : web3_js.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
1747
|
+
{
|
1748
|
+
accounts: {
|
1749
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1750
|
+
poolEra: poolStateInfo.currentEra,
|
1751
|
+
vaultAccount: vaultPublickey,
|
1752
|
+
poolState: liquidationPoolStatePublicKey,
|
1753
|
+
usdhMint: usdhMintPublickey,
|
1754
|
+
chainlinkFeedAccount: CHAINLINK_SOL_USD_PUBLICKEY,
|
1755
|
+
history: historyPublicKey,
|
1756
|
+
payer: payerPublicKey,
|
1757
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1758
|
+
systemProgram: web3_js.SystemProgram.programId,
|
1759
|
+
feePool: hedgeStakingPoolPublicKey,
|
1760
|
+
poolUsdhAccount: liquidationPoolUsdhAccountPublickey,
|
1761
|
+
newEra: newEraPublicKey
|
1762
|
+
},
|
1763
|
+
signers: []
|
1764
|
+
});
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
/**
|
1768
|
+
* Convert a U128 to a Decimal
|
1769
|
+
*
|
1770
|
+
* On chain, u128s are used to store Decimal numbers. These values
|
1771
|
+
* are simply stored as u128 where the actual value is divided by
|
1772
|
+
* 1.0e+24. This gives 24 digits of percision on decimal numbers.
|
1773
|
+
*
|
1774
|
+
* Example: the number 1.5 is stored as a u128: 1.5 * 10^24
|
1775
|
+
*
|
1776
|
+
* @param value the value to be converted to Decimal
|
1777
|
+
* @returns the converted value as a decimal.js object
|
1778
|
+
*/
|
1779
|
+
function DecimalFromU128(value) {
|
1780
|
+
const adjustedValue = new Decimal__default["default"](value.toString());
|
1781
|
+
return adjustedValue.div(new Decimal__default["default"]('1e+24'));
|
1782
|
+
}
|
1783
|
+
|
1784
|
+
/**
|
1785
|
+
* A class that represents an on-chian vault.
|
1786
|
+
*/
|
1787
|
+
class VaultAccount {
|
1788
|
+
constructor(vault, publicKey) {
|
1789
|
+
this.publicKey = publicKey;
|
1790
|
+
this.vaultOwner = vault.vaultOwner;
|
1791
|
+
this.debt = vault.debt.toNumber();
|
1792
|
+
this.deposited = vault.deposited.toNumber();
|
1793
|
+
this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio);
|
1794
|
+
this.liquidationPrice = vault.liquidationPrice.toNumber();
|
1795
|
+
this.minCollateralRatio = vault.minCollateralRatio.toNumber();
|
1796
|
+
this.vaultStatus = Object.keys(vault.vaultStatus)[0];
|
1797
|
+
}
|
1798
|
+
/**
|
1799
|
+
* Check if some `PublicKey` is the owner
|
1800
|
+
*
|
1801
|
+
* @param publicKey the publicKey to check against the vault owner
|
1802
|
+
* @returns true if publicKey matches the owner publicKey
|
1803
|
+
*/
|
1804
|
+
isOwnedBy(publicKey) {
|
1805
|
+
return publicKey.toString() === this.vaultOwner.toString();
|
1806
|
+
}
|
1807
|
+
/**
|
1808
|
+
* Get the collateral value in SOL
|
1809
|
+
*
|
1810
|
+
* @returns collateral value in SOL
|
1811
|
+
*/
|
1812
|
+
inSol() {
|
1813
|
+
return this.deposited / web3_js.LAMPORTS_PER_SOL;
|
1814
|
+
}
|
1815
|
+
/**
|
1816
|
+
* Get the debt value in USDH
|
1817
|
+
*
|
1818
|
+
* @returns debt value in USDH
|
1819
|
+
*/
|
1820
|
+
inUsd() {
|
1821
|
+
return this.debt / web3_js.LAMPORTS_PER_SOL;
|
1822
|
+
}
|
1823
|
+
/**
|
1824
|
+
* Pretty print the vault publickey for easy display
|
1825
|
+
*
|
1826
|
+
* @returns example: `1b6ca...azy71s`
|
1827
|
+
*/
|
1828
|
+
toDisplayString() {
|
1829
|
+
return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey.toString().substring(this.publicKey.toString().length - 6)}`;
|
1830
|
+
}
|
1831
|
+
}
|
1832
|
+
|
1833
|
+
var Vaults = /*#__PURE__*/Object.freeze({
|
1834
|
+
__proto__: null,
|
1835
|
+
createVault: createVault,
|
1836
|
+
createVaultInstruction: createVaultInstruction,
|
1837
|
+
depositVault: depositVault,
|
1838
|
+
depositVaultInstruction: depositVaultInstruction,
|
1839
|
+
withdrawVault: withdrawVault,
|
1840
|
+
withdrawVaultInstruction: withdrawVaultInstruction,
|
1841
|
+
loanVault: loanVault,
|
1842
|
+
loanVaultInstruction: loanVaultInstruction,
|
1843
|
+
repayVault: repayVault,
|
1844
|
+
repayVaultInstruction: repayVaultInstruction,
|
1845
|
+
redeemVault: redeemVault,
|
1846
|
+
redeemVaultInstruction: redeemVaultInstruction,
|
1847
|
+
liquidateVault: liquidateVault,
|
1848
|
+
liquidateVaultInstruction: liquidateVaultInstruction,
|
1849
|
+
VaultAccount: VaultAccount
|
1850
|
+
});
|
1851
|
+
|
1852
|
+
function parseAnchorErrors(error) {
|
1853
|
+
const idlErrors = anchor.parseIdlErrors(vaultIdl);
|
1854
|
+
const parsedError = anchor.ProgramError.parse(error, idlErrors);
|
1855
|
+
if (parsedError !== null) {
|
1856
|
+
throw parsedError;
|
1857
|
+
}
|
1858
|
+
throw error;
|
1859
|
+
}
|
1860
|
+
|
1861
|
+
async function createStakingPool(connection, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime, confirmOptions) {
|
1862
|
+
const transaction = new web3_js.Transaction().add(await createStakingPoolInstruction(payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
|
1863
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer], confirmOptions).catch(parseAnchorErrors);
|
1864
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey);
|
1865
|
+
return poolPublickey;
|
1866
|
+
}
|
1867
|
+
async function createStakingPoolInstruction(payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
1868
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1869
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1870
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1871
|
+
const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey);
|
1872
|
+
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey);
|
1873
|
+
const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
|
1874
|
+
return program.instruction.createStakingPool(poolBump, poolSeedPhrase, new anchor.BN(hedgeTokensToBeMinted), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), {
|
1875
|
+
accounts: {
|
1876
|
+
signer: payerPublicKey,
|
1877
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1878
|
+
pool: poolPublickey,
|
1879
|
+
stakedTokenMintInfo: mintPublicKey,
|
1880
|
+
usdhMint: usdhMintPublickey,
|
1881
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
1882
|
+
poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
|
1883
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
1884
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1885
|
+
splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1886
|
+
systemProgram: web3_js.SystemProgram.programId
|
1887
|
+
},
|
1888
|
+
signers: []
|
1889
|
+
});
|
1890
|
+
}
|
1891
|
+
|
1892
|
+
async function depositStakingPool(connection, payer, mintPublicKey, depositAmount, overrideStartTime, confirmOptions) {
|
1893
|
+
const poolPosition = web3_js.Keypair.generate();
|
1894
|
+
const transaction = new web3_js.Transaction().add(await depositStakingPoolInstruction(payer.publicKey, poolPosition.publicKey, mintPublicKey, depositAmount, overrideStartTime));
|
1895
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, poolPosition], confirmOptions).catch(parseAnchorErrors);
|
1896
|
+
return poolPosition.publicKey;
|
1897
|
+
}
|
1898
|
+
async function depositStakingPoolInstruction(payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, depositAmount, overrideStartTime) {
|
1899
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1900
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
|
1901
|
+
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
|
1902
|
+
const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
|
1903
|
+
return program.instruction.depositStakingPool(new anchor.BN(depositAmount), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
1904
|
+
{
|
1905
|
+
accounts: {
|
1906
|
+
payer: payerPublicKey,
|
1907
|
+
pool: poolPublickey,
|
1908
|
+
poolPosition: poolPositionPublicKey,
|
1909
|
+
stakedTokenMintInfo: stakedTokenMintPublicKey,
|
1910
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
1911
|
+
payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
|
1912
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
1913
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1914
|
+
splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1915
|
+
systemProgram: web3_js.SystemProgram.programId
|
1916
|
+
},
|
1917
|
+
signers: []
|
1918
|
+
});
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
async function withdrawStakingPool(connection, payer, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime, confirmOptions) {
|
1922
|
+
const poolPosition = web3_js.Keypair.generate();
|
1923
|
+
const transaction = new web3_js.Transaction().add(await withdrawStakingPoolInstruction(payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime));
|
1924
|
+
await web3_js.sendAndConfirmTransaction(connection, transaction, [payer], confirmOptions).catch(parseAnchorErrors);
|
1925
|
+
return poolPosition.publicKey;
|
1926
|
+
}
|
1927
|
+
async function withdrawStakingPoolInstruction(payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
1928
|
+
const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
|
1929
|
+
const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
|
1930
|
+
const [usdhMintPublickey] = await getUsdhMintPublicKey();
|
1931
|
+
const [hedgeMintPublickey] = await getHedgeMintPublicKey();
|
1932
|
+
const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
|
1933
|
+
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
|
1934
|
+
const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
|
1935
|
+
const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
|
1936
|
+
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey);
|
1937
|
+
const payerAssociatedUsdhAccount = await findAssociatedTokenAddress(payerPublicKey, usdhMintPublickey);
|
1938
|
+
return program.instruction.withdrawStakingPool(new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
1939
|
+
{
|
1940
|
+
accounts: {
|
1941
|
+
payer: payerPublicKey,
|
1942
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
1943
|
+
pool: poolPublickey,
|
1944
|
+
poolPosition: poolPositionPublicKey,
|
1945
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
1946
|
+
poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
|
1947
|
+
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
1948
|
+
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
1949
|
+
payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
|
1950
|
+
hedgeMint: hedgeMintPublickey,
|
1951
|
+
stakedTokenMint: stakedTokenMintPublicKey,
|
1952
|
+
usdhMint: usdhMintPublickey,
|
1953
|
+
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
1954
|
+
splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
|
1955
|
+
splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1956
|
+
systemProgram: web3_js.SystemProgram.programId
|
1957
|
+
},
|
1958
|
+
signers: []
|
1959
|
+
});
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
var StakingPools = /*#__PURE__*/Object.freeze({
|
1963
|
+
__proto__: null,
|
1964
|
+
createStakingPool: createStakingPool,
|
1965
|
+
createStakingPoolInstruction: createStakingPoolInstruction,
|
1966
|
+
depositStakingPool: depositStakingPool,
|
1967
|
+
depositStakingPoolInstruction: depositStakingPoolInstruction,
|
1968
|
+
withdrawStakingPool: withdrawStakingPool,
|
1969
|
+
withdrawStakingPoolInstruction: withdrawStakingPoolInstruction
|
1970
|
+
});
|
1971
|
+
|
1972
|
+
exports.Constants = Constants;
|
1973
|
+
exports.DecimalFromU128 = DecimalFromU128;
|
1974
|
+
exports.StakingPool = StakingPools;
|
1975
|
+
exports.Vaults = Vaults;
|
1976
|
+
//# sourceMappingURL=index.js.map
|