@hypercerts-org/marketplace-sdk 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  This project is dual licensed under MIT and Apache-2.0.
2
2
 
3
3
  MIT: https://www.opensource.org/licenses/mit
4
+
4
5
  Apache-2.0: https://www.apache.org/licenses/license-2.0
package/README.md CHANGED
@@ -1,101 +1,133 @@
1
- # @looksrare/sdk-v2
1
+ # @hypercerts-org/marketplace-sdk
2
2
 
3
- ![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)
3
+ ![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)
4
4
 
5
- A collection of typescript tools to interact with LooksRare protocol V2 smart contracts 👀💎
5
+ A collection of TypeScript tools to interact with HypercertsExchange smart contracts, enabling users to sell and buy Hypercerts on the marketplace.
6
6
 
7
- ## Install
7
+ ## SDK usage
8
8
 
9
- This package has a peer dependency on [etherjs V5](https://docs.ethers.io/v5/).
9
+ <!-- TODO: Check if links still work on deployment -->
10
10
 
11
- ```bash
12
- yarn add @looksrare/sdk-v2 ethers
13
- ```
11
+ Read the [guides](./guides) if you need help with the implementation.
14
12
 
15
- ```bash
16
- npm install @looksrare/sdk-v2 ethers --save
17
- ```
13
+ You can also read the detailed [API documentation](./doc).
18
14
 
19
- ## Getting Started
15
+ ## SDK development
20
16
 
21
- The SDK expose a main class used to perform all the onchain operations:
17
+ ### Environment variables
22
18
 
23
- ```ts
24
- import { ChainId } from "@looksrare/sdk-v2";
25
- const looksrare = new LooksRare(ChainId.MAINNET, provider, signer);
26
- ```
19
+ No environment variables are required to run, build or run tests on the SDK.
27
20
 
28
- 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):
21
+ ### Local development
29
22
 
30
- ```ts
31
- import { ChainId } from "@looksrare/sdk-v2";
32
- const looksrare = new LooksRare(ChainId.MAINNET, provider);
33
- ```
23
+ The `HypercertExchangeClient()` allows you to override the API endpoint. This can be useful for developing against a local instance of the API.
34
24
 
35
- If you work on a hardhat setup, you can override the addresses as follow:
25
+ To use a locally built version of the SDK in another project, you can use `pnpm link`:
36
26
 
