Skip to content

Commit

Permalink
chore: review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor-Aftermath committed Dec 30, 2024
1 parent 22ff425 commit b905b13
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 133 deletions.
2 changes: 0 additions & 2 deletions src/general/utils/casting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,7 +37,6 @@ export class Casting {
public static farms = FarmsApiCasting;
public static nfts = NftsApiCasting;
public static dca = DcaApiCasting;
public static limit = LimitOrdersApiCasting;

// =========================================================================
// Constants
Expand Down
20 changes: 3 additions & 17 deletions src/packages/limitOrders/api/limitOrdersApi.ts
Original file line number Diff line number Diff line change
@@ -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
// =========================================================================
Expand Down Expand Up @@ -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"
);
}
34 changes: 0 additions & 34 deletions src/packages/limitOrders/api/limitOrdersApiCasting.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/packages/limitOrders/api/limitOrdersApiCastingTypes.ts

This file was deleted.

52 changes: 36 additions & 16 deletions src/packages/limitOrders/limitOrders.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -59,10 +59,10 @@ export class LimitOrders extends Caller {
*/

public async getPastLimitOrders(inputs: { walletAddress: SuiAddress }) {
return this.fetchApi<LimitOrderObject[], ApiLimitOrdersOwnedBody>(
"orders/past",
inputs
);
return this.fetchApi<
LimitOrderObject[],
ApiLimitOrdersPastOrdersOwnedBody
>("orders/past", inputs);
}

// =========================================================================
Expand All @@ -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<Transaction> } A promise that resolves with the API transaction.
*/

public async getCreateLimitOrderTx(
inputs: ApiLimitOrdersTransactionForCreateOrderBody
inputs: ApiLimitOrdersCreateOrderTransactionBody
): Promise<Transaction> {
return this.fetchApiTransaction<ApiLimitOrdersTransactionForCreateOrderBody>(
return this.fetchApiTransaction<ApiLimitOrdersCreateOrderTransactionBody>(
"transactions/create-order",
inputs
);
Expand All @@ -91,12 +91,12 @@ export class LimitOrders extends Caller {
*/

public async cancelLimitOrder(
inputs: ApiLimitOrdersTransactionForCancelOrderBody
inputs: ApiLimitOrdersCancelOrderTransactionBody
): Promise<boolean> {
return this.fetchApi<
boolean,
ApiLimitOrdersTransactionForCancelOrderBody
>(`interactions/cancel-order`, inputs);
return this.fetchApi<boolean, ApiLimitOrdersCancelOrderTransactionBody>(
`interactions/cancel-order`,
inputs
);
}

// =========================================================================
Expand All @@ -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");
}
}
26 changes: 5 additions & 21 deletions src/packages/limitOrders/limitOrdersTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface LimitOrdersIntegratorFeeData {
// Initialize Order Transaction
// =========================================================================

export interface ApiLimitOrdersTransactionForCreateOrderBody {
export interface ApiLimitOrdersCreateOrderTransactionBody {
walletAddress: SuiAddress;
allocateCoinType: CoinType;
allocateCoinAmount: Balance;
Expand All @@ -36,7 +36,7 @@ export interface ApiLimitOrdersTransactionForCreateOrderBody {
// Cancel Order Transaction
// =========================================================================

export interface ApiLimitOrdersTransactionForCancelOrderBody {
export interface ApiLimitOrdersCancelOrderTransactionBody {
walletAddress: SuiAddress;
bytes: string;
signature: string;
Expand All @@ -46,7 +46,7 @@ export interface ApiLimitOrdersTransactionForCancelOrderBody {
// Limit Order Fetch
// =========================================================================

export type LimitOrdersIndexerOrderStatus =
export type LimitOrdersOrderStatus =
| "Active"
| "Canceled"
| "Failed"
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/packages/userData/userData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class UserData extends Caller {

public async getUserPublicKey(
inputs: ApiUserDataOwnedBody
): Promise<string | undefined | null> {
): Promise<string | undefined | "None"> {
return this.fetchApi<string | undefined, ApiUserDataOwnedBody>(
`public-key`,
inputs
Expand Down

0 comments on commit b905b13

Please sign in to comment.