flash-sdk 1.0.127 → 1.0.129
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/PerpetualsClient.d.ts +7 -1
- package/dist/PerpetualsClient.js +276 -46
- package/dist/PoolConfig.d.ts +3 -1
- package/dist/PoolConfig.js +4 -3
- package/dist/PoolConfig.json +15 -708
- package/dist/backupOracle.d.ts +7 -0
- package/dist/backupOracle.js +89 -0
- package/dist/idl/perp_composability.d.ts +159 -0
- package/dist/idl/perp_composability.js +159 -0
- package/dist/idl/perpetuals.d.ts +181 -0
- package/dist/idl/perpetuals.js +183 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +4 -2
@@ -0,0 +1,7 @@
|
|
1
|
+
/// <reference types="@solana/web3.js" />
|
2
|
+
import { PriceServiceConnection } from "@pythnetwork/price-service-client";
|
3
|
+
import { PoolConfig } from "./PoolConfig";
|
4
|
+
import { Program } from "@coral-xyz/anchor";
|
5
|
+
import { Perpetuals } from "./idl/perpetuals";
|
6
|
+
export declare const pythPriceServiceConnection: PriceServiceConnection;
|
7
|
+
export declare const getPythnetOraclePrices: (program: Program<Perpetuals>, poolConfig: PoolConfig, backupOracleSecretKey: string) => Promise<import("@solana/web3.js").TransactionInstruction>;
|
@@ -0,0 +1,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.getPythnetOraclePrices = exports.pythPriceServiceConnection = void 0;
|
43
|
+
var price_service_client_1 = require("@pythnetwork/price-service-client");
|
44
|
+
var web3_js_1 = require("@solana/web3.js");
|
45
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
46
|
+
var bs58_1 = __importDefault(require("bs58"));
|
47
|
+
var tweetnacl_1 = __importDefault(require("tweetnacl"));
|
48
|
+
exports.pythPriceServiceConnection = new price_service_client_1.PriceServiceConnection('https://hermes.pyth.network', {
|
49
|
+
priceFeedRequestConfig: {},
|
50
|
+
});
|
51
|
+
var getPythnetOraclePrices = function (program, poolConfig, backupOracleSecretKey) { return __awaiter(void 0, void 0, void 0, function () {
|
52
|
+
var pythPriceIds, currentPrices, backupOracleAccount, caches_1, permissionlessPythCache, message, signature, preInstruction;
|
53
|
+
return __generator(this, function (_a) {
|
54
|
+
switch (_a.label) {
|
55
|
+
case 0:
|
56
|
+
pythPriceIds = poolConfig.custodies.map(function (f) { return f.pythPriceId; });
|
57
|
+
return [4, exports.pythPriceServiceConnection.getLatestPriceFeeds(pythPriceIds)];
|
58
|
+
case 1:
|
59
|
+
currentPrices = _a.sent();
|
60
|
+
backupOracleAccount = web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(backupOracleSecretKey));
|
61
|
+
if (pythPriceIds.length === currentPrices.length) {
|
62
|
+
caches_1 = currentPrices.map(function (price) {
|
63
|
+
var uncheckedPrice = price.getPriceUnchecked();
|
64
|
+
var uncheckedEmaPrice = price.getEmaPriceUnchecked();
|
65
|
+
return {
|
66
|
+
price: new bn_js_1.default(uncheckedPrice.price),
|
67
|
+
expo: uncheckedPrice.expo,
|
68
|
+
conf: new bn_js_1.default(uncheckedPrice.conf),
|
69
|
+
ema: new bn_js_1.default(uncheckedEmaPrice.price),
|
70
|
+
publishTime: new bn_js_1.default(uncheckedPrice.publishTime)
|
71
|
+
};
|
72
|
+
});
|
73
|
+
permissionlessPythCache = {
|
74
|
+
backupCache: caches_1
|
75
|
+
};
|
76
|
+
message = program._coder.types.encode('PermissionlessPythCache', permissionlessPythCache);
|
77
|
+
signature = tweetnacl_1.default.sign.detached(message, backupOracleAccount.secretKey);
|
78
|
+
preInstruction = web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
79
|
+
publicKey: backupOracleAccount.publicKey.toBytes(),
|
80
|
+
message: message,
|
81
|
+
signature: signature,
|
82
|
+
});
|
83
|
+
return [2, preInstruction];
|
84
|
+
}
|
85
|
+
return [2];
|
86
|
+
}
|
87
|
+
});
|
88
|
+
}); };
|
89
|
+
exports.getPythnetOraclePrices = getPythnetOraclePrices;
|
@@ -119,6 +119,11 @@ export type PerpComposability = {
|
|
119
119
|
"name": "eventAuthority";
|
120
120
|
"isMut": false;
|
121
121
|
"isSigner": false;
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"name": "ixSysvar";
|
125
|
+
"isMut": false;
|
126
|
+
"isSigner": false;
|
122
127
|
}
|
123
128
|
];
|
124
129
|
"args": [
|
@@ -242,6 +247,11 @@ export type PerpComposability = {
|
|
242
247
|
"name": "eventAuthority";
|
243
248
|
"isMut": false;
|
244
249
|
"isSigner": false;
|
250
|
+
},
|
251
|
+
{
|
252
|
+
"name": "ixSysvar";
|
253
|
+
"isMut": false;
|
254
|
+
"isSigner": false;
|
245
255
|
}
|
246
256
|
];
|
247
257
|
"args": [
|
@@ -365,6 +375,11 @@ export type PerpComposability = {
|
|
365
375
|
"name": "eventAuthority";
|
366
376
|
"isMut": false;
|
367
377
|
"isSigner": false;
|
378
|
+
},
|
379
|
+
{
|
380
|
+
"name": "ixSysvar";
|
381
|
+
"isMut": false;
|
382
|
+
"isSigner": false;
|
368
383
|
}
|
369
384
|
];
|
370
385
|
"args": [
|
@@ -375,6 +390,134 @@ export type PerpComposability = {
|
|
375
390
|
};
|
376
391
|
}
|
377
392
|
];
|
393
|
+
},
|
394
|
+
{
|
395
|
+
"name": "removeCollateralAndSwap";
|
396
|
+
"accounts": [
|
397
|
+
{
|
398
|
+
"name": "delegate";
|
399
|
+
"isMut": true;
|
400
|
+
"isSigner": true;
|
401
|
+
},
|
402
|
+
{
|
403
|
+
"name": "owner";
|
404
|
+
"isMut": true;
|
405
|
+
"isSigner": false;
|
406
|
+
},
|
407
|
+
{
|
408
|
+
"name": "fundingAccount";
|
409
|
+
"isMut": true;
|
410
|
+
"isSigner": false;
|
411
|
+
},
|
412
|
+
{
|
413
|
+
"name": "receivingAccount";
|
414
|
+
"isMut": true;
|
415
|
+
"isSigner": false;
|
416
|
+
},
|
417
|
+
{
|
418
|
+
"name": "transferAuthority";
|
419
|
+
"isMut": false;
|
420
|
+
"isSigner": false;
|
421
|
+
},
|
422
|
+
{
|
423
|
+
"name": "perpetuals";
|
424
|
+
"isMut": false;
|
425
|
+
"isSigner": false;
|
426
|
+
},
|
427
|
+
{
|
428
|
+
"name": "pool";
|
429
|
+
"isMut": true;
|
430
|
+
"isSigner": false;
|
431
|
+
},
|
432
|
+
{
|
433
|
+
"name": "receivingCustody";
|
434
|
+
"isMut": true;
|
435
|
+
"isSigner": false;
|
436
|
+
},
|
437
|
+
{
|
438
|
+
"name": "receivingCustodyOracleAccount";
|
439
|
+
"isMut": false;
|
440
|
+
"isSigner": false;
|
441
|
+
},
|
442
|
+
{
|
443
|
+
"name": "receivingCustodyCustomOracleAccount";
|
444
|
+
"isMut": false;
|
445
|
+
"isSigner": false;
|
446
|
+
},
|
447
|
+
{
|
448
|
+
"name": "receivingCustodyTokenAccount";
|
449
|
+
"isMut": true;
|
450
|
+
"isSigner": false;
|
451
|
+
},
|
452
|
+
{
|
453
|
+
"name": "dispensingCustody";
|
454
|
+
"isMut": true;
|
455
|
+
"isSigner": false;
|
456
|
+
},
|
457
|
+
{
|
458
|
+
"name": "dispensingCustodyOracleAccount";
|
459
|
+
"isMut": false;
|
460
|
+
"isSigner": false;
|
461
|
+
},
|
462
|
+
{
|
463
|
+
"name": "dispensingCustodyCustomOracleAccount";
|
464
|
+
"isMut": false;
|
465
|
+
"isSigner": false;
|
466
|
+
},
|
467
|
+
{
|
468
|
+
"name": "dispensingCustodyTokenAccount";
|
469
|
+
"isMut": true;
|
470
|
+
"isSigner": false;
|
471
|
+
},
|
472
|
+
{
|
473
|
+
"name": "perpProgram";
|
474
|
+
"isMut": false;
|
475
|
+
"isSigner": false;
|
476
|
+
},
|
477
|
+
{
|
478
|
+
"name": "position";
|
479
|
+
"isMut": true;
|
480
|
+
"isSigner": false;
|
481
|
+
},
|
482
|
+
{
|
483
|
+
"name": "custody";
|
484
|
+
"isMut": true;
|
485
|
+
"isSigner": false;
|
486
|
+
},
|
487
|
+
{
|
488
|
+
"name": "custodyOracleAccount";
|
489
|
+
"isMut": false;
|
490
|
+
"isSigner": false;
|
491
|
+
},
|
492
|
+
{
|
493
|
+
"name": "custodyCustomOracleAccount";
|
494
|
+
"isMut": false;
|
495
|
+
"isSigner": false;
|
496
|
+
},
|
497
|
+
{
|
498
|
+
"name": "tokenProgram";
|
499
|
+
"isMut": false;
|
500
|
+
"isSigner": false;
|
501
|
+
},
|
502
|
+
{
|
503
|
+
"name": "eventAuthority";
|
504
|
+
"isMut": false;
|
505
|
+
"isSigner": false;
|
506
|
+
},
|
507
|
+
{
|
508
|
+
"name": "ixSysvar";
|
509
|
+
"isMut": false;
|
510
|
+
"isSigner": false;
|
511
|
+
}
|
512
|
+
];
|
513
|
+
"args": [
|
514
|
+
{
|
515
|
+
"name": "params";
|
516
|
+
"type": {
|
517
|
+
"defined": "RemoveCollateralAndSwapParams";
|
518
|
+
};
|
519
|
+
}
|
520
|
+
];
|
378
521
|
}
|
379
522
|
];
|
380
523
|
"types": [
|
@@ -440,6 +583,22 @@ export type PerpComposability = {
|
|
440
583
|
];
|
441
584
|
};
|
442
585
|
},
|
586
|
+
{
|
587
|
+
"name": "RemoveCollateralAndSwapParams";
|
588
|
+
"type": {
|
589
|
+
"kind": "struct";
|
590
|
+
"fields": [
|
591
|
+
{
|
592
|
+
"name": "minAmountOut";
|
593
|
+
"type": "u64";
|
594
|
+
},
|
595
|
+
{
|
596
|
+
"name": "collateralDelta";
|
597
|
+
"type": "u64";
|
598
|
+
}
|
599
|
+
];
|
600
|
+
};
|
601
|
+
},
|
443
602
|
{
|
444
603
|
"name": "Side";
|
445
604
|
"type": {
|
@@ -122,6 +122,11 @@ exports.IDL = {
|
|
122
122
|
"name": "eventAuthority",
|
123
123
|
"isMut": false,
|
124
124
|
"isSigner": false
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"name": "ixSysvar",
|
128
|
+
"isMut": false,
|
129
|
+
"isSigner": false
|
125
130
|
}
|
126
131
|
],
|
127
132
|
"args": [
|
@@ -245,6 +250,11 @@ exports.IDL = {
|
|
245
250
|
"name": "eventAuthority",
|
246
251
|
"isMut": false,
|
247
252
|
"isSigner": false
|
253
|
+
},
|
254
|
+
{
|
255
|
+
"name": "ixSysvar",
|
256
|
+
"isMut": false,
|
257
|
+
"isSigner": false
|
248
258
|
}
|
249
259
|
],
|
250
260
|
"args": [
|
@@ -368,6 +378,11 @@ exports.IDL = {
|
|
368
378
|
"name": "eventAuthority",
|
369
379
|
"isMut": false,
|
370
380
|
"isSigner": false
|
381
|
+
},
|
382
|
+
{
|
383
|
+
"name": "ixSysvar",
|
384
|
+
"isMut": false,
|
385
|
+
"isSigner": false
|
371
386
|
}
|
372
387
|
],
|
373
388
|
"args": [
|
@@ -378,6 +393,134 @@ exports.IDL = {
|
|
378
393
|
}
|
379
394
|
}
|
380
395
|
]
|
396
|
+
},
|
397
|
+
{
|
398
|
+
"name": "removeCollateralAndSwap",
|
399
|
+
"accounts": [
|
400
|
+
{
|
401
|
+
"name": "delegate",
|
402
|
+
"isMut": true,
|
403
|
+
"isSigner": true
|
404
|
+
},
|
405
|
+
{
|
406
|
+
"name": "owner",
|
407
|
+
"isMut": true,
|
408
|
+
"isSigner": false
|
409
|
+
},
|
410
|
+
{
|
411
|
+
"name": "fundingAccount",
|
412
|
+
"isMut": true,
|
413
|
+
"isSigner": false
|
414
|
+
},
|
415
|
+
{
|
416
|
+
"name": "receivingAccount",
|
417
|
+
"isMut": true,
|
418
|
+
"isSigner": false
|
419
|
+
},
|
420
|
+
{
|
421
|
+
"name": "transferAuthority",
|
422
|
+
"isMut": false,
|
423
|
+
"isSigner": false
|
424
|
+
},
|
425
|
+
{
|
426
|
+
"name": "perpetuals",
|
427
|
+
"isMut": false,
|
428
|
+
"isSigner": false
|
429
|
+
},
|
430
|
+
{
|
431
|
+
"name": "pool",
|
432
|
+
"isMut": true,
|
433
|
+
"isSigner": false
|
434
|
+
},
|
435
|
+
{
|
436
|
+
"name": "receivingCustody",
|
437
|
+
"isMut": true,
|
438
|
+
"isSigner": false
|
439
|
+
},
|
440
|
+
{
|
441
|
+
"name": "receivingCustodyOracleAccount",
|
442
|
+
"isMut": false,
|
443
|
+
"isSigner": false
|
444
|
+
},
|
445
|
+
{
|
446
|
+
"name": "receivingCustodyCustomOracleAccount",
|
447
|
+
"isMut": false,
|
448
|
+
"isSigner": false
|
449
|
+
},
|
450
|
+
{
|
451
|
+
"name": "receivingCustodyTokenAccount",
|
452
|
+
"isMut": true,
|
453
|
+
"isSigner": false
|
454
|
+
},
|
455
|
+
{
|
456
|
+
"name": "dispensingCustody",
|
457
|
+
"isMut": true,
|
458
|
+
"isSigner": false
|
459
|
+
},
|
460
|
+
{
|
461
|
+
"name": "dispensingCustodyOracleAccount",
|
462
|
+
"isMut": false,
|
463
|
+
"isSigner": false
|
464
|
+
},
|
465
|
+
{
|
466
|
+
"name": "dispensingCustodyCustomOracleAccount",
|
467
|
+
"isMut": false,
|
468
|
+
"isSigner": false
|
469
|
+
},
|
470
|
+
{
|
471
|
+
"name": "dispensingCustodyTokenAccount",
|
472
|
+
"isMut": true,
|
473
|
+
"isSigner": false
|
474
|
+
},
|
475
|
+
{
|
476
|
+
"name": "perpProgram",
|
477
|
+
"isMut": false,
|
478
|
+
"isSigner": false
|
479
|
+
},
|
480
|
+
{
|
481
|
+
"name": "position",
|
482
|
+
"isMut": true,
|
483
|
+
"isSigner": false
|
484
|
+
},
|
485
|
+
{
|
486
|
+
"name": "custody",
|
487
|
+
"isMut": true,
|
488
|
+
"isSigner": false
|
489
|
+
},
|
490
|
+
{
|
491
|
+
"name": "custodyOracleAccount",
|
492
|
+
"isMut": false,
|
493
|
+
"isSigner": false
|
494
|
+
},
|
495
|
+
{
|
496
|
+
"name": "custodyCustomOracleAccount",
|
497
|
+
"isMut": false,
|
498
|
+
"isSigner": false
|
499
|
+
},
|
500
|
+
{
|
501
|
+
"name": "tokenProgram",
|
502
|
+
"isMut": false,
|
503
|
+
"isSigner": false
|
504
|
+
},
|
505
|
+
{
|
506
|
+
"name": "eventAuthority",
|
507
|
+
"isMut": false,
|
508
|
+
"isSigner": false
|
509
|
+
},
|
510
|
+
{
|
511
|
+
"name": "ixSysvar",
|
512
|
+
"isMut": false,
|
513
|
+
"isSigner": false
|
514
|
+
}
|
515
|
+
],
|
516
|
+
"args": [
|
517
|
+
{
|
518
|
+
"name": "params",
|
519
|
+
"type": {
|
520
|
+
"defined": "RemoveCollateralAndSwapParams"
|
521
|
+
}
|
522
|
+
}
|
523
|
+
]
|
381
524
|
}
|
382
525
|
],
|
383
526
|
"types": [
|
@@ -443,6 +586,22 @@ exports.IDL = {
|
|
443
586
|
]
|
444
587
|
}
|
445
588
|
},
|
589
|
+
{
|
590
|
+
"name": "RemoveCollateralAndSwapParams",
|
591
|
+
"type": {
|
592
|
+
"kind": "struct",
|
593
|
+
"fields": [
|
594
|
+
{
|
595
|
+
"name": "minAmountOut",
|
596
|
+
"type": "u64"
|
597
|
+
},
|
598
|
+
{
|
599
|
+
"name": "collateralDelta",
|
600
|
+
"type": "u64"
|
601
|
+
}
|
602
|
+
]
|
603
|
+
}
|
604
|
+
},
|
446
605
|
{
|
447
606
|
"name": "Side",
|
448
607
|
"type": {
|