Skip to content

Commit 2c8e9be

Browse files
authored
Seaport v1.2: large counters (#161)
* update counter to be Bignumberish, since in seaport v1.2 it is incremented by large amounts (rather than one by one) * fix typo
1 parent 7f0912e commit 2c8e9be

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

src/__tests__/cancel.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
22
import { expect } from "chai";
3+
import { BigNumber } from "ethers";
34
import { parseEther } from "ethers/lib/utils";
45
import { ethers } from "hardhat";
56
import { ItemType } from "../constants";
@@ -76,8 +77,8 @@ describeWithFixture("As a user I want to cancel an order", (fixture) => {
7677
await expect(executeAllFulfillActionsOffChainOrder()).to.be.reverted;
7778
await expect(executeAllFulfillActionsOnChainOrder()).to.be.reverted;
7879

79-
expect(await seaport.getCounter(offerer.address)).to.equal(
80-
offChainOrder.parameters.counter + 1
80+
expect(await seaport.getCounter(offerer.address)).to.deep.equal(
81+
BigNumber.from(offChainOrder.parameters.counter).add(1)
8182
);
8283
});
8384

src/__tests__/create-bulk-orders.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from "chai";
2+
import { BigNumber } from "ethers";
23
import { ethers } from "hardhat";
34
import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../constants";
45
import {
@@ -128,7 +129,7 @@ describeWithFixture(
128129
zone: ethers.constants.AddressZero,
129130
zoneHash: ethers.constants.HashZero,
130131
conduitKey: NO_CONDUIT,
131-
counter: 0,
132+
counter: BigNumber.from(0),
132133
},
133134
signature: order.signature,
134135
});

src/__tests__/create-order.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ItemType, MAX_INT, NO_CONDUIT, OrderType } from "../constants";
66
import { ApprovalAction, CreateOrderAction } from "../types";
77
import { generateRandomSalt } from "../utils/order";
88
import { describeWithFixture } from "./utils/setup";
9+
import { BigNumber } from "ethers";
910

1011
describeWithFixture("As a user I want to create an order", (fixture) => {
1112
it("should create the order after setting needed approvals", async () => {
@@ -103,7 +104,7 @@ describeWithFixture("As a user I want to create an order", (fixture) => {
103104
zone: ethers.constants.AddressZero,
104105
zoneHash: ethers.constants.HashZero,
105106
conduitKey: NO_CONDUIT,
106-
counter: 0,
107+
counter: BigNumber.from(0),
107108
},
108109
signature: order.signature,
109110
});
@@ -218,7 +219,7 @@ describeWithFixture("As a user I want to create an order", (fixture) => {
218219
zone: ethers.constants.AddressZero,
219220
zoneHash: ethers.constants.HashZero,
220221
conduitKey: NO_CONDUIT,
221-
counter: 0,
222+
counter: BigNumber.from(0),
222223
},
223224
signature: order.signature,
224225
});
@@ -382,7 +383,7 @@ describeWithFixture("As a user I want to create an order", (fixture) => {
382383
zone: ethers.constants.AddressZero,
383384
zoneHash: ethers.constants.HashZero,
384385
conduitKey: NO_CONDUIT,
385-
counter: 0,
386+
counter: BigNumber.from(0),
386387
},
387388
signature: order.signature,
388389
});
@@ -594,7 +595,7 @@ describeWithFixture("As a user I want to create an order", (fixture) => {
594595
zone: ethers.constants.AddressZero,
595596
zoneHash: ethers.constants.HashZero,
596597
conduitKey: NO_CONDUIT,
597-
counter: 0,
598+
counter: BigNumber.from(0),
598599
},
599600
signature: order.signature,
600601
});

src/__tests__/sign-order.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describeWithFixture("As a user I want to sign an order", (fixture) => {
5858
endTime,
5959
zoneHash: ethers.constants.HashZero,
6060
conduitKey: NO_CONDUIT,
61-
counter: counter.toNumber(),
61+
counter,
6262
};
6363

6464
const signature = await seaport.signOrder(orderComponents);

src/seaport.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,8 @@ export class Seaport {
636636
* @param offerer the offerer to get the counter of
637637
* @returns counter as a number
638638
*/
639-
public getCounter(offerer: string): Promise<number> {
640-
return this.contract
641-
.getCounter(offerer)
642-
.then((counter) => counter.toNumber());
639+
public getCounter(offerer: string): Promise<BigNumber> {
640+
return this.contract.getCounter(offerer);
643641
}
644642

645643
/**

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export type OrderParameters = {
9494
conduitKey: string;
9595
};
9696

97-
export type OrderComponents = OrderParameters & { counter: number };
97+
export type OrderComponents = OrderParameters & { counter: BigNumberish };
9898

9999
export type Order = {
100100
parameters: OrderParameters;
@@ -166,7 +166,7 @@ export type CreateOrderInput = {
166166
endTime?: string;
167167
offer: readonly CreateInputItem[];
168168
consideration: readonly ConsiderationInputItem[];
169-
counter?: number;
169+
counter?: BigNumberish;
170170
fees?: readonly Fee[];
171171
allowPartialFills?: boolean;
172172
restrictedByZone?: boolean;
@@ -325,7 +325,7 @@ export type SeaportContract = TypeChainSeaportContract & {
325325
): Promise<BigNumber>;
326326
};
327327

328-
populateTranscation: TypeChainSeaportContract["populateTransaction"] & {
328+
populateTransaction: TypeChainSeaportContract["populateTransaction"] & {
329329
matchOrders(
330330
orders: OrderStruct[],
331331
fulfillments: MatchOrdersFulfillment[],

src/utils/usecase.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ export const executeAllActions = async <
2525

2626
const finalAction = actions[actions.length - 1] as T;
2727

28-
return finalAction.type === "create"
29-
? await finalAction.createOrder()
30-
: finalAction.type === "createBulk"
31-
? await finalAction.createBulkOrders()
32-
: await finalAction.transactionMethods.transact();
28+
switch (finalAction.type) {
29+
case "create":
30+
return finalAction.createOrder();
31+
case "createBulk":
32+
return finalAction.createBulkOrders();
33+
default:
34+
return finalAction.transactionMethods.transact();
35+
}
3336
};
3437

3538
const instanceOfOverrides = <

0 commit comments

Comments
 (0)