Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Moving helper functions from dex-react (#69)
Browse files Browse the repository at this point in the history
* Moving assert form dex-react

* Added isNeverExpiresOrder function
  • Loading branch information
alfetopito committed Jan 24, 2020
1 parent 1739ff1 commit 5d90fa6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ export const FEE_PERCENTAGE = (1 / FEE_DENOMINATOR) * 100 // syntatic sugar for

// Amount for an order to be considered unlimited, from contract's point of view: https://github.com/gnosis/dex-contracts/blob/master/contracts/BatchExchange.sol#L35
export const UNLIMITED_ORDER_AMOUNT = TWO.pow(new BN(128)).sub(ONE)

// Batch ID of orders without expiration date set
export const MAX_BATCH_ID = 2 ** 32 - 1
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './time'
export * from './ethereum'
export * from './format'
export * from './orders'
export * from './misc'
7 changes: 7 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AssertionError } from 'assert'

export function assert<T>(val: T, message: string): asserts val is NonNullable<T> {
if (!val) {
throw new AssertionError({ message })
}
}
13 changes: 13 additions & 0 deletions src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { MAX_BATCH_ID } from 'const'

/**
* Epoch in seconds
*/
export function getEpoch(): number {
return Math.floor(Date.now() / 1000)
}

/**
* Checks whether batchId is `never expires`
* Using the convention which the fronted creates orders with expiration date set
* to max uint32 when placing orders active indefinitely.
*
* @param batchId The expiration batch id to check
*/
export function isNeverExpiresOrder(batchId: number): boolean {
return MAX_BATCH_ID === batchId
}

0 comments on commit 5d90fa6

Please sign in to comment.