• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cowprotocol / cow-sdk / 13048394494

30 Jan 2025 08:29AM UTC coverage: 78.102% (-0.7%) from 78.851%
13048394494

push

github

shoom3301
fix(trading-sdk): fix eth-flow

287 of 401 branches covered (71.57%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 2 files covered. (0.0%)

8 existing lines in 2 files now uncovered.

651 of 800 relevant lines covered (81.38%)

19.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/src/trading/getEthFlowTransaction.ts
1
import { Signer } from 'ethers'
2
import { LimitTradeParametersFromQuote, TransactionParams } from './types'
3
import { calculateUniqueOrderId, EthFlowOrderExistsCallback } from './calculateUniqueOrderId'
4
import { getOrderToSign } from './getOrderToSign'
5
import { type EthFlow, EthFlow__factory } from '../common/generated'
6
import {
7
  BARN_ETH_FLOW_ADDRESSES,
8
  CowEnv,
9
  ETH_FLOW_ADDRESSES,
10
  SupportedChainId,
11
  WRAPPED_NATIVE_CURRENCIES,
12
} from '../common'
13
import { GAS_LIMIT_DEFAULT } from './consts'
14
import type { EthFlowOrder } from '../common/generated/EthFlow'
15
import { calculateGasMargin } from './utils'
16

17
export async function getEthFlowTransaction(
18
  signer: Signer,
19
  appDataKeccak256: string,
20
  _params: LimitTradeParametersFromQuote,
21
  chainId: SupportedChainId,
22
  networkCostsAmount = '0',
3✔
23
  checkEthFlowOrderExists?: EthFlowOrderExistsCallback
24
): Promise<{ orderId: string; transaction: TransactionParams }> {
25
  const from = await signer.getAddress()
3✔
26

27
  const params = {
3✔
28
    ..._params,
29
    sellToken: WRAPPED_NATIVE_CURRENCIES[chainId],
30
  }
31
  const { quoteId } = params
3✔
32

33
  const contract = getEthFlowContract(chainId, signer, params.env)
3✔
34
  const orderToSign = getOrderToSign({ from, networkCostsAmount }, params, appDataKeccak256)
3✔
35
  const orderId = await calculateUniqueOrderId(chainId, orderToSign, checkEthFlowOrderExists, params.env)
3✔
36

37
  const ethOrderParams: EthFlowOrder.DataStruct = {
3✔
38
    ...orderToSign,
39
    quoteId,
40
    appData: appDataKeccak256,
41
    validTo: orderToSign.validTo.toString(),
42
  }
43

44
  const estimatedGas = await contract.estimateGas
3✔
45
    .createOrder(ethOrderParams, { value: orderToSign.sellAmount })
46
    .then((res) => BigInt(res.toHexString()))
3✔
47
    .catch((error) => {
UNCOV
48
      console.error(error)
×
49

UNCOV
50
      return GAS_LIMIT_DEFAULT
×
51
    })
52

53
  const data = contract.interface.encodeFunctionData('createOrder', [ethOrderParams])
3✔
54

55
  return {
3✔
56
    orderId,
57
    transaction: {
58
      data,
59
      gasLimit: '0x' + calculateGasMargin(estimatedGas).toString(16),
60
      to: contract.address,
61
      value: '0x' + BigInt(orderToSign.sellAmount).toString(16),
62
    },
63
  }
64
}
65

66
function getEthFlowContract(chainId: SupportedChainId, signer: Signer, env?: CowEnv): EthFlow {
67
  return EthFlow__factory.connect((env === 'staging' ? BARN_ETH_FLOW_ADDRESSES : ETH_FLOW_ADDRESSES)[chainId], signer)
3!
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc