Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/seaport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
} from "./utils/balanceAndApprovalCheck"
import { getBulkOrderTree } from "./utils/eip712/bulk-orders"
import {
assertUnitsToFillIsPositive,
type FulfillOrdersMetadata,
fulfillAvailableOrders,
fulfillBasicOrder,
Expand Down Expand Up @@ -910,6 +911,8 @@ export class Seaport {
throw new Error("Order is missing signature")
}

assertUnitsToFillIsPositive(unitsToFill)

const { parameters: orderParameters } = order
const { offerer, offer, consideration } = orderParameters

Expand Down Expand Up @@ -1083,6 +1086,10 @@ export class Seaport {
throw new Error("All orders must include signatures")
}

for (const { unitsToFill } of fulfillOrderDetails) {
assertUnitsToFillIsPositive(unitsToFill)
}

const fulfiller = await this._getSigner(accountAddress)

const fulfillerAddress = await fulfiller.getAddress()
Expand Down
15 changes: 15 additions & 0 deletions src/utils/fulfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,21 @@ export function assertNoCriteriaTips(tips: ConsiderationItem[]) {
}
}

/**
* Rejects a requested fill of zero or fewer units.
*
* Leaving `unitsToFill` out fills whatever is left of the order, and the fill
* paths tell the two apart by whether it is truthy. A zero written as a number
* or a bigint is falsy, so it was read as "not set" and filled the whole
* order, while the same zero as a string reached the "must be greater than 0"
* check in mapOrderAmountsFromUnitsToFill. Settle it before any of that runs.
*/
export const assertUnitsToFillIsPositive = (unitsToFill?: BigNumberish) => {
if (unitsToFill != null && BigInt(unitsToFill) <= 0n) {
throw new Error("Units to fill must be greater than 0")
}
}

/**
* Caps a requested fill at what is left of a partially filled order.
*
Expand Down
44 changes: 44 additions & 0 deletions test/partial-fulfill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,50 @@ describeWithFixture(
})
})

it("rejects a zero unitsToFill written as a number or bigint instead of filling the whole order", async () => {
const { seaport } = fixture

const { executeAllActions } = await seaport.createOrder(
standardCreateOrderInput,
)
const order = await executeAllActions()
const accountAddress = await fulfiller.getAddress()

for (const unitsToFill of [0, 0n]) {
await expect(
seaport.fulfillOrder({ order, unitsToFill, accountAddress }),
).to.be.rejectedWith("Units to fill must be greater than 0")

await expect(
seaport.fulfillOrders({
fulfillOrderDetails: [{ order, unitsToFill }],
accountAddress,
}),
).to.be.rejectedWith("Units to fill must be greater than 0")
}
})

it("rejects a zero unitsToFill written as a string, as before", async () => {
const { seaport } = fixture

const { executeAllActions } = await seaport.createOrder(
standardCreateOrderInput,
)
const order = await executeAllActions()
const accountAddress = await fulfiller.getAddress()

await expect(
seaport.fulfillOrder({ order, unitsToFill: "0", accountAddress }),
).to.be.rejectedWith("Units to fill must be greater than 0")

await expect(
seaport.fulfillOrders({
fulfillOrderDetails: [{ order, unitsToFill: "0" }],
accountAddress,
}),
).to.be.rejectedWith("Units to fill must be greater than 0")
})

it("ERC1155 <=> ETH adjust tips correctly", async () => {
// Note: For simplicity in this test, tips are returned to the fulfiller.
const tips = [
Expand Down
Loading