Skip to content

Commit

Permalink
[SWA-46] Add LimitOder type
Browse files Browse the repository at this point in the history
  • Loading branch information
Wixzi committed Jun 20, 2023
1 parent a619f5e commit ce24f22
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/services/LimitOrders/CoW/CoW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class CoW extends LimitOrderBase {
...this.limitOrder,
buyAmount,
}

this.logger.log(`Buy Amount Change ${this.sellAmount.raw.toString()}`)
}

Expand Down Expand Up @@ -87,7 +88,7 @@ export class CoW extends LimitOrderBase {
if (!sellToken || !buyToken) {
return
}
let tokenAmount = this.kind === 'sell' ? this.sellAmount : this.buyAmount
let tokenAmount = this.kind === Kind.Sell ? this.sellAmount : this.buyAmount
if (!tokenAmount) {
return
}
Expand All @@ -113,7 +114,7 @@ export class CoW extends LimitOrderBase {
const signer = this.provider?.getSigner()
const chainId = this.activeChainId
const order = limitOrder ?? this.limitOrder
const expiresAt = dayjs().add(this.expiresAt, 'minutes').unix()
const expiresAt = dayjs().add(this.expiresAt, this.expiresAtUnit).unix()
const kind = this.kind
if (!signer || !chainId || !limitOrder || !expiresAt || !kind) {
throw new Error('Missing required params')
Expand Down
57 changes: 55 additions & 2 deletions src/services/LimitOrders/LimitOrder.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export enum OrderExpiresInUnit {
Days = 'days',
}
export enum Kind {
Buy = 'buy',
Sell = 'sell',
Buy = 'Buy',
Sell = 'Sell',
}

export interface LimitOrderBaseConstructor {
Expand All @@ -40,3 +40,56 @@ export interface WalletData {
provider: Web3Provider
activeChainId: ChainId
}

type EVMAddress = string

export interface LimitOrder {
/**
* The user Address.
*/
userAddress: EVMAddress
/**
* receiver Address.
*/
receiverAddress: EVMAddress
/**
* The sell token Address. The sellToken cannot be native token of the network.
*/
sellToken: EVMAddress
/**
* The buy token address. The native token of the network is represented by `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`
*/
buyToken: EVMAddress
/**
* The sell amount.
*/
sellAmount: string
/**
* The buy amount.
*/
buyAmount: string
/**
* Fee amount.
*/
feeAmount: string
/**
* The buy amount.
*/
limitPrice: string
/**
* Order timestamp as epoh seconds.
*/
createdAt: number
/**
* Order expiration time in seconds.
*/
expiresAt: number
/**
* Order kind
*/
kind: Kind
/**
* Quote Id
*/
quoteId?: number | null
}

0 comments on commit ce24f22

Please sign in to comment.