@lavarage/sdk 6.8.0 → 6.8.2
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/abi/borrowerOperations.ts +1 -248
- package/dist/index.d.mts +18 -74
- package/dist/index.d.ts +18 -74
- package/dist/index.js +1480 -1975
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1458 -1965
- package/dist/index.mjs.map +1 -1
- package/evm.ts +43 -0
- package/index.ts +2 -3
- package/package.json +1 -1
- package/playground.ts +28 -0
- package/interfaces/sol.ts +0 -9
- package/lending.ts +0 -456
package/dist/index.js
CHANGED
|
@@ -96,7 +96,6 @@ __export(index_exports, {
|
|
|
96
96
|
getProfitFeeEvm: () => getProfitFeeEvm,
|
|
97
97
|
getTokenBalanceEvm: () => getTokenBalanceEvm,
|
|
98
98
|
getUserLoansEvm: () => getUserLoansEvm,
|
|
99
|
-
lending: () => lending_exports,
|
|
100
99
|
mergePositionV2: () => mergePositionV2,
|
|
101
100
|
modifyTpDelegate: () => modifyTpDelegate,
|
|
102
101
|
openPositionEvm: () => openPositionEvm,
|
|
@@ -105,1492 +104,14 @@ __export(index_exports, {
|
|
|
105
104
|
partialRepayV1: () => partialRepayV1,
|
|
106
105
|
partialRepayV2: () => partialRepayV2,
|
|
107
106
|
removeTpDelegate: () => removeTpDelegate,
|
|
108
|
-
splitPositionV2: () => splitPositionV2
|
|
107
|
+
splitPositionV2: () => splitPositionV2,
|
|
108
|
+
updateMaxLendPerTokenBatchEvm: () => updateMaxLendPerTokenBatchEvm
|
|
109
109
|
});
|
|
110
110
|
module.exports = __toCommonJS(index_exports);
|
|
111
|
-
var import_anchor2 = require("@coral-xyz/anchor");
|
|
112
|
-
var import_bs58 = __toESM(require("bs58"));
|
|
113
|
-
var import_web32 = require("@solana/web3.js");
|
|
114
|
-
var import_spl_token2 = require("@solana/spl-token");
|
|
115
|
-
|
|
116
|
-
// evm.ts
|
|
117
|
-
var import_ethers = require("ethers");
|
|
118
|
-
|
|
119
|
-
// abi/borrowerOperations.ts
|
|
120
|
-
var borrowerOperationsAbi = [
|
|
121
|
-
{ inputs: [], name: "InvalidInitialization", type: "error" },
|
|
122
|
-
{ inputs: [], name: "NotInitializing", type: "error" },
|
|
123
|
-
{ inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
|
|
124
|
-
{
|
|
125
|
-
anonymous: false,
|
|
126
|
-
inputs: [
|
|
127
|
-
{
|
|
128
|
-
indexed: true,
|
|
129
|
-
internalType: "address",
|
|
130
|
-
name: "buyer",
|
|
131
|
-
type: "address"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
indexed: true,
|
|
135
|
-
internalType: "address",
|
|
136
|
-
name: "tokenCollateral",
|
|
137
|
-
type: "address"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
indexed: true,
|
|
141
|
-
internalType: "uint256",
|
|
142
|
-
name: "loanId",
|
|
143
|
-
type: "uint256"
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
indexed: false,
|
|
147
|
-
internalType: "uint256",
|
|
148
|
-
name: "openingPositionSize",
|
|
149
|
-
type: "uint256"
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
indexed: false,
|
|
153
|
-
internalType: "uint256",
|
|
154
|
-
name: "collateralAmount",
|
|
155
|
-
type: "uint256"
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
indexed: false,
|
|
159
|
-
internalType: "uint256",
|
|
160
|
-
name: "initialMargin",
|
|
161
|
-
type: "uint256"
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
name: "Buy",
|
|
165
|
-
type: "event"
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
anonymous: false,
|
|
169
|
-
inputs: [
|
|
170
|
-
{
|
|
171
|
-
indexed: false,
|
|
172
|
-
internalType: "uint64",
|
|
173
|
-
name: "version",
|
|
174
|
-
type: "uint64"
|
|
175
|
-
}
|
|
176
|
-
],
|
|
177
|
-
name: "Initialized",
|
|
178
|
-
type: "event"
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
anonymous: false,
|
|
182
|
-
inputs: [
|
|
183
|
-
{
|
|
184
|
-
indexed: true,
|
|
185
|
-
internalType: "address",
|
|
186
|
-
name: "borrower",
|
|
187
|
-
type: "address"
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
indexed: true,
|
|
191
|
-
internalType: "address",
|
|
192
|
-
name: "tokenCollateral",
|
|
193
|
-
type: "address"
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
indexed: true,
|
|
197
|
-
internalType: "uint256",
|
|
198
|
-
name: "loanId",
|
|
199
|
-
type: "uint256"
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
indexed: false,
|
|
203
|
-
internalType: "uint256",
|
|
204
|
-
name: "closingPositionSize",
|
|
205
|
-
type: "uint256"
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
indexed: false,
|
|
209
|
-
internalType: "uint256",
|
|
210
|
-
name: "liquidatorRepaidAmount",
|
|
211
|
-
type: "uint256"
|
|
212
|
-
}
|
|
213
|
-
],
|
|
214
|
-
name: "Liquidation",
|
|
215
|
-
type: "event"
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
anonymous: false,
|
|
219
|
-
inputs: [
|
|
220
|
-
{
|
|
221
|
-
indexed: true,
|
|
222
|
-
internalType: "address",
|
|
223
|
-
name: "buyer",
|
|
224
|
-
type: "address"
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
indexed: true,
|
|
228
|
-
internalType: "address",
|
|
229
|
-
name: "tokenCollateral",
|
|
230
|
-
type: "address"
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
indexed: true,
|
|
234
|
-
internalType: "uint256",
|
|
235
|
-
name: "loanId",
|
|
236
|
-
type: "uint256"
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
indexed: false,
|
|
240
|
-
internalType: "uint256",
|
|
241
|
-
name: "closingPositionSize",
|
|
242
|
-
type: "uint256"
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
indexed: false,
|
|
246
|
-
internalType: "uint256",
|
|
247
|
-
name: "profit",
|
|
248
|
-
type: "uint256"
|
|
249
|
-
}
|
|
250
|
-
],
|
|
251
|
-
name: "Sell",
|
|
252
|
-
type: "event"
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
inputs: [],
|
|
256
|
-
name: "admin",
|
|
257
|
-
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
258
|
-
stateMutability: "view",
|
|
259
|
-
type: "function"
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
inputs: [
|
|
263
|
-
{ internalType: "bytes", name: "buyingCode", type: "bytes" },
|
|
264
|
-
{
|
|
265
|
-
internalType: "contract IERC20",
|
|
266
|
-
name: "tokenCollateral",
|
|
267
|
-
type: "address"
|
|
268
|
-
},
|
|
269
|
-
{ internalType: "uint256", name: "borrowAmount", type: "uint256" },
|
|
270
|
-
{
|
|
271
|
-
internalType: "contract TokenHolder",
|
|
272
|
-
name: "tokenHolder",
|
|
273
|
-
type: "address"
|
|
274
|
-
},
|
|
275
|
-
{ internalType: "address", name: "inchRouter", type: "address" },
|
|
276
|
-
{
|
|
277
|
-
internalType: "address",
|
|
278
|
-
name: "integratorFeeAddress",
|
|
279
|
-
type: "address"
|
|
280
|
-
}
|
|
281
|
-
],
|
|
282
|
-
name: "buy",
|
|
283
|
-
outputs: [],
|
|
284
|
-
stateMutability: "payable",
|
|
285
|
-
type: "function"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
inputs: [
|
|
289
|
-
{ internalType: "contract IERC20", name: "_weth", type: "address" }
|
|
290
|
-
],
|
|
291
|
-
name: "initialize",
|
|
292
|
-
outputs: [],
|
|
293
|
-
stateMutability: "nonpayable",
|
|
294
|
-
type: "function"
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
inputs: [
|
|
298
|
-
{ internalType: "uint256", name: "loanId", type: "uint256" },
|
|
299
|
-
{
|
|
300
|
-
internalType: "contract TokenHolder",
|
|
301
|
-
name: "tokenHolder",
|
|
302
|
-
type: "address"
|
|
303
|
-
},
|
|
304
|
-
{ internalType: "uint256", name: "closingPositionSize", type: "uint256" }
|
|
305
|
-
],
|
|
306
|
-
name: "liquidate",
|
|
307
|
-
outputs: [],
|
|
308
|
-
stateMutability: "nonpayable",
|
|
309
|
-
type: "function"
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
inputs: [],
|
|
313
|
-
name: "openingFee",
|
|
314
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
315
|
-
stateMutability: "view",
|
|
316
|
-
type: "function"
|
|
317
|
-
},
|
|
318
|
-
{
|
|
319
|
-
inputs: [],
|
|
320
|
-
name: "profitFee",
|
|
321
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
322
|
-
stateMutability: "view",
|
|
323
|
-
type: "function"
|
|
324
|
-
},
|
|
325
|
-
{
|
|
326
|
-
inputs: [
|
|
327
|
-
{ internalType: "uint256", name: "loanId", type: "uint256" },
|
|
328
|
-
{ internalType: "bytes", name: "sellingCode", type: "bytes" },
|
|
329
|
-
{
|
|
330
|
-
internalType: "contract TokenHolder",
|
|
331
|
-
name: "tokenHolder",
|
|
332
|
-
type: "address"
|
|
333
|
-
},
|
|
334
|
-
{ internalType: "address", name: "inchRouter", type: "address" },
|
|
335
|
-
{
|
|
336
|
-
internalType: "address",
|
|
337
|
-
name: "integratorFeeAddress",
|
|
338
|
-
type: "address"
|
|
339
|
-
}
|
|
340
|
-
],
|
|
341
|
-
name: "sell",
|
|
342
|
-
outputs: [],
|
|
343
|
-
stateMutability: "payable",
|
|
344
|
-
type: "function"
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
inputs: [{ internalType: "address", name: "_admin", type: "address" }],
|
|
348
|
-
name: "setAdmin",
|
|
349
|
-
outputs: [],
|
|
350
|
-
stateMutability: "nonpayable",
|
|
351
|
-
type: "function"
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
inputs: [{ internalType: "uint256", name: "_openingFee", type: "uint256" }],
|
|
355
|
-
name: "setOpeningFee",
|
|
356
|
-
outputs: [],
|
|
357
|
-
stateMutability: "nonpayable",
|
|
358
|
-
type: "function"
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
inputs: [{ internalType: "uint256", name: "_profitFee", type: "uint256" }],
|
|
362
|
-
name: "setProfitFee",
|
|
363
|
-
outputs: [],
|
|
364
|
-
stateMutability: "nonpayable",
|
|
365
|
-
type: "function"
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
|
|
369
|
-
// abi/tokenHolderAbi.ts
|
|
370
|
-
var tokenHolderAbi = [
|
|
371
|
-
{ inputs: [], name: "AccessControlBadConfirmation", type: "error" },
|
|
372
|
-
{
|
|
373
|
-
inputs: [
|
|
374
|
-
{ internalType: "address", name: "account", type: "address" },
|
|
375
|
-
{ internalType: "bytes32", name: "neededRole", type: "bytes32" }
|
|
376
|
-
],
|
|
377
|
-
name: "AccessControlUnauthorizedAccount",
|
|
378
|
-
type: "error"
|
|
379
|
-
},
|
|
380
|
-
{ inputs: [], name: "InvalidInitialization", type: "error" },
|
|
381
|
-
{ inputs: [], name: "NotInitializing", type: "error" },
|
|
382
|
-
{
|
|
383
|
-
anonymous: false,
|
|
384
|
-
inputs: [
|
|
385
|
-
{
|
|
386
|
-
indexed: false,
|
|
387
|
-
internalType: "uint64",
|
|
388
|
-
name: "version",
|
|
389
|
-
type: "uint64"
|
|
390
|
-
}
|
|
391
|
-
],
|
|
392
|
-
name: "Initialized",
|
|
393
|
-
type: "event"
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
anonymous: false,
|
|
397
|
-
inputs: [
|
|
398
|
-
{
|
|
399
|
-
indexed: false,
|
|
400
|
-
internalType: "uint256",
|
|
401
|
-
name: "newInterestRate",
|
|
402
|
-
type: "uint256"
|
|
403
|
-
}
|
|
404
|
-
],
|
|
405
|
-
name: "InterestRateSet",
|
|
406
|
-
type: "event"
|
|
407
|
-
},
|
|
408
|
-
{
|
|
409
|
-
anonymous: false,
|
|
410
|
-
inputs: [
|
|
411
|
-
{
|
|
412
|
-
indexed: false,
|
|
413
|
-
internalType: "uint256",
|
|
414
|
-
name: "loanId",
|
|
415
|
-
type: "uint256"
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
indexed: false,
|
|
419
|
-
internalType: "uint256",
|
|
420
|
-
name: "amount",
|
|
421
|
-
type: "uint256"
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
indexed: false,
|
|
425
|
-
internalType: "uint256",
|
|
426
|
-
name: "timestamp",
|
|
427
|
-
type: "uint256"
|
|
428
|
-
},
|
|
429
|
-
{ indexed: false, internalType: "bool", name: "repaid", type: "bool" }
|
|
430
|
-
],
|
|
431
|
-
name: "LoanCreated",
|
|
432
|
-
type: "event"
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
anonymous: false,
|
|
436
|
-
inputs: [
|
|
437
|
-
{
|
|
438
|
-
indexed: false,
|
|
439
|
-
internalType: "uint256",
|
|
440
|
-
name: "loanId",
|
|
441
|
-
type: "uint256"
|
|
442
|
-
}
|
|
443
|
-
],
|
|
444
|
-
name: "LoanRepaid",
|
|
445
|
-
type: "event"
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
anonymous: false,
|
|
449
|
-
inputs: [
|
|
450
|
-
{
|
|
451
|
-
indexed: false,
|
|
452
|
-
internalType: "address",
|
|
453
|
-
name: "collateralAddress",
|
|
454
|
-
type: "address"
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
indexed: false,
|
|
458
|
-
internalType: "uint256",
|
|
459
|
-
name: "oldValue",
|
|
460
|
-
type: "uint256"
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
indexed: false,
|
|
464
|
-
internalType: "uint256",
|
|
465
|
-
name: "newValue",
|
|
466
|
-
type: "uint256"
|
|
467
|
-
}
|
|
468
|
-
],
|
|
469
|
-
name: "MaxLendPerTokenUpdated",
|
|
470
|
-
type: "event"
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
anonymous: false,
|
|
474
|
-
inputs: [
|
|
475
|
-
{
|
|
476
|
-
indexed: false,
|
|
477
|
-
internalType: "address",
|
|
478
|
-
name: "borrower",
|
|
479
|
-
type: "address"
|
|
480
|
-
},
|
|
481
|
-
{
|
|
482
|
-
indexed: false,
|
|
483
|
-
internalType: "uint256",
|
|
484
|
-
name: "amount",
|
|
485
|
-
type: "uint256"
|
|
486
|
-
}
|
|
487
|
-
],
|
|
488
|
-
name: "PrivilegedLoan",
|
|
489
|
-
type: "event"
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
anonymous: false,
|
|
493
|
-
inputs: [
|
|
494
|
-
{
|
|
495
|
-
indexed: false,
|
|
496
|
-
internalType: "address",
|
|
497
|
-
name: "borrower",
|
|
498
|
-
type: "address"
|
|
499
|
-
},
|
|
500
|
-
{
|
|
501
|
-
indexed: false,
|
|
502
|
-
internalType: "uint256",
|
|
503
|
-
name: "amount",
|
|
504
|
-
type: "uint256"
|
|
505
|
-
}
|
|
506
|
-
],
|
|
507
|
-
name: "PrivilegedLoanRepaid",
|
|
508
|
-
type: "event"
|
|
509
|
-
},
|
|
510
|
-
{
|
|
511
|
-
anonymous: false,
|
|
512
|
-
inputs: [
|
|
513
|
-
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
514
|
-
{
|
|
515
|
-
indexed: true,
|
|
516
|
-
internalType: "bytes32",
|
|
517
|
-
name: "previousAdminRole",
|
|
518
|
-
type: "bytes32"
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
indexed: true,
|
|
522
|
-
internalType: "bytes32",
|
|
523
|
-
name: "newAdminRole",
|
|
524
|
-
type: "bytes32"
|
|
525
|
-
}
|
|
526
|
-
],
|
|
527
|
-
name: "RoleAdminChanged",
|
|
528
|
-
type: "event"
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
anonymous: false,
|
|
532
|
-
inputs: [
|
|
533
|
-
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
534
|
-
{
|
|
535
|
-
indexed: true,
|
|
536
|
-
internalType: "address",
|
|
537
|
-
name: "account",
|
|
538
|
-
type: "address"
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
indexed: true,
|
|
542
|
-
internalType: "address",
|
|
543
|
-
name: "sender",
|
|
544
|
-
type: "address"
|
|
545
|
-
}
|
|
546
|
-
],
|
|
547
|
-
name: "RoleGranted",
|
|
548
|
-
type: "event"
|
|
549
|
-
},
|
|
550
|
-
{
|
|
551
|
-
anonymous: false,
|
|
552
|
-
inputs: [
|
|
553
|
-
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
554
|
-
{
|
|
555
|
-
indexed: true,
|
|
556
|
-
internalType: "address",
|
|
557
|
-
name: "account",
|
|
558
|
-
type: "address"
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
indexed: true,
|
|
562
|
-
internalType: "address",
|
|
563
|
-
name: "sender",
|
|
564
|
-
type: "address"
|
|
565
|
-
}
|
|
566
|
-
],
|
|
567
|
-
name: "RoleRevoked",
|
|
568
|
-
type: "event"
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
inputs: [],
|
|
572
|
-
name: "BORROWER_ROUTER_ROLE",
|
|
573
|
-
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
574
|
-
stateMutability: "view",
|
|
575
|
-
type: "function"
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
inputs: [],
|
|
579
|
-
name: "DEFAULT_ADMIN_ROLE",
|
|
580
|
-
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
581
|
-
stateMutability: "view",
|
|
582
|
-
type: "function"
|
|
583
|
-
},
|
|
584
|
-
{
|
|
585
|
-
inputs: [
|
|
586
|
-
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
587
|
-
{ internalType: "uint256", name: "_interestRate", type: "uint256" },
|
|
588
|
-
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
589
|
-
{ internalType: "uint256", name: "minAmount", type: "uint256" }
|
|
590
|
-
],
|
|
591
|
-
name: "addCollateral",
|
|
592
|
-
outputs: [],
|
|
593
|
-
stateMutability: "nonpayable",
|
|
594
|
-
type: "function"
|
|
595
|
-
},
|
|
596
|
-
{
|
|
597
|
-
inputs: [{ internalType: "address", name: "", type: "address" }],
|
|
598
|
-
name: "collateralMapping",
|
|
599
|
-
outputs: [
|
|
600
|
-
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
601
|
-
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
602
|
-
{ internalType: "uint256", name: "interestRate", type: "uint256" },
|
|
603
|
-
{ internalType: "bool", name: "active", type: "bool" },
|
|
604
|
-
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
605
|
-
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
606
|
-
{ internalType: "uint256", name: "currentExposure", type: "uint256" }
|
|
607
|
-
],
|
|
608
|
-
stateMutability: "view",
|
|
609
|
-
type: "function"
|
|
610
|
-
},
|
|
611
|
-
{
|
|
612
|
-
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
|
|
613
|
-
name: "deposit",
|
|
614
|
-
outputs: [],
|
|
615
|
-
stateMutability: "nonpayable",
|
|
616
|
-
type: "function"
|
|
617
|
-
},
|
|
618
|
-
{
|
|
619
|
-
inputs: [],
|
|
620
|
-
name: "getBalance",
|
|
621
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
622
|
-
stateMutability: "view",
|
|
623
|
-
type: "function"
|
|
624
|
-
},
|
|
625
|
-
{
|
|
626
|
-
inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
|
|
627
|
-
name: "getRoleAdmin",
|
|
628
|
-
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
629
|
-
stateMutability: "view",
|
|
630
|
-
type: "function"
|
|
631
|
-
},
|
|
632
|
-
{
|
|
633
|
-
inputs: [{ internalType: "address", name: "account", type: "address" }],
|
|
634
|
-
name: "grantBorrowerRouterRole",
|
|
635
|
-
outputs: [],
|
|
636
|
-
stateMutability: "nonpayable",
|
|
637
|
-
type: "function"
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
inputs: [
|
|
641
|
-
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
642
|
-
{ internalType: "address", name: "account", type: "address" }
|
|
643
|
-
],
|
|
644
|
-
name: "grantRole",
|
|
645
|
-
outputs: [],
|
|
646
|
-
stateMutability: "nonpayable",
|
|
647
|
-
type: "function"
|
|
648
|
-
},
|
|
649
|
-
{
|
|
650
|
-
inputs: [
|
|
651
|
-
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
652
|
-
{ internalType: "address", name: "account", type: "address" }
|
|
653
|
-
],
|
|
654
|
-
name: "hasRole",
|
|
655
|
-
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
656
|
-
stateMutability: "view",
|
|
657
|
-
type: "function"
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
inputs: [
|
|
661
|
-
{ internalType: "address", name: "_tokenAddress", type: "address" }
|
|
662
|
-
],
|
|
663
|
-
name: "initialize",
|
|
664
|
-
outputs: [],
|
|
665
|
-
stateMutability: "nonpayable",
|
|
666
|
-
type: "function"
|
|
667
|
-
},
|
|
668
|
-
{
|
|
669
|
-
inputs: [
|
|
670
|
-
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
671
|
-
{ internalType: "uint256", name: "collateralAmount", type: "uint256" },
|
|
672
|
-
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
673
|
-
{ internalType: "address", name: "borrower", type: "address" },
|
|
674
|
-
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
675
|
-
],
|
|
676
|
-
name: "loanConfirmation",
|
|
677
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
678
|
-
stateMutability: "nonpayable",
|
|
679
|
-
type: "function"
|
|
680
|
-
},
|
|
681
|
-
{
|
|
682
|
-
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
683
|
-
name: "loans",
|
|
684
|
-
outputs: [
|
|
685
|
-
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
686
|
-
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
687
|
-
{
|
|
688
|
-
components: [
|
|
689
|
-
{
|
|
690
|
-
internalType: "address",
|
|
691
|
-
name: "collateralAddress",
|
|
692
|
-
type: "address"
|
|
693
|
-
},
|
|
694
|
-
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
695
|
-
{ internalType: "uint256", name: "interestRate", type: "uint256" },
|
|
696
|
-
{ internalType: "bool", name: "active", type: "bool" },
|
|
697
|
-
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
698
|
-
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
699
|
-
{ internalType: "uint256", name: "currentExposure", type: "uint256" }
|
|
700
|
-
],
|
|
701
|
-
internalType: "struct Collateral",
|
|
702
|
-
name: "collateral",
|
|
703
|
-
type: "tuple"
|
|
704
|
-
},
|
|
705
|
-
{ internalType: "uint256", name: "collateralAmount", type: "uint256" },
|
|
706
|
-
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
707
|
-
{ internalType: "address", name: "borrower", type: "address" },
|
|
708
|
-
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
709
|
-
],
|
|
710
|
-
stateMutability: "view",
|
|
711
|
-
type: "function"
|
|
712
|
-
},
|
|
713
|
-
{
|
|
714
|
-
inputs: [],
|
|
715
|
-
name: "nextLoanId",
|
|
716
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
717
|
-
stateMutability: "view",
|
|
718
|
-
type: "function"
|
|
719
|
-
},
|
|
720
|
-
{
|
|
721
|
-
inputs: [
|
|
722
|
-
{
|
|
723
|
-
internalType: "contract IERC20",
|
|
724
|
-
name: "flashLoanToken",
|
|
725
|
-
type: "address"
|
|
726
|
-
},
|
|
727
|
-
{ internalType: "uint256", name: "amount", type: "uint256" }
|
|
728
|
-
],
|
|
729
|
-
name: "privilegedLoan",
|
|
730
|
-
outputs: [],
|
|
731
|
-
stateMutability: "nonpayable",
|
|
732
|
-
type: "function"
|
|
733
|
-
},
|
|
734
|
-
{
|
|
735
|
-
inputs: [
|
|
736
|
-
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
737
|
-
],
|
|
738
|
-
name: "removeCollateral",
|
|
739
|
-
outputs: [],
|
|
740
|
-
stateMutability: "nonpayable",
|
|
741
|
-
type: "function"
|
|
742
|
-
},
|
|
743
|
-
{
|
|
744
|
-
inputs: [
|
|
745
|
-
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
746
|
-
{ internalType: "address", name: "callerConfirmation", type: "address" }
|
|
747
|
-
],
|
|
748
|
-
name: "renounceRole",
|
|
749
|
-
outputs: [],
|
|
750
|
-
stateMutability: "nonpayable",
|
|
751
|
-
type: "function"
|
|
752
|
-
},
|
|
753
|
-
{
|
|
754
|
-
inputs: [{ internalType: "uint256", name: "loanId", type: "uint256" }],
|
|
755
|
-
name: "repayLoan",
|
|
756
|
-
outputs: [],
|
|
757
|
-
stateMutability: "nonpayable",
|
|
758
|
-
type: "function"
|
|
759
|
-
},
|
|
760
|
-
{
|
|
761
|
-
inputs: [{ internalType: "address", name: "account", type: "address" }],
|
|
762
|
-
name: "revokeBorrowerRouterRole",
|
|
763
|
-
outputs: [],
|
|
764
|
-
stateMutability: "nonpayable",
|
|
765
|
-
type: "function"
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
inputs: [
|
|
769
|
-
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
770
|
-
{ internalType: "address", name: "account", type: "address" }
|
|
771
|
-
],
|
|
772
|
-
name: "revokeRole",
|
|
773
|
-
outputs: [],
|
|
774
|
-
stateMutability: "nonpayable",
|
|
775
|
-
type: "function"
|
|
776
|
-
},
|
|
777
|
-
{
|
|
778
|
-
inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
|
|
779
|
-
name: "supportsInterface",
|
|
780
|
-
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
781
|
-
stateMutability: "view",
|
|
782
|
-
type: "function"
|
|
783
|
-
},
|
|
784
|
-
{
|
|
785
|
-
inputs: [],
|
|
786
|
-
name: "tokenHolded",
|
|
787
|
-
outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
|
|
788
|
-
stateMutability: "view",
|
|
789
|
-
type: "function"
|
|
790
|
-
},
|
|
791
|
-
{
|
|
792
|
-
inputs: [
|
|
793
|
-
{
|
|
794
|
-
internalType: "address[]",
|
|
795
|
-
name: "collateralAddresses",
|
|
796
|
-
type: "address[]"
|
|
797
|
-
},
|
|
798
|
-
{
|
|
799
|
-
internalType: "uint256[]",
|
|
800
|
-
name: "newMaxLendPerTokens",
|
|
801
|
-
type: "uint256[]"
|
|
802
|
-
}
|
|
803
|
-
],
|
|
804
|
-
name: "updateMaxLendPerTokenBulk",
|
|
805
|
-
outputs: [],
|
|
806
|
-
stateMutability: "nonpayable",
|
|
807
|
-
type: "function"
|
|
808
|
-
},
|
|
809
|
-
{
|
|
810
|
-
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
|
|
811
|
-
name: "withdraw",
|
|
812
|
-
outputs: [],
|
|
813
|
-
stateMutability: "nonpayable",
|
|
814
|
-
type: "function"
|
|
815
|
-
},
|
|
816
|
-
{
|
|
817
|
-
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
818
|
-
name: "activeLoanIds",
|
|
819
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
820
|
-
stateMutability: "view",
|
|
821
|
-
type: "function"
|
|
822
|
-
},
|
|
823
|
-
{
|
|
824
|
-
inputs: [],
|
|
825
|
-
name: "getActiveLoanCount",
|
|
826
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
827
|
-
stateMutability: "view",
|
|
828
|
-
type: "function"
|
|
829
|
-
},
|
|
830
|
-
{
|
|
831
|
-
inputs: [
|
|
832
|
-
{ internalType: "uint256", name: "startIndex", type: "uint256" },
|
|
833
|
-
{ internalType: "uint256", name: "batchSize", type: "uint256" }
|
|
834
|
-
],
|
|
835
|
-
name: "getActiveLoansBatch",
|
|
836
|
-
outputs: [
|
|
837
|
-
{
|
|
838
|
-
components: [
|
|
839
|
-
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
840
|
-
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
841
|
-
{
|
|
842
|
-
components: [
|
|
843
|
-
{
|
|
844
|
-
internalType: "address",
|
|
845
|
-
name: "collateralAddress",
|
|
846
|
-
type: "address"
|
|
847
|
-
},
|
|
848
|
-
{
|
|
849
|
-
internalType: "uint256",
|
|
850
|
-
name: "maxLendPerToken",
|
|
851
|
-
type: "uint256"
|
|
852
|
-
},
|
|
853
|
-
{
|
|
854
|
-
internalType: "uint256",
|
|
855
|
-
name: "interestRate",
|
|
856
|
-
type: "uint256"
|
|
857
|
-
},
|
|
858
|
-
{ internalType: "bool", name: "active", type: "bool" },
|
|
859
|
-
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
860
|
-
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
861
|
-
{
|
|
862
|
-
internalType: "uint256",
|
|
863
|
-
name: "currentExposure",
|
|
864
|
-
type: "uint256"
|
|
865
|
-
}
|
|
866
|
-
],
|
|
867
|
-
internalType: "struct Collateral",
|
|
868
|
-
name: "collateral",
|
|
869
|
-
type: "tuple"
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
internalType: "uint256",
|
|
873
|
-
name: "collateralAmount",
|
|
874
|
-
type: "uint256"
|
|
875
|
-
},
|
|
876
|
-
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
877
|
-
{ internalType: "address", name: "borrower", type: "address" },
|
|
878
|
-
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
879
|
-
],
|
|
880
|
-
internalType: "struct Loan[]",
|
|
881
|
-
name: "",
|
|
882
|
-
type: "tuple[]"
|
|
883
|
-
}
|
|
884
|
-
],
|
|
885
|
-
stateMutability: "view",
|
|
886
|
-
type: "function"
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
inputs: [{ internalType: "address", name: "borrower", type: "address" }],
|
|
890
|
-
name: "getLoansByBorrower",
|
|
891
|
-
outputs: [
|
|
892
|
-
{
|
|
893
|
-
components: [
|
|
894
|
-
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
895
|
-
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
896
|
-
{
|
|
897
|
-
components: [
|
|
898
|
-
{
|
|
899
|
-
internalType: "address",
|
|
900
|
-
name: "collateralAddress",
|
|
901
|
-
type: "address"
|
|
902
|
-
},
|
|
903
|
-
{
|
|
904
|
-
internalType: "uint256",
|
|
905
|
-
name: "maxLendPerToken",
|
|
906
|
-
type: "uint256"
|
|
907
|
-
},
|
|
908
|
-
{
|
|
909
|
-
internalType: "uint256",
|
|
910
|
-
name: "interestRate",
|
|
911
|
-
type: "uint256"
|
|
912
|
-
},
|
|
913
|
-
{ internalType: "bool", name: "active", type: "bool" },
|
|
914
|
-
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
915
|
-
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
916
|
-
{
|
|
917
|
-
internalType: "uint256",
|
|
918
|
-
name: "currentExposure",
|
|
919
|
-
type: "uint256"
|
|
920
|
-
}
|
|
921
|
-
],
|
|
922
|
-
internalType: "struct Collateral",
|
|
923
|
-
name: "collateral",
|
|
924
|
-
type: "tuple"
|
|
925
|
-
},
|
|
926
|
-
{
|
|
927
|
-
internalType: "uint256",
|
|
928
|
-
name: "collateralAmount",
|
|
929
|
-
type: "uint256"
|
|
930
|
-
},
|
|
931
|
-
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
932
|
-
{ internalType: "address", name: "borrower", type: "address" },
|
|
933
|
-
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
934
|
-
],
|
|
935
|
-
internalType: "struct Loan[]",
|
|
936
|
-
name: "",
|
|
937
|
-
type: "tuple[]"
|
|
938
|
-
}
|
|
939
|
-
],
|
|
940
|
-
stateMutability: "view",
|
|
941
|
-
type: "function"
|
|
942
|
-
},
|
|
943
|
-
{
|
|
944
|
-
inputs: [
|
|
945
|
-
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
946
|
-
],
|
|
947
|
-
name: "getCollateralExposure",
|
|
948
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
949
|
-
stateMutability: "view",
|
|
950
|
-
type: "function"
|
|
951
|
-
},
|
|
952
|
-
{
|
|
953
|
-
inputs: [
|
|
954
|
-
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
955
|
-
],
|
|
956
|
-
name: "getAvailableExposure",
|
|
957
|
-
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
958
|
-
stateMutability: "view",
|
|
959
|
-
type: "function"
|
|
960
|
-
},
|
|
961
|
-
{
|
|
962
|
-
inputs: [
|
|
963
|
-
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
964
|
-
{ internalType: "uint256", name: "_interestRate", type: "uint256" },
|
|
965
|
-
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
966
|
-
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
967
|
-
{ internalType: "uint256", name: "maxExposure", type: "uint256" }
|
|
968
|
-
],
|
|
969
|
-
name: "addCollateral",
|
|
970
|
-
outputs: [],
|
|
971
|
-
stateMutability: "nonpayable",
|
|
972
|
-
type: "function"
|
|
973
|
-
},
|
|
974
|
-
{
|
|
975
|
-
inputs: [
|
|
976
|
-
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
977
|
-
{ internalType: "uint256", name: "newMaxExposure", type: "uint256" }
|
|
978
|
-
],
|
|
979
|
-
name: "updateMaxExposure",
|
|
980
|
-
outputs: [],
|
|
981
|
-
stateMutability: "nonpayable",
|
|
982
|
-
type: "function"
|
|
983
|
-
},
|
|
984
|
-
{
|
|
985
|
-
anonymous: false,
|
|
986
|
-
inputs: [
|
|
987
|
-
{
|
|
988
|
-
indexed: false,
|
|
989
|
-
internalType: "address",
|
|
990
|
-
name: "collateralAddress",
|
|
991
|
-
type: "address"
|
|
992
|
-
},
|
|
993
|
-
{
|
|
994
|
-
indexed: false,
|
|
995
|
-
internalType: "uint256",
|
|
996
|
-
name: "currentExposure",
|
|
997
|
-
type: "uint256"
|
|
998
|
-
}
|
|
999
|
-
],
|
|
1000
|
-
name: "ExposureUpdated",
|
|
1001
|
-
type: "event"
|
|
1002
|
-
},
|
|
1003
|
-
{
|
|
1004
|
-
anonymous: false,
|
|
1005
|
-
inputs: [
|
|
1006
|
-
{
|
|
1007
|
-
indexed: false,
|
|
1008
|
-
internalType: "address",
|
|
1009
|
-
name: "collateralAddress",
|
|
1010
|
-
type: "address"
|
|
1011
|
-
},
|
|
1012
|
-
{
|
|
1013
|
-
indexed: false,
|
|
1014
|
-
internalType: "uint256",
|
|
1015
|
-
name: "oldMaxExposure",
|
|
1016
|
-
type: "uint256"
|
|
1017
|
-
},
|
|
1018
|
-
{
|
|
1019
|
-
indexed: false,
|
|
1020
|
-
internalType: "uint256",
|
|
1021
|
-
name: "newMaxExposure",
|
|
1022
|
-
type: "uint256"
|
|
1023
|
-
}
|
|
1024
|
-
],
|
|
1025
|
-
name: "MaxExposureUpdated",
|
|
1026
|
-
type: "event"
|
|
1027
|
-
}
|
|
1028
|
-
];
|
|
1029
|
-
|
|
1030
|
-
// evm.ts
|
|
1031
|
-
var openPositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
|
|
1032
|
-
buyingCode,
|
|
1033
|
-
tokenCollateral,
|
|
1034
|
-
borrowAmount,
|
|
1035
|
-
tokenHolder,
|
|
1036
|
-
inchRouter,
|
|
1037
|
-
integratorFeeAddress = import_ethers.ZeroAddress,
|
|
1038
|
-
buyerContribution,
|
|
1039
|
-
gasLimit,
|
|
1040
|
-
gasPrice
|
|
1041
|
-
}) {
|
|
1042
|
-
const contract = new import_ethers.Contract(
|
|
1043
|
-
borrowerOpsContractAddress,
|
|
1044
|
-
borrowerOperationsAbi,
|
|
1045
|
-
provider
|
|
1046
|
-
);
|
|
1047
|
-
const txOptions = {
|
|
1048
|
-
value: buyerContribution
|
|
1049
|
-
};
|
|
1050
|
-
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
1051
|
-
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
1052
|
-
return contract.buy.populateTransaction(
|
|
1053
|
-
buyingCode,
|
|
1054
|
-
tokenCollateral,
|
|
1055
|
-
borrowAmount,
|
|
1056
|
-
tokenHolder,
|
|
1057
|
-
inchRouter,
|
|
1058
|
-
integratorFeeAddress,
|
|
1059
|
-
txOptions
|
|
1060
|
-
);
|
|
1061
|
-
});
|
|
1062
|
-
var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
|
|
1063
|
-
loanId,
|
|
1064
|
-
sellingCode,
|
|
1065
|
-
tokenHolder,
|
|
1066
|
-
inchRouter,
|
|
1067
|
-
integratorFeeAddress = import_ethers.ZeroAddress,
|
|
1068
|
-
gasLimit,
|
|
1069
|
-
gasPrice
|
|
1070
|
-
}) {
|
|
1071
|
-
const contract = new import_ethers.Contract(
|
|
1072
|
-
borrowerOpsContractAddress,
|
|
1073
|
-
borrowerOperationsAbi,
|
|
1074
|
-
provider
|
|
1075
|
-
);
|
|
1076
|
-
const txOptions = {};
|
|
1077
|
-
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
1078
|
-
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
1079
|
-
return contract.sell.populateTransaction(
|
|
1080
|
-
loanId,
|
|
1081
|
-
sellingCode,
|
|
1082
|
-
tokenHolder,
|
|
1083
|
-
inchRouter,
|
|
1084
|
-
integratorFeeAddress,
|
|
1085
|
-
Object.keys(txOptions).length > 0 ? txOptions : {}
|
|
1086
|
-
);
|
|
1087
|
-
});
|
|
1088
|
-
function getPositionsEvm(provider, tokenHolderContractAddress) {
|
|
1089
|
-
return __async(this, null, function* () {
|
|
1090
|
-
const contract = new import_ethers.Contract(
|
|
1091
|
-
tokenHolderContractAddress,
|
|
1092
|
-
tokenHolderAbi,
|
|
1093
|
-
provider
|
|
1094
|
-
);
|
|
1095
|
-
const activeLoanCount = yield contract.getActiveLoanCount();
|
|
1096
|
-
const batchSize = 100;
|
|
1097
|
-
const positions = [];
|
|
1098
|
-
for (let i = 0; i < activeLoanCount; i += batchSize) {
|
|
1099
|
-
const currentBatchSize = Math.min(Number(activeLoanCount) - i, batchSize);
|
|
1100
|
-
const loans = yield contract.getActiveLoansBatch(i, currentBatchSize);
|
|
1101
|
-
for (const loan of loans) {
|
|
1102
|
-
positions.push({
|
|
1103
|
-
trader: loan.borrower,
|
|
1104
|
-
tokenCollateral: loan.collateral.collateralAddress,
|
|
1105
|
-
loanId: loan.id,
|
|
1106
|
-
openingPositionSize: loan.amount + loan.userPaid,
|
|
1107
|
-
collateralAmount: loan.collateralAmount,
|
|
1108
|
-
initialMargin: loan.userPaid,
|
|
1109
|
-
transactionHash: "",
|
|
1110
|
-
// Not available from loan data
|
|
1111
|
-
timestamp: Number(loan.timestamp)
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
return positions;
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
|
|
1119
|
-
return __async(this, null, function* () {
|
|
1120
|
-
const contract = new import_ethers.Contract(
|
|
1121
|
-
borrowerOpsContractAddress,
|
|
1122
|
-
borrowerOperationsAbi,
|
|
1123
|
-
provider
|
|
1124
|
-
);
|
|
1125
|
-
const currentBlock = yield provider.getBlockNumber();
|
|
1126
|
-
const filter = contract.filters.Sell();
|
|
1127
|
-
const allEvents = [];
|
|
1128
|
-
for (let start = fromBlock; start <= currentBlock; start += 1e4) {
|
|
1129
|
-
const end = Math.min(start + 9999, currentBlock);
|
|
1130
|
-
const events = yield contract.queryFilter(filter, start, end);
|
|
1131
|
-
allEvents.push(...events);
|
|
1132
|
-
}
|
|
1133
|
-
return Promise.all(
|
|
1134
|
-
allEvents.map((event) => __async(this, null, function* () {
|
|
1135
|
-
const { buyer, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
|
|
1136
|
-
const block = yield provider.getBlock(event.blockNumber);
|
|
1137
|
-
const timestamp = block ? Number(block.timestamp) : 0;
|
|
1138
|
-
return {
|
|
1139
|
-
trader: buyer,
|
|
1140
|
-
tokenCollateral,
|
|
1141
|
-
loanId,
|
|
1142
|
-
closingPositionSize,
|
|
1143
|
-
profit,
|
|
1144
|
-
transactionHash: event.transactionHash,
|
|
1145
|
-
timestamp
|
|
1146
|
-
};
|
|
1147
|
-
}))
|
|
1148
|
-
);
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
|
|
1152
|
-
return __async(this, null, function* () {
|
|
1153
|
-
const contract = new import_ethers.Contract(
|
|
1154
|
-
borrowerOpsContractAddress,
|
|
1155
|
-
borrowerOperationsAbi,
|
|
1156
|
-
provider
|
|
1157
|
-
);
|
|
1158
|
-
const currentBlock = yield provider.getBlockNumber();
|
|
1159
|
-
const filter = contract.filters.Liquidation();
|
|
1160
|
-
const allEvents = [];
|
|
1161
|
-
for (let start = fromBlock; start <= currentBlock; start += 1e4) {
|
|
1162
|
-
const end = Math.min(start + 9999, currentBlock);
|
|
1163
|
-
const events = yield contract.queryFilter(filter, start, end);
|
|
1164
|
-
allEvents.push(...events);
|
|
1165
|
-
}
|
|
1166
|
-
return Promise.all(
|
|
1167
|
-
allEvents.map((event) => __async(this, null, function* () {
|
|
1168
|
-
const {
|
|
1169
|
-
borrower,
|
|
1170
|
-
tokenCollateral,
|
|
1171
|
-
loanId,
|
|
1172
|
-
closingPositionSize,
|
|
1173
|
-
liquidatorRepaidAmount
|
|
1174
|
-
} = event.args;
|
|
1175
|
-
const block = yield provider.getBlock(event.blockNumber);
|
|
1176
|
-
const timestamp = block ? Number(block.timestamp) : 0;
|
|
1177
|
-
return {
|
|
1178
|
-
trader: borrower,
|
|
1179
|
-
tokenCollateral,
|
|
1180
|
-
loanId,
|
|
1181
|
-
closingPositionSize,
|
|
1182
|
-
liquidatorRepaidAmount,
|
|
1183
|
-
transactionHash: event.transactionHash,
|
|
1184
|
-
timestamp
|
|
1185
|
-
};
|
|
1186
|
-
}))
|
|
1187
|
-
);
|
|
1188
|
-
});
|
|
1189
|
-
}
|
|
1190
|
-
function getLoanEvm(provider, tokenHolderContractAddress, loanId) {
|
|
1191
|
-
return __async(this, null, function* () {
|
|
1192
|
-
const contract = new import_ethers.Contract(
|
|
1193
|
-
tokenHolderContractAddress,
|
|
1194
|
-
tokenHolderAbi,
|
|
1195
|
-
provider
|
|
1196
|
-
);
|
|
1197
|
-
return contract.loans(loanId);
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
function getUserLoansEvm(provider, tokenHolderContractAddress, userAddress) {
|
|
1201
|
-
return __async(this, null, function* () {
|
|
1202
|
-
const contract = new import_ethers.Contract(
|
|
1203
|
-
tokenHolderContractAddress,
|
|
1204
|
-
tokenHolderAbi,
|
|
1205
|
-
provider
|
|
1206
|
-
);
|
|
1207
|
-
const nextLoanId = yield contract.nextLoanId();
|
|
1208
|
-
const userLoans = [];
|
|
1209
|
-
for (let i = 0; i < nextLoanId; i++) {
|
|
1210
|
-
const loan = yield contract.loans(i);
|
|
1211
|
-
if (loan.borrower.toLowerCase() === userAddress.toLowerCase()) {
|
|
1212
|
-
userLoans.push(loan);
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
return userLoans;
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
function getCollateralInfoEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
1219
|
-
return __async(this, null, function* () {
|
|
1220
|
-
const contract = new import_ethers.Contract(
|
|
1221
|
-
tokenHolderContractAddress,
|
|
1222
|
-
tokenHolderAbi,
|
|
1223
|
-
provider
|
|
1224
|
-
);
|
|
1225
|
-
return contract.collateralMapping(collateralAddress);
|
|
1226
|
-
});
|
|
1227
|
-
}
|
|
1228
|
-
function getOffersEvm(provider, tokenHolderContractAddress, collateralAddresses) {
|
|
1229
|
-
return __async(this, null, function* () {
|
|
1230
|
-
const contract = new import_ethers.Contract(
|
|
1231
|
-
tokenHolderContractAddress,
|
|
1232
|
-
tokenHolderAbi,
|
|
1233
|
-
provider
|
|
1234
|
-
);
|
|
1235
|
-
const activeCollaterals = [];
|
|
1236
|
-
for (const address of collateralAddresses) {
|
|
1237
|
-
const collateral = yield contract.collateralMapping(address);
|
|
1238
|
-
activeCollaterals.push({
|
|
1239
|
-
address,
|
|
1240
|
-
collateral
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
return activeCollaterals;
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
function getOpeningFeeEvm(provider, borrowerOpsContractAddress) {
|
|
1247
|
-
return __async(this, null, function* () {
|
|
1248
|
-
const contract = new import_ethers.Contract(
|
|
1249
|
-
borrowerOpsContractAddress,
|
|
1250
|
-
borrowerOperationsAbi,
|
|
1251
|
-
provider
|
|
1252
|
-
);
|
|
1253
|
-
return contract.openingFee();
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
function getProfitFeeEvm(provider, borrowerOpsContractAddress) {
|
|
1257
|
-
return __async(this, null, function* () {
|
|
1258
|
-
const contract = new import_ethers.Contract(
|
|
1259
|
-
borrowerOpsContractAddress,
|
|
1260
|
-
borrowerOperationsAbi,
|
|
1261
|
-
provider
|
|
1262
|
-
);
|
|
1263
|
-
return contract.profitFee();
|
|
1264
|
-
});
|
|
1265
|
-
}
|
|
1266
|
-
function getTokenBalanceEvm(provider, tokenHolderContractAddress) {
|
|
1267
|
-
return __async(this, null, function* () {
|
|
1268
|
-
const contract = new import_ethers.Contract(
|
|
1269
|
-
tokenHolderContractAddress,
|
|
1270
|
-
tokenHolderAbi,
|
|
1271
|
-
provider
|
|
1272
|
-
);
|
|
1273
|
-
return contract.getBalance();
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
function getActiveLoanCountEvm(provider, tokenHolderContractAddress) {
|
|
1277
|
-
return __async(this, null, function* () {
|
|
1278
|
-
const contract = new import_ethers.Contract(
|
|
1279
|
-
tokenHolderContractAddress,
|
|
1280
|
-
tokenHolderAbi,
|
|
1281
|
-
provider
|
|
1282
|
-
);
|
|
1283
|
-
return contract.getActiveLoanCount();
|
|
1284
|
-
});
|
|
1285
|
-
}
|
|
1286
|
-
function getActiveLoansBatchEvm(provider, tokenHolderContractAddress, startIndex, batchSize) {
|
|
1287
|
-
return __async(this, null, function* () {
|
|
1288
|
-
const contract = new import_ethers.Contract(
|
|
1289
|
-
tokenHolderContractAddress,
|
|
1290
|
-
tokenHolderAbi,
|
|
1291
|
-
provider
|
|
1292
|
-
);
|
|
1293
|
-
return contract.getActiveLoansBatch(startIndex, batchSize);
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
function getLoansByBorrowerEvm(provider, tokenHolderContractAddress, borrowerAddress) {
|
|
1297
|
-
return __async(this, null, function* () {
|
|
1298
|
-
const contract = new import_ethers.Contract(
|
|
1299
|
-
tokenHolderContractAddress,
|
|
1300
|
-
tokenHolderAbi,
|
|
1301
|
-
provider
|
|
1302
|
-
);
|
|
1303
|
-
return contract.getLoansByBorrower(borrowerAddress);
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
function getCollateralExposureEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
1307
|
-
return __async(this, null, function* () {
|
|
1308
|
-
const contract = new import_ethers.Contract(
|
|
1309
|
-
tokenHolderContractAddress,
|
|
1310
|
-
tokenHolderAbi,
|
|
1311
|
-
provider
|
|
1312
|
-
);
|
|
1313
|
-
return contract.getCollateralExposure(collateralAddress);
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
|
-
function getAvailableExposureEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
1317
|
-
return __async(this, null, function* () {
|
|
1318
|
-
const contract = new import_ethers.Contract(
|
|
1319
|
-
tokenHolderContractAddress,
|
|
1320
|
-
tokenHolderAbi,
|
|
1321
|
-
provider
|
|
1322
|
-
);
|
|
1323
|
-
return contract.getAvailableExposure(collateralAddress);
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
// lending.ts
|
|
1328
|
-
var lending_exports = {};
|
|
1329
|
-
__export(lending_exports, {
|
|
1330
|
-
createOffer: () => createOffer,
|
|
1331
|
-
depositFunds: () => depositFunds,
|
|
1332
|
-
getNodeWalletPDA: () => getNodeWalletPDA,
|
|
1333
|
-
getTradingPoolPDA: () => getTradingPoolPDA,
|
|
1334
|
-
updateInterestRate: () => updateInterestRate,
|
|
1335
|
-
updateMaxExposure: () => updateMaxExposure,
|
|
1336
|
-
updateOffer: () => updateOffer,
|
|
1337
|
-
withdrawFunds: () => withdrawFunds,
|
|
1338
|
-
withdrawFundsV1: () => withdrawFundsV1,
|
|
1339
|
-
withdrawFundsV2: () => withdrawFundsV2
|
|
1340
|
-
});
|
|
1341
111
|
var import_anchor = require("@coral-xyz/anchor");
|
|
112
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
1342
113
|
var import_web3 = require("@solana/web3.js");
|
|
1343
114
|
var import_spl_token = require("@solana/spl-token");
|
|
1344
|
-
function getNodeWalletPDA(operatorPublicKey, mintPublicKey, programId) {
|
|
1345
|
-
return getPda(
|
|
1346
|
-
[
|
|
1347
|
-
Buffer.from("node_wallet"),
|
|
1348
|
-
operatorPublicKey.toBuffer(),
|
|
1349
|
-
mintPublicKey.toBuffer()
|
|
1350
|
-
],
|
|
1351
|
-
programId
|
|
1352
|
-
);
|
|
1353
|
-
}
|
|
1354
|
-
function getTradingPoolPDA(poolOwnerPublicKey, tokenPublicKey, programId) {
|
|
1355
|
-
return getPda(
|
|
1356
|
-
[
|
|
1357
|
-
Buffer.from("trading_pool"),
|
|
1358
|
-
poolOwnerPublicKey.toBuffer(),
|
|
1359
|
-
tokenPublicKey.toBuffer()
|
|
1360
|
-
],
|
|
1361
|
-
programId
|
|
1362
|
-
);
|
|
1363
|
-
}
|
|
1364
|
-
var computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
1365
|
-
microLamports: 15e4
|
|
1366
|
-
});
|
|
1367
|
-
function createNodeWallet(lavarageProgram, params) {
|
|
1368
|
-
return __async(this, null, function* () {
|
|
1369
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1370
|
-
let instruction, nodeWallet;
|
|
1371
|
-
if (params.liquidationLtv !== void 0 && params.mint !== void 0) {
|
|
1372
|
-
nodeWallet = getNodeWalletPDA(
|
|
1373
|
-
new import_web3.PublicKey(params.operator),
|
|
1374
|
-
new import_web3.PublicKey(params.mint),
|
|
1375
|
-
lavarageProgram.programId
|
|
1376
|
-
);
|
|
1377
|
-
instruction = yield lavarageProgram.methods.lpOperatorCreateNodeWallet(new import_anchor.BN(params.liquidationLtv)).accounts({
|
|
1378
|
-
nodeWallet,
|
|
1379
|
-
operator: new import_web3.PublicKey(params.operator),
|
|
1380
|
-
systemProgram: import_web3.SystemProgram.programId,
|
|
1381
|
-
mint: new import_web3.PublicKey(params.mint)
|
|
1382
|
-
}).instruction();
|
|
1383
|
-
} else {
|
|
1384
|
-
nodeWallet = import_web3.Keypair.generate();
|
|
1385
|
-
instruction = yield lavarageProgram.methods.lpOperatorCreateNodeWallet().accounts({
|
|
1386
|
-
nodeWallet: nodeWallet.publicKey,
|
|
1387
|
-
operator: new import_web3.PublicKey(params.operator),
|
|
1388
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1389
|
-
}).instruction();
|
|
1390
|
-
}
|
|
1391
|
-
return {
|
|
1392
|
-
instruction,
|
|
1393
|
-
nodeWallet: nodeWallet instanceof import_web3.Keypair ? nodeWallet : void 0
|
|
1394
|
-
};
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
function depositFunds(lavarageProgram, params) {
|
|
1398
|
-
return __async(this, null, function* () {
|
|
1399
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1400
|
-
let instruction;
|
|
1401
|
-
if (params.mint === void 0) {
|
|
1402
|
-
instruction = yield lavarageProgram.methods.lpOperatorFundNodeWallet(new import_anchor.BN(params.amount)).accounts({
|
|
1403
|
-
nodeWallet: params.nodeWallet,
|
|
1404
|
-
funder: params.funder,
|
|
1405
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1406
|
-
}).instruction();
|
|
1407
|
-
} else {
|
|
1408
|
-
const mintPubkey = new import_web3.PublicKey(params.mint);
|
|
1409
|
-
const mintOwner = yield lavarageProgram.provider.connection.getAccountInfo(mintPubkey);
|
|
1410
|
-
const mintAccount = yield (0, import_spl_token.getMint)(lavarageProgram.provider.connection, mintPubkey, "confirmed", mintOwner == null ? void 0 : mintOwner.owner);
|
|
1411
|
-
instruction = (0, import_spl_token.createTransferCheckedInstruction)(
|
|
1412
|
-
(0, import_spl_token.getAssociatedTokenAddressSync)(mintPubkey, new import_web3.PublicKey(params.funder), true, mintOwner == null ? void 0 : mintOwner.owner),
|
|
1413
|
-
new import_web3.PublicKey(params.mint),
|
|
1414
|
-
(0, import_spl_token.getAssociatedTokenAddressSync)(mintPubkey, new import_web3.PublicKey(params.nodeWallet), true, mintOwner == null ? void 0 : mintOwner.owner),
|
|
1415
|
-
lavarageProgram.provider.publicKey,
|
|
1416
|
-
params.amount,
|
|
1417
|
-
mintAccount.decimals,
|
|
1418
|
-
[],
|
|
1419
|
-
mintOwner == null ? void 0 : mintOwner.owner
|
|
1420
|
-
);
|
|
1421
|
-
}
|
|
1422
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1423
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1424
|
-
recentBlockhash: blockhash,
|
|
1425
|
-
instructions: [instruction, computeFeeIx]
|
|
1426
|
-
}).compileToV0Message();
|
|
1427
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1428
|
-
});
|
|
1429
|
-
}
|
|
1430
|
-
function withdrawFundsV1(lavarageProgram, params) {
|
|
1431
|
-
return __async(this, null, function* () {
|
|
1432
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1433
|
-
const instruction = yield lavarageProgram.methods.lpOperatorWithdrawFromNodeWallet(new import_anchor.BN(params.amount)).accounts({
|
|
1434
|
-
nodeWallet: params.nodeWallet,
|
|
1435
|
-
funder: params.funder,
|
|
1436
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1437
|
-
}).instruction();
|
|
1438
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1439
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1440
|
-
recentBlockhash: blockhash,
|
|
1441
|
-
instructions: [instruction, computeFeeIx]
|
|
1442
|
-
}).compileToV0Message();
|
|
1443
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1444
|
-
});
|
|
1445
|
-
}
|
|
1446
|
-
function withdrawFundsV2(lavarageProgram, params) {
|
|
1447
|
-
return __async(this, null, function* () {
|
|
1448
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1449
|
-
const mintPubkey = new import_web3.PublicKey(params.mint);
|
|
1450
|
-
const fromTokenAccount = params.fromTokenAccount || (0, import_spl_token.getAssociatedTokenAddressSync)(mintPubkey, params.nodeWallet, true);
|
|
1451
|
-
const toTokenAccount = params.toTokenAccount || (0, import_spl_token.getAssociatedTokenAddressSync)(mintPubkey, params.funder);
|
|
1452
|
-
const instruction = yield lavarageProgram.methods.lpOperatorWithdrawFromNodeWallet(new import_anchor.BN(params.amount)).accounts({
|
|
1453
|
-
nodeWallet: params.nodeWallet,
|
|
1454
|
-
funder: params.funder,
|
|
1455
|
-
systemProgram: import_web3.SystemProgram.programId,
|
|
1456
|
-
mint: mintPubkey,
|
|
1457
|
-
fromTokenAccount,
|
|
1458
|
-
toTokenAccount,
|
|
1459
|
-
tokenProgram: import_spl_token.TOKEN_PROGRAM_ID
|
|
1460
|
-
}).instruction();
|
|
1461
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1462
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1463
|
-
recentBlockhash: blockhash,
|
|
1464
|
-
instructions: [instruction, computeFeeIx]
|
|
1465
|
-
}).compileToV0Message();
|
|
1466
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
function withdrawFunds(lavarageProgram, params) {
|
|
1470
|
-
return __async(this, null, function* () {
|
|
1471
|
-
if (params.mint) {
|
|
1472
|
-
return withdrawFundsV2(lavarageProgram, {
|
|
1473
|
-
nodeWallet: params.nodeWallet,
|
|
1474
|
-
funder: params.funder,
|
|
1475
|
-
mint: params.mint,
|
|
1476
|
-
amount: params.amount,
|
|
1477
|
-
fromTokenAccount: params.fromTokenAccount,
|
|
1478
|
-
toTokenAccount: params.toTokenAccount
|
|
1479
|
-
});
|
|
1480
|
-
} else {
|
|
1481
|
-
return withdrawFundsV1(lavarageProgram, {
|
|
1482
|
-
nodeWallet: params.nodeWallet,
|
|
1483
|
-
funder: params.funder,
|
|
1484
|
-
amount: params.amount
|
|
1485
|
-
});
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
}
|
|
1489
|
-
function createOffer(lavarageProgram, params) {
|
|
1490
|
-
return __async(this, null, function* () {
|
|
1491
|
-
const nodeWalletAccount = yield lavarageProgram.provider.connection.getAccountInfo(new import_web3.PublicKey(params.nodeWallet));
|
|
1492
|
-
let nodeWalletSigner, createNodeWalletInstruction;
|
|
1493
|
-
if (!nodeWalletAccount) {
|
|
1494
|
-
const { instruction: instruction2, nodeWallet } = yield createNodeWallet(lavarageProgram, {
|
|
1495
|
-
operator: new import_web3.PublicKey(params.poolOwner.toBase58()),
|
|
1496
|
-
mint: params.mint,
|
|
1497
|
-
liquidationLtv: 90
|
|
1498
|
-
});
|
|
1499
|
-
nodeWalletSigner = nodeWallet;
|
|
1500
|
-
createNodeWalletInstruction = instruction2;
|
|
1501
|
-
}
|
|
1502
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1503
|
-
const instruction = yield lavarageProgram.methods.lpOperatorCreateTradingPool(new import_anchor.BN(params.interestRate)).accounts({
|
|
1504
|
-
tradingPool: params.tradingPool,
|
|
1505
|
-
operator: params.poolOwner,
|
|
1506
|
-
nodeWallet: new import_web3.PublicKey(params.nodeWallet),
|
|
1507
|
-
mint: params.mint ? new import_web3.PublicKey(params.mint) : void 0,
|
|
1508
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1509
|
-
}).instruction();
|
|
1510
|
-
const updateMaxExposureInstruction = yield lavarageProgram.methods.lpOperatorUpdateMaxExposure(new import_anchor.BN(params.maxExposure)).accounts({
|
|
1511
|
-
tradingPool: params.tradingPool,
|
|
1512
|
-
nodeWallet: new import_web3.PublicKey(params.nodeWallet),
|
|
1513
|
-
operator: params.poolOwner,
|
|
1514
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1515
|
-
}).instruction();
|
|
1516
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1517
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1518
|
-
recentBlockhash: blockhash,
|
|
1519
|
-
instructions: [createNodeWalletInstruction === void 0 ? null : createNodeWalletInstruction, instruction, updateMaxExposureInstruction, computeFeeIx].filter(Boolean)
|
|
1520
|
-
}).compileToV0Message();
|
|
1521
|
-
if (nodeWalletSigner) {
|
|
1522
|
-
const transaction = new import_web3.VersionedTransaction(messageV0);
|
|
1523
|
-
transaction.addSignature(
|
|
1524
|
-
nodeWalletSigner.publicKey,
|
|
1525
|
-
nodeWalletSigner.secretKey
|
|
1526
|
-
);
|
|
1527
|
-
return transaction;
|
|
1528
|
-
}
|
|
1529
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
function updateMaxExposure(lavarageProgram, params) {
|
|
1533
|
-
return __async(this, null, function* () {
|
|
1534
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1535
|
-
const instruction = yield lavarageProgram.methods.lpOperatorUpdateMaxExposure(new import_anchor.BN(params.maxExposure)).accounts({
|
|
1536
|
-
tradingPool: params.tradingPool,
|
|
1537
|
-
nodeWallet: new import_web3.PublicKey(params.nodeWallet),
|
|
1538
|
-
operator: params.poolOwner,
|
|
1539
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1540
|
-
}).instruction();
|
|
1541
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1542
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1543
|
-
recentBlockhash: blockhash,
|
|
1544
|
-
instructions: [instruction]
|
|
1545
|
-
}).compileToV0Message();
|
|
1546
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
|
-
function updateInterestRate(lavarageProgram, params) {
|
|
1550
|
-
return __async(this, null, function* () {
|
|
1551
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1552
|
-
const instruction = yield lavarageProgram.methods.lpOperatorUpdateInterestRate(new import_anchor.BN(params.interestRate)).accounts({
|
|
1553
|
-
tradingPool: params.tradingPool,
|
|
1554
|
-
nodeWallet: new import_web3.PublicKey(params.nodeWallet),
|
|
1555
|
-
operator: params.poolOwner,
|
|
1556
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1557
|
-
}).instruction();
|
|
1558
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1559
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1560
|
-
recentBlockhash: blockhash,
|
|
1561
|
-
instructions: [instruction]
|
|
1562
|
-
}).compileToV0Message();
|
|
1563
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1564
|
-
});
|
|
1565
|
-
}
|
|
1566
|
-
function updateOffer(lavarageProgram, params) {
|
|
1567
|
-
return __async(this, null, function* () {
|
|
1568
|
-
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
1569
|
-
const instructions = [];
|
|
1570
|
-
const updateMaxExposureInstruction = yield lavarageProgram.methods.lpOperatorUpdateMaxExposure(new import_anchor.BN(params.maxExposure)).accounts({
|
|
1571
|
-
tradingPool: params.tradingPool,
|
|
1572
|
-
nodeWallet: new import_web3.PublicKey(params.nodeWallet),
|
|
1573
|
-
operator: params.poolOwner,
|
|
1574
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1575
|
-
}).instruction();
|
|
1576
|
-
const updateInterestRateInstruction = yield lavarageProgram.methods.lpOperatorUpdateInterestRate(new import_anchor.BN(params.interestRate)).accounts({
|
|
1577
|
-
tradingPool: params.tradingPool,
|
|
1578
|
-
nodeWallet: new import_web3.PublicKey(params.nodeWallet),
|
|
1579
|
-
operator: params.poolOwner,
|
|
1580
|
-
systemProgram: import_web3.SystemProgram.programId
|
|
1581
|
-
}).instruction();
|
|
1582
|
-
instructions.push(
|
|
1583
|
-
updateMaxExposureInstruction,
|
|
1584
|
-
updateInterestRateInstruction
|
|
1585
|
-
);
|
|
1586
|
-
const messageV0 = new import_web3.TransactionMessage({
|
|
1587
|
-
payerKey: lavarageProgram.provider.publicKey,
|
|
1588
|
-
recentBlockhash: blockhash,
|
|
1589
|
-
instructions
|
|
1590
|
-
}).compileToV0Message();
|
|
1591
|
-
return new import_web3.VersionedTransaction(messageV0);
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
115
|
|
|
1595
116
|
// idl/lavarage.ts
|
|
1596
117
|
var IDL = {
|
|
@@ -3823,410 +2344,1394 @@ var IDL2 = {
|
|
|
3823
2344
|
],
|
|
3824
2345
|
"accounts": [
|
|
3825
2346
|
{
|
|
3826
|
-
"name": "delegate",
|
|
2347
|
+
"name": "delegate",
|
|
2348
|
+
"type": {
|
|
2349
|
+
"kind": "struct",
|
|
2350
|
+
"fields": [
|
|
2351
|
+
{
|
|
2352
|
+
"name": "delegateType",
|
|
2353
|
+
"type": "u8"
|
|
2354
|
+
},
|
|
2355
|
+
{
|
|
2356
|
+
"name": "field1",
|
|
2357
|
+
"type": "u64"
|
|
2358
|
+
},
|
|
2359
|
+
{
|
|
2360
|
+
"name": "field2",
|
|
2361
|
+
"type": "u64"
|
|
2362
|
+
},
|
|
2363
|
+
{
|
|
2364
|
+
"name": "field3",
|
|
2365
|
+
"type": "u64"
|
|
2366
|
+
},
|
|
2367
|
+
{
|
|
2368
|
+
"name": "field4",
|
|
2369
|
+
"type": "publicKey"
|
|
2370
|
+
},
|
|
2371
|
+
{
|
|
2372
|
+
"name": "field5",
|
|
2373
|
+
"type": "publicKey"
|
|
2374
|
+
},
|
|
2375
|
+
{
|
|
2376
|
+
"name": "originalOperator",
|
|
2377
|
+
"type": "publicKey"
|
|
2378
|
+
},
|
|
2379
|
+
{
|
|
2380
|
+
"name": "delegateOperator",
|
|
2381
|
+
"type": "publicKey"
|
|
2382
|
+
},
|
|
2383
|
+
{
|
|
2384
|
+
"name": "account",
|
|
2385
|
+
"type": "publicKey"
|
|
2386
|
+
}
|
|
2387
|
+
]
|
|
2388
|
+
}
|
|
2389
|
+
},
|
|
2390
|
+
{
|
|
2391
|
+
"name": "nodeWallet",
|
|
2392
|
+
"type": {
|
|
2393
|
+
"kind": "struct",
|
|
2394
|
+
"fields": [
|
|
2395
|
+
{
|
|
2396
|
+
"name": "totalFunds",
|
|
2397
|
+
"type": "u64"
|
|
2398
|
+
},
|
|
2399
|
+
{
|
|
2400
|
+
"name": "totalBorrowed",
|
|
2401
|
+
"type": "u64"
|
|
2402
|
+
},
|
|
2403
|
+
{
|
|
2404
|
+
"name": "maintenanceLtv",
|
|
2405
|
+
"type": "u8"
|
|
2406
|
+
},
|
|
2407
|
+
{
|
|
2408
|
+
"name": "liquidationLtv",
|
|
2409
|
+
"type": "u16"
|
|
2410
|
+
},
|
|
2411
|
+
{
|
|
2412
|
+
"name": "nodeOperator",
|
|
2413
|
+
"type": "publicKey"
|
|
2414
|
+
},
|
|
2415
|
+
{
|
|
2416
|
+
"name": "mint",
|
|
2417
|
+
"type": "publicKey"
|
|
2418
|
+
}
|
|
2419
|
+
]
|
|
2420
|
+
}
|
|
2421
|
+
},
|
|
2422
|
+
{
|
|
2423
|
+
"name": "pool",
|
|
2424
|
+
"type": {
|
|
2425
|
+
"kind": "struct",
|
|
2426
|
+
"fields": [
|
|
2427
|
+
{
|
|
2428
|
+
"name": "interestRate",
|
|
2429
|
+
"type": "u8"
|
|
2430
|
+
},
|
|
2431
|
+
{
|
|
2432
|
+
"name": "collateralType",
|
|
2433
|
+
"type": "publicKey"
|
|
2434
|
+
},
|
|
2435
|
+
{
|
|
2436
|
+
"name": "maxBorrow",
|
|
2437
|
+
"type": "u64"
|
|
2438
|
+
},
|
|
2439
|
+
{
|
|
2440
|
+
"name": "nodeWallet",
|
|
2441
|
+
"type": "publicKey"
|
|
2442
|
+
},
|
|
2443
|
+
{
|
|
2444
|
+
"name": "maxExposure",
|
|
2445
|
+
"type": "u64"
|
|
2446
|
+
},
|
|
2447
|
+
{
|
|
2448
|
+
"name": "currentExposure",
|
|
2449
|
+
"type": "u64"
|
|
2450
|
+
},
|
|
2451
|
+
{
|
|
2452
|
+
"name": "qtType",
|
|
2453
|
+
"type": "publicKey"
|
|
2454
|
+
}
|
|
2455
|
+
]
|
|
2456
|
+
}
|
|
2457
|
+
},
|
|
2458
|
+
{
|
|
2459
|
+
"name": "position",
|
|
3827
2460
|
"type": {
|
|
3828
2461
|
"kind": "struct",
|
|
3829
2462
|
"fields": [
|
|
3830
2463
|
{
|
|
3831
|
-
"name": "
|
|
3832
|
-
"type": "
|
|
2464
|
+
"name": "pool",
|
|
2465
|
+
"type": "publicKey"
|
|
3833
2466
|
},
|
|
3834
2467
|
{
|
|
3835
|
-
"name": "
|
|
2468
|
+
"name": "closeStatusRecallTimestamp",
|
|
3836
2469
|
"type": "u64"
|
|
3837
2470
|
},
|
|
3838
2471
|
{
|
|
3839
|
-
"name": "
|
|
2472
|
+
"name": "amount",
|
|
3840
2473
|
"type": "u64"
|
|
3841
2474
|
},
|
|
3842
2475
|
{
|
|
3843
|
-
"name": "
|
|
2476
|
+
"name": "userPaid",
|
|
3844
2477
|
"type": "u64"
|
|
3845
2478
|
},
|
|
3846
2479
|
{
|
|
3847
|
-
"name": "
|
|
3848
|
-
"type": "
|
|
2480
|
+
"name": "collateralAmount",
|
|
2481
|
+
"type": "u64"
|
|
3849
2482
|
},
|
|
3850
2483
|
{
|
|
3851
|
-
"name": "
|
|
3852
|
-
"type": "
|
|
2484
|
+
"name": "timestamp",
|
|
2485
|
+
"type": "i64"
|
|
3853
2486
|
},
|
|
3854
2487
|
{
|
|
3855
|
-
"name": "
|
|
2488
|
+
"name": "trader",
|
|
3856
2489
|
"type": "publicKey"
|
|
3857
2490
|
},
|
|
3858
2491
|
{
|
|
3859
|
-
"name": "
|
|
2492
|
+
"name": "seed",
|
|
3860
2493
|
"type": "publicKey"
|
|
3861
2494
|
},
|
|
3862
2495
|
{
|
|
3863
|
-
"name": "
|
|
3864
|
-
"type": "
|
|
2496
|
+
"name": "closeTimestamp",
|
|
2497
|
+
"type": "i64"
|
|
2498
|
+
},
|
|
2499
|
+
{
|
|
2500
|
+
"name": "closingPositionSize",
|
|
2501
|
+
"type": "u64"
|
|
2502
|
+
},
|
|
2503
|
+
{
|
|
2504
|
+
"name": "interestRate",
|
|
2505
|
+
"type": "u8"
|
|
2506
|
+
},
|
|
2507
|
+
{
|
|
2508
|
+
"name": "lastInterestCollect",
|
|
2509
|
+
"type": "i64"
|
|
2510
|
+
}
|
|
2511
|
+
]
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
],
|
|
2515
|
+
"types": [
|
|
2516
|
+
{
|
|
2517
|
+
"name": "LendingErrors",
|
|
2518
|
+
"docs": [
|
|
2519
|
+
"Errors for this program"
|
|
2520
|
+
],
|
|
2521
|
+
"type": {
|
|
2522
|
+
"kind": "enum",
|
|
2523
|
+
"variants": [
|
|
2524
|
+
{
|
|
2525
|
+
"name": "AddressMismatch"
|
|
2526
|
+
},
|
|
2527
|
+
{
|
|
2528
|
+
"name": "ProgramMismatch"
|
|
2529
|
+
},
|
|
2530
|
+
{
|
|
2531
|
+
"name": "MissingRepay"
|
|
2532
|
+
},
|
|
2533
|
+
{
|
|
2534
|
+
"name": "IncorrectOwner"
|
|
2535
|
+
},
|
|
2536
|
+
{
|
|
2537
|
+
"name": "IncorrectProgramAuthority"
|
|
2538
|
+
},
|
|
2539
|
+
{
|
|
2540
|
+
"name": "CannotBorrowBeforeRepay"
|
|
2541
|
+
},
|
|
2542
|
+
{
|
|
2543
|
+
"name": "UnknownInstruction"
|
|
2544
|
+
},
|
|
2545
|
+
{
|
|
2546
|
+
"name": "ExpectedCollateralNotEnough"
|
|
3865
2547
|
}
|
|
3866
2548
|
]
|
|
3867
2549
|
}
|
|
3868
2550
|
},
|
|
3869
2551
|
{
|
|
3870
|
-
"name": "
|
|
2552
|
+
"name": "ErrorCode",
|
|
3871
2553
|
"type": {
|
|
3872
|
-
"kind": "
|
|
3873
|
-
"
|
|
2554
|
+
"kind": "enum",
|
|
2555
|
+
"variants": [
|
|
3874
2556
|
{
|
|
3875
|
-
"name": "
|
|
3876
|
-
"type": "u64"
|
|
2557
|
+
"name": "InvalidSignature"
|
|
3877
2558
|
},
|
|
3878
2559
|
{
|
|
3879
|
-
"name": "
|
|
3880
|
-
|
|
2560
|
+
"name": "InvalidOracle"
|
|
2561
|
+
}
|
|
2562
|
+
]
|
|
2563
|
+
}
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
"name": "ErrorCode",
|
|
2567
|
+
"type": {
|
|
2568
|
+
"kind": "enum",
|
|
2569
|
+
"variants": [
|
|
2570
|
+
{
|
|
2571
|
+
"name": "InvalidSplitRatio"
|
|
3881
2572
|
},
|
|
3882
2573
|
{
|
|
3883
|
-
"name": "
|
|
3884
|
-
|
|
2574
|
+
"name": "PositionsNotMergeable"
|
|
2575
|
+
}
|
|
2576
|
+
]
|
|
2577
|
+
}
|
|
2578
|
+
},
|
|
2579
|
+
{
|
|
2580
|
+
"name": "ErrorCode",
|
|
2581
|
+
"type": {
|
|
2582
|
+
"kind": "enum",
|
|
2583
|
+
"variants": [
|
|
2584
|
+
{
|
|
2585
|
+
"name": "OnlyDelegateOperator"
|
|
3885
2586
|
},
|
|
3886
2587
|
{
|
|
3887
|
-
"name": "
|
|
3888
|
-
"type": "u16"
|
|
2588
|
+
"name": "AddressMismatch"
|
|
3889
2589
|
},
|
|
3890
2590
|
{
|
|
3891
|
-
"name": "
|
|
3892
|
-
|
|
2591
|
+
"name": "InvalidDelegateType"
|
|
2592
|
+
}
|
|
2593
|
+
]
|
|
2594
|
+
}
|
|
2595
|
+
},
|
|
2596
|
+
{
|
|
2597
|
+
"name": "PositionCloseType",
|
|
2598
|
+
"type": {
|
|
2599
|
+
"kind": "enum",
|
|
2600
|
+
"variants": [
|
|
2601
|
+
{
|
|
2602
|
+
"name": "ClosedByUser"
|
|
3893
2603
|
},
|
|
3894
2604
|
{
|
|
3895
|
-
"name": "
|
|
3896
|
-
"type": "publicKey"
|
|
2605
|
+
"name": "Liquidated"
|
|
3897
2606
|
}
|
|
3898
2607
|
]
|
|
3899
2608
|
}
|
|
2609
|
+
}
|
|
2610
|
+
],
|
|
2611
|
+
"events": [
|
|
2612
|
+
{
|
|
2613
|
+
"name": "PositionCloseEvent",
|
|
2614
|
+
"fields": [
|
|
2615
|
+
{
|
|
2616
|
+
"name": "pool",
|
|
2617
|
+
"type": "publicKey",
|
|
2618
|
+
"index": false
|
|
2619
|
+
},
|
|
2620
|
+
{
|
|
2621
|
+
"name": "amount",
|
|
2622
|
+
"type": "u64",
|
|
2623
|
+
"index": false
|
|
2624
|
+
},
|
|
2625
|
+
{
|
|
2626
|
+
"name": "userPaid",
|
|
2627
|
+
"type": "u64",
|
|
2628
|
+
"index": false
|
|
2629
|
+
},
|
|
2630
|
+
{
|
|
2631
|
+
"name": "collateralAmount",
|
|
2632
|
+
"type": "u64",
|
|
2633
|
+
"index": false
|
|
2634
|
+
},
|
|
2635
|
+
{
|
|
2636
|
+
"name": "openTimestamp",
|
|
2637
|
+
"type": "i64",
|
|
2638
|
+
"index": false
|
|
2639
|
+
},
|
|
2640
|
+
{
|
|
2641
|
+
"name": "trader",
|
|
2642
|
+
"type": "publicKey",
|
|
2643
|
+
"index": false
|
|
2644
|
+
},
|
|
2645
|
+
{
|
|
2646
|
+
"name": "closeType",
|
|
2647
|
+
"type": "u8",
|
|
2648
|
+
"index": false
|
|
2649
|
+
},
|
|
2650
|
+
{
|
|
2651
|
+
"name": "closeTimestamp",
|
|
2652
|
+
"type": "i64",
|
|
2653
|
+
"index": false
|
|
2654
|
+
},
|
|
2655
|
+
{
|
|
2656
|
+
"name": "closingPositionSize",
|
|
2657
|
+
"type": "u64",
|
|
2658
|
+
"index": false
|
|
2659
|
+
}
|
|
2660
|
+
]
|
|
2661
|
+
},
|
|
2662
|
+
{
|
|
2663
|
+
"name": "PositionOpenEvent",
|
|
2664
|
+
"fields": [
|
|
2665
|
+
{
|
|
2666
|
+
"name": "pool",
|
|
2667
|
+
"type": "publicKey",
|
|
2668
|
+
"index": false
|
|
2669
|
+
},
|
|
2670
|
+
{
|
|
2671
|
+
"name": "amount",
|
|
2672
|
+
"type": "u64",
|
|
2673
|
+
"index": false
|
|
2674
|
+
},
|
|
2675
|
+
{
|
|
2676
|
+
"name": "userPaid",
|
|
2677
|
+
"type": "u64",
|
|
2678
|
+
"index": false
|
|
2679
|
+
},
|
|
2680
|
+
{
|
|
2681
|
+
"name": "collateralAmount",
|
|
2682
|
+
"type": "u64",
|
|
2683
|
+
"index": false
|
|
2684
|
+
},
|
|
2685
|
+
{
|
|
2686
|
+
"name": "openTimestamp",
|
|
2687
|
+
"type": "i64",
|
|
2688
|
+
"index": false
|
|
2689
|
+
},
|
|
2690
|
+
{
|
|
2691
|
+
"name": "trader",
|
|
2692
|
+
"type": "publicKey",
|
|
2693
|
+
"index": false
|
|
2694
|
+
}
|
|
2695
|
+
]
|
|
2696
|
+
}
|
|
2697
|
+
],
|
|
2698
|
+
"errors": [
|
|
2699
|
+
{
|
|
2700
|
+
"code": 6e3,
|
|
2701
|
+
"name": "AddressMismatch",
|
|
2702
|
+
"msg": "Address Mismatch"
|
|
2703
|
+
},
|
|
2704
|
+
{
|
|
2705
|
+
"code": 6001,
|
|
2706
|
+
"name": "ProgramMismatch",
|
|
2707
|
+
"msg": "Program Mismatch"
|
|
2708
|
+
},
|
|
2709
|
+
{
|
|
2710
|
+
"code": 6002,
|
|
2711
|
+
"name": "MissingRepay",
|
|
2712
|
+
"msg": "Missing Repay"
|
|
2713
|
+
},
|
|
2714
|
+
{
|
|
2715
|
+
"code": 6003,
|
|
2716
|
+
"name": "IncorrectOwner",
|
|
2717
|
+
"msg": "Incorrect Owner"
|
|
2718
|
+
},
|
|
2719
|
+
{
|
|
2720
|
+
"code": 6004,
|
|
2721
|
+
"name": "IncorrectProgramAuthority",
|
|
2722
|
+
"msg": "Incorrect Program Authority"
|
|
2723
|
+
},
|
|
2724
|
+
{
|
|
2725
|
+
"code": 6005,
|
|
2726
|
+
"name": "CannotBorrowBeforeRepay",
|
|
2727
|
+
"msg": "Cannot Borrow Before Repay"
|
|
3900
2728
|
},
|
|
3901
2729
|
{
|
|
3902
|
-
"
|
|
3903
|
-
"
|
|
3904
|
-
|
|
3905
|
-
"fields": [
|
|
3906
|
-
{
|
|
3907
|
-
"name": "interestRate",
|
|
3908
|
-
"type": "u8"
|
|
3909
|
-
},
|
|
3910
|
-
{
|
|
3911
|
-
"name": "collateralType",
|
|
3912
|
-
"type": "publicKey"
|
|
3913
|
-
},
|
|
3914
|
-
{
|
|
3915
|
-
"name": "maxBorrow",
|
|
3916
|
-
"type": "u64"
|
|
3917
|
-
},
|
|
3918
|
-
{
|
|
3919
|
-
"name": "nodeWallet",
|
|
3920
|
-
"type": "publicKey"
|
|
3921
|
-
},
|
|
3922
|
-
{
|
|
3923
|
-
"name": "maxExposure",
|
|
3924
|
-
"type": "u64"
|
|
3925
|
-
},
|
|
3926
|
-
{
|
|
3927
|
-
"name": "currentExposure",
|
|
3928
|
-
"type": "u64"
|
|
3929
|
-
},
|
|
3930
|
-
{
|
|
3931
|
-
"name": "qtType",
|
|
3932
|
-
"type": "publicKey"
|
|
3933
|
-
}
|
|
3934
|
-
]
|
|
3935
|
-
}
|
|
2730
|
+
"code": 6006,
|
|
2731
|
+
"name": "UnknownInstruction",
|
|
2732
|
+
"msg": "Unknown Instruction"
|
|
3936
2733
|
},
|
|
3937
2734
|
{
|
|
3938
|
-
"
|
|
3939
|
-
"
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
2735
|
+
"code": 6007,
|
|
2736
|
+
"name": "ExpectedCollateralNotEnough",
|
|
2737
|
+
"msg": "Expected collateral not enough"
|
|
2738
|
+
},
|
|
2739
|
+
{
|
|
2740
|
+
"code": 6008,
|
|
2741
|
+
"name": "ForTesting",
|
|
2742
|
+
"msg": "TestError"
|
|
2743
|
+
}
|
|
2744
|
+
]
|
|
2745
|
+
};
|
|
2746
|
+
|
|
2747
|
+
// evm.ts
|
|
2748
|
+
var import_ethers = require("ethers");
|
|
2749
|
+
|
|
2750
|
+
// abi/borrowerOperations.ts
|
|
2751
|
+
var borrowerOperationsAbi = [{ "type": "function", "name": "admin", "inputs": [], "outputs": [{ "name": "", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "buy", "inputs": [{ "name": "buyingCode", "type": "bytes", "internalType": "bytes" }, { "name": "tokenCollateral", "type": "address", "internalType": "contract IERC20" }, { "name": "borrowAmount", "type": "uint256", "internalType": "uint256" }, { "name": "tokenHolder", "type": "address", "internalType": "contract TokenHolder" }, { "name": "inchRouter", "type": "address", "internalType": "address" }, { "name": "integratorFeeAddress", "type": "address", "internalType": "address" }], "outputs": [], "stateMutability": "payable" }, { "type": "function", "name": "initialize", "inputs": [{ "name": "_weth", "type": "address", "internalType": "contract IERC20" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "liquidate", "inputs": [{ "name": "loanId", "type": "uint256", "internalType": "uint256" }, { "name": "tokenHolder", "type": "address", "internalType": "contract TokenHolder" }, { "name": "closingPositionSize", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "loanRecords", "inputs": [{ "name": "", "type": "address", "internalType": "address" }, { "name": "", "type": "uint256", "internalType": "uint256" }], "outputs": [{ "name": "id", "type": "uint256", "internalType": "uint256" }, { "name": "tokenHolder", "type": "address", "internalType": "address" }], "stateMutability": "view" }, { "type": "function", "name": "openingFee", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "profitFee", "inputs": [], "outputs": [{ "name": "", "type": "uint256", "internalType": "uint256" }], "stateMutability": "view" }, { "type": "function", "name": "sell", "inputs": [{ "name": "loanId", "type": "uint256", "internalType": "uint256" }, { "name": "sellingCode", "type": "bytes", "internalType": "bytes" }, { "name": "tokenHolder", "type": "address", "internalType": "contract TokenHolder" }, { "name": "inchRouter", "type": "address", "internalType": "address" }, { "name": "integratorFeeAddress", "type": "address", "internalType": "address" }], "outputs": [], "stateMutability": "payable" }, { "type": "function", "name": "setAdmin", "inputs": [{ "name": "_admin", "type": "address", "internalType": "address" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "setOpeningFee", "inputs": [{ "name": "_openingFee", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "function", "name": "setProfitFee", "inputs": [{ "name": "_profitFee", "type": "uint256", "internalType": "uint256" }], "outputs": [], "stateMutability": "nonpayable" }, { "type": "event", "name": "Buy", "inputs": [{ "name": "buyer", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokenHolder", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokenCollateral", "type": "address", "indexed": true, "internalType": "address" }, { "name": "loanId", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "openingPositionSize", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "collateralAmount", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "initialMargin", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "Initialized", "inputs": [{ "name": "version", "type": "uint64", "indexed": false, "internalType": "uint64" }], "anonymous": false }, { "type": "event", "name": "Liquidation", "inputs": [{ "name": "borrower", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokenHolder", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokenCollateral", "type": "address", "indexed": true, "internalType": "address" }, { "name": "loanId", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "closingPositionSize", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "liquidatorRepaidAmount", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "event", "name": "Sell", "inputs": [{ "name": "buyer", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokenHolder", "type": "address", "indexed": true, "internalType": "address" }, { "name": "tokenCollateral", "type": "address", "indexed": true, "internalType": "address" }, { "name": "loanId", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "closingPositionSize", "type": "uint256", "indexed": false, "internalType": "uint256" }, { "name": "profit", "type": "uint256", "indexed": false, "internalType": "uint256" }], "anonymous": false }, { "type": "error", "name": "InvalidInitialization", "inputs": [] }, { "type": "error", "name": "NotInitializing", "inputs": [] }, { "type": "error", "name": "ReentrancyGuardReentrantCall", "inputs": [] }];
|
|
2752
|
+
|
|
2753
|
+
// abi/tokenHolderAbi.ts
|
|
2754
|
+
var tokenHolderAbi = [
|
|
2755
|
+
{ inputs: [], name: "AccessControlBadConfirmation", type: "error" },
|
|
2756
|
+
{
|
|
2757
|
+
inputs: [
|
|
2758
|
+
{ internalType: "address", name: "account", type: "address" },
|
|
2759
|
+
{ internalType: "bytes32", name: "neededRole", type: "bytes32" }
|
|
2760
|
+
],
|
|
2761
|
+
name: "AccessControlUnauthorizedAccount",
|
|
2762
|
+
type: "error"
|
|
2763
|
+
},
|
|
2764
|
+
{ inputs: [], name: "InvalidInitialization", type: "error" },
|
|
2765
|
+
{ inputs: [], name: "NotInitializing", type: "error" },
|
|
2766
|
+
{
|
|
2767
|
+
anonymous: false,
|
|
2768
|
+
inputs: [
|
|
2769
|
+
{
|
|
2770
|
+
indexed: false,
|
|
2771
|
+
internalType: "uint64",
|
|
2772
|
+
name: "version",
|
|
2773
|
+
type: "uint64"
|
|
2774
|
+
}
|
|
2775
|
+
],
|
|
2776
|
+
name: "Initialized",
|
|
2777
|
+
type: "event"
|
|
2778
|
+
},
|
|
2779
|
+
{
|
|
2780
|
+
anonymous: false,
|
|
2781
|
+
inputs: [
|
|
2782
|
+
{
|
|
2783
|
+
indexed: false,
|
|
2784
|
+
internalType: "uint256",
|
|
2785
|
+
name: "newInterestRate",
|
|
2786
|
+
type: "uint256"
|
|
2787
|
+
}
|
|
2788
|
+
],
|
|
2789
|
+
name: "InterestRateSet",
|
|
2790
|
+
type: "event"
|
|
2791
|
+
},
|
|
2792
|
+
{
|
|
2793
|
+
anonymous: false,
|
|
2794
|
+
inputs: [
|
|
2795
|
+
{
|
|
2796
|
+
indexed: false,
|
|
2797
|
+
internalType: "uint256",
|
|
2798
|
+
name: "loanId",
|
|
2799
|
+
type: "uint256"
|
|
2800
|
+
},
|
|
2801
|
+
{
|
|
2802
|
+
indexed: false,
|
|
2803
|
+
internalType: "uint256",
|
|
2804
|
+
name: "amount",
|
|
2805
|
+
type: "uint256"
|
|
2806
|
+
},
|
|
2807
|
+
{
|
|
2808
|
+
indexed: false,
|
|
2809
|
+
internalType: "uint256",
|
|
2810
|
+
name: "timestamp",
|
|
2811
|
+
type: "uint256"
|
|
2812
|
+
},
|
|
2813
|
+
{ indexed: false, internalType: "bool", name: "repaid", type: "bool" }
|
|
2814
|
+
],
|
|
2815
|
+
name: "LoanCreated",
|
|
2816
|
+
type: "event"
|
|
2817
|
+
},
|
|
2818
|
+
{
|
|
2819
|
+
anonymous: false,
|
|
2820
|
+
inputs: [
|
|
2821
|
+
{
|
|
2822
|
+
indexed: false,
|
|
2823
|
+
internalType: "uint256",
|
|
2824
|
+
name: "loanId",
|
|
2825
|
+
type: "uint256"
|
|
2826
|
+
}
|
|
2827
|
+
],
|
|
2828
|
+
name: "LoanRepaid",
|
|
2829
|
+
type: "event"
|
|
2830
|
+
},
|
|
2831
|
+
{
|
|
2832
|
+
anonymous: false,
|
|
2833
|
+
inputs: [
|
|
2834
|
+
{
|
|
2835
|
+
indexed: false,
|
|
2836
|
+
internalType: "address",
|
|
2837
|
+
name: "collateralAddress",
|
|
2838
|
+
type: "address"
|
|
2839
|
+
},
|
|
2840
|
+
{
|
|
2841
|
+
indexed: false,
|
|
2842
|
+
internalType: "uint256",
|
|
2843
|
+
name: "oldValue",
|
|
2844
|
+
type: "uint256"
|
|
2845
|
+
},
|
|
2846
|
+
{
|
|
2847
|
+
indexed: false,
|
|
2848
|
+
internalType: "uint256",
|
|
2849
|
+
name: "newValue",
|
|
2850
|
+
type: "uint256"
|
|
2851
|
+
}
|
|
2852
|
+
],
|
|
2853
|
+
name: "MaxLendPerTokenUpdated",
|
|
2854
|
+
type: "event"
|
|
2855
|
+
},
|
|
2856
|
+
{
|
|
2857
|
+
anonymous: false,
|
|
2858
|
+
inputs: [
|
|
2859
|
+
{
|
|
2860
|
+
indexed: false,
|
|
2861
|
+
internalType: "address",
|
|
2862
|
+
name: "borrower",
|
|
2863
|
+
type: "address"
|
|
2864
|
+
},
|
|
2865
|
+
{
|
|
2866
|
+
indexed: false,
|
|
2867
|
+
internalType: "uint256",
|
|
2868
|
+
name: "amount",
|
|
2869
|
+
type: "uint256"
|
|
2870
|
+
}
|
|
2871
|
+
],
|
|
2872
|
+
name: "PrivilegedLoan",
|
|
2873
|
+
type: "event"
|
|
2874
|
+
},
|
|
2875
|
+
{
|
|
2876
|
+
anonymous: false,
|
|
2877
|
+
inputs: [
|
|
2878
|
+
{
|
|
2879
|
+
indexed: false,
|
|
2880
|
+
internalType: "address",
|
|
2881
|
+
name: "borrower",
|
|
2882
|
+
type: "address"
|
|
2883
|
+
},
|
|
2884
|
+
{
|
|
2885
|
+
indexed: false,
|
|
2886
|
+
internalType: "uint256",
|
|
2887
|
+
name: "amount",
|
|
2888
|
+
type: "uint256"
|
|
2889
|
+
}
|
|
2890
|
+
],
|
|
2891
|
+
name: "PrivilegedLoanRepaid",
|
|
2892
|
+
type: "event"
|
|
2893
|
+
},
|
|
2894
|
+
{
|
|
2895
|
+
anonymous: false,
|
|
2896
|
+
inputs: [
|
|
2897
|
+
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
2898
|
+
{
|
|
2899
|
+
indexed: true,
|
|
2900
|
+
internalType: "bytes32",
|
|
2901
|
+
name: "previousAdminRole",
|
|
2902
|
+
type: "bytes32"
|
|
2903
|
+
},
|
|
2904
|
+
{
|
|
2905
|
+
indexed: true,
|
|
2906
|
+
internalType: "bytes32",
|
|
2907
|
+
name: "newAdminRole",
|
|
2908
|
+
type: "bytes32"
|
|
2909
|
+
}
|
|
2910
|
+
],
|
|
2911
|
+
name: "RoleAdminChanged",
|
|
2912
|
+
type: "event"
|
|
2913
|
+
},
|
|
2914
|
+
{
|
|
2915
|
+
anonymous: false,
|
|
2916
|
+
inputs: [
|
|
2917
|
+
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
2918
|
+
{
|
|
2919
|
+
indexed: true,
|
|
2920
|
+
internalType: "address",
|
|
2921
|
+
name: "account",
|
|
2922
|
+
type: "address"
|
|
2923
|
+
},
|
|
2924
|
+
{
|
|
2925
|
+
indexed: true,
|
|
2926
|
+
internalType: "address",
|
|
2927
|
+
name: "sender",
|
|
2928
|
+
type: "address"
|
|
2929
|
+
}
|
|
2930
|
+
],
|
|
2931
|
+
name: "RoleGranted",
|
|
2932
|
+
type: "event"
|
|
2933
|
+
},
|
|
2934
|
+
{
|
|
2935
|
+
anonymous: false,
|
|
2936
|
+
inputs: [
|
|
2937
|
+
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
2938
|
+
{
|
|
2939
|
+
indexed: true,
|
|
2940
|
+
internalType: "address",
|
|
2941
|
+
name: "account",
|
|
2942
|
+
type: "address"
|
|
2943
|
+
},
|
|
2944
|
+
{
|
|
2945
|
+
indexed: true,
|
|
2946
|
+
internalType: "address",
|
|
2947
|
+
name: "sender",
|
|
2948
|
+
type: "address"
|
|
2949
|
+
}
|
|
2950
|
+
],
|
|
2951
|
+
name: "RoleRevoked",
|
|
2952
|
+
type: "event"
|
|
2953
|
+
},
|
|
2954
|
+
{
|
|
2955
|
+
inputs: [],
|
|
2956
|
+
name: "BORROWER_ROUTER_ROLE",
|
|
2957
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
2958
|
+
stateMutability: "view",
|
|
2959
|
+
type: "function"
|
|
2960
|
+
},
|
|
2961
|
+
{
|
|
2962
|
+
inputs: [],
|
|
2963
|
+
name: "DEFAULT_ADMIN_ROLE",
|
|
2964
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
2965
|
+
stateMutability: "view",
|
|
2966
|
+
type: "function"
|
|
2967
|
+
},
|
|
2968
|
+
{
|
|
2969
|
+
inputs: [
|
|
2970
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
2971
|
+
{ internalType: "uint256", name: "_interestRate", type: "uint256" },
|
|
2972
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
2973
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" }
|
|
2974
|
+
],
|
|
2975
|
+
name: "addCollateral",
|
|
2976
|
+
outputs: [],
|
|
2977
|
+
stateMutability: "nonpayable",
|
|
2978
|
+
type: "function"
|
|
2979
|
+
},
|
|
2980
|
+
{
|
|
2981
|
+
inputs: [{ internalType: "address", name: "", type: "address" }],
|
|
2982
|
+
name: "collateralMapping",
|
|
2983
|
+
outputs: [
|
|
2984
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
2985
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
2986
|
+
{ internalType: "uint256", name: "interestRate", type: "uint256" },
|
|
2987
|
+
{ internalType: "bool", name: "active", type: "bool" },
|
|
2988
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
2989
|
+
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
2990
|
+
{ internalType: "uint256", name: "currentExposure", type: "uint256" }
|
|
2991
|
+
],
|
|
2992
|
+
stateMutability: "view",
|
|
2993
|
+
type: "function"
|
|
2994
|
+
},
|
|
2995
|
+
{
|
|
2996
|
+
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
|
|
2997
|
+
name: "deposit",
|
|
2998
|
+
outputs: [],
|
|
2999
|
+
stateMutability: "nonpayable",
|
|
3000
|
+
type: "function"
|
|
3001
|
+
},
|
|
3002
|
+
{
|
|
3003
|
+
inputs: [],
|
|
3004
|
+
name: "getBalance",
|
|
3005
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3006
|
+
stateMutability: "view",
|
|
3007
|
+
type: "function"
|
|
3008
|
+
},
|
|
3009
|
+
{
|
|
3010
|
+
inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
|
|
3011
|
+
name: "getRoleAdmin",
|
|
3012
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
3013
|
+
stateMutability: "view",
|
|
3014
|
+
type: "function"
|
|
3015
|
+
},
|
|
3016
|
+
{
|
|
3017
|
+
inputs: [{ internalType: "address", name: "account", type: "address" }],
|
|
3018
|
+
name: "grantBorrowerRouterRole",
|
|
3019
|
+
outputs: [],
|
|
3020
|
+
stateMutability: "nonpayable",
|
|
3021
|
+
type: "function"
|
|
3022
|
+
},
|
|
3023
|
+
{
|
|
3024
|
+
inputs: [
|
|
3025
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3026
|
+
{ internalType: "address", name: "account", type: "address" }
|
|
3027
|
+
],
|
|
3028
|
+
name: "grantRole",
|
|
3029
|
+
outputs: [],
|
|
3030
|
+
stateMutability: "nonpayable",
|
|
3031
|
+
type: "function"
|
|
3032
|
+
},
|
|
3033
|
+
{
|
|
3034
|
+
inputs: [
|
|
3035
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3036
|
+
{ internalType: "address", name: "account", type: "address" }
|
|
3037
|
+
],
|
|
3038
|
+
name: "hasRole",
|
|
3039
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
3040
|
+
stateMutability: "view",
|
|
3041
|
+
type: "function"
|
|
3042
|
+
},
|
|
3043
|
+
{
|
|
3044
|
+
inputs: [
|
|
3045
|
+
{ internalType: "address", name: "_tokenAddress", type: "address" }
|
|
3046
|
+
],
|
|
3047
|
+
name: "initialize",
|
|
3048
|
+
outputs: [],
|
|
3049
|
+
stateMutability: "nonpayable",
|
|
3050
|
+
type: "function"
|
|
3051
|
+
},
|
|
3052
|
+
{
|
|
3053
|
+
inputs: [
|
|
3054
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
3055
|
+
{ internalType: "uint256", name: "collateralAmount", type: "uint256" },
|
|
3056
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
3057
|
+
{ internalType: "address", name: "borrower", type: "address" },
|
|
3058
|
+
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
3059
|
+
],
|
|
3060
|
+
name: "loanConfirmation",
|
|
3061
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3062
|
+
stateMutability: "nonpayable",
|
|
3063
|
+
type: "function"
|
|
3064
|
+
},
|
|
3065
|
+
{
|
|
3066
|
+
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3067
|
+
name: "loans",
|
|
3068
|
+
outputs: [
|
|
3069
|
+
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
3070
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
3071
|
+
{
|
|
3072
|
+
components: [
|
|
3982
3073
|
{
|
|
3983
|
-
|
|
3984
|
-
|
|
3074
|
+
internalType: "address",
|
|
3075
|
+
name: "collateralAddress",
|
|
3076
|
+
type: "address"
|
|
3985
3077
|
},
|
|
3986
|
-
{
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
}
|
|
3990
|
-
|
|
3078
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
3079
|
+
{ internalType: "uint256", name: "interestRate", type: "uint256" },
|
|
3080
|
+
{ internalType: "bool", name: "active", type: "bool" },
|
|
3081
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
3082
|
+
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
3083
|
+
{ internalType: "uint256", name: "currentExposure", type: "uint256" }
|
|
3084
|
+
],
|
|
3085
|
+
internalType: "struct Collateral",
|
|
3086
|
+
name: "collateral",
|
|
3087
|
+
type: "tuple"
|
|
3088
|
+
},
|
|
3089
|
+
{ internalType: "uint256", name: "collateralAmount", type: "uint256" },
|
|
3090
|
+
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
3091
|
+
{ internalType: "address", name: "borrower", type: "address" },
|
|
3092
|
+
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
3093
|
+
],
|
|
3094
|
+
stateMutability: "view",
|
|
3095
|
+
type: "function"
|
|
3096
|
+
},
|
|
3097
|
+
{
|
|
3098
|
+
inputs: [],
|
|
3099
|
+
name: "nextLoanId",
|
|
3100
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3101
|
+
stateMutability: "view",
|
|
3102
|
+
type: "function"
|
|
3103
|
+
},
|
|
3104
|
+
{
|
|
3105
|
+
inputs: [
|
|
3106
|
+
{
|
|
3107
|
+
internalType: "contract IERC20",
|
|
3108
|
+
name: "flashLoanToken",
|
|
3109
|
+
type: "address"
|
|
3110
|
+
},
|
|
3111
|
+
{ internalType: "uint256", name: "amount", type: "uint256" }
|
|
3112
|
+
],
|
|
3113
|
+
name: "privilegedLoan",
|
|
3114
|
+
outputs: [],
|
|
3115
|
+
stateMutability: "nonpayable",
|
|
3116
|
+
type: "function"
|
|
3117
|
+
},
|
|
3118
|
+
{
|
|
3119
|
+
inputs: [
|
|
3120
|
+
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
3121
|
+
],
|
|
3122
|
+
name: "removeCollateral",
|
|
3123
|
+
outputs: [],
|
|
3124
|
+
stateMutability: "nonpayable",
|
|
3125
|
+
type: "function"
|
|
3126
|
+
},
|
|
3127
|
+
{
|
|
3128
|
+
inputs: [
|
|
3129
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3130
|
+
{ internalType: "address", name: "callerConfirmation", type: "address" }
|
|
3131
|
+
],
|
|
3132
|
+
name: "renounceRole",
|
|
3133
|
+
outputs: [],
|
|
3134
|
+
stateMutability: "nonpayable",
|
|
3135
|
+
type: "function"
|
|
3136
|
+
},
|
|
3137
|
+
{
|
|
3138
|
+
inputs: [{ internalType: "uint256", name: "loanId", type: "uint256" }],
|
|
3139
|
+
name: "repayLoan",
|
|
3140
|
+
outputs: [],
|
|
3141
|
+
stateMutability: "nonpayable",
|
|
3142
|
+
type: "function"
|
|
3143
|
+
},
|
|
3144
|
+
{
|
|
3145
|
+
inputs: [{ internalType: "address", name: "account", type: "address" }],
|
|
3146
|
+
name: "revokeBorrowerRouterRole",
|
|
3147
|
+
outputs: [],
|
|
3148
|
+
stateMutability: "nonpayable",
|
|
3149
|
+
type: "function"
|
|
3150
|
+
},
|
|
3151
|
+
{
|
|
3152
|
+
inputs: [
|
|
3153
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3154
|
+
{ internalType: "address", name: "account", type: "address" }
|
|
3155
|
+
],
|
|
3156
|
+
name: "revokeRole",
|
|
3157
|
+
outputs: [],
|
|
3158
|
+
stateMutability: "nonpayable",
|
|
3159
|
+
type: "function"
|
|
3160
|
+
},
|
|
3161
|
+
{
|
|
3162
|
+
inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
|
|
3163
|
+
name: "supportsInterface",
|
|
3164
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
3165
|
+
stateMutability: "view",
|
|
3166
|
+
type: "function"
|
|
3167
|
+
},
|
|
3168
|
+
{
|
|
3169
|
+
inputs: [],
|
|
3170
|
+
name: "tokenHolded",
|
|
3171
|
+
outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
|
|
3172
|
+
stateMutability: "view",
|
|
3173
|
+
type: "function"
|
|
3174
|
+
},
|
|
3175
|
+
{
|
|
3176
|
+
inputs: [
|
|
3177
|
+
{
|
|
3178
|
+
internalType: "address[]",
|
|
3179
|
+
name: "collateralAddresses",
|
|
3180
|
+
type: "address[]"
|
|
3181
|
+
},
|
|
3182
|
+
{
|
|
3183
|
+
internalType: "uint256[]",
|
|
3184
|
+
name: "newMaxLendPerTokens",
|
|
3185
|
+
type: "uint256[]"
|
|
3991
3186
|
}
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
3187
|
+
],
|
|
3188
|
+
name: "updateMaxLendPerTokenBulk",
|
|
3189
|
+
outputs: [],
|
|
3190
|
+
stateMutability: "nonpayable",
|
|
3191
|
+
type: "function"
|
|
3192
|
+
},
|
|
3193
|
+
{
|
|
3194
|
+
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
|
|
3195
|
+
name: "withdraw",
|
|
3196
|
+
outputs: [],
|
|
3197
|
+
stateMutability: "nonpayable",
|
|
3198
|
+
type: "function"
|
|
3199
|
+
},
|
|
3200
|
+
{
|
|
3201
|
+
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3202
|
+
name: "activeLoanIds",
|
|
3203
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3204
|
+
stateMutability: "view",
|
|
3205
|
+
type: "function"
|
|
3206
|
+
},
|
|
3207
|
+
{
|
|
3208
|
+
inputs: [],
|
|
3209
|
+
name: "getActiveLoanCount",
|
|
3210
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3211
|
+
stateMutability: "view",
|
|
3212
|
+
type: "function"
|
|
3213
|
+
},
|
|
3214
|
+
{
|
|
3215
|
+
inputs: [
|
|
3216
|
+
{ internalType: "uint256", name: "startIndex", type: "uint256" },
|
|
3217
|
+
{ internalType: "uint256", name: "batchSize", type: "uint256" }
|
|
3218
|
+
],
|
|
3219
|
+
name: "getActiveLoansBatch",
|
|
3220
|
+
outputs: [
|
|
3221
|
+
{
|
|
3222
|
+
components: [
|
|
3223
|
+
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
3224
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
4018
3225
|
{
|
|
4019
|
-
|
|
3226
|
+
components: [
|
|
3227
|
+
{
|
|
3228
|
+
internalType: "address",
|
|
3229
|
+
name: "collateralAddress",
|
|
3230
|
+
type: "address"
|
|
3231
|
+
},
|
|
3232
|
+
{
|
|
3233
|
+
internalType: "uint256",
|
|
3234
|
+
name: "maxLendPerToken",
|
|
3235
|
+
type: "uint256"
|
|
3236
|
+
},
|
|
3237
|
+
{
|
|
3238
|
+
internalType: "uint256",
|
|
3239
|
+
name: "interestRate",
|
|
3240
|
+
type: "uint256"
|
|
3241
|
+
},
|
|
3242
|
+
{ internalType: "bool", name: "active", type: "bool" },
|
|
3243
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
3244
|
+
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
3245
|
+
{
|
|
3246
|
+
internalType: "uint256",
|
|
3247
|
+
name: "currentExposure",
|
|
3248
|
+
type: "uint256"
|
|
3249
|
+
}
|
|
3250
|
+
],
|
|
3251
|
+
internalType: "struct Collateral",
|
|
3252
|
+
name: "collateral",
|
|
3253
|
+
type: "tuple"
|
|
4020
3254
|
},
|
|
4021
3255
|
{
|
|
4022
|
-
|
|
3256
|
+
internalType: "uint256",
|
|
3257
|
+
name: "collateralAmount",
|
|
3258
|
+
type: "uint256"
|
|
4023
3259
|
},
|
|
4024
|
-
{
|
|
4025
|
-
|
|
4026
|
-
}
|
|
4027
|
-
]
|
|
3260
|
+
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
3261
|
+
{ internalType: "address", name: "borrower", type: "address" },
|
|
3262
|
+
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
3263
|
+
],
|
|
3264
|
+
internalType: "struct Loan[]",
|
|
3265
|
+
name: "",
|
|
3266
|
+
type: "tuple[]"
|
|
4028
3267
|
}
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
3268
|
+
],
|
|
3269
|
+
stateMutability: "view",
|
|
3270
|
+
type: "function"
|
|
3271
|
+
},
|
|
3272
|
+
{
|
|
3273
|
+
inputs: [{ internalType: "address", name: "borrower", type: "address" }],
|
|
3274
|
+
name: "getLoansByBorrower",
|
|
3275
|
+
outputs: [
|
|
3276
|
+
{
|
|
3277
|
+
components: [
|
|
3278
|
+
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
3279
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
4035
3280
|
{
|
|
4036
|
-
|
|
3281
|
+
components: [
|
|
3282
|
+
{
|
|
3283
|
+
internalType: "address",
|
|
3284
|
+
name: "collateralAddress",
|
|
3285
|
+
type: "address"
|
|
3286
|
+
},
|
|
3287
|
+
{
|
|
3288
|
+
internalType: "uint256",
|
|
3289
|
+
name: "maxLendPerToken",
|
|
3290
|
+
type: "uint256"
|
|
3291
|
+
},
|
|
3292
|
+
{
|
|
3293
|
+
internalType: "uint256",
|
|
3294
|
+
name: "interestRate",
|
|
3295
|
+
type: "uint256"
|
|
3296
|
+
},
|
|
3297
|
+
{ internalType: "bool", name: "active", type: "bool" },
|
|
3298
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
3299
|
+
{ internalType: "uint256", name: "maxExposure", type: "uint256" },
|
|
3300
|
+
{
|
|
3301
|
+
internalType: "uint256",
|
|
3302
|
+
name: "currentExposure",
|
|
3303
|
+
type: "uint256"
|
|
3304
|
+
}
|
|
3305
|
+
],
|
|
3306
|
+
internalType: "struct Collateral",
|
|
3307
|
+
name: "collateral",
|
|
3308
|
+
type: "tuple"
|
|
4037
3309
|
},
|
|
4038
3310
|
{
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
}
|
|
4043
|
-
},
|
|
4044
|
-
{
|
|
4045
|
-
"name": "ErrorCode",
|
|
4046
|
-
"type": {
|
|
4047
|
-
"kind": "enum",
|
|
4048
|
-
"variants": [
|
|
4049
|
-
{
|
|
4050
|
-
"name": "InvalidSplitRatio"
|
|
3311
|
+
internalType: "uint256",
|
|
3312
|
+
name: "collateralAmount",
|
|
3313
|
+
type: "uint256"
|
|
4051
3314
|
},
|
|
4052
|
-
{
|
|
4053
|
-
|
|
4054
|
-
}
|
|
4055
|
-
]
|
|
3315
|
+
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
3316
|
+
{ internalType: "address", name: "borrower", type: "address" },
|
|
3317
|
+
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
3318
|
+
],
|
|
3319
|
+
internalType: "struct Loan[]",
|
|
3320
|
+
name: "",
|
|
3321
|
+
type: "tuple[]"
|
|
3322
|
+
}
|
|
3323
|
+
],
|
|
3324
|
+
stateMutability: "view",
|
|
3325
|
+
type: "function"
|
|
3326
|
+
},
|
|
3327
|
+
{
|
|
3328
|
+
inputs: [
|
|
3329
|
+
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
3330
|
+
],
|
|
3331
|
+
name: "getCollateralExposure",
|
|
3332
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3333
|
+
stateMutability: "view",
|
|
3334
|
+
type: "function"
|
|
3335
|
+
},
|
|
3336
|
+
{
|
|
3337
|
+
inputs: [
|
|
3338
|
+
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
3339
|
+
],
|
|
3340
|
+
name: "getAvailableExposure",
|
|
3341
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3342
|
+
stateMutability: "view",
|
|
3343
|
+
type: "function"
|
|
3344
|
+
},
|
|
3345
|
+
{
|
|
3346
|
+
inputs: [
|
|
3347
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
3348
|
+
{ internalType: "uint256", name: "_interestRate", type: "uint256" },
|
|
3349
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
3350
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" },
|
|
3351
|
+
{ internalType: "uint256", name: "maxExposure", type: "uint256" }
|
|
3352
|
+
],
|
|
3353
|
+
name: "addCollateral",
|
|
3354
|
+
outputs: [],
|
|
3355
|
+
stateMutability: "nonpayable",
|
|
3356
|
+
type: "function"
|
|
3357
|
+
},
|
|
3358
|
+
{
|
|
3359
|
+
inputs: [
|
|
3360
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
3361
|
+
{ internalType: "uint256", name: "newMaxExposure", type: "uint256" }
|
|
3362
|
+
],
|
|
3363
|
+
name: "updateMaxExposure",
|
|
3364
|
+
outputs: [],
|
|
3365
|
+
stateMutability: "nonpayable",
|
|
3366
|
+
type: "function"
|
|
3367
|
+
},
|
|
3368
|
+
{
|
|
3369
|
+
anonymous: false,
|
|
3370
|
+
inputs: [
|
|
3371
|
+
{
|
|
3372
|
+
indexed: false,
|
|
3373
|
+
internalType: "address",
|
|
3374
|
+
name: "collateralAddress",
|
|
3375
|
+
type: "address"
|
|
3376
|
+
},
|
|
3377
|
+
{
|
|
3378
|
+
indexed: false,
|
|
3379
|
+
internalType: "uint256",
|
|
3380
|
+
name: "currentExposure",
|
|
3381
|
+
type: "uint256"
|
|
4056
3382
|
}
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
3383
|
+
],
|
|
3384
|
+
name: "ExposureUpdated",
|
|
3385
|
+
type: "event"
|
|
3386
|
+
},
|
|
3387
|
+
{
|
|
3388
|
+
anonymous: false,
|
|
3389
|
+
inputs: [
|
|
3390
|
+
{
|
|
3391
|
+
indexed: false,
|
|
3392
|
+
internalType: "address",
|
|
3393
|
+
name: "collateralAddress",
|
|
3394
|
+
type: "address"
|
|
3395
|
+
},
|
|
3396
|
+
{
|
|
3397
|
+
indexed: false,
|
|
3398
|
+
internalType: "uint256",
|
|
3399
|
+
name: "oldMaxExposure",
|
|
3400
|
+
type: "uint256"
|
|
3401
|
+
},
|
|
3402
|
+
{
|
|
3403
|
+
indexed: false,
|
|
3404
|
+
internalType: "uint256",
|
|
3405
|
+
name: "newMaxExposure",
|
|
3406
|
+
type: "uint256"
|
|
4073
3407
|
}
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
3408
|
+
],
|
|
3409
|
+
name: "MaxExposureUpdated",
|
|
3410
|
+
type: "event"
|
|
3411
|
+
}
|
|
3412
|
+
];
|
|
3413
|
+
|
|
3414
|
+
// evm.ts
|
|
3415
|
+
var openPositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
|
|
3416
|
+
buyingCode,
|
|
3417
|
+
tokenCollateral,
|
|
3418
|
+
borrowAmount,
|
|
3419
|
+
tokenHolder,
|
|
3420
|
+
inchRouter,
|
|
3421
|
+
integratorFeeAddress = import_ethers.ZeroAddress,
|
|
3422
|
+
buyerContribution,
|
|
3423
|
+
gasLimit,
|
|
3424
|
+
gasPrice
|
|
3425
|
+
}) {
|
|
3426
|
+
const contract = new import_ethers.Contract(
|
|
3427
|
+
borrowerOpsContractAddress,
|
|
3428
|
+
borrowerOperationsAbi,
|
|
3429
|
+
provider
|
|
3430
|
+
);
|
|
3431
|
+
const txOptions = {
|
|
3432
|
+
value: buyerContribution
|
|
3433
|
+
};
|
|
3434
|
+
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
3435
|
+
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
3436
|
+
return contract.buy.populateTransaction(
|
|
3437
|
+
buyingCode,
|
|
3438
|
+
tokenCollateral,
|
|
3439
|
+
borrowAmount,
|
|
3440
|
+
tokenHolder,
|
|
3441
|
+
inchRouter,
|
|
3442
|
+
integratorFeeAddress,
|
|
3443
|
+
txOptions
|
|
3444
|
+
);
|
|
3445
|
+
});
|
|
3446
|
+
var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
|
|
3447
|
+
loanId,
|
|
3448
|
+
sellingCode,
|
|
3449
|
+
tokenHolder,
|
|
3450
|
+
inchRouter,
|
|
3451
|
+
integratorFeeAddress = import_ethers.ZeroAddress,
|
|
3452
|
+
gasLimit,
|
|
3453
|
+
gasPrice
|
|
3454
|
+
}) {
|
|
3455
|
+
const contract = new import_ethers.Contract(
|
|
3456
|
+
borrowerOpsContractAddress,
|
|
3457
|
+
borrowerOperationsAbi,
|
|
3458
|
+
provider
|
|
3459
|
+
);
|
|
3460
|
+
const txOptions = {};
|
|
3461
|
+
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
3462
|
+
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
3463
|
+
return contract.sell.populateTransaction(
|
|
3464
|
+
loanId,
|
|
3465
|
+
sellingCode,
|
|
3466
|
+
tokenHolder,
|
|
3467
|
+
inchRouter,
|
|
3468
|
+
integratorFeeAddress,
|
|
3469
|
+
Object.keys(txOptions).length > 0 ? txOptions : {}
|
|
3470
|
+
);
|
|
3471
|
+
});
|
|
3472
|
+
function getPositionsEvm(provider, tokenHolderContractAddress) {
|
|
3473
|
+
return __async(this, null, function* () {
|
|
3474
|
+
const contract = new import_ethers.Contract(
|
|
3475
|
+
tokenHolderContractAddress,
|
|
3476
|
+
tokenHolderAbi,
|
|
3477
|
+
provider
|
|
3478
|
+
);
|
|
3479
|
+
const activeLoanCount = yield contract.getActiveLoanCount();
|
|
3480
|
+
const batchSize = 100;
|
|
3481
|
+
const positions = [];
|
|
3482
|
+
for (let i = 0; i < activeLoanCount; i += batchSize) {
|
|
3483
|
+
const currentBatchSize = Math.min(Number(activeLoanCount) - i, batchSize);
|
|
3484
|
+
const loans = yield contract.getActiveLoansBatch(i, currentBatchSize);
|
|
3485
|
+
for (const loan of loans) {
|
|
3486
|
+
positions.push({
|
|
3487
|
+
trader: loan.borrower,
|
|
3488
|
+
tokenCollateral: loan.collateral.collateralAddress,
|
|
3489
|
+
loanId: loan.id,
|
|
3490
|
+
openingPositionSize: loan.amount + loan.userPaid,
|
|
3491
|
+
collateralAmount: loan.collateralAmount,
|
|
3492
|
+
initialMargin: loan.userPaid,
|
|
3493
|
+
transactionHash: "",
|
|
3494
|
+
// Not available from loan data
|
|
3495
|
+
timestamp: Number(loan.timestamp)
|
|
3496
|
+
});
|
|
4087
3497
|
}
|
|
4088
3498
|
}
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
"type": "u64",
|
|
4107
|
-
"index": false
|
|
4108
|
-
},
|
|
4109
|
-
{
|
|
4110
|
-
"name": "collateralAmount",
|
|
4111
|
-
"type": "u64",
|
|
4112
|
-
"index": false
|
|
4113
|
-
},
|
|
4114
|
-
{
|
|
4115
|
-
"name": "openTimestamp",
|
|
4116
|
-
"type": "i64",
|
|
4117
|
-
"index": false
|
|
4118
|
-
},
|
|
4119
|
-
{
|
|
4120
|
-
"name": "trader",
|
|
4121
|
-
"type": "publicKey",
|
|
4122
|
-
"index": false
|
|
4123
|
-
},
|
|
4124
|
-
{
|
|
4125
|
-
"name": "closeType",
|
|
4126
|
-
"type": "u8",
|
|
4127
|
-
"index": false
|
|
4128
|
-
},
|
|
4129
|
-
{
|
|
4130
|
-
"name": "closeTimestamp",
|
|
4131
|
-
"type": "i64",
|
|
4132
|
-
"index": false
|
|
4133
|
-
},
|
|
4134
|
-
{
|
|
4135
|
-
"name": "closingPositionSize",
|
|
4136
|
-
"type": "u64",
|
|
4137
|
-
"index": false
|
|
4138
|
-
}
|
|
4139
|
-
]
|
|
4140
|
-
},
|
|
4141
|
-
{
|
|
4142
|
-
"name": "PositionOpenEvent",
|
|
4143
|
-
"fields": [
|
|
4144
|
-
{
|
|
4145
|
-
"name": "pool",
|
|
4146
|
-
"type": "publicKey",
|
|
4147
|
-
"index": false
|
|
4148
|
-
},
|
|
4149
|
-
{
|
|
4150
|
-
"name": "amount",
|
|
4151
|
-
"type": "u64",
|
|
4152
|
-
"index": false
|
|
4153
|
-
},
|
|
4154
|
-
{
|
|
4155
|
-
"name": "userPaid",
|
|
4156
|
-
"type": "u64",
|
|
4157
|
-
"index": false
|
|
4158
|
-
},
|
|
4159
|
-
{
|
|
4160
|
-
"name": "collateralAmount",
|
|
4161
|
-
"type": "u64",
|
|
4162
|
-
"index": false
|
|
4163
|
-
},
|
|
4164
|
-
{
|
|
4165
|
-
"name": "openTimestamp",
|
|
4166
|
-
"type": "i64",
|
|
4167
|
-
"index": false
|
|
4168
|
-
},
|
|
4169
|
-
{
|
|
4170
|
-
"name": "trader",
|
|
4171
|
-
"type": "publicKey",
|
|
4172
|
-
"index": false
|
|
4173
|
-
}
|
|
4174
|
-
]
|
|
3499
|
+
return positions;
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
|
|
3503
|
+
return __async(this, null, function* () {
|
|
3504
|
+
const contract = new import_ethers.Contract(
|
|
3505
|
+
borrowerOpsContractAddress,
|
|
3506
|
+
borrowerOperationsAbi,
|
|
3507
|
+
provider
|
|
3508
|
+
);
|
|
3509
|
+
const currentBlock = yield provider.getBlockNumber();
|
|
3510
|
+
const filter = contract.filters.Sell();
|
|
3511
|
+
const allEvents = [];
|
|
3512
|
+
for (let start = fromBlock; start <= currentBlock; start += 1e4) {
|
|
3513
|
+
const end = Math.min(start + 9999, currentBlock);
|
|
3514
|
+
const events = yield contract.queryFilter(filter, start, end);
|
|
3515
|
+
allEvents.push(...events);
|
|
4175
3516
|
}
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
{
|
|
4209
|
-
"code": 6006,
|
|
4210
|
-
"name": "UnknownInstruction",
|
|
4211
|
-
"msg": "Unknown Instruction"
|
|
4212
|
-
},
|
|
4213
|
-
{
|
|
4214
|
-
"code": 6007,
|
|
4215
|
-
"name": "ExpectedCollateralNotEnough",
|
|
4216
|
-
"msg": "Expected collateral not enough"
|
|
4217
|
-
},
|
|
4218
|
-
{
|
|
4219
|
-
"code": 6008,
|
|
4220
|
-
"name": "ForTesting",
|
|
4221
|
-
"msg": "TestError"
|
|
3517
|
+
return Promise.all(
|
|
3518
|
+
allEvents.map((event) => __async(this, null, function* () {
|
|
3519
|
+
const { buyer, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
|
|
3520
|
+
const block = yield provider.getBlock(event.blockNumber);
|
|
3521
|
+
const timestamp = block ? Number(block.timestamp) : 0;
|
|
3522
|
+
return {
|
|
3523
|
+
trader: buyer,
|
|
3524
|
+
tokenCollateral,
|
|
3525
|
+
loanId,
|
|
3526
|
+
closingPositionSize,
|
|
3527
|
+
profit,
|
|
3528
|
+
transactionHash: event.transactionHash,
|
|
3529
|
+
timestamp
|
|
3530
|
+
};
|
|
3531
|
+
}))
|
|
3532
|
+
);
|
|
3533
|
+
});
|
|
3534
|
+
}
|
|
3535
|
+
function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
|
|
3536
|
+
return __async(this, null, function* () {
|
|
3537
|
+
const contract = new import_ethers.Contract(
|
|
3538
|
+
borrowerOpsContractAddress,
|
|
3539
|
+
borrowerOperationsAbi,
|
|
3540
|
+
provider
|
|
3541
|
+
);
|
|
3542
|
+
const currentBlock = yield provider.getBlockNumber();
|
|
3543
|
+
const filter = contract.filters.Liquidation();
|
|
3544
|
+
const allEvents = [];
|
|
3545
|
+
for (let start = fromBlock; start <= currentBlock; start += 1e4) {
|
|
3546
|
+
const end = Math.min(start + 9999, currentBlock);
|
|
3547
|
+
const events = yield contract.queryFilter(filter, start, end);
|
|
3548
|
+
allEvents.push(...events);
|
|
4222
3549
|
}
|
|
4223
|
-
|
|
4224
|
-
|
|
3550
|
+
return Promise.all(
|
|
3551
|
+
allEvents.map((event) => __async(this, null, function* () {
|
|
3552
|
+
const {
|
|
3553
|
+
borrower,
|
|
3554
|
+
tokenCollateral,
|
|
3555
|
+
loanId,
|
|
3556
|
+
closingPositionSize,
|
|
3557
|
+
liquidatorRepaidAmount
|
|
3558
|
+
} = event.args;
|
|
3559
|
+
const block = yield provider.getBlock(event.blockNumber);
|
|
3560
|
+
const timestamp = block ? Number(block.timestamp) : 0;
|
|
3561
|
+
return {
|
|
3562
|
+
trader: borrower,
|
|
3563
|
+
tokenCollateral,
|
|
3564
|
+
loanId,
|
|
3565
|
+
closingPositionSize,
|
|
3566
|
+
liquidatorRepaidAmount,
|
|
3567
|
+
transactionHash: event.transactionHash,
|
|
3568
|
+
timestamp
|
|
3569
|
+
};
|
|
3570
|
+
}))
|
|
3571
|
+
);
|
|
3572
|
+
});
|
|
3573
|
+
}
|
|
3574
|
+
function getLoanEvm(provider, tokenHolderContractAddress, loanId) {
|
|
3575
|
+
return __async(this, null, function* () {
|
|
3576
|
+
const contract = new import_ethers.Contract(
|
|
3577
|
+
tokenHolderContractAddress,
|
|
3578
|
+
tokenHolderAbi,
|
|
3579
|
+
provider
|
|
3580
|
+
);
|
|
3581
|
+
return contract.loans(loanId);
|
|
3582
|
+
});
|
|
3583
|
+
}
|
|
3584
|
+
function getUserLoansEvm(provider, tokenHolderContractAddress, userAddress) {
|
|
3585
|
+
return __async(this, null, function* () {
|
|
3586
|
+
const contract = new import_ethers.Contract(
|
|
3587
|
+
tokenHolderContractAddress,
|
|
3588
|
+
tokenHolderAbi,
|
|
3589
|
+
provider
|
|
3590
|
+
);
|
|
3591
|
+
const nextLoanId = yield contract.nextLoanId();
|
|
3592
|
+
const userLoans = [];
|
|
3593
|
+
for (let i = 0; i < nextLoanId; i++) {
|
|
3594
|
+
const loan = yield contract.loans(i);
|
|
3595
|
+
if (loan.borrower.toLowerCase() === userAddress.toLowerCase()) {
|
|
3596
|
+
userLoans.push(loan);
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
return userLoans;
|
|
3600
|
+
});
|
|
3601
|
+
}
|
|
3602
|
+
function getCollateralInfoEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
3603
|
+
return __async(this, null, function* () {
|
|
3604
|
+
const contract = new import_ethers.Contract(
|
|
3605
|
+
tokenHolderContractAddress,
|
|
3606
|
+
tokenHolderAbi,
|
|
3607
|
+
provider
|
|
3608
|
+
);
|
|
3609
|
+
return contract.collateralMapping(collateralAddress);
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
function getOffersEvm(provider, tokenHolderContractAddress, collateralAddresses) {
|
|
3613
|
+
return __async(this, null, function* () {
|
|
3614
|
+
const contract = new import_ethers.Contract(
|
|
3615
|
+
tokenHolderContractAddress,
|
|
3616
|
+
tokenHolderAbi,
|
|
3617
|
+
provider
|
|
3618
|
+
);
|
|
3619
|
+
const activeCollaterals = [];
|
|
3620
|
+
for (const address of collateralAddresses) {
|
|
3621
|
+
const collateral = yield contract.collateralMapping(address);
|
|
3622
|
+
activeCollaterals.push({
|
|
3623
|
+
address,
|
|
3624
|
+
collateral
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
return activeCollaterals;
|
|
3628
|
+
});
|
|
3629
|
+
}
|
|
3630
|
+
function getOpeningFeeEvm(provider, borrowerOpsContractAddress) {
|
|
3631
|
+
return __async(this, null, function* () {
|
|
3632
|
+
const contract = new import_ethers.Contract(
|
|
3633
|
+
borrowerOpsContractAddress,
|
|
3634
|
+
borrowerOperationsAbi,
|
|
3635
|
+
provider
|
|
3636
|
+
);
|
|
3637
|
+
return contract.openingFee();
|
|
3638
|
+
});
|
|
3639
|
+
}
|
|
3640
|
+
function getProfitFeeEvm(provider, borrowerOpsContractAddress) {
|
|
3641
|
+
return __async(this, null, function* () {
|
|
3642
|
+
const contract = new import_ethers.Contract(
|
|
3643
|
+
borrowerOpsContractAddress,
|
|
3644
|
+
borrowerOperationsAbi,
|
|
3645
|
+
provider
|
|
3646
|
+
);
|
|
3647
|
+
return contract.profitFee();
|
|
3648
|
+
});
|
|
3649
|
+
}
|
|
3650
|
+
function getTokenBalanceEvm(provider, tokenHolderContractAddress) {
|
|
3651
|
+
return __async(this, null, function* () {
|
|
3652
|
+
const contract = new import_ethers.Contract(
|
|
3653
|
+
tokenHolderContractAddress,
|
|
3654
|
+
tokenHolderAbi,
|
|
3655
|
+
provider
|
|
3656
|
+
);
|
|
3657
|
+
return contract.getBalance();
|
|
3658
|
+
});
|
|
3659
|
+
}
|
|
3660
|
+
function getActiveLoanCountEvm(provider, tokenHolderContractAddress) {
|
|
3661
|
+
return __async(this, null, function* () {
|
|
3662
|
+
const contract = new import_ethers.Contract(
|
|
3663
|
+
tokenHolderContractAddress,
|
|
3664
|
+
tokenHolderAbi,
|
|
3665
|
+
provider
|
|
3666
|
+
);
|
|
3667
|
+
return contract.getActiveLoanCount();
|
|
3668
|
+
});
|
|
3669
|
+
}
|
|
3670
|
+
function getActiveLoansBatchEvm(provider, tokenHolderContractAddress, startIndex, batchSize) {
|
|
3671
|
+
return __async(this, null, function* () {
|
|
3672
|
+
const contract = new import_ethers.Contract(
|
|
3673
|
+
tokenHolderContractAddress,
|
|
3674
|
+
tokenHolderAbi,
|
|
3675
|
+
provider
|
|
3676
|
+
);
|
|
3677
|
+
return contract.getActiveLoansBatch(startIndex, batchSize);
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
function getLoansByBorrowerEvm(provider, tokenHolderContractAddress, borrowerAddress) {
|
|
3681
|
+
return __async(this, null, function* () {
|
|
3682
|
+
const contract = new import_ethers.Contract(
|
|
3683
|
+
tokenHolderContractAddress,
|
|
3684
|
+
tokenHolderAbi,
|
|
3685
|
+
provider
|
|
3686
|
+
);
|
|
3687
|
+
return contract.getLoansByBorrower(borrowerAddress);
|
|
3688
|
+
});
|
|
3689
|
+
}
|
|
3690
|
+
function getCollateralExposureEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
3691
|
+
return __async(this, null, function* () {
|
|
3692
|
+
const contract = new import_ethers.Contract(
|
|
3693
|
+
tokenHolderContractAddress,
|
|
3694
|
+
tokenHolderAbi,
|
|
3695
|
+
provider
|
|
3696
|
+
);
|
|
3697
|
+
return contract.getCollateralExposure(collateralAddress);
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
function getAvailableExposureEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
3701
|
+
return __async(this, null, function* () {
|
|
3702
|
+
const contract = new import_ethers.Contract(
|
|
3703
|
+
tokenHolderContractAddress,
|
|
3704
|
+
tokenHolderAbi,
|
|
3705
|
+
provider
|
|
3706
|
+
);
|
|
3707
|
+
return contract.getAvailableExposure(collateralAddress);
|
|
3708
|
+
});
|
|
3709
|
+
}
|
|
3710
|
+
var updateMaxLendPerTokenBatchEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, tokenHolderContractAddress, {
|
|
3711
|
+
collateralAddresses,
|
|
3712
|
+
newMaxLendPerTokens,
|
|
3713
|
+
gasLimit,
|
|
3714
|
+
gasPrice
|
|
3715
|
+
}) {
|
|
3716
|
+
const contract = new import_ethers.Contract(
|
|
3717
|
+
tokenHolderContractAddress,
|
|
3718
|
+
tokenHolderAbi,
|
|
3719
|
+
provider
|
|
3720
|
+
);
|
|
3721
|
+
const txOptions = {};
|
|
3722
|
+
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
3723
|
+
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
3724
|
+
return contract.updateMaxLendPerTokenBulk.populateTransaction(
|
|
3725
|
+
collateralAddresses,
|
|
3726
|
+
newMaxLendPerTokens,
|
|
3727
|
+
Object.keys(txOptions).length > 0 ? txOptions : {}
|
|
3728
|
+
);
|
|
3729
|
+
});
|
|
4225
3730
|
|
|
4226
3731
|
// index.ts
|
|
4227
3732
|
function getPda(seed, programId) {
|
|
4228
3733
|
const seedsBuffer = Array.isArray(seed) ? seed : [seed];
|
|
4229
|
-
return
|
|
3734
|
+
return import_web3.PublicKey.findProgramAddressSync(seedsBuffer, programId)[0];
|
|
4230
3735
|
}
|
|
4231
3736
|
function getPositionAccountPDA(lavarageProgram, offer, seed) {
|
|
4232
3737
|
return getPda(
|
|
@@ -4241,20 +3746,20 @@ function getPositionAccountPDA(lavarageProgram, offer, seed) {
|
|
|
4241
3746
|
}
|
|
4242
3747
|
function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
|
|
4243
3748
|
return __async(this, null, function* () {
|
|
4244
|
-
const associatedTokenAddress = (0,
|
|
3749
|
+
const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4245
3750
|
tokenAddress,
|
|
4246
3751
|
ownerPublicKey,
|
|
4247
3752
|
true,
|
|
4248
3753
|
tokenProgram,
|
|
4249
|
-
|
|
3754
|
+
import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
4250
3755
|
);
|
|
4251
|
-
const instruction = (0,
|
|
3756
|
+
const instruction = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
4252
3757
|
lavarageProgram.provider.publicKey,
|
|
4253
3758
|
associatedTokenAddress,
|
|
4254
3759
|
ownerPublicKey,
|
|
4255
3760
|
tokenAddress,
|
|
4256
3761
|
tokenProgram,
|
|
4257
|
-
|
|
3762
|
+
import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
4258
3763
|
);
|
|
4259
3764
|
return {
|
|
4260
3765
|
account: {
|
|
@@ -4342,7 +3847,7 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4342
3847
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
4343
3848
|
const feeBuffer32 = Buffer.alloc(32);
|
|
4344
3849
|
feeBuffer32.set(feeBuffer, 0);
|
|
4345
|
-
partnerFeeMarkupAsPkey = new
|
|
3850
|
+
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
4346
3851
|
}
|
|
4347
3852
|
const positionAccount = getPositionAccountPDA(
|
|
4348
3853
|
lavarageProgram,
|
|
@@ -4361,7 +3866,7 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4361
3866
|
offer.account.collateralType,
|
|
4362
3867
|
tokenProgram
|
|
4363
3868
|
);
|
|
4364
|
-
const tokenAccountCreationTx = new
|
|
3869
|
+
const tokenAccountCreationTx = new import_web3.Transaction();
|
|
4365
3870
|
if (fromTokenAccount.instruction) {
|
|
4366
3871
|
tokenAccountCreationTx.add(fromTokenAccount.instruction);
|
|
4367
3872
|
}
|
|
@@ -4375,10 +3880,10 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4375
3880
|
addressLookupTableAddresses
|
|
4376
3881
|
} = instructionsJup;
|
|
4377
3882
|
const deserializeInstruction = (instruction) => {
|
|
4378
|
-
return new
|
|
4379
|
-
programId: new
|
|
3883
|
+
return new import_web3.TransactionInstruction({
|
|
3884
|
+
programId: new import_web3.PublicKey(instruction.programId),
|
|
4380
3885
|
keys: instruction.accounts.map((key) => ({
|
|
4381
|
-
pubkey: new
|
|
3886
|
+
pubkey: new import_web3.PublicKey(key.pubkey),
|
|
4382
3887
|
isSigner: key.isSigner,
|
|
4383
3888
|
isWritable: key.isWritable
|
|
4384
3889
|
})),
|
|
@@ -4387,14 +3892,14 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4387
3892
|
};
|
|
4388
3893
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
4389
3894
|
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4390
|
-
keys.map((key) => new
|
|
3895
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
4391
3896
|
);
|
|
4392
3897
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
4393
3898
|
const addressLookupTableAddress = keys[index];
|
|
4394
3899
|
if (accountInfo) {
|
|
4395
|
-
const addressLookupTableAccount = new
|
|
4396
|
-
key: new
|
|
4397
|
-
state:
|
|
3900
|
+
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
3901
|
+
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
3902
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4398
3903
|
Uint8Array.from(accountInfo.data)
|
|
4399
3904
|
)
|
|
4400
3905
|
});
|
|
@@ -4412,16 +3917,16 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4412
3917
|
);
|
|
4413
3918
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
4414
3919
|
const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
|
|
4415
|
-
new
|
|
3920
|
+
new import_anchor.BN((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
4416
3921
|
marginSOL
|
|
4417
3922
|
).accountsStrict({
|
|
4418
3923
|
nodeWallet: offer.account.nodeWallet,
|
|
4419
|
-
instructions:
|
|
3924
|
+
instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4420
3925
|
tradingPool: offer.publicKey,
|
|
4421
3926
|
positionAccount,
|
|
4422
3927
|
trader: lavarageProgram.provider.publicKey,
|
|
4423
|
-
systemProgram:
|
|
4424
|
-
clock:
|
|
3928
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
3929
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4425
3930
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
4426
3931
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
4427
3932
|
}).remainingAccounts(
|
|
@@ -4443,7 +3948,7 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4443
3948
|
trader: lavarageProgram.provider.publicKey,
|
|
4444
3949
|
mint: offer.account.collateralType,
|
|
4445
3950
|
toTokenAccount: toTokenAccount.account.address,
|
|
4446
|
-
systemProgram:
|
|
3951
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4447
3952
|
positionAccount,
|
|
4448
3953
|
randomAccountAsId: randomSeed.publicKey.toBase58()
|
|
4449
3954
|
}).instruction();
|
|
@@ -4458,12 +3963,12 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4458
3963
|
...jupiterIxs,
|
|
4459
3964
|
openAddCollateralInstruction
|
|
4460
3965
|
].filter(Boolean);
|
|
4461
|
-
const messageV0 = new
|
|
3966
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4462
3967
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4463
3968
|
recentBlockhash: blockhash,
|
|
4464
3969
|
instructions: allInstructions
|
|
4465
3970
|
}).compileToV0Message(addressLookupTableAccounts);
|
|
4466
|
-
const tx = new
|
|
3971
|
+
const tx = new import_web3.VersionedTransaction(messageV0);
|
|
4467
3972
|
return tx;
|
|
4468
3973
|
});
|
|
4469
3974
|
var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, tokenProgram, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
@@ -4473,7 +3978,7 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4473
3978
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
4474
3979
|
const feeBuffer32 = Buffer.alloc(32);
|
|
4475
3980
|
feeBuffer32.set(feeBuffer, 0);
|
|
4476
|
-
partnerFeeMarkupAsPkey = new
|
|
3981
|
+
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
4477
3982
|
}
|
|
4478
3983
|
const positionAccount = getPositionAccountPDA(
|
|
4479
3984
|
lavarageProgram,
|
|
@@ -4494,7 +3999,7 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4494
3999
|
offer.account.collateralType,
|
|
4495
4000
|
tokenProgram
|
|
4496
4001
|
);
|
|
4497
|
-
const tokenAccountCreationTx = new
|
|
4002
|
+
const tokenAccountCreationTx = new import_web3.Transaction();
|
|
4498
4003
|
if (fromTokenAccount.instruction) {
|
|
4499
4004
|
tokenAccountCreationTx.add(fromTokenAccount.instruction);
|
|
4500
4005
|
}
|
|
@@ -4508,10 +4013,10 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4508
4013
|
addressLookupTableAddresses
|
|
4509
4014
|
} = instructionsJup;
|
|
4510
4015
|
const deserializeInstruction = (instruction) => {
|
|
4511
|
-
return new
|
|
4512
|
-
programId: new
|
|
4016
|
+
return new import_web3.TransactionInstruction({
|
|
4017
|
+
programId: new import_web3.PublicKey(instruction.programId),
|
|
4513
4018
|
keys: instruction.accounts.map((key) => ({
|
|
4514
|
-
pubkey: new
|
|
4019
|
+
pubkey: new import_web3.PublicKey(key.pubkey),
|
|
4515
4020
|
isSigner: key.isSigner,
|
|
4516
4021
|
isWritable: key.isWritable
|
|
4517
4022
|
})),
|
|
@@ -4520,14 +4025,14 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4520
4025
|
};
|
|
4521
4026
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
4522
4027
|
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4523
|
-
keys.map((key) => new
|
|
4028
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
4524
4029
|
);
|
|
4525
4030
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
4526
4031
|
const addressLookupTableAddress = keys[index];
|
|
4527
4032
|
if (accountInfo) {
|
|
4528
|
-
const addressLookupTableAccount = new
|
|
4529
|
-
key: new
|
|
4530
|
-
state:
|
|
4033
|
+
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
4034
|
+
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
4035
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4531
4036
|
Uint8Array.from(accountInfo.data)
|
|
4532
4037
|
)
|
|
4533
4038
|
});
|
|
@@ -4546,31 +4051,31 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4546
4051
|
);
|
|
4547
4052
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
4548
4053
|
const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
|
|
4549
|
-
new
|
|
4054
|
+
new import_anchor.BN((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
4550
4055
|
marginSOL
|
|
4551
4056
|
).accountsStrict({
|
|
4552
4057
|
nodeWallet: offer.account.nodeWallet,
|
|
4553
|
-
instructions:
|
|
4058
|
+
instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4554
4059
|
tradingPool: offer.publicKey,
|
|
4555
4060
|
positionAccount,
|
|
4556
4061
|
trader: lavarageProgram.provider.publicKey,
|
|
4557
|
-
systemProgram:
|
|
4558
|
-
clock:
|
|
4062
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4063
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4559
4064
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
4560
|
-
feeTokenAccount: (0,
|
|
4065
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4561
4066
|
quoteToken,
|
|
4562
|
-
new
|
|
4067
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
4563
4068
|
true,
|
|
4564
4069
|
quoteTokenProgram
|
|
4565
4070
|
),
|
|
4566
|
-
toTokenAccount: (0,
|
|
4071
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4567
4072
|
quoteToken,
|
|
4568
4073
|
lavarageProgram.provider.publicKey,
|
|
4569
4074
|
true,
|
|
4570
4075
|
quoteTokenProgram
|
|
4571
4076
|
),
|
|
4572
4077
|
tokenProgram: quoteTokenProgram,
|
|
4573
|
-
fromTokenAccount: (0,
|
|
4078
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4574
4079
|
quoteToken,
|
|
4575
4080
|
offer.account.nodeWallet,
|
|
4576
4081
|
true,
|
|
@@ -4579,7 +4084,7 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4579
4084
|
}).remainingAccounts(
|
|
4580
4085
|
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
4581
4086
|
{
|
|
4582
|
-
pubkey: (0,
|
|
4087
|
+
pubkey: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4583
4088
|
quoteToken,
|
|
4584
4089
|
partnerFeeRecipient,
|
|
4585
4090
|
false,
|
|
@@ -4600,7 +4105,7 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4600
4105
|
trader: lavarageProgram.provider.publicKey,
|
|
4601
4106
|
mint: offer.account.collateralType,
|
|
4602
4107
|
toTokenAccount: toTokenAccount.account.address,
|
|
4603
|
-
systemProgram:
|
|
4108
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4604
4109
|
positionAccount,
|
|
4605
4110
|
randomAccountAsId: randomSeed.publicKey.toBase58()
|
|
4606
4111
|
}).instruction();
|
|
@@ -4615,12 +4120,12 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
4615
4120
|
...jupiterIxs,
|
|
4616
4121
|
openAddCollateralInstruction
|
|
4617
4122
|
].filter(Boolean);
|
|
4618
|
-
const messageV0 = new
|
|
4123
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4619
4124
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4620
4125
|
recentBlockhash: blockhash,
|
|
4621
4126
|
instructions: allInstructions
|
|
4622
4127
|
}).compileToV0Message(addressLookupTableAccounts);
|
|
4623
|
-
const tx = new
|
|
4128
|
+
const tx = new import_web3.VersionedTransaction(messageV0);
|
|
4624
4129
|
return tx;
|
|
4625
4130
|
});
|
|
4626
4131
|
var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
|
|
@@ -4628,8 +4133,8 @@ var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee
|
|
|
4628
4133
|
const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
|
|
4629
4134
|
tpPrice,
|
|
4630
4135
|
tpTolerence,
|
|
4631
|
-
new
|
|
4632
|
-
new
|
|
4136
|
+
new import_web3.PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
|
|
4137
|
+
new import_anchor.BN(1e4)
|
|
4633
4138
|
).accountsStrict({
|
|
4634
4139
|
delegate: getPda(
|
|
4635
4140
|
[Buffer.from("delegate"), position.publicKey.toBuffer()],
|
|
@@ -4637,11 +4142,11 @@ var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee
|
|
|
4637
4142
|
),
|
|
4638
4143
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
4639
4144
|
delegatedAccount: position.publicKey,
|
|
4640
|
-
systemProgram:
|
|
4145
|
+
systemProgram: import_web3.SystemProgram.programId
|
|
4641
4146
|
}).remainingAccounts(
|
|
4642
4147
|
partnerFeeRecipient ? [
|
|
4643
4148
|
{
|
|
4644
|
-
pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0,
|
|
4149
|
+
pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4645
4150
|
quoteToken,
|
|
4646
4151
|
partnerFeeRecipient,
|
|
4647
4152
|
false
|
|
@@ -4651,15 +4156,15 @@ var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee
|
|
|
4651
4156
|
}
|
|
4652
4157
|
] : []
|
|
4653
4158
|
).instruction();
|
|
4654
|
-
const
|
|
4159
|
+
const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
4655
4160
|
microLamports: prioFee.toNumber()
|
|
4656
4161
|
});
|
|
4657
|
-
const messageV0 = new
|
|
4162
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4658
4163
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4659
4164
|
recentBlockhash: blockhash,
|
|
4660
|
-
instructions: [ix,
|
|
4165
|
+
instructions: [ix, computeFeeIx].filter(Boolean)
|
|
4661
4166
|
}).compileToV0Message();
|
|
4662
|
-
return new
|
|
4167
|
+
return new import_web3.VersionedTransaction(messageV0);
|
|
4663
4168
|
});
|
|
4664
4169
|
var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
|
|
4665
4170
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
@@ -4671,22 +4176,22 @@ var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee
|
|
|
4671
4176
|
delegate: delegatePda,
|
|
4672
4177
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
4673
4178
|
delegatedAccount: position.publicKey,
|
|
4674
|
-
systemProgram:
|
|
4179
|
+
systemProgram: import_web3.SystemProgram.programId
|
|
4675
4180
|
}).instruction();
|
|
4676
4181
|
const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
|
|
4677
4182
|
tpPrice,
|
|
4678
4183
|
tpTolerence,
|
|
4679
|
-
new
|
|
4680
|
-
new
|
|
4184
|
+
new import_web3.PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
|
|
4185
|
+
new import_anchor.BN(1e4)
|
|
4681
4186
|
).accountsStrict({
|
|
4682
4187
|
delegate: delegatePda,
|
|
4683
4188
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
4684
4189
|
delegatedAccount: position.publicKey,
|
|
4685
|
-
systemProgram:
|
|
4190
|
+
systemProgram: import_web3.SystemProgram.programId
|
|
4686
4191
|
}).remainingAccounts(
|
|
4687
4192
|
partnerFeeRecipient ? [
|
|
4688
4193
|
{
|
|
4689
|
-
pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0,
|
|
4194
|
+
pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4690
4195
|
quoteToken,
|
|
4691
4196
|
partnerFeeRecipient,
|
|
4692
4197
|
false
|
|
@@ -4696,15 +4201,15 @@ var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee
|
|
|
4696
4201
|
}
|
|
4697
4202
|
] : []
|
|
4698
4203
|
).instruction();
|
|
4699
|
-
const
|
|
4204
|
+
const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
4700
4205
|
microLamports: prioFee.toNumber()
|
|
4701
4206
|
});
|
|
4702
|
-
const messageV0 = new
|
|
4207
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4703
4208
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4704
4209
|
recentBlockhash: blockhash,
|
|
4705
|
-
instructions: [removeIx, ix,
|
|
4210
|
+
instructions: [removeIx, ix, computeFeeIx].filter(Boolean)
|
|
4706
4211
|
}).compileToV0Message();
|
|
4707
|
-
return new
|
|
4212
|
+
return new import_web3.VersionedTransaction(messageV0);
|
|
4708
4213
|
});
|
|
4709
4214
|
var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, null, function* () {
|
|
4710
4215
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
@@ -4716,73 +4221,73 @@ var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, n
|
|
|
4716
4221
|
delegate: delegatePda,
|
|
4717
4222
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
4718
4223
|
delegatedAccount: position.publicKey,
|
|
4719
|
-
systemProgram:
|
|
4224
|
+
systemProgram: import_web3.SystemProgram.programId
|
|
4720
4225
|
}).instruction();
|
|
4721
|
-
const
|
|
4226
|
+
const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
4722
4227
|
microLamports: prioFee.toNumber()
|
|
4723
4228
|
});
|
|
4724
|
-
const messageV0 = new
|
|
4229
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4725
4230
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4726
4231
|
recentBlockhash: blockhash,
|
|
4727
|
-
instructions: [removeIx,
|
|
4232
|
+
instructions: [removeIx, computeFeeIx].filter(Boolean)
|
|
4728
4233
|
}).compileToV0Message();
|
|
4729
|
-
return new
|
|
4234
|
+
return new import_web3.VersionedTransaction(messageV0);
|
|
4730
4235
|
});
|
|
4731
4236
|
var partialRepayV1 = (lavarageProgram, position, repaymentBps) => __async(void 0, null, function* () {
|
|
4732
4237
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
4733
4238
|
const pool = yield lavarageProgram.account.pool.fetch(position.account.pool);
|
|
4734
4239
|
const positionAccountPDA = position.publicKey;
|
|
4735
|
-
const ix = yield lavarageProgram.methods.tradingClosePartialRepaySol(new
|
|
4736
|
-
systemProgram:
|
|
4240
|
+
const ix = yield lavarageProgram.methods.tradingClosePartialRepaySol(new import_anchor.BN(repaymentBps)).accountsStrict({
|
|
4241
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4737
4242
|
positionAccount: positionAccountPDA,
|
|
4738
4243
|
tradingPool: position.account.pool,
|
|
4739
4244
|
nodeWallet: pool.nodeWallet,
|
|
4740
4245
|
trader: lavarageProgram.provider.publicKey,
|
|
4741
|
-
clock:
|
|
4246
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4742
4247
|
randomAccountAsId: position.account.seed,
|
|
4743
4248
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
4744
4249
|
}).instruction();
|
|
4745
|
-
const messageV0 = new
|
|
4250
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4746
4251
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4747
4252
|
recentBlockhash: blockhash,
|
|
4748
4253
|
instructions: [ix]
|
|
4749
4254
|
}).compileToV0Message();
|
|
4750
|
-
return new
|
|
4255
|
+
return new import_web3.VersionedTransaction(messageV0);
|
|
4751
4256
|
});
|
|
4752
4257
|
var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0, null, function* () {
|
|
4753
4258
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
4754
4259
|
const pool = yield lavarageProgram.account.pool.fetch(position.account.pool);
|
|
4755
4260
|
const positionAccountPDA = position.publicKey;
|
|
4756
|
-
const ix = yield lavarageProgram.methods.tradingPartialRepaySol(new
|
|
4757
|
-
systemProgram:
|
|
4261
|
+
const ix = yield lavarageProgram.methods.tradingPartialRepaySol(new import_anchor.BN(repaymentBps)).accountsStrict({
|
|
4262
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4758
4263
|
positionAccount: positionAccountPDA,
|
|
4759
4264
|
tradingPool: position.account.pool,
|
|
4760
4265
|
nodeWallet: pool.nodeWallet,
|
|
4761
4266
|
trader: lavarageProgram.provider.publicKey,
|
|
4762
|
-
clock:
|
|
4267
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4763
4268
|
randomAccountAsId: position.account.seed,
|
|
4764
|
-
fromTokenAccount: (0,
|
|
4269
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4765
4270
|
pool.qtType,
|
|
4766
4271
|
lavarageProgram.provider.publicKey
|
|
4767
4272
|
),
|
|
4768
|
-
toTokenAccount: (0,
|
|
4273
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4769
4274
|
pool.qtType,
|
|
4770
4275
|
pool.nodeWallet,
|
|
4771
4276
|
true
|
|
4772
4277
|
),
|
|
4773
4278
|
mint: pool.qtType,
|
|
4774
|
-
feeTokenAccount: (0,
|
|
4279
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4775
4280
|
pool.qtType,
|
|
4776
|
-
new
|
|
4281
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")
|
|
4777
4282
|
),
|
|
4778
|
-
tokenProgram:
|
|
4283
|
+
tokenProgram: import_spl_token.TOKEN_PROGRAM_ID
|
|
4779
4284
|
}).instruction();
|
|
4780
|
-
const messageV0 = new
|
|
4285
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4781
4286
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4782
4287
|
recentBlockhash: blockhash,
|
|
4783
4288
|
instructions: [ix]
|
|
4784
4289
|
}).compileToV0Message();
|
|
4785
|
-
return new
|
|
4290
|
+
return new import_web3.VersionedTransaction(messageV0);
|
|
4786
4291
|
});
|
|
4787
4292
|
var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
4788
4293
|
var _a, _b;
|
|
@@ -4792,13 +4297,13 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4792
4297
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
4793
4298
|
const feeBuffer32 = Buffer.alloc(32);
|
|
4794
4299
|
feeBuffer32.set(feeBuffer, 0);
|
|
4795
|
-
partnerFeeMarkupAsPkey = new
|
|
4300
|
+
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
4796
4301
|
}
|
|
4797
4302
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58())
|
|
4798
4303
|
throw "Mismatch offer";
|
|
4799
4304
|
const pool = offer;
|
|
4800
4305
|
const poolPubKey = offer.publicKey;
|
|
4801
|
-
const tokenAddressPubKey = new
|
|
4306
|
+
const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
|
|
4802
4307
|
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4803
4308
|
offer.account.collateralType
|
|
4804
4309
|
);
|
|
@@ -4818,10 +4323,10 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4818
4323
|
);
|
|
4819
4324
|
const jupiterSellIx = jupInstruction.instructions;
|
|
4820
4325
|
const deserializeInstruction = (instruction) => {
|
|
4821
|
-
return new
|
|
4822
|
-
programId: new
|
|
4326
|
+
return new import_web3.TransactionInstruction({
|
|
4327
|
+
programId: new import_web3.PublicKey(instruction.programId),
|
|
4823
4328
|
keys: instruction.accounts.map((key) => ({
|
|
4824
|
-
pubkey: new
|
|
4329
|
+
pubkey: new import_web3.PublicKey(key.pubkey),
|
|
4825
4330
|
isSigner: key.isSigner,
|
|
4826
4331
|
isWritable: key.isWritable
|
|
4827
4332
|
})),
|
|
@@ -4830,14 +4335,14 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4830
4335
|
};
|
|
4831
4336
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
4832
4337
|
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4833
|
-
keys.map((key) => new
|
|
4338
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
4834
4339
|
);
|
|
4835
4340
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
4836
4341
|
const addressLookupTableAddress = keys[index];
|
|
4837
4342
|
if (accountInfo) {
|
|
4838
|
-
const addressLookupTableAccount = new
|
|
4839
|
-
key: new
|
|
4840
|
-
state:
|
|
4343
|
+
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
4344
|
+
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
4345
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4841
4346
|
Uint8Array.from(accountInfo.data)
|
|
4842
4347
|
)
|
|
4843
4348
|
});
|
|
@@ -4850,13 +4355,13 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4850
4355
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
4851
4356
|
const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
|
|
4852
4357
|
tradingPool: poolPubKey,
|
|
4853
|
-
instructions:
|
|
4358
|
+
instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4854
4359
|
mint: offer.account.collateralType,
|
|
4855
4360
|
fromTokenAccount: fromTokenAccount.account.address,
|
|
4856
4361
|
toTokenAccount: toTokenAccount.account.address,
|
|
4857
4362
|
positionAccount: positionAccountPDA,
|
|
4858
|
-
clock:
|
|
4859
|
-
systemProgram:
|
|
4363
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4364
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4860
4365
|
trader: lavarageProgram.provider.publicKey,
|
|
4861
4366
|
tokenProgram,
|
|
4862
4367
|
randomAccountAsId: position.account.seed
|
|
@@ -4865,15 +4370,15 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4865
4370
|
let jupiterIxs = [];
|
|
4866
4371
|
if (jupInstruction.instructions == void 0) {
|
|
4867
4372
|
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4868
|
-
new
|
|
4869
|
-
new
|
|
4373
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4374
|
+
new import_anchor.BN(9997)
|
|
4870
4375
|
).accountsStrict({
|
|
4871
4376
|
nodeWallet: pool.account.nodeWallet,
|
|
4872
4377
|
positionAccount: positionAccountPDA,
|
|
4873
4378
|
tradingPool: poolPubKey,
|
|
4874
4379
|
trader: lavarageProgram.provider.publicKey,
|
|
4875
|
-
systemProgram:
|
|
4876
|
-
clock:
|
|
4380
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4381
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4877
4382
|
randomAccountAsId: position.account.seed,
|
|
4878
4383
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
4879
4384
|
}).remainingAccounts(
|
|
@@ -4892,15 +4397,15 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4892
4397
|
).instruction();
|
|
4893
4398
|
} else {
|
|
4894
4399
|
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4895
|
-
new
|
|
4896
|
-
new
|
|
4400
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4401
|
+
new import_anchor.BN(9998)
|
|
4897
4402
|
).accountsStrict({
|
|
4898
4403
|
nodeWallet: pool.account.nodeWallet,
|
|
4899
4404
|
positionAccount: positionAccountPDA,
|
|
4900
4405
|
tradingPool: poolPubKey,
|
|
4901
4406
|
trader: lavarageProgram.provider.publicKey,
|
|
4902
|
-
systemProgram:
|
|
4903
|
-
clock:
|
|
4407
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4408
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4904
4409
|
randomAccountAsId: position.account.seed,
|
|
4905
4410
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
4906
4411
|
}).remainingAccounts(
|
|
@@ -4935,8 +4440,8 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4935
4440
|
])
|
|
4936
4441
|
);
|
|
4937
4442
|
}
|
|
4938
|
-
const profit = new
|
|
4939
|
-
let createAssociatedTokenAccountInstruction2 = (0,
|
|
4443
|
+
const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
|
|
4444
|
+
let createAssociatedTokenAccountInstruction2 = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
4940
4445
|
lavarageProgram.provider.publicKey,
|
|
4941
4446
|
toTokenAccount.account.address,
|
|
4942
4447
|
lavarageProgram.provider.publicKey,
|
|
@@ -4953,12 +4458,12 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
4953
4458
|
...jupiterIxs,
|
|
4954
4459
|
repaySolIx
|
|
4955
4460
|
].filter((i) => !!i);
|
|
4956
|
-
const messageV0 = new
|
|
4461
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
4957
4462
|
payerKey: lavarageProgram.provider.publicKey,
|
|
4958
4463
|
recentBlockhash: blockhash,
|
|
4959
4464
|
instructions: allInstructions
|
|
4960
4465
|
}).compileToV0Message(addressLookupTableAccounts);
|
|
4961
|
-
const tx = new
|
|
4466
|
+
const tx = new import_web3.VersionedTransaction(messageV0);
|
|
4962
4467
|
return tx;
|
|
4963
4468
|
});
|
|
4964
4469
|
var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
@@ -4969,13 +4474,13 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
4969
4474
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
4970
4475
|
const feeBuffer32 = Buffer.alloc(32);
|
|
4971
4476
|
feeBuffer32.set(feeBuffer, 0);
|
|
4972
|
-
partnerFeeMarkupAsPkey = new
|
|
4477
|
+
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
4973
4478
|
}
|
|
4974
4479
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58())
|
|
4975
4480
|
throw "Mismatch offer";
|
|
4976
4481
|
const pool = offer;
|
|
4977
4482
|
const poolPubKey = offer.publicKey;
|
|
4978
|
-
const tokenAddressPubKey = new
|
|
4483
|
+
const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
|
|
4979
4484
|
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4980
4485
|
offer.account.collateralType
|
|
4981
4486
|
);
|
|
@@ -4997,10 +4502,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
4997
4502
|
);
|
|
4998
4503
|
const jupiterSellIx = jupInstruction.instructions;
|
|
4999
4504
|
const deserializeInstruction = (instruction) => {
|
|
5000
|
-
return new
|
|
5001
|
-
programId: new
|
|
4505
|
+
return new import_web3.TransactionInstruction({
|
|
4506
|
+
programId: new import_web3.PublicKey(instruction.programId),
|
|
5002
4507
|
keys: instruction.accounts.map((key) => ({
|
|
5003
|
-
pubkey: new
|
|
4508
|
+
pubkey: new import_web3.PublicKey(key.pubkey),
|
|
5004
4509
|
isSigner: key.isSigner,
|
|
5005
4510
|
isWritable: key.isWritable
|
|
5006
4511
|
})),
|
|
@@ -5009,14 +4514,14 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5009
4514
|
};
|
|
5010
4515
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
5011
4516
|
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
5012
|
-
keys.map((key) => new
|
|
4517
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
5013
4518
|
);
|
|
5014
4519
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
5015
4520
|
const addressLookupTableAddress = keys[index];
|
|
5016
4521
|
if (accountInfo) {
|
|
5017
|
-
const addressLookupTableAccount = new
|
|
5018
|
-
key: new
|
|
5019
|
-
state:
|
|
4522
|
+
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
4523
|
+
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
4524
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
5020
4525
|
Uint8Array.from(accountInfo.data)
|
|
5021
4526
|
)
|
|
5022
4527
|
});
|
|
@@ -5029,13 +4534,13 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5029
4534
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5030
4535
|
const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
|
|
5031
4536
|
tradingPool: poolPubKey,
|
|
5032
|
-
instructions:
|
|
4537
|
+
instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5033
4538
|
mint: offer.account.collateralType,
|
|
5034
4539
|
fromTokenAccount: fromTokenAccount.account.address,
|
|
5035
4540
|
toTokenAccount: toTokenAccount.account.address,
|
|
5036
4541
|
positionAccount: positionAccountPDA,
|
|
5037
|
-
clock:
|
|
5038
|
-
systemProgram:
|
|
4542
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
4543
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
5039
4544
|
trader: lavarageProgram.provider.publicKey,
|
|
5040
4545
|
tokenProgram,
|
|
5041
4546
|
randomAccountAsId: position.account.seed
|
|
@@ -5044,30 +4549,30 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5044
4549
|
let jupiterIxs = [];
|
|
5045
4550
|
if (jupInstruction.instructions == void 0) {
|
|
5046
4551
|
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
5047
|
-
new
|
|
5048
|
-
new
|
|
4552
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4553
|
+
new import_anchor.BN(9997)
|
|
5049
4554
|
).accountsStrict({
|
|
5050
4555
|
nodeWallet: pool.account.nodeWallet,
|
|
5051
4556
|
positionAccount: positionAccountPDA,
|
|
5052
4557
|
tradingPool: poolPubKey,
|
|
5053
4558
|
trader: lavarageProgram.provider.publicKey,
|
|
5054
|
-
systemProgram:
|
|
5055
|
-
clock:
|
|
4559
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4560
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
5056
4561
|
randomAccountAsId: position.account.seed,
|
|
5057
|
-
feeTokenAccount: (0,
|
|
4562
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5058
4563
|
quoteToken,
|
|
5059
|
-
new
|
|
4564
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
5060
4565
|
false,
|
|
5061
4566
|
quoteTokenProgram
|
|
5062
4567
|
),
|
|
5063
|
-
fromTokenAccount: (0,
|
|
4568
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5064
4569
|
quoteToken,
|
|
5065
4570
|
lavarageProgram.provider.publicKey,
|
|
5066
4571
|
false,
|
|
5067
4572
|
quoteTokenProgram
|
|
5068
4573
|
),
|
|
5069
4574
|
tokenProgram: quoteTokenProgram,
|
|
5070
|
-
toTokenAccount: (0,
|
|
4575
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5071
4576
|
quoteToken,
|
|
5072
4577
|
pool.account.nodeWallet,
|
|
5073
4578
|
true,
|
|
@@ -5077,7 +4582,7 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5077
4582
|
}).remainingAccounts(
|
|
5078
4583
|
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
5079
4584
|
{
|
|
5080
|
-
pubkey: (0,
|
|
4585
|
+
pubkey: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5081
4586
|
quoteToken,
|
|
5082
4587
|
partnerFeeRecipient,
|
|
5083
4588
|
false,
|
|
@@ -5095,30 +4600,30 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5095
4600
|
).instruction();
|
|
5096
4601
|
} else {
|
|
5097
4602
|
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
5098
|
-
new
|
|
5099
|
-
new
|
|
4603
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4604
|
+
new import_anchor.BN(9998)
|
|
5100
4605
|
).accountsStrict({
|
|
5101
4606
|
nodeWallet: pool.account.nodeWallet,
|
|
5102
4607
|
positionAccount: positionAccountPDA,
|
|
5103
4608
|
tradingPool: poolPubKey,
|
|
5104
4609
|
trader: lavarageProgram.provider.publicKey,
|
|
5105
|
-
systemProgram:
|
|
5106
|
-
clock:
|
|
4610
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
4611
|
+
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
5107
4612
|
randomAccountAsId: position.account.seed,
|
|
5108
|
-
feeTokenAccount: (0,
|
|
4613
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5109
4614
|
quoteToken,
|
|
5110
|
-
new
|
|
4615
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
5111
4616
|
false,
|
|
5112
4617
|
quoteTokenProgram
|
|
5113
4618
|
),
|
|
5114
|
-
fromTokenAccount: (0,
|
|
4619
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5115
4620
|
quoteToken,
|
|
5116
4621
|
lavarageProgram.provider.publicKey,
|
|
5117
4622
|
false,
|
|
5118
4623
|
quoteTokenProgram
|
|
5119
4624
|
),
|
|
5120
4625
|
tokenProgram: quoteTokenProgram,
|
|
5121
|
-
toTokenAccount: (0,
|
|
4626
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5122
4627
|
quoteToken,
|
|
5123
4628
|
pool.account.nodeWallet,
|
|
5124
4629
|
true,
|
|
@@ -5158,8 +4663,8 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5158
4663
|
])
|
|
5159
4664
|
);
|
|
5160
4665
|
}
|
|
5161
|
-
const profit = new
|
|
5162
|
-
let createAssociatedTokenAccountInstruction2 = (0,
|
|
4666
|
+
const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
|
|
4667
|
+
let createAssociatedTokenAccountInstruction2 = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
5163
4668
|
lavarageProgram.provider.publicKey,
|
|
5164
4669
|
toTokenAccount.account.address,
|
|
5165
4670
|
lavarageProgram.provider.publicKey,
|
|
@@ -5176,12 +4681,12 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
5176
4681
|
...jupiterIxs,
|
|
5177
4682
|
repaySolIx
|
|
5178
4683
|
].filter((i) => !!i);
|
|
5179
|
-
const messageV0 = new
|
|
4684
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
5180
4685
|
payerKey: lavarageProgram.provider.publicKey,
|
|
5181
4686
|
recentBlockhash: blockhash,
|
|
5182
4687
|
instructions: allInstructions
|
|
5183
4688
|
}).compileToV0Message(addressLookupTableAccounts);
|
|
5184
|
-
const tx = new
|
|
4689
|
+
const tx = new import_web3.VersionedTransaction(messageV0);
|
|
5185
4690
|
return tx;
|
|
5186
4691
|
});
|
|
5187
4692
|
var getDelegateAccounts = (lavarageProgram, userPubKey) => __async(void 0, null, function* () {
|
|
@@ -5197,8 +4702,8 @@ var getDelegateAccounts = (lavarageProgram, userPubKey) => __async(void 0, null,
|
|
|
5197
4702
|
);
|
|
5198
4703
|
return delegateAccounts.map((d) => __spreadProps(__spreadValues({}, d), {
|
|
5199
4704
|
parsed: {
|
|
5200
|
-
tpPrice: new
|
|
5201
|
-
tpThreshold: new
|
|
4705
|
+
tpPrice: new import_anchor.BN(d.account.field1),
|
|
4706
|
+
tpThreshold: new import_anchor.BN(d.account.field2)
|
|
5202
4707
|
}
|
|
5203
4708
|
}));
|
|
5204
4709
|
});
|
|
@@ -5214,8 +4719,8 @@ var getQuoteCurrencySpecificAddressLookupTable = (quoteCurrency) => {
|
|
|
5214
4719
|
};
|
|
5215
4720
|
var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBps) => __async(void 0, null, function* () {
|
|
5216
4721
|
const positionAccountPDA = position.publicKey;
|
|
5217
|
-
const newPosition1Seed =
|
|
5218
|
-
const newPosition2Seed =
|
|
4722
|
+
const newPosition1Seed = import_web3.Keypair.generate().publicKey;
|
|
4723
|
+
const newPosition2Seed = import_web3.Keypair.generate().publicKey;
|
|
5219
4724
|
const newPosition1AccountPDA = getPositionAccountPDA(
|
|
5220
4725
|
lavarageProgram,
|
|
5221
4726
|
offer,
|
|
@@ -5230,26 +4735,26 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
5230
4735
|
offer.account.collateralType
|
|
5231
4736
|
);
|
|
5232
4737
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
5233
|
-
const newPosition1TokenAccount = (0,
|
|
4738
|
+
const newPosition1TokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5234
4739
|
offer.account.collateralType,
|
|
5235
4740
|
newPosition1AccountPDA,
|
|
5236
4741
|
true,
|
|
5237
4742
|
tokenProgram
|
|
5238
4743
|
);
|
|
5239
|
-
const newPosition2TokenAccount = (0,
|
|
4744
|
+
const newPosition2TokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5240
4745
|
offer.account.collateralType,
|
|
5241
4746
|
newPosition2AccountPDA,
|
|
5242
4747
|
true,
|
|
5243
4748
|
tokenProgram
|
|
5244
4749
|
);
|
|
5245
|
-
const createNewPosition1TokenAccountIx = (0,
|
|
4750
|
+
const createNewPosition1TokenAccountIx = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
5246
4751
|
lavarageProgram.provider.publicKey,
|
|
5247
4752
|
newPosition1TokenAccount,
|
|
5248
4753
|
newPosition1AccountPDA,
|
|
5249
4754
|
offer.account.collateralType,
|
|
5250
4755
|
tokenProgram
|
|
5251
4756
|
);
|
|
5252
|
-
const createNewPosition2TokenAccountIx = (0,
|
|
4757
|
+
const createNewPosition2TokenAccountIx = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
5253
4758
|
lavarageProgram.provider.publicKey,
|
|
5254
4759
|
newPosition2TokenAccount,
|
|
5255
4760
|
newPosition2AccountPDA,
|
|
@@ -5257,7 +4762,7 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
5257
4762
|
tokenProgram
|
|
5258
4763
|
);
|
|
5259
4764
|
const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(
|
|
5260
|
-
new
|
|
4765
|
+
new import_anchor.BN(propotionBps),
|
|
5261
4766
|
newPosition1Seed,
|
|
5262
4767
|
newPosition2Seed
|
|
5263
4768
|
).accountsStrict({
|
|
@@ -5265,10 +4770,10 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
5265
4770
|
newPositionOne: newPosition1AccountPDA,
|
|
5266
4771
|
newPositionTwo: newPosition2AccountPDA,
|
|
5267
4772
|
trader: lavarageProgram.provider.publicKey,
|
|
5268
|
-
systemProgram:
|
|
4773
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
5269
4774
|
mint: offer.account.collateralType,
|
|
5270
4775
|
tokenProgram,
|
|
5271
|
-
originalPositionTokenAccount: (0,
|
|
4776
|
+
originalPositionTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5272
4777
|
offer.account.collateralType,
|
|
5273
4778
|
positionAccountPDA,
|
|
5274
4779
|
true,
|
|
@@ -5277,7 +4782,7 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
5277
4782
|
newPositionTokenAccountOne: newPosition1TokenAccount,
|
|
5278
4783
|
newPositionTokenAccountTwo: newPosition2TokenAccount
|
|
5279
4784
|
}).instruction();
|
|
5280
|
-
const computeBudgetIx =
|
|
4785
|
+
const computeBudgetIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
5281
4786
|
microLamports: 1e5
|
|
5282
4787
|
});
|
|
5283
4788
|
const allInstructions = [
|
|
@@ -5287,18 +4792,18 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
5287
4792
|
computeBudgetIx
|
|
5288
4793
|
].filter((i) => !!i);
|
|
5289
4794
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5290
|
-
const messageV0 = new
|
|
4795
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
5291
4796
|
payerKey: lavarageProgram.provider.publicKey,
|
|
5292
4797
|
recentBlockhash: blockhash,
|
|
5293
4798
|
instructions: allInstructions
|
|
5294
4799
|
}).compileToV0Message();
|
|
5295
|
-
const tx = new
|
|
4800
|
+
const tx = new import_web3.VersionedTransaction(messageV0);
|
|
5296
4801
|
return tx;
|
|
5297
4802
|
});
|
|
5298
4803
|
var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken) => __async(void 0, null, function* () {
|
|
5299
4804
|
const positionAccountPDA1 = position1.publicKey;
|
|
5300
4805
|
const positionAccountPDA2 = position2.publicKey;
|
|
5301
|
-
const newPositionSeed =
|
|
4806
|
+
const newPositionSeed = import_web3.Keypair.generate().publicKey;
|
|
5302
4807
|
const newPositionAccountPDA = getPositionAccountPDA(
|
|
5303
4808
|
lavarageProgram,
|
|
5304
4809
|
offer,
|
|
@@ -5308,13 +4813,13 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
5308
4813
|
offer.account.collateralType
|
|
5309
4814
|
);
|
|
5310
4815
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
5311
|
-
const newPositionTokenAccount = (0,
|
|
4816
|
+
const newPositionTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5312
4817
|
offer.account.collateralType,
|
|
5313
4818
|
newPositionAccountPDA,
|
|
5314
4819
|
true,
|
|
5315
4820
|
tokenProgram
|
|
5316
4821
|
);
|
|
5317
|
-
const createNewPositionTokenAccountIx = (0,
|
|
4822
|
+
const createNewPositionTokenAccountIx = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
5318
4823
|
lavarageProgram.provider.publicKey,
|
|
5319
4824
|
newPositionTokenAccount,
|
|
5320
4825
|
newPositionAccountPDA,
|
|
@@ -5326,16 +4831,16 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
5326
4831
|
positionOne: positionAccountPDA1,
|
|
5327
4832
|
positionTwo: positionAccountPDA2,
|
|
5328
4833
|
trader: lavarageProgram.provider.publicKey,
|
|
5329
|
-
systemProgram:
|
|
4834
|
+
systemProgram: import_web3.SystemProgram.programId,
|
|
5330
4835
|
mint: offer.account.collateralType,
|
|
5331
4836
|
tokenProgram,
|
|
5332
|
-
positionOneTokenAccount: (0,
|
|
4837
|
+
positionOneTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5333
4838
|
offer.account.collateralType,
|
|
5334
4839
|
positionAccountPDA1,
|
|
5335
4840
|
true,
|
|
5336
4841
|
tokenProgram
|
|
5337
4842
|
),
|
|
5338
|
-
positionTwoTokenAccount: (0,
|
|
4843
|
+
positionTwoTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
5339
4844
|
offer.account.collateralType,
|
|
5340
4845
|
positionAccountPDA2,
|
|
5341
4846
|
true,
|
|
@@ -5343,7 +4848,7 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
5343
4848
|
),
|
|
5344
4849
|
mergedPositionTokenAccount: newPositionTokenAccount
|
|
5345
4850
|
}).instruction();
|
|
5346
|
-
const computeBudgetIx =
|
|
4851
|
+
const computeBudgetIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
5347
4852
|
microLamports: 1e5
|
|
5348
4853
|
});
|
|
5349
4854
|
const allInstructions = [
|
|
@@ -5352,12 +4857,12 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
5352
4857
|
computeBudgetIx
|
|
5353
4858
|
].filter((i) => !!i);
|
|
5354
4859
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5355
|
-
const messageV0 = new
|
|
4860
|
+
const messageV0 = new import_web3.TransactionMessage({
|
|
5356
4861
|
payerKey: lavarageProgram.provider.publicKey,
|
|
5357
4862
|
recentBlockhash: blockhash,
|
|
5358
4863
|
instructions: allInstructions
|
|
5359
4864
|
}).compileToV0Message();
|
|
5360
|
-
const tx = new
|
|
4865
|
+
const tx = new import_web3.VersionedTransaction(messageV0);
|
|
5361
4866
|
return tx;
|
|
5362
4867
|
});
|
|
5363
4868
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -5391,7 +4896,6 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
5391
4896
|
getProfitFeeEvm,
|
|
5392
4897
|
getTokenBalanceEvm,
|
|
5393
4898
|
getUserLoansEvm,
|
|
5394
|
-
lending,
|
|
5395
4899
|
mergePositionV2,
|
|
5396
4900
|
modifyTpDelegate,
|
|
5397
4901
|
openPositionEvm,
|
|
@@ -5400,6 +4904,7 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
5400
4904
|
partialRepayV1,
|
|
5401
4905
|
partialRepayV2,
|
|
5402
4906
|
removeTpDelegate,
|
|
5403
|
-
splitPositionV2
|
|
4907
|
+
splitPositionV2,
|
|
4908
|
+
updateMaxLendPerTokenBatchEvm
|
|
5404
4909
|
});
|
|
5405
4910
|
//# sourceMappingURL=index.js.map
|