@deriverse/kit 1.0.14 → 1.0.16

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Address, Base64EncodedDataResponse, Rpc, IAccountMeta, IInstruction, Commitment } from "@solana/kit";
2
- import { Instrument, GetClientSpotOrdersInfoResponse, GetClientSpotOrdersArgs, GetClientSpotOrdersResponse, SpotOrderCancelArgs, GetClientDataResponse, GetClientSpotOrdersInfoArgs, SpotLpArgs, getInstrAccountByTagArgs, GetInstrIdArgs, NewSpotOrderArgs, DepositArgs, WithdrawArgs, SpotQuotesReplaceArgs, SpotMassCancelArgs, InstrId, GetClientPerpOrdersInfoArgs, GetClientPerpOrdersInfoResponse, GetClientPerpOrdersArgs, GetClientPerpOrdersResponse, PerpDepositArgs, NewPerpOrderArgs, PerpQuotesReplaceArgs, PerpOrderCancelArgs, PerpMassCancelArgs, PerpForcedCloseArgs, CommunityData, LogMessage, PerpChangeLeverageArgs, PerpStatisticsResetArgs, EngineArgs } from './types';
2
+ import { Instrument, GetClientSpotOrdersInfoResponse, GetClientSpotOrdersArgs, GetClientSpotOrdersResponse, SpotOrderCancelArgs, GetClientDataResponse, GetClientSpotOrdersInfoArgs, SpotLpArgs, getInstrAccountByTagArgs, GetInstrIdArgs, NewSpotOrderArgs, DepositArgs, WithdrawArgs, SpotQuotesReplaceArgs, SpotMassCancelArgs, InstrId, GetClientPerpOrdersInfoArgs, GetClientPerpOrdersInfoResponse, GetClientPerpOrdersArgs, GetClientPerpOrdersResponse, PerpDepositArgs, NewPerpOrderArgs, PerpQuotesReplaceArgs, PerpOrderCancelArgs, PerpMassCancelArgs, PerpForcedCloseArgs, CommunityData, LogMessage, PerpChangeLeverageArgs, PerpStatisticsResetArgs, EngineArgs, NewInstrumentArgs } from './types';
3
3
  import { InstrAccountHeaderModel, RootStateModel, TokenStateModel } from "./structure_models";
4
4
  export * from './types';
5
5
  export * from './logs_models';
@@ -227,4 +227,10 @@ export declare class Engine {
227
227
  * @returns Transaction instruction
228
228
  */
229
229
  perpStatisticsResetInstruction(args: PerpStatisticsResetArgs): Promise<any>;
230
+ /**
231
+ * Build new instrument instructions
232
+ * @param args New instrument data
233
+ * @returns Transaction instruction
234
+ */
235
+ newInstrumentInstructions(args: NewInstrumentArgs): Promise<any[]>;
230
236
  }
package/dist/index.js CHANGED
@@ -1986,7 +1986,7 @@ class Engine {
1986
1986
  throw new Error("Client account not found");
1987
1987
  }
1988
1988
  let instr = this.instruments.get(args.instrId);
