-
Notifications
You must be signed in to change notification settings - Fork 25
/
client.ts
303 lines (272 loc) · 10.1 KB
/
client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import { PartialTypedDataConfig } from "@ethereum-attestation-service/eas-sdk";
import { HypercertIndexer } from "../indexer";
import { AllowlistEntry, TransferRestrictions } from "./hypercerts";
import { HypercertMetadata } from "./metadata";
import { ByteArray, Chain, Hex, PublicClient, WalletClient } from "viem";
/**
* Enum to verify the supported chainIds
*
* @note 10 = Optimism, 42220 = Celo, 11155111 = Sepolia, 84532 = Base Sepolia, 8453 = Base Mainnet
*/
export type SupportedChainIds = 10 | 42220 | 11155111 | 84532 | 8453;
export type SupportedOverrides = ContractOverrides & StorageConfigOverrides;
/**
* Configuration options for the contract interactions.
*
* @param value The value to send with the transaction (in wei).
* @param gasPrice The gas price to use for the transaction (in wei).
* @param gasLimit The gas limit to use for the transaction (in wei).
*/
export type ContractOverrides = {
value?: bigint;
gasPrice?: bigint;
gasLimit?: bigint;
};
/**
* Configuration options for the Hypercert storage layer.
* @param timeout The timeout (im ms) for the HTTP request; for example for uploading metadata or fetching allowlists.
*/
export type StorageConfigOverrides = {
// Axios timout in ms
timeout?: number;
};
export type Contracts =
| "HypercertMinterUUPS"
| "TransferManager"
| "ProtocolFeeRecipient"
| "HypercertExchange"
| "RoyaltyFeeRegistry"
| "OrderValidator"
| "CreatorFeeManager"
| "StrategyCollectionOffer"
| "StrategyDutchAuction"
| "StrategyItemIdsRange"
| "StrategyHypercertCollectionOffer"
| "StrategyHypercertDutchAuction"
| "StrategyHypercertFractionOffer";
/**
* Represents a deployment of a contract on a specific network.
*/
export type Deployment = {
chain: Partial<Chain>;
/** The address of the deployed contract. */
addresses: Partial<Record<Contracts, `0x${string}`>>;
/** The url to the subgraph that indexes the contract events. Override for localized testing */
graphUrl: string;
graphName: string;
isTestnet: boolean;
};
/**
* Configuration options for the Hypercert client.
*/
export type HypercertClientConfig = Pick<Deployment, "addresses" | "chain"> &
HypercertStorageConfig &
HypercertEvaluatorConfig & {
/** The PublicClient is inherently read-only */
publicClient: PublicClient;
walletClient: WalletClient;
/** Force the use of overridden values */
unsafeForceOverrideConfig?: boolean;
/** Boolean to assert if the client is in readOnly mode */
readOnly: boolean;
/** Reason for readOnly mode */
readOnlyReason?: string;
/** The environment to run the indexer in. This can be either production, test or all. Defaults to test */
indexerEnvironment: IndexerEnvironment;
};
/**
* The environment to run the indexer in.
* Production will run against all mainnet chains, while test will run against testnet chains.
* All will run against both
*/
export type IndexerEnvironment = "production" | "test" | "all";
/**
* Configuration options for the Hypercert storage layer.
* @note The API tokens are optional, but required for storing data on NFT.storage and Web3.storage.
*
* @deprecated nft.storage and web3.storage are no longer used
*/
export type HypercertStorageConfig = {
/** The API token for NFT.storage. */
nftStorageToken?: string;
};
/**
* Configuration options for the Hypercert evaluator.
* @note The signer is required for submitting evaluations.
*/
export type HypercertEvaluatorConfig = Omit<PartialTypedDataConfig, "address"> & {
easContractAddress: string;
};
/**
* The interface for the Hypercert storage layer.
*/
export interface HypercertStorageInterface {
/**
* Stores the allowlost for a hypercert.
* @param allowList The metadata to store.
* @param {StorageConfigOverrides} [config] - An optional configuration object.
* @returns A Promise that resolves to the CID of the stored metadata.
*/
storeAllowList: (allowList: AllowlistEntry[], totalUnits: bigint, config?: StorageConfigOverrides) => Promise<string>;
/**
* Stores the metadata for a hypercert.
* @param metadata The metadata to store.
* @param {StorageConfigOverrides} [config] - An optional configuration object.
* @returns A Promise that resolves to the CID of the stored metadata.
*/
storeMetadata: (metadata: HypercertMetadata, config?: StorageConfigOverrides) => Promise<string>;
/**
* Retrieves the metadata for a hypercerts.
* @param cidOrIpfsUri The CID or IPFS URI of the metadata to retrieve.
* @param {StorageConfigOverrides} [config] - An optional configuration object.
* @returns A Promise that resolves to the retrieved metadata.
*/
getMetadata: (cidOrIpfsUri: string, config?: StorageConfigOverrides) => Promise<HypercertMetadata>;
/**
* Retrieves arbitrary data from IPFS.
* @param cidOrIpfsUri The CID or IPFS URI of the data to retrieve.
* @param {StorageConfigOverrides} [config] - An optional configuration object.
* @returns A Promise that resolves to the retrieved data.
*/
getData: (cidOrIpfsUri: string, config?: StorageConfigOverrides) => Promise<unknown>;
}
/**
* The props for the Hypercert client.
*/
export type HypercertClientProps = {
/** The configuration options for the Hypercert client. */
config?: Partial<HypercertClientConfig>;
};
/**
* The interface for the Hypercert client.
*/
export interface HypercertClientInterface extends HypercertClientMethods, HypercertClientState {}
/**
* The state of the Hypercert client.
*/
export interface HypercertClientState {
/** Whether the client is in read-only mode. */
readonly: boolean;
/** The storage layer used by the client. */
storage: HypercertStorageInterface;
/** The indexer used by the client. */
indexer: HypercertIndexer;
}
/**
* The methods for the Hypercert client.
*/
export interface HypercertClientMethods {
/**
* Gets the contract addresses and graph urls for the provided `chainId`
* @returns The addresses, graph name and graph url.
*/
getDeployments: (chainId: SupportedChainIds) => Partial<Deployment>;
/**
* Mints a new claim.
* @param metaData The metadata for the claim.
* @param totalUnits The total number of units for the claim.
* @param transferRestriction The transfer restriction for the claim.
* @returns A Promise that resolves to the transaction hash
*/
mintClaim: (
metaData: HypercertMetadata,
totalUnits: bigint,
transferRestriction: TransferRestrictions,
) => Promise<`0x${string}` | undefined>;
/**
* Retrieves the TransferRestrictions for a claim.
* @param fractionId The ID of the claim to retrieve.
* @returns A Promise that resolves to the applicable transfer restrictions.
*/
getTransferRestrictions: (fractionId: bigint) => Promise<TransferRestrictions>;
/**
* Transfers a claim fraction to a new owner.
* @param fractionId
* @param to
* @param overrides
* @returns A Promise that resolves to the transaction hash
*/
transferFraction: (
fractionId: bigint,
to: `0x${string}`,
overrides?: SupportedOverrides,
) => Promise<`0x${string}` | undefined>;
/**
* Transfers multiple claim fractions to a new owner.
* @param fractionIds
* @param to
* @param overrides
* @returns A Promise that resolves to the transaction hash
*/
batchTransferFractions: (
fractionIds: bigint[],
to: `0x${string}`,
overrides?: SupportedOverrides,
) => Promise<`0x${string}` | undefined>;
/**
* Creates a new allowlist and mints a new claim with the allowlist.
* @param allowList The allowlist for the claim.
* @param metaData The metadata for the claim.
* @param totalUnits The total number of units for the claim.
* @param transferRestriction The transfer restriction for the claim.
* @returns A Promise that resolves to the transaction hash
*/
createAllowlist: (
allowList: AllowlistEntry[],
metaData: HypercertMetadata,
totalUnits: bigint,
transferRestriction: TransferRestrictions,
) => Promise<`0x${string}` | undefined>;
/**
* Splits a claim into multiple fractions.
* @param fractionId The ID of the claim to split.
* @param newFractions The number of units for each fraction.
* @returns A Promise that resolves to the transaction hash
*/
splitFractionUnits: (fractionId: bigint, fractions: bigint[]) => Promise<`0x${string}` | undefined>;
/**
* Merges multiple claim fractions into a single claim.
* @param fractionIds The IDs of the claim fractions to merge.
* @returns A Promise that resolves to the transaction hash
*/
mergeFractionUnits: (fractionIds: bigint[]) => Promise<`0x${string}` | undefined>;
/**
* Burns a claim fraction.
* @param fractionId The ID of the claim fraction to burn.
* @returns A Promise that resolves to the transaction hash
*/
burnClaimFraction: (fractionId: bigint) => Promise<`0x${string}` | undefined>;
/**
* Mints a claim fraction from an allowlist.
* @param claimId The ID of the claim to mint a fraction for.
* @param units The number of units for the fraction.
* @param proof The Merkle proof for the allowlist.
* @returns A Promise that resolves to the transaction hash
*/
mintClaimFractionFromAllowlist: (
claimId: bigint,
units: bigint,
proof: (Hex | ByteArray)[],
) => Promise<`0x${string}` | undefined>;
/**
* Batch mints a claim fraction from an allowlist
* @param claimIds Array of the IDs of the claims to mint fractions for.
* @param units Array of the number of units for each fraction.
* @param proofs Array of Merkle proofs for the allowlists.
* @returns A Promise that resolves to the transaction receipt
* @note The length of the arrays must be equal.
* @note The order of the arrays must be equal.
* @returns A Promise that resolves to the transaction hash
*/
batchMintClaimFractionsFromAllowlists: (
claimIds: bigint[],
units: bigint[],
proofs: (Hex | ByteArray)[][],
) => Promise<`0x${string}` | undefined>;
/**
* Check if a claim or fraction is on the chain that the Hypercertclient
* is currently connected to
* @param claimOrFractionId The ID of the claim or fraction to check.
*/
isClaimOrFractionOnConnectedChain: (claimOrFractionId: string) => boolean;
}