Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: actions: getOpenOrders, getOrderMetadata: use new response shapes #99

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/core/src/actions/getOpenOrders.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { ADMIN_OPEN_ORDERS_ROUTE } from '../constants.js'
import type { Config } from '../createConfig.js'
import { BaseError, type BaseErrorType } from '../errors/base.js'
import type { OpenOrder } from '../types/order.js'
import { getRelayerWithAdmin } from '../utils/http.js'

export type GetOpenOrdersParams = {
matchingPool?: string
includeFillable?: boolean
}

export type GetOpenOrdersReturnType = Map<string, OpenOrder>
export type GetOpenOrdersReturnType = string[]

export type GetOpenOrdersErrorType = BaseErrorType

Expand All @@ -25,14 +23,10 @@ export async function getOpenOrders(
url.searchParams.set('matching_pool', parameters.matchingPool)
}

if (parameters.includeFillable) {
url.searchParams.set('include_fillable', String(true))
}

const res = await getRelayerWithAdmin(config, url.toString())

if (!res.orders) {
throw new BaseError('No orders found')
}
return new Map(res.orders.map((order: OpenOrder) => [order.order.id, order]))
return res.orders
}
20 changes: 13 additions & 7 deletions packages/core/src/actions/getOrderMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { ADMIN_ORDER_METADATA_ROUTE } from '../constants.js'
import type { Config } from '../createConfig.js'
import { BaseError, type BaseErrorType } from '../errors/base.js'
import type { OrderMetadata } from '../types/order.js'
import type { AdminOrderMetadata } from '../types/order.js'
import { getRelayerWithAdmin } from '../utils/http.js'

export type GetOrderMetadataParameters = { id: string }
export type GetOrderMetadataParameters = {
id: string
includeFillable?: boolean
}

export type GetOrderMetadataReturnType = OrderMetadata
export type GetOrderMetadataReturnType = AdminOrderMetadata

export type GetOrderMetadataErrorType = BaseErrorType

Expand All @@ -17,10 +20,13 @@ export async function getOrderMetadata(
const { id } = parameters
const { getRelayerBaseUrl } = config

const res = await getRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_ORDER_METADATA_ROUTE(id)),
)
const url = new URL(getRelayerBaseUrl(ADMIN_ORDER_METADATA_ROUTE(id)))

if (parameters.includeFillable) {
url.searchParams.set('include_fillable', String(true))
}

const res = await getRelayerWithAdmin(config, url.toString())

if (!res.order) {
throw new BaseError('No order found')
Expand Down
31 changes: 31 additions & 0 deletions packages/core/src/actions/getWalletOrderIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ADMIN_WALLET_ORDER_IDS_ROUTE } from '../constants.js'
import type { Config } from '../createConfig.js'
import { BaseError, type BaseErrorType } from '../errors/base.js'
import { getRelayerWithAdmin } from '../utils/http.js'

export type GetWalletOrderIdsParameters = {
id: string
}

export type GetWalletOrderIdsReturnType = string[]

export type GetWalletOrderIdsErrorType = BaseErrorType

export async function getWalletOrderIds(
config: Config,
parameters: GetWalletOrderIdsParameters,
): Promise<GetWalletOrderIdsReturnType> {
const { id } = parameters
const { getRelayerBaseUrl } = config

const res = await getRelayerWithAdmin(
config,
getRelayerBaseUrl(ADMIN_WALLET_ORDER_IDS_ROUTE(id)),
)

if (!res.order_ids) {
throw new BaseError('No orders found')
}

return res.order_ids
}
7 changes: 7 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ export const ADMIN_ASSIGN_ORDER_ROUTE = (
// Route to get the matching pool for an order
export const ADMIN_GET_ORDER_MATCHING_POOL_ROUTE = (order_id: string) =>
`/admin/orders/${order_id}/matching-pool`
// Route to get all the order IDs for a given wallet
export const ADMIN_WALLET_ORDER_IDS_ROUTE = (wallet_id: string) =>
`/admin/wallet/${wallet_id}/order-ids`

// The admin wallet updates topic, streams opaque event indicating
// updates for all wallets
export const WS_ADMIN_WALLET_UPDATES_ROUTE = '/v0/admin/wallet-updates'

////////////////////////////////////////////////////////////////////////////////
// Price Reporter
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/exports/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ export {
getWalletId,
} from '../actions/getWalletId.js'

export {
type GetWalletOrderIdsParameters as GetWalletOrdersParameters,
type GetWalletOrderIdsReturnType as GetWalletOrdersReturnType,
type GetWalletOrderIdsErrorType as GetWalletOrdersErrorType,
getWalletOrderIds,
} from '../actions/getWalletOrderIds.js'

export {
type LookupWalletReturnType,
lookupWallet,
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ export {
getWalletId,
} from '../actions/getWalletId.js'

export {
type GetWalletOrderIdsParameters as GetWalletOrdersParameters,
type GetWalletOrderIdsReturnType as GetWalletOrdersReturnType,
type GetWalletOrderIdsErrorType as GetWalletOrdersErrorType,
getWalletOrderIds,
} from '../actions/getWalletOrderIds.js'

export {
type LookupWalletReturnType,
lookupWallet,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type TimestampedPrice = {
timestamp: bigint
}

export type OpenOrder = {
export type AdminOrderMetadata = {
order: OrderMetadata
wallet_id: string
fillable?: bigint
Expand Down
Loading