@hypercerts-org/marketplace-sdk 0.0.23 → 0.1.0
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.
- package/dist/HypercertExchangeClient.d.ts +13 -13
- package/dist/index.cjs.js +103 -78
- package/dist/index.d.ts +6 -6
- package/dist/index.esm.js +103 -78
- package/dist/types.d.ts +3 -3
- package/dist/utils/api.d.ts +106 -60
- package/dist/utils/calls/exchange.d.ts +7 -6
- package/package.json +2 -2
@@ -1,16 +1,16 @@
|
|
1
1
|
import { BigNumberish, ContractTransactionResponse, Overrides, Provider, Signer, TypedDataDomain } from "ethers";
|
2
|
-
import * as api from "./utils/api";
|
3
2
|
import { Addresses, BatchTransferItem, ChainId, ContractMethods, CreateMakerAskOutput, CreateMakerBidOutput, CreateMakerCollectionOfferInput, CreateMakerCollectionOfferWithProofInput, CreateMakerInput, Maker, MerkleTree, OrderValidatorCode, SignMerkleTreeOrdersOutput, StrategyInfo, StrategyType, Taker } from "./types";
|
3
|
+
import { ApiClient } from "./utils/api";
|
4
4
|
/**
|
5
|
-
*
|
6
|
-
* This class provides helpers to interact with the
|
5
|
+
* HypercertExchange
|
6
|
+
* This class provides helpers to interact with the HypercertExchange V2 contracts
|
7
7
|
*/
|
8
8
|
export declare class HypercertExchangeClient {
|
9
9
|
/** Current app chain ID */
|
10
10
|
readonly chainId: ChainId;
|
11
|
-
/** Mapping of
|
11
|
+
/** Mapping of Hypercert protocol addresses for the current chain */
|
12
12
|
readonly addresses: Addresses;
|
13
|
-
readonly api:
|
13
|
+
readonly api: ApiClient;
|
14
14
|
/**
|
15
15
|
* Ethers signer
|
16
16
|
* @see {@link https://docs.ethers.org/v6/api/providers/#Signer Ethers signer doc}
|
@@ -22,13 +22,13 @@ export declare class HypercertExchangeClient {
|
|
22
22
|
*/
|
23
23
|
readonly provider: Provider;
|
24
24
|
/**
|
25
|
-
*
|
25
|
+
* HypercertExchange protocol main class
|
26
26
|
* @param chainId Current app chain id
|
27
27
|
* @param provider Ethers provider
|
28
28
|
* @param signer Ethers signer
|
29
29
|
* @param override Overrides contract addresses for hardhat setup
|
30
30
|
*/
|
31
|
-
constructor(chainId: ChainId, provider: Provider, signer?: Signer, override?: Addresses);
|
31
|
+
constructor(chainId: ChainId, provider: Provider, signer?: Signer, override?: Addresses, apiEndpoint?: string);
|
32
32
|
/**
|
33
33
|
* Return the signer it it's set, throw an exception otherwise
|
34
34
|
* @returns Signer
|
@@ -135,9 +135,9 @@ export declare class HypercertExchangeClient {
|
|
135
135
|
signature: string;
|
136
136
|
merkleTree?: MerkleTree;
|
137
137
|
}[], isAtomic: boolean, overrides?: Overrides): {
|
138
|
-
call: (additionalOverrides?:
|
139
|
-
estimateGas: (additionalOverrides?:
|
140
|
-
callStatic: (additionalOverrides?:
|
138
|
+
call: (additionalOverrides?: import("./typechain/common").PayableOverrides | undefined) => any;
|
139
|
+
estimateGas: (additionalOverrides?: import("./typechain/common").PayableOverrides | undefined) => any;
|
140
|
+
callStatic: (additionalOverrides?: import("./typechain/common").PayableOverrides | undefined) => any;
|
141
141
|
};
|
142
142
|
/**
|
143
143
|
* Cancell all maker bid and/or ask orders for the current user
|
@@ -159,7 +159,7 @@ export declare class HypercertExchangeClient {
|
|
159
159
|
*/
|
160
160
|
cancelSubsetOrders(nonces: BigNumberish[], overrides?: Overrides): ContractMethods;
|
161
161
|
/**
|
162
|
-
* Approve all the items of a collection, to eventually be traded on
|
162
|
+
* Approve all the items of a collection, to eventually be traded on HypercertExchange
|
163
163
|
* The spender is the TransferManager.
|
164
164
|
* @param collectionAddress Address of the collection to be approved.
|
165
165
|
* @param approved true to approve, false to revoke the approval (default to true)
|
@@ -167,8 +167,8 @@ export declare class HypercertExchangeClient {
|
|
167
167
|
*/
|
168
168
|
approveAllCollectionItems(collectionAddress: string, approved?: boolean, overrides?: Overrides): Promise<ContractTransactionResponse>;
|
169
169
|
/**
|
170
|
-
* Approve an ERC20 to be used as a currency on
|
171
|
-
* The spender is the
|
170
|
+
* Approve an ERC20 to be used as a currency on HypercertExchange.
|
171
|
+
* The spender is the HypercertExchangeProtocol contract.
|
172
172
|
* @param tokenAddress Address of the ERC20 to approve
|
173
173
|
* @param amount Amount to be approved (default to MaxUint256)
|
174
174
|
* @returns ContractTransaction
|
package/dist/index.cjs.js
CHANGED
@@ -4804,95 +4804,120 @@ const contractName = "LooksRareProtocol";
|
|
4804
4804
|
*/
|
4805
4805
|
const version = 2;
|
4806
4806
|
|
4807
|
-
const HYPERCERTS_MARKETPLACE_API_URL = "
|
4807
|
+
const HYPERCERTS_MARKETPLACE_API_URL = "http://localhost:3000/api";
|
4808
4808
|
const SUPABASE_HYPERCERTS_URL = "https://clagjjfinooizoqdkvqc.supabase.co";
|
4809
4809
|
const SUPABASE_HYPERCERTS_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNsYWdqamZpbm9vaXpvcWRrdnFjIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzY5NTAxNDAsImV4cCI6MTk5MjUyNjE0MH0.LOIW3NcYEfF7w893PS3Ne1VrntACE3OPeSRFkspvyqw";
|
4810
4810
|
const supabaseHypercerts = supabaseJs.createClient(SUPABASE_HYPERCERTS_URL, SUPABASE_HYPERCERTS_ANON_KEY);
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4823
|
-
|
4824
|
-
|
4825
|
-
|
4826
|
-
|
4827
|
-
|
4828
|
-
|
4829
|
-
}
|
4830
|
-
|
4831
|
-
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
|
4862
|
-
|
4863
|
-
|
4864
|
-
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
4871
|
-
|
4872
|
-
|
4873
|
-
|
4874
|
-
|
4875
|
-
|
4876
|
-
}
|
4811
|
+
class ApiClient {
|
4812
|
+
constructor(baseUrl) {
|
4813
|
+
this.baseUrl = baseUrl;
|
4814
|
+
/**
|
4815
|
+
* Fetches order nonce from api
|
4816
|
+
* @param address Address
|
4817
|
+
* @param chainId Chain ID
|
4818
|
+
*/
|
4819
|
+
this.fetchOrderNonce = async ({ address, chainId }) => {
|
4820
|
+
return fetch(`${this.baseUrl}/marketplace/order-nonce/`, {
|
4821
|
+
method: "POST",
|
4822
|
+
headers: {
|
4823
|
+
"Content-Type": "application/json",
|
4824
|
+
},
|
4825
|
+
body: JSON.stringify({
|
4826
|
+
address,
|
4827
|
+
chainId,
|
4828
|
+
}),
|
4829
|
+
})
|
4830
|
+
.then((res) => res.json())
|
4831
|
+
.then((res) => res.data);
|
4832
|
+
};
|
4833
|
+
/**
|
4834
|
+
* Registers order in api
|
4835
|
+
* @param order Order
|
4836
|
+
* @param signer Signer
|
4837
|
+
* @param signature Signature
|
4838
|
+
* @param quoteType Quote type
|
4839
|
+
* @param chainId Chain ID
|
4840
|
+
*/
|
4841
|
+
this.registerOrder = async ({ order, signer, signature, quoteType, chainId, }) => {
|
4842
|
+
const { globalNonce, ...orderWithoutGlobalNonce } = order;
|
4843
|
+
return fetch(`${this.baseUrl}/marketplace/order/`, {
|
4844
|
+
method: "POST",
|
4845
|
+
headers: {
|
4846
|
+
"Content-Type": "application/json",
|
4847
|
+
},
|
4848
|
+
body: JSON.stringify({
|
4849
|
+
...orderWithoutGlobalNonce,
|
4850
|
+
globalNonce: globalNonce.toString(10),
|
4851
|
+
price: order.price.toString(10),
|
4852
|
+
quoteType,
|
4853
|
+
signer,
|
4854
|
+
signature,
|
4855
|
+
chainId,
|
4856
|
+
}),
|
4857
|
+
}).then((res) => res.json());
|
4858
|
+
};
|
4859
|
+
/**
|
4860
|
+
* Fetch existing open orders from the marketplace API
|
4861
|
+
* @param signer address of the user that created the order
|
4862
|
+
* @param claimTokenIds a list of claimTokenIds - will return any order that is for one or more of these claimTokenIds
|
4863
|
+
* @param chainId chain id for the order
|
4864
|
+
* @param strategy strategy for the order
|
4865
|
+
*/
|
4866
|
+
this.fetchOrders = async ({ signer, claimTokenIds, chainId, strategy }) => {
|
4867
|
+
let baseQuery = supabaseHypercerts.from("marketplace-orders").select("*");
|
4868
|
+
if (signer) {
|
4869
|
+
baseQuery.eq("signer", signer);
|
4870
|
+
}
|
4871
|
+
if (claimTokenIds) {
|
4872
|
+
baseQuery = baseQuery.overlaps("itemIds", claimTokenIds);
|
4873
|
+
}
|
4874
|
+
if (chainId) {
|
4875
|
+
baseQuery.eq("chainId", chainId);
|
4876
|
+
}
|
4877
|
+
if (strategy) {
|
4878
|
+
baseQuery.eq("strategyId", strategy);
|
4879
|
+
}
|
4880
|
+
return baseQuery.throwOnError();
|
4881
|
+
};
|
4882
|
+
/**
|
4883
|
+
* Fetches orders from api by hypercert ID
|
4884
|
+
* @param hypercertId Hypercert ID
|
4885
|
+
* @param chainId Chain ID
|
4886
|
+
*/
|
4887
|
+
this.fetchOrdersByHypercertId = async ({ hypercertId, chainId }) => {
|
4888
|
+
const hypercertsClient = new sdk.HypercertClient({
|
4889
|
+
chain: { id: chainId },
|
4890
|
+
});
|
4891
|
+
const fractions = await hypercertsClient.indexer.fractionsByClaim(hypercertId);
|
4892
|
+
const tokenIds = fractions.claimTokens.map((fraction) => fraction.tokenID);
|
4893
|
+
return supabaseHypercerts.from("marketplace-orders").select("*").containedBy("itemIds", tokenIds).throwOnError();
|
4894
|
+
};
|
4895
|
+
const url = baseUrl || HYPERCERTS_MARKETPLACE_API_URL;
|
4896
|
+
if (!url) {
|
4897
|
+
throw new Error("No API URL provided");
|
4898
|
+
}
|
4899
|
+
this._baseUrl = url;
|
4900
|
+
}
|
4901
|
+
}
|
4877
4902
|
|
4878
4903
|
/**
|
4879
|
-
*
|
4880
|
-
* This class provides helpers to interact with the
|
4904
|
+
* HypercertExchange
|
4905
|
+
* This class provides helpers to interact with the HypercertExchange V2 contracts
|
4881
4906
|
*/
|
4882
4907
|
class HypercertExchangeClient {
|
4883
4908
|
/**
|
4884
|
-
*
|
4909
|
+
* HypercertExchange protocol main class
|
4885
4910
|
* @param chainId Current app chain id
|
4886
4911
|
* @param provider Ethers provider
|
4887
4912
|
* @param signer Ethers signer
|
4888
4913
|
* @param override Overrides contract addresses for hardhat setup
|
4889
4914
|
*/
|
4890
|
-
constructor(chainId, provider, signer, override) {
|
4915
|
+
constructor(chainId, provider, signer, override, apiEndpoint) {
|
4891
4916
|
this.chainId = chainId;
|
4892
4917
|
this.addresses = override ?? addressesByNetwork[this.chainId];
|
4893
4918
|
this.signer = signer;
|
4894
4919
|
this.provider = provider;
|
4895
|
-
this.api =
|
4920
|
+
this.api = new ApiClient(apiEndpoint);
|
4896
4921
|
}
|
4897
4922
|
/**
|
4898
4923
|
* Return the signer it it's set, throw an exception otherwise
|
@@ -5185,7 +5210,7 @@ class HypercertExchangeClient {
|
|
5185
5210
|
return cancelSubsetNonces(signer, this.addresses.EXCHANGE_V2, nonces, overrides);
|
5186
5211
|
}
|
5187
5212
|
/**
|
5188
|
-
* Approve all the items of a collection, to eventually be traded on
|
5213
|
+
* Approve all the items of a collection, to eventually be traded on HypercertExchange
|
5189
5214
|
* The spender is the TransferManager.
|
5190
5215
|
* @param collectionAddress Address of the collection to be approved.
|
5191
5216
|
* @param approved true to approve, false to revoke the approval (default to true)
|
@@ -5197,8 +5222,8 @@ class HypercertExchangeClient {
|
|
5197
5222
|
return setApprovalForAll(signer, collectionAddress, spenderAddress, approved, overrides);
|
5198
5223
|
}
|
5199
5224
|
/**
|
5200
|
-
* Approve an ERC20 to be used as a currency on
|
5201
|
-
* The spender is the
|
5225
|
+
* Approve an ERC20 to be used as a currency on HypercertExchange.
|
5226
|
+
* The spender is the HypercertExchangeProtocol contract.
|
5202
5227
|
* @param tokenAddress Address of the ERC20 to approve
|
5203
5228
|
* @param amount Amount to be approved (default to MaxUint256)
|
5204
5229
|
* @returns ContractTransaction
|
@@ -5283,7 +5308,7 @@ class HypercertExchangeClient {
|
|
5283
5308
|
throw new Error("No signer address could be determined");
|
5284
5309
|
}
|
5285
5310
|
const chainId = this.chainId;
|
5286
|
-
const { nonce_counter } = await fetchOrderNonce({
|
5311
|
+
const { nonce_counter } = await this.api.fetchOrderNonce({
|
5287
5312
|
address,
|
5288
5313
|
chainId,
|
5289
5314
|
});
|
@@ -5324,7 +5349,7 @@ class HypercertExchangeClient {
|
|
5324
5349
|
throw new Error("No signer address could be determined");
|
5325
5350
|
}
|
5326
5351
|
const chainId = this.chainId;
|
5327
|
-
const { nonce_counter } = await fetchOrderNonce({
|
5352
|
+
const { nonce_counter } = await this.api.fetchOrderNonce({
|
5328
5353
|
address,
|
5329
5354
|
chainId,
|
5330
5355
|
});
|
@@ -5380,7 +5405,7 @@ class HypercertExchangeClient {
|
|
5380
5405
|
throw new Error("No signer address could be determined");
|
5381
5406
|
}
|
5382
5407
|
const chainId = this.chainId;
|
5383
|
-
return registerOrder({
|
5408
|
+
return this.api.registerOrder({
|
5384
5409
|
order,
|
5385
5410
|
signer: address,
|
5386
5411
|
signature,
|
package/dist/index.d.ts
CHANGED
@@ -23,12 +23,12 @@ declare const utils: {
|
|
23
23
|
cancelOrderNonces: (signer: import("ethers").Signer, address: string, nonces: import("ethers").BigNumberish[], overrides?: import("ethers").Overrides | undefined) => import("./types").ContractMethods;
|
24
24
|
cancelSubsetNonces: (signer: import("ethers").Signer, address: string, nonces: import("ethers").BigNumberish[], overrides?: import("ethers").Overrides | undefined) => import("./types").ContractMethods;
|
25
25
|
incrementBidAskNonces: (signer: import("ethers").Signer, address: string, bid: boolean, ask: boolean, overrides?: import("ethers").Overrides | undefined) => import("./types").ContractMethods;
|
26
|
-
executeTakerBid: (signer: import("ethers").Signer, address: string, taker: import("./types").Taker, maker: import("./types").Maker, makerSignature: string, merkleTree: import("./types").MerkleTree, overrides?:
|
27
|
-
executeTakerAsk: (signer: import("ethers").Signer, address: string, taker: import("./types").Taker, maker: import("./types").Maker, makerSignature: string, merkleTree: import("./types").MerkleTree, overrides?:
|
28
|
-
executeMultipleTakerBids: (signer: import("ethers").Signer, address: string, taker: import("./types").Taker[], maker: import("./types").Maker[], makerSignature: string[], isAtomic: boolean, merkleTree: import("./types").MerkleTree[], overrides?:
|
29
|
-
call: (additionalOverrides?:
|
30
|
-
estimateGas: (additionalOverrides?:
|
31
|
-
callStatic: (additionalOverrides?:
|
26
|
+
executeTakerBid: (signer: import("ethers").Signer, address: string, taker: import("./types").Taker, maker: import("./types").Maker, makerSignature: string, merkleTree: import("./types").MerkleTree, overrides?: import("./typechain/common").PayableOverrides | undefined) => import("./types").ContractMethods;
|
27
|
+
executeTakerAsk: (signer: import("ethers").Signer, address: string, taker: import("./types").Taker, maker: import("./types").Maker, makerSignature: string, merkleTree: import("./types").MerkleTree, overrides?: import("./typechain/common").PayableOverrides | undefined) => import("./types").ContractMethods;
|
28
|
+
executeMultipleTakerBids: (signer: import("ethers").Signer, address: string, taker: import("./types").Taker[], maker: import("./types").Maker[], makerSignature: string[], isAtomic: boolean, merkleTree: import("./types").MerkleTree[], overrides?: import("./typechain/common").PayableOverrides | undefined) => {
|
29
|
+
call: (additionalOverrides?: import("./typechain/common").PayableOverrides | undefined) => any;
|
30
|
+
estimateGas: (additionalOverrides?: import("./typechain/common").PayableOverrides | undefined) => any;
|
31
|
+
callStatic: (additionalOverrides?: import("./typechain/common").PayableOverrides | undefined) => any;
|
32
32
|
};
|
33
33
|
setApprovalForAll: (signer: import("ethers").Signer, collection: string, operator: string, approved: boolean, overrides?: import("ethers").Overrides | undefined) => Promise<import("ethers").ContractTransactionResponse>;
|
34
34
|
isApprovedForAll: (signerOrProvider: import("ethers").Signer | import("ethers").Provider, collection: string, account: string, operator: string, overrides?: import("ethers").Overrides | undefined) => Promise<boolean>;
|
package/dist/index.esm.js
CHANGED
@@ -4802,95 +4802,120 @@ const contractName = "LooksRareProtocol";
|
|
4802
4802
|
*/
|
4803
4803
|
const version = 2;
|
4804
4804
|
|
4805
|
-
const HYPERCERTS_MARKETPLACE_API_URL = "
|
4805
|
+
const HYPERCERTS_MARKETPLACE_API_URL = "http://localhost:3000/api";
|
4806
4806
|
const SUPABASE_HYPERCERTS_URL = "https://clagjjfinooizoqdkvqc.supabase.co";
|
4807
4807
|
const SUPABASE_HYPERCERTS_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNsYWdqamZpbm9vaXpvcWRrdnFjIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzY5NTAxNDAsImV4cCI6MTk5MjUyNjE0MH0.LOIW3NcYEfF7w893PS3Ne1VrntACE3OPeSRFkspvyqw";
|
4808
4808
|
const supabaseHypercerts = createClient(SUPABASE_HYPERCERTS_URL, SUPABASE_HYPERCERTS_ANON_KEY);
|
4809
|
-
|
4810
|
-
|
4811
|
-
|
4812
|
-
|
4813
|
-
|
4814
|
-
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
|
4821
|
-
|
4822
|
-
|
4823
|
-
|
4824
|
-
|
4825
|
-
|
4826
|
-
|
4827
|
-
}
|
4828
|
-
|
4829
|
-
|
4830
|
-
|
4831
|
-
|
4832
|
-
|
4833
|
-
|
4834
|
-
|
4835
|
-
|
4836
|
-
|
4837
|
-
|
4838
|
-
|
4839
|
-
|
4840
|
-
|
4841
|
-
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
|
4862
|
-
|
4863
|
-
|
4864
|
-
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4868
|
-
|
4869
|
-
|
4870
|
-
|
4871
|
-
|
4872
|
-
|
4873
|
-
|
4874
|
-
}
|
4809
|
+
class ApiClient {
|
4810
|
+
constructor(baseUrl) {
|
4811
|
+
this.baseUrl = baseUrl;
|
4812
|
+
/**
|
4813
|
+
* Fetches order nonce from api
|
4814
|
+
* @param address Address
|
4815
|
+
* @param chainId Chain ID
|
4816
|
+
*/
|
4817
|
+
this.fetchOrderNonce = async ({ address, chainId }) => {
|
4818
|
+
return fetch(`${this.baseUrl}/marketplace/order-nonce/`, {
|
4819
|
+
method: "POST",
|
4820
|
+
headers: {
|
4821
|
+
"Content-Type": "application/json",
|
4822
|
+
},
|
4823
|
+
body: JSON.stringify({
|
4824
|
+
address,
|
4825
|
+
chainId,
|
4826
|
+
}),
|
4827
|
+
})
|
4828
|
+
.then((res) => res.json())
|
4829
|
+
.then((res) => res.data);
|
4830
|
+
};
|
4831
|
+
/**
|
4832
|
+
* Registers order in api
|
4833
|
+
* @param order Order
|
4834
|
+
* @param signer Signer
|
4835
|
+
* @param signature Signature
|
4836
|
+
* @param quoteType Quote type
|
4837
|
+
* @param chainId Chain ID
|
4838
|
+
*/
|
4839
|
+
this.registerOrder = async ({ order, signer, signature, quoteType, chainId, }) => {
|
4840
|
+
const { globalNonce, ...orderWithoutGlobalNonce } = order;
|
4841
|
+
return fetch(`${this.baseUrl}/marketplace/order/`, {
|
4842
|
+
method: "POST",
|
4843
|
+
headers: {
|
4844
|
+
"Content-Type": "application/json",
|
4845
|
+
},
|
4846
|
+
body: JSON.stringify({
|
4847
|
+
...orderWithoutGlobalNonce,
|
4848
|
+
globalNonce: globalNonce.toString(10),
|
4849
|
+
price: order.price.toString(10),
|
4850
|
+
quoteType,
|
4851
|
+
signer,
|
4852
|
+
signature,
|
4853
|
+
chainId,
|
4854
|
+
}),
|
4855
|
+
}).then((res) => res.json());
|
4856
|
+
};
|
4857
|
+
/**
|
4858
|
+
* Fetch existing open orders from the marketplace API
|
4859
|
+
* @param signer address of the user that created the order
|
4860
|
+
* @param claimTokenIds a list of claimTokenIds - will return any order that is for one or more of these claimTokenIds
|
4861
|
+
* @param chainId chain id for the order
|
4862
|
+
* @param strategy strategy for the order
|
4863
|
+
*/
|
4864
|
+
this.fetchOrders = async ({ signer, claimTokenIds, chainId, strategy }) => {
|
4865
|
+
let baseQuery = supabaseHypercerts.from("marketplace-orders").select("*");
|
4866
|
+
if (signer) {
|
4867
|
+
baseQuery.eq("signer", signer);
|
4868
|
+
}
|
4869
|
+
if (claimTokenIds) {
|
4870
|
+
baseQuery = baseQuery.overlaps("itemIds", claimTokenIds);
|
4871
|
+
}
|
4872
|
+
if (chainId) {
|
4873
|
+
baseQuery.eq("chainId", chainId);
|
4874
|
+
}
|
4875
|
+
if (strategy) {
|
4876
|
+
baseQuery.eq("strategyId", strategy);
|
4877
|
+
}
|
4878
|
+
return baseQuery.throwOnError();
|
4879
|
+
};
|
4880
|
+
/**
|
4881
|
+
* Fetches orders from api by hypercert ID
|
4882
|
+
* @param hypercertId Hypercert ID
|
4883
|
+
* @param chainId Chain ID
|
4884
|
+
*/
|
4885
|
+
this.fetchOrdersByHypercertId = async ({ hypercertId, chainId }) => {
|
4886
|
+
const hypercertsClient = new HypercertClient({
|
4887
|
+
chain: { id: chainId },
|
4888
|
+
});
|
4889
|
+
const fractions = await hypercertsClient.indexer.fractionsByClaim(hypercertId);
|
4890
|
+
const tokenIds = fractions.claimTokens.map((fraction) => fraction.tokenID);
|
4891
|
+
return supabaseHypercerts.from("marketplace-orders").select("*").containedBy("itemIds", tokenIds).throwOnError();
|
4892
|
+
};
|
4893
|
+
const url = baseUrl || HYPERCERTS_MARKETPLACE_API_URL;
|
4894
|
+
if (!url) {
|
4895
|
+
throw new Error("No API URL provided");
|
4896
|
+
}
|
4897
|
+
this._baseUrl = url;
|
4898
|
+
}
|
4899
|
+
}
|
4875
4900
|
|
4876
4901
|
/**
|
4877
|
-
*
|
4878
|
-
* This class provides helpers to interact with the
|
4902
|
+
* HypercertExchange
|
4903
|
+
* This class provides helpers to interact with the HypercertExchange V2 contracts
|
4879
4904
|
*/
|
4880
4905
|
class HypercertExchangeClient {
|
4881
4906
|
/**
|
4882
|
-
*
|
4907
|
+
* HypercertExchange protocol main class
|
4883
4908
|
* @param chainId Current app chain id
|
4884
4909
|
* @param provider Ethers provider
|
4885
4910
|
* @param signer Ethers signer
|
4886
4911
|
* @param override Overrides contract addresses for hardhat setup
|
4887
4912
|
*/
|
4888
|
-
constructor(chainId, provider, signer, override) {
|
4913
|
+
constructor(chainId, provider, signer, override, apiEndpoint) {
|
4889
4914
|
this.chainId = chainId;
|
4890
4915
|
this.addresses = override ?? addressesByNetwork[this.chainId];
|
4891
4916
|
this.signer = signer;
|
4892
4917
|
this.provider = provider;
|
4893
|
-
this.api =
|
4918
|
+
this.api = new ApiClient(apiEndpoint);
|
4894
4919
|
}
|
4895
4920
|
/**
|
4896
4921
|
* Return the signer it it's set, throw an exception otherwise
|
@@ -5183,7 +5208,7 @@ class HypercertExchangeClient {
|
|
5183
5208
|
return cancelSubsetNonces(signer, this.addresses.EXCHANGE_V2, nonces, overrides);
|
5184
5209
|
}
|
5185
5210
|
/**
|
5186
|
-
* Approve all the items of a collection, to eventually be traded on
|
5211
|
+
* Approve all the items of a collection, to eventually be traded on HypercertExchange
|
5187
5212
|
* The spender is the TransferManager.
|
5188
5213
|
* @param collectionAddress Address of the collection to be approved.
|
5189
5214
|
* @param approved true to approve, false to revoke the approval (default to true)
|
@@ -5195,8 +5220,8 @@ class HypercertExchangeClient {
|
|
5195
5220
|
return setApprovalForAll(signer, collectionAddress, spenderAddress, approved, overrides);
|
5196
5221
|
}
|
5197
5222
|
/**
|
5198
|
-
* Approve an ERC20 to be used as a currency on
|
5199
|
-
* The spender is the
|
5223
|
+
* Approve an ERC20 to be used as a currency on HypercertExchange.
|
5224
|
+
* The spender is the HypercertExchangeProtocol contract.
|
5200
5225
|
* @param tokenAddress Address of the ERC20 to approve
|
5201
5226
|
* @param amount Amount to be approved (default to MaxUint256)
|
5202
5227
|
* @returns ContractTransaction
|
@@ -5281,7 +5306,7 @@ class HypercertExchangeClient {
|
|
5281
5306
|
throw new Error("No signer address could be determined");
|
5282
5307
|
}
|
5283
5308
|
const chainId = this.chainId;
|
5284
|
-
const { nonce_counter } = await fetchOrderNonce({
|
5309
|
+
const { nonce_counter } = await this.api.fetchOrderNonce({
|
5285
5310
|
address,
|
5286
5311
|
chainId,
|
5287
5312
|
});
|
@@ -5322,7 +5347,7 @@ class HypercertExchangeClient {
|
|
5322
5347
|
throw new Error("No signer address could be determined");
|
5323
5348
|
}
|
5324
5349
|
const chainId = this.chainId;
|
5325
|
-
const { nonce_counter } = await fetchOrderNonce({
|
5350
|
+
const { nonce_counter } = await this.api.fetchOrderNonce({
|
5326
5351
|
address,
|
5327
5352
|
chainId,
|
5328
5353
|
});
|
@@ -5378,7 +5403,7 @@ class HypercertExchangeClient {
|
|
5378
5403
|
throw new Error("No signer address could be determined");
|
5379
5404
|
}
|
5380
5405
|
const chainId = this.chainId;
|
5381
|
-
return registerOrder({
|
5406
|
+
return this.api.registerOrder({
|
5382
5407
|
order,
|
5383
5408
|
signer: address,
|
5384
5409
|
signature,
|
package/dist/types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { BigNumberish, BytesLike, Overrides, TypedDataField, ContractTransactionResponse } from "ethers";
|
2
2
|
import { Eip712MakerMerkleTree } from "./utils/Eip712MakerMerkleTree";
|
3
|
-
/** Addresses used to create a
|
3
|
+
/** Addresses used to create a HypercertExchange instance */
|
4
4
|
export interface Addresses {
|
5
5
|
EXCHANGE_V2: `0x${string}`;
|
6
6
|
TRANSFER_MANAGER_V2: `0x${string}`;
|
@@ -13,7 +13,7 @@ export declare enum ChainId {
|
|
13
13
|
SEPOLIA = 11155111,
|
14
14
|
HARDHAT = 31337
|
15
15
|
}
|
16
|
-
/** ChainInfo data used to interact with
|
16
|
+
/** ChainInfo data used to interact with HypercertExchange ecosystem */
|
17
17
|
export interface ChainInfo {
|
18
18
|
label: string;
|
19
19
|
appUrl: string;
|
@@ -97,7 +97,7 @@ export interface CreateMakerInput {
|
|
97
97
|
collectionType: CollectionType;
|
98
98
|
/** Subset nonce used to group an arbitrary number of orders under the same nonce */
|
99
99
|
subsetNonce: BigNumberish;
|
100
|
-
/** Order nonce, get it from the
|
100
|
+
/** Order nonce, get it from the HypercertExchange api */
|
101
101
|
orderNonce: BigNumberish;
|
102
102
|
/** Timestamp in seconds when the order becomes invalid */
|
103
103
|
endTime: BigNumberish;
|
package/dist/utils/api.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Maker, QuoteType } from "../types";
|
1
|
+
import { Maker, QuoteType, StrategyType } from "../types";
|
2
2
|
import { Database as HypercertsDatabase } from "./hypercerts-database-types";
|
3
3
|
export declare const supabaseHypercerts: import("@supabase/supabase-js").SupabaseClient<HypercertsDatabase, "public", {
|
4
4
|
Tables: {
|
@@ -85,7 +85,13 @@ export declare const supabaseHypercerts: import("@supabase/supabase-js").Supabas
|
|
85
85
|
id?: number | undefined;
|
86
86
|
};
|
87
87
|
Relationships: [];
|
88
|
-
};
|
88
|
+
}; /**
|
89
|
+
* Fetch existing open orders from the marketplace API
|
90
|
+
* @param signer address of the user that created the order
|
91
|
+
* @param claimTokenIds a list of claimTokenIds - will return any order that is for one or more of these claimTokenIds
|
92
|
+
* @param chainId chain id for the order
|
93
|
+
* @param strategy strategy for the order
|
94
|
+
*/
|
89
95
|
"allowlistCache-optimism": {
|
90
96
|
Row: {
|
91
97
|
address: string | null;
|
@@ -724,62 +730,102 @@ export declare const supabaseHypercerts: import("@supabase/supabase-js").Supabas
|
|
724
730
|
Enums: {};
|
725
731
|
CompositeTypes: {};
|
726
732
|
}>;
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
}
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
quoteType:
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
733
|
+
export declare class ApiClient {
|
734
|
+
private readonly baseUrl?;
|
735
|
+
private _baseUrl;
|
736
|
+
constructor(baseUrl?: string | undefined);
|
737
|
+
/**
|
738
|
+
* Fetches order nonce from api
|
739
|
+
* @param address Address
|
740
|
+
* @param chainId Chain ID
|
741
|
+
*/
|
742
|
+
fetchOrderNonce: ({ address, chainId }: {
|
743
|
+
address: string;
|
744
|
+
chainId: number;
|
745
|
+
}) => Promise<{
|
746
|
+
nonce_counter: number;
|
747
|
+
address: string;
|
748
|
+
chain_id: number;
|
749
|
+
}>;
|
750
|
+
/**
|
751
|
+
* Registers order in api
|
752
|
+
* @param order Order
|
753
|
+
* @param signer Signer
|
754
|
+
* @param signature Signature
|
755
|
+
* @param quoteType Quote type
|
756
|
+
* @param chainId Chain ID
|
757
|
+
*/
|
758
|
+
registerOrder: ({ order, signer, signature, quoteType, chainId, }: {
|
759
|
+
order: Maker;
|
760
|
+
signer: string;
|
761
|
+
signature: string;
|
762
|
+
quoteType: QuoteType;
|
763
|
+
chainId: number;
|
764
|
+
}) => Promise<{
|
765
|
+
success: boolean;
|
766
|
+
}>;
|
767
|
+
/**
|
768
|
+
* Fetch existing open orders from the marketplace API
|
769
|
+
* @param signer address of the user that created the order
|
770
|
+
* @param claimTokenIds a list of claimTokenIds - will return any order that is for one or more of these claimTokenIds
|
771
|
+
* @param chainId chain id for the order
|
772
|
+
* @param strategy strategy for the order
|
773
|
+
*/
|
774
|
+
fetchOrders: ({ signer, claimTokenIds, chainId, strategy }: Partial<FetchOrderArgs>) => Promise<import("@supabase/supabase-js").PostgrestSingleResponse<{
|
775
|
+
additionalParameters: string;
|
776
|
+
amounts: number[];
|
777
|
+
chainId: number;
|
778
|
+
collection: string;
|
779
|
+
collectionType: number;
|
780
|
+
createdAt: string;
|
781
|
+
currency: string;
|
782
|
+
endTime: number;
|
783
|
+
globalNonce: string;
|
784
|
+
id: string;
|
785
|
+
itemIds: string[];
|
786
|
+
orderNonce: string;
|
787
|
+
price: string;
|
788
|
+
quoteType: number;
|
789
|
+
signature: string;
|
790
|
+
signer: string;
|
791
|
+
startTime: number;
|
792
|
+
strategyId: number;
|
793
|
+
subsetNonce: number;
|
794
|
+
}[]>>;
|
795
|
+
/**
|
796
|
+
* Fetches orders from api by hypercert ID
|
797
|
+
* @param hypercertId Hypercert ID
|
798
|
+
* @param chainId Chain ID
|
799
|
+
*/
|
800
|
+
fetchOrdersByHypercertId: ({ hypercertId, chainId }: {
|
801
|
+
hypercertId: string;
|
802
|
+
chainId: number;
|
803
|
+
}) => Promise<import("@supabase/supabase-js").PostgrestSingleResponse<{
|
804
|
+
additionalParameters: string;
|
805
|
+
amounts: number[];
|
806
|
+
chainId: number;
|
807
|
+
collection: string;
|
808
|
+
collectionType: number;
|
809
|
+
createdAt: string;
|
810
|
+
currency: string;
|
811
|
+
endTime: number;
|
812
|
+
globalNonce: string;
|
813
|
+
id: string;
|
814
|
+
itemIds: string[];
|
815
|
+
orderNonce: string;
|
816
|
+
price: string;
|
817
|
+
quoteType: number;
|
818
|
+
signature: string;
|
819
|
+
signer: string;
|
820
|
+
startTime: number;
|
821
|
+
strategyId: number;
|
822
|
+
subsetNonce: number;
|
823
|
+
}[]>>;
|
824
|
+
}
|
825
|
+
interface FetchOrderArgs {
|
826
|
+
signer: `0x${string}`;
|
827
|
+
claimTokenIds: string[];
|
768
828
|
chainId: number;
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
currency: string;
|
773
|
-
endTime: number;
|
774
|
-
globalNonce: string;
|
775
|
-
id: string;
|
776
|
-
itemIds: string[];
|
777
|
-
orderNonce: string;
|
778
|
-
price: string;
|
779
|
-
quoteType: number;
|
780
|
-
signature: string;
|
781
|
-
signer: string;
|
782
|
-
startTime: number;
|
783
|
-
strategyId: number;
|
784
|
-
subsetNonce: number;
|
785
|
-
}[]>>;
|
829
|
+
strategy: StrategyType;
|
830
|
+
}
|
831
|
+
export {};
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { Signer } from "ethers";
|
2
2
|
import { Maker, MerkleTree, Taker, ContractMethods } from "../../types";
|
3
|
-
|
4
|
-
export declare const
|
5
|
-
export declare const
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
import { PayableOverrides } from "../../typechain/common";
|
4
|
+
export declare const executeTakerBid: (signer: Signer, address: string, taker: Taker, maker: Maker, makerSignature: string, merkleTree: MerkleTree, overrides?: PayableOverrides) => ContractMethods;
|
5
|
+
export declare const executeTakerAsk: (signer: Signer, address: string, taker: Taker, maker: Maker, makerSignature: string, merkleTree: MerkleTree, overrides?: PayableOverrides) => ContractMethods;
|
6
|
+
export declare const executeMultipleTakerBids: (signer: Signer, address: string, taker: Taker[], maker: Maker[], makerSignature: string[], isAtomic: boolean, merkleTree: MerkleTree[], overrides?: PayableOverrides) => {
|
7
|
+
call: (additionalOverrides?: PayableOverrides) => any;
|
8
|
+
estimateGas: (additionalOverrides?: PayableOverrides) => any;
|
9
|
+
callStatic: (additionalOverrides?: PayableOverrides) => any;
|
9
10
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hypercerts-org/marketplace-sdk",
|
3
|
-
"version": "0.0
|
3
|
+
"version": "0.1.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "dist/index.cjs.js",
|
6
6
|
"module": "dist/index.esm.js",
|
@@ -13,7 +13,7 @@
|
|
13
13
|
"registry": "https://registry.npmjs.org"
|
14
14
|
},
|
15
15
|
"keywords": [
|
16
|
-
"
|
16
|
+
"hypercertexchange"
|
17
17
|
],
|
18
18
|
"homepage": "https://hypercerts.org/",
|
19
19
|
"bugs": "https://github.com/hypercerts-org/hypercerts/issues",
|