1
- import { Order } from " ./types"
2
- import { WyvernProtocol } from " wyvern-js"
3
- import { NULL_ADDRESS } from './constants'
1
+ import { Order } from ' ./types'
2
+ import { WyvernProtocol } from ' wyvern-js'
3
+ import { NULL_ADDRESS } from './constants'
4
4
5
5
export const MAX_ERROR_LENGTH = 120
6
6
@@ -13,17 +13,17 @@ enum Side { Buy, Sell }
13
13
enum SaleKind { FixedPrice , DutchAuction }
14
14
15
15
const SaleKindInterface = {
16
- Side,
17
- SaleKind,
16
+ Side,
17
+ SaleKind,
18
18
19
- validateParameters ( saleKind : SaleKind , expirationTime : number ) : boolean {
20
- return ( saleKind === SaleKind . FixedPrice || expirationTime > 0 )
21
- } ,
19
+ validateParameters ( saleKind : SaleKind , expirationTime : number ) : boolean {
20
+ return ( saleKind === SaleKind . FixedPrice || expirationTime > 0 )
21
+ } ,
22
22
23
- canSettleOrder ( listingTime : number , expirationTime : number ) : boolean {
24
- const now = Math . round ( Date . now ( ) / 1000 )
25
- return ( listingTime < now ) && ( expirationTime === 0 || now < expirationTime )
26
- }
23
+ canSettleOrder ( listingTime : number , expirationTime : number ) : boolean {
24
+ const now = Math . round ( Date . now ( ) / 1000 )
25
+ return ( listingTime < now ) && ( expirationTime === 0 || now < expirationTime )
26
+ }
27
27
}
28
28
29
29
/**
@@ -34,67 +34,67 @@ const SaleKindInterface = {
34
34
export async function requireOrdersCanMatch (
35
35
client : WyvernProtocol ,
36
36
{ buy, sell, accountAddress} :
37
- { buy : Order , sell : Order , accountAddress : string }
38
- ) {
39
- const result = await client . wyvernExchange . ordersCanMatch_ . callAsync (
40
- [ buy . exchange , buy . maker , buy . taker , buy . feeRecipient , buy . target , buy . staticTarget , buy . paymentToken , sell . exchange , sell . maker , sell . taker , sell . feeRecipient , sell . target , sell . staticTarget , sell . paymentToken ] ,
41
- [ buy . makerRelayerFee , buy . takerRelayerFee , buy . makerProtocolFee , buy . takerProtocolFee , buy . basePrice , buy . extra , buy . listingTime , buy . expirationTime , buy . salt , sell . makerRelayerFee , sell . takerRelayerFee , sell . makerProtocolFee , sell . takerProtocolFee , sell . basePrice , sell . extra , sell . listingTime , sell . expirationTime , sell . salt ] ,
42
- [ buy . feeMethod , buy . side , buy . saleKind , buy . howToCall , sell . feeMethod , sell . side , sell . saleKind , sell . howToCall ] ,
43
- buy . calldata ,
44
- sell . calldata ,
45
- buy . replacementPattern ,
46
- sell . replacementPattern ,
47
- buy . staticExtradata ,
48
- sell . staticExtradata ,
49
- { from : accountAddress } ,
50
- )
51
-
52
- if ( result ) {
53
- return
54
- }
55
-
56
- if ( ! ( + buy . side == + SaleKindInterface . Side . Buy && + sell . side == + SaleKindInterface . Side . Sell ) ) {
57
- throw new Error ( 'Must be opposite-side' )
58
- }
59
-
60
- if ( ! ( buy . feeMethod == sell . feeMethod ) ) {
61
- throw new Error ( 'Must use same fee method' )
62
- }
63
-
64
- if ( ! ( buy . paymentToken == sell . paymentToken ) ) {
65
- throw new Error ( 'Must use same payment token' )
66
- }
67
-
68
- if ( ! ( sell . taker == NULL_ADDRESS || sell . taker == buy . maker ) ) {
69
- throw new Error ( 'Sell taker must be null or matching buy maker' )
70
- }
71
-
72
- if ( ! ( buy . taker == NULL_ADDRESS || buy . taker == sell . maker ) ) {
73
- throw new Error ( 'Buy taker must be null or matching sell maker' )
74
- }
75
-
76
- if ( ! ( ( sell . feeRecipient == NULL_ADDRESS && buy . feeRecipient != NULL_ADDRESS ) || ( sell . feeRecipient != NULL_ADDRESS && buy . feeRecipient == NULL_ADDRESS ) ) ) {
77
- throw new Error ( 'One order must be maker and the other must be taker' )
78
- }
79
-
80
- if ( ! ( buy . target == sell . target ) ) {
81
- throw new Error ( 'Must match target' )
82
- }
83
-
84
- if ( ! ( buy . howToCall == sell . howToCall ) ) {
85
- throw new Error ( 'Must match howToCall' )
86
- }
87
-
88
- if ( ! SaleKindInterface . canSettleOrder ( + buy . listingTime , + buy . expirationTime ) ) {
89
- throw new Error ( `Buy-side order is set in the future or expired` )
90
- }
91
-
92
- if ( ! SaleKindInterface . canSettleOrder ( + sell . listingTime , + sell . expirationTime ) ) {
93
- throw new Error ( `Sell-side order is set in the future or expired` )
94
- }
95
-
96
- // Handle default
97
- throw new Error ( 'Unable to match offer with auction' )
37
+ { buy : Order , sell : Order , accountAddress : string }
38
+ ) {
39
+ const result = await client . wyvernExchange . ordersCanMatch_ . callAsync (
40
+ [ buy . exchange , buy . maker , buy . taker , buy . feeRecipient , buy . target , buy . staticTarget , buy . paymentToken , sell . exchange , sell . maker , sell . taker , sell . feeRecipient , sell . target , sell . staticTarget , sell . paymentToken ] ,
41
+ [ buy . makerRelayerFee , buy . takerRelayerFee , buy . makerProtocolFee , buy . takerProtocolFee , buy . basePrice , buy . extra , buy . listingTime , buy . expirationTime , buy . salt , sell . makerRelayerFee , sell . takerRelayerFee , sell . makerProtocolFee , sell . takerProtocolFee , sell . basePrice , sell . extra , sell . listingTime , sell . expirationTime , sell . salt ] ,
42
+ [ buy . feeMethod , buy . side , buy . saleKind , buy . howToCall , sell . feeMethod , sell . side , sell . saleKind , sell . howToCall ] ,
43
+ buy . calldata ,
44
+ sell . calldata ,
45
+ buy . replacementPattern ,
46
+ sell . replacementPattern ,
47
+ buy . staticExtradata ,
48
+ sell . staticExtradata ,
49
+ { from : accountAddress } ,
50
+ )
51
+
52
+ if ( result ) {
53
+ return
54
+ }
55
+
56
+ if ( ! ( + buy . side == + SaleKindInterface . Side . Buy && + sell . side == + SaleKindInterface . Side . Sell ) ) {
57
+ throw new Error ( 'Must be opposite-side' )
58
+ }
59
+
60
+ if ( ! ( buy . feeMethod == sell . feeMethod ) ) {
61
+ throw new Error ( 'Must use same fee method' )
62
+ }
63
+
64
+ if ( ! ( buy . paymentToken == sell . paymentToken ) ) {
65
+ throw new Error ( 'Must use same payment token' )
66
+ }
67
+
68
+ if ( ! ( sell . taker == NULL_ADDRESS || sell . taker == buy . maker ) ) {
69
+ throw new Error ( 'Sell taker must be null or matching buy maker' )
70
+ }
71
+
72
+ if ( ! ( buy . taker == NULL_ADDRESS || buy . taker == sell . maker ) ) {
73
+ throw new Error ( 'Buy taker must be null or matching sell maker' )
74
+ }
75
+
76
+ if ( ! ( ( sell . feeRecipient == NULL_ADDRESS && buy . feeRecipient != NULL_ADDRESS ) || ( sell . feeRecipient != NULL_ADDRESS && buy . feeRecipient == NULL_ADDRESS ) ) ) {
77
+ throw new Error ( 'One order must be maker and the other must be taker' )
78
+ }
79
+
80
+ if ( ! ( buy . target == sell . target ) ) {
81
+ throw new Error ( 'Must match target' )
82
+ }
83
+
84
+ if ( ! ( buy . howToCall == sell . howToCall ) ) {
85
+ throw new Error ( 'Must match howToCall' )
86
+ }
87
+
88
+ if ( ! SaleKindInterface . canSettleOrder ( + buy . listingTime , + buy . expirationTime ) ) {
89
+ throw new Error ( `Buy-side order is set in the future or expired` )
90
+ }
91
+
92
+ if ( ! SaleKindInterface . canSettleOrder ( + sell . listingTime , + sell . expirationTime ) ) {
93
+ throw new Error ( `Sell-side order is set in the future or expired` )
94
+ }
95
+
96
+ // Handle default
97
+ throw new Error ( 'Unable to match offer with auction' )
98
98
}
99
99
100
100
/**
@@ -104,12 +104,12 @@ export async function requireOrdersCanMatch(
104
104
*/
105
105
export async function requireOrderCalldataCanMatch (
106
106
client : WyvernProtocol ,
107
- { buy, sell } :
108
- { buy : Order , sell : Order }
109
- ) {
110
- const result = client . wyvernExchange . orderCalldataCanMatch . callAsync ( buy . calldata , buy . replacementPattern , sell . calldata , sell . replacementPattern )
111
- if ( result ) {
112
- return
113
- }
114
- throw new Error ( 'Unable to match offer data with auction data.' )
107
+ { buy, sell} :
108
+ { buy : Order , sell : Order }
109
+ ) {
110
+ const result = client . wyvernExchange . orderCalldataCanMatch . callAsync ( buy . calldata , buy . replacementPattern , sell . calldata , sell . replacementPattern )
111
+ if ( result ) {
112
+ return
113
+ }
114
+ throw new Error ( 'Unable to match offer data with auction data.' )
115
115
}
0 commit comments