37
- ```ts
38
- import { Addresses } from "@looksrare/sdk-v2";
39
- const addresses: Addresses = {...};
40
- const looksrare = new LooksRare(ChainId.HARDHAT, provider, signer, addresses);
27
+ ```bash
28
+ cd marketplace-sdk
29
+ pnpm install && pnpm run build
30
+ cd ../your-project
31
+ pnpm link <path to marketplace sdk on you local filesystem>
41
32
  ```
42
33
 
43
- :information_source: Use [`JsonRpcProvider`](https://docs.ethers.org/v6/api/providers/jsonrpc/#JsonRpcApiProviderOptions) from `ethers v6` if you want to make batched RPC calls.
44
-
45
- ```ts
46
- import { JsonRpcProvider, Network } from "ethers";
47
-
48
- // Create a HTTP/HTTPS batch call provider
49
- const provider = new JsonRpcProvider(RPC_URL, CHAIN_ID, { staticNetwork: Network.from(CHAIN_ID) });
50
-
51
- // Create LooksRare instance using this provider
52
- const looksrare = new LooksRare(ChainId.HARDHAT, provider, signer, addresses);
34
+ ### Scripts
35
+
36
+ - `dev` - Run the SDK in development mode
37
+ - `build` - Build the SDK
38
+ - `test` - Run the tests
39
+ - `docs` - Generate the documentation into the `doc` folder
40
+ - `supabase:types:hypercerts` - Generate types for the `data-staging` database
41
+
42
+ ## Architecture
43
+
44
+ ### Lifecycle of an order
45
+
46
+ 1. User A creates maker order and signs it
47
+ 1. User A registers maker order with API
48
+ 1. Signature on maker order gets verified by API
49
+ 1. If verified correctly, order gets stored in data postgres DB
50
+ 1. Order will live in DB until deleted
51
+ 1. Order will be visible to other users as long as it's valid.
52
+ 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).
53
+ 1. User B fetches order from API
54
+ 1. User B creates taker order for maker order
55
+ 1. User B signs taker order against maker order using the `HypercertExchangeClient`, found in the marketplace SDK
56
+ 1. User B calls the `executeOrder` method on the `HypercertExchangeClient` with the taker order, which calls the `HypercertExchange` contract in turn.
57
+ 1. The `HypercertExchange` contract verifies the signature and executes the order
58
+ 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.
59
+ 1. Once a maker order is invalidated it's only visible to User A.
60
+ 1. Maker order can be deleted or permanently rendered invalid by declaring the nonce invalid by User A at any time.
61
+
62
+ > [!WARNING]
63
+ >
64
+ > The indexer is not listing to the OrderExecuted event yet, so the order will not be updated in the DB, unless reverified manually.
65
+
66
+ ```mermaid
67
+ graph TD
68
+ subgraph User A
69
+ A1[Creates maker order and signs it]
70
+ A2[Registers maker order with API]
71
+ end
72
+
73
+ subgraph API
74
+ B1[Receives maker order]
75
+ B2[Verifies signature on maker order]
76
+ B3[Stores order in Postgres DB]
77
+ end
78
+
79
+ subgraph Postgres DB
80
+ C1[Stores order]
81
+ C2[Order visible to other users as long as it's valid]
82
+ C3[Order validity can be updated]
83
+ C4[Order can become invalid due to various reasons]
84
+ C5[Marks order as invalid and stores error codes]
85
+ end
86
+
87
+ subgraph User B
88
+ D1[Fetches order from API]
89
+ D2[Creates taker order for maker order]
90
+ D3[Signs taker order against maker order using HypercertExchangeClient]
91
+ D4[Calls executeOrder method on HypercertExchangeClient]
92
+ end
93
+
94
+ subgraph HypercertExchange Contract
95
+ E1[Verifies signature]
96
+ E2[Executes order]
97
+ E3[Emits OrderExecuted event]
98
+ end
99
+
100
+ subgraph Indexer
101
+ F1[Picks up OrderExecuted event]
102
+ F2[Revalidates order]
103
+ F3[Updates error codes and validity in DB]
104
+ end
105
+
106
+ subgraph User A
107
+ G1[Invalid order is only visible to User A]
108
+ G2[Can delete or render order permanently invalid]
109
+ end
110
+
111
+ A1 --> A2
112
+ A2 --> B1
113
+ B1 --> B2
114
+ B2 --> B3
115
+ B3 --> C1
116
+ C1 --> C2
117
+ C2 --> C3
118
+ C3 --> D1
119
+ C3 --> C4
120
+ C4 --> C5
121
+ C5 --> C6
122
+ D1 --> D2
123
+ D2 --> D3
124
+ D3 --> D4
125
+ D4 --> E1
126
+ E1 --> E2
127
+ E2 --> E3
128
+ E3 --> F1
129
+ F1 --> F2
130
+ F2 --> F3
131
+ C6 --> G1
132
+ G1 --> G2
53
133
  ```
