Skip to content

Commit

Permalink
update: update CoW swap to zero fee amount
Browse files Browse the repository at this point in the history
  • Loading branch information
berteotti committed Mar 7, 2024
1 parent 91e4f23 commit 4e93411
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/pages/Swap/LimitOrderBox/api/cow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Signer } from '@ethersproject/abstract-signer'
import { ChainId, CoWTrade, GPv2SupportedChainId } from '@swapr/sdk'
import { ChainId, CoWTrade, GPv2SupportedChainId, JSBI } from '@swapr/sdk'

import contractNetworks from '@cowprotocol/contracts/networks.json'
import { OrderKind as CoWOrderKind } from '@cowprotocol/cow-sdk'
Expand Down Expand Up @@ -86,14 +86,25 @@ export async function signLimitOrder({
})

// Get feeAmount from CoW
const { buyAmount, buyToken, receiverAddress, feeAmount, expiresAt, sellAmount, sellToken, kind } = order
const {
buyAmount,
buyToken,
receiverAddress,
feeAmount,
expiresAt,
sellAmount: quoteSellAmount,
sellToken,
kind,
} = order

const sellAmount = JSBI.add(JSBI.BigInt(quoteSellAmount.toString()), JSBI.BigInt(feeAmount.toString())).toString()

const signedResult = await cowSdk.signOrder({
buyAmount,
buyToken,
sellAmount,
sellToken,
feeAmount, // from CoW APIs
feeAmount: '0', // from CoW APIs
receiver: receiverAddress, // the account that will receive the order
validTo: expiresAt,
kind: kind === LimitOrderKind.BUY ? CoWOrderKind.BUY : CoWOrderKind.SELL,
Expand All @@ -118,10 +129,15 @@ export async function createCoWLimitOrder({ order, signer, chainId }: GetLimitOr
appDataHash: getAppDataIPFSHash(chainId),
})

const sellAmount = JSBI.add(
JSBI.BigInt(order.sellAmount.toString()),
JSBI.BigInt(order.feeAmount.toString())
).toString()

const cowUnsignedOrder: Omit<UnsignedOrder, 'appData'> = {
buyAmount: order.buyAmount,
buyToken: order.buyToken,
sellAmount: order.sellAmount,
sellAmount: sellAmount,
sellToken: order.sellToken,
feeAmount: '0', // from CoW APIs
receiver: order.receiverAddress, // the account that will receive the order
Expand Down

0 comments on commit 4e93411

Please sign in to comment.