Skip to content

Commit

Permalink
Merge pull request #28 from mangrovedao/feat/orderType
Browse files Browse the repository at this point in the history
feat: order label
  • Loading branch information
maxencerb authored May 7, 2024
2 parents bc5bf0a + 94fdc5d commit da6ee36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/few-plants-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mangrovedao/mgv": patch
---

Add orderLabel function to lib to get the label of an order
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export {
rawLimitOrderResultFromLogs,
limitOrderResultFromLogs,
getDefaultLimitOrderGasreq,
orderLabel,
} from './limit-order.js'

// local
Expand Down
16 changes: 15 additions & 1 deletion src/lib/limit-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
MarketParams,
} from '../types/index.js'
import type { OLKey } from '../types/lib.js'
import { BS } from './enums.js'
import { BS, Order } from './enums.js'
import { mgvEventsABI, rawMarketOrderResultFromLogs } from './market-order.js'
import { flip, hash } from './ol-key.js'
import { inboundFromOutbound } from './tick.js'
Expand Down Expand Up @@ -105,3 +105,17 @@ export type GetDefaultLimitOrderGasreqParams = {
export function getDefaultLimitOrderGasreq(): bigint {
return 250_000n
}

const _orderLabel = {
[Order.GTC]: 'Good Til Cancelled',
[Order.GTCE]: 'Good Til Cancelled Enforced',
[Order.PO]: 'Post Only',
[Order.IOC]: 'Immediate Or Cancel',
[Order.FOK]: 'Fill Or Kill',
} as const satisfies { [key in Order]: string }

export function orderLabel<TOrder extends Order = Order>(
order: TOrder,
): (typeof _orderLabel)[TOrder] {
return _orderLabel[order]
}

0 comments on commit da6ee36

Please sign in to comment.