1989
- let buf = (0, instruction_models_1.newSpotOrderData)(12, args.ioc == null || args.ioc == undefined ? 0 : args.ioc, args.orderType == null || args.orderType == undefined ? 0 : args.orderType, args.side, args.instrId, Math.round(args.price * dec), Math.round(args.qty * this.tokenDec(instr.header.assetTokenId)));
1989
+ let buf = (0, instruction_models_1.newSpotOrderData)(12, args.ioc == null || args.ioc == undefined ? 0 : args.ioc, args.orderType == null || args.orderType == undefined ? 0 : args.orderType, args.side, args.instrId, Math.round(args.price * 1000000000), Math.round(args.qty * this.tokenDec(instr.header.assetTokenId)));
1990
1990
  let keys = [
1991
1991
  { address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
1992
1992
  { address: this.rootAccount, role: kit_1.AccountRole.READONLY },
@@ -2021,7 +2021,7 @@ class Engine {
2021
2021
  }
2022
2022
  let instr = this.instruments.get(args.instrId);
2023
2023
  let assetTokenDecFactor = this.tokenDec(instr.header.assetTokenId);
2024
- let buf = (0, instruction_models_1.spotQuotesReplaceData)(34, args.instrId, Math.round(args.newBidPrice * dec), Math.round(args.newBidQty * assetTokenDecFactor), args.bidOrderIdToCancel, Math.round(args.newAskPrice * dec), Math.round(args.newAskQty * assetTokenDecFactor), args.askOrderIdToCancel);
2024
+ let buf = (0, instruction_models_1.spotQuotesReplaceData)(34, args.instrId, Math.round(args.newBidPrice * 1000000000), Math.round(args.newBidQty * assetTokenDecFactor), args.bidOrderIdToCancel, Math.round(args.newAskPrice * 1000000000), Math.round(args.newAskQty * assetTokenDecFactor), args.askOrderIdToCancel);
2025
2025
  let keys = [
2026
2026
  { address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
2027
2027
  { address: this.rootAccount, role: kit_1.AccountRole.READONLY },
@@ -2145,10 +2145,9 @@ class Engine {
2145
2145
  });
2146
2146
  const perpMapsAccountSize = 175336;
2147
2147
  const perpMapsAccountLamports = yield this.rpc.getMinimumBalanceForRentExemption(BigInt(perpMapsAccountSize)).send();
2148
- const signer = (0, kit_1.createNoopSigner)(this.signer);
2149
2148
  const createMapsAccountIx = (0, system_1.getCreateAccountWithSeedInstruction)({
2150
- payer: signer,
2151
- baseAccount: signer,
2149
+ payer: this.signer,
2150
+ baseAccount: this.signer,
2152
2151
  base: this.signer,
2153
2152
  newAccount: perpMapsAccount,
2154
2153
  seed: perpMapsAccountSeed,
@@ -2339,7 +2338,7 @@ class Engine {
2339
2338
  return {
2340
2339
  accounts: keys,
2341
2340
  programAddress: this.programId,
2342
- data: (0, instruction_models_1.newPerpOrderData)(19, args.ioc == null || args.ioc == undefined ? 0 : args.ioc, args.leverage == null || args.leverage == undefined ? 0 : args.leverage, args.orderType == null || args.orderType == undefined ? 0 : args.orderType, args.side, args.instrId, args.price * dec, args.qty * this.tokenDec(instr.header.assetTokenId)),
2341
+ data: (0, instruction_models_1.newPerpOrderData)(19, args.ioc == null || args.ioc == undefined ? 0 : args.ioc, args.leverage == null || args.leverage == undefined ? 0 : args.leverage, args.orderType == null || args.orderType == undefined ? 0 : args.orderType, args.side, args.instrId, args.price * 1000000000, args.qty * this.tokenDec(instr.header.assetTokenId)),
2343
2342
  };
2344
2343
  });
2345
2344
  }
@@ -2355,7 +2354,7 @@ class Engine {
2355
2354
  }
2356
2355
  const instr = this.instruments.get(args.instrId);
2357
2356
  let assetTokenDecFactor = this.tokenDec(instr.header.assetTokenId);
2358
- let buf = (0, instruction_models_1.perpQuotesReplaceData)(42, args.instrId, Math.round(args.newBidPrice * dec), Math.round(args.newBidQty * assetTokenDecFactor), args.bidOrderIdToCancel, Math.round(args.newAskPrice * dec), Math.round(args.newAskQty * assetTokenDecFactor), args.askOrderIdToCancel);
2357
+ let buf = (0, instruction_models_1.perpQuotesReplaceData)(42, args.instrId, Math.round(args.newBidPrice * 1000000000), Math.round(args.newBidQty * assetTokenDecFactor), args.bidOrderIdToCancel, Math.round(args.newAskPrice * 1000000000), Math.round(args.newAskQty * assetTokenDecFactor), args.askOrderIdToCancel);
2359
2358
  let keys = [
2360
2359
  { address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
2361
2360
  { address: this.rootAccount, role: kit_1.AccountRole.READONLY },
@@ -2529,5 +2528,167 @@ class Engine {
2529
2528
  };
2530
2529
  });
2531
2530
  }
2531
+ /**
2532
+ * Build new instrument instructions
2533
+ * @param args New instrument data
2534
+ * @returns Transaction instruction
2535
+ */
2536
+ newInstrumentInstructions(args) {
2537
+ return __awaiter(this, void 0, void 0, function* () {
2538
+ if (this.signer == null) {
2539
+ throw new Error("Wallet is not connected");
2540
+ }
2541
+ if (args.initialPrice <= 0) {
2542
+ throw new Error("Invalid initial price");
2543
+ }
2544
+ const assetInfo = yield this.rpc.getAccountInfo(args.assetMint).send();
2545
+ if (!assetInfo.value) {
2546
+ throw new Error("Asset mint not found");
2547
+ }
2548
+ const tokenProgramId = assetInfo.value.owner == TOKEN_2022_PROGRAM_ID ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID;
2549
+ const crncyTokenId = yield this.getTokenId(args.crncyMint);
2550
+ const id = yield this.getTokenId(args.assetMint);
2551
+ const newAssetTokenId = id != null;
2552
+ const assetTokenId = id !== null && id !== void 0 ? id : this.rootAccount.tokensCount;
2553
+ if (!crncyTokenId) {
2554
+ throw new Error("Currency mint not found");
2555
+ }
2556
+ const mapsAccountSeed = this.version.toString() + "_" +
2557
+ types_1.AccountType.SPOT_MAPS.toString() + "_" +
2558
+ assetTokenId.toString() + "_" +
2559
+ crncyTokenId.toString();
2560
+ const mapsAccount = yield (0, kit_1.createAddressWithSeed)({
2561
+ baseAddress: this.signer,
2562
+ programAddress: this.programId,
2563
+ seed: mapsAccountSeed
2564
+ });
2565
+ const mapsAccountSize = 42184;
2566
+ const mapsAccountLamports = yield this.rpc.getMinimumBalanceForRentExemption(BigInt(mapsAccountSize)).send();
2567
+ const createMapsAccountIx = (0, system_1.getCreateAccountWithSeedInstruction)({
2568
+ payer: this.signer,
2569
+ baseAccount: this.signer,
2570
+ base: this.signer,
2571
+ newAccount: mapsAccount,
2572
+ seed: mapsAccountSeed,
2573
+ space: mapsAccountSize,
2574
+ programAddress: this.programId,
2575
+ amount: mapsAccountLamports,
2576
+ });
2577
+ const slot = Number((yield this.rpc.getSlot().send())) - 1;
2578
+ const lutAddress = yield getLookupTableAddress(this.signer, slot);
2579
+ let keys = [
2580
+ { address: this.signer, role: kit_1.AccountRole.READONLY_SIGNER },
2581
+ { address: this.rootAccount, role: kit_1.AccountRole.WRITABLE },
2582
+ { address: yield this.getTokenAccount(args.assetMint), role: newAssetTokenId ? kit_1.AccountRole.WRITABLE : kit_1.AccountRole.READONLY },
2583
+ { address: yield this.getTokenAccount(args.crncyMint), role: kit_1.AccountRole.READONLY },
2584
+ { address: newAssetTokenId ? args.newProgramAccountAddress : this.tokens.get(assetTokenId).programAddress, role: newAssetTokenId ? kit_1.AccountRole.WRITABLE_SIGNER : kit_1.AccountRole.READONLY },
2585
+ { address: args.assetMint, role: kit_1.AccountRole.READONLY },
2586
+ { address: lutAddress, role: kit_1.AccountRole.WRITABLE },
2587
+ { address: tokenProgramId, role: kit_1.AccountRole.READONLY },
2588
+ { address: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, role: kit_1.AccountRole.READONLY },
2589
+ { address: this.drvsAuthority, role: kit_1.AccountRole.READONLY },
2590
+ {
2591
+ address: yield this.getInstrAccountByTag({
2592
+ assetTokenId: assetTokenId,
2593
+ crncyTokenId: crncyTokenId,
2594
+ tag: types_1.AccountType.INSTR
2595
+ }), role: kit_1.AccountRole.WRITABLE
2596
+ },
2597
+ {
2598
+ address: yield this.getInstrAccountByTag({
2599
+ assetTokenId: assetTokenId,
2600
+ crncyTokenId: crncyTokenId,
2601
+ tag: types_1.AccountType.SPOT_BIDS_TREE
2602
+ }), role: kit_1.AccountRole.WRITABLE
2603
+ },
2604
+ {
2605
+ address: yield this.getInstrAccountByTag({
2606
+ assetTokenId: assetTokenId,
2607
+ crncyTokenId: crncyTokenId,
2608
+ tag: types_1.AccountType.SPOT_ASKS_TREE
2609
+ }), role: kit_1.AccountRole.WRITABLE
2610
+ },
2611
+ {
2612
+ address: yield this.getInstrAccountByTag({
2613
+ assetTokenId: assetTokenId,
2614
+ crncyTokenId: crncyTokenId,
2615
+ tag: types_1.AccountType.SPOT_BID_ORDERS
2616
+ }), role: kit_1.AccountRole.WRITABLE
2617
+ },
2618
+ {
2619
+ address: yield this.getInstrAccountByTag({
2620
+ assetTokenId: assetTokenId,
2621
+ crncyTokenId: crncyTokenId,
2622
+ tag: types_1.AccountType.SPOT_ASK_ORDERS
2623
+ }), role: kit_1.AccountRole.WRITABLE
2624
+ },
2625
+ {
2626
+ address: yield this.getInstrAccountByTag({
2627
+ assetTokenId: assetTokenId,
2628
+ crncyTokenId: crncyTokenId,
2629
+ tag: types_1.AccountType.SPOT_LINES
2630
+ }), role: kit_1.AccountRole.WRITABLE
2631
+ },
2632
+ {
2633
+ address: mapsAccount, role: kit_1.AccountRole.WRITABLE
2634
+ },
2635
+ {
2636
+ address: yield this.getInstrAccountByTag({
2637
+ assetTokenId: assetTokenId,
2638
+ crncyTokenId: crncyTokenId,
2639
+ tag: types_1.AccountType.SPOT_CLIENT_INFOS
2640
+ }), role: kit_1.AccountRole.WRITABLE
2641
+ },
2642
+ {
2643
+ address: yield this.getInstrAccountByTag({
2644
+ assetTokenId: assetTokenId,
2645
+ crncyTokenId: crncyTokenId,
2646
+ tag: types_1.AccountType.SPOT_CLIENT_INFOS2
2647
+ }), role: kit_1.AccountRole.WRITABLE
2648
+ },
2649
+ {
2650
+ address: yield this.getInstrAccountByTag({
2651
+ assetTokenId: assetTokenId,
2652
+ crncyTokenId: crncyTokenId,
2653
+ tag: types_1.AccountType.SPOT_CLIENT_ACCOUNTS
2654
+ }), role: kit_1.AccountRole.WRITABLE
2655
+ },
2656
+ {
2657
+ address: yield this.getInstrAccountByTag({
2658
+ assetTokenId: assetTokenId,
2659
+ crncyTokenId: crncyTokenId,
2660
+ tag: types_1.AccountType.SPOT_1M_CANDLES
2661
+ }), role: kit_1.AccountRole.WRITABLE
2662
+ },
2663
+ {
2664
+ address: yield this.getInstrAccountByTag({
2665
+ assetTokenId: assetTokenId,
2666
+ crncyTokenId: crncyTokenId,
2667
+ tag: types_1.AccountType.SPOT_15M_CANDLES
2668
+ }), role: kit_1.AccountRole.WRITABLE
2669
+ },
2670
+ {
2671
+ address: yield this.getInstrAccountByTag({
2672
+ assetTokenId: assetTokenId,
2673
+ crncyTokenId: crncyTokenId,
2674
+ tag: types_1.AccountType.SPOT_DAY_CANDLES
2675
+ }), role: kit_1.AccountRole.WRITABLE
2676
+ },
2677
+ {
2678
+ address: yield this.getInstrAccountByTag({
2679
+ assetTokenId: assetTokenId,
2680
+ crncyTokenId: crncyTokenId,
2681
+ tag: types_1.AccountType.INSTR_TRACE
2682
+ }), role: kit_1.AccountRole.WRITABLE
2683
+ },
2684
+ ];
2685
+ const upgradeIx = {
2686
+ accounts: keys,
2687
+ programAddress: this.programId,
2688
+ data: (0, instruction_models_1.newInstrumentData)(9, crncyTokenId, slot, args.initialPrice * 1000000000)
2689
+ };
2690
+ return [createMapsAccountIx, upgradeIx];
2691
+ });
2692
+ }
2532
2693
  }
2533
2694
  exports.Engine = Engine;
package/dist/types.d.ts CHANGED
@@ -552,4 +552,10 @@ export interface NewPerpOrderArgs {
552
552
  leverage?: number;
553
553
  side: number;
554
554
  }
555
+ export interface NewInstrumentArgs {
556
+ assetMint: Address;
557
+ crncyMint: Address;
558
+ newProgramAccountAddress?: Address;
559
+ initialPrice: number;
560
+ }
555
561
  export type LogMessage = DepositReportModel | WithdrawReportModel | PerpDepositReportModel | PerpWithdrawReportModel | FeesDepositReportModel | FeesWithdrawReportModel | SpotlpTradeReportModel | EarningsReportModel | DrvsAirdropReportModel | SpotPlaceOrderReportModel | SpotFillOrderReportModel | SpotNewOrderReportModel | SpotOrderCancelReportModel | SpotOrderRevokeReportModel | SpotFeesReportModel | SpotPlaceMassCancelReportModel | SpotMassCancelReportModel | PerpPlaceOrderReportModel | PerpFillOrderReportModel | PerpNewOrderReportModel | PerpOrderCancelReportModel | PerpOrderRevokeReportModel | PerpFeesReportModel | PerpPlaceMassCancelReportModel | PerpMassCancelReportModel | PerpFundingReportModel | PerpSocLossReportModel | PerpChangeLeverageReportModel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deriverse/kit",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",