@opensea/seaport-js 1.0.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.
- package/README.md +45 -0
- package/lib/abi/ERC1155.d.ts +29 -0
- package/lib/abi/ERC1155.js +319 -0
- package/lib/abi/ERC1155.js.map +1 -0
- package/lib/abi/ERC20.d.ts +29 -0
- package/lib/abi/ERC20.js +317 -0
- package/lib/abi/ERC20.js.map +1 -0
- package/lib/abi/ERC721.d.ts +29 -0
- package/lib/abi/ERC721.js +337 -0
- package/lib/abi/ERC721.js.map +1 -0
- package/lib/abi/Seaport.d.ts +112 -0
- package/lib/abi/Seaport.js +2585 -0
- package/lib/abi/Seaport.js.map +1 -0
- package/lib/constants.d.ts +49 -0
- package/lib/constants.js +73 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/seaport.d.ts +181 -0
- package/lib/seaport.js +720 -0
- package/lib/seaport.js.map +1 -0
- package/lib/typechain/ERC1155.d.ts +189 -0
- package/lib/typechain/ERC1155.js +3 -0
- package/lib/typechain/ERC1155.js.map +1 -0
- package/lib/typechain/ERC20.d.ts +209 -0
- package/lib/typechain/ERC20.js +3 -0
- package/lib/typechain/ERC20.js.map +1 -0
- package/lib/typechain/ERC721.d.ts +220 -0
- package/lib/typechain/ERC721.js +3 -0
- package/lib/typechain/ERC721.js.map +1 -0
- package/lib/typechain/Seaport.d.ts +686 -0
- package/lib/typechain/Seaport.js +3 -0
- package/lib/typechain/Seaport.js.map +1 -0
- package/lib/typechain/common.d.ts +21 -0
- package/lib/typechain/common.js +3 -0
- package/lib/typechain/common.js.map +1 -0
- package/lib/types.d.ts +207 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/approval.d.ts +9 -0
- package/lib/utils/approval.js +108 -0
- package/lib/utils/approval.js.map +1 -0
- package/lib/utils/balance.d.ts +4 -0
- package/lib/utils/balance.js +86 -0
- package/lib/utils/balance.js.map +1 -0
- package/lib/utils/balanceAndApprovalCheck.d.ts +108 -0
- package/lib/utils/balanceAndApprovalCheck.js +322 -0
- package/lib/utils/balanceAndApprovalCheck.js.map +1 -0
- package/lib/utils/criteria.d.ts +14 -0
- package/lib/utils/criteria.js +91 -0
- package/lib/utils/criteria.js.map +1 -0
- package/lib/utils/fulfill.d.ts +84 -0
- package/lib/utils/fulfill.js +573 -0
- package/lib/utils/fulfill.js.map +1 -0
- package/lib/utils/gcd.d.ts +3 -0
- package/lib/utils/gcd.js +25 -0
- package/lib/utils/gcd.js.map +1 -0
- package/lib/utils/item.d.ts +29 -0
- package/lib/utils/item.js +136 -0
- package/lib/utils/item.js.map +1 -0
- package/lib/utils/match.d.ts +54 -0
- package/lib/utils/match.js +56 -0
- package/lib/utils/match.js.map +1 -0
- package/lib/utils/merkletree.d.ts +11 -0
- package/lib/utils/merkletree.js +32 -0
- package/lib/utils/merkletree.js.map +1 -0
- package/lib/utils/order.d.ts +37 -0
- package/lib/utils/order.js +224 -0
- package/lib/utils/order.js.map +1 -0
- package/lib/utils/usecase.d.ts +4 -0
- package/lib/utils/usecase.js +158 -0
- package/lib/utils/usecase.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
};
|
|
74
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
+
exports.validateStandardFulfillBalancesAndApprovals = exports.validateBasicFulfillBalancesAndApprovals = exports.validateOfferBalancesAndApprovals = exports.getInsufficientBalanceAndApprovalAmounts = exports.getBalancesAndApprovals = void 0;
|
|
76
|
+
var ethers_1 = require("ethers");
|
|
77
|
+
var constants_1 = require("../constants");
|
|
78
|
+
var approval_1 = require("./approval");
|
|
79
|
+
var balance_1 = require("./balance");
|
|
80
|
+
var criteria_1 = require("./criteria");
|
|
81
|
+
var item_1 = require("./item");
|
|
82
|
+
var findBalanceAndApproval = function (balancesAndApprovals, token, identifierOrCriteria) {
|
|
83
|
+
var balanceAndApproval = balancesAndApprovals.find(function (_a) {
|
|
84
|
+
var checkedToken = _a.token, checkedIdentifierOrCriteria = _a.identifierOrCriteria;
|
|
85
|
+
return token.toLowerCase() === checkedToken.toLowerCase() &&
|
|
86
|
+
checkedIdentifierOrCriteria.toLowerCase() ===
|
|
87
|
+
identifierOrCriteria.toLowerCase();
|
|
88
|
+
});
|
|
89
|
+
if (!balanceAndApproval) {
|
|
90
|
+
throw new Error("Balances and approvals didn't contain all tokens and identifiers");
|
|
91
|
+
}
|
|
92
|
+
return balanceAndApproval;
|
|
93
|
+
};
|
|
94
|
+
var getBalancesAndApprovals = function (_a) {
|
|
95
|
+
var owner = _a.owner, items = _a.items, criterias = _a.criterias, operator = _a.operator, multicallProvider = _a.multicallProvider;
|
|
96
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
+
var itemToCriteria;
|
|
98
|
+
return __generator(this, function (_b) {
|
|
99
|
+
itemToCriteria = (0, criteria_1.getItemToCriteriaMap)(items, criterias);
|
|
100
|
+
return [2 /*return*/, Promise.all(items.map(function (item) { return __awaiter(void 0, void 0, void 0, function () {
|
|
101
|
+
var approvedAmountPromise;
|
|
102
|
+
var _a;
|
|
103
|
+
var _b, _c;
|
|
104
|
+
return __generator(this, function (_d) {
|
|
105
|
+
switch (_d.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
approvedAmountPromise = Promise.resolve(ethers_1.BigNumber.from(0));
|
|
108
|
+
if ((0, item_1.isErc721Item)(item.itemType) || (0, item_1.isErc1155Item)(item.itemType)) {
|
|
109
|
+
approvedAmountPromise = (0, approval_1.approvedItemAmount)(owner, item, operator, multicallProvider);
|
|
110
|
+
}
|
|
111
|
+
else if ((0, item_1.isErc20Item)(item.itemType)) {
|
|
112
|
+
approvedAmountPromise = (0, approval_1.approvedItemAmount)(owner, item, operator, multicallProvider);
|
|
113
|
+
}
|
|
114
|
+
// If native token, we don't need to check for approvals
|
|
115
|
+
else {
|
|
116
|
+
approvedAmountPromise = Promise.resolve(constants_1.MAX_INT);
|
|
117
|
+
}
|
|
118
|
+
_a = {
|
|
119
|
+
token: item.token,
|
|
120
|
+
identifierOrCriteria: (_c = (_b = itemToCriteria.get(item)) === null || _b === void 0 ? void 0 : _b.identifier) !== null && _c !== void 0 ? _c : item.identifierOrCriteria
|
|
121
|
+
};
|
|
122
|
+
return [4 /*yield*/, (0, balance_1.balanceOf)(owner, item, multicallProvider, itemToCriteria.get(item))];
|
|
123
|
+
case 1:
|
|
124
|
+
_a.balance = _d.sent();
|
|
125
|
+
return [4 /*yield*/, approvedAmountPromise];
|
|
126
|
+
case 2: return [2 /*return*/, (_a.approvedAmount = _d.sent(),
|
|
127
|
+
_a.itemType = item.itemType,
|
|
128
|
+
_a)];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); }))];
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
exports.getBalancesAndApprovals = getBalancesAndApprovals;
|
|
136
|
+
var getInsufficientBalanceAndApprovalAmounts = function (_a) {
|
|
137
|
+
var balancesAndApprovals = _a.balancesAndApprovals, tokenAndIdentifierAmounts = _a.tokenAndIdentifierAmounts, operator = _a.operator;
|
|
138
|
+
var tokenAndIdentifierAndAmountNeeded = __spreadArray([], __read(Object.entries(tokenAndIdentifierAmounts).map(function (_a) {
|
|
139
|
+
var _b = __read(_a, 2), token = _b[0], identifierToAmount = _b[1];
|
|
140
|
+
return Object.entries(identifierToAmount).map(function (_a) {
|
|
141
|
+
var _b = __read(_a, 2), identifierOrCriteria = _b[0], amountNeeded = _b[1];
|
|
142
|
+
return [token, identifierOrCriteria, amountNeeded];
|
|
143
|
+
});
|
|
144
|
+
})), false).flat();
|
|
145
|
+
var filterBalancesOrApprovals = function (filterKey) {
|
|
146
|
+
return tokenAndIdentifierAndAmountNeeded
|
|
147
|
+
.filter(function (_a) {
|
|
148
|
+
var _b = __read(_a, 3), token = _b[0], identifierOrCriteria = _b[1], amountNeeded = _b[2];
|
|
149
|
+
return findBalanceAndApproval(balancesAndApprovals, token, identifierOrCriteria)[filterKey].lt(amountNeeded);
|
|
150
|
+
})
|
|
151
|
+
.map(function (_a) {
|
|
152
|
+
var _b = __read(_a, 3), token = _b[0], identifierOrCriteria = _b[1], amount = _b[2];
|
|
153
|
+
var balanceAndApproval = findBalanceAndApproval(balancesAndApprovals, token, identifierOrCriteria);
|
|
154
|
+
return {
|
|
155
|
+
token: token,
|
|
156
|
+
identifierOrCriteria: identifierOrCriteria,
|
|
157
|
+
requiredAmount: amount,
|
|
158
|
+
amountHave: balanceAndApproval[filterKey],
|
|
159
|
+
itemType: balanceAndApproval.itemType,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
var mapToApproval = function (insufficientBalance) { return ({
|
|
164
|
+
token: insufficientBalance.token,
|
|
165
|
+
identifierOrCriteria: insufficientBalance.identifierOrCriteria,
|
|
166
|
+
approvedAmount: insufficientBalance.amountHave,
|
|
167
|
+
requiredApprovedAmount: insufficientBalance.requiredAmount,
|
|
168
|
+
itemType: insufficientBalance.itemType,
|
|
169
|
+
operator: operator,
|
|
170
|
+
}); };
|
|
171
|
+
var _b = __read([
|
|
172
|
+
filterBalancesOrApprovals("balance"),
|
|
173
|
+
filterBalancesOrApprovals("approvedAmount").map(mapToApproval),
|
|
174
|
+
], 2), insufficientBalances = _b[0], insufficientApprovals = _b[1];
|
|
175
|
+
return {
|
|
176
|
+
insufficientBalances: insufficientBalances,
|
|
177
|
+
insufficientApprovals: insufficientApprovals,
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
exports.getInsufficientBalanceAndApprovalAmounts = getInsufficientBalanceAndApprovalAmounts;
|
|
181
|
+
/**
|
|
182
|
+
* 1. The offerer should have sufficient balance of all offered items.
|
|
183
|
+
* 2. If the order does not indicate proxy utilization, the offerer should have sufficient approvals set
|
|
184
|
+
* for the Seaport contract for all offered ERC20, ERC721, and ERC1155 items.
|
|
185
|
+
* 3. If the order does indicate proxy utilization, the offerer should have sufficient approvals set
|
|
186
|
+
* for their respective proxy contract for all offered ERC20, ERC721, and ERC1155 items.
|
|
187
|
+
*/
|
|
188
|
+
var validateOfferBalancesAndApprovals = function (_a) {
|
|
189
|
+
var offer = _a.offer, criterias = _a.criterias, balancesAndApprovals = _a.balancesAndApprovals, timeBasedItemParams = _a.timeBasedItemParams, _b = _a.throwOnInsufficientBalances, throwOnInsufficientBalances = _b === void 0 ? true : _b, throwOnInsufficientApprovals = _a.throwOnInsufficientApprovals, operator = _a.operator;
|
|
190
|
+
var _c = (0, exports.getInsufficientBalanceAndApprovalAmounts)({
|
|
191
|
+
balancesAndApprovals: balancesAndApprovals,
|
|
192
|
+
tokenAndIdentifierAmounts: (0, item_1.getSummedTokenAndIdentifierAmounts)({
|
|
193
|
+
items: offer,
|
|
194
|
+
criterias: criterias,
|
|
195
|
+
timeBasedItemParams: timeBasedItemParams
|
|
196
|
+
? __assign(__assign({}, timeBasedItemParams), { isConsiderationItem: false }) : undefined,
|
|
197
|
+
}),
|
|
198
|
+
operator: operator,
|
|
199
|
+
}), insufficientBalances = _c.insufficientBalances, insufficientApprovals = _c.insufficientApprovals;
|
|
200
|
+
if (throwOnInsufficientBalances && insufficientBalances.length > 0) {
|
|
201
|
+
throw new Error("The offerer does not have the amount needed to create or fulfill.");
|
|
202
|
+
}
|
|
203
|
+
if (throwOnInsufficientApprovals && insufficientApprovals.length > 0) {
|
|
204
|
+
throw new Error("The offerer does not have the sufficient approvals.");
|
|
205
|
+
}
|
|
206
|
+
return insufficientApprovals;
|
|
207
|
+
};
|
|
208
|
+
exports.validateOfferBalancesAndApprovals = validateOfferBalancesAndApprovals;
|
|
209
|
+
/**
|
|
210
|
+
* When fulfilling a basic order, the following requirements need to be checked to ensure that the order will be fulfillable:
|
|
211
|
+
* 1. Offer checks need to be performed to ensure that the offerer still has sufficient balance and approvals
|
|
212
|
+
* 2. The fulfiller should have sufficient balance of all consideration items except for those with an
|
|
213
|
+
* item type that matches the order's offered item type — by way of example, if the fulfilled order offers
|
|
214
|
+
* an ERC20 item and requires an ERC721 item to the offerer and the same ERC20 item to another recipient,
|
|
215
|
+
* the fulfiller needs to own the ERC721 item but does not need to own the ERC20 item as it will be sourced from the offerer.
|
|
216
|
+
* 3. If the fulfiller does not elect to utilize a proxy, they need to have sufficient approvals set for the
|
|
217
|
+
* Seaport contract for all ERC20, ERC721, and ERC1155 consideration items on the fulfilled order except
|
|
218
|
+
* for ERC20 items with an item type that matches the order's offered item type.
|
|
219
|
+
* 4. If the fulfiller does elect to utilize a proxy, they need to have sufficient approvals set for their
|
|
220
|
+
* respective proxy contract for all ERC20, ERC721, and ERC1155 consideration items on the fulfilled order
|
|
221
|
+
* except for ERC20 items with an item type that matches the order's offered item type.
|
|
222
|
+
* 5. If the fulfilled order specifies Ether (or other native tokens) as consideration items, the fulfiller must
|
|
223
|
+
* be able to supply the sum total of those items as msg.value.
|
|
224
|
+
*
|
|
225
|
+
* @returns the list of insufficient owner and proxy approvals
|
|
226
|
+
*/
|
|
227
|
+
var validateBasicFulfillBalancesAndApprovals = function (_a) {
|
|
228
|
+
var offer = _a.offer, consideration = _a.consideration, offererBalancesAndApprovals = _a.offererBalancesAndApprovals, fulfillerBalancesAndApprovals = _a.fulfillerBalancesAndApprovals, timeBasedItemParams = _a.timeBasedItemParams, offererOperator = _a.offererOperator, fulfillerOperator = _a.fulfillerOperator;
|
|
229
|
+
(0, exports.validateOfferBalancesAndApprovals)({
|
|
230
|
+
offer: offer,
|
|
231
|
+
criterias: [],
|
|
232
|
+
balancesAndApprovals: offererBalancesAndApprovals,
|
|
233
|
+
timeBasedItemParams: timeBasedItemParams,
|
|
234
|
+
throwOnInsufficientApprovals: true,
|
|
235
|
+
operator: offererOperator,
|
|
236
|
+
});
|
|
237
|
+
var considerationWithoutOfferItemType = consideration.filter(function (item) { return item.itemType !== offer[0].itemType; });
|
|
238
|
+
var _b = (0, exports.getInsufficientBalanceAndApprovalAmounts)({
|
|
239
|
+
balancesAndApprovals: fulfillerBalancesAndApprovals,
|
|
240
|
+
tokenAndIdentifierAmounts: (0, item_1.getSummedTokenAndIdentifierAmounts)({
|
|
241
|
+
items: considerationWithoutOfferItemType,
|
|
242
|
+
criterias: [],
|
|
243
|
+
timeBasedItemParams: __assign(__assign({}, timeBasedItemParams), { isConsiderationItem: true }),
|
|
244
|
+
}),
|
|
245
|
+
operator: fulfillerOperator,
|
|
246
|
+
}), insufficientBalances = _b.insufficientBalances, insufficientApprovals = _b.insufficientApprovals;
|
|
247
|
+
if (insufficientBalances.length > 0) {
|
|
248
|
+
throw new Error("The fulfiller does not have the balances needed to fulfill.");
|
|
249
|
+
}
|
|
250
|
+
return insufficientApprovals;
|
|
251
|
+
};
|
|
252
|
+
exports.validateBasicFulfillBalancesAndApprovals = validateBasicFulfillBalancesAndApprovals;
|
|
253
|
+
/**
|
|
254
|
+
* When fulfilling a standard order, the following requirements need to be checked to ensure that the order will be fulfillable:
|
|
255
|
+
* 1. Offer checks need to be performed to ensure that the offerer still has sufficient balance and approvals
|
|
256
|
+
* 2. The fulfiller should have sufficient balance of all consideration items after receiving all offered items
|
|
257
|
+
* — by way of example, if the fulfilled order offers an ERC20 item and requires an ERC721 item to the offerer
|
|
258
|
+
* and the same ERC20 item to another recipient with an amount less than or equal to the offered amount,
|
|
259
|
+
* the fulfiller does not need to own the ERC20 item as it will first be received from the offerer.
|
|
260
|
+
* 3. If the fulfiller does not elect to utilize a proxy, they need to have sufficient approvals set for the
|
|
261
|
+
* Seaport contract for all ERC20, ERC721, and ERC1155 consideration items on the fulfilled order.
|
|
262
|
+
* 4. If the fulfiller does elect to utilize a proxy, they need to have sufficient approvals set for their
|
|
263
|
+
* respective proxy contract for all ERC20, ERC721, and ERC1155 consideration items on the fulfilled order.
|
|
264
|
+
* 5. If the fulfilled order specifies Ether (or other native tokens) as consideration items, the fulfiller must
|
|
265
|
+
* be able to supply the sum total of those items as msg.value.
|
|
266
|
+
*
|
|
267
|
+
* @returns the list of insufficient owner and proxy approvals
|
|
268
|
+
*/
|
|
269
|
+
var validateStandardFulfillBalancesAndApprovals = function (_a) {
|
|
270
|
+
var offer = _a.offer, consideration = _a.consideration, offerCriteria = _a.offerCriteria, considerationCriteria = _a.considerationCriteria, offererBalancesAndApprovals = _a.offererBalancesAndApprovals, fulfillerBalancesAndApprovals = _a.fulfillerBalancesAndApprovals, timeBasedItemParams = _a.timeBasedItemParams, offererOperator = _a.offererOperator, fulfillerOperator = _a.fulfillerOperator;
|
|
271
|
+
(0, exports.validateOfferBalancesAndApprovals)({
|
|
272
|
+
offer: offer,
|
|
273
|
+
criterias: offerCriteria,
|
|
274
|
+
balancesAndApprovals: offererBalancesAndApprovals,
|
|
275
|
+
timeBasedItemParams: timeBasedItemParams,
|
|
276
|
+
throwOnInsufficientApprovals: true,
|
|
277
|
+
operator: offererOperator,
|
|
278
|
+
});
|
|
279
|
+
var fulfillerBalancesAndApprovalsAfterReceivingOfferedItems = addToExistingBalances({
|
|
280
|
+
items: offer,
|
|
281
|
+
criterias: offerCriteria,
|
|
282
|
+
balancesAndApprovals: fulfillerBalancesAndApprovals,
|
|
283
|
+
timeBasedItemParams: timeBasedItemParams,
|
|
284
|
+
});
|
|
285
|
+
var _b = (0, exports.getInsufficientBalanceAndApprovalAmounts)({
|
|
286
|
+
balancesAndApprovals: fulfillerBalancesAndApprovalsAfterReceivingOfferedItems,
|
|
287
|
+
tokenAndIdentifierAmounts: (0, item_1.getSummedTokenAndIdentifierAmounts)({
|
|
288
|
+
items: consideration,
|
|
289
|
+
criterias: considerationCriteria,
|
|
290
|
+
timeBasedItemParams: __assign(__assign({}, timeBasedItemParams), { isConsiderationItem: true }),
|
|
291
|
+
}),
|
|
292
|
+
operator: fulfillerOperator,
|
|
293
|
+
}), insufficientBalances = _b.insufficientBalances, insufficientApprovals = _b.insufficientApprovals;
|
|
294
|
+
if (insufficientBalances.length > 0) {
|
|
295
|
+
throw new Error("The fulfiller does not have the balances needed to fulfill.");
|
|
296
|
+
}
|
|
297
|
+
return insufficientApprovals;
|
|
298
|
+
};
|
|
299
|
+
exports.validateStandardFulfillBalancesAndApprovals = validateStandardFulfillBalancesAndApprovals;
|
|
300
|
+
var addToExistingBalances = function (_a) {
|
|
301
|
+
var items = _a.items, criterias = _a.criterias, timeBasedItemParams = _a.timeBasedItemParams, balancesAndApprovals = _a.balancesAndApprovals;
|
|
302
|
+
var summedItemAmounts = (0, item_1.getSummedTokenAndIdentifierAmounts)({
|
|
303
|
+
items: items,
|
|
304
|
+
criterias: criterias,
|
|
305
|
+
timeBasedItemParams: __assign(__assign({}, timeBasedItemParams), { isConsiderationItem: false }),
|
|
306
|
+
});
|
|
307
|
+
// Deep clone existing balances
|
|
308
|
+
var balancesAndApprovalsAfterReceivingItems = balancesAndApprovals.map(function (item) { return (__assign({}, item)); });
|
|
309
|
+
// Add each summed item amount to the existing balances as we may want tocheck balances after receiving all items
|
|
310
|
+
Object.entries(summedItemAmounts).forEach(function (_a) {
|
|
311
|
+
var _b = __read(_a, 2), token = _b[0], identifierOrCriteriaToAmount = _b[1];
|
|
312
|
+
return Object.entries(identifierOrCriteriaToAmount).forEach(function (_a) {
|
|
313
|
+
var _b = __read(_a, 2), identifierOrCriteria = _b[0], amount = _b[1];
|
|
314
|
+
var balanceAndApproval = findBalanceAndApproval(balancesAndApprovalsAfterReceivingItems, token, identifierOrCriteria);
|
|
315
|
+
var balanceAndApprovalIndex = balancesAndApprovalsAfterReceivingItems.indexOf(balanceAndApproval);
|
|
316
|
+
balancesAndApprovalsAfterReceivingItems[balanceAndApprovalIndex].balance =
|
|
317
|
+
balancesAndApprovalsAfterReceivingItems[balanceAndApprovalIndex].balance.add(amount);
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
return balancesAndApprovalsAfterReceivingItems;
|
|
321
|
+
};
|
|
322
|
+
//# sourceMappingURL=balanceAndApprovalCheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balanceAndApprovalCheck.js","sourceRoot":"","sources":["../../src/utils/balanceAndApprovalCheck.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAmC;AACnC,0CAAiD;AAEjD,uCAAgD;AAChD,qCAAsC;AACtC,uCAAkD;AAClD,+BAMgB;AA2BhB,IAAM,sBAAsB,GAAG,UAC7B,oBAA0C,EAC1C,KAAa,EACb,oBAA4B;IAE5B,IAAM,kBAAkB,GAAG,oBAAoB,CAAC,IAAI,CAClD,UAAC,EAGA;YAFQ,YAAY,WAAA,EACG,2BAA2B,0BAAA;QAEjD,OAAA,KAAK,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE;YAClD,2BAA2B,CAAC,WAAW,EAAE;gBACvC,oBAAoB,CAAC,WAAW,EAAE;IAFpC,CAEoC,CACvC,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,MAAM,IAAI,KAAK,CACb,kEAAkE,CACnE,CAAC;KACH;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AAEK,IAAM,uBAAuB,GAAG,UAAO,EAY7C;QAXC,KAAK,WAAA,EACL,KAAK,WAAA,EACL,SAAS,eAAA,EACT,QAAQ,cAAA,EACR,iBAAiB,uBAAA;;;;YAQX,cAAc,GAAG,IAAA,+BAAoB,EAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YAE9D,sBAAO,OAAO,CAAC,GAAG,CAChB,KAAK,CAAC,GAAG,CAAC,UAAO,IAAI;;;;;;;gCACf,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAS,C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AE,KAAK,GAAE;KAC5E,CAAC,CAAC;IAEH,+BAA+B;IAC/B,IAAM,uCAAuC,GAAG,oBAAoB,CAAC,GAAG,CACtE,UAAC,IAAI,IAAK,OAAA,cAAM,IAAI,EAAG,EAAb,CAAa,CACxB,CAAC;IAEF,iHAAiH;IACjH,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CACvC,UAAC,EAAqC;YAArC,KAAA,aAAqC,EAApC,KAAK,QAAA,EAAE,4BAA4B,QAAA;QACnC,OAAA,MAAM,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC,OAAO,CAClD,UAAC,EAA8B;gBAA9B,KAAA,aAA8B,EAA7B,oBAAoB,QAAA,EAAE,MAAM,QAAA;YAC5B,IAAM,kBAAkB,GAAG,sBAAsB,CAC/C,uCAAuC,EACvC,KAAK,EACL,oBAAoB,CACrB,CAAC;YAEF,IAAM,uBAAuB,GAC3B,uCAAuC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;YAEtE,uCAAuC,CACrC,uBAAuB,CACxB,CAAC,OAAO;gBACP,uCAAuC,CACrC,uBAAuB,CACxB,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC,CACF;IAlBD,CAkBC,CACJ,CAAC;IAEF,OAAO,uCAAuC,CAAC;AACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Side } from "../constants";
|
|
2
|
+
import { InputCriteria, Item, Order } from "../types";
|
|
3
|
+
export declare const generateCriteriaResolvers: ({ orders, offerCriterias, considerationCriterias, }: {
|
|
4
|
+
orders: Order[];
|
|
5
|
+
offerCriterias?: InputCriteria[][] | undefined;
|
|
6
|
+
considerationCriterias?: InputCriteria[][] | undefined;
|
|
7
|
+
}) => {
|
|
8
|
+
orderIndex: number;
|
|
9
|
+
index: number;
|
|
10
|
+
side: Side;
|
|
11
|
+
identifier: string;
|
|
12
|
+
criteriaProof: string[];
|
|
13
|
+
}[];
|
|
14
|
+
export declare const getItemToCriteriaMap: (items: Item[], criterias: InputCriteria[]) => Map<Item, InputCriteria>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.getItemToCriteriaMap = exports.generateCriteriaResolvers = void 0;
|
|
29
|
+
var constants_1 = require("../constants");
|
|
30
|
+
var item_1 = require("./item");
|
|
31
|
+
var generateCriteriaResolvers = function (_a) {
|
|
32
|
+
var orders = _a.orders, _b = _a.offerCriterias, offerCriterias = _b === void 0 ? [[]] : _b, _c = _a.considerationCriterias, considerationCriterias = _c === void 0 ? [[]] : _c;
|
|
33
|
+
var offerCriteriaItems = orders.flatMap(function (order, orderIndex) {
|
|
34
|
+
return order.parameters.offer
|
|
35
|
+
.map(function (item, index) {
|
|
36
|
+
return ({
|
|
37
|
+
orderIndex: orderIndex,
|
|
38
|
+
item: item,
|
|
39
|
+
index: index,
|
|
40
|
+
side: constants_1.Side.OFFER,
|
|
41
|
+
});
|
|
42
|
+
})
|
|
43
|
+
.filter(function (_a) {
|
|
44
|
+
var item = _a.item;
|
|
45
|
+
return (0, item_1.isCriteriaItem)(item.itemType);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
var considerationCriteriaItems = orders.flatMap(function (order, orderIndex) {
|
|
49
|
+
return order.parameters.consideration
|
|
50
|
+
.map(function (item, index) {
|
|
51
|
+
return ({
|
|
52
|
+
orderIndex: orderIndex,
|
|
53
|
+
item: item,
|
|
54
|
+
index: index,
|
|
55
|
+
side: constants_1.Side.CONSIDERATION,
|
|
56
|
+
});
|
|
57
|
+
})
|
|
58
|
+
.filter(function (_a) {
|
|
59
|
+
var item = _a.item;
|
|
60
|
+
return (0, item_1.isCriteriaItem)(item.itemType);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
var mapCriteriaItemsToResolver = function (criteriaItems, criterias) {
|
|
64
|
+
return criteriaItems.map(function (_a, i) {
|
|
65
|
+
var orderIndex = _a.orderIndex, item = _a.item, index = _a.index, side = _a.side;
|
|
66
|
+
var merkleRoot = item.identifierOrCriteria || "0";
|
|
67
|
+
var inputCriteria = criterias[orderIndex][i];
|
|
68
|
+
return {
|
|
69
|
+
orderIndex: orderIndex,
|
|
70
|
+
index: index,
|
|
71
|
+
side: side,
|
|
72
|
+
identifier: inputCriteria.identifier,
|
|
73
|
+
criteriaProof: merkleRoot === "0" ? [] : inputCriteria.proof,
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
var criteriaResolvers = __spreadArray(__spreadArray([], __read(mapCriteriaItemsToResolver(offerCriteriaItems, offerCriterias)), false), __read(mapCriteriaItemsToResolver(considerationCriteriaItems, considerationCriterias)), false);
|
|
78
|
+
return criteriaResolvers;
|
|
79
|
+
};
|
|
80
|
+
exports.generateCriteriaResolvers = generateCriteriaResolvers;
|
|
81
|
+
var getItemToCriteriaMap = function (items, criterias) {
|
|
82
|
+
var criteriasCopy = __spreadArray([], __read(criterias), false);
|
|
83
|
+
return items.reduce(function (map, item) {
|
|
84
|
+
if ((0, item_1.isCriteriaItem)(item.itemType)) {
|
|
85
|
+
map.set(item, criteriasCopy.shift());
|
|
86
|
+
}
|
|
87
|
+
return map;
|
|
88
|
+
}, new Map());
|
|
89
|
+
};
|
|
90
|
+
exports.getItemToCriteriaMap = getItemToCriteriaMap;
|
|
91
|
+
//# sourceMappingURL=criteria.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"criteria.js","sourceRoot":"","sources":["../../src/utils/criteria.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAAoC;AAEpC,+BAAwC;AAEjC,IAAM,yBAAyB,GAAG,UAAC,EAQzC;QAPC,MAAM,YAAA,EACN,sBAAqB,EAArB,cAAc,mBAAG,CAAC,EAAE,CAAC,KAAA,EACrB,8BAA6B,EAA7B,sBAAsB,mBAAG,CAAC,EAAE,CAAC,KAAA;IAM7B,IAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK,EAAE,UAAU;QAC1D,OAAA,KAAK,CAAC,UAAU,CAAC,KAAK;aACnB,GAAG,CACF,UAAC,IAAI,EAAE,KAAK;YACV,OAAA,CAAC;gBACC,UAAU,YAAA;gBACV,IAAI,MAAA;gBACJ,KAAK,OAAA;gBACL,IAAI,EAAE,gBAAI,CAAC,KAAK;aACP,CAAA;QALX,CAKW,CACd;aACA,MAAM,CAAC,UAAC,EAAQ;gBAAN,IAAI,UAAA;YAAO,OAAA,IAAA,qBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC;QAA7B,CAA6B,CAAC;IAVtD,CAUsD,CACvD,CAAC;IAEF,IAAM,0BAA0B,GAAG,MAAM,CAAC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KAAa,EACb,SAA0B;IAE1B,IAAM,aAAa,4BAAO,SAAS,SAAC,CAAC;IAErC,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,GAAG,EAAE,IAAI;QAC5B,IAAI,IAAA,qBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACjC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,CAAC,KAAK,EAAmB,CAAC,CAAC;SACvD;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,IAAI,GAAG,EAAuB,CAAC,CAAC;AACrC,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { BigNumber, BigNumberish, providers } from "ethers";
|
|
2
|
+
import type { Seaport as SeaportContract, Seaport, FulfillmentComponentStruct } from "../typechain/Seaport";
|
|
3
|
+
import type { ConsiderationItem, ExchangeAction, InputCriteria, Order, OrderParameters, OrderStatus, OrderUseCase, ContractMethodReturnType } from "../types";
|
|
4
|
+
import { BalancesAndApprovals } from "./balanceAndApprovalCheck";
|
|
5
|
+
import { TimeBasedItemParams } from "./item";
|
|
6
|
+
/**
|
|
7
|
+
* We should use basic fulfill order if the order adheres to the following criteria:
|
|
8
|
+
* 1. The order should not be partially filled.
|
|
9
|
+
* 2. The order only contains a single offer item and contains at least one consideration item
|
|
10
|
+
* 3. The order does not offer an item with Ether (or other native tokens) as its item type.
|
|
11
|
+
* 4. The order only contains a single ERC721 or ERC1155 item and that item is not criteria-based
|
|
12
|
+
* 5. All other items have the same Native or ERC20 item type and token
|
|
13
|
+
* 6. All items have the same startAmount and endAmount
|
|
14
|
+
* 7. First consideration item must contain the offerer as the recipient
|
|
15
|
+
* 8. If the order has multiple consideration items and all consideration items other than the
|
|
16
|
+
* first consideration item have the same item type as the offered item, the offered item
|
|
17
|
+
* amount is not less than the sum of all consideration item amounts excluding the
|
|
18
|
+
* first consideration item amount
|
|
19
|
+
* 9. The token on native currency items needs to be set to the null address and the identifier on
|
|
20
|
+
* currencies needs to be zero, and the amounts on the 721 item need to be 1
|
|
21
|
+
*/
|
|
22
|
+
export declare const shouldUseBasicFulfill: ({ offer, consideration, offerer }: OrderParameters, totalFilled: OrderStatus["totalFilled"]) => boolean;
|
|
23
|
+
export declare function fulfillBasicOrder({ order, seaportContract, offererBalancesAndApprovals, fulfillerBalancesAndApprovals, timeBasedItemParams, offererOperator, fulfillerOperator, signer, tips, conduitKey, }: {
|
|
24
|
+
order: Order;
|
|
25
|
+
seaportContract: Seaport;
|
|
26
|
+
offererBalancesAndApprovals: BalancesAndApprovals;
|
|
27
|
+
fulfillerBalancesAndApprovals: BalancesAndApprovals;
|
|
28
|
+
timeBasedItemParams: TimeBasedItemParams;
|
|
29
|
+
offererOperator: string;
|
|
30
|
+
fulfillerOperator: string;
|
|
31
|
+
signer: providers.JsonRpcSigner;
|
|
32
|
+
tips?: ConsiderationItem[];
|
|
33
|
+
conduitKey: string;
|
|
34
|
+
}): Promise<OrderUseCase<ExchangeAction<ContractMethodReturnType<SeaportContract, "fulfillBasicOrder">>>>;
|
|
35
|
+
export declare function fulfillStandardOrder({ order, unitsToFill, totalSize, totalFilled, offerCriteria, considerationCriteria, tips, extraData, seaportContract, offererBalancesAndApprovals, fulfillerBalancesAndApprovals, offererOperator, fulfillerOperator, timeBasedItemParams, conduitKey, recipientAddress, signer, }: {
|
|
36
|
+
order: Order;
|
|
37
|
+
unitsToFill?: BigNumberish;
|
|
38
|
+
totalFilled: BigNumber;
|
|
39
|
+
totalSize: BigNumber;
|
|
40
|
+
offerCriteria: InputCriteria[];
|
|
41
|
+
considerationCriteria: InputCriteria[];
|
|
42
|
+
tips?: ConsiderationItem[];
|
|
43
|
+
extraData?: string;
|
|
44
|
+
seaportContract: Seaport;
|
|
45
|
+
offererBalancesAndApprovals: BalancesAndApprovals;
|
|
46
|
+
fulfillerBalancesAndApprovals: BalancesAndApprovals;
|
|
47
|
+
offererOperator: string;
|
|
48
|
+
fulfillerOperator: string;
|
|
49
|
+
conduitKey: string;
|
|
50
|
+
recipientAddress: string;
|
|
51
|
+
timeBasedItemParams: TimeBasedItemParams;
|
|
52
|
+
signer: providers.JsonRpcSigner;
|
|
53
|
+
}): Promise<OrderUseCase<ExchangeAction<ContractMethodReturnType<SeaportContract, "fulfillAdvancedOrder" | "fulfillOrder">>>>;
|
|
54
|
+
export declare function validateAndSanitizeFromOrderStatus(order: Order, orderStatus: OrderStatus): Order;
|
|
55
|
+
export declare type FulfillOrdersMetadata = {
|
|
56
|
+
order: Order;
|
|
57
|
+
unitsToFill?: BigNumberish;
|
|
58
|
+
orderStatus: OrderStatus;
|
|
59
|
+
offerCriteria: InputCriteria[];
|
|
60
|
+
considerationCriteria: InputCriteria[];
|
|
61
|
+
tips: ConsiderationItem[];
|
|
62
|
+
extraData: string;
|
|
63
|
+
offererBalancesAndApprovals: BalancesAndApprovals;
|
|
64
|
+
offererOperator: string;
|
|
65
|
+
}[];
|
|
66
|
+
export declare function fulfillAvailableOrders({ ordersMetadata, seaportContract, fulfillerBalancesAndApprovals, fulfillerOperator, currentBlockTimestamp, ascendingAmountTimestampBuffer, conduitKey, signer, recipientAddress, }: {
|
|
67
|
+
ordersMetadata: FulfillOrdersMetadata;
|
|
68
|
+
seaportContract: Seaport;
|
|
69
|
+
fulfillerBalancesAndApprovals: BalancesAndApprovals;
|
|
70
|
+
fulfillerOperator: string;
|
|
71
|
+
currentBlockTimestamp: number;
|
|
72
|
+
ascendingAmountTimestampBuffer: number;
|
|
73
|
+
conduitKey: string;
|
|
74
|
+
signer: providers.JsonRpcSigner;
|
|
75
|
+
recipientAddress: string;
|
|
76
|
+
}): Promise<OrderUseCase<ExchangeAction<ContractMethodReturnType<SeaportContract, "fulfillAvailableAdvancedOrders">>>>;
|
|
77
|
+
export declare function generateFulfillOrdersFulfillments(ordersMetadata: FulfillOrdersMetadata): {
|
|
78
|
+
offerFulfillments: FulfillmentComponentStruct[];
|
|
79
|
+
considerationFulfillments: FulfillmentComponentStruct[];
|
|
80
|
+
};
|
|
81
|
+
export declare const getAdvancedOrderNumeratorDenominator: (order: Order, unitsToFill?: BigNumberish | undefined) => {
|
|
82
|
+
numerator: BigNumber;
|
|
83
|
+
denominator: BigNumber;
|
|
84
|
+
};
|