@cowprotocol/sdk-contracts-ts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1317 @@
1
+ import { Bytes, TypedDataDomain, SignerLike, TypedDataTypes, BigIntish, AbstractProviderAdapter, SignatureLike, Abi, Address, Provider, Signer, AbstractSigner } from '@cowprotocol/sdk-common';
2
+
3
+ /**
4
+ * Value returned by a call to `isValidSignature` if the signature was verified
5
+ * successfully. The value is defined in the EIP-1271 standard as:
6
+ * bytes4(keccak256("isValidSignature(bytes32,bytes)"))
7
+ */
8
+ declare const EIP1271_MAGICVALUE = "0x1626ba7e";
9
+ /**
10
+ * Marker value indicating a presignature is set.
11
+ * const PRE_SIGNED = ethersV5.utils.id("GPv2Signing.Scheme.PreSign");
12
+ */
13
+ declare const PRE_SIGNED = "0xf59c009283ff87aa78203fc4d9c2df025ee851130fb69cc3e068941f6b5e2d6f";
14
+ /**
15
+ * EIP-1271 signature data.
16
+ */
17
+ interface Eip1271SignatureData {
18
+ /**
19
+ * The verifying contract address.
20
+ */
21
+ verifier: string;
22
+ /**
23
+ * The arbitrary signature data used for verification.
24
+ */
25
+ signature: Bytes;
26
+ }
27
+ /**
28
+ * EIP-1271 signature of an order.
29
+ */
30
+ interface Eip1271Signature {
31
+ /**
32
+ * The signing scheme used in the signature.
33
+ */
34
+ scheme: SigningScheme.EIP1271;
35
+ /**
36
+ * The signature data.
37
+ */
38
+ data: Eip1271SignatureData;
39
+ }
40
+ /**
41
+ * Signature data for a pre-signed order.
42
+ */
43
+ interface PreSignSignature {
44
+ /**
45
+ * The signing scheme used in the signature.
46
+ */
47
+ scheme: SigningScheme.PRESIGN;
48
+ /**
49
+ * The address of the signer.
50
+ */
51
+ data: string;
52
+ }
53
+ declare function ecdsaSignTypedData(scheme: EcdsaSigningScheme, domain: TypedDataDomain, types: TypedDataTypes, data: Record<string, unknown>, owner?: SignerLike): Promise<string>;
54
+ /**
55
+ * Returns the signature for the specified order with the signing scheme encoded
56
+ * into the signature.
57
+ *
58
+ * @param domain The domain to sign the order for. This is used by the smart
59
+ * contract to ensure orders can't be replayed across different applications,
60
+ * but also different deployments (as the contract chain ID and address are
61
+ * mixed into to the domain value).
62
+ * @param owner The owner for the order used to sign.
63
+ * @param scheme The signing scheme to use. See {@link SigningScheme} for more
64
+ * details.
65
+ * @param order The order to sign.
66
+ *
67
+ * @return Encoded signature including signing scheme for the order.
68
+ */
69
+ declare function signOrder(domain: TypedDataDomain, order: Order, scheme: EcdsaSigningScheme, owner?: SignerLike): Promise<EcdsaSignature>;
70
+ /**
71
+ * Encodes the necessary data required for the Gnosis Protocol contracts to
72
+ * verify an EIP-1271 signature.
73
+ *
74
+ * @param signature The EIP-1271 signature data to encode.
75
+ */
76
+ declare function encodeEip1271SignatureData({ verifier, signature }: Eip1271SignatureData): string;
77
+ /**
78
+ * Decodes a GPv2 EIP-1271-type signature into the actual EIP-1271 signature
79
+ * and the verifier contract.
80
+ *
81
+ * @param signature The EIP-1271 signature data to decode.
82
+ * @returns decodedSignature The decoded signature object, composed of an
83
+ * EIP-1271 signature and a verifier.
84
+ */
85
+ declare function decodeEip1271SignatureData(signature: Bytes): Eip1271SignatureData;
86
+ /**
87
+ * Returns the signature for cancelling a single order with the specified
88
+ * signing scheme.
89
+ *
90
+ * @param domain The domain to sign the cancellation.
91
+ * @param orderUid The unique identifier of the order being cancelled.
92
+ * @param scheme The signing scheme to use. See {@link SigningScheme} for more
93
+ * details.
94
+ * @param owner The owner for the order used to sign.
95
+ *
96
+ * @return Encoded signature including signing scheme for the cancellation.
97
+ */
98
+ declare function signOrderCancellation(domain: TypedDataDomain, orderUid: Bytes, scheme: EcdsaSigningScheme, owner?: SignerLike): Promise<EcdsaSignature>;
99
+ /**
100
+ * Returns the signature for cancelling multiple orders by UID with the
101
+ * specified signing scheme.
102
+ *
103
+ * @param domain The domain to sign the cancellation.
104
+ * @param orderUids The unique identifiers of the orders to cancel.
105
+ * @param scheme The signing scheme to use. See {@link SigningScheme} for more
106
+ * details.
107
+ * @param owner The owner for the order used to sign.
108
+ *
109
+ * @return Encoded signature including signing scheme for the cancellation.
110
+ */
111
+ declare function signOrderCancellations(domain: TypedDataDomain, orderUids: Bytes[], scheme: EcdsaSigningScheme, owner?: SignerLike): Promise<EcdsaSignature>;
112
+
113
+ /**
114
+ * Gnosis Protocol v2 interaction data.
115
+ */
116
+ interface Interaction {
117
+ /**
118
+ * Address of the smart contract to be called in this interaction.
119
+ */
120
+ target: string;
121
+ /**
122
+ * Call value in wei for the interaction, allowing Ether to be sent.
123
+ */
124
+ value: BigIntish;
125
+ /**
126
+ * Call data used in the interaction with a smart contract.
127
+ */
128
+ callData: Bytes;
129
+ }
130
+ type InteractionLike = Pick<Interaction, 'target'> & Partial<Interaction>;
131
+ /**
132
+ * Normalizes interaction data so that it is ready to be be ABI encoded.
133
+ *
134
+ * @param interaction The interaction to normalize.
135
+ * @return The normalized interaction.
136
+ */
137
+ declare function normalizeInteraction(interaction: InteractionLike): Interaction;
138
+ /**
139
+ * Normalizes data for many interactions so that they can be ABI encoded. This
140
+ * calls [`normalizeInteraction`] for each interaction.
141
+ *
142
+ * @param interactions The interactions to normalize.
143
+ * @return The normalized interactions.
144
+ */
145
+ declare function normalizeInteractions(interactions: InteractionLike[]): Interaction[];
146
+
147
+ /**
148
+ * The stage an interaction should be executed in.
149
+ */
150
+ declare enum InteractionStage {
151
+ /**
152
+ * A pre-settlement intraction.
153
+ *
154
+ * The interaction will be executed before any trading occurs. This can be
155
+ * used, for example, to perform as EIP-2612 `permit` call for a user trading
156
+ * in the current settlement.
157
+ */
158
+ PRE = 0,
159
+ /**
160
+ * An intra-settlement interaction.
161
+ *
162
+ * The interaction will be executed after all trade sell amounts are
163
+ * transferred into the settlement contract, but before the buy amounts are
164
+ * transferred out to the traders. This can be used, for example, to interact
165
+ * with on-chain AMMs.
166
+ */
167
+ INTRA = 1,
168
+ /**
169
+ * A post-settlement interaction.
170
+ *
171
+ * The interaction will be executed after all trading has completed.
172
+ */
173
+ POST = 2
174
+ }
175
+ /**
176
+ * Gnosis Protocol v2 trade flags.
177
+ */
178
+ interface TradeFlags extends OrderFlags {
179
+ /**
180
+ * The signing scheme used to encode the signature.
181
+ */
182
+ signingScheme: SigningScheme;
183
+ }
184
+ /**
185
+ * Details representing how an order was executed.
186
+ */
187
+ interface TradeExecution {
188
+ /**
189
+ * The executed trade amount.
190
+ *
191
+ * How this amount is used by the settlement contract depends on the order
192
+ * flags:
193
+ * - Partially fillable sell orders: the amount of sell tokens to trade.
194
+ * - Partially fillable buy orders: the amount of buy tokens to trade.
195
+ * - Fill-or-kill orders: this value is ignored.
196
+ */
197
+ executedAmount: BigIntish;
198
+ }
199
+ /**
200
+ * Order refund data.
201
+ *
202
+ * Note: after the London hardfork (specifically the introduction of EIP-3529)
203
+ * order refunds have become meaningless as the refunded amount is less than the
204
+ * gas cost of triggering the refund. The logic surrounding this feature is kept
205
+ * in order to keep full test coverage and in case the value of a refund will be
206
+ * increased again in the future. However, order refunds should not be used in
207
+ * an actual settlement.
208
+ */
209
+ interface OrderRefunds {
210
+ /** Refund storage used for order filled amount */
211
+ filledAmounts: Bytes[];
212
+ /** Refund storage used for order pre-signature */
213
+ preSignatures: Bytes[];
214
+ }
215
+ /**
216
+ * Table mapping token addresses to their respective clearing prices.
217
+ */
218
+ type Prices = Record<string, BigIntish | undefined>;
219
+ /**
220
+ * Encoded settlement parameters.
221
+ */
222
+ type EncodedSettlement = [
223
+ /** Tokens. */
224
+ string[],
225
+ /** Clearing prices. */
226
+ BigIntish[],
227
+ /** Encoded trades. */
228
+ Trade[],
229
+ /** Encoded interactions. */
230
+ [
231
+ Interaction[],
232
+ Interaction[],
233
+ Interaction[]
234
+ ]
235
+ ];
236
+ /**
237
+ * An object listing all flag options in order along with their bit offset.
238
+ */
239
+ declare const FLAG_MASKS: {
240
+ readonly kind: {
241
+ readonly offset: 0;
242
+ readonly options: readonly [OrderKind.SELL, OrderKind.BUY];
243
+ };
244
+ readonly partiallyFillable: {
245
+ readonly offset: 1;
246
+ readonly options: readonly [false, true];
247
+ };
248
+ readonly sellTokenBalance: {
249
+ readonly offset: 2;
250
+ readonly options: readonly [OrderBalance.ERC20, undefined, OrderBalance.EXTERNAL, OrderBalance.INTERNAL];
251
+ };
252
+ readonly buyTokenBalance: {
253
+ readonly offset: 4;
254
+ readonly options: readonly [OrderBalance.ERC20, OrderBalance.INTERNAL];
255
+ };
256
+ readonly signingScheme: {
257
+ readonly offset: 5;
258
+ readonly options: readonly [SigningScheme.EIP712, SigningScheme.ETHSIGN, SigningScheme.EIP1271, SigningScheme.PRESIGN];
259
+ };
260
+ };
261
+ type FlagKey = keyof typeof FLAG_MASKS;
262
+ type FlagOptions<K extends FlagKey> = (typeof FLAG_MASKS)[K]['options'];
263
+ type FlagValue<K extends FlagKey> = Exclude<FlagOptions<K>[number], undefined>;
264
+ /**
265
+ * Encodes signing scheme as a bitfield.
266
+ *
267
+ * @param scheme The signing scheme to encode.
268
+ * @return The bitfield result.
269
+ */
270
+ declare function encodeSigningScheme(scheme: SigningScheme): number;
271
+ /**
272
+ * Decodes signing scheme from a bitfield.
273
+ *
274
+ * @param flag The encoded order flag.
275
+ * @return The decoded signing scheme.
276
+ */
277
+ declare function decodeSigningScheme(flags: BigIntish): SigningScheme;
278
+ /**
279
+ * Encodes order flags as a bitfield.
280
+ *
281
+ * @param flags The order flags to encode.
282
+ * @return The bitfield result.
283
+ */
284
+ declare function encodeOrderFlags(flags: OrderFlags): number;
285
+ /**
286
+ * Decode order flags from a bitfield.
287
+ *
288
+ * @param flags The order flags encoded as a bitfield.
289
+ * @return The decoded order flags.
290
+ */
291
+ declare function decodeOrderFlags(flags: BigIntish): OrderFlags;
292
+ /**
293
+ * Encodes trade flags as a bitfield.
294
+ *
295
+ * @param flags The trade flags to encode.
296
+ * @return The bitfield result.
297
+ */
298
+ declare function encodeTradeFlags(flags: TradeFlags): number;
299
+ /**
300
+ * Decode trade flags from a bitfield.
301
+ *
302
+ * @param flags The trade flags encoded as a bitfield.
303
+ * @return The bitfield result.
304
+ */
305
+ declare function decodeTradeFlags(flags: BigIntish): TradeFlags;
306
+ declare function encodeSignatureData(sig: Signature): string;
307
+ declare function decodeSignatureOwner(domain: TypedDataDomain, order: Order, scheme: SigningScheme, sig: Bytes): string;
308
+ /**
309
+ * Encodes a trade to be used with the settlement contract.
310
+ */
311
+ declare function encodeTrade(tokens: TokenRegistry, order: Order, signature: Signature, { executedAmount }: TradeExecution): Trade;
312
+ /**
313
+ * A class used for tracking tokens when encoding settlements.
314
+ *
315
+ * This is used as settlement trades reference tokens by index instead of
316
+ * directly by address for multiple reasons:
317
+ * - Reduce encoding size of orders to save on `calldata` gas.
318
+ * - Direct access to a token's clearing price on settlement instead of
319
+ * requiring a search.
320
+ */
321
+ declare class TokenRegistry {
322
+ /**
323
+ * Creates a new TokenRegistry instance
324
+ *
325
+ * @param adapter Provider adapter implementation
326
+ */
327
+ constructor(adapter?: AbstractProviderAdapter);
328
+ private readonly _tokens;
329
+ private readonly _tokenMap;
330
+ /**
331
+ * Gets the array of token addresses currently stored in the registry.
332
+ */
333
+ get addresses(): string[];
334
+ /**
335
+ * Retrieves the token index for the specified token address. If the token is
336
+ * not in the registry, it will be added.
337
+ *
338
+ * @param token The token address to add to the registry.
339
+ * @return The token index.
340
+ */
341
+ index(token: string): number;
342
+ }
343
+ /**
344
+ * Encoder for CoW Protocol settlement transactions.
345
+ *
346
+ * This class provides methods to encode trades, interactions, and order refunds
347
+ * for CoW Protocol settlements. It maintains state for tokens, trades, and
348
+ * interactions across different execution stages.
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * const encoder = new SettlementEncoder(domain, adapter)
353
+ * encoder.encodeTrade(order, signature)
354
+ * const settlement = encoder.encodedSettlement(prices)
355
+ * ```
356
+ */
357
+ declare class SettlementEncoder {
358
+ readonly domain: TypedDataDomain;
359
+ private readonly _tokens;
360
+ private readonly _trades;
361
+ private readonly _interactions;
362
+ private readonly _orderRefunds;
363
+ /**
364
+ * Creates a new settlement encoder instance.
365
+ * @param domain Domain used for signing orders. See {@link signOrder} for
366
+ * more details.
367
+ */
368
+ constructor(domain: TypedDataDomain, adapter?: AbstractProviderAdapter);
369
+ /**
370
+ * Gets the array of token addresses used by the currently encoded orders.
371
+ */
372
+ get tokens(): string[];
373
+ /**
374
+ * Gets the encoded trades.
375
+ */
376
+ get trades(): Trade[];
377
+ /**
378
+ * Gets all encoded interactions for all stages.
379
+ *
380
+ * Note that order refund interactions are included as post-interactions.
381
+ */
382
+ get interactions(): [Interaction[], Interaction[], Interaction[]];
383
+ /**
384
+ * Gets the order refunds encoded as interactions.
385
+ */
386
+ get encodedOrderRefunds(): Interaction[];
387
+ /**
388
+ * Returns a clearing price vector for the current settlement tokens from the
389
+ * provided price map.
390
+ *
391
+ * @param prices The price map from token address to price.
392
+ * @return The price vector.
393
+ */
394
+ clearingPrices(prices: Prices): BigIntish[];
395
+ /**
396
+ * Encodes a trade from a signed order and executed amount, appending it to
397
+ * the `calldata` bytes that are being built.
398
+ *
399
+ * Additionally, if the order references new tokens that the encoder has not
400
+ * yet seen, they are added to the tokens array.
401
+ *
402
+ * @param order The order of the trade to encode.
403
+ * @param signature The signature for the order data.
404
+ * @param tradeExecution The execution details for the trade.
405
+ */
406
+ encodeTrade(order: Order, signature: Signature, { executedAmount }?: Partial<TradeExecution>): void;
407
+ /**
408
+ * Signs an order and encodes a trade with that order.
409
+ *
410
+ * @param order The order to sign for the trade.
411
+ * @param scheme The signing scheme to use. See {@link SigningScheme} for more
412
+ * details.
413
+ * @param tradeExecution The execution details for the trade.
414
+ * @param owner The externally owned account that should sign the order.
415
+ */
416
+ signEncodeTrade(order: Order, scheme: EcdsaSigningScheme, tradeExecution?: Partial<TradeExecution>, owner?: SignerLike): Promise<void>;
417
+ /**
418
+ * Encodes the input interaction in the packed format accepted by the smart
419
+ * contract and adds it to the interactions encoded so far.
420
+ *
421
+ * @param stage The stage the interaction should be executed.
422
+ * @param interaction The interaction to encode.
423
+ */
424
+ encodeInteraction(interaction: InteractionLike, stage?: InteractionStage): void;
425
+ /**
426
+ * Encodes order UIDs for gas refunds.
427
+ *
428
+ * @param settlement The address of the settlement contract.
429
+ * @param orderRefunds The order refunds to encode.
430
+ */
431
+ encodeOrderRefunds(orderRefunds: Partial<OrderRefunds>): void;
432
+ /**
433
+ * Returns the encoded settlement parameters.
434
+ */
435
+ encodedSettlement(prices: Prices): EncodedSettlement;
436
+ /**
437
+ * Returns an encoded settlement that exclusively performs setup interactions.
438
+ * This method can be used, for example, to set the settlement contract's
439
+ * allowances to other protocols it may interact with.
440
+ *
441
+ * @param interactions The list of setup interactions to encode.
442
+ */
443
+ static encodedSetup(...interactions: InteractionLike[]): EncodedSettlement;
444
+ }
445
+ /**
446
+ * Decodes an order from a settlement trade.
447
+ *
448
+ * @param trade The trade to decode into an order.
449
+ * @param tokens The list of token addresses as they appear in the settlement.
450
+ * @returns The decoded order.
451
+ */
452
+ declare function decodeOrder(trade: Trade, tokens: string[]): Order;
453
+
454
+ /**
455
+ * The signing scheme used to sign the order.
456
+ */
457
+ declare enum SigningScheme {
458
+ /**
459
+ * The EIP-712 typed data signing scheme. This is the preferred scheme as it
460
+ * provides more infomation to wallets performing the signature on the data
461
+ * being signed.
462
+ *
463
+ * <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md#definition-of-domainseparator>
464
+ */
465
+ EIP712 = 0,
466
+ /**
467
+ * Message signed using eth_sign RPC call.
468
+ */
469
+ ETHSIGN = 1,
470
+ /**
471
+ * Smart contract signatures as defined in EIP-1271.
472
+ *
473
+ * <https://eips.ethereum.org/EIPS/eip-1271>
474
+ */
475
+ EIP1271 = 2,
476
+ /**
477
+ * Pre-signed order.
478
+ */
479
+ PRESIGN = 3
480
+ }
481
+ type EcdsaSigningScheme = SigningScheme.EIP712 | SigningScheme.ETHSIGN;
482
+ /**
483
+ * The signature of an order.
484
+ */
485
+ type Signature = EcdsaSignature | Eip1271Signature | PreSignSignature;
486
+ /**
487
+ * ECDSA signature of an order.
488
+ */
489
+ interface EcdsaSignature {
490
+ /**
491
+ * The signing scheme used in the signature.
492
+ */
493
+ scheme: EcdsaSigningScheme;
494
+ /**
495
+ * The ECDSA signature.
496
+ */
497
+ data: SignatureLike;
498
+ }
499
+ /**
500
+ * Trade parameters used in a settlement.
501
+ */
502
+ type Trade = TradeExecution & Omit<NormalizedOrder, 'sellToken' | 'buyToken' | 'kind' | 'partiallyFillable' | 'sellTokenBalance' | 'buyTokenBalance'> & {
503
+ /**
504
+ * The index of the sell token in the settlement.
505
+ */
506
+ sellTokenIndex: BigIntish;
507
+ /**
508
+ * The index of the buy token in the settlement.
509
+ */
510
+ buyTokenIndex: BigIntish;
511
+ /**
512
+ * Encoded order flags.
513
+ */
514
+ flags: BigIntish;
515
+ /**
516
+ * Signature data.
517
+ */
518
+ signature: Bytes;
519
+ };
520
+ /**
521
+ * Gnosis Protocol v2 order data.
522
+ */
523
+ interface Order {
524
+ /**
525
+ * Sell token address.
526
+ */
527
+ sellToken: string;
528
+ /**
529
+ * Buy token address.
530
+ */
531
+ buyToken: string;
532
+ /**
533
+ * An optional address to receive the proceeds of the trade instead of the
534
+ * owner (i.e. the order signer).
535
+ */
536
+ receiver?: string;
537
+ /**
538
+ * The order sell amount.
539
+ *
540
+ * For fill or kill sell orders, this amount represents the exact sell amount
541
+ * that will be executed in the trade. For fill or kill buy orders, this
542
+ * amount represents the maximum sell amount that can be executed. For partial
543
+ * fill orders, this represents a component of the limit price fraction.
544
+ */
545
+ sellAmount: BigIntish;
546
+ /**
547
+ * The order buy amount.
548
+ *
549
+ * For fill or kill sell orders, this amount represents the minimum buy amount
550
+ * that can be executed in the trade. For fill or kill buy orders, this amount
551
+ * represents the exact buy amount that will be executed. For partial fill
552
+ * orders, this represents a component of the limit price fraction.
553
+ */
554
+ buyAmount: BigIntish;
555
+ /**
556
+ * The timestamp this order is valid until
557
+ */
558
+ validTo: Timestamp;
559
+ /**
560
+ * Arbitrary application specific data that can be added to an order. This can
561
+ * also be used to ensure uniqueness between two orders with otherwise the
562
+ * exact same parameters.
563
+ */
564
+ appData: HashLike;
565
+ /**
566
+ * Fee to give to the protocol.
567
+ */
568
+ feeAmount: BigIntish;
569
+ /**
570
+ * The order kind.
571
+ */
572
+ kind: OrderKind;
573
+ /**
574
+ * Specifies whether or not the order is partially fillable.
575
+ */
576
+ partiallyFillable: boolean;
577
+ /**
578
+ * Specifies how the sell token balance will be withdrawn. It can either be
579
+ * taken using ERC20 token allowances made directly to the Vault relayer
580
+ * (default) or using Balancer Vault internal or external balances.
581
+ */
582
+ sellTokenBalance?: OrderBalance;
583
+ /**
584
+ * Specifies how the buy token balance will be paid. It can either be paid
585
+ * directly in ERC20 tokens (default) in Balancer Vault internal balances.
586
+ */
587
+ buyTokenBalance?: OrderBalance;
588
+ }
589
+ /**
590
+ * Gnosis Protocol v2 order cancellation data.
591
+ */
592
+ interface OrderCancellations {
593
+ /**
594
+ * The unique identifier of the order to be cancelled.
595
+ */
596
+ orderUids: Bytes[];
597
+ }
598
+ /**
599
+ * Order kind.
600
+ */
601
+ declare enum OrderKind {
602
+ /**
603
+ * A sell order.
604
+ */
605
+ SELL = "sell",
606
+ /**
607
+ * A buy order.
608
+ */
609
+ BUY = "buy"
610
+ }
611
+
612
+ /**
613
+ * Marker address to indicate that an order is buying Ether.
614
+ *
615
+ * Note that this address is only has special meaning in the `buyToken` and will
616
+ * be treated as a ERC20 token address in the `sellToken` position, causing the
617
+ * settlement to revert.
618
+ */
619
+ declare const BUY_ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
620
+ /**
621
+ * Gnosis Protocol v2 order flags.
622
+ */
623
+ type OrderFlags = Pick<Order, 'kind' | 'partiallyFillable' | 'sellTokenBalance' | 'buyTokenBalance'>;
624
+ /**
625
+ * A timestamp value.
626
+ */
627
+ type Timestamp = number | Date;
628
+ /**
629
+ * A hash-like app data value.
630
+ */
631
+ type HashLike = Bytes | number;
632
+ /**
633
+ * Order balance configuration.
634
+ */
635
+ declare enum OrderBalance {
636
+ /**
637
+ * Use ERC20 token balances.
638
+ */
639
+ ERC20 = "erc20",
640
+ /**
641
+ * Use Balancer Vault external balances.
642
+ *
643
+ * This can only be specified specified for the sell balance and allows orders
644
+ * to re-use Vault ERC20 allowances. When specified for the buy balance, it
645
+ * will be treated as {@link OrderBalance.ERC20}.
646
+ */
647
+ EXTERNAL = "external",
648
+ /**
649
+ * Use Balancer Vault internal balances.
650
+ */
651
+ INTERNAL = "internal"
652
+ }
653
+ /**
654
+ * The EIP-712 type fields definition for a Gnosis Protocol v2 order.
655
+ */
656
+ declare const ORDER_TYPE_FIELDS: {
657
+ name: string;
658
+ type: string;
659
+ }[];
660
+ /**
661
+ * The EIP-712 type hash for a Gnosis Protocol v2 order.
662
+ * ethersV5.utils.id(
663
+ `Order(${ORDER_TYPE_FIELDS.map(({ name, type }) => `${type} ${name}`).join(
664
+ ",",
665
+ )})`,
666
+ );
667
+ */
668
+ declare const ORDER_TYPE_HASH = "0xd5a25ba2e97094ad7d83dc28a6572da797d6b3e7fc6663bd93efb789fc17e489";
669
+ /**
670
+ * The EIP-712 type fields definition for a Gnosis Protocol v2 order.
671
+ */
672
+ declare const CANCELLATIONS_TYPE_FIELDS: {
673
+ name: string;
674
+ type: string;
675
+ }[];
676
+ /**
677
+ * Normalizes a timestamp value to a Unix timestamp.
678
+ * @param time The timestamp value to normalize.
679
+ * @return Unix timestamp or number of seconds since the Unix Epoch.
680
+ */
681
+ declare function timestamp(t: Timestamp): number;
682
+ /**
683
+ * Normalizes an app data value to a 32-byte hash.
684
+ * @param hashLike A hash-like value to normalize.
685
+ * @returns A 32-byte hash encoded as a hex-string.
686
+ */
687
+ declare function hashify(h: HashLike): string;
688
+ /**
689
+ * Normalizes the balance configuration for a buy token. Specifically, this
690
+ * function ensures that {@link OrderBalance.EXTERNAL} gets normalized to
691
+ * {@link OrderBalance.ERC20}.
692
+ *
693
+ * @param balance The balance configuration.
694
+ * @returns The normalized balance configuration.
695
+ */
696
+ declare function normalizeBuyTokenBalance(balance: OrderBalance | undefined): OrderBalance.ERC20 | OrderBalance.INTERNAL;
697
+ /**
698
+ * Normalized representation of an {@link Order} for EIP-712 operations.
699
+ */
700
+ type NormalizedOrder = Omit<Order, 'validTo' | 'appData' | 'kind' | 'sellTokenBalance' | 'buyTokenBalance'> & {
701
+ receiver: string;
702
+ validTo: number;
703
+ appData: string;
704
+ kind: 'sell' | 'buy';
705
+ sellTokenBalance: 'erc20' | 'external' | 'internal';
706
+ buyTokenBalance: 'erc20' | 'internal';
707
+ };
708
+ /**
709
+ * Normalizes an order for hashing and signing, so that it can be used with
710
+ * Ethers.js for EIP-712 operations.
711
+ * @param hashLike A hash-like value to normalize.
712
+ * @returns A 32-byte hash encoded as a hex-string.
713
+ */
714
+ declare function normalizeOrder(order: Order): NormalizedOrder;
715
+ /**
716
+ * Compute the 32-byte signing hash for the specified order.
717
+ *
718
+ * @param domain The EIP-712 domain separator to compute the hash for.
719
+ * @param types The order to compute the digest for.
720
+ * @return Hex-encoded 32-byte order digest.
721
+ */
722
+ declare function hashTypedData(domain: TypedDataDomain, types: TypedDataTypes, data: Record<string, unknown>): string;
723
+ /**
724
+ * Compute the 32-byte signing hash for the specified order.
725
+ *
726
+ * @param domain The EIP-712 domain separator to compute the hash for.
727
+ * @param order The order to compute the digest for.
728
+ * @return Hex-encoded 32-byte order digest.
729
+ */
730
+ declare function hashOrder(domain: TypedDataDomain, order: Order): string;
731
+ /**
732
+ * The byte length of an order UID.
733
+ */
734
+ declare const ORDER_UID_LENGTH = 56;
735
+ /**
736
+ * Order unique identifier parameters.
737
+ */
738
+ interface OrderUidParams {
739
+ /**
740
+ * The EIP-712 order struct hash.
741
+ */
742
+ orderDigest: string;
743
+ /**
744
+ * The owner of the order.
745
+ */
746
+ owner: string;
747
+ /**
748
+ * The timestamp this order is valid until.
749
+ */
750
+ validTo: number | Date;
751
+ }
752
+ /**
753
+ * Computes the order UID for an order and the given owner.
754
+ */
755
+ declare function computeOrderUid(domain: TypedDataDomain, order: Order, owner: string): string;
756
+ /**
757
+ * Compute the unique identifier describing a user order in the settlement
758
+ * contract.
759
+ *
760
+ * @param OrderUidParams The parameters used for computing the order's unique
761
+ * identifier.
762
+ * @returns A string that unequivocally identifies the order of the user.
763
+ */
764
+ declare function packOrderUidParams({ orderDigest, owner, validTo }: OrderUidParams): string;
765
+ /**
766
+ * Extracts the order unique identifier parameters from the specified bytes.
767
+ *
768
+ * @param orderUid The order UID encoded as a hexadecimal string.
769
+ * @returns The extracted order UID parameters.
770
+ */
771
+ declare function extractOrderUidParams(orderUid: string): OrderUidParams;
772
+ /**
773
+ * Compute the 32-byte signing hash for the specified cancellation.
774
+ *
775
+ * @param domain The EIP-712 domain separator to compute the hash for.
776
+ * @param orderUid The unique identifier of the order to cancel.
777
+ * @return Hex-encoded 32-byte order digest.
778
+ */
779
+ declare function hashOrderCancellation(domain: TypedDataDomain, orderUid: Bytes): string;
780
+ /**
781
+ * Compute the 32-byte signing hash for the specified order cancellations.
782
+ *
783
+ * @param domain The EIP-712 domain separator to compute the hash for.
784
+ * @param orderUids The unique identifiers of the orders to cancel.
785
+ * @return Hex-encoded 32-byte order digest.
786
+ */
787
+ declare function hashOrderCancellations(domain: TypedDataDomain, orderUids: Bytes[]): string;
788
+
789
+ /**
790
+ * The salt used when deterministically deploying smart contracts.
791
+ * SALT = ethers.utils.formatBytes32String("Mattresses in Berlin!");
792
+ */
793
+ declare const SALT = "0x4d61747472657373657320696e204265726c696e210000000000000000000000";
794
+ /**
795
+ * The contract used to deploy contracts deterministically with CREATE2.
796
+ * The address is chosen by the hardhat-deploy library.
797
+ * It is the same in any EVM-based network.
798
+ *
799
+ * https://github.com/Arachnid/deterministic-deployment-proxy
800
+ */
801
+ declare const DEPLOYER_CONTRACT = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
802
+ /**
803
+ * Dictionary containing all deployed contract names.
804
+ */
805
+ declare enum CONTRACT_NAMES {
806
+ authenticator = "GPv2AllowListAuthentication",
807
+ settlement = "GPv2Settlement",
808
+ tradeSimulator = "GPv2TradeSimulator"
809
+ }
810
+ /**
811
+ * The name of a deployed contract.
812
+ */
813
+ type ContractName = (typeof CONTRACT_NAMES)[keyof typeof CONTRACT_NAMES];
814
+ /**
815
+ * The deployment args for a contract.
816
+ */
817
+ type DeploymentArguments<T> = T extends typeof CONTRACT_NAMES.authenticator ? never : T extends typeof CONTRACT_NAMES.settlement ? [string, string] : T extends typeof CONTRACT_NAMES.tradeSimulator ? [] : unknown[];
818
+ /**
819
+ * Artifact information important for computing deterministic deployments.
820
+ */
821
+ interface ArtifactDeployment {
822
+ abi: Abi;
823
+ bytecode: string;
824
+ }
825
+ /**
826
+ * An artifact with a contract name matching one of the deterministically
827
+ * deployed contracts.
828
+ */
829
+ interface NamedArtifactDeployment<C extends ContractName> extends ArtifactDeployment {
830
+ contractName: C;
831
+ }
832
+ type MaybeNamedArtifactArtifactDeployment<C> = C extends ContractName ? NamedArtifactDeployment<C> : ArtifactDeployment;
833
+ /**
834
+ * Computes the deterministic address at which the contract will be deployed.
835
+ * This address does not depend on which network the contract is deployed to.
836
+ *
837
+ * @param contractName Name of the contract for which to find the address.
838
+ * @param deploymentArguments Extra arguments that are necessary to deploy.
839
+ * @returns The address that is expected to store the deployed code.
840
+ */
841
+ declare function deterministicDeploymentAddress<C>({ bytecode }: MaybeNamedArtifactArtifactDeployment<C>, deploymentArguments: DeploymentArguments<C>): Address;
842
+
843
+ /**
844
+ * Returns the address of the implementation of an EIP-1967-compatible proxy
845
+ * from its address.
846
+ *
847
+ * @param proxy Address of the proxy contract.
848
+ * @returns The address of the contract storing the proxy implementation.
849
+ */
850
+ declare function implementationAddress(_provider: Provider, proxy: string): Promise<string>;
851
+ /**
852
+ * Returns the address of the implementation of an EIP-1967-compatible proxy
853
+ * from its address.
854
+ *
855
+ * @param proxy Address of the proxy contract.
856
+ * @returns The address of the administrator of the proxy.
857
+ */
858
+ declare function ownerAddress(provider: Provider, proxy: string): Promise<string>;
859
+ /**
860
+ * EIP-173 proxy ABI in "human-readable ABI" format. The proxy used by the
861
+ * deployment plugin implements this interface, and copying it here avoids
862
+ * pulling in `hardhat` as a dependency for just this ABI.
863
+ *
864
+ * <https://eips.ethereum.org/EIPS/eip-173#specification>
865
+ */
866
+ declare const EIP173_PROXY_ABI: string[];
867
+
868
+ /**
869
+ * Grants the required roles to the specified Vault relayer.
870
+ *
871
+ * This method is intended to be called by the Balancer Vault admin, and **not**
872
+ * traders. It is included in the exported TypeScript library for completeness
873
+ * and "documentation".
874
+ *
875
+ * @param authorizerAddress The address of the Vault authorizer contract that manages access.
876
+ * @param authorizerAbi The ABI of the authorizer contract.
877
+ * @param vaultAddress The address to the Vault.
878
+ * @param vaultRelayerAddress The address to the GPv2 Vault relayer contract.
879
+ * @param contractCall Function to execute the contract call (provided by the adapter).
880
+ */
881
+ declare function grantRequiredRoles(authorizerAddress: string, authorizerAbi: Abi, vaultAddress: string, vaultRelayerAddress: string, contractCall: (address: string, abi: Abi, functionName: string, args: unknown[]) => Promise<void>): Promise<void>;
882
+
883
+ /**
884
+ * A Balancer swap used for settling a single order against Balancer pools.
885
+ */
886
+ interface Swap {
887
+ /**
888
+ * The ID of the pool for the swap.
889
+ */
890
+ poolId: Bytes;
891
+ /**
892
+ * The swap input token address.
893
+ */
894
+ assetIn: string;
895
+ /**
896
+ * The swap output token address.
897
+ */
898
+ assetOut: string;
899
+ /**
900
+ * The amount to swap. This will ether be a fixed input amount when swapping
901
+ * a sell order, or a fixed output amount when swapping a buy order.
902
+ */
903
+ amount: BigIntish;
904
+ /**
905
+ * Optional additional pool user data required for the swap.
906
+ *
907
+ * This additional user data is pool implementation specific, and allows pools
908
+ * to extend the Vault pool interface.
909
+ */
910
+ userData?: Bytes;
911
+ }
912
+ /**
913
+ * An encoded Balancer swap request that can be used as input to the settlement
914
+ * contract.
915
+ */
916
+ interface BatchSwapStep {
917
+ /**
918
+ * The ID of the pool for the swap.
919
+ */
920
+ poolId: Bytes;
921
+ /**
922
+ * The index of the input token.
923
+ *
924
+ * Settlement swap calls encode tokens as an array, this number represents an
925
+ * index into that array.
926
+ */
927
+ assetInIndex: number;
928
+ /**
929
+ * The index of the output token.
930
+ */
931
+ assetOutIndex: number;
932
+ /**
933
+ * The amount to swap.
934
+ */
935
+ amount: BigIntish;
936
+ /**
937
+ * Additional pool user data required for the swap.
938
+ */
939
+ userData: Bytes;
940
+ }
941
+ /**
942
+ * Swap execution parameters.
943
+ */
944
+ interface SwapExecution {
945
+ /**
946
+ * The limit amount for the swap.
947
+ *
948
+ * This allows settlement submission to define a tighter slippage than what
949
+ * was specified by the order in order to reduce MEV opportunity.
950
+ */
951
+ limitAmount: BigIntish;
952
+ }
953
+ /**
954
+ * Encoded swap parameters.
955
+ */
956
+ type EncodedSwap = [
957
+ /** Swap requests. */
958
+ BatchSwapStep[],
959
+ /** Tokens. */
960
+ string[],
961
+ /** Encoded trade. */
962
+ Trade
963
+ ];
964
+ /**
965
+ * Encodes a swap as a {@link BatchSwapStep} to be used with the settlement
966
+ * contract.
967
+ */
968
+ declare function encodeSwapStep(tokens: TokenRegistry, swap: Swap): BatchSwapStep;
969
+ /**
970
+ * Encoder for CoW Protocol swap transactions.
971
+ *
972
+ * This class provides methods to encode swaps and trades for CoW Protocol
973
+ * settlements that involve Balancer Vault swaps. It maintains state for tokens,
974
+ * swaps, and the associated trade.
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * const encoder = new SwapEncoder(domain, adapter)
979
+ * encoder.encodeSwapStep(swap)
980
+ * encoder.encodeTrade(order, signature)
981
+ * const swapData = encoder.encodedSwap()
982
+ * ```
983
+ */
984
+ declare class SwapEncoder {
985
+ readonly domain: TypedDataDomain;
986
+ private readonly _tokens;
987
+ private readonly _swaps;
988
+ private _trade;
989
+ /**
990
+ * Creates a new settlement encoder instance.
991
+ *
992
+ * @param domain Domain used for signing orders. See {@link signOrder} for
993
+ * more details.
994
+ */
995
+ constructor(domain: TypedDataDomain, adapter?: AbstractProviderAdapter);
996
+ /**
997
+ * Gets the array of token addresses used by the currently encoded swaps.
998
+ */
999
+ get tokens(): string[];
1000
+ /**
1001
+ * Gets the encoded swaps.
1002
+ */
1003
+ get swaps(): BatchSwapStep[];
1004
+ /**
1005
+ * Gets the encoded trade.
1006
+ */
1007
+ get trade(): Trade;
1008
+ /**
1009
+ * Encodes the swap as a swap request and appends it to the swaps encoded so
1010
+ * far.
1011
+ *
1012
+ * @param swap The Balancer swap to encode.
1013
+ */
1014
+ encodeSwapStep(...swaps: Swap[]): void;
1015
+ /**
1016
+ * Encodes a trade from a signed order.
1017
+ *
1018
+ * Additionally, if the order references new tokens that the encoder has not
1019
+ * yet seen, they are added to the tokens array.
1020
+ *
1021
+ * @param order The order of the trade to encode.
1022
+ * @param signature The signature for the order data.
1023
+ */
1024
+ encodeTrade(order: Order, signature: Signature, swapExecution?: Partial<SwapExecution>): void;
1025
+ /**
1026
+ * Signs an order and encodes a trade with that order.
1027
+ *
1028
+ * @param order The order to sign for the trade.
1029
+ * @param scheme The signing scheme to use. See {@link SigningScheme} for more
1030
+ * details.
1031
+ * @param owner The externally owned account that should sign the order.
1032
+ */
1033
+ signEncodeTrade(order: Order, scheme: EcdsaSigningScheme, swapExecution?: Partial<SwapExecution>, owner?: SignerLike): Promise<void>;
1034
+ /**
1035
+ * Returns the encoded swap parameters for the current state of the encoder.
1036
+ *
1037
+ * This method with raise an exception if a trade has not been encoded.
1038
+ */
1039
+ encodedSwap(): EncodedSwap;
1040
+ static encodeSwap(swaps: Swap[], order: Order, signature: Signature): EncodedSwap;
1041
+ static encodeSwap(swaps: Swap[], order: Order, signature: Signature, swapExecution: Partial<SwapExecution> | undefined): EncodedSwap;
1042
+ static encodeSwap(domain: TypedDataDomain, swaps: Swap[], order: Order, owner: Signer, scheme: EcdsaSigningScheme): Promise<EncodedSwap>;
1043
+ static encodeSwap(domain: TypedDataDomain, swaps: Swap[], order: Order, owner: Signer, scheme: EcdsaSigningScheme, swapExecution: Partial<SwapExecution> | undefined): Promise<EncodedSwap>;
1044
+ }
1045
+
1046
+ declare class ContractsTs {
1047
+ ORDER_TYPE_FIELDS: {
1048
+ name: string;
1049
+ type: string;
1050
+ }[];
1051
+ ORDER_UID_LENGTH: number;
1052
+ /**
1053
+ * Creates a new ContractsTs instance
1054
+ *
1055
+ * @param adapter Provider adapter implementation
1056
+ */
1057
+ constructor(adapter: AbstractProviderAdapter);
1058
+ deterministicDeploymentAddress: typeof deterministicDeploymentAddress;
1059
+ normalizeInteraction: typeof normalizeInteraction;
1060
+ normalizeInteractions: typeof normalizeInteractions;
1061
+ timestamp: typeof timestamp;
1062
+ hashify: typeof hashify;
1063
+ normalizeBuyTokenBalance: typeof normalizeBuyTokenBalance;
1064
+ normalizeOrder: typeof normalizeOrder;
1065
+ hashTypedData: typeof hashTypedData;
1066
+ hashOrder: typeof hashOrder;
1067
+ computeOrderUid: typeof computeOrderUid;
1068
+ packOrderUidParams: typeof packOrderUidParams;
1069
+ extractOrderUidParams: typeof extractOrderUidParams;
1070
+ implementationAddress: typeof implementationAddress;
1071
+ ownerAddress: typeof ownerAddress;
1072
+ signOrder: typeof signOrder;
1073
+ encodeEip1271SignatureData: typeof encodeEip1271SignatureData;
1074
+ decodeEip1271SignatureData: typeof decodeEip1271SignatureData;
1075
+ grantRequiredRoles: typeof grantRequiredRoles;
1076
+ encodeSigningScheme: typeof encodeSigningScheme;
1077
+ decodeSigningScheme: typeof decodeSigningScheme;
1078
+ encodeOrderFlags: typeof encodeOrderFlags;
1079
+ decodeOrderFlags: typeof decodeOrderFlags;
1080
+ encodeTradeFlags: typeof encodeTradeFlags;
1081
+ decodeTradeFlags: typeof decodeTradeFlags;
1082
+ encodeSignatureData: typeof encodeSignatureData;
1083
+ decodeSignatureOwner: typeof decodeSignatureOwner;
1084
+ encodeTrade: typeof encodeTrade;
1085
+ decodeOrder: typeof decodeOrder;
1086
+ TokenRegistry: typeof TokenRegistry;
1087
+ SettlementEncoder: typeof SettlementEncoder;
1088
+ InteractionStage: typeof InteractionStage;
1089
+ FLAG_MASKS: {
1090
+ readonly kind: {
1091
+ readonly offset: 0;
1092
+ readonly options: readonly [OrderKind.SELL, OrderKind.BUY];
1093
+ };
1094
+ readonly partiallyFillable: {
1095
+ readonly offset: 1;
1096
+ readonly options: readonly [false, true];
1097
+ };
1098
+ readonly sellTokenBalance: {
1099
+ readonly offset: 2;
1100
+ readonly options: readonly [OrderBalance.ERC20, undefined, OrderBalance.EXTERNAL, OrderBalance.INTERNAL];
1101
+ };
1102
+ readonly buyTokenBalance: {
1103
+ readonly offset: 4;
1104
+ readonly options: readonly [OrderBalance.ERC20, OrderBalance.INTERNAL];
1105
+ };
1106
+ readonly signingScheme: {
1107
+ readonly offset: 5;
1108
+ readonly options: readonly [SigningScheme.EIP712, SigningScheme.ETHSIGN, SigningScheme.EIP1271, SigningScheme.PRESIGN];
1109
+ };
1110
+ };
1111
+ encodeSwapStep: typeof encodeSwapStep;
1112
+ SwapEncoder: typeof SwapEncoder;
1113
+ /**
1114
+ * Return the Gnosis Protocol v2 domain used for signing.
1115
+ * @param chainId The EIP-155 chain ID.
1116
+ * @param verifyingContract The address of the contract that will verify the
1117
+ * signature.
1118
+ * @return An EIP-712 compatible typed domain data.
1119
+ */
1120
+ static domain(chainId: number, verifyingContract: string): {
1121
+ name: string;
1122
+ version: string;
1123
+ chainId: number;
1124
+ verifyingContract: string;
1125
+ };
1126
+ }
1127
+
1128
+ declare enum Environment {
1129
+ Dev = 0,
1130
+ Prod = 1
1131
+ }
1132
+ declare const LIMIT_CONCURRENT_REQUESTS = 5;
1133
+ declare function apiUrl(environment: Environment, network: string): string;
1134
+ interface ApiCall {
1135
+ baseUrl: string;
1136
+ }
1137
+ interface EstimateTradeAmountQuery {
1138
+ sellToken: string;
1139
+ buyToken: string;
1140
+ kind: OrderKind;
1141
+ amount: BigIntish;
1142
+ }
1143
+ interface PlaceOrderQuery {
1144
+ order: Order;
1145
+ signature: Signature;
1146
+ from?: string;
1147
+ }
1148
+ interface GetExecutedSellAmountQuery {
1149
+ uid: string;
1150
+ }
1151
+ type SellAmountBeforeFee = {
1152
+ kind: OrderKind.SELL;
1153
+ sellAmountBeforeFee: BigIntish;
1154
+ };
1155
+ type SellAmountAfterFee = {
1156
+ kind: OrderKind.SELL;
1157
+ sellAmountAfterFee: BigIntish;
1158
+ };
1159
+ type BuyAmountAfterFee = {
1160
+ kind: OrderKind.BUY;
1161
+ buyAmountAfterFee: BigIntish;
1162
+ };
1163
+ type QuoteQuery = CommonQuoteQuery & (SellAmountBeforeFee | SellAmountAfterFee | BuyAmountAfterFee);
1164
+ interface CommonQuoteQuery {
1165
+ sellToken: string;
1166
+ buyToken: string;
1167
+ receiver?: string;
1168
+ validTo?: Timestamp;
1169
+ appData?: HashLike;
1170
+ partiallyFillable?: boolean;
1171
+ sellTokenBalance?: OrderBalance;
1172
+ buyTokenBalance?: OrderBalance;
1173
+ from: string;
1174
+ priceQuality?: QuotePriceQuality;
1175
+ }
1176
+ declare enum QuotePriceQuality {
1177
+ FAST = "fast",
1178
+ OPTIMAL = "optimal"
1179
+ }
1180
+ interface OrderDetailResponse {
1181
+ executedSellAmount: string;
1182
+ }
1183
+ interface GetQuoteResponse {
1184
+ quote: Order;
1185
+ from: string;
1186
+ expiration: Timestamp;
1187
+ id?: number;
1188
+ }
1189
+ interface ApiError {
1190
+ errorType: string;
1191
+ description: string;
1192
+ }
1193
+ interface CallError extends Error {
1194
+ apiError?: ApiError;
1195
+ }
1196
+ declare enum GetQuoteErrorType {
1197
+ SellAmountDoesNotCoverFee = "SellAmountDoesNotCoverFee",
1198
+ NoLiquidity = "NoLiquidity"
1199
+ }
1200
+ declare class Api {
1201
+ network: string;
1202
+ baseUrl: string;
1203
+ constructor(network: string, baseUrlOrEnv: string | Environment);
1204
+ private apiCallParams;
1205
+ estimateTradeAmount(query: EstimateTradeAmountQuery): Promise<BigIntish>;
1206
+ placeOrder(query: PlaceOrderQuery): Promise<string>;
1207
+ getExecutedSellAmount(query: GetExecutedSellAmountQuery): Promise<BigIntish>;
1208
+ getQuote(query: QuoteQuery): Promise<GetQuoteResponse>;
1209
+ }
1210
+
1211
+ /**
1212
+ * A class for attaching the storage reader contract to a solver allow list for
1213
+ * providing additional storage reading methods.
1214
+ */
1215
+ declare class AllowListReader {
1216
+ readonly allowListAddress: Address;
1217
+ readonly allowListAbi: Abi;
1218
+ readonly readerAddress: Address;
1219
+ readonly readerAbi: Abi;
1220
+ readonly provider: Provider;
1221
+ constructor(allowListAddress: Address, allowListAbi: Abi, readerAddress: Address, readerAbi: Abi, provider: Provider);
1222
+ /**
1223
+ * Returns true if all the specified addresses are allowed solvers.
1224
+ */
1225
+ areSolvers(solvers: Bytes[]): Promise<string>;
1226
+ }
1227
+ /**
1228
+ * A class for attaching the storage reader contract to the GPv2Settlement contract
1229
+ * for providing additional storage reading methods.
1230
+ */
1231
+ declare class SettlementReader {
1232
+ readonly settlementAddress: Address;
1233
+ readonly settlementAbi: Abi;
1234
+ readonly readerAddress: Address;
1235
+ readonly readerAbi: Abi;
1236
+ readonly provider: Provider;
1237
+ constructor(settlementAddress: Address, settlementAbi: Abi, readerAddress: Address, readerAbi: Abi, provider: Provider);
1238
+ /**
1239
+ * Read and return filled amounts for a list of orders
1240
+ */
1241
+ filledAmountsForOrders(orderUids: Bytes[]): Promise<BigIntish[]>;
1242
+ }
1243
+ /**
1244
+ * A simulated trade.
1245
+ */
1246
+ type TradeSimulation = Pick<Order, 'sellToken' | 'buyToken' | 'receiver' | 'sellAmount' | 'buyAmount' | 'sellTokenBalance' | 'buyTokenBalance'> & {
1247
+ /**
1248
+ * The address of the owner of the trade. For an actual settlement, this would
1249
+ * usually this would be determinied by recovering an order signature.
1250
+ */
1251
+ owner: string;
1252
+ };
1253
+ /**
1254
+ * Account balance changes in a trade simulation
1255
+ */
1256
+ interface TradeSimulationBalanceDelta {
1257
+ sellTokenDelta: BigIntish;
1258
+ buyTokenDelta: BigIntish;
1259
+ }
1260
+ /**
1261
+ * The result of a trade simulation.
1262
+ */
1263
+ interface TradeSimulationResult {
1264
+ gasUsed: BigIntish;
1265
+ executedBuyAmount: BigIntish;
1266
+ contractBalance: TradeSimulationBalanceDelta;
1267
+ ownerBalance: TradeSimulationBalanceDelta;
1268
+ }
1269
+ /**
1270
+ * Trade simulation storage reader contract allowing the simulation of trades.
1271
+ */
1272
+ declare class TradeSimulator {
1273
+ readonly settlementAddress: Address;
1274
+ readonly settlementAbi: Abi;
1275
+ readonly simulatorAddress: Address;
1276
+ readonly simulatorAbi: Abi;
1277
+ readonly provider: Provider;
1278
+ constructor(settlementAddress: Address, settlementAbi: Abi, simulatorAddress: Address, simulatorAbi: Abi, provider: Provider);
1279
+ /**
1280
+ * Simulates the single order settlement for an executed trade and a set of
1281
+ * interactions.
1282
+ */
1283
+ simulateTrade(trade: TradeSimulation, interactions: Partial<Record<InteractionStage, InteractionLike[]>>): Promise<TradeSimulationResult>;
1284
+ }
1285
+
1286
+ /**
1287
+ * Wrapper around a TypedDataSigner Signer object that implements `_signTypedData`. It allows to specify the version of
1288
+ * EIP-712 used.
1289
+ *
1290
+ * Takes a Signer instance on creation.
1291
+ * All other Signer methods are proxied to initial instance.
1292
+ */
1293
+ declare function getTypedDataVersionedSigner(signer: Signer, version: 'v3' | 'v4'): AbstractSigner<unknown>;
1294
+ /**
1295
+ * Wrapper around a TypedDataSigner Signer object that implements `_signTypedData` using
1296
+ * `eth_signTypedData_v3` instead of `eth_signTypedData_v4`.
1297
+ *
1298
+ * Takes a Signer instance on creation.
1299
+ * All other Signer methods are proxied to initial instance.
1300
+ */
1301
+ declare function getTypedDataV3Signer(signer: Signer): AbstractSigner<unknown>;
1302
+ /**
1303
+ * Wrapper around a TypedDataSigner Signer object that implements `_signTypedData` using
1304
+ * `eth_signTypedData_v4` as usual.
1305
+ * The difference here is that the domain `chainId` is transformed to a `number`.
1306
+ * That's done to circumvent a bug introduced in the latest Metamask version (9.6.0)
1307
+ * that no longer accepts a string for domain `chainId`.
1308
+ * See for more details https://github.com/MetaMask/metamask-extension/issues/11308.
1309
+ *
1310
+ * Takes a Signer instance on creation.
1311
+ * All other Signer methods are proxied to initial instance.
1312
+ */
1313
+ declare function getIntChainIdTypedDataV4Signer(signer: Signer): AbstractSigner<unknown>;
1314
+
1315
+ declare const CONTRACTS_PKG_VERSION = "0.1.0";
1316
+
1317
+ export { AllowListReader, Api, type ApiCall, type ApiError, type ArtifactDeployment, BUY_ETH_ADDRESS, type BatchSwapStep, type BuyAmountAfterFee, CANCELLATIONS_TYPE_FIELDS, CONTRACTS_PKG_VERSION, CONTRACT_NAMES, type CallError, type CommonQuoteQuery, type ContractName, type EcdsaSignature as ContractsEcdsaSignature, type EcdsaSigningScheme as ContractsEcdsaSigningScheme, type Order as ContractsOrder, type OrderCancellations as ContractsOrderCancellations, OrderKind as ContractsOrderKind, type Signature as ContractsSignature, SigningScheme as ContractsSigningScheme, type Trade as ContractsTrade, ContractsTs, DEPLOYER_CONTRACT, type DeploymentArguments, EIP1271_MAGICVALUE, EIP173_PROXY_ABI, type Eip1271Signature, type Eip1271SignatureData, type EncodedSettlement, type EncodedSwap, Environment, type EstimateTradeAmountQuery, FLAG_MASKS, type FlagKey, type FlagOptions, type FlagValue, type GetExecutedSellAmountQuery, GetQuoteErrorType, type GetQuoteResponse, type HashLike, type Interaction, type InteractionLike, InteractionStage, LIMIT_CONCURRENT_REQUESTS, type MaybeNamedArtifactArtifactDeployment, type NamedArtifactDeployment, type NormalizedOrder, ORDER_TYPE_FIELDS, ORDER_TYPE_HASH, ORDER_UID_LENGTH, OrderBalance, type OrderDetailResponse, type OrderFlags, type OrderRefunds, type OrderUidParams, PRE_SIGNED, type PlaceOrderQuery, type PreSignSignature, type Prices, QuotePriceQuality, type QuoteQuery, SALT, type SellAmountAfterFee, type SellAmountBeforeFee, SettlementEncoder, SettlementReader, type Swap, SwapEncoder, type SwapExecution, type Timestamp, TokenRegistry, type TradeExecution, type TradeFlags, type TradeSimulation, type TradeSimulationBalanceDelta, type TradeSimulationResult, TradeSimulator, apiUrl, computeOrderUid, decodeEip1271SignatureData, decodeOrder, decodeOrderFlags, decodeSignatureOwner, decodeSigningScheme, decodeTradeFlags, deterministicDeploymentAddress, ecdsaSignTypedData, encodeEip1271SignatureData, encodeOrderFlags, encodeSignatureData, encodeSigningScheme, encodeSwapStep, encodeTrade, encodeTradeFlags, extractOrderUidParams, getIntChainIdTypedDataV4Signer, getTypedDataV3Signer, getTypedDataVersionedSigner, grantRequiredRoles, hashOrder, hashOrderCancellation, hashOrderCancellations, hashTypedData, hashify, implementationAddress, normalizeBuyTokenBalance, normalizeInteraction, normalizeInteractions, normalizeOrder, ownerAddress, packOrderUidParams, signOrder, signOrderCancellation, signOrderCancellations, timestamp };