From bb76394cb9550cf74e8717ae3ddd33dcd5a6d914 Mon Sep 17 00:00:00 2001 From: Xowiek Date: Sat, 22 Aug 2026 07:28:13 +0300 Subject: [PATCH] fix: stop crediting the fulfiller with offer items sent to someone else validateStandardFulfillBalancesAndApprovals adds the offered items to the fulfiller's balances before checking consideration, per requirement 2 in its own doc comment: the fulfiller "does not need to own the ERC20 item as it will first be received from the offerer". That only holds when the offer actually reaches the fulfiller. recipientAddress forwards it somewhere else, and the check never sees that value -- fulfillStandardOrder and fulfillAvailableOrders both take recipientAddress but never pass it down. The credit is applied either way. Accepting a bid is where it shows. The offerer bids 10 ERC20 with a 2.5% fee, so the fulfiller receives 10 and settles 0.25 out of it. Hand the proceeds to a third party with recipientAddress and the fee has to come from the fulfiller's own balance instead. With a zero balance the SDK reports no problem and hands back a fulfillment that reverts on transfer with panic 0x11, which says nothing about what went wrong. Only apply the credit when the offer lands with the fulfiller. The zero address means it stays with them, and naming the fulfiller explicitly is the same thing, so both keep the existing behaviour -- checked on chain, that second case really does settle. --- src/seaport.ts | 2 + src/utils/balanceAndApprovalCheck.ts | 21 ++++-- src/utils/fulfill.ts | 29 +++++++++ test/gifting.spec.ts | 95 ++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 6 deletions(-) diff --git a/src/seaport.ts b/src/seaport.ts index 4819a848..c7bc6e77 100644 --- a/src/seaport.ts +++ b/src/seaport.ts @@ -946,6 +946,7 @@ export class Seaport { offererOperator, fulfillerOperator, recipientAddress, + fulfillerAddress, domain, overrides, }, @@ -1102,6 +1103,7 @@ export class Seaport { signer: fulfiller, conduitKey, recipientAddress, + fulfillerAddress, domain, exactApproval, overrides, diff --git a/src/utils/balanceAndApprovalCheck.ts b/src/utils/balanceAndApprovalCheck.ts index 3b503f79..31ba1bc4 100644 --- a/src/utils/balanceAndApprovalCheck.ts +++ b/src/utils/balanceAndApprovalCheck.ts @@ -342,6 +342,7 @@ export const validateStandardFulfillBalancesAndApprovals = ({ timeBasedItemParams, offererOperator, fulfillerOperator, + offerItemsGoToFulfiller = true, }: Pick & { offerCriteria: InputCriteria[] considerationCriteria: InputCriteria[] @@ -350,6 +351,7 @@ export const validateStandardFulfillBalancesAndApprovals = ({ timeBasedItemParams: TimeBasedItemParams offererOperator: string fulfillerOperator: string + offerItemsGoToFulfiller?: boolean }) => { validateOfferBalancesAndApprovals({ offer, @@ -360,13 +362,20 @@ export const validateStandardFulfillBalancesAndApprovals = ({ operator: offererOperator, }) + // Requirement 2 above only holds while the offered items land with the + // fulfiller. When they are forwarded to someone else, the fulfiller never + // receives them and has to cover every consideration item out of what they + // already hold, so crediting the offer here would clear a fulfillment that + // reverts on transfer. const fulfillerBalancesAndApprovalsAfterReceivingOfferedItems = - addToExistingBalances({ - items: offer, - criterias: offerCriteria, - balancesAndApprovals: fulfillerBalancesAndApprovals, - timeBasedItemParams, - }) + offerItemsGoToFulfiller + ? addToExistingBalances({ + items: offer, + criterias: offerCriteria, + balancesAndApprovals: fulfillerBalancesAndApprovals, + timeBasedItemParams, + }) + : fulfillerBalancesAndApprovals const { insufficientBalances, insufficientApprovals } = getInsufficientBalanceAndApprovalAmounts({ diff --git a/src/utils/fulfill.ts b/src/utils/fulfill.ts index f15d251e..52c155c9 100644 --- a/src/utils/fulfill.ts +++ b/src/utils/fulfill.ts @@ -346,6 +346,7 @@ export function fulfillStandardOrder( timeBasedItemParams, conduitKey, recipientAddress, + fulfillerAddress, signer, domain, overrides, @@ -365,6 +366,7 @@ export function fulfillStandardOrder( fulfillerOperator: string conduitKey: string recipientAddress: string + fulfillerAddress: string timeBasedItemParams: TimeBasedItemParams signer: Signer domain?: string @@ -462,6 +464,10 @@ export function fulfillStandardOrder( timeBasedItemParams, offererOperator, fulfillerOperator, + offerItemsGoToFulfiller: offerItemsLandWithFulfiller( + recipientAddress, + fulfillerAddress, + ), }) overrides = { ...overrides, value: totalNativeAmount } @@ -536,6 +542,23 @@ export function fulfillStandardOrder( } } +/** + * Whether the order's offered items end up with the fulfiller. + * + * `recipientAddress` forwards them somewhere else, with the zero address + * meaning "leave them with the fulfiller". Naming the fulfiller explicitly is + * the same thing, so it counts as landing with them too. + */ +export function offerItemsLandWithFulfiller( + recipientAddress: string, + fulfillerAddress: string, +): boolean { + return ( + recipientAddress === ethers.ZeroAddress || + recipientAddress.toLowerCase() === fulfillerAddress.toLowerCase() + ) +} + export function validateAndSanitizeFromOrderStatus( order: Order, orderStatus: OrderStatus, @@ -580,6 +603,7 @@ export function fulfillAvailableOrders({ conduitKey, signer, recipientAddress, + fulfillerAddress, exactApproval, domain, overrides, @@ -593,6 +617,7 @@ export function fulfillAvailableOrders({ conduitKey: string signer: Signer recipientAddress: string + fulfillerAddress: string exactApproval: boolean domain?: string overrides?: Overrides @@ -738,6 +763,10 @@ export function fulfillAvailableOrders({ timeBasedItemParams, offererOperator, fulfillerOperator, + offerItemsGoToFulfiller: offerItemsLandWithFulfiller( + recipientAddress, + fulfillerAddress, + ), }, ) diff --git a/test/gifting.spec.ts b/test/gifting.spec.ts index 6166d70e..e4e472b2 100644 --- a/test/gifting.spec.ts +++ b/test/gifting.spec.ts @@ -295,5 +295,100 @@ describeWithFixture( }) }) }) + + // Accepting a bid pays the fulfiller in the bid currency, and the fee on + // that bid is a consideration item the fulfiller settles. Those two net out + // while the fulfiller keeps the proceeds. Forward them to someone else and + // the fee has to come from the fulfiller's own balance instead. + describe("[Accept offer] I want to send the proceeds to another address", () => { + const bidNftId = "77" + const bidAmount = parseEther("10") + let bid: Awaited> + + const buildBid = async () => { + const { seaport, testErc20, testErc721 } = fixture + + const input: CreateOrderInput = { + startTime: "0", + offer: [ + { + token: await testErc20.getAddress(), + amount: bidAmount.toString(), + }, + ], + consideration: [ + { + itemType: ItemType.ERC721, + token: await testErc721.getAddress(), + identifier: bidNftId, + recipient: await offerer.getAddress(), + }, + ], + fees: [{ recipient: await zone.getAddress(), basisPoints: 250 }], + } + + return ( + await seaport.createOrder(input, await offerer.getAddress()) + ).executeAllActions() + } + + beforeEach(async () => { + const { testErc20, testErc721 } = fixture + + // The fulfiller owns the NFT but holds none of the bid currency. + await testErc721.mint(await fulfiller.getAddress(), bidNftId) + await testErc20.mint(await offerer.getAddress(), bidAmount) + + bid = await buildBid() + }) + + it("reports the shortfall when the proceeds go elsewhere", async () => { + const { seaport } = fixture + + await expect( + seaport.fulfillOrder({ + order: bid, + accountAddress: await fulfiller.getAddress(), + recipientAddress: await recipient.getAddress(), + }), + ).to.be.rejectedWith("The fulfiller does not have the balances needed") + }) + + it("still lets the fee come out of the proceeds when they are kept", async () => { + const { seaport, testErc20 } = fixture + + const { actions } = await seaport.fulfillOrder({ + order: bid, + accountAddress: await fulfiller.getAddress(), + }) + + for (const action of actions) { + await (await action.transactionMethods.transact()).wait() + } + + // 10 received, 0.25 paid out as the fee. + expect(await testErc20.balanceOf(await fulfiller.getAddress())).to.eq( + parseEther("9.75"), + ) + }) + + it("treats naming yourself as the recipient the same as keeping them", async () => { + const { seaport, testErc20 } = fixture + + const { actions } = await seaport.fulfillOrder({ + order: bid, + accountAddress: await fulfiller.getAddress(), + recipientAddress: await fulfiller.getAddress(), + }) + + for (const action of actions) { + await (await action.transactionMethods.transact()).wait() + } + + expect(await testErc20.balanceOf(await fulfiller.getAddress())).to.eq( + parseEther("9.75"), + ) + }) + }) }, )