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

feat: Migrate to ethers v6 #164

Merged
merged 12 commits into from
Aug 3, 2023
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ const addresses: Addresses = {...};
const looksrare = new LooksRare(ChainId.HARDHAT, provider, signer, addresses);
```

:information_source: You can access the multicall provider after the instance creation:
:information_source: Use [`JsonRpcProvider`](https://docs.ethers.org/v6/api/providers/jsonrpc/#JsonRpcApiProviderOptions) from `ethers v6` if you want to make batched RPC calls.

```ts
const multicallProvider = looksrare.provider;
import { JsonRpcProvider, Network } from "ethers";

// Create a HTTP/HTTPS batch call provider
const provider = new JsonRpcProvider(RPC_URL, CHAIN_ID, { staticNetwork: Network.from(CHAIN_ID) });

// Create LooksRare instance using this provider
const looksrare = new LooksRare(ChainId.HARDHAT, provider, signer, addresses);
```

See [0xsequence doc](https://github.com/0xsequence/sequence.js/tree/master/packages/multicall) to understand how to use it.
Prior to [`@looksrare/[email protected]`](https://www.npmjs.com/package/@looksrare/sdk-v2/v/0.9.2?activeTab=readme), LooksRareSDK was making batched calls using `0xsequence/multicall`. But this is not natively supported since `@looksrare/[email protected]`.

## Documentation

Expand Down
35 changes: 17 additions & 18 deletions doc/classes/LooksRare.LooksRare.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LooksRare protocol main class
| :------ | :------ | :------ |
| `chainId` | [`ChainId`](../enums/types.ChainId.md) | Current app chain id |
| `provider` | `Provider` | Ethers provider |
| `signer?` | [`Signer`](../modules/types.md#signer) | Ethers signer |
| `signer?` | `Signer` | Ethers signer |
| `override?` | [`Addresses`](../interfaces/types.Addresses.md) | Overrides contract addresses for hardhat setup |

## Properties
Expand All @@ -44,30 +44,29 @@ ___

• `Readonly` **provider**: `Provider`

Ethers multicall provider
Ethers provider. If you want a batch functionality, use JsonRpcProvider.

**`See`**

- [Ethers providers doc](https://docs.ethers.io/v5/api/providers/)
- [0xsequence multicall doc](https://github.com/0xsequence/sequence.js/tree/master/packages/multicall)
[Ethers provider doc](https://docs.ethers.org/v6/api/providers/#Provider)

___

### signer

• `Optional` `Readonly` **signer**: [`Signer`](../modules/types.md#signer)
• `Optional` `Readonly` **signer**: `Signer`

Ethers signer

**`See`**

[Ethers signer doc](https://docs.ethers.io/v5/api/signer/)
[Ethers signer doc](https://docs.ethers.org/v6/api/providers/#Signer)

## Methods

### approveAllCollectionItems

▸ **approveAllCollectionItems**(`collectionAddress`, `approved?`, `overrides?`): `Promise`<`ContractTransaction`\>
▸ **approveAllCollectionItems**(`collectionAddress`, `approved?`, `overrides?`): `Promise`<`ContractTransactionResponse`\>

Approve all the items of a collection, to eventually be traded on LooksRare
The spender is the TransferManager.
Expand All @@ -82,15 +81,15 @@ The spender is the TransferManager.

#### Returns

`Promise`<`ContractTransaction`\>
`Promise`<`ContractTransactionResponse`\>

ContractTransaction

___

### approveErc20

▸ **approveErc20**(`tokenAddress`, `amount?`, `overrides?`): `Promise`<`ContractTransaction`\>
▸ **approveErc20**(`tokenAddress`, `amount?`, `overrides?`): `Promise`<`ContractTransactionResponse`\>

Approve an ERC20 to be used as a currency on LooksRare.
The spender is the LooksRareProtocol contract.
Expand All @@ -100,12 +99,12 @@ The spender is the LooksRareProtocol contract.
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `tokenAddress` | `string` | `undefined` | Address of the ERC20 to approve |
| `amount` | `BigNumber` | `constants.MaxUint256` | Amount to be approved (default to MaxUint256) |
| `amount` | `bigint` | `MaxUint256` | Amount to be approved (default to MaxUint256) |
| `overrides?` | `Overrides` | `undefined` | - |

#### Returns

`Promise`<`ContractTransaction`\>
`Promise`<`ContractTransactionResponse`\>

ContractTransaction

Expand Down Expand Up @@ -274,7 +273,7 @@ Create a taker ask ready to be executed against a maker bid
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `maker` | [`Maker`](../interfaces/types.Maker.md) | `undefined` | Maker order that will be used as counterparty for the taker |
| `recipient` | `string` | `constants.AddressZero` | Recipient address of the taker (if none, it will use the sender) |
| `recipient` | `string` | `ZeroAddress` | Recipient address of the taker (if none, it will use the sender) |
| `additionalParameters` | `any`[] | `[]` | Additional parameters used to support complex orders |

#### Returns
Expand Down Expand Up @@ -352,7 +351,7 @@ Execute several orders
| :------ | :------ | :------ | :------ |
| `orders` | { `maker`: [`Maker`](../interfaces/types.Maker.md) ; `merkleTree?`: [`MerkleTree`](../interfaces/types.MerkleTree.md) ; `signature`: `string` ; `taker`: [`Taker`](../interfaces/types.Taker.md) }[] | `undefined` | List of orders data |
| `isAtomic` | `boolean` | `undefined` | Should the transaction revert or not if a trade fails |
| `affiliate` | `string` | `constants.AddressZero` | Affiliate address |
| `affiliate` | `string` | `ZeroAddress` | Affiliate address |
| `overrides?` | `Overrides` | `undefined` | Call overrides |

#### Returns
Expand All @@ -363,9 +362,9 @@ ContractMethods

| Name | Type |
| :------ | :------ |
| `call` | (`additionalOverrides?`: `PayableOverrides`) => `Promise`<`ContractTransaction`\> |
| `call` | (`additionalOverrides?`: `PayableOverrides`) => `Promise`<`ContractTransactionResponse`\> |
| `callStatic` | (`additionalOverrides?`: `PayableOverrides`) => `Promise`<`void`\> |
| `estimateGas` | (`additionalOverrides?`: `PayableOverrides`) => `Promise`<`BigNumber`\> |
| `estimateGas` | (`additionalOverrides?`: `PayableOverrides`) => `Promise`<`bigint`\> |

___

Expand All @@ -383,7 +382,7 @@ Execute a trade
| `taker` | [`Taker`](../interfaces/types.Taker.md) | `undefined` | Taker order |
| `signature` | `string` | `undefined` | Signature of the maker order |
| `merkleTree` | [`MerkleTree`](../interfaces/types.MerkleTree.md) | `defaultMerkleTree` | If the maker has been signed with a merkle tree |
| `affiliate` | `string` | `constants.AddressZero` | Affiliate address if applicable |
| `affiliate` | `string` | `ZeroAddress` | Affiliate address if applicable |
| `overrides?` | `Overrides` | `undefined` | - |

#### Returns
Expand All @@ -396,13 +395,13 @@ ___

### getSigner

▸ `Private` **getSigner**(): [`Signer`](../modules/types.md#signer)
▸ `Private` **getSigner**(): `Signer`

Return the signer it it's set, throw an exception otherwise

#### Returns

[`Signer`](../modules/types.md#signer)
`Signer`

Signer

Expand Down
6 changes: 6 additions & 0 deletions doc/interfaces/types.ChainInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ ___
### rpcUrl

• **rpcUrl**: `string`

___

### wsUrl

• **wsUrl**: `string`
12 changes: 6 additions & 6 deletions doc/interfaces/types.ContractMethods.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Return type for any on chain call

### call

• **call**: (`additionalOverrides?`: `Overrides`) => `Promise`<`ContractTransaction`\>
• **call**: (`additionalOverrides?`: `Overrides`) => `Promise`<`ContractTransactionResponse`\>

#### Type declaration

▸ (`additionalOverrides?`): `Promise`<`ContractTransaction`\>
▸ (`additionalOverrides?`): `Promise`<`ContractTransactionResponse`\>

##### Parameters

Expand All @@ -22,7 +22,7 @@ Return type for any on chain call

##### Returns

`Promise`<`ContractTransaction`\>
`Promise`<`ContractTransactionResponse`\>

___

Expand All @@ -48,11 +48,11 @@ ___

### estimateGas

• **estimateGas**: (`additionalOverrides?`: `Overrides`) => `Promise`<`BigNumber`\>
• **estimateGas**: (`additionalOverrides?`: `Overrides`) => `Promise`<`bigint`\>

#### Type declaration

▸ (`additionalOverrides?`): `Promise`<`BigNumber`\>
▸ (`additionalOverrides?`): `Promise`<`bigint`\>

##### Parameters

Expand All @@ -62,4 +62,4 @@ ___

##### Returns

`Promise`<`BigNumber`\>
`Promise`<`bigint`\>
17 changes: 17 additions & 0 deletions doc/interfaces/types.Referrer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Interface: Referrer

[types](../modules/types.md).Referrer

Referrer object to be used in maker order API

## Properties

### address

• **address**: `string`

___

### rate

• **rate**: `BigNumberish`
RareBodhi marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 1 addition & 12 deletions doc/modules/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [Maker](../interfaces/types.Maker.md)
- [MerkleTree](../interfaces/types.MerkleTree.md)
- [MerkleTreeProof](../interfaces/types.MerkleTreeProof.md)
- [Referrer](../interfaces/types.Referrer.md)
- [SignMerkleTreeOrdersOutput](../interfaces/types.SignMerkleTreeOrdersOutput.md)
- [StrategyInfo](../interfaces/types.StrategyInfo.md)
- [Taker](../interfaces/types.Taker.md)
Expand All @@ -47,18 +48,6 @@ EIP712 type data

___

### Signer

Ƭ **Signer**: `ethers.Signer` & `TypedDataSigner`

Temporary type until full of TypedDataSigner in ethers V6

**`See`**

[Ethers TypedDataSigner](https://github.com/ethers-io/ethers.js/blob/master/packages/abstract-signer/src.ts/index.ts#L53)

___

### SolidityType

Ƭ **SolidityType**: ``"bool"`` \| ``"address"`` \| ``"uint8"`` \| ``"uint16"`` \| ``"uint112"`` \| ``"uint256"`` \| ``"uint256[]"`` \| ``"bytes"`` \| ``"bytes32"`` \| ``"bytes32[]"`` \| ``"string"``
Expand Down
4 changes: 2 additions & 2 deletions guides/collectionOrder.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The main steps are:
Here is an example:

```ts
import { ethers } from "ethers";
import { parseEther } from "ethers";
import { LooksRare, ChainId, CollectionType, StrategyType } from "@looksrare/sdk-v2";

