@1inch/fusion-sdk 0.0.4 → 0.0.6
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/api/fusion-api.d.ts +25 -16
- package/api/fusion-api.js +36 -26
- package/api/index.d.ts +4 -4
- package/api/index.js +8 -8
- package/api/orders/index.d.ts +3 -3
- package/api/orders/index.js +7 -7
- package/api/orders/order-api.spec.d.ts +1 -1
- package/api/orders/order-api.spec.js +479 -395
- package/api/orders/order-api.spec.js.map +1 -1
- package/api/orders/orders.api.d.ts +24 -10
- package/api/orders/orders.api.js +30 -28
- package/api/orders/orders.request.d.ts +22 -18
- package/api/orders/orders.request.js +40 -31
- package/api/orders/types.d.ts +59 -57
- package/api/orders/types.js +17 -16
- package/api/orders/types.js.map +1 -1
- package/api/pagination.d.ts +7 -7
- package/api/pagination.js +10 -10
- package/api/pagination.spec.d.ts +1 -1
- package/api/pagination.spec.js +28 -21
- package/api/params.d.ts +3 -1
- package/api/params.js +25 -19
- package/api/quoter/index.d.ts +5 -5
- package/api/quoter/index.js +9 -9
- package/api/quoter/preset.d.ts +13 -13
- package/api/quoter/preset.js +19 -17
- package/api/quoter/quote/index.d.ts +3 -3
- package/api/quoter/quote/index.js +7 -7
- package/api/quoter/quote/order-params.d.ts +6 -6
- package/api/quoter/quote/order-params.js +12 -12
- package/api/quoter/quote/quote.d.ts +26 -21
- package/api/quoter/quote/quote.js +85 -52
- package/api/quoter/quote/quote.js.map +1 -1
- package/api/quoter/quote/types.d.ts +4 -4
- package/api/quoter/quote/types.js +3 -3
- package/api/quoter/quoter.api.d.ts +12 -9
- package/api/quoter/quoter.api.js +19 -19
- package/api/quoter/quoter.api.spec.d.ts +1 -1
- package/api/quoter/quoter.api.spec.js +32 -23
- package/api/quoter/quoter.api.spec.js.map +1 -1
- package/api/quoter/quoter.request.d.ts +11 -11
- package/api/quoter/quoter.request.js +28 -26
- package/api/quoter/types.d.ts +45 -44
- package/api/quoter/types.js +10 -10
- package/api/quoter/types.js.map +1 -1
- package/api/relayer/index.d.ts +3 -3
- package/api/relayer/index.js +7 -7
- package/api/relayer/relayer.api.d.ts +12 -9
- package/api/relayer/relayer.api.js +13 -13
- package/api/relayer/relayer.api.spec.d.ts +1 -1
- package/api/relayer/relayer.api.spec.js +96 -79
- package/api/relayer/relayer.request.d.ts +8 -8
- package/api/relayer/relayer.request.js +10 -10
- package/api/relayer/types.d.ts +9 -9
- package/api/relayer/types.js +3 -3
- package/api/types.d.ts +17 -15
- package/api/types.js +3 -3
- package/auction-calculator/auction-calculator.d.ts +22 -13
- package/auction-calculator/auction-calculator.js +70 -45
- package/auction-calculator/auction-calculator.spec.d.ts +1 -1
- package/auction-calculator/auction-calculator.spec.js +45 -32
- package/auction-calculator/calc.d.ts +8 -2
- package/auction-calculator/calc.js +12 -12
- package/auction-calculator/constants.d.ts +1 -1
- package/auction-calculator/constants.js +5 -5
- package/auction-calculator/index.d.ts +3 -3
- package/auction-calculator/index.js +7 -7
- package/auction-salt/auction-salt.d.ts +9 -9
- package/auction-salt/auction-salt.js +34 -23
- package/auction-salt/auction.salt.spec.d.ts +1 -1
- package/auction-salt/auction.salt.spec.js +38 -27
- package/auction-salt/index.d.ts +3 -3
- package/auction-salt/index.js +7 -7
- package/auction-salt/parser/constants.d.ts +9 -9
- package/auction-salt/parser/constants.js +33 -14
- package/auction-salt/parser/index.d.ts +2 -2
- package/auction-salt/parser/index.js +6 -6
- package/auction-salt/parser/parser.d.ts +6 -6
- package/auction-salt/parser/parser.js +33 -22
- package/auction-salt/types.d.ts +6 -6
- package/auction-salt/types.js +3 -3
- package/auction-suffix/auction-suffix.d.ts +9 -9
- package/auction-suffix/auction-suffix.js +36 -23
- package/auction-suffix/auction-suffix.spec.d.ts +1 -1
- package/auction-suffix/auction-suffix.spec.js +20 -15
- package/auction-suffix/constants.d.ts +1 -1
- package/auction-suffix/constants.js +5 -5
- package/auction-suffix/encoder.d.ts +15 -6
- package/auction-suffix/encoder.js +45 -28
- package/auction-suffix/index.d.ts +5 -5
- package/auction-suffix/index.js +9 -9
- package/auction-suffix/parser/constants.d.ts +13 -13
- package/auction-suffix/parser/constants.js +30 -17
- package/auction-suffix/parser/errors.d.ts +1 -2
- package/auction-suffix/parser/errors.js +6 -7
- package/auction-suffix/parser/index.d.ts +4 -4
- package/auction-suffix/parser/index.js +8 -8
- package/auction-suffix/parser/parser.d.ts +28 -8
- package/auction-suffix/parser/parser.js +162 -81
- package/auction-suffix/parser/types.d.ts +22 -22
- package/auction-suffix/parser/types.js +3 -3
- package/auction-suffix/types.d.ts +12 -12
- package/auction-suffix/types.js +3 -3
- package/connector/blockchain/blockchain-provider.connector.d.ts +6 -3
- package/connector/blockchain/blockchain-provider.connector.js +3 -3
- package/connector/blockchain/index.d.ts +3 -3
- package/connector/blockchain/index.js +7 -7
- package/connector/blockchain/private-key-provider.connector.d.ts +15 -10
- package/connector/blockchain/private-key-provider.connector.js +12 -12
- package/connector/blockchain/private-key-provider.connector.spec.d.ts +1 -1
- package/connector/blockchain/private-key-provider.connector.spec.js +36 -23
- package/connector/blockchain/web3-provider-connector.d.ts +13 -8
- package/connector/blockchain/web3-provider-connector.js +12 -9
- package/connector/blockchain/web3-provider.connector.spec.d.ts +1 -1
- package/connector/blockchain/web3-provider.connector.spec.js +37 -26
- package/connector/http/axios-provider.connector.d.ts +3 -3
- package/connector/http/axios-provider.connector.js +13 -13
- package/connector/http/axios-provider.connector.spec.d.ts +1 -1
- package/connector/http/axios-provider.connector.spec.js +37 -31
- package/connector/http/http-provider.connector.d.ts +2 -2
- package/connector/http/http-provider.connector.js +3 -3
- package/connector/http/index.d.ts +2 -2
- package/connector/http/index.js +6 -6
- package/connector/index.d.ts +2 -2
- package/connector/index.js +6 -6
- package/constants.d.ts +10 -6
- package/constants.js +23 -16
- package/fusion-order/fusion-order.d.ts +17 -7
- package/fusion-order/fusion-order.js +14 -12
- package/fusion-order/fusion-order.spec.d.ts +1 -1
- package/fusion-order/fusion-order.spec.js +27 -22
- package/fusion-order/index.d.ts +1 -1
- package/fusion-order/index.js +5 -5
- package/index.d.ts +11 -11
- package/index.js +15 -15
- package/limit-order/eip712/domain.d.ts +10 -9
- package/limit-order/eip712/domain.js +28 -23
- package/limit-order/eip712/eip712.types.d.ts +19 -15
- package/limit-order/eip712/eip712.types.js +3 -3
- package/limit-order/eip712/index.d.ts +3 -3
- package/limit-order/eip712/index.js +7 -7
- package/limit-order/eip712/order-typed-data-builder.d.ts +17 -6
- package/limit-order/eip712/order-typed-data-builder.js +34 -19
- package/limit-order/index.d.ts +4 -4
- package/limit-order/index.js +8 -8
- package/limit-order/interactions-factory.d.ts +1 -1
- package/limit-order/interactions-factory.js +6 -6
- package/limit-order/limit-order.d.ts +31 -25
- package/limit-order/limit-order.js +103 -50
- package/limit-order/limit-order.spec.d.ts +1 -1
- package/limit-order/limit-order.spec.js +75 -51
- package/limit-order/parser/constants.d.ts +9 -9
- package/limit-order/parser/constants.js +5 -5
- package/limit-order/parser/index.d.ts +3 -3
- package/limit-order/parser/index.js +7 -7
- package/limit-order/parser/parser.d.ts +5 -2
- package/limit-order/parser/parser.js +23 -18
- package/limit-order/parser/types.d.ts +3 -3
- package/limit-order/parser/types.js +3 -3
- package/limit-order/predicate-factory.d.ts +9 -5
- package/limit-order/predicate-factory.js +40 -24
- package/limit-order/predicate-factory.spec.d.ts +1 -1
- package/limit-order/predicate-factory.spec.js +44 -29
- package/limit-order/types.d.ts +29 -29
- package/limit-order/types.js +3 -3
- package/limit-order/utils.d.ts +1 -1
- package/limit-order/utils.js +6 -6
- package/package.json +2 -3
- package/sdk/index.d.ts +2 -2
- package/sdk/index.js +6 -6
- package/sdk/sdk.d.ts +29 -11
- package/sdk/sdk.js +48 -38
- package/sdk/types.d.ts +27 -27
- package/sdk/types.js +3 -3
- package/settlement/encoders/constants.d.ts +1 -1
- package/settlement/encoders/constants.js +5 -5
- package/settlement/encoders/fill-order.encoder.d.ts +2 -2
- package/settlement/encoders/fill-order.encoder.js +26 -12
- package/settlement/encoders/index.d.ts +3 -3
- package/settlement/encoders/index.js +7 -7
- package/settlement/encoders/settlement.encoder.d.ts +13 -4
- package/settlement/encoders/settlement.encoder.js +41 -19
- package/settlement/index.d.ts +4 -4
- package/settlement/index.js +8 -8
- package/settlement/settlement.d.ts +8 -5
- package/settlement/settlement.js +28 -14
- package/settlement/settlement.spec.d.ts +1 -1
- package/settlement/settlement.spec.js +45 -35
- package/settlement/signature-patcher.d.ts +1 -1
- package/settlement/signature-patcher.js +19 -16
- package/settlement/types.d.ts +13 -13
- package/settlement/types.js +3 -3
- package/utils.d.ts +6 -6
- package/utils.js +29 -23
- package/validations.d.ts +2 -2
- package/validations.js +14 -15
|
@@ -1,48 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.LimitOrder = void 0
|
|
4
|
-
const utils_1 = require(
|
|
5
|
-
const eip712_1 = require(
|
|
6
|
-
const constants_1 = require(
|
|
7
|
-
const utils_2 = require(
|
|
8
|
-
const parser_1 = require(
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
exports.LimitOrder = void 0
|
|
4
|
+
const utils_1 = require('../utils')
|
|
5
|
+
const eip712_1 = require('./eip712')
|
|
6
|
+
const constants_1 = require('../constants')
|
|
7
|
+
const utils_2 = require('./utils')
|
|
8
|
+
const parser_1 = require('./parser/parser')
|
|
9
9
|
class LimitOrder {
|
|
10
10
|
constructor(orderInfo, interactions) {
|
|
11
|
-
this.makerAsset = orderInfo.makerAsset
|
|
12
|
-
this.takerAsset = orderInfo.takerAsset
|
|
13
|
-
this.makingAmount = orderInfo.makingAmount
|
|
14
|
-
this.takingAmount = orderInfo.takingAmount
|
|
15
|
-
this.salt = orderInfo.salt || (0, utils_2.buildSalt)()
|
|
16
|
-
this.from = orderInfo.maker
|
|
17
|
-
this.allowedSender = orderInfo.allowedSender || constants_1.ZERO_ADDRESS
|
|
18
|
-
this.receiver = orderInfo.receiver || constants_1.ZERO_ADDRESS
|
|
19
|
-
this.makerAssetData =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
this.makerAsset = orderInfo.makerAsset
|
|
12
|
+
this.takerAsset = orderInfo.takerAsset
|
|
13
|
+
this.makingAmount = orderInfo.makingAmount
|
|
14
|
+
this.takingAmount = orderInfo.takingAmount
|
|
15
|
+
this.salt = orderInfo.salt || (0, utils_2.buildSalt)()
|
|
16
|
+
this.from = orderInfo.maker
|
|
17
|
+
this.allowedSender = orderInfo.allowedSender || constants_1.ZERO_ADDRESS
|
|
18
|
+
this.receiver = orderInfo.receiver || constants_1.ZERO_ADDRESS
|
|
19
|
+
this.makerAssetData =
|
|
20
|
+
(interactions === null || interactions === void 0
|
|
21
|
+
? void 0
|
|
22
|
+
: interactions.makerAssetData) || constants_1.ZX
|
|
23
|
+
this.takerAssetData =
|
|
24
|
+
(interactions === null || interactions === void 0
|
|
25
|
+
? void 0
|
|
26
|
+
: interactions.takerAssetData) || constants_1.ZX
|
|
27
|
+
this.getMakingAmount =
|
|
28
|
+
(interactions === null || interactions === void 0
|
|
29
|
+
? void 0
|
|
30
|
+
: interactions.getMakingAmount) || constants_1.ZX
|
|
31
|
+
this.getTakingAmount =
|
|
32
|
+
(interactions === null || interactions === void 0
|
|
33
|
+
? void 0
|
|
34
|
+
: interactions.getTakingAmount) || constants_1.ZX
|
|
35
|
+
this.predicate =
|
|
36
|
+
(interactions === null || interactions === void 0
|
|
37
|
+
? void 0
|
|
38
|
+
: interactions.predicate) || constants_1.ZX
|
|
39
|
+
this.permit =
|
|
40
|
+
(interactions === null || interactions === void 0
|
|
41
|
+
? void 0
|
|
42
|
+
: interactions.permit) || constants_1.ZX
|
|
43
|
+
this.preInteraction =
|
|
44
|
+
(interactions === null || interactions === void 0
|
|
45
|
+
? void 0
|
|
46
|
+
: interactions.preInteraction) || constants_1.ZX
|
|
47
|
+
this.postInteraction =
|
|
48
|
+
(interactions === null || interactions === void 0
|
|
49
|
+
? void 0
|
|
50
|
+
: interactions.postInteraction) || constants_1.ZX
|
|
27
51
|
}
|
|
28
|
-
static getOrderHash(
|
|
29
|
-
|
|
52
|
+
static getOrderHash(
|
|
53
|
+
order,
|
|
54
|
+
domain = (0, eip712_1.getLimitOrderV3Domain)(1)
|
|
55
|
+
) {
|
|
56
|
+
return (0, eip712_1.getOrderHash)(
|
|
57
|
+
LimitOrder.getTypedData(order, domain)
|
|
58
|
+
)
|
|
30
59
|
}
|
|
31
|
-
static getTypedData(
|
|
32
|
-
|
|
60
|
+
static getTypedData(
|
|
61
|
+
order,
|
|
62
|
+
domain = (0, eip712_1.getLimitOrderV3Domain)(1)
|
|
63
|
+
) {
|
|
64
|
+
return (0, eip712_1.buildOrderData)(
|
|
65
|
+
domain.chainId,
|
|
66
|
+
domain.verifyingContract,
|
|
67
|
+
domain.name,
|
|
68
|
+
domain.version,
|
|
69
|
+
order
|
|
70
|
+
)
|
|
33
71
|
}
|
|
34
72
|
static decode(struct) {
|
|
35
|
-
const interactions = (0, parser_1.parseInteractions)(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
const interactions = (0, parser_1.parseInteractions)(
|
|
74
|
+
struct.offsets,
|
|
75
|
+
struct.interactions
|
|
76
|
+
)
|
|
77
|
+
return new LimitOrder(
|
|
78
|
+
{
|
|
79
|
+
makerAsset: struct.makerAsset,
|
|
80
|
+
takerAsset: struct.takerAsset,
|
|
81
|
+
maker: struct.maker,
|
|
82
|
+
takingAmount: struct.takingAmount,
|
|
83
|
+
makingAmount: struct.makingAmount,
|
|
84
|
+
allowedSender: struct.allowedSender,
|
|
85
|
+
receiver: struct.receiver,
|
|
86
|
+
salt: struct.salt
|
|
87
|
+
},
|
|
88
|
+
interactions
|
|
89
|
+
)
|
|
46
90
|
}
|
|
47
91
|
build() {
|
|
48
92
|
const allInteractions = [
|
|
@@ -54,17 +98,20 @@ class LimitOrder {
|
|
|
54
98
|
this.permit,
|
|
55
99
|
this.preInteraction,
|
|
56
100
|
this.postInteraction
|
|
57
|
-
]
|
|
101
|
+
]
|
|
58
102
|
// https://stackoverflow.com/a/55261098/440168
|
|
59
103
|
const cumulativeSum = ((sum) => (value) => {
|
|
60
|
-
sum += value
|
|
61
|
-
return sum
|
|
62
|
-
})(0)
|
|
104
|
+
sum += value
|
|
105
|
+
return sum
|
|
106
|
+
})(0)
|
|
63
107
|
const offsets = allInteractions
|
|
64
108
|
.map((a) => a.length / 2 - 1)
|
|
65
109
|
.map(cumulativeSum)
|
|
66
|
-
.reduce(
|
|
67
|
-
|
|
110
|
+
.reduce(
|
|
111
|
+
(acc, a, i) => acc.add((0, utils_1.toBN)(a).shln(32 * i)),
|
|
112
|
+
(0, utils_1.toBN)(0)
|
|
113
|
+
)
|
|
114
|
+
const interactions = '0x' + allInteractions.map(utils_1.trim0x).join('')
|
|
68
115
|
return {
|
|
69
116
|
salt: this.salt,
|
|
70
117
|
makerAsset: this.makerAsset,
|
|
@@ -76,14 +123,20 @@ class LimitOrder {
|
|
|
76
123
|
takingAmount: this.takingAmount,
|
|
77
124
|
offsets: offsets.toString(),
|
|
78
125
|
interactions
|
|
79
|
-
}
|
|
126
|
+
}
|
|
80
127
|
}
|
|
81
128
|
getTypedData(domain = (0, eip712_1.getLimitOrderV3Domain)(1)) {
|
|
82
|
-
return (0, eip712_1.buildOrderData)(
|
|
129
|
+
return (0, eip712_1.buildOrderData)(
|
|
130
|
+
domain.chainId,
|
|
131
|
+
domain.verifyingContract,
|
|
132
|
+
domain.name,
|
|
133
|
+
domain.version,
|
|
134
|
+
this.build()
|
|
135
|
+
)
|
|
83
136
|
}
|
|
84
137
|
getOrderHash(domain = (0, eip712_1.getLimitOrderV3Domain)(1)) {
|
|
85
|
-
return (0, eip712_1.getOrderHash)(this.getTypedData(domain))
|
|
138
|
+
return (0, eip712_1.getOrderHash)(this.getTypedData(domain))
|
|
86
139
|
}
|
|
87
140
|
}
|
|
88
|
-
exports.LimitOrder = LimitOrder
|
|
89
|
-
//# sourceMappingURL=limit-order.js.map
|
|
141
|
+
exports.LimitOrder = LimitOrder
|
|
142
|
+
//# sourceMappingURL=limit-order.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {}
|
|
1
|
+
export {}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const limit_order_1 = require(
|
|
4
|
-
const predicate_factory_1 = require(
|
|
5
|
-
const interactions_factory_1 = require(
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
const limit_order_1 = require('./limit-order')
|
|
4
|
+
const predicate_factory_1 = require('./predicate-factory')
|
|
5
|
+
const interactions_factory_1 = require('./interactions-factory')
|
|
6
6
|
describe('Limit Order', () => {
|
|
7
|
-
jest.spyOn(Math, 'random').mockReturnValue(1)
|
|
8
|
-
jest.spyOn(Date, 'now').mockReturnValue(1673549418040)
|
|
7
|
+
jest.spyOn(Math, 'random').mockReturnValue(1)
|
|
8
|
+
jest.spyOn(Date, 'now').mockReturnValue(1673549418040)
|
|
9
9
|
it('should create limit order', () => {
|
|
10
10
|
const order = new limit_order_1.LimitOrder({
|
|
11
11
|
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -13,7 +13,7 @@ describe('Limit Order', () => {
|
|
|
13
13
|
makingAmount: '1000000000000000000',
|
|
14
14
|
takingAmount: '1420000000',
|
|
15
15
|
maker: '0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
16
|
-
})
|
|
16
|
+
})
|
|
17
17
|
expect(order.build()).toStrictEqual({
|
|
18
18
|
allowedSender: '0x0000000000000000000000000000000000000000',
|
|
19
19
|
interactions: '0x',
|
|
@@ -25,71 +25,93 @@ describe('Limit Order', () => {
|
|
|
25
25
|
salt: '1673549418040',
|
|
26
26
|
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
27
27
|
takingAmount: '1420000000'
|
|
28
|
-
})
|
|
29
|
-
})
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
30
|
it('should create limit order with timestampBelow predicate', () => {
|
|
31
|
-
const order = new limit_order_1.LimitOrder(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const order = new limit_order_1.LimitOrder(
|
|
32
|
+
{
|
|
33
|
+
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
34
|
+
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
35
|
+
makingAmount: '1000000000000000000',
|
|
36
|
+
takingAmount: '1420000000',
|
|
37
|
+
maker: '0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
predicate:
|
|
41
|
+
predicate_factory_1.PredicateFactory.timestampBelow(
|
|
42
|
+
1673549418
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
)
|
|
40
46
|
expect(order.build()).toStrictEqual({
|
|
41
47
|
allowedSender: '0x0000000000000000000000000000000000000000',
|
|
42
|
-
interactions:
|
|
48
|
+
interactions:
|
|
49
|
+
'0x63592c2b0000000000000000000000000000000000000000000000000000000063c0566a',
|
|
43
50
|
maker: '0x00000000219ab540356cbb839cbe05303d7705fa',
|
|
44
51
|
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
45
52
|
makingAmount: '1000000000000000000',
|
|
46
|
-
offsets:
|
|
53
|
+
offsets:
|
|
54
|
+
'970558080243398695134547109586957793750899628853613079895592438595584',
|
|
47
55
|
receiver: '0x0000000000000000000000000000000000000000',
|
|
48
56
|
salt: '1673549418040',
|
|
49
57
|
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
50
58
|
takingAmount: '1420000000'
|
|
51
|
-
})
|
|
52
|
-
})
|
|
59
|
+
})
|
|
60
|
+
})
|
|
53
61
|
it('should create limit order with timestampBelow predicate that will unwrap maker weth to eth', () => {
|
|
54
|
-
const order = new limit_order_1.LimitOrder(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const order = new limit_order_1.LimitOrder(
|
|
63
|
+
{
|
|
64
|
+
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
65
|
+
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
66
|
+
makingAmount: '1000000000000000000',
|
|
67
|
+
takingAmount: '1420000000',
|
|
68
|
+
maker: '0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
predicate:
|
|
72
|
+
predicate_factory_1.PredicateFactory.timestampBelow(
|
|
73
|
+
1673549418
|
|
74
|
+
),
|
|
75
|
+
postInteraction:
|
|
76
|
+
interactions_factory_1.InteractionsFactory.unwrap(
|
|
77
|
+
'0x08b067ad41e45babe5bbb52fc2fe7f692f628b06',
|
|
78
|
+
'0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
)
|
|
64
82
|
expect(order.build()).toStrictEqual({
|
|
65
83
|
allowedSender: '0x0000000000000000000000000000000000000000',
|
|
66
|
-
interactions:
|
|
84
|
+
interactions:
|
|
85
|
+
'0x63592c2b0000000000000000000000000000000000000000000000000000000063c0566a08b067ad41e45babe5bbb52fc2fe7f692f628b0600000000219ab540356cbb839cbe05303d7705fa',
|
|
67
86
|
maker: '0x00000000219ab540356cbb839cbe05303d7705fa',
|
|
68
87
|
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
69
88
|
makingAmount: '1000000000000000000',
|
|
70
|
-
offsets:
|
|
89
|
+
offsets:
|
|
90
|
+
'2048955946929424286921227713067743020696385405755235979139736848564224',
|
|
71
91
|
receiver: '0x0000000000000000000000000000000000000000',
|
|
72
92
|
salt: '1673549418040',
|
|
73
93
|
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
74
94
|
takingAmount: '1420000000'
|
|
75
|
-
})
|
|
76
|
-
})
|
|
95
|
+
})
|
|
96
|
+
})
|
|
77
97
|
it('should decode limit order struct', () => {
|
|
78
98
|
const orderStruct = {
|
|
79
99
|
allowedSender: '0x0000000000000000000000000000000000000000',
|
|
80
|
-
interactions:
|
|
100
|
+
interactions:
|
|
101
|
+
'0x63592c2b0000000000000000000000000000000000000000000000000000000063c0566a08b067ad41e45babe5bbb52fc2fe7f692f628b0600000000219ab540356cbb839cbe05303d7705fa',
|
|
81
102
|
maker: '0x00000000219ab540356cbb839cbe05303d7705fa',
|
|
82
103
|
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
83
104
|
makingAmount: '1000000000000000000',
|
|
84
|
-
offsets:
|
|
105
|
+
offsets:
|
|
106
|
+
'2048955946929424286921227713067743020696385405755235979139736848564224',
|
|
85
107
|
receiver: '0x0000000000000000000000000000000000000000',
|
|
86
108
|
salt: '1673549418040',
|
|
87
109
|
takerAsset: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
88
110
|
takingAmount: '1420000000'
|
|
89
|
-
}
|
|
90
|
-
const order = limit_order_1.LimitOrder.decode(orderStruct)
|
|
91
|
-
expect(order.build()).toStrictEqual(orderStruct)
|
|
92
|
-
})
|
|
111
|
+
}
|
|
112
|
+
const order = limit_order_1.LimitOrder.decode(orderStruct)
|
|
113
|
+
expect(order.build()).toStrictEqual(orderStruct)
|
|
114
|
+
})
|
|
93
115
|
it('should get limit order typed data', () => {
|
|
94
116
|
const order = new limit_order_1.LimitOrder({
|
|
95
117
|
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -97,7 +119,7 @@ describe('Limit Order', () => {
|
|
|
97
119
|
makingAmount: '1000000000000000000',
|
|
98
120
|
takingAmount: '1420000000',
|
|
99
121
|
maker: '0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
100
|
-
})
|
|
122
|
+
})
|
|
101
123
|
expect(order.getTypedData()).toStrictEqual({
|
|
102
124
|
domain: {
|
|
103
125
|
chainId: 1,
|
|
@@ -180,8 +202,8 @@ describe('Limit Order', () => {
|
|
|
180
202
|
}
|
|
181
203
|
]
|
|
182
204
|
}
|
|
183
|
-
})
|
|
184
|
-
})
|
|
205
|
+
})
|
|
206
|
+
})
|
|
185
207
|
it('should get limit order hash', () => {
|
|
186
208
|
const order = new limit_order_1.LimitOrder({
|
|
187
209
|
makerAsset: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -189,8 +211,10 @@ describe('Limit Order', () => {
|
|
|
189
211
|
makingAmount: '1000000000000000000',
|
|
190
212
|
takingAmount: '1420000000',
|
|
191
213
|
maker: '0x00000000219ab540356cbb839cbe05303d7705fa'
|
|
192
|
-
})
|
|
193
|
-
expect(order.getOrderHash()).toBe(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
214
|
+
})
|
|
215
|
+
expect(order.getOrderHash()).toBe(
|
|
216
|
+
'0x4bdb758d3d4b265367c461cdb12b2fbe92fd8f2bcc9423393e9da4490d6157c4'
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
//# sourceMappingURL=limit-order.spec.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const DynamicField: {
|
|
2
|
-
readonly makerAssetData: 0
|
|
3
|
-
readonly takerAssetData: 1
|
|
4
|
-
readonly getMakingAmount: 2
|
|
5
|
-
readonly getTakingAmount: 3
|
|
6
|
-
readonly predicate: 4
|
|
7
|
-
readonly permit: 5
|
|
8
|
-
readonly preInteraction: 6
|
|
9
|
-
readonly postInteraction: 7
|
|
10
|
-
}
|
|
2
|
+
readonly makerAssetData: 0
|
|
3
|
+
readonly takerAssetData: 1
|
|
4
|
+
readonly getMakingAmount: 2
|
|
5
|
+
readonly getTakingAmount: 3
|
|
6
|
+
readonly predicate: 4
|
|
7
|
+
readonly permit: 5
|
|
8
|
+
readonly preInteraction: 6
|
|
9
|
+
readonly postInteraction: 7
|
|
10
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.DynamicField = void 0
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
exports.DynamicField = void 0
|
|
4
4
|
exports.DynamicField = {
|
|
5
5
|
makerAssetData: 0,
|
|
6
6
|
takerAssetData: 1,
|
|
@@ -10,5 +10,5 @@ exports.DynamicField = {
|
|
|
10
10
|
permit: 5,
|
|
11
11
|
preInteraction: 6,
|
|
12
12
|
postInteraction: 7
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=constants.js.map
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './parser'
|
|
2
|
-
export * from './types'
|
|
3
|
-
export * from './constants'
|
|
1
|
+
export * from './parser'
|
|
2
|
+
export * from './types'
|
|
3
|
+
export * from './constants'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const tslib_1 = require(
|
|
4
|
-
tslib_1.__exportStar(require(
|
|
5
|
-
tslib_1.__exportStar(require(
|
|
6
|
-
tslib_1.__exportStar(require(
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
const tslib_1 = require('tslib')
|
|
4
|
+
tslib_1.__exportStar(require('./parser'), exports)
|
|
5
|
+
tslib_1.__exportStar(require('./types'), exports)
|
|
6
|
+
tslib_1.__exportStar(require('./constants'), exports)
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function parseInteractions(
|
|
1
|
+
import {ParsedInteractions} from './types'
|
|
2
|
+
export declare function parseInteractions(
|
|
3
|
+
offsets: string,
|
|
4
|
+
interactions: string
|
|
5
|
+
): ParsedInteractions
|
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.parseInteractions = void 0
|
|
4
|
-
const utils_1 = require(
|
|
5
|
-
const constants_1 = require(
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
exports.parseInteractions = void 0
|
|
4
|
+
const utils_1 = require('../../utils')
|
|
5
|
+
const constants_1 = require('./constants')
|
|
6
6
|
function parseInteractions(offsets, interactions) {
|
|
7
|
-
const offsetsBN = (0, utils_1.toBN)(offsets)
|
|
8
|
-
const parsedInteractions = {}
|
|
9
|
-
interactions = (0, utils_1.trim0x)(interactions)
|
|
7
|
+
const offsetsBN = (0, utils_1.toBN)(offsets)
|
|
8
|
+
const parsedInteractions = {}
|
|
9
|
+
interactions = (0, utils_1.trim0x)(interactions)
|
|
10
10
|
for (const interactionName in constants_1.DynamicField) {
|
|
11
|
-
const field = interactionName
|
|
12
|
-
parsedInteractions[field] = parseInteractionForField(
|
|
11
|
+
const field = interactionName
|
|
12
|
+
parsedInteractions[field] = parseInteractionForField(
|
|
13
|
+
offsetsBN,
|
|
14
|
+
interactions,
|
|
15
|
+
constants_1.DynamicField[field]
|
|
16
|
+
)
|
|
13
17
|
}
|
|
14
|
-
return parsedInteractions
|
|
18
|
+
return parsedInteractions
|
|
15
19
|
}
|
|
16
|
-
exports.parseInteractions = parseInteractions
|
|
20
|
+
exports.parseInteractions = parseInteractions
|
|
17
21
|
function parseInteractionForField(offsets, interactions, field) {
|
|
18
|
-
const {
|
|
19
|
-
return '0x' + interactions.slice(fromByte * 2, toByte * 2)
|
|
22
|
+
const {fromByte, toByte} = getOffsetForInteraction(offsets, field)
|
|
23
|
+
return '0x' + interactions.slice(fromByte * 2, toByte * 2)
|
|
20
24
|
}
|
|
21
25
|
function getOffsetForInteraction(offsets, field) {
|
|
22
|
-
const fromByteBN =
|
|
23
|
-
|
|
26
|
+
const fromByteBN =
|
|
27
|
+
field === 0 ? '0' : offsets.shrn((field - 1) * 32).maskn(32)
|
|
28
|
+
const toByteBN = offsets.shrn(field * 32).maskn(32)
|
|
24
29
|
return {
|
|
25
30
|
fromByte: parseInt(fromByteBN.toString()),
|
|
26
31
|
toByte: parseInt(toByteBN.toString())
|
|
27
|
-
}
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
|
-
//# sourceMappingURL=parser.js.map
|
|
34
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare type InteractionField = keyof typeof DynamicField
|
|
3
|
-
export declare type ParsedInteractions = Record<InteractionField, string
|
|
1
|
+
import {DynamicField} from './constants'
|
|
2
|
+
export declare type InteractionField = keyof typeof DynamicField
|
|
3
|
+
export declare type ParsedInteractions = Record<InteractionField, string>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', {value: true})
|
|
3
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -2,24 +2,28 @@ export declare class PredicateFactory {
|
|
|
2
2
|
/**
|
|
3
3
|
* timestampBelow(uint256)
|
|
4
4
|
*/
|
|
5
|
-
private static TIMESTAMP_BELOW_SELECTOR
|
|
5
|
+
private static TIMESTAMP_BELOW_SELECTOR
|
|
6
6
|
/**
|
|
7
7
|
* timestampBelowAndNonceEquals(uint256 timeNonceAccount)
|
|
8
8
|
*/
|
|
9
|
-
private static TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR
|
|
9
|
+
private static TIMESTAMP_BELOW_AND_NONCE_EQUALS_SELECTOR
|
|
10
10
|
/**
|
|
11
11
|
* @param deadline timestamp in seconds (order expiration time)
|
|
12
12
|
*/
|
|
13
|
-
static timestampBelow(deadline: number): string
|
|
13
|
+
static timestampBelow(deadline: number): string
|
|
14
14
|
/**
|
|
15
15
|
* @param address limit order creator address
|
|
16
16
|
* @param nonce sequence number for order cancellation
|
|
17
17
|
* @param deadline timestamp in seconds (order expiration time)
|
|
18
18
|
*/
|
|
19
|
-
static timestampBelowAndNonceEquals(
|
|
19
|
+
static timestampBelowAndNonceEquals(
|
|
20
|
+
address: string,
|
|
21
|
+
nonce: string | number,
|
|
22
|
+
deadline: number
|
|
23
|
+
): string
|
|
20
24
|
/**
|
|
21
25
|
* @param predicate predicate field from parsed order's interactions
|
|
22
26
|
* @returns {number} expiration time in seconds in case it exists in predicate
|
|
23
27
|
*/
|
|
24
|
-
static parseExpirationTime(predicate: string): number | null
|
|
28
|
+
static parseExpirationTime(predicate: string): number | null
|
|
25
29
|
}
|