54
-
55
- Prior to [`@looksrare/sdk-v2@0.9.2`](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/sdk-v2@1.0.0`.
56
-
57
- ## Documentation
58
-
59
- Read the [guides](./guides) if you need help with the implementation.
60
-
61
- You can also read the detailed [api documentation](./doc).
62
-
63
- ## FAQ
64
-
65
- ### ❓ How to use ABIs
66
-
67
- 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.
68
-
69
- ```js
70
- import LooksRareProtocolABI from "@looksrare/sdk-v2/dist/abis/LooksRareProtocol.json";
71
- ```
72
-
73
- ### ❓ How to retrieve order nonce ?
74
-
75
- Call the public api endpoint [/orders/nonce](https://looksrare.dev/reference/getordernonce), and use this nonce directly.
76
-
77
- ### ❓ What to do when the order is created and signed ?
78
-
79
- 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..).
80
-
81
- ### ❓ When should I use merkle tree orders ?
82
-
83
- 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.
84
-
85
- ### ❓ Why do I need to call grantTransferManagerApproval ?
86
-
87
- 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.
88
-
89
- ### ❓ What are subset nonces and how to use them ?
90
-
91
- tl;dr subset nonces allow you to cancel all the orders sharing the same subset nonce.
92
- 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`.
93
- :information_source: Unlike order nonces, executing an order with a specific subset nonce doesn't invalidate other orders sharing the same subset nonce.
94
-
95
- ## Resources
96
-
97
- 🔗 [Developer documentation](https://docs.looksrare.org/developers/welcome)
98
-
99
- 🔗 [Public API documentation](https://looksrare.dev/reference/important-information)
100
-
101
- 🔗 [Developer discord](https://discord.gg/jJA4qM5dXz)
@@ -1,5 +1,5 @@
1
1
  import { BigNumberish, ContractTransactionResponse, Overrides, Provider, Signer, TypedDataDomain } from "ethers";
2
- import { Addresses, BatchTransferItem, ChainId, ContractMethods, CreateMakerAskOutput, CreateMakerBidOutput, CreateMakerCollectionOfferInput, CreateMakerCollectionOfferWithProofInput, CreateMakerInput, Currencies, Maker, MerkleTree, Order, OrderValidatorCode, SignMerkleTreeOrdersOutput, StrategyInfo, StrategyType, Taker } from "./types";
2
+ import { Addresses, ChainId, ContractMethods, CreateDirectFractionsSaleMakerAskInput, CreateFractionalSaleMakerAskInput, CreateMakerAskOutput, CreateMakerBidOutput, CreateMakerInput, Currencies, Maker, MerkleTree, Order, OrderValidatorCode, SignMerkleTreeOrdersOutput, StrategyInfo, StrategyType, Taker } from "./types";
3
3
  import { ApiClient } from "./utils/api";
4
4
  /**
5
5
  * HypercertExchange
@@ -26,10 +26,10 @@ export declare class HypercertExchangeClient {
26
26
  readonly provider: Provider;
27
27
  /**
28
28
  * HypercertExchange protocol main class
29
- * @param chainId Current app chain id
29
+ * @param chainId Chain id for contract interactions
30
30
  * @param provider Ethers provider
31
31
  * @param signer Ethers signer
32
- * @param overrides Override contract addresses or api endpoint used
32
+ * @param overrides Override contract addresses or API endpoint used
33
33
  */
34
34
  constructor(chainId: ChainId, provider: Provider, signer?: Signer, overrides?: {
35
35
  addresses: Addresses;
@@ -57,27 +57,13 @@ export declare class HypercertExchangeClient {
57
57
  * @param CreateMakerInput
58
58
  * @returns the maker object, isTransferManagerApproved, and isTransferManagerApproved
59
59
  */
60
- createMakerAsk({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, amounts, currency, startTime, additionalParameters, }: CreateMakerInput): Promise<CreateMakerAskOutput>;
60
+ createMakerAsk({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, currency, startTime, additionalParameters, }: CreateMakerInput): Promise<CreateMakerAskOutput>;
61
61
  /**
62
62
  * Create a maker bid object ready to be signed
63
63
  * @param CreateMakerInput
64
64
  * @returns the maker object, isCurrencyApproved, and isBalanceSufficient
65
65
  */
66
- createMakerBid({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, amounts, currency, startTime, additionalParameters, }: CreateMakerInput): Promise<CreateMakerBidOutput>;
67
- /**
68
- * Create a maker bid for collection offer.
69
- * @see this.createMakerBid
70
- * @param orderInputs Order data
71
- * @returns CreateMakerBidOutput
72
- */
73
- createMakerCollectionOffer(orderInputs: CreateMakerCollectionOfferInput): Promise<CreateMakerBidOutput>;
74
- /**
75
- * Create a maker bid for collection, with a list of item id that can be used for the taker order
76
- * @see this.createMakerBid
77
- * @param orderInputs Order data
78
- * @returns CreateMakerBidOutput
79
- */
80
- createMakerCollectionOfferWithProof(orderInputs: CreateMakerCollectionOfferWithProofInput): Promise<CreateMakerBidOutput>;
66
+ createMakerBid({ collection, strategyId, collectionType, subsetNonce, orderNonce, endTime, price, itemIds, currency, startTime, additionalParameters, }: CreateMakerInput): Promise<CreateMakerBidOutput>;
81
67
  /**
82
68
  * Create a taker ask ready to be executed against a maker bid
83
69
  * @param maker Maker order that will be used as counterparty for the taker
@@ -86,27 +72,6 @@ export declare class HypercertExchangeClient {
86
72
  * @returns Taker object
87
73
  */
88
74
  createTaker(maker: Maker, recipient?: string, additionalParameters?: any[]): Taker;
89
- /**
90
- * Create a taker ask order for collection order.
91
- * @see this.createTaker
92
- * @see this.createMakerCollectionOffer
93
- * @param maker Maker bid that will be used as counterparty for the taker
94
- * @param itemId Token id to use as a counterparty for the collection order
95
- * @param recipient Recipient address of the taker (if none, it will use the sender)
96
- * @returns Taker object
97
- */
98
- createTakerCollectionOffer(maker: Maker, itemId: BigNumberish, recipient?: string): Taker;
99
- /**
100
- * Create a taker ask to fulfill a collection order (maker bid) created with a whitelist of item ids
101
- * @see this.createTaker
102
- * @see this.createMakerCollectionOfferWithMerkleTree
103
- * @param maker Maker bid that will be used as counterparty for the taker
104
- * @param itemId Token id to use as a counterparty for the collection order
105
- * @param itemIds List of token ids used during the maker creation
106
- * @param recipient Recipient address of the taker (if none, it will use the sender)
107
- * @returns Taker object
108
- */
109
- createTakerCollectionOfferWithProof(maker: Maker, itemId: BigNumberish, itemIds: BigNumberish[], recipient?: string): Taker;
110
75
  /**
111
76
  * Sign a maker order using the signer provided in the constructor
112
77
  * @param maker Order to be signed by the user
@@ -125,7 +90,7 @@ export declare class HypercertExchangeClient {
125
90
  * @param maker Maker order
126
91
  * @param taker Taker order
127
92
  * @param signature Signature of the maker order
128
- * @param merkleTree If the maker has been signed with a merkle tree
93
+ * @param merkleTree Optional merkle tree
129
94
  * @returns ContractMethods
130
95
  */
131
96
  executeOrder(maker: Maker, taker: Taker, signature: string, merkleTree?: MerkleTree, overrides?: Overrides): ContractMethods;
@@ -154,19 +119,13 @@ export declare class HypercertExchangeClient {
154
119
  */
155
120
  cancelAllOrders(bid: boolean, ask: boolean, overrides?: Overrides): ContractMethods;
156
121
  /**
157
- * Cancel a list of specific orders
122
+ * Cancel a list of orders by nonce
158
123
  * @param nonces List of nonces to be cancelled
159
124
  * @returns ContractMethods
160
125
  */
161
126
  cancelOrders(nonces: BigNumberish[], overrides?: Overrides): ContractMethods;
162
127
  /**
163
- * Cancel a list of specific subset orders
164
- * @param nonces List of nonces to be cancelled
165
- * @returns ContractMethods
166
- */
167
- cancelSubsetOrders(nonces: BigNumberish[], overrides?: Overrides): ContractMethods;
168
- /**
169
- * Approve all the items of a collection, to eventually be traded on HypercertExchange
128
+ * Approve all the items of a collection, to eventually be traded on the Hypercert Exchange
170
129
  * The spender is the TransferManager.
171
130
  * @param collectionAddress Address of the collection to be approved.
172
131
  * @param approved true to approve, false to revoke the approval (default to true)
@@ -174,7 +133,7 @@ export declare class HypercertExchangeClient {
174
133
  */
175
134
  approveAllCollectionItems(collectionAddress: string, approved?: boolean, overrides?: Overrides): Promise<ContractTransactionResponse>;
176
135
  /**
177
- * Approve an ERC20 to be used as a currency on HypercertExchange.
136
+ * Approve an ERC20 to be used as a currency on the Hypercert Exchange.
178
137
  * The spender is the HypercertExchangeProtocol contract.
179
138
  * @param tokenAddress Address of the ERC20 to approve
180
139
  * @param amount Amount to be approved (default to MaxUint256)
@@ -201,13 +160,6 @@ export declare class HypercertExchangeClient {
201
160
  * @returns ContractMethods
202
161
  */
203
162
  revokeTransferManagerApproval(operators?: string[], overrides?: Overrides): ContractMethods;
204
- /**
205
- * Transfer a list of items across different collections
206
- * @param to Recipient address
207
- * @param collectionItems Each object in the array represent a list of items for a specific collection
208
- * @returns ContractMethods
209
- */
210
- transferItemsAcrossCollection(to: string, collectionItems: BatchTransferItem[], overrides?: Overrides): Promise<ContractMethods>;
211
163
  /**
212
164
  * Verify if a set of orders can be executed (i.e are valid)
213
165
  * @param makerOrders List of maker orders
@@ -235,36 +187,16 @@ export declare class HypercertExchangeClient {
235
187
  strategyInfo(strategyId: StrategyType, overrides?: Overrides): Promise<StrategyInfo>;
236
188
  /**
237
189
  * Create a maker ask for a collection or singular offer of fractions
238
- * @param itemIds Token IDs of the fractions to be sold
239
- * @param price Price of the fractions in wei
240
- * @param startTime Timestamp in seconds when the order becomes valid
241
- * @param endTime Timestamp in seconds when the order becomes invalid
242
- * @param currency Currency used to buy the fractions (default to WETH)
243
- * @param additionalParameters Additional parameters used to support complex orders
190
+ * @param CreateDirectFractionsSaleMakerAskInput
244
191
  */
245
- createDirectFractionsSaleMakerAsk({ itemIds, price, startTime, endTime, currency, additionalParameters, }: Omit<CreateMakerInput, "strategyId" | "collectionType" | "collection" | "subsetNonce" | "orderNonce" | "amounts">): Promise<CreateMakerAskOutput>;
192
+ createDirectFractionsSaleMakerAsk({ itemIds, price, startTime, endTime, currency, additionalParameters, }: CreateDirectFractionsSaleMakerAskInput): Promise<CreateMakerAskOutput>;
246
193
  /**
247
- * Create a maker ask to let the buyer decide how much of the fraction they want to buy
248
- * @param itemIds Token IDs of the fractions to be sold
249
- * @param price Price of one unit in wei
250
- * @param startTime Timestamp in seconds when the order becomes valid
251
- * @param endTime Timestamp in seconds when the order becomes invalid
252
- * @param currency Currency used to buy the fractions (default to WETH)
253
- * @param maxUnitAmount Maximum amount of units that can be bought in a single transaction
254
- * @param minUnitAmount Minimum amount of units that can be bought in a single transaction
255
- * @param minUnitsToKeep Minimum amount of units that the seller wants to keep
256
- * @param sellLeftoverFraction Whether or not the seller wants to sell the leftover units
257
- * @param root Merkle tree root (optional)
194
+ * Create a maker ask to let the buyer decide how much of a fraction they want to buy
195
+ * @param CreateFractionalSaleMakerInput
258
196
  */
259
- createFractionalSaleMakerAsk({ itemIds, price, startTime, endTime, currency, maxUnitAmount, minUnitAmount, minUnitsToKeep, sellLeftoverFraction, root, }: Omit<CreateMakerInput, "strategyId" | "collectionType" | "collection" | "subsetNonce" | "orderNonce" | "amounts" | "additionalParameters"> & {
260
- minUnitAmount: BigNumberish;
261
- maxUnitAmount: BigNumberish;
262
- minUnitsToKeep: BigNumberish;
263
- sellLeftoverFraction: boolean;
264
- root?: string;
265
- }): Promise<CreateMakerAskOutput>;
197
+ createFractionalSaleMakerAsk({ itemIds, price, startTime, endTime, currency, maxUnitAmount, minUnitAmount, minUnitsToKeep, sellLeftoverFraction, root, }: CreateFractionalSaleMakerAskInput): Promise<CreateMakerAskOutput>;
266
198
  /**
267
- * Create a taker bid for buying a fraction of an open fractional sale
199
+ * Create a taker bid for buying part of a fraction
268
200
  * @param maker Maker order
269
201
  * @param recipient Recipient address of the taker (if none, it will use the sender)
270
202
  * @param unitAmount Amount of units to buy
@@ -272,7 +204,7 @@ export declare class HypercertExchangeClient {
272
204
  */
273
205
  createFractionalSaleTakerBid(maker: Maker, recipient: string | undefined, unitAmount: BigNumberish, pricePerUnit: BigNumberish): Taker;
274
206
  /**
275
- * Register the order with hypercerts marketplace API.
207
+ * Register the order with the hypercerts marketplace API
276
208
  * @param order Maker order
277
209
  * @param signature Signature of the maker order
278
210
  */
@@ -283,7 +215,7 @@ export declare class HypercertExchangeClient {
283
215
  success: boolean;
284
216
  }>;
285
217
  /**
286
- * Delete the order
218
+ * Delete the order from the hypercerts marketplace API
287
219
  * @param orderId Order ID
288
220
  */
289
221
  deleteOrder(orderId: string): Promise<boolean>;