Skip to content
Merged
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
11 changes: 9 additions & 2 deletions src/sdk/fulfillment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
getSeaportInstance,
} from "../utils/utils";

const FULFILL_BASIC_ORDER_ALIAS = "fulfillBasicOrder_efficient_6GL6yc";

/**
* Manager for order fulfillment and validation operations.
* Handles fulfilling orders, validating orders onchain, and approving orders.
Expand Down Expand Up @@ -175,7 +177,11 @@ export class FulfillmentManager {
const seaportInterface = new ethers.Interface(SeaportABI);

// Extract function name and build parameters array in correct order
const functionName = transaction.function.split("(")[0];
const rawFunctionName = transaction.function.split("(")[0];
const functionName =
rawFunctionName === FULFILL_BASIC_ORDER_ALIAS
? "fulfillBasicOrder"
: rawFunctionName;
let params: unknown[];

// Order parameters based on the function being called
Expand All @@ -191,7 +197,8 @@ export class FulfillmentManager {
inputData.recipient,
];
} else if (
functionName === "fulfillBasicOrder" &&
(functionName === "fulfillBasicOrder" ||
rawFunctionName === FULFILL_BASIC_ORDER_ALIAS) &&
"basicOrderParameters" in inputData
) {
params = [inputData.basicOrderParameters];
Expand Down
42 changes: 42 additions & 0 deletions test/sdk/fulfillmentManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "chai";
import { ethers } from "ethers";
import { suite, test } from "mocha";
import * as sinon from "sinon";
import { FulfillmentManager } from "../../src/sdk/fulfillment";
Expand Down Expand Up @@ -258,6 +259,47 @@ suite("SDK: FulfillmentManager", () => {
expect(apiCall[7]).to.equal(recipientAddress);
});

test("encodes fulfillBasicOrder alias using supported fragment", async () => {
mockAPI.generateFulfillmentData.resolves({
fulfillment_data: {
transaction: {
to: "0xSeaportAddress",
value: 0,
function: "fulfillBasicOrder_efficient_6GL6yc((uint256))",
input_data: {
basicOrderParameters: {
offerer: "0xOfferer",
zone: "0x0000000000000000000000000000000000000000",
},
},
},
orders: [{ signature: "0xAliasSignature" }],
},
});

const encodeStub = sinon.stub(
ethers.Interface.prototype,
"encodeFunctionData",
);
encodeStub.callsFake(() => "0xAliasEncoded");

try {
const result = await fulfillmentManager.fulfillOrder({
order: mockOrderV2,
accountAddress: "0xBuyer",
});

expect(result).to.equal("0xFulfillTxHash");
expect(mockSigner.sendTransaction.calledOnce).to.be.true;
expect(encodeStub.firstCall.args[0]).to.equal("fulfillBasicOrder");
expect(mockSigner.sendTransaction.firstCall.args[0].data).to.equal(
"0xAliasEncoded",
);
} finally {
encodeStub.restore();
}
});

test("fulfills private listing successfully", async () => {
const result = await fulfillmentManager.fulfillOrder({
order: mockPrivateListingOrderV2,
Expand Down