const lr = new LooksRare(ChainId.MAINNET, provider, signer);
Expand All @@ -29,7 +29,7 @@ const { maker, isCurrencyApproved, isBalanceSufficient } = await lr.createMakerC
subsetNonce: 0, // keep 0 if you don't know what it is used for
orderNonce: 0, // You need to retrieve this value from the API
endTime: Math.floor(Date.now() / 1000) + 86400, // If you use a timestamp in ms, the function will revert
price: ethers.utils.parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
price: parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
amounts: [1], // Use it for listing multiple ERC-1155 (Optional, Default to [1])
startTime: Math.floor(Date.now() / 1000), // Use it to create an order that will be valid in the future (Optional, Default to now)
});
Expand Down
4 changes: 2 additions & 2 deletions guides/createMakerAsk.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The main steps are:
Here is an example:

```ts
import { ethers } from "ethers";
import { parseEther } from "ethers";
import { LooksRare, ChainId, CollectionType, StrategyType } from "@looksrare/sdk-v2";

const lr = new LooksRare(ChainId.MAINNET, provider, signer);
Expand All @@ -28,7 +28,7 @@ const { maker, isCollectionApproved, isTransferManagerApproved } = await lr.crea
subsetNonce: 0, // keep 0 if you don't know what it is used for
orderNonce: 0, // You need to retrieve this value from the API
endTime: Math.floor(Date.now() / 1000) + 86400, // If you use a timestamp in ms, the function will revert
price: ethers.utils.parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
price: parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
itemIds: [0], // Token id of the NFT(s) you want to sell, add several ids to create a bundle
amounts: [1], // Use it for listing multiple ERC-1155 (Optional, Default to [1])
startTime: Math.floor(Date.now() / 1000), // Use it to create an order that will be valid in the future (Optional, Default to now)
Expand Down
4 changes: 2 additions & 2 deletions guides/createMakerBid.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The code snippet below is an example of how to create a maker bid using the `@lo

