πŸ—“οΈ Predicate
LimitOrderPredicateBuilder
A limit order can contain one or more predicates that indicate the logic of its validity. There are two types of predicate operators:

Conditional operators:

Name
Description
and
combine several predicates, return true when all predicates are valid
or
combine several predicates, return true when one of predicates is valid

Comparative operators:

All comparative operators have three arguments: (value: string, address: string, callData: string)
How the operators works: On an operator call, the contract execute the callData for the address and compare a result with the value
Name
Description
eq
a result must be equal to the value
lt
a result must be less than the value
gt
a result must be greater than the value

Built-in operators:

nonceEquals(makerAddress: string, makerNonce: number)
The predicate checks that the makerNonce is equal to the nonce of makerAddress
timestampBelow(timestamp: number)
The predicate checks that timestamp is greater than the current time

Example:

1
import {
2
LimitOrderProtocolFacade,
3
LimitOrderPredicateBuilder,
4
LimitOrderPredicateCallData
5
} from '@1inch/limit-order-protocol';
6
​
7
const makerAddress = '0x5fa31604fc5dcebfcac2481f9fa59d174126e5e6';
8
const tokenAddress = '0xsss...';
9
const balanceOfCallData = '0xccc...';
10
​
11
const limitOrderProtocolFacade = new LimitOrderProtocolFacade(...);
12
​
13
const limitOrderPredicateBuilder = new LimitOrderPredicateBuilder(
14
limitOrderProtocolFacade
15
);
16
​
17
const {or, and, timestampBelow, nonceEquals, gt, lt, eq} = predicateBuilder;
18
​
19
const simplePredicate: LimitOrderPredicateCallData = and(
20
timestampBelow(Math.round(Date.now() / 1000) + 60_000), // a limit order is valid only for 1 minute
21
nonceEquals(makerAddress, 4) // a limit order is valid until the nonce of makerAddress is equal to 4
22
);
23
​
24
const complexPredicate: LimitOrderPredicateCallData = or(
25
and(
26
timestampBelow(Math.round(Date.now() / 1000) + 60_000),
27
nonceEquals(makerAddress, 4),
28
gt('10', tokenAddress, balanceOfCallData)
29
),
30
or(
31
timestampBelow(5444440000),
32
lt('20', tokenAddress, balanceOfCallData)
33
),
34
eq('30', tokenAddress, balanceOfCallData)
35
);
Copied!
Last modified 3mo ago