flash-sdk 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CustodyAccount.d.ts +3 -1
- 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 +1 -2
- package/lib/PoolDisplayData.d.ts +0 -1
- 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 +0 -1
- package/package.json +1 -1
- package/readme.md +23 -3
- package/src/CustodyAccount.ts +3 -1
- package/src/PerpetualsClient.ts +62 -32
- package/src/PoolAccount.ts +1 -1
- package/src/PositionAccount.ts +2 -1
- 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 +3 -3
package/src/PerpetualsClient.ts
CHANGED
@@ -24,42 +24,72 @@ import {
|
|
24
24
|
TOKEN_PROGRAM_ID,
|
25
25
|
} from "@solana/spl-token";
|
26
26
|
|
27
|
-
import fetch from "node-fetch";
|
28
27
|
import { sha256 } from "js-sha256";
|
29
28
|
import { encode } from "bs58";
|
30
|
-
import { readFileSync } from "fs";
|
31
|
-
|
32
29
|
import { PoolAccount } from "./PoolAccount";
|
33
30
|
import { PositionAccount } from "./PositionAccount";
|
34
31
|
import { BorrowRateParams, Custody, Fees, OracleParams, Permissions, Position, PositionSide, PricingParams, TokenRatios, isVariant } from "./types";
|
35
32
|
import { OraclePrice } from "./OraclePrice";
|
36
33
|
import { CustodyAccount } from "./CustodyAccount";
|
37
|
-
import { Perpetuals } from "./target/types/perpetuals"
|
38
|
-
|
34
|
+
import { Perpetuals } from "./target/types/perpetuals";
|
35
|
+
import {IDL} from './target/types/perpetuals';
|
36
|
+
|
37
|
+
|
38
|
+
/* USEAGE
|
39
|
+
|
40
|
+
UI ---
|
41
|
+
provider = from phatom
|
42
|
+
|
43
|
+
client = new PerpetualsClient(provider, user.pubkey , programId);
|
44
|
+
|
45
|
+
BOT cli --------
|
39
46
|
|
47
|
+
provider = await getProvider(new DefaultWallet(DEFAULT_PERPS_USER));
|
40
48
|
|
49
|
+
AnchorProvider.local(clusterUrl, {
|
50
|
+
commitment: "confirmed",
|
51
|
+
preflightCommitment: "confirmed",
|
52
|
+
skipPreflight: true
|
53
|
+
});
|
54
|
+
process.env["ANCHOR_WALLET"] = adminKeyPath;
|
55
|
+
|
56
|
+
client = new PerpetualsClient(provider, DEFAULT_PERPS_USER.pubkey , programId);
|
57
|
+
|
58
|
+
*/
|
41
59
|
export class PerpetualsClient {
|
42
60
|
provider: AnchorProvider;
|
43
61
|
program: Program<Perpetuals>;
|
44
|
-
admin:
|
62
|
+
admin: PublicKey;
|
63
|
+
programId: PublicKey;
|
45
64
|
|
46
65
|
// pdas
|
47
66
|
multisig: { publicKey: PublicKey; bump: number };
|
48
67
|
authority: { publicKey: PublicKey; bump: number };
|
49
68
|
perpetuals: { publicKey: PublicKey; bump: number };
|
50
69
|
|
51
|
-
constructor(
|
52
|
-
this.provider = AnchorProvider.local(clusterUrl, {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
});
|
57
|
-
setProvider(this.provider);
|
58
|
-
this.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
);
|
70
|
+
constructor(provider: AnchorProvider, programId: PublicKey) {
|
71
|
+
// this.provider = AnchorProvider.local(clusterUrl, {
|
72
|
+
// commitment: "confirmed",
|
73
|
+
// preflightCommitment: "confirmed",
|
74
|
+
// skipPreflight: true
|
75
|
+
// });
|
76
|
+
// setProvider(this.provider);
|
77
|
+
this.provider = provider;
|
78
|
+
setProvider(provider);
|
79
|
+
|
80
|
+
// const idl = JSON.parse( fs.readFileSync("./target/idl/perpetuals.json", "utf8"));
|
81
|
+
// const idl = JSON.parse(IDL);
|
82
|
+
// const program = new anchor.Program(idl, programId, provider);
|
83
|
+
this.program = new Program(IDL, programId);
|
84
|
+
//this.program = workspace.Perpetuals as Program<Perpetuals>;
|
85
|
+
console.log("client constructor programID : ",this.program.programId.toBase58());
|
86
|
+
|
87
|
+
// this.admin = Keypair.fromSecretKey(
|
88
|
+
// new Uint8Array(JSON.parse(readFileSync(adminKey).toString()))
|
89
|
+
// );
|
90
|
+
|
91
|
+
this.admin = this.provider.wallet.publicKey;
|
92
|
+
console.log("admin:",this.admin.toBase58())
|
63
93
|
|
64
94
|
this.multisig = this.findProgramAddress("multisig");
|
65
95
|
this.authority = this.findProgramAddress("transfer_authority");
|
@@ -343,11 +373,11 @@ export class PerpetualsClient {
|
|
343
373
|
minSignatures,
|
344
374
|
})
|
345
375
|
.accounts({
|
346
|
-
admin: this.admin
|
376
|
+
admin: this.admin,
|
347
377
|
multisig: this.multisig.publicKey,
|
348
378
|
})
|
349
379
|
.remainingAccounts(adminMetas)
|
350
|
-
.signers([this.admin])
|
380
|
+
// .signers([this.admin])
|
351
381
|
.rpc();
|
352
382
|
} catch (err) {
|
353
383
|
// @ts-ignore
|
@@ -362,7 +392,7 @@ export class PerpetualsClient {
|
|
362
392
|
await this.program.methods
|
363
393
|
.addPool({ name })
|
364
394
|
.accounts({
|
365
|
-
admin: this.
|
395
|
+
admin: this.provider.wallet.publicKey,
|
366
396
|
multisig: this.multisig.publicKey,
|
367
397
|
transferAuthority: this.authority.publicKey,
|
368
398
|
perpetuals: this.perpetuals.publicKey,
|
@@ -372,7 +402,7 @@ export class PerpetualsClient {
|
|
372
402
|
tokenProgram: TOKEN_PROGRAM_ID,
|
373
403
|
rent: SYSVAR_RENT_PUBKEY,
|
374
404
|
})
|
375
|
-
.signers([this.admin])
|
405
|
+
// .signers([this.admin])
|
376
406
|
.rpc()
|
377
407
|
.catch((err) => {
|
378
408
|
console.error(err);
|
@@ -384,14 +414,14 @@ export class PerpetualsClient {
|
|
384
414
|
await this.program.methods
|
385
415
|
.removePool({})
|
386
416
|
.accounts({
|
387
|
-
admin: this.admin
|
417
|
+
admin: this.admin,
|
388
418
|
multisig: this.multisig.publicKey,
|
389
419
|
transferAuthority: this.authority.publicKey,
|
390
420
|
perpetuals: this.perpetuals.publicKey,
|
391
421
|
pool: this.getPoolKey(name),
|
392
422
|
systemProgram: SystemProgram.programId,
|
393
423
|
})
|
394
|
-
.signers([this.admin])
|
424
|
+
// .signers([this.admin])
|
395
425
|
.rpc()
|
396
426
|
.catch((err) => {
|
397
427
|
console.error(err);
|
@@ -425,7 +455,7 @@ export class PerpetualsClient {
|
|
425
455
|
ratios,
|
426
456
|
})
|
427
457
|
.accounts({
|
428
|
-
admin: this.admin
|
458
|
+
admin: this.admin,
|
429
459
|
multisig: this.multisig.publicKey,
|
430
460
|
transferAuthority: this.authority.publicKey,
|
431
461
|
perpetuals: this.perpetuals.publicKey,
|
@@ -440,7 +470,7 @@ export class PerpetualsClient {
|
|
440
470
|
tokenProgram: TOKEN_PROGRAM_ID,
|
441
471
|
rent: SYSVAR_RENT_PUBKEY,
|
442
472
|
})
|
443
|
-
.signers([this.admin])
|
473
|
+
// .signers([this.admin])
|
444
474
|
.rpc()
|
445
475
|
.catch((err) => {
|
446
476
|
console.error(err);
|
@@ -481,7 +511,7 @@ export class PerpetualsClient {
|
|
481
511
|
ratios,
|
482
512
|
})
|
483
513
|
.accounts({
|
484
|
-
admin: this.admin
|
514
|
+
admin: this.admin,
|
485
515
|
multisig: this.multisig.publicKey,
|
486
516
|
transferAuthority: this.authority.publicKey,
|
487
517
|
perpetuals: this.perpetuals.publicKey,
|
@@ -496,7 +526,7 @@ export class PerpetualsClient {
|
|
496
526
|
tokenProgram: TOKEN_PROGRAM_ID,
|
497
527
|
rent: SYSVAR_RENT_PUBKEY,
|
498
528
|
})
|
499
|
-
.signers([this.admin])
|
529
|
+
// .signers([this.admin])
|
500
530
|
.rpc()
|
501
531
|
.catch((err) => {
|
502
532
|
console.error(err);
|
@@ -509,7 +539,7 @@ export class PerpetualsClient {
|
|
509
539
|
await this.program.methods
|
510
540
|
.removeCustody({ ratios })
|
511
541
|
.accounts({
|
512
|
-
admin: this.admin
|
542
|
+
admin: this.admin,
|
513
543
|
multisig: this.multisig.publicKey,
|
514
544
|
transferAuthority: this.authority.publicKey,
|
515
545
|
perpetuals: this.perpetuals.publicKey,
|
@@ -522,7 +552,7 @@ export class PerpetualsClient {
|
|
522
552
|
systemProgram: SystemProgram.programId,
|
523
553
|
tokenProgram: TOKEN_PROGRAM_ID,
|
524
554
|
})
|
525
|
-
.signers([this.admin])
|
555
|
+
// .signers([this.admin])
|
526
556
|
.rpc()
|
527
557
|
.catch((err) => {
|
528
558
|
console.error(err);
|
@@ -534,13 +564,13 @@ export class PerpetualsClient {
|
|
534
564
|
await this.program.methods
|
535
565
|
.upgradeCustody({})
|
536
566
|
.accounts({
|
537
|
-
admin: this.admin
|
567
|
+
admin: this.admin,
|
538
568
|
multisig: this.multisig.publicKey,
|
539
569
|
pool: this.getPoolKey(poolName),
|
540
570
|
custody: this.getCustodyKey(poolName, tokenMint),
|
541
571
|
systemProgram: SystemProgram.programId,
|
542
572
|
})
|
543
|
-
.signers([this.admin])
|
573
|
+
// .signers([this.admin])
|
544
574
|
.rpc()
|
545
575
|
.catch((err) => {
|
546
576
|
console.error(err);
|
package/src/PoolAccount.ts
CHANGED
package/src/PositionAccount.ts
CHANGED
@@ -3,7 +3,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { isVariant, Position, Side } from "./types";
|
4
4
|
|
5
5
|
|
6
|
-
export class PositionAccount {
|
6
|
+
export class PositionAccount implements Position {
|
7
7
|
|
8
8
|
public publicKey: PublicKey;
|
9
9
|
|
@@ -25,6 +25,7 @@ export class PositionAccount {
|
|
25
25
|
public lockedAmount: BN;
|
26
26
|
public collateralAmount: BN;
|
27
27
|
// extra
|
28
|
+
public bump: number
|
28
29
|
|
29
30
|
constructor( publicKey : PublicKey, parseData : Position) {
|
30
31
|
this.publicKey = publicKey;
|