Skip to content

Commit

Permalink
Add more tx override params (#373)
Browse files Browse the repository at this point in the history
* move OPENSEA_DOMAIN and OPENSEA_DOMAIN_TAG to constants file

* add tx overrides to more methods that send txs

* fixes

* trim whitespace
  • Loading branch information
ryanio authored Oct 13, 2023
1 parent 1f9f820 commit db93843
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 78 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber } from "ethers";
import { BigNumber, constants } from "ethers";

export const SEAPORT_CONTRACT_NAME = "Seaport";
export const SEAPORT_CONTRACT_VERSION_V1_4 = "1.4";
Expand Down Expand Up @@ -108,9 +108,8 @@ export enum BasicOrderRouteType {
export const MAX_INT = BigNumber.from(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
);
export const ONE_HUNDRED_PERCENT_BP = 10000;
export const NO_CONDUIT =
"0x0000000000000000000000000000000000000000000000000000000000000000";
export const ONE_HUNDRED_PERCENT_BP = 10_000;
export const NO_CONDUIT = constants.HashZero;

// Supply here any known conduit keys as well as their conduits
export const KNOWN_CONDUIT_KEYS_TO_CONDUIT = {
Expand Down
53 changes: 39 additions & 14 deletions src/seaport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,19 +563,21 @@ export class Seaport {
* @param orders list of order components
* @param accountAddress optional account address from which to cancel the orders from.
* @param domain optional domain to be hashed and appended to calldata
* @param overrides any transaction overrides the client wants, ignored if not set
* @returns the set of transaction methods that can be used
*/
public cancelOrders(
orders: OrderComponents[],
accountAddress?: string,
domain?: string,
overrides?: PayableOverrides,
): TransactionMethods<ContractMethodReturnType<SeaportContract, "cancel">> {
const signer = this._getSigner(accountAddress);

return getTransactionMethods(
this.contract.connect(signer),
"cancel",
[orders],
[orders, overrides],
domain,
);
}
Expand All @@ -584,11 +586,13 @@ export class Seaport {
* Bulk cancels all existing orders for a given account
* @param offerer the account to bulk cancel orders on
* @param domain optional domain to be hashed and appended to calldata
* @param overrides any transaction overrides the client wants, ignored if not set
* @returns the set of transaction methods that can be used
*/
public bulkCancelOrders(
offerer?: string,
domain?: string,
overrides?: PayableOverrides,
): TransactionMethods<
ContractMethodReturnType<SeaportContract, "incrementCounter">
> {
Expand All @@ -597,7 +601,7 @@ export class Seaport {
return getTransactionMethods(
this.contract.connect(signer),
"incrementCounter",
[],
[overrides],
domain,
);
}
Expand All @@ -608,19 +612,21 @@ export class Seaport {
* @param orders list of order structs
* @param accountAddress optional account address to approve orders.
* @param domain optional domain to be hashed and appended to calldata
* @param overrides any transaction overrides the client wants, ignored if not set
* @returns the set of transaction methods that can be used
*/
public validate(
orders: Order[],
accountAddress?: string,
domain?: string,
overrides?: PayableOverrides,
): TransactionMethods<ContractMethodReturnType<SeaportContract, "validate">> {
const signer = this._getSigner(accountAddress);

return getTransactionMethods(
this.contract.connect(signer),
"validate",
[orders],
[orders, overrides],
domain,
);
}
Expand Down Expand Up @@ -780,7 +786,7 @@ export class Seaport {
* Defaults to the zero address which means the offer goes to the fulfiller
* @param input.domain optional domain to be hashed and appended to calldata
* @param input.exactApproval optional boolean to indicate whether the approval should be exact or not
* @param input.overrides any overrides the client wants, will ignore value
* @param input.overrides any transaction overrides the client wants, ignored if not set
* @returns a use case containing the set of approval actions and fulfillment action
*/
public async fulfillOrder({
Expand Down Expand Up @@ -1082,7 +1088,7 @@ export class Seaport {
* @param input
* @param input.orders the list of orders to match
* @param input.fulfillments the list of fulfillments to match offer and considerations
* @param input.overrides any overrides the client wants, will need to pass in value for matching orders with ETH.
* @param input.overrides any transaction overrides the client wants, will need to pass in value for matching orders with ETH.
* @param input.accountAddress Optional address for which to match the order with
* @param input.domain optional domain to be hashed and appended to calldata
* @returns set of transaction methods for matching orders
Expand Down Expand Up @@ -1112,9 +1118,17 @@ export class Seaport {
);
}

/**
* Set a domain on the canonical domain registry.
* @param domain The domain to set
* @param accountAddress Address to send the transaction from
* @param overrides Any transaction overrides the client wants, ignored if not set
* @returns The domain tag (4 byte keccak hash of the domain)
*/
public setDomain(
domain: string,
accountAddress?: string,
overrides?: PayableOverrides,
): TransactionMethods<
ContractMethodReturnType<DomainRegistryContract, "setDomain">
> {
Expand All @@ -1123,29 +1137,40 @@ export class Seaport {
return getTransactionMethods(
this.domainRegistry.connect(signer),
"setDomain",
[domain],
[domain, overrides],
);
}

/**
* Get the number of domains registered under a domain tag.
* @param tag The domain tag.
* @returns The number of domains registered under the tag.
*/
public async getNumberOfDomains(tag: string): Promise<BigNumber> {
return this.domainRegistry.getNumberOfDomains(tag);
}

/**
* Gets the domain at a given index under a domain tag.
* @param tag The domain tag.
* @param index The index.
* @returns The domain at the index for the given tag.
*/
public getDomain(tag: string, index: number): Promise<string> {
return this.domainRegistry.getDomain(tag, index);
}

public async getDomains(
tag: string,
shouldThrow?: boolean,
): Promise<string[]> {
/**
* Gets the domains registered under a tag.
* @param tag The domain tag.
* @returns The domains registered under the tag.
*/
public async getDomains(tag: string): Promise<string[]> {
try {
if (shouldThrow) {
throw Error;
}

return this.domainRegistry.getDomains(tag);
} catch (error) {
// If there are too many domains set under the tag, it will revert when trying to return in memory.
// This fallback will manually query each index to get the full list of domains.
const totalDomains = (
await this.domainRegistry.getNumberOfDomains(tag)
).toNumber();
Expand Down
7 changes: 3 additions & 4 deletions test/basic-fulfill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
verifyBalancesAfterFulfill,
} from "./utils/balance";
import { describeWithFixture } from "./utils/setup";
import { OPENSEA_DOMAIN, OVERRIDE_GAS_LIMIT } from "./utils/constants";

const sinon = require("sinon");

Expand All @@ -27,8 +28,6 @@ describeWithFixture(
let fulfillStandardOrderSpy: sinon.SinonSpy; // eslint-disable-line no-undef
const nftId = "1";
const erc1155Amount = "3";
const OPENSEA_DOMAIN = "opensea.io";
const overrideGasLimit = 10_000_000;

beforeEach(async () => {
fulfillBasicOrderSpy = sinon.spy(fulfill, "fulfillBasicOrder");
Expand Down Expand Up @@ -207,7 +206,7 @@ describeWithFixture(
order,
accountAddress: fulfiller.address,
domain: OPENSEA_DOMAIN,
overrides: { gasLimit: overrideGasLimit },
overrides: { gasLimit: OVERRIDE_GAS_LIMIT },
});

const approvalAction = actions[0];
Expand Down Expand Up @@ -250,7 +249,7 @@ describeWithFixture(
fulfillReceipt: receipt,
});
expect(fulfillBasicOrderSpy).calledOnce;
expect(transaction.gasLimit).equal(overrideGasLimit);
expect(transaction.gasLimit).equal(OVERRIDE_GAS_LIMIT);
});

it("ERC721 <=> ERC20 (already validated order)", async () => {
Expand Down
20 changes: 17 additions & 3 deletions test/cancel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ethers } from "hardhat";
import { ItemType } from "../src/constants";
import { CreateOrderInput } from "../src/types";
import { describeWithFixture } from "./utils/setup";
import { OVERRIDE_GAS_LIMIT } from "./utils/constants";

describeWithFixture("As a user I want to cancel an order", (fixture) => {
let offerer: SignerWithAddress;
Expand Down Expand Up @@ -58,8 +59,17 @@ describeWithFixture("As a user I want to cancel an order", (fixture) => {
// Remove signature
onChainOrder.signature = "0x";

await seaport.validate([onChainOrder], offerer.address).transact();
await seaport.bulkCancelOrders(offerer.address).transact();
const overrides = { gasLimit: OVERRIDE_GAS_LIMIT };

const validateTx = await seaport
.validate([onChainOrder], offerer.address, undefined, overrides)
.transact();
expect(validateTx.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);

const bulkCancelOrdersTx = await seaport
.bulkCancelOrders(offerer.address, undefined, overrides)
.transact();
expect(bulkCancelOrdersTx.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);

const { executeAllActions: executeAllFulfillActionsOffChainOrder } =
await seaport.fulfillOrder({
Expand Down Expand Up @@ -101,10 +111,14 @@ describeWithFixture("As a user I want to cancel an order", (fixture) => {
true,
);

await seaport.cancelOrders([order.parameters], offerer.address).transact();
const overrides = { gasLimit: OVERRIDE_GAS_LIMIT };
const cancelOrdersTx = await seaport
.cancelOrders([order.parameters], offerer.address, undefined, overrides)
.transact();
expect(await seaport.getOrderStatus(orderHash)).to.have.property(
"isCancelled",
true,
);
expect(cancelOrdersTx.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);
});
});
9 changes: 3 additions & 6 deletions test/create-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "../src/types";
import { generateRandomSalt } from "../src/utils/order";
import { describeWithFixture } from "./utils/setup";
import { OPENSEA_DOMAIN, OPENSEA_DOMAIN_TAG } from "./utils/constants";

describeWithFixture("As a user I want to create an order", (fixture) => {
it("should create the order after setting needed approvals", async () => {
Expand Down Expand Up @@ -921,9 +922,6 @@ describeWithFixture("As a user I want to create an order", (fixture) => {
});
});

const OPENSEA_DOMAIN = "opensea.io";
const OPENSEA_TAG = "360c6ebe";

describeWithFixture(
"As a user I want to create and fulfill an order using contract wallet",
(fixture) => {
Expand Down Expand Up @@ -1005,11 +1003,10 @@ describeWithFixture(

const exchangeTransaction =
await exchange.transactionMethods.buildTransaction();
expect(exchangeTransaction.data?.slice(-8)).to.eq(OPENSEA_TAG);
expect(exchangeTransaction.data?.slice(-8)).to.eq(OPENSEA_DOMAIN_TAG);

const transaction = await exchange.transactionMethods.transact();

expect(transaction.data.slice(-8)).to.eq(OPENSEA_TAG);
expect(transaction.data.slice(-8)).to.eq(OPENSEA_DOMAIN_TAG);

expect(await testErc721.ownerOf(nftId)).to.equal(
testERC1271Wallet.address,
Expand Down
29 changes: 21 additions & 8 deletions test/domain-registry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { expect } from "chai";
import { keccak256, toUtf8Bytes } from "ethers/lib/utils";
import { ethers } from "hardhat";
import { describeWithFixture } from "./utils/setup";
import {
OPENSEA_DOMAIN,
OPENSEA_DOMAIN_TAG,
OVERRIDE_GAS_LIMIT,
} from "./utils/constants";

describeWithFixture(
"As a user I want to register or look up a domain",
(fixture) => {
let user: SignerWithAddress;

const OPENSEA_DOMAIN = "opensea.io";
const OPENSEA_TAG = keccak256(toUtf8Bytes(OPENSEA_DOMAIN)).slice(0, 10);

const expectedExampleDomainArray = [
"join_tg_invmru_haha_fd06787(address,bool)",
"func_2093253501(bytes)",
Expand All @@ -27,9 +29,11 @@ describeWithFixture(

[user] = await ethers.getSigners();

await seaport
.setDomain(expectedExampleDomainArray[0], user.address)
const overrides = { gasLimit: OVERRIDE_GAS_LIMIT };
const setDomainTxWithOverrides = await seaport
.setDomain(expectedExampleDomainArray[0], user.address, overrides)
.transact();
expect(setDomainTxWithOverrides.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);

await seaport
.setDomain(expectedExampleDomainArray[1], user.address)
Expand All @@ -49,7 +53,9 @@ describeWithFixture(

await seaport.setDomain(OPENSEA_DOMAIN, user.address).transact();

expect(await seaport.getDomain(OPENSEA_TAG, 0)).to.eq(OPENSEA_DOMAIN);
expect(await seaport.getDomain(`0x${OPENSEA_DOMAIN_TAG}`, 0)).to.eq(
OPENSEA_DOMAIN,
);

expect(await seaport.getDomain(exampleTag, 0)).to.eq(
expectedExampleDomainArray[0],
Expand Down Expand Up @@ -82,10 +88,17 @@ describeWithFixture(
expect(await seaport.getNumberOfDomains(exampleTag)).to.eq(4);
});

it("Should return an array of domains even if getDomains should throw", async () => {
it("Should return an array of domains even if getDomains throws", async () => {
const { seaport } = fixture;

expect(await seaport.getDomains(exampleTag, true)).to.deep.eq(
(seaport.domainRegistry as any) = {
...seaport.domainRegistry,
getDomains: () => {
throw new Error();
},
};

expect(await seaport.getDomains(exampleTag)).to.deep.eq(
expectedExampleDomainArray,
);
});
Expand Down
Loading

0 comments on commit db93843

Please sign in to comment.