@cowprotocol/cow-sdk 2.4.0-rc.0 → 3.0.0-rc.3
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.
- package/dist/composable/{conditionalorder.d.ts → ConditionalOrder.d.ts} +66 -39
- package/dist/composable/ConditionalOrderFactory.d.ts +9 -0
- package/dist/composable/{multiplexer.d.ts → Multiplexer.d.ts} +16 -63
- package/dist/composable/contracts.d.ts +6 -0
- package/dist/composable/index.d.ts +5 -3
- package/dist/composable/orderTypes/Twap.d.ts +222 -0
- package/dist/composable/orderTypes/index.d.ts +3 -0
- package/dist/composable/types.d.ts +111 -0
- package/dist/composable/utils.d.ts +30 -0
- package/dist/index-6d619900.js +29 -0
- package/dist/index-6d619900.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.module.js +4 -4
- package/dist/index.module.js.map +1 -1
- package/dist/order-book/api.d.ts +4 -4
- package/dist/order-book/generated/index.d.ts +2 -1
- package/dist/order-book/generated/models/AppData.d.ts +7 -0
- package/dist/order-book/generated/models/AppDataHash.d.ts +2 -0
- package/dist/order-book/generated/models/AppDataObject.d.ts +7 -0
- package/dist/order-book/generated/models/OrderCreation.d.ts +4 -3
- package/dist/order-book/generated/models/OrderQuoteRequest.d.ts +16 -1
- package/dist/package.json +2 -2
- package/dist/utils-4e0f831b.js +2 -0
- package/dist/{utils-6743154b.js.map → utils-4e0f831b.js.map} +1 -1
- package/dist/utils-9b00464e.js +2 -0
- package/dist/{utils-16a884bc.js.map → utils-9b00464e.js.map} +1 -1
- package/dist/utils-c362412e.js +2 -0
- package/dist/{utils-3ea4a36c.js.map → utils-c362412e.js.map} +1 -1
- package/package.json +2 -2
- package/dist/composable/extensible.d.ts +0 -6
- package/dist/composable/types/index.d.ts +0 -1
- package/dist/composable/types/twap.d.ts +0 -114
- package/dist/index-856e1ad2.js +0 -29
- package/dist/index-856e1ad2.js.map +0 -1
- package/dist/order-book/generated/models/AppDataDocument.d.ts +0 -12
- package/dist/utils-16a884bc.js +0 -2
- package/dist/utils-3ea4a36c.js +0 -2
- package/dist/utils-6743154b.js +0 -2
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { BigNumber,
|
|
2
|
-
import { ContextFactory } from './
|
|
3
|
-
|
|
4
|
-
export type ConditionalOrderParams = {
|
|
5
|
-
readonly handler: string;
|
|
6
|
-
readonly salt: string;
|
|
7
|
-
readonly staticInput: string;
|
|
8
|
-
};
|
|
1
|
+
import { BigNumber, providers } from 'ethers';
|
|
2
|
+
import { ConditionalOrderArguments, ConditionalOrderParams, ContextFactory, IsValidResult, PollResult, PollResultErrors } from './types';
|
|
3
|
+
import { SupportedChainId } from '../common';
|
|
9
4
|
/**
|
|
10
5
|
* An abstract base class from which all conditional orders should inherit.
|
|
11
6
|
*
|
|
@@ -20,27 +15,29 @@ export type ConditionalOrderParams = {
|
|
|
20
15
|
* **NOTE**: Instances of conditional orders have an `id` property that is a `keccak256` hash of
|
|
21
16
|
* the serialized conditional order.
|
|
22
17
|
*/
|
|
23
|
-
export declare abstract class
|
|
18
|
+
export declare abstract class ConditionalOrder<D, S> {
|
|
24
19
|
readonly handler: string;
|
|
25
20
|
readonly salt: string;
|
|
26
|
-
readonly
|
|
21
|
+
readonly data: D;
|
|
22
|
+
readonly staticInput: S;
|
|
27
23
|
readonly hasOffChainInput: boolean;
|
|
28
24
|
/**
|
|
29
25
|
* A constructor that provides some basic validation for the conditional order.
|
|
30
26
|
*
|
|
31
|
-
* This constructor **MUST** be called by any class that inherits from `
|
|
27
|
+
* This constructor **MUST** be called by any class that inherits from `ConditionalOrder`.
|
|
32
28
|
*
|
|
33
29
|
* **NOTE**: The salt is optional and will be randomly generated if not provided.
|
|
34
30
|
* @param handler The address of the handler for the conditional order.
|
|
35
31
|
* @param salt A 32-byte string used to salt the conditional order.
|
|
36
|
-
* @param
|
|
32
|
+
* @param data The data of the order
|
|
37
33
|
* @param hasOffChainInput Whether the conditional order has off-chain input.
|
|
38
34
|
* @throws If the handler is not a valid ethereum address.
|
|
39
35
|
* @throws If the salt is not a valid 32-byte string.
|
|
40
36
|
*/
|
|
41
|
-
constructor(
|
|
37
|
+
constructor(params: ConditionalOrderArguments<D>);
|
|
42
38
|
/**
|
|
43
|
-
* Get the
|
|
39
|
+
* Get a descriptive name for the type of the conditional order (i.e twap, dca, etc).
|
|
40
|
+
*
|
|
44
41
|
* @returns {string} The concrete type of the conditional order.
|
|
45
42
|
*/
|
|
46
43
|
abstract get orderType(): string;
|
|
@@ -51,6 +48,8 @@ export declare abstract class BaseConditionalOrder<T, P> {
|
|
|
51
48
|
* @returns The context dependency.
|
|
52
49
|
*/
|
|
53
50
|
get context(): ContextFactory | undefined;
|
|
51
|
+
assertIsValid(): void;
|
|
52
|
+
abstract isValid(): IsValidResult;
|
|
54
53
|
/**
|
|
55
54
|
* Get the calldata for creating the conditional order.
|
|
56
55
|
*
|
|
@@ -67,7 +66,7 @@ export declare abstract class BaseConditionalOrder<T, P> {
|
|
|
67
66
|
*/
|
|
68
67
|
get removeCalldata(): string;
|
|
69
68
|
/**
|
|
70
|
-
* Calculate the id of the conditional order.
|
|
69
|
+
* Calculate the id of the conditional order (which also happens to be the key used for `ctx` in the ComposableCoW contract).
|
|
71
70
|
*
|
|
72
71
|
* This is a `keccak256` hash of the serialized conditional order.
|
|
73
72
|
* @returns The id of the conditional order.
|
|
@@ -95,15 +94,9 @@ export declare abstract class BaseConditionalOrder<T, P> {
|
|
|
95
94
|
* @returns The off-chain input.
|
|
96
95
|
*/
|
|
97
96
|
get offChainInput(): string;
|
|
98
|
-
/**
|
|
99
|
-
* Helper method for validating ABI types.
|
|
100
|
-
* @param types ABI types to validate against.
|
|
101
|
-
* @param values The values to validate.
|
|
102
|
-
* @returns {boolean} Whether the values are valid ABI for the given types.
|
|
103
|
-
*/
|
|
104
|
-
protected static isValidAbi(types: readonly (string | ethers.utils.ParamType)[], values: any[]): boolean;
|
|
105
97
|
/**
|
|
106
98
|
* Create a human-readable string representation of the conditional order.
|
|
99
|
+
*
|
|
107
100
|
* @param tokenFormatter An optional function that takes an address and an amount and returns a human-readable string.
|
|
108
101
|
*/
|
|
109
102
|
abstract toString(tokenFormatter?: (address: string, amount: BigNumber) => string): string;
|
|
@@ -115,39 +108,73 @@ export declare abstract class BaseConditionalOrder<T, P> {
|
|
|
115
108
|
abstract serialize(): string;
|
|
116
109
|
/**
|
|
117
110
|
* Encode the `staticInput` for the conditional order.
|
|
111
|
+
*
|
|
118
112
|
* @returns The ABI-encoded `staticInput` for the conditional order.
|
|
119
113
|
* @see ConditionalOrderParams
|
|
120
114
|
*/
|
|
121
115
|
abstract encodeStaticInput(): string;
|
|
122
116
|
/**
|
|
123
117
|
* A helper function for generically serializing a conditional order's static input.
|
|
118
|
+
*
|
|
124
119
|
* @param orderDataTypes ABI types for the order's data struct.
|
|
125
|
-
* @param
|
|
120
|
+
* @param data The order's data struct.
|
|
126
121
|
* @returns An ABI-encoded representation of the order's data struct.
|
|
127
122
|
*/
|
|
128
|
-
protected encodeStaticInputHelper(orderDataTypes: string[], staticInput:
|
|
123
|
+
protected encodeStaticInputHelper(orderDataTypes: string[], staticInput: S): string;
|
|
129
124
|
/**
|
|
130
|
-
*
|
|
125
|
+
* Poll a conditional order to see if it is tradeable.
|
|
131
126
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @param
|
|
135
|
-
* @
|
|
127
|
+
* @param owner The owner of the conditional order.
|
|
128
|
+
* @param p The proof and parameters.
|
|
129
|
+
* @param chain Which chain to use for the ComposableCoW contract.
|
|
130
|
+
* @param provider An RPC provider for the chain.
|
|
131
|
+
* @param offChainInputFn A function, if provided, that will return the off-chain input for the conditional order.
|
|
132
|
+
* @throws If the conditional order is not tradeable.
|
|
133
|
+
* @returns The tradeable `GPv2Order.Data` struct and the `signature` for the conditional order.
|
|
136
134
|
*/
|
|
137
|
-
|
|
135
|
+
poll(owner: string, chain: SupportedChainId, provider: providers.Provider): Promise<PollResult>;
|
|
138
136
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
142
|
-
* @
|
|
137
|
+
* Checks if the owner authorized the conditional order.
|
|
138
|
+
*
|
|
139
|
+
* @param owner The owner of the conditional order.
|
|
140
|
+
* @param chain Which chain to use for the ComposableCoW contract.
|
|
141
|
+
* @param provider An RPC provider for the chain.
|
|
142
|
+
* @returns true if the owner authorized the order, false otherwise.
|
|
143
143
|
*/
|
|
144
|
-
|
|
144
|
+
isAuthorized(owner: string, chain: SupportedChainId, provider: providers.Provider): Promise<boolean>;
|
|
145
145
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
146
|
+
* Allow concrete conditional orders to perform additional validation for the poll method.
|
|
147
|
+
*
|
|
148
|
+
* This will allow the concrete orders to decide when an order shouldn't be polled again. For example, if the orders is expired.
|
|
149
|
+
* It also allows to signal when should the next check be done. For example, an order could signal that the validations will fail until a certain time or block.
|
|
150
|
+
*
|
|
151
|
+
* @param owner The owner of the conditional order.
|
|
152
|
+
* @param chain Which chain to use for the ComposableCoW contract.
|
|
153
|
+
* @param provider An RPC provider for the chain.
|
|
154
|
+
*
|
|
155
|
+
* @returns undefined if the concrete order can't make a decision. Otherwise, it returns a PollResultErrors object.
|
|
156
|
+
*/
|
|
157
|
+
protected abstract pollValidate(owner: string, chain: SupportedChainId, provider: providers.Provider): Promise<PollResultErrors | undefined>;
|
|
158
|
+
/**
|
|
159
|
+
* Convert the struct that the contract expect as an encoded `staticInput` into a friendly data object modeling the smart order.
|
|
160
|
+
*
|
|
161
|
+
* **NOTE**: This should be overridden by any conditional order that requires transformations.
|
|
162
|
+
* This implementation is a no-op if you use the same type for both.
|
|
163
|
+
*
|
|
164
|
+
* @param params {S} Parameters that are passed in to the constructor.
|
|
165
|
+
* @returns {D} The static input for the conditional order.
|
|
166
|
+
*/
|
|
167
|
+
abstract transformStructToData(params: S): D;
|
|
168
|
+
/**
|
|
169
|
+
* Converts a friendly data object modeling the smart order into the struct that the contract expect as an encoded `staticInput`.
|
|
170
|
+
*
|
|
171
|
+
* **NOTE**: This should be overridden by any conditional order that requires transformations.
|
|
172
|
+
* This implementation is a no-op if you use the same type for both.
|
|
173
|
+
*
|
|
174
|
+
* @param params {S} Parameters that are passed in to the constructor.
|
|
175
|
+
* @returns {D} The static input for the conditional order.
|
|
149
176
|
*/
|
|
150
|
-
|
|
177
|
+
abstract transformDataToStruct(params: D): S;
|
|
151
178
|
/**
|
|
152
179
|
* A helper function for generically deserializing a conditional order.
|
|
153
180
|
* @param s The ABI-encoded `IConditionalOrder.Params` struct to deserialize.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ConditionalOrder } from './ConditionalOrder';
|
|
2
|
+
import { ConditionalOrderParams } from './types';
|
|
3
|
+
export type FromParams<D, S> = (params: ConditionalOrderParams) => ConditionalOrder<D, S>;
|
|
4
|
+
export type ConditionalOrderRegistry = Record<string, FromParams<unknown, unknown>>;
|
|
5
|
+
export declare class ConditionalOrderFactory {
|
|
6
|
+
knownOrderTypes: ConditionalOrderRegistry;
|
|
7
|
+
constructor(registry: ConditionalOrderRegistry);
|
|
8
|
+
fromParams(params: ConditionalOrderParams): ConditionalOrder<unknown, unknown> | undefined;
|
|
9
|
+
}
|
|
@@ -1,56 +1,9 @@
|
|
|
1
1
|
import { providers } from 'ethers';
|
|
2
2
|
import { SupportedChainId } from '../common';
|
|
3
|
-
import { BaseConditionalOrder, ConditionalOrderParams } from './conditionalorder';
|
|
4
3
|
import { ComposableCoW, GPv2Order } from './generated/ComposableCoW';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
EMITTED = 1,
|
|
9
|
-
SWARM = 2,
|
|
10
|
-
WAKU = 3,
|
|
11
|
-
RESERVED = 4,
|
|
12
|
-
IPFS = 5
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A factory and it's arguments that are called at transaction mining time to generate the context
|
|
16
|
-
* for a conditional order(s).
|
|
17
|
-
*
|
|
18
|
-
* This allows to support the case where conditional orders may want to *commence* validity at the
|
|
19
|
-
* time of transaction mining, like in the case of a `TWAP` executed by a DAO or `Safe` that takes
|
|
20
|
-
* a reasonable amount of time to aggregate signatures or collect votes.
|
|
21
|
-
*
|
|
22
|
-
* @remarks This is used in conjunction with `setRootWithContext` or `createWithContext`.
|
|
23
|
-
*/
|
|
24
|
-
export type ContextFactory = {
|
|
25
|
-
address: string;
|
|
26
|
-
factoryArgs?: {
|
|
27
|
-
args: any[];
|
|
28
|
-
argsType: string[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* A struct for a proof that can be used with `setRoot` and `setRootWithContext` on a
|
|
33
|
-
* ComposableCoW-enabled Safe.
|
|
34
|
-
*/
|
|
35
|
-
export type ProofStruct = {
|
|
36
|
-
location: ProofLocation;
|
|
37
|
-
data: string | '0x';
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Payload for emitting a merkle root to a ComposableCoW-enabled Safe.
|
|
41
|
-
*
|
|
42
|
-
* If setting `ProofLocation.EMITTED`, this type should be used as the `data` in the `Proof` struct.
|
|
43
|
-
*/
|
|
44
|
-
export type PayloadLocationEmitted = {
|
|
45
|
-
proofs: ProofWithParams[];
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* A proof for a conditional order and it's parameters.
|
|
49
|
-
*/
|
|
50
|
-
export type ProofWithParams = {
|
|
51
|
-
proof: string[];
|
|
52
|
-
params: ConditionalOrderParams;
|
|
53
|
-
};
|
|
4
|
+
import { ProofLocation, ProofWithParams, ConditionalOrderParams } from './types';
|
|
5
|
+
import { ConditionalOrder } from './ConditionalOrder';
|
|
6
|
+
export type Orders = Record<string, ConditionalOrder<unknown, unknown>>;
|
|
54
7
|
/**
|
|
55
8
|
* Multiplexer for conditional orders - using `ComposableCoW`!
|
|
56
9
|
*
|
|
@@ -61,7 +14,7 @@ export type ProofWithParams = {
|
|
|
61
14
|
* - Support for passing an optional upload function to upload the proofs to a decentralized storage network
|
|
62
15
|
*/
|
|
63
16
|
export declare class Multiplexer {
|
|
64
|
-
static orderTypeRegistry: Record<string, new (...args:
|
|
17
|
+
static orderTypeRegistry: Record<string, new (...args: unknown[]) => ConditionalOrder<unknown, unknown>>;
|
|
65
18
|
chain: SupportedChainId;
|
|
66
19
|
location: ProofLocation;
|
|
67
20
|
private orders;
|
|
@@ -99,30 +52,30 @@ export declare class Multiplexer {
|
|
|
99
52
|
* Add a conditional order to the merkle tree.
|
|
100
53
|
* @param order The order to add to the merkle tree.
|
|
101
54
|
*/
|
|
102
|
-
add<T, P>(order:
|
|
55
|
+
add<T, P>(order: ConditionalOrder<T, P>): void;
|
|
103
56
|
/**
|
|
104
57
|
* Remove a conditional order from the merkle tree.
|
|
105
|
-
* @param id The id of the `
|
|
58
|
+
* @param id The id of the `ConditionalOrder` to remove from the merkle tree.
|
|
106
59
|
*/
|
|
107
60
|
remove(id: string): void;
|
|
108
61
|
/**
|
|
109
62
|
* Update a given conditional order in the merkle tree.
|
|
110
|
-
* @param id The id of the `
|
|
111
|
-
* @param updater A function that takes the existing `
|
|
63
|
+
* @param id The id of the `ConditionalOrder` to update.
|
|
64
|
+
* @param updater A function that takes the existing `ConditionalOrder` and context, returning an updated `ConditionalOrder`.
|
|
112
65
|
*/
|
|
113
|
-
update
|
|
66
|
+
update(id: string, updater: (order: ConditionalOrder<unknown, unknown>, ctx?: string) => ConditionalOrder<unknown, unknown>): void;
|
|
114
67
|
/**
|
|
115
68
|
* Accessor for a given conditional order in the multiplexer.
|
|
116
|
-
* @param id The `id` of the `
|
|
117
|
-
* @returns A `
|
|
69
|
+
* @param id The `id` of the `ConditionalOrder` to retrieve.
|
|
70
|
+
* @returns A `ConditionalOrder` with the given `id`.
|
|
118
71
|
*/
|
|
119
|
-
getById(id: string):
|
|
72
|
+
getById(id: string): ConditionalOrder<unknown, unknown>;
|
|
120
73
|
/**
|
|
121
74
|
* Accessor for a given conditional order in the multiplexer.
|
|
122
|
-
* @param i The index of the `
|
|
123
|
-
* @returns A `
|
|
75
|
+
* @param i The index of the `ConditionalOrder` to retrieve.
|
|
76
|
+
* @returns A `ConditionalOrder` at the given index.
|
|
124
77
|
*/
|
|
125
|
-
getByIndex(i: number):
|
|
78
|
+
getByIndex(i: number): ConditionalOrder<unknown, unknown>;
|
|
126
79
|
/**
|
|
127
80
|
* Get all the conditional order ids in the multiplexer.
|
|
128
81
|
*/
|
|
@@ -213,7 +166,7 @@ export declare class Multiplexer {
|
|
|
213
166
|
* @param orderType The order type to register.
|
|
214
167
|
* @param conditionalOrderClass The class to use for the given order type.
|
|
215
168
|
*/
|
|
216
|
-
static registerOrderType(orderType: string, conditionalOrderClass: new (...args:
|
|
169
|
+
static registerOrderType(orderType: string, conditionalOrderClass: new (...args: unknown[]) => ConditionalOrder<unknown, unknown>): void;
|
|
217
170
|
/**
|
|
218
171
|
* Reset the order type registry.
|
|
219
172
|
*/
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { providers } from 'ethers';
|
|
2
|
+
import { SupportedChainId } from '../common';
|
|
3
|
+
import { ComposableCoW } from './generated';
|
|
4
|
+
import { ComposableCoWInterface } from './generated/ComposableCoW';
|
|
5
|
+
export declare function getComposableCowInterface(): ComposableCoWInterface;
|
|
6
|
+
export declare function getComposableCow(chain: SupportedChainId, provider: providers.Provider): ComposableCoW;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export * from './extensible';
|
|
2
|
-
export * from './multiplexer';
|
|
3
|
-
export * from './conditionalorder';
|
|
4
1
|
export * from './types';
|
|
2
|
+
export * from './utils';
|
|
3
|
+
export * from './ConditionalOrder';
|
|
4
|
+
export * from './Multiplexer';
|
|
5
|
+
export * from './ConditionalOrderFactory';
|
|
6
|
+
export * from './orderTypes';
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { BigNumber, providers } from 'ethers';
|
|
2
|
+
import { ConditionalOrder } from '../ConditionalOrder';
|
|
3
|
+
import { ConditionalOrderArguments, ConditionalOrderParams, ContextFactory, IsNotValid, IsValid, PollResultErrors } from '../types';
|
|
4
|
+
import { SupportedChainId } from '../../common';
|
|
5
|
+
export declare const TWAP_ADDRESS = "0x6cF1e9cA41f7611dEf408122793c358a3d11E5a5";
|
|
6
|
+
/**
|
|
7
|
+
* The address of the `CurrentBlockTimestampFactory` contract
|
|
8
|
+
*
|
|
9
|
+
* **NOTE**: This is used in the event that TWAP's have a `t0` of `0`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CURRENT_BLOCK_TIMESTAMP_FACTORY_ADDRESS = "0x52eD56Da04309Aca4c3FECC595298d80C2f16BAc";
|
|
12
|
+
export declare const MAX_UINT32: BigNumber;
|
|
13
|
+
export declare const MAX_FREQUENCY: BigNumber;
|
|
14
|
+
/**
|
|
15
|
+
* Base parameters for a TWAP order. Shared by:
|
|
16
|
+
* - TwapStruct (modeling the contract's struct used for `staticInput`).
|
|
17
|
+
* - TwapData (modeling the friendly SDK interface).
|
|
18
|
+
*/
|
|
19
|
+
export type TwapDataBase = {
|
|
20
|
+
/**
|
|
21
|
+
* which token to sell
|
|
22
|
+
*/
|
|
23
|
+
readonly sellToken: string;
|
|
24
|
+
/**
|
|
25
|
+
* which token to buy
|
|
26
|
+
*/
|
|
27
|
+
readonly buyToken: string;
|
|
28
|
+
/**
|
|
29
|
+
* who to send the tokens to
|
|
30
|
+
*/
|
|
31
|
+
readonly receiver: string;
|
|
32
|
+
/**
|
|
33
|
+
* Meta-data associated with the order. Normally would be the keccak256 hash of the document generated in http://github.com/cowprotocol/app-data
|
|
34
|
+
*
|
|
35
|
+
* This hash should have been uploaded to the API https://api.cow.fi/docs/#/default/put_api_v1_app_data__app_data_hash_ and potentially to other data availability protocols like IPFS.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
readonly appData: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Parameters for a TWAP order, as expected by the contract's `staticInput`.
|
|
42
|
+
*/
|
|
43
|
+
export interface TwapStruct extends TwapDataBase {
|
|
44
|
+
/**
|
|
45
|
+
* amount of sellToken to sell in each part
|
|
46
|
+
*/
|
|
47
|
+
readonly partSellAmount: BigNumber;
|
|
48
|
+
/**
|
|
49
|
+
* minimum amount of buyToken that must be bought in each part
|
|
50
|
+
*/
|
|
51
|
+
readonly minPartLimit: BigNumber;
|
|
52
|
+
/**
|
|
53
|
+
* start time of the TWAP
|
|
54
|
+
*/
|
|
55
|
+
readonly t0: BigNumber;
|
|
56
|
+
/**
|
|
57
|
+
* number of parts
|
|
58
|
+
*/
|
|
59
|
+
readonly n: BigNumber;
|
|
60
|
+
/**
|
|
61
|
+
* duration of the TWAP interval
|
|
62
|
+
*/
|
|
63
|
+
readonly t: BigNumber;
|
|
64
|
+
/**
|
|
65
|
+
* whether the TWAP is valid for the entire interval or not
|
|
66
|
+
*/
|
|
67
|
+
readonly span: BigNumber;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parameters for a TWAP order, made a little more user-friendly for SDK users.
|
|
71
|
+
*
|
|
72
|
+
* @see {@link TwapStruct} for the native struct.
|
|
73
|
+
*/
|
|
74
|
+
export interface TwapData extends TwapDataBase {
|
|
75
|
+
/**
|
|
76
|
+
* total amount of sellToken to sell across the entire TWAP
|
|
77
|
+
*/
|
|
78
|
+
readonly sellAmount: BigNumber;
|
|
79
|
+
/**
|
|
80
|
+
* minimum amount of buyToken that must be bought across the entire TWAP
|
|
81
|
+
*/
|
|
82
|
+
readonly buyAmount: BigNumber;
|
|
83
|
+
/**
|
|
84
|
+
* start time of the TWAP
|
|
85
|
+
*/
|
|
86
|
+
readonly startTime?: StartTime;
|
|
87
|
+
/**
|
|
88
|
+
* number of parts
|
|
89
|
+
*/
|
|
90
|
+
readonly numberOfParts: BigNumber;
|
|
91
|
+
/**
|
|
92
|
+
* duration of the TWAP interval
|
|
93
|
+
*/
|
|
94
|
+
readonly timeBetweenParts: BigNumber;
|
|
95
|
+
/**
|
|
96
|
+
* whether the TWAP is valid for the entire interval or not
|
|
97
|
+
*/
|
|
98
|
+
readonly durationOfPart?: DurationOfPart;
|
|
99
|
+
}
|
|
100
|
+
export type DurationOfPart = {
|
|
101
|
+
durationType: DurationType.AUTO;
|
|
102
|
+
} | {
|
|
103
|
+
durationType: DurationType.LIMIT_DURATION;
|
|
104
|
+
duration: BigNumber;
|
|
105
|
+
};
|
|
106
|
+
export declare enum DurationType {
|
|
107
|
+
AUTO = "AUTO",
|
|
108
|
+
LIMIT_DURATION = "LIMIT_DURATION"
|
|
109
|
+
}
|
|
110
|
+
export type StartTime = {
|
|
111
|
+
startType: StartTimeValue.AT_MINING_TIME;
|
|
112
|
+
} | {
|
|
113
|
+
startType: StartTimeValue.AT_EPOC;
|
|
114
|
+
epoch: BigNumber;
|
|
115
|
+
};
|
|
116
|
+
export declare enum StartTimeValue {
|
|
117
|
+
AT_MINING_TIME = "AT_MINING_TIME",
|
|
118
|
+
AT_EPOC = "AT_EPOC"
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* `ComposableCoW` implementation of a TWAP order.
|
|
122
|
+
* @author mfw78 <mfw78@rndlabs.xyz>
|
|
123
|
+
*/
|
|
124
|
+
export declare class Twap extends ConditionalOrder<TwapData, TwapStruct> {
|
|
125
|
+
/**
|
|
126
|
+
* @see {@link ConditionalOrder.constructor}
|
|
127
|
+
* @throws If the TWAP order is invalid.
|
|
128
|
+
* @throws If the TWAP order is not ABI-encodable.
|
|
129
|
+
* @throws If the handler is not the TWAP address.
|
|
130
|
+
*/
|
|
131
|
+
constructor(params: ConditionalOrderArguments<TwapData>);
|
|
132
|
+
/**
|
|
133
|
+
* Create a TWAP order with sound defaults.
|
|
134
|
+
* @param data The TWAP order parameters in a more user-friendly format.
|
|
135
|
+
* @returns An instance of the TWAP order.
|
|
136
|
+
*/
|
|
137
|
+
static fromData(data: TwapData): Twap;
|
|
138
|
+
/**
|
|
139
|
+
* Create a TWAP order with sound defaults.
|
|
140
|
+
* @param data The TWAP order parameters in a more user-friendly format.
|
|
141
|
+
* @returns An instance of the TWAP order.
|
|
142
|
+
*/
|
|
143
|
+
static fromParams(params: ConditionalOrderParams): Twap;
|
|
144
|
+
/**
|
|
145
|
+
* Enforces that TWAPs will commence at the beginning of a block by use of the
|
|
146
|
+
* `CurrentBlockTimestampFactory` contract to provide the current block timestamp
|
|
147
|
+
* as the start time of the TWAP.
|
|
148
|
+
*/
|
|
149
|
+
get context(): ContextFactory | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* @inheritdoc {@link ConditionalOrder.orderType}
|
|
152
|
+
*/
|
|
153
|
+
get orderType(): string;
|
|
154
|
+
/**
|
|
155
|
+
* Validate the TWAP order.
|
|
156
|
+
* @param data The TWAP order to validate.
|
|
157
|
+
* @returns Whether the TWAP order is valid.
|
|
158
|
+
* @throws If the TWAP order is invalid.
|
|
159
|
+
* @see {@link TwapStruct} for the native struct.
|
|
160
|
+
*/
|
|
161
|
+
isValid(): IsValid | IsNotValid;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if the owner authorized the conditional order.
|
|
164
|
+
*
|
|
165
|
+
* @param owner The owner of the conditional order.
|
|
166
|
+
* @param chain Which chain to use for the ComposableCoW contract.
|
|
167
|
+
* @param provider An RPC provider for the chain.
|
|
168
|
+
* @returns true if the owner authorized the order, false otherwise.
|
|
169
|
+
*/
|
|
170
|
+
protected pollValidate(_owner: string, _chain: SupportedChainId, _provider: providers.Provider): Promise<PollResultErrors | undefined>;
|
|
171
|
+
/**
|
|
172
|
+
* Serialize the TWAP order into it's ABI-encoded form.
|
|
173
|
+
* @returns {string} The ABI-encoded TWAP order.
|
|
174
|
+
*/
|
|
175
|
+
serialize(): string;
|
|
176
|
+
/**
|
|
177
|
+
* Get the encoded static input for the TWAP order.
|
|
178
|
+
* @returns {string} The ABI-encoded TWAP order.
|
|
179
|
+
*/
|
|
180
|
+
encodeStaticInput(): string;
|
|
181
|
+
/**
|
|
182
|
+
* Deserialize a TWAP order from it's ABI-encoded form.
|
|
183
|
+
* @param {string} twapSerialized ABI-encoded TWAP order to deserialize.
|
|
184
|
+
* @returns A deserialized TWAP order.
|
|
185
|
+
*/
|
|
186
|
+
static deserialize(twapSerialized: string): Twap;
|
|
187
|
+
/**
|
|
188
|
+
* Create a human-readable string representation of the TWAP order.
|
|
189
|
+
* @param {((address: string, amount: BigNumber) => string) | undefined} tokenFormatter An optional
|
|
190
|
+
* function that takes an address and an amount and returns a human-readable string.
|
|
191
|
+
* @returns {string} A human-readable string representation of the TWAP order.
|
|
192
|
+
*/
|
|
193
|
+
toString(tokenFormatter?: (address: string, amount: BigNumber) => string): string;
|
|
194
|
+
/**
|
|
195
|
+
* Transform parameters into a native struct.
|
|
196
|
+
*
|
|
197
|
+
* @param {TwapData} data As passed by the consumer of the API.
|
|
198
|
+
* @returns {TwapStruct} A formatted struct as expected by the smart contract.
|
|
199
|
+
*/
|
|
200
|
+
transformDataToStruct(data: TwapData): TwapStruct;
|
|
201
|
+
/**
|
|
202
|
+
* Transform parameters into a TWAP order struct.
|
|
203
|
+
*
|
|
204
|
+
* @param {TwapData} params As passed by the consumer of the API.
|
|
205
|
+
* @returns {TwapStruct} A formatted struct as expected by the smart contract.
|
|
206
|
+
*/
|
|
207
|
+
transformStructToData(struct: TwapStruct): TwapData;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Transform parameters into a native struct.
|
|
211
|
+
*
|
|
212
|
+
* @param {TwapData} data As passed by the consumer of the API.
|
|
213
|
+
* @returns {TwapStruct} A formatted struct as expected by the smart contract.
|
|
214
|
+
*/
|
|
215
|
+
export declare function transformDataToStruct(data: TwapData): TwapStruct;
|
|
216
|
+
/**
|
|
217
|
+
* Transform parameters into a TWAP order struct.
|
|
218
|
+
*
|
|
219
|
+
* @param {TwapData} params As passed by the consumer of the API.
|
|
220
|
+
* @returns {TwapStruct} A formatted struct as expected by the smart contract.
|
|
221
|
+
*/
|
|
222
|
+
export declare function transformStructToData(struct: TwapStruct): TwapData;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { GPv2Order } from './generated/ComposableCoW';
|
|
2
|
+
export interface ConditionalOrderArguments<T> {
|
|
3
|
+
handler: string;
|
|
4
|
+
data: T;
|
|
5
|
+
salt?: string;
|
|
6
|
+
hasOffChainInput?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type ConditionalOrderParams = {
|
|
9
|
+
readonly handler: string;
|
|
10
|
+
readonly salt: string;
|
|
11
|
+
readonly staticInput: string;
|
|
12
|
+
};
|
|
13
|
+
export declare enum ProofLocation {
|
|
14
|
+
PRIVATE = 0,
|
|
15
|
+
EMITTED = 1,
|
|
16
|
+
SWARM = 2,
|
|
17
|
+
WAKU = 3,
|
|
18
|
+
RESERVED = 4,
|
|
19
|
+
IPFS = 5
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A factory and it's arguments that are called at transaction mining time to generate the context
|
|
23
|
+
* for a conditional order(s).
|
|
24
|
+
*
|
|
25
|
+
* This allows to support the case where conditional orders may want to *commence* validity at the
|
|
26
|
+
* time of transaction mining, like in the case of a `TWAP` executed by a DAO or `Safe` that takes
|
|
27
|
+
* a reasonable amount of time to aggregate signatures or collect votes.
|
|
28
|
+
*
|
|
29
|
+
* @remarks This is used in conjunction with `setRootWithContext` or `createWithContext`.
|
|
30
|
+
*/
|
|
31
|
+
export type ContextFactory = {
|
|
32
|
+
address: string;
|
|
33
|
+
factoryArgs?: {
|
|
34
|
+
args: unknown[];
|
|
35
|
+
argsType: string[];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* A struct for a proof that can be used with `setRoot` and `setRootWithContext` on a
|
|
40
|
+
* ComposableCoW-enabled Safe.
|
|
41
|
+
*/
|
|
42
|
+
export type ProofStruct = {
|
|
43
|
+
location: ProofLocation;
|
|
44
|
+
data: string | '0x';
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Payload for emitting a merkle root to a ComposableCoW-enabled Safe.
|
|
48
|
+
*
|
|
49
|
+
* If setting `ProofLocation.EMITTED`, this type should be used as the `data` in the `Proof` struct.
|
|
50
|
+
*/
|
|
51
|
+
export type PayloadLocationEmitted = {
|
|
52
|
+
proofs: ProofWithParams[];
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* A proof for a conditional order and it's parameters.
|
|
56
|
+
*/
|
|
57
|
+
export type ProofWithParams = {
|
|
58
|
+
proof: string[];
|
|
59
|
+
params: ConditionalOrderParams;
|
|
60
|
+
};
|
|
61
|
+
export type PollResult = PollResultSuccess | PollResultErrors;
|
|
62
|
+
export type PollResultErrors = PollResultTryNextBlock | PollResultTryOnBlock | PollResultTryAtEpoch | PollResultUnexpectedError | PollResultDontTryAgain;
|
|
63
|
+
export declare enum PollResultCode {
|
|
64
|
+
SUCCESS = "SUCCESS",
|
|
65
|
+
UNEXPECTED_ERROR = "UNEXPECTED_ERROR",
|
|
66
|
+
TRY_NEXT_BLOCK = "TRY_NEXT_BLOCK",
|
|
67
|
+
TRY_ON_BLOCK = "TRY_ON_BLOCK",
|
|
68
|
+
TRY_AT_EPOCH = "TRY_AT_DATE",
|
|
69
|
+
DONT_TRY_AGAIN = "DONT_TRY_AGAIN"
|
|
70
|
+
}
|
|
71
|
+
export interface PollResultSuccess {
|
|
72
|
+
readonly result: PollResultCode.SUCCESS;
|
|
73
|
+
readonly order: GPv2Order.DataStructOutput;
|
|
74
|
+
readonly signature: string;
|
|
75
|
+
}
|
|
76
|
+
export interface PollResultUnexpectedError {
|
|
77
|
+
readonly result: PollResultCode.UNEXPECTED_ERROR;
|
|
78
|
+
readonly error: unknown;
|
|
79
|
+
}
|
|
80
|
+
export interface PollResultTryNextBlock {
|
|
81
|
+
readonly result: PollResultCode.TRY_NEXT_BLOCK;
|
|
82
|
+
reason?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface PollResultTryOnBlock {
|
|
85
|
+
readonly result: PollResultCode.TRY_ON_BLOCK;
|
|
86
|
+
readonly blockNumber: number;
|
|
87
|
+
reason?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface PollResultTryAtEpoch {
|
|
90
|
+
readonly result: PollResultCode.TRY_AT_EPOCH;
|
|
91
|
+
/**
|
|
92
|
+
* The epoch after which it is ok to re-try to to poll this order.
|
|
93
|
+
* The value is expressed as a Unix timestamp (in seconds).
|
|
94
|
+
*
|
|
95
|
+
* This epoch will be inclusive, meaning that it is ok to re-try at the block mined pricesely at this epoch or later.
|
|
96
|
+
*/
|
|
97
|
+
readonly epoch: number;
|
|
98
|
+
reason?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface PollResultDontTryAgain {
|
|
101
|
+
readonly result: PollResultCode.DONT_TRY_AGAIN;
|
|
102
|
+
reason?: string;
|
|
103
|
+
}
|
|
104
|
+
export type IsValidResult = IsValid | IsNotValid;
|
|
105
|
+
export interface IsValid {
|
|
106
|
+
isValid: true;
|
|
107
|
+
}
|
|
108
|
+
export interface IsNotValid {
|
|
109
|
+
isValid: false;
|
|
110
|
+
reason: string;
|
|
111
|
+
}
|