File tree Expand file tree Collapse file tree 3 files changed +358
-3
lines changed Expand file tree Collapse file tree 3 files changed +358
-3
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ import {
4444 areAllCurrenciesSame ,
4545 mapOrderAmountsFromFilledStatus ,
4646 mapOrderAmountsFromUnitsToFill ,
47+ adjustTipsForPartialFills ,
4748 totalItemsAmount ,
4849} from "./order" ;
4950import {
@@ -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 ) ,
Original file line number Diff line number Diff 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+
276302export const generateRandomSalt = ( domain ?: string ) => {
277303 if ( domain ) {
278304 return toBeHex (
You can’t perform that action at this time.
0 commit comments