From b905b13c6e2d7326b8e97bbd92dd15f22d7d8797 Mon Sep 17 00:00:00 2001 From: Fedor-Aftermath Date: Mon, 30 Dec 2024 11:43:30 +0200 Subject: [PATCH] chore: review fixes --- src/general/utils/casting.ts | 2 - .../limitOrders/api/limitOrdersApi.ts | 20 ++----- .../limitOrders/api/limitOrdersApiCasting.ts | 34 ------------ .../api/limitOrdersApiCastingTypes.ts | 42 --------------- src/packages/limitOrders/limitOrders.ts | 52 +++++++++++++------ src/packages/limitOrders/limitOrdersTypes.ts | 26 ++-------- src/packages/userData/userData.ts | 2 +- 7 files changed, 45 insertions(+), 133 deletions(-) delete mode 100644 src/packages/limitOrders/api/limitOrdersApiCasting.ts delete mode 100644 src/packages/limitOrders/api/limitOrdersApiCastingTypes.ts diff --git a/src/general/utils/casting.ts b/src/general/utils/casting.ts index f925c19f..c2bd4fe0 100644 --- a/src/general/utils/casting.ts +++ b/src/general/utils/casting.ts @@ -16,7 +16,6 @@ import { BcsTypeName } from "../types/castingTypes"; import { SuiObjectResponse } from "@mysten/sui/client"; import { NftsApiCasting } from "../nfts/nftsApiCasting"; import { DcaApiCasting } from "../../packages/dca/api/dcaApiCasting"; -import { LimitOrdersApiCasting } from "../../packages/limitOrders/api/limitOrdersApiCasting"; /** * Utility class for casting and conversion functions. @@ -38,7 +37,6 @@ export class Casting { public static farms = FarmsApiCasting; public static nfts = NftsApiCasting; public static dca = DcaApiCasting; - public static limit = LimitOrdersApiCasting; // ========================================================================= // Constants diff --git a/src/packages/limitOrders/api/limitOrdersApi.ts b/src/packages/limitOrders/api/limitOrdersApi.ts index 7894ca25..9ee9f492 100644 --- a/src/packages/limitOrders/api/limitOrdersApi.ts +++ b/src/packages/limitOrders/api/limitOrdersApi.ts @@ -1,22 +1,8 @@ import { AftermathApi } from "../../../general/providers"; -import { AnyObjectType, LimitAddresses, SuiAddress } from "../../../types"; +import { AnyObjectType, LimitAddresses } from "../../../types"; import { EventsApiHelpers } from "../../../general/apiHelpers/eventsApiHelpers"; export class LimitOrdersApi { - // ========================================================================= - // Constants - // ========================================================================= - - private static readonly constants = { - moduleNames: { - limit: "order", - events: "events", - }, - eventNames: { - createdOrder: "CreatedOrderEvent", - }, - }; - // ========================================================================= // Class Members // ========================================================================= @@ -51,7 +37,7 @@ export class LimitOrdersApi { private createdOrderEventType = () => EventsApiHelpers.createEventType( this.addresses.packages.limit, - LimitOrdersApi.constants.moduleNames.events, - LimitOrdersApi.constants.eventNames.createdOrder + "events", + "CreatedOrderEvent" ); } diff --git a/src/packages/limitOrders/api/limitOrdersApiCasting.ts b/src/packages/limitOrders/api/limitOrdersApiCasting.ts deleted file mode 100644 index 5ab11327..00000000 --- a/src/packages/limitOrders/api/limitOrdersApiCasting.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Helpers } from "../../../general/utils"; -import { LimitOrdersCreatedOrderEvent } from "../limitOrdersTypes"; -import { LimitCreatedOrderEventOnChain } from "./limitOrdersApiCastingTypes"; - -export class LimitOrdersApiCasting { - // ========================================================================= - // Chain Event objects - // ========================================================================= - - public static createdLimitOrderEventFromOnChain = ( - eventOnChain: LimitCreatedOrderEventOnChain - ): LimitOrdersCreatedOrderEvent => { - const fields = eventOnChain.parsedJson; - return { - orderId: Helpers.addLeadingZeroesToType(fields.order_id), - user: Helpers.addLeadingZeroesToType(fields.user), - // TODO: - should i convert to string? - userPublicKey: fields.user_pk, - recipient: Helpers.addLeadingZeroesToType(fields.recipient), - inputAmount: BigInt(fields.input_amount), - inputType: Helpers.addLeadingZeroesToType( - "0x" + Buffer.from(fields.input_type).toString() - ), - outputType: Helpers.addLeadingZeroesToType( - "0x" + Buffer.from(fields.output_type).toString() - ), - gasAmount: BigInt(fields.gas_amount), - encryptedFields: fields.encrypted_fields, - timestamp: eventOnChain.timestampMs, - txnDigest: eventOnChain.id.txDigest, - type: eventOnChain.type, - }; - }; -} diff --git a/src/packages/limitOrders/api/limitOrdersApiCastingTypes.ts b/src/packages/limitOrders/api/limitOrdersApiCastingTypes.ts deleted file mode 100644 index 53aac461..00000000 --- a/src/packages/limitOrders/api/limitOrdersApiCastingTypes.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { EventOnChain } from "../../../general/types/castingTypes"; -import { - Balance, - BigIntAsString, - CoinType, - ObjectId, - SerializedTransaction, - ServiceCoinData, - SuiAddress, - Timestamp, - TransactionDigest, -} from "../../../types"; -import { LimitOrdersIndexerOrderStatus } from "../limitOrdersTypes"; - -// ========================================================================= -// Objects -// ========================================================================= - -export interface LimitOrderFieldsOnChain { - id: ObjectId; - user: SuiAddress; - recipient: ObjectId; - balance: BigIntAsString; - gas: BigIntAsString; - encrypted_fields: Uint8Array; -} - -// ========================================================================= -// Events -// ========================================================================= - -export type LimitCreatedOrderEventOnChain = EventOnChain<{ - order_id: ObjectId; - user: SuiAddress; - user_pk: Uint8Array; - recipient: ObjectId; - input_amount: BigIntAsString; - input_type: Uint8Array; - output_type: Uint8Array; - gas_amount: BigIntAsString; - encrypted_fields: Uint8Array; -}>; diff --git a/src/packages/limitOrders/limitOrders.ts b/src/packages/limitOrders/limitOrders.ts index d271a48b..af11ea7a 100644 --- a/src/packages/limitOrders/limitOrders.ts +++ b/src/packages/limitOrders/limitOrders.ts @@ -1,11 +1,11 @@ -import { ObjectId, SuiNetwork } from "../../types"; +import { CoinType, ObjectId, SuiNetwork } from "../../types"; import { Caller } from "../../general/utils/caller"; import { AftermathApi } from "../../general/providers"; import { SuiAddress } from "../../types"; import { - ApiLimitOrdersOwnedBody, - ApiLimitOrdersTransactionForCreateOrderBody, - ApiLimitOrdersTransactionForCancelOrderBody, + ApiLimitOrdersPastOrdersOwnedBody, + ApiLimitOrdersCreateOrderTransactionBody, + ApiLimitOrdersCancelOrderTransactionBody, LimitOrderObject, ApiLimitOrdersActiveOrdersOwnedBody, } from "./limitOrdersTypes"; @@ -59,10 +59,10 @@ export class LimitOrders extends Caller { */ public async getPastLimitOrders(inputs: { walletAddress: SuiAddress }) { - return this.fetchApi( - "orders/past", - inputs - ); + return this.fetchApi< + LimitOrderObject[], + ApiLimitOrdersPastOrdersOwnedBody + >("orders/past", inputs); } // ========================================================================= @@ -71,14 +71,14 @@ export class LimitOrders extends Caller { /** * Fetches the API transaction for creating Limit order. - * @param { ApiLimitOrdersTransactionForCreateOrderBody } inputs - The inputs for the transaction. + * @param { ApiLimitOrdersCreateOrderTransactionBody } inputs - The inputs for the transaction. * @returns { Promise } A promise that resolves with the API transaction. */ public async getCreateLimitOrderTx( - inputs: ApiLimitOrdersTransactionForCreateOrderBody + inputs: ApiLimitOrdersCreateOrderTransactionBody ): Promise { - return this.fetchApiTransaction( + return this.fetchApiTransaction( "transactions/create-order", inputs ); @@ -91,12 +91,12 @@ export class LimitOrders extends Caller { */ public async cancelLimitOrder( - inputs: ApiLimitOrdersTransactionForCancelOrderBody + inputs: ApiLimitOrdersCancelOrderTransactionBody ): Promise { - return this.fetchApi< - boolean, - ApiLimitOrdersTransactionForCancelOrderBody - >(`interactions/cancel-order`, inputs); + return this.fetchApi( + `interactions/cancel-order`, + inputs + ); } // ========================================================================= @@ -121,4 +121,24 @@ export class LimitOrders extends Caller { order_object_ids: inputs.orderIds, }; } + + // ========================================================================= + // Configuration + // ========================================================================= + + /** + * Method for getting a minimum allowable order size. + * @returns Minimum order size in usd. + */ + + public async getMinOrderSize() { + return this.fetchApi< + | { + minOrderCoinType: CoinType; + minOrderSizeUsd: number; + } + | undefined, + undefined + >("min-order-size-usd"); + } } diff --git a/src/packages/limitOrders/limitOrdersTypes.ts b/src/packages/limitOrders/limitOrdersTypes.ts index 52adab03..70d44e10 100644 --- a/src/packages/limitOrders/limitOrdersTypes.ts +++ b/src/packages/limitOrders/limitOrdersTypes.ts @@ -20,7 +20,7 @@ export interface LimitOrdersIntegratorFeeData { // Initialize Order Transaction // ========================================================================= -export interface ApiLimitOrdersTransactionForCreateOrderBody { +export interface ApiLimitOrdersCreateOrderTransactionBody { walletAddress: SuiAddress; allocateCoinType: CoinType; allocateCoinAmount: Balance; @@ -36,7 +36,7 @@ export interface ApiLimitOrdersTransactionForCreateOrderBody { // Cancel Order Transaction // ========================================================================= -export interface ApiLimitOrdersTransactionForCancelOrderBody { +export interface ApiLimitOrdersCancelOrderTransactionBody { walletAddress: SuiAddress; bytes: string; signature: string; @@ -46,7 +46,7 @@ export interface ApiLimitOrdersTransactionForCancelOrderBody { // Limit Order Fetch // ========================================================================= -export type LimitOrdersIndexerOrderStatus = +export type LimitOrdersOrderStatus = | "Active" | "Canceled" | "Failed" @@ -80,32 +80,16 @@ export interface LimitOrderObject { tnxDigest: TransactionDigest; }; expiry: Timestamp; - status: LimitOrdersIndexerOrderStatus | undefined; + status: LimitOrdersOrderStatus | undefined; error: string | undefined; integratorFee?: LimitOrdersIntegratorFeeData; } -// ========================================================================= -// Limit Orders Events -// ========================================================================= - -export interface LimitOrdersCreatedOrderEvent extends Event { - orderId: ObjectId; - user: SuiAddress; - userPublicKey: Uint8Array; - recipient: SuiAddress; - inputAmount: Balance; - inputType: CoinType; - outputType: CoinType; - gasAmount: Balance; - encryptedFields: Uint8Array; -} - // ========================================================================= // Owned Limit Orders // ========================================================================= -export interface ApiLimitOrdersOwnedBody { +export interface ApiLimitOrdersPastOrdersOwnedBody { walletAddress: SuiAddress; } diff --git a/src/packages/userData/userData.ts b/src/packages/userData/userData.ts index 9a4a41ac..c37a554a 100644 --- a/src/packages/userData/userData.ts +++ b/src/packages/userData/userData.ts @@ -34,7 +34,7 @@ export class UserData extends Caller { public async getUserPublicKey( inputs: ApiUserDataOwnedBody - ): Promise { + ): Promise { return this.fetchApi( `public-key`, inputs