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

cowprotocol / cow-sdk / 6027054998

30 Aug 2023 03:39PM UTC coverage: 72.617% (-3.8%) from 76.379%
6027054998

Pull #153

github

anxolin
Decode cabinet and verify its value
Pull Request #153: Handle Expired TWAP and not started TWAP

185 of 273 branches covered (0.0%)

Branch coverage included in aggregate %.

31 of 31 new or added lines in 3 files covered. (100.0%)

356 of 472 relevant lines covered (75.42%)

19.43 hits per line

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

50.0
/src/composable/utils.ts
1
import { utils, providers } from 'ethers'
2
import {
3
  COMPOSABLE_COW_CONTRACT_ADDRESS,
4
  EXTENSIBLE_FALLBACK_HANDLER_CONTRACT_ADDRESS,
5
  SupportedChainId,
6
} from '../common'
7
import { ExtensibleFallbackHandler__factory } from './generated'
8
import { BlockInfo, ConditionalOrderParams } from './types'
9

10
// Define the ABI tuple for the ConditionalOrderParams struct
11
export const CONDITIONAL_ORDER_PARAMS_ABI = ['tuple(address handler, bytes32 salt, bytes staticInput)']
4✔
12

13
export function isExtensibleFallbackHandler(handler: string, chainId: SupportedChainId): boolean {
14
  return handler === EXTENSIBLE_FALLBACK_HANDLER_CONTRACT_ADDRESS[chainId]
×
15
}
16

17
export function isComposableCow(handler: string, chainId: SupportedChainId): boolean {
18
  return handler === COMPOSABLE_COW_CONTRACT_ADDRESS[chainId]
×
19
}
20

21
export async function getDomainVerifier(
22
  safe: string,
23
  domain: string,
24
  chainId: SupportedChainId,
25
  provider: providers.Provider
26
): Promise<string> {
27
  const contract = ExtensibleFallbackHandler__factory.connect(
×
28
    EXTENSIBLE_FALLBACK_HANDLER_CONTRACT_ADDRESS[chainId],
29
    provider
30
  )
31
  return await contract.callStatic.domainVerifiers(safe, domain)
×
32
}
33

34
export function createSetDomainVerifierTx(domain: string, verifier: string): string {
35
  return ExtensibleFallbackHandler__factory.createInterface().encodeFunctionData('setDomainVerifier', [
×
36
    domain,
37
    verifier,
38
  ])
39
}
40

41
/**
42
 * Encode the `ConditionalOrderParams` for the conditional order.
43
 *
44
 * @param params The `ConditionalOrderParams` struct representing the conditional order as taken from a merkle tree.
45
 * @returns The ABI-encoded conditional order.
46
 * @see ConditionalOrderParams
47
 */
48
export function encodeParams(params: ConditionalOrderParams): string {
49
  return utils.defaultAbiCoder.encode(CONDITIONAL_ORDER_PARAMS_ABI, [params])
52✔
50
}
51

52
/**
53
 * Decode the `ConditionalOrderParams` for the conditional order.
54
 *
55
 * @param encoded The encoded conditional order.
56
 * @returns The decoded conditional order.
57
 */
58
export function decodeParams(encoded: string): ConditionalOrderParams {
59
  const { handler, salt, staticInput } = utils.defaultAbiCoder.decode(CONDITIONAL_ORDER_PARAMS_ABI, encoded)[0]
7✔
60
  return { handler, salt, staticInput }
4✔
61
}
62

63
/**
64
 * Helper method for validating ABI types.
65
 * @param types ABI types to validate against.
66
 * @param values The values to validate.
67
 * @returns {boolean} Whether the values are valid ABI for the given types.
68
 */
69
export function isValidAbi(types: readonly (string | utils.ParamType)[], values: any[]): boolean {
70
  try {
45✔
71
    utils.defaultAbiCoder.encode(types, values)
45✔
72
  } catch (e) {
73
    return false
5✔
74
  }
75
  return true
40✔
76
}
77

78
export async function getBlockInfo(provider: providers.Provider): Promise<BlockInfo> {
79
  const block = await provider.getBlock('latest')
×
80

81
  return {
×
82
    blockNumber: block.number,
83
    blockTimestamp: block.timestamp,
84
  }
85
}
86

87
export function formatEpoch(epoch: number): string {
88
  return new Date(epoch * 1000).toISOString()
×
89
}
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