The main steps are:

1. Initialize a LooksRare class instance by providing the chain id, [RPC provider](https://docs.ethers.io/v5/api/providers/) and a [signer](https://docs.ethers.io/v5/api/signer/).
1. Initialize a LooksRare class instance by providing the chain id, [JSON-RPC provider](https://docs.ethers.org/v6/api/providers/jsonrpc/) and a [signer](https://docs.ethers.org/v6/api/providers/#Signer).
2. Use the `createMakerBid` method to create a maker bid with the parameters of your order.
3. Check and grant necessary approvals for transferring assets.
4. Sign the maker bid order with `signMakerOrder` method.
Expand All @@ -28,7 +28,7 @@ const { maker, isCurrencyApproved, isBalanceSufficient } = await lr.createMakerB
subsetNonce: 0, // keep 0 if you don't know what it is used for
orderNonce: 0, // You need to retrieve this value from the API
endTime: Math.floor(Date.now() / 1000) + 86400, // If you use a timestamp in ms, the function will revert
price: ethers.utils.parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
price: parseEther("1"), // Be careful to use a price in wei, this example is for 1 ETH
itemIds: [0], // Token id of the NFT you want to buy
amounts: [1], // Use it for listing several ERC-1155 (Optional, Default to [1])
startTime: Math.floor(Date.now() / 1000), // Use it to create an order that will be valid in the future (Optional, Default to now)
Expand Down
5 changes: 2 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "@nomiclabs/hardhat-waffle";
import "@nomiclabs/hardhat-ethers";
0xShisui marked this conversation as resolved.
Show resolved Hide resolved
import "@nomicfoundation/hardhat-ethers";
import "@typechain/hardhat";
import "hardhat-abi-exporter";

Expand Down Expand Up @@ -51,7 +50,7 @@ const config = {
},
typechain: {
outDir: "src/typechain",
target: "ethers-v5",
target: "ethers-v6",
},
paths: {
tests: "src/__tests__",
Expand Down
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,19 @@
"*.{js,jsx,ts,tsx,json,yaml,yml}": "yarn format:write"
},
"peerDependencies": {
"ethers": "^5.6.8"
"ethers": "^6.6.2"
},
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@looksrare/contracts-exchange-v1": "^1.2.0",
"@looksrare/contracts-exchange-v2": "^0.1.2",
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-typescript": "^11.0.0",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@typechain/ethers-v6": "^0.4.0",
"@typechain/hardhat": "^8.0.0",
0xShisui marked this conversation as resolved.
Show resolved Hide resolved
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.1",
Expand All @@ -68,9 +67,8 @@
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.6.8",
"hardhat": "^2.13.0",
"ethers": "^6.6.2",
"hardhat": "^2.16.1",
"hardhat-abi-exporter": "^2.9.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.0",
Expand All @@ -85,13 +83,12 @@
"solmate": "^6.6.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typechain": "^8.0.0",
"typechain": "^8.2.0",
"typedoc": "^0.24.7",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^4.7.3"
},
"dependencies": {
"@0xsequence/multicall": "^0.43.20",
"merkletreejs": "^0.3.9"
}
}
Loading
Loading