Skip to content

Commit db93843

Browse files
authored
Add more tx override params (#373)
* move OPENSEA_DOMAIN and OPENSEA_DOMAIN_TAG to constants file * add tx overrides to more methods that send txs * fixes * trim whitespace
1 parent 1f9f820 commit db93843

File tree

10 files changed

+113
-78
lines changed

10 files changed

+113
-78
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BigNumber } from "ethers";
1+
import { BigNumber, constants } from "ethers";
22

33
export const SEAPORT_CONTRACT_NAME = "Seaport";
44
export const SEAPORT_CONTRACT_VERSION_V1_4 = "1.4";
@@ -108,9 +108,8 @@ export enum BasicOrderRouteType {
108108
export const MAX_INT = BigNumber.from(
109109
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
110110
);
111-
export const ONE_HUNDRED_PERCENT_BP = 10000;
112-
export const NO_CONDUIT =
113-
"0x0000000000000000000000000000000000000000000000000000000000000000";
111+
export const ONE_HUNDRED_PERCENT_BP = 10_000;
112+
export const NO_CONDUIT = constants.HashZero;
114113

115114
// Supply here any known conduit keys as well as their conduits
116115
export const KNOWN_CONDUIT_KEYS_TO_CONDUIT = {

src/seaport.ts

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -563,19 +563,21 @@ export class Seaport {
563563
* @param orders list of order components
564564
* @param accountAddress optional account address from which to cancel the orders from.
565565
* @param domain optional domain to be hashed and appended to calldata
566+
* @param overrides any transaction overrides the client wants, ignored if not set
566567
* @returns the set of transaction methods that can be used
567568
*/
568569
public cancelOrders(
569570
orders: OrderComponents[],
570571
accountAddress?: string,
571572
domain?: string,
573+
overrides?: PayableOverrides,
572574
): TransactionMethods<ContractMethodReturnType<SeaportContract, "cancel">> {
573575
const signer = this._getSigner(accountAddress);
574576

575577
return getTransactionMethods(
576578
this.contract.connect(signer),
577579
"cancel",
578-
[orders],
580+
[orders, overrides],
579581
domain,
580582
);
581583
}
@@ -584,11 +586,13 @@ export class Seaport {
584586
* Bulk cancels all existing orders for a given account
585587
* @param offerer the account to bulk cancel orders on
586588
* @param domain optional domain to be hashed and appended to calldata
589+
* @param overrides any transaction overrides the client wants, ignored if not set
587590
* @returns the set of transaction methods that can be used
588591
*/
589592
public bulkCancelOrders(
590593
offerer?: string,
591594
domain?: string,
595+
overrides?: PayableOverrides,
592596
): TransactionMethods<
593597
ContractMethodReturnType<SeaportContract, "incrementCounter">
594598
> {
@@ -597,7 +601,7 @@ export class Seaport {
597601
return getTransactionMethods(
598602
this.contract.connect(signer),
599603
"incrementCounter",
600-
[],
604+
[overrides],
601605
domain,
602606
);
603607
}
@@ -608,19 +612,21 @@ export class Seaport {
608612
* @param orders list of order structs
609613
* @param accountAddress optional account address to approve orders.
610614
* @param domain optional domain to be hashed and appended to calldata
615+
* @param overrides any transaction overrides the client wants, ignored if not set
611616
* @returns the set of transaction methods that can be used
612617
*/
613618
public validate(
614619
orders: Order[],
615620
accountAddress?: string,
616621
domain?: string,
622+
overrides?: PayableOverrides,
617623
): TransactionMethods<ContractMethodReturnType<SeaportContract, "validate">> {
618624
const signer = this._getSigner(accountAddress);
619625

620626
return getTransactionMethods(
621627
this.contract.connect(signer),
622628
"validate",
623-
[orders],
629+
[orders, overrides],
624630
domain,
625631
);
626632
}
@@ -780,7 +786,7 @@ export class Seaport {
780786
* Defaults to the zero address which means the offer goes to the fulfiller
781787
* @param input.domain optional domain to be hashed and appended to calldata
782788
* @param input.exactApproval optional boolean to indicate whether the approval should be exact or not
783-
* @param input.overrides any overrides the client wants, will ignore value
789+
* @param input.overrides any transaction overrides the client wants, ignored if not set
784790
* @returns a use case containing the set of approval actions and fulfillment action
785791
*/
786792
public async fulfillOrder({
@@ -1082,7 +1088,7 @@ export class Seaport {
10821088
* @param input
10831089
* @param input.orders the list of orders to match
10841090
* @param input.fulfillments the list of fulfillments to match offer and considerations
1085-
* @param input.overrides any overrides the client wants, will need to pass in value for matching orders with ETH.
1091+
* @param input.overrides any transaction overrides the client wants, will need to pass in value for matching orders with ETH.
10861092
* @param input.accountAddress Optional address for which to match the order with
10871093
* @param input.domain optional domain to be hashed and appended to calldata
10881094
* @returns set of transaction methods for matching orders
@@ -1112,9 +1118,17 @@ export class Seaport {
11121118
);
11131119
}
11141120

1121+
/**
1122+
* Set a domain on the canonical domain registry.
1123+
* @param domain The domain to set
1124+
* @param accountAddress Address to send the transaction from
1125+
* @param overrides Any transaction overrides the client wants, ignored if not set
1126+
* @returns The domain tag (4 byte keccak hash of the domain)
1127+
*/
11151128
public setDomain(
11161129
domain: string,
11171130
accountAddress?: string,
1131+
overrides?: PayableOverrides,
11181132
): TransactionMethods<
11191133
ContractMethodReturnType<DomainRegistryContract, "setDomain">
11201134
> {
@@ -1123,29 +1137,40 @@ export class Seaport {
11231137
return getTransactionMethods(
11241138
this.domainRegistry.connect(signer),
11251139
"setDomain",
1126-
[domain],
1140+
[domain, overrides],
11271141
);
11281142
}
11291143

1144+
/**
1145+
* Get the number of domains registered under a domain tag.
1146+
* @param tag The domain tag.
1147+
* @returns The number of domains registered under the tag.
1148+
*/
11301149
public async getNumberOfDomains(tag: string): Promise<BigNumber> {
11311150
return this.domainRegistry.getNumberOfDomains(tag);
11321151
}
11331152

1153+
/**
1154+
* Gets the domain at a given index under a domain tag.
1155+
* @param tag The domain tag.
1156+
* @param index The index.
1157+
* @returns The domain at the index for the given tag.
1158+
*/
11341159
public getDomain(tag: string, index: number): Promise<string> {
11351160
return this.domainRegistry.getDomain(tag, index);
11361161
}
11371162

1138-
public async getDomains(
1139-
tag: string,
1140-
shouldThrow?: boolean,
1141-
): Promise<string[]> {
1163+
/**
1164+
* Gets the domains registered under a tag.
1165+
* @param tag The domain tag.
1166+
* @returns The domains registered under the tag.
1167+
*/
1168+
public async getDomains(tag: string): Promise<string[]> {
11421169
try {
1143-
if (shouldThrow) {
1144-
throw Error;
1145-
}
1146-
11471170
return this.domainRegistry.getDomains(tag);
11481171
} catch (error) {
1172+
// If there are too many domains set under the tag, it will revert when trying to return in memory.
1173+
// This fallback will manually query each index to get the full list of domains.
11491174
const totalDomains = (
11501175
await this.domainRegistry.getNumberOfDomains(tag)
11511176
).toNumber();

test/basic-fulfill.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
verifyBalancesAfterFulfill,
1313
} from "./utils/balance";
1414
import { describeWithFixture } from "./utils/setup";
15+
import { OPENSEA_DOMAIN, OVERRIDE_GAS_LIMIT } from "./utils/constants";
1516

1617
const sinon = require("sinon");
1718

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

3332
beforeEach(async () => {
3433
fulfillBasicOrderSpy = sinon.spy(fulfill, "fulfillBasicOrder");
@@ -207,7 +206,7 @@ describeWithFixture(
207206
order,
208207
accountAddress: fulfiller.address,
209208
domain: OPENSEA_DOMAIN,
210-
overrides: { gasLimit: overrideGasLimit },
209+
overrides: { gasLimit: OVERRIDE_GAS_LIMIT },
211210
});
212211

213212
const approvalAction = actions[0];
@@ -250,7 +249,7 @@ describeWithFixture(
250249
fulfillReceipt: receipt,
251250
});
252251
expect(fulfillBasicOrderSpy).calledOnce;
253-
expect(transaction.gasLimit).equal(overrideGasLimit);
252+
expect(transaction.gasLimit).equal(OVERRIDE_GAS_LIMIT);
254253
});
255254

256255
it("ERC721 <=> ERC20 (already validated order)", async () => {

test/cancel.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ethers } from "hardhat";
55
import { ItemType } from "../src/constants";
66
import { CreateOrderInput } from "../src/types";
77
import { describeWithFixture } from "./utils/setup";
8+
import { OVERRIDE_GAS_LIMIT } from "./utils/constants";
89

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

61-
await seaport.validate([onChainOrder], offerer.address).transact();
62-
await seaport.bulkCancelOrders(offerer.address).transact();
62+
const overrides = { gasLimit: OVERRIDE_GAS_LIMIT };
63+
64+
const validateTx = await seaport
65+
.validate([onChainOrder], offerer.address, undefined, overrides)
66+
.transact();
67+
expect(validateTx.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);
68+
69+
const bulkCancelOrdersTx = await seaport
70+
.bulkCancelOrders(offerer.address, undefined, overrides)
71+
.transact();
72+
expect(bulkCancelOrdersTx.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);
6373

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

104-
await seaport.cancelOrders([order.parameters], offerer.address).transact();
114+
const overrides = { gasLimit: OVERRIDE_GAS_LIMIT };
115+
const cancelOrdersTx = await seaport
116+
.cancelOrders([order.parameters], offerer.address, undefined, overrides)
117+
.transact();
105118
expect(await seaport.getOrderStatus(orderHash)).to.have.property(
106119
"isCancelled",
107120
true,
108121
);
122+
expect(cancelOrdersTx.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);
109123
});
110124
});

test/create-order.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "../src/types";
1010
import { generateRandomSalt } from "../src/utils/order";
1111
import { describeWithFixture } from "./utils/setup";
12+
import { OPENSEA_DOMAIN, OPENSEA_DOMAIN_TAG } from "./utils/constants";
1213

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

924-
const OPENSEA_DOMAIN = "opensea.io";
925-
const OPENSEA_TAG = "360c6ebe";
926-
927925
describeWithFixture(
928926
"As a user I want to create and fulfill an order using contract wallet",
929927
(fixture) => {
@@ -1005,11 +1003,10 @@ describeWithFixture(
10051003

10061004
const exchangeTransaction =
10071005
await exchange.transactionMethods.buildTransaction();
1008-
expect(exchangeTransaction.data?.slice(-8)).to.eq(OPENSEA_TAG);
1006+
expect(exchangeTransaction.data?.slice(-8)).to.eq(OPENSEA_DOMAIN_TAG);
10091007

10101008
const transaction = await exchange.transactionMethods.transact();
1011-
1012-
expect(transaction.data.slice(-8)).to.eq(OPENSEA_TAG);
1009+
expect(transaction.data.slice(-8)).to.eq(OPENSEA_DOMAIN_TAG);
10131010

10141011
expect(await testErc721.ownerOf(nftId)).to.equal(
10151012
testERC1271Wallet.address,

test/domain-registry.spec.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import { expect } from "chai";
33
import { keccak256, toUtf8Bytes } from "ethers/lib/utils";
44
import { ethers } from "hardhat";
55
import { describeWithFixture } from "./utils/setup";
6+
import {
7+
OPENSEA_DOMAIN,
8+
OPENSEA_DOMAIN_TAG,
9+
OVERRIDE_GAS_LIMIT,
10+
} from "./utils/constants";
611

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

12-
const OPENSEA_DOMAIN = "opensea.io";
13-
const OPENSEA_TAG = keccak256(toUtf8Bytes(OPENSEA_DOMAIN)).slice(0, 10);
14-
1517
const expectedExampleDomainArray = [
1618
"join_tg_invmru_haha_fd06787(address,bool)",
1719
"func_2093253501(bytes)",
@@ -27,9 +29,11 @@ describeWithFixture(
2729

2830
[user] = await ethers.getSigners();
2931

30-
await seaport
31-
.setDomain(expectedExampleDomainArray[0], user.address)
32+
const overrides = { gasLimit: OVERRIDE_GAS_LIMIT };
33+
const setDomainTxWithOverrides = await seaport
34+
.setDomain(expectedExampleDomainArray[0], user.address, overrides)
3235
.transact();
36+
expect(setDomainTxWithOverrides.gasLimit).to.eq(OVERRIDE_GAS_LIMIT);
3337

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

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

52-
expect(await seaport.getDomain(OPENSEA_TAG, 0)).to.eq(OPENSEA_DOMAIN);
56+
expect(await seaport.getDomain(`0x${OPENSEA_DOMAIN_TAG}`, 0)).to.eq(
57+
OPENSEA_DOMAIN,
58+
);
5359

5460
expect(await seaport.getDomain(exampleTag, 0)).to.eq(
5561
expectedExampleDomainArray[0],
@@ -82,10 +88,17 @@ describeWithFixture(
8288
expect(await seaport.getNumberOfDomains(exampleTag)).to.eq(4);
8389
});
8490

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

88-
expect(await seaport.getDomains(exampleTag, true)).to.deep.eq(
94+
(seaport.domainRegistry as any) = {
95+
...seaport.domainRegistry,
96+
getDomains: () => {
97+
throw new Error();
98+
},
99+
};
100+
101+
expect(await seaport.getDomains(exampleTag)).to.deep.eq(
89102
expectedExampleDomainArray,
90103
);
91104
});

0 commit comments

Comments
 (0)