Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Fix native currency tip amount scaling logic for partial fills when using fulfillOrders #565

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensea/seaport-js",
"version": "4.0.1",
"version": "4.0.2",
"description": "[Seaport](https://github.com/ProjectOpenSea/seaport) is a new marketplace protocol for safely and efficiently buying and selling NFTs. This is a TypeScript library intended to make interfacing with the contract reasonable and easy.",
"license": "MIT",
"author": "OpenSea Developers",
Expand Down
13 changes: 1 addition & 12 deletions src/seaport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ import {
shouldUseBasicFulfill,
validateAndSanitizeFromOrderStatus,
} from "./utils/fulfill";
import { getMaximumSizeForOrder, isCurrencyItem } from "./utils/item";
import { isCurrencyItem } from "./utils/item";
import {
adjustTipsForPartialFills,
areAllCurrenciesSame,
deductFees,
feeToConsiderationItem,
Expand Down Expand Up @@ -1049,16 +1048,6 @@ export class Seaport {
offererBalancesAndApprovals: offerersBalancesAndApprovals[index],
offererOperator: allOffererOperators[index],
};
if (order.tips.length > 0) {
order.tips = adjustTipsForPartialFills(
order.tips,
order.unitsToFill || 1,
// Max total amount to fulfill for scaling
getMaximumSizeForOrder({
...order.order,
}),
);
}

return order;
},
Expand Down
26 changes: 26 additions & 0 deletions src/utils/fulfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,31 @@ export function fulfillAvailableOrders({
),
}));

const adjustTips = (orderMetadata: {
order: Order;
unitsToFill?: BigNumberish;
orderStatus: OrderStatus;
offerCriteria: InputCriteria[];
considerationCriteria: InputCriteria[];
tips: ConsiderationItem[];
extraData: string;
offererBalancesAndApprovals: BalancesAndApprovals;
offererOperator: string;
}): ConsiderationItem[] => {
if (!orderMetadata.tips || !orderMetadata.tips.length) {
return [];
}

// Max total amount to fulfill for scaling
const maxUnits = getMaximumSizeForOrder(orderMetadata.order);

return adjustTipsForPartialFills(
orderMetadata.tips,
orderMetadata.unitsToFill || 1,
maxUnits,
);
};

const ordersMetadataWithAdjustedFills = sanitizedOrdersMetadata.map(
(orderMetadata) => ({
...orderMetadata,
Expand All @@ -589,6 +614,7 @@ export function fulfillAvailableOrders({
totalFilled: orderMetadata.orderStatus.totalFilled,
totalSize: orderMetadata.orderStatus.totalSize,
}),
tips: adjustTips(orderMetadata),
}),
);

Expand Down
5 changes: 4 additions & 1 deletion test/partial-fulfill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describeWithFixture(
let fulfiller: Signer;

let fulfillStandardOrderSpy: SinonSpy;
let fulfillAvailableOrdersSpy: SinonSpy;
let standardCreateOrderInput: CreateOrderInput;
let secondTestErc1155: TestERC1155;

Expand All @@ -33,6 +34,7 @@ describeWithFixture(
[offerer, zone, fulfiller] = await ethers.getSigners();

fulfillStandardOrderSpy = sinon.spy(fulfill, "fulfillStandardOrder");
fulfillAvailableOrdersSpy = sinon.spy(fulfill, "fulfillAvailableOrders");

const TestERC1155 = await ethers.getContractFactory("TestERC1155");
secondTestErc1155 = await TestERC1155.deploy();
Expand All @@ -41,6 +43,7 @@ describeWithFixture(

afterEach(() => {
fulfillStandardOrderSpy.restore();
fulfillAvailableOrdersSpy.restore();
});

describe("An ERC1155 is partially transferred", () => {
Expand Down Expand Up @@ -304,7 +307,7 @@ describeWithFixture(
fulfillReceipt: receipt!,
});

expect(fulfillStandardOrderSpy.calledOnce);
expect(fulfillAvailableOrdersSpy.calledOnce).to.be.true;
});

it("ERC1155 <=> ETH adjust tips correctly with low denomination", async () => {
Expand Down