flash-sdk 1.0.2 → 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.
@@ -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
- // import { Perpetuals } from "../../target/types/perpetuals"
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: Keypair;
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(clusterUrl: string, adminKey: string) {
52
- this.provider = AnchorProvider.local(clusterUrl, {
53
- commitment: "confirmed",
54
- preflightCommitment: "confirmed",
55
- skipPreflight: true
56
- });
57
- setProvider(this.provider);
58
- this.program = workspace.Perpetuals as Program<Perpetuals>;
59
-
60
- this.admin = Keypair.fromSecretKey(
61
- new Uint8Array(JSON.parse(readFileSync(adminKey).toString()))
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.publicKey,
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.admin.publicKey,
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.publicKey,
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.publicKey,
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.publicKey,
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.publicKey,
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.publicKey,
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);
@@ -11,7 +11,7 @@ import { checkedCeilDiv, checkedDecimalCeilMul, checkedDecimalMul, scaleToExpone
11
11
 
12
12
 
13
13
 
14
- export class PoolAccount {
14
+ export class PoolAccount implements Pool {
15
15
 
16
16
  publicKey: PublicKey;
17
17
 
@@ -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;
package/src/readme.md CHANGED
@@ -1,4 +1,24 @@
1
- # strict JS types <=> Rust types
1
+ # Flash SDK
2
+ Client SDK for interacting with FLASH.TRADE's smart-contracts
2
3
 
3
- 1) u65 : unisigned intergar - so no decimals => BN
4
- 2) u8 : number
4
+ ## Install
5
+ ```
6
+ npm i flash-sdk / yarn add flash-sdk
7
+ ```
8
+
9
+ ## Using the SDK
10
+
11
+ ### connect sdk locally
12
+ `
13
+ import { AnchorProvider } from "@coral-xyz/anchor";
14
+
15
+ const provider : AnchorProvider = AnchorProvider.local(clusterUrl, {
16
+ commitment: "confirmed",
17
+ preflightCommitment: "confirmed",
18
+ skipPreflight: true
19
+ });
20
+ client = new PerpetualsClient(provider, programId);
21
+ `
22
+
23
+
24
+ ### To fetch all the pool data