Skip to content

Commit e5b9453

Browse files
Adjust Tips Correctly for Partial Fills (#416)
* Adjust tips correctly for partial fills * Add ERC1155 <=> ETH adjust tips correctly with low denomination * Add ERC1155 <=> ERC20 include tips correctly test
1 parent 2b6788d commit e5b9453

File tree

3 files changed

+358
-3
lines changed

3 files changed

+358
-3
lines changed

src/utils/fulfill.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
areAllCurrenciesSame,
4545
mapOrderAmountsFromFilledStatus,
4646
mapOrderAmountsFromUnitsToFill,
47+
adjustTipsForPartialFills,
4748
totalItemsAmount,
4849
} from "./order";
4950
import {
@@ -377,11 +378,17 @@ export function fulfillStandardOrder(
377378
totalSize,
378379
});
379380

381+
let adjustedTips: ConsiderationItem[] = [];
382+
383+
if (tips.length > 0) {
384+
adjustedTips = adjustTipsForPartialFills(tips, unitsToFill, totalSize);
385+
}
386+
380387
const {
381388
parameters: { offer, consideration },
382389
} = orderWithAdjustedFills;
383390

384-
const considerationIncludingTips = [...consideration, ...tips];
391+
const considerationIncludingTips = [...consideration, ...adjustedTips];
385392

386393
const offerCriteriaItems = offer.filter(({ itemType }) =>
387394
isCriteriaItem(itemType),

src/utils/order.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,32 @@ export const mapOrderAmountsFromUnitsToFill = (
273273
};
274274
};
275275

276+
export function adjustTipsForPartialFills(
277+
tips: ConsiderationItem[],
278+
unitsToFill: BigNumberish,
279+
totalSize: bigint,
280+
): ConsiderationItem[] {
281+
const unitsToFillBn = BigInt(unitsToFill);
282+
283+
if (unitsToFillBn <= 0n) {
284+
throw new Error("Units to fill must be greater than 0");
285+
}
286+
287+
return tips.map((tip) => ({
288+
...tip,
289+
startAmount: multiplyDivision(
290+
tip.startAmount,
291+
unitsToFillBn,
292+
totalSize,
293+
).toString(),
294+
endAmount: multiplyDivision(
295+
tip.endAmount,
296+
unitsToFillBn,
297+
totalSize,
298+
).toString(),
299+
}));
300+
}
301+
276302
export const generateRandomSalt = (domain?: string) => {
277303
if (domain) {
278304
return toBeHex(

0 commit comments

Comments
 (0)