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

(chore): update developer documentation #25

Merged
merged 5 commits into from
Feb 12, 2025
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
4 changes: 0 additions & 4 deletions .env.example

This file was deleted.

24 changes: 0 additions & 24 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

19 changes: 0 additions & 19 deletions .github/ISSUE_TEMPLATE/change_request.md

This file was deleted.

20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/technical_question.md

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ yarn-error.log*
tsconfig.tsbuildinfo
/.idea/
/.env.test

/.vscode/
pheuberger marked this conversation as resolved.
Show resolved Hide resolved

# Generated doc files
/doc/*
32 changes: 0 additions & 32 deletions CONTRIBUTING.md

This file was deleted.

3 changes: 3 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ MIT License

Copyright (c) 2023 Hypercerts Foundation

Copyright (c) 2022 LooksRare for portions of sdk: https://github.com/LooksRare/sdk-v2 commit:
d23e2248c3b9dbc6b302dad573bfa35c37922748

Copyright (c) 2022 LooksRare for portions of marketplace: https://github.com/LooksRare/contracts-exchange-v2 commit:
7fca565

Expand Down
1 change: 1 addition & 0 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
This project is dual licensed under MIT and Apache-2.0.

MIT: https://www.opensource.org/licenses/mit

Apache-2.0: https://www.apache.org/licenses/license-2.0
202 changes: 117 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,133 @@
# @looksrare/sdk-v2
# @hypercerts-org/marketplace-sdk

![GitHub package.json version](https://img.shields.io/github/package-json/v/LooksRare/sdk-v2) ![GitHub](https://img.shields.io/github/license/LooksRare/sdk-v2) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/LooksRare/sdk-v2/build.yml) ![npm](https://img.shields.io/npm/dt/@looksrare/sdk-v2)
![GitHub package.json version](https://img.shields.io/github/package-json/v/hypercerts-org/marketplace-sdk) ![GitHub](https://img.shields.io/github/license/hypercerts-org/marketplace-sdk) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/hypercerts-org/marketplace-sdk/build.yml) ![npm](https://img.shields.io/npm/dt/@hypercerts-org/marketplace-sdk)

A collection of typescript tools to interact with LooksRare protocol V2 smart contracts 👀💎
A collection of TypeScript tools to interact with HypercertsExchange smart contracts, enabling users to sell and buy Hypercerts on the marketplace.

## Install
## SDK usage

This package has a peer dependency on [etherjs V5](https://docs.ethers.io/v5/).
<!-- TODO: Check if links still work on deployment -->

```bash
yarn add @looksrare/sdk-v2 ethers
```
Read the [guides](./guides) if you need help with the implementation.
bitbeckers marked this conversation as resolved.
Show resolved Hide resolved

```bash
npm install @looksrare/sdk-v2 ethers --save
```
You can also read the detailed [API documentation](./doc).

## Getting Started
## SDK development

The SDK expose a main class used to perform all the onchain operations:
### Environment variables

```ts
import { ChainId } from "@looksrare/sdk-v2";
const looksrare = new LooksRare(ChainId.MAINNET, provider, signer);
```
No environment variables are required to run, build or run tests on the SDK.

The signer is optional if you need access to read only data (:warning: Calls to function that need a signer will throw a `Signer is undefined` exception):
### Local development

```ts
import { ChainId } from "@looksrare/sdk-v2";
const looksrare = new LooksRare(ChainId.MAINNET, provider);
```
The `HypercertExchangeClient()` allows you to override the API endpoint. This can be useful for developing against a local instance of the API.

If you work on a hardhat setup, you can override the addresses as follow:
To use a locally built version of the SDK in another project, you can use `pnpm link`:

```ts
import { Addresses } from "@looksrare/sdk-v2";
const addresses: Addresses = {...};
const looksrare = new LooksRare(ChainId.HARDHAT, provider, signer, addresses);
```bash
cd marketplace-sdk
pnpm install && pnpm run build
cd ../your-project
pnpm link <path to marketplace sdk on you local filesystem>
```

: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
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);
### Scripts

- `dev` - Run the SDK in development mode
- `build` - Build the SDK
- `test` - Run the tests
- `docs` - Generate the documentation into the `doc` folder
- `supabase:types:hypercerts` - Generate types for the `data-staging` database
bitbeckers marked this conversation as resolved.
Show resolved Hide resolved

## Architecture

### Lifecycle of an order

1. User A creates maker order and signs it
pheuberger marked this conversation as resolved.
Show resolved Hide resolved
1. User A registers maker order with API
1. Signature on maker order gets verified by API
1. If verified correctly, order gets stored in data postgres DB
1. Order will live in DB until deleted
1. Order will be visible to other users as long as it's valid.
1. An order being executed might render it being invalid. A user can invalidate their own orders on request. There are more possible reasons, see the `OrderValidatorCode` enum located in [src/types.ts](./src/types.ts#L266) and the guide on [order validation](./guides/orderValidation.md).
1. User B fetches order from API
1. User B creates taker order for maker order
1. User B signs taker order against maker order using the `HypercertExchangeClient`, found in the marketplace SDK
1. User B calls the `executeOrder` method on the `HypercertExchangeClient` with the taker order, which calls the `HypercertExchange` contract in turn.
1. The `HypercertExchange` contract verifies the signature and executes the order
1. The `HypercertExchange` contract will emit an event that the order has been executed, which is picked up by the indexer which revalidates the order. If the transaction rendered the order invalid for any further sales, the error codes and validity get updated in the DB.
1. Once a maker order is invalidated it's only visible to User A.
1. Maker order can be deleted or permanently rendered invalid by declaring the nonce invalid by User A at any time.

> [!WARNING]
>
> The indexer is not listing to the OrderExecuted event yet, so the order will not be updated in the DB, unless reverified manually.
pheuberger marked this conversation as resolved.
Show resolved Hide resolved

```mermaid
graph TD
subgraph User A
A1[Creates maker order and signs it]
A2[Registers maker order with API]
end

subgraph API
B1[Receives maker order]
B2[Verifies signature on maker order]
B3[Stores order in Postgres DB]
end

subgraph Postgres DB
C1[Stores order]
C2[Order visible to other users as long as it's valid]
C3[Order validity can be updated]
C4[Order can become invalid due to various reasons]
C5[Marks order as invalid and stores error codes]
end

subgraph User B
D1[Fetches order from API]
D2[Creates taker order for maker order]
D3[Signs taker order against maker order using HypercertExchangeClient]
D4[Calls executeOrder method on HypercertExchangeClient]
end

subgraph HypercertExchange Contract
E1[Verifies signature]
E2[Executes order]
E3[Emits OrderExecuted event]
end

subgraph Indexer
F1[Picks up OrderExecuted event]
F2[Revalidates order]
F3[Updates error codes and validity in DB]
end

subgraph User A
G1[Invalid order is only visible to User A]
G2[Can delete or render order permanently invalid]
end

A1 --> A2
A2 --> B1
B1 --> B2
B2 --> B3
B3 --> C1
C1 --> C2
C2 --> C3
C3 --> D1
C3 --> C4
C4 --> C5
C5 --> C6
D1 --> D2
D2 --> D3
D3 --> D4
D4 --> E1
E1 --> E2
E2 --> E3
E3 --> F1
F1 --> F2
F2 --> F3
C6 --> G1
G1 --> G2
```

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

Read the [guides](./guides) if you need help with the implementation.

You can also read the detailed [api documentation](./doc).

## FAQ

### ❓ How to use ABIs

The SDK exposes most of the LooksRare contract [ABIs](https://github.com/LooksRare/sdk-v2/tree/master/src/abis). For convenience, some commonly used ABIs are also exported.

```js
import LooksRareProtocolABI from "@looksrare/sdk-v2/dist/abis/LooksRareProtocol.json";
```

### ❓ How to retrieve order nonce ?

Call the public api endpoint [/orders/nonce](https://looksrare.dev/reference/getordernonce), and use this nonce directly.

### ❓ What to do when the order is created and signed ?

Use the public api endpoint [/orders](https://looksrare.dev/reference/createorder) to push the order to the database. After that, the order will be visible by everyone using the API (looksrare.org, aggregators, etc..).

### ❓ When should I use merkle tree orders ?

Merkle tree orders are used to create several orders with a single signature. You shouldn't use them when using a bot. Their main purpose is to facilitate orders creation using a user interface.

### ❓ Why do I need to call grantTransferManagerApproval ?

When you approve a collection to be traded on LooksRare, you approve the TransferManager instead of the exchange. Calling `grantTransferManagerApproval` gives the exchange contract the right to call the transfer function on the TransferManager. You need to call this function only once, the first time you use the V2.

### ❓ What are subset nonces and how to use them ?

tl;dr subset nonces allow you to cancel all the orders sharing the same subset nonce.
Subset nonces allow you to group some orders together according to arbitrary rules (for example all your orders for a specific collection, all your orders above a certain threshold, etc). You can then cancel them all with a single call to `cancelSubsetOrders`.
:information_source: Unlike order nonces, executing an order with a specific subset nonce doesn't invalidate other orders sharing the same subset nonce.

## Resources

🔗 [Developer documentation](https://docs.looksrare.org/developers/welcome)

🔗 [Public API documentation](https://looksrare.dev/reference/important-information)

🔗 [Developer discord](https://discord.gg/jJA4qM5dXz)
6 changes: 0 additions & 6 deletions doc/README.md

This file was deleted.

Loading