flash-sdk 1.0.1 → 1.0.3
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/lib/CustodyAccount.d.ts +5 -2
- package/lib/CustodyAccount.js +30 -0
- package/lib/OraclePrice.d.ts +0 -1
- package/lib/PerpetualsClient.d.ts +4 -3
- package/lib/PerpetualsClient.js +56 -25
- package/lib/PoolAccount.d.ts +3 -3
- package/lib/PoolAccount.js +60 -3
- package/lib/PoolDisplayData.d.ts +23 -3
- package/lib/PoolDisplayData.js +145 -2
- package/lib/PositionAccount.d.ts +2 -2
- package/lib/PositionAccount.js +0 -1
- package/lib/client/src/PerpetualsClient.d.ts +6 -8
- package/lib/client/src/PerpetualsClient.js +55 -25
- package/lib/client/src/index.d.ts +2 -1
- package/lib/client/src/index.js +3 -1
- package/lib/client/src/target/types/limit_order_cpi.d.ts +130 -0
- package/lib/client/src/target/types/limit_order_cpi.js +132 -0
- package/lib/constants/index.d.ts +0 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +14 -1
- package/lib/types/index.js +11 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +45 -1
- package/package.json +1 -1
- package/src/CustodyAccount.ts +36 -2
- package/src/PerpetualsClient.ts +62 -32
- package/src/PoolAccount.ts +76 -5
- package/src/PoolDisplayData.ts +157 -7
- package/src/PositionAccount.ts +2 -1
- package/src/readme.md +23 -3
- package/src/target/idl/perpetuals.json +0 -3537
- package/src/target/types/limit_order_cpi.js +132 -0
- package/src/target/types/limit_order_cpi.ts +259 -0
- package/src/types/index.ts +9 -2
- package/src/utils/index.ts +51 -0
@@ -42,10 +42,31 @@ var web3_js_1 = require("@solana/web3.js");
|
|
42
42
|
var spl_token_1 = require("@solana/spl-token");
|
43
43
|
var js_sha256_1 = require("js-sha256");
|
44
44
|
var bs58_1 = require("bs58");
|
45
|
-
var fs_1 = require("fs");
|
46
45
|
var PositionAccount_1 = require("./PositionAccount");
|
46
|
+
var perpetuals_1 = require("../../target/types/perpetuals");
|
47
|
+
/* USEAGE
|
48
|
+
|
49
|
+
UI ---
|
50
|
+
provider = from phatom
|
51
|
+
|
52
|
+
client = new PerpetualsClient(provider, user.pubkey , programId);
|
53
|
+
|
54
|
+
BOT cli --------
|
55
|
+
|
56
|
+
provider = await getProvider(new DefaultWallet(DEFAULT_PERPS_USER));
|
57
|
+
|
58
|
+
AnchorProvider.local(clusterUrl, {
|
59
|
+
commitment: "confirmed",
|
60
|
+
preflightCommitment: "confirmed",
|
61
|
+
skipPreflight: true
|
62
|
+
});
|
63
|
+
process.env["ANCHOR_WALLET"] = adminKeyPath;
|
64
|
+
|
65
|
+
client = new PerpetualsClient(provider, DEFAULT_PERPS_USER.pubkey , programId);
|
66
|
+
|
67
|
+
*/
|
47
68
|
var PerpetualsClient = /** @class */ (function () {
|
48
|
-
function PerpetualsClient(
|
69
|
+
function PerpetualsClient(provider, programId) {
|
49
70
|
var _this = this;
|
50
71
|
this.findProgramAddress = function (label, extraSeeds) {
|
51
72
|
if (extraSeeds === void 0) { extraSeeds = null; }
|
@@ -334,11 +355,11 @@ var PerpetualsClient = /** @class */ (function () {
|
|
334
355
|
minSignatures: minSignatures,
|
335
356
|
})
|
336
357
|
.accounts({
|
337
|
-
admin: this.admin
|
358
|
+
admin: this.admin,
|
338
359
|
multisig: this.multisig.publicKey,
|
339
360
|
})
|
340
361
|
.remainingAccounts(adminMetas)
|
341
|
-
.signers([this.admin])
|
362
|
+
// .signers([this.admin])
|
342
363
|
.rpc()];
|
343
364
|
case 2:
|
344
365
|
_a.sent();
|
@@ -360,7 +381,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
360
381
|
case 0: return [4 /*yield*/, this.program.methods
|
361
382
|
.addPool({ name: name })
|
362
383
|
.accounts({
|
363
|
-
admin: this.
|
384
|
+
admin: this.provider.wallet.publicKey,
|
364
385
|
multisig: this.multisig.publicKey,
|
365
386
|
transferAuthority: this.authority.publicKey,
|
366
387
|
perpetuals: this.perpetuals.publicKey,
|
@@ -370,7 +391,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
370
391
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
371
392
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
372
393
|
})
|
373
|
-
.signers([this.admin])
|
394
|
+
// .signers([this.admin])
|
374
395
|
.rpc()
|
375
396
|
.catch(function (err) {
|
376
397
|
console.error(err);
|
@@ -388,14 +409,14 @@ var PerpetualsClient = /** @class */ (function () {
|
|
388
409
|
case 0: return [4 /*yield*/, this.program.methods
|
389
410
|
.removePool({})
|
390
411
|
.accounts({
|
391
|
-
admin: this.admin
|
412
|
+
admin: this.admin,
|
392
413
|
multisig: this.multisig.publicKey,
|
393
414
|
transferAuthority: this.authority.publicKey,
|
394
415
|
perpetuals: this.perpetuals.publicKey,
|
395
416
|
pool: this.getPoolKey(name),
|
396
417
|
systemProgram: web3_js_1.SystemProgram.programId,
|
397
418
|
})
|
398
|
-
.signers([this.admin])
|
419
|
+
// .signers([this.admin])
|
399
420
|
.rpc()
|
400
421
|
.catch(function (err) {
|
401
422
|
console.error(err);
|
@@ -429,7 +450,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
429
450
|
ratios: ratios,
|
430
451
|
})
|
431
452
|
.accounts({
|
432
|
-
admin: this.admin
|
453
|
+
admin: this.admin,
|
433
454
|
multisig: this.multisig.publicKey,
|
434
455
|
transferAuthority: this.authority.publicKey,
|
435
456
|
perpetuals: this.perpetuals.publicKey,
|
@@ -441,7 +462,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
441
462
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
442
463
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
443
464
|
})
|
444
|
-
.signers([this.admin])
|
465
|
+
// .signers([this.admin])
|
445
466
|
.rpc()
|
446
467
|
.catch(function (err) {
|
447
468
|
console.error(err);
|
@@ -478,7 +499,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
478
499
|
ratios: ratios,
|
479
500
|
})
|
480
501
|
.accounts({
|
481
|
-
admin: this.admin
|
502
|
+
admin: this.admin,
|
482
503
|
multisig: this.multisig.publicKey,
|
483
504
|
transferAuthority: this.authority.publicKey,
|
484
505
|
perpetuals: this.perpetuals.publicKey,
|
@@ -490,7 +511,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
490
511
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
491
512
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
492
513
|
})
|
493
|
-
.signers([this.admin])
|
514
|
+
// .signers([this.admin])
|
494
515
|
.rpc()
|
495
516
|
.catch(function (err) {
|
496
517
|
console.error(err);
|
@@ -509,7 +530,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
509
530
|
case 0: return [4 /*yield*/, this.program.methods
|
510
531
|
.removeCustody({ ratios: ratios })
|
511
532
|
.accounts({
|
512
|
-
admin: this.admin
|
533
|
+
admin: this.admin,
|
513
534
|
multisig: this.multisig.publicKey,
|
514
535
|
transferAuthority: this.authority.publicKey,
|
515
536
|
perpetuals: this.perpetuals.publicKey,
|
@@ -519,7 +540,7 @@ var PerpetualsClient = /** @class */ (function () {
|
|
519
540
|
systemProgram: web3_js_1.SystemProgram.programId,
|
520
541
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
521
542
|
})
|
522
|
-
.signers([this.admin])
|
543
|
+
// .signers([this.admin])
|
523
544
|
.rpc()
|
524
545
|
.catch(function (err) {
|
525
546
|
console.error(err);
|
@@ -537,13 +558,13 @@ var PerpetualsClient = /** @class */ (function () {
|
|
537
558
|
case 0: return [4 /*yield*/, this.program.methods
|
538
559
|
.upgradeCustody({})
|
539
560
|
.accounts({
|
540
|
-
admin: this.admin
|
561
|
+
admin: this.admin,
|
541
562
|
multisig: this.multisig.publicKey,
|
542
563
|
pool: this.getPoolKey(poolName),
|
543
564
|
custody: this.getCustodyKey(poolName, tokenMint),
|
544
565
|
systemProgram: web3_js_1.SystemProgram.programId,
|
545
566
|
})
|
546
|
-
.signers([this.admin])
|
567
|
+
// .signers([this.admin])
|
547
568
|
.rpc()
|
548
569
|
.catch(function (err) {
|
549
570
|
console.error(err);
|
@@ -992,14 +1013,24 @@ var PerpetualsClient = /** @class */ (function () {
|
|
992
1013
|
}
|
993
1014
|
});
|
994
1015
|
}); };
|
995
|
-
this.provider =
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
});
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1016
|
+
// this.provider = AnchorProvider.local(clusterUrl, {
|
1017
|
+
// commitment: "confirmed",
|
1018
|
+
// preflightCommitment: "confirmed",
|
1019
|
+
// skipPreflight: true
|
1020
|
+
// });
|
1021
|
+
// setProvider(this.provider);
|
1022
|
+
(0, anchor_1.setProvider)(provider);
|
1023
|
+
// const idl = JSON.parse( fs.readFileSync("./target/idl/perpetuals.json", "utf8"));
|
1024
|
+
// const idl = JSON.parse(IDL);
|
1025
|
+
// const program = new anchor.Program(idl, programId, provider);
|
1026
|
+
this.program = new anchor_1.Program(perpetuals_1.IDL, programId);
|
1027
|
+
//this.program = workspace.Perpetuals as Program<Perpetuals>;
|
1028
|
+
console.log("client constructor programID : ", this.program.programId.toBase58());
|
1029
|
+
// this.admin = Keypair.fromSecretKey(
|
1030
|
+
// new Uint8Array(JSON.parse(readFileSync(adminKey).toString()))
|
1031
|
+
// );
|
1032
|
+
this.admin = this.provider.wallet.publicKey;
|
1033
|
+
console.log("admin:", this.admin.toBase58());
|
1003
1034
|
this.multisig = this.findProgramAddress("multisig");
|
1004
1035
|
this.authority = this.findProgramAddress("transfer_authority");
|
1005
1036
|
this.perpetuals = this.findProgramAddress("perpetuals");
|
@@ -1010,4 +1041,3 @@ var PerpetualsClient = /** @class */ (function () {
|
|
1010
1041
|
return PerpetualsClient;
|
1011
1042
|
}());
|
1012
1043
|
exports.PerpetualsClient = PerpetualsClient;
|
1013
|
-
//# sourceMappingURL=PerpetualsClient.js.map
|
package/lib/client/src/index.js
CHANGED
@@ -20,5 +20,7 @@ __exportStar(require("./PositionAccount"), exports);
|
|
20
20
|
__exportStar(require("./OraclePrice"), exports);
|
21
21
|
__exportStar(require("./constants"), exports);
|
22
22
|
__exportStar(require("./types"), exports);
|
23
|
+
__exportStar(require("./utils"), exports);
|
23
24
|
__exportStar(require("./PerpetualsClient"), exports);
|
24
|
-
|
25
|
+
__exportStar(require("./PoolConfig"), exports);
|
26
|
+
// export { default as PoolConfigJson } from "./PoolConfig.json";
|
@@ -0,0 +1,130 @@
|
|
1
|
+
export type LimitOrderCpi = {
|
2
|
+
"version": "0.1.0";
|
3
|
+
"name": "limit_order_cpi";
|
4
|
+
"instructions": [
|
5
|
+
{
|
6
|
+
"name": "processMarketOrder";
|
7
|
+
"accounts": [
|
8
|
+
{
|
9
|
+
"name": "keeper";
|
10
|
+
"isMut": true;
|
11
|
+
"isSigner": true;
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"name": "pdaAccount";
|
15
|
+
"isMut": true;
|
16
|
+
"isSigner": false;
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "pdaTokenVault";
|
20
|
+
"isMut": true;
|
21
|
+
"isSigner": false;
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"name": "transferAuthority";
|
25
|
+
"isMut": false;
|
26
|
+
"isSigner": false;
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"name": "perpetuals";
|
30
|
+
"isMut": false;
|
31
|
+
"isSigner": false;
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"name": "pool";
|
35
|
+
"isMut": true;
|
36
|
+
"isSigner": false;
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"name": "position";
|
40
|
+
"isMut": true;
|
41
|
+
"isSigner": false;
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"name": "custody";
|
45
|
+
"isMut": true;
|
46
|
+
"isSigner": false;
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"name": "custodyOracleAccount";
|
50
|
+
"isMut": false;
|
51
|
+
"isSigner": false;
|
52
|
+
},
|
53
|
+
{
|
54
|
+
"name": "custodyTokenAccount";
|
55
|
+
"isMut": true;
|
56
|
+
"isSigner": false;
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"name": "systemProgram";
|
60
|
+
"isMut": false;
|
61
|
+
"isSigner": false;
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"name": "tokenProgram";
|
65
|
+
"isMut": false;
|
66
|
+
"isSigner": false;
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"name": "flashProgram";
|
70
|
+
"isMut": false;
|
71
|
+
"isSigner": false;
|
72
|
+
}
|
73
|
+
];
|
74
|
+
"args": [
|
75
|
+
{
|
76
|
+
"name": "params";
|
77
|
+
"type": {
|
78
|
+
"defined": "OpenPositionParams";
|
79
|
+
};
|
80
|
+
}
|
81
|
+
];
|
82
|
+
}
|
83
|
+
];
|
84
|
+
"types": [
|
85
|
+
{
|
86
|
+
"name": "OpenPositionParams";
|
87
|
+
"type": {
|
88
|
+
"kind": "struct";
|
89
|
+
"fields": [
|
90
|
+
{
|
91
|
+
"name": "price";
|
92
|
+
"type": "u64";
|
93
|
+
},
|
94
|
+
{
|
95
|
+
"name": "collateral";
|
96
|
+
"type": "u64";
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"name": "size";
|
100
|
+
"type": "u64";
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"name": "side";
|
104
|
+
"type": {
|
105
|
+
"defined": "Side";
|
106
|
+
};
|
107
|
+
}
|
108
|
+
];
|
109
|
+
};
|
110
|
+
},
|
111
|
+
{
|
112
|
+
"name": "Side";
|
113
|
+
"type": {
|
114
|
+
"kind": "enum";
|
115
|
+
"variants": [
|
116
|
+
{
|
117
|
+
"name": "None";
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"name": "Long";
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"name": "Short";
|
124
|
+
}
|
125
|
+
];
|
126
|
+
};
|
127
|
+
}
|
128
|
+
];
|
129
|
+
};
|
130
|
+
export declare const IDL: LimitOrderCpi;
|
@@ -0,0 +1,132 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.IDL = void 0;
|
4
|
+
exports.IDL = {
|
5
|
+
"version": "0.1.0",
|
6
|
+
"name": "limit_order_cpi",
|
7
|
+
"instructions": [
|
8
|
+
{
|
9
|
+
"name": "processMarketOrder",
|
10
|
+
"accounts": [
|
11
|
+
{
|
12
|
+
"name": "keeper",
|
13
|
+
"isMut": true,
|
14
|
+
"isSigner": true
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "pdaAccount",
|
18
|
+
"isMut": true,
|
19
|
+
"isSigner": false
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"name": "pdaTokenVault",
|
23
|
+
"isMut": true,
|
24
|
+
"isSigner": false
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "transferAuthority",
|
28
|
+
"isMut": false,
|
29
|
+
"isSigner": false
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"name": "perpetuals",
|
33
|
+
"isMut": false,
|
34
|
+
"isSigner": false
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"name": "pool",
|
38
|
+
"isMut": true,
|
39
|
+
"isSigner": false
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"name": "position",
|
43
|
+
"isMut": true,
|
44
|
+
"isSigner": false
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"name": "custody",
|
48
|
+
"isMut": true,
|
49
|
+
"isSigner": false
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"name": "custodyOracleAccount",
|
53
|
+
"isMut": false,
|
54
|
+
"isSigner": false
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"name": "custodyTokenAccount",
|
58
|
+
"isMut": true,
|
59
|
+
"isSigner": false
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"name": "systemProgram",
|
63
|
+
"isMut": false,
|
64
|
+
"isSigner": false
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"name": "tokenProgram",
|
68
|
+
"isMut": false,
|
69
|
+
"isSigner": false
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"name": "flashProgram",
|
73
|
+
"isMut": false,
|
74
|
+
"isSigner": false
|
75
|
+
}
|
76
|
+
],
|
77
|
+
"args": [
|
78
|
+
{
|
79
|
+
"name": "params",
|
80
|
+
"type": {
|
81
|
+
"defined": "OpenPositionParams"
|
82
|
+
}
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
],
|
87
|
+
"types": [
|
88
|
+
{
|
89
|
+
"name": "OpenPositionParams",
|
90
|
+
"type": {
|
91
|
+
"kind": "struct",
|
92
|
+
"fields": [
|
93
|
+
{
|
94
|
+
"name": "price",
|
95
|
+
"type": "u64"
|
96
|
+
},
|
97
|
+
{
|
98
|
+
"name": "collateral",
|
99
|
+
"type": "u64"
|
100
|
+
},
|
101
|
+
{
|
102
|
+
"name": "size",
|
103
|
+
"type": "u64"
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"name": "side",
|
107
|
+
"type": {
|
108
|
+
"defined": "Side"
|
109
|
+
}
|
110
|
+
}
|
111
|
+
]
|
112
|
+
}
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"name": "Side",
|
116
|
+
"type": {
|
117
|
+
"kind": "enum",
|
118
|
+
"variants": [
|
119
|
+
{
|
120
|
+
"name": "None"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"name": "Long"
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"name": "Short"
|
127
|
+
}
|
128
|
+
]
|
129
|
+
}
|
130
|
+
}
|
131
|
+
]
|
132
|
+
};
|
package/lib/constants/index.d.ts
CHANGED