@zero-tech/zauction-sdk 0.2.9 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/actions/approveSpender.d.ts.map +1 -1
- package/lib/actions/approveSpender.js +3 -1
- package/lib/actions/approveSpender.js.map +1 -1
- package/lib/actions/cancelBid.d.ts.map +1 -1
- package/lib/actions/cancelBid.js.map +1 -1
- package/lib/actions/getPaymentTokenAllowance.d.ts.map +1 -1
- package/lib/actions/getPaymentTokenAllowance.js +3 -1
- package/lib/actions/getPaymentTokenAllowance.js.map +1 -1
- package/lib/api/actions/helpers.d.ts +1 -1
- package/lib/api/actions/helpers.d.ts.map +1 -1
- package/lib/api/actions/helpers.js +2 -2
- package/lib/api/actions/helpers.js.map +1 -1
- package/lib/api/actions/listBidsForAccount.d.ts +1 -1
- package/lib/api/actions/listBidsForAccount.d.ts.map +1 -1
- package/lib/api/actions/listBidsForAccount.js +2 -2
- package/lib/api/actions/listBidsForAccount.js.map +1 -1
- package/lib/api/actions/listBidsForTokens.d.ts +1 -1
- package/lib/api/actions/listBidsForTokens.d.ts.map +1 -1
- package/lib/api/actions/listBidsForTokens.js +2 -2
- package/lib/api/actions/listBidsForTokens.js.map +1 -1
- package/lib/api/actions/submitBid.d.ts.map +1 -1
- package/lib/api/actions/submitBid.js +1 -1
- package/lib/api/actions/submitBid.js.map +1 -1
- package/lib/api/actions/submitCancelMessage.d.ts.map +1 -1
- package/lib/api/actions/submitCancelMessage.js.map +1 -1
- package/lib/api/client.d.ts +2 -2
- package/lib/api/client.d.ts.map +1 -1
- package/lib/api/client.js +5 -5
- package/lib/api/client.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/subgraph/actions/listAllBuyNowListings.d.ts.map +1 -1
- package/lib/subgraph/actions/listAllBuyNowListings.js +1 -0
- package/lib/subgraph/actions/listAllBuyNowListings.js.map +1 -1
- package/lib/subgraph/actions/listAllSales.d.ts.map +1 -1
- package/lib/subgraph/actions/listAllSales.js +1 -0
- package/lib/subgraph/actions/listAllSales.js.map +1 -1
- package/lib/subgraph/actions/listBuyNowSales.js +1 -1
- package/lib/subgraph/actions/listBuyNowSales.js.map +1 -1
- package/lib/subgraph/helpers/index.d.ts.map +1 -1
- package/lib/subgraph/helpers/index.js.map +1 -1
- package/lib/utilities/logging.js +1 -0
- package/lib/utilities/logging.js.map +1 -1
- package/package.json +3 -2
- package/src/actions/acceptBid.ts +167 -0
- package/src/actions/approveDomainTransfer.ts +25 -0
- package/src/actions/approveSpender.ts +27 -0
- package/src/actions/buyNow.ts +109 -0
- package/src/actions/cancelBid.ts +37 -0
- package/src/actions/getBuyNowListing.ts +65 -0
- package/src/actions/getPaymentTokenAllowance.ts +30 -0
- package/src/actions/index.ts +11 -0
- package/src/actions/isZAuctionApproved.ts +20 -0
- package/src/actions/placeBid.ts +102 -0
- package/src/actions/setBuyNowPrice.ts +56 -0
- package/src/actions/setNetworkPaymentToken.ts +46 -0
- package/src/api/actions/encodeBid.ts +44 -0
- package/src/api/actions/encodeCancelMessage.ts +24 -0
- package/src/api/actions/helpers.ts +61 -0
- package/src/api/actions/index.ts +6 -0
- package/src/api/actions/listBidsForAccount.ts +24 -0
- package/src/api/actions/listBidsForTokens.ts +39 -0
- package/src/api/actions/submitBid.ts +28 -0
- package/src/api/actions/submitCancelMessage.ts +30 -0
- package/src/api/client.ts +78 -0
- package/src/api/index.ts +1 -0
- package/src/api/types.ts +47 -0
- package/src/contracts/index.ts +53 -0
- package/src/contracts/types/IERC20.d.ts +294 -0
- package/src/contracts/types/IERC721.d.ts +472 -0
- package/src/contracts/types/IZNSHub.d.ts +578 -0
- package/src/contracts/types/ZAuction.d.ts +1487 -0
- package/src/contracts/types/ZAuctionV1.d.ts +440 -0
- package/src/contracts/types/commons.ts +36 -0
- package/src/contracts/types/factories/IERC20__factory.ts +203 -0
- package/src/contracts/types/factories/IERC721__factory.ts +308 -0
- package/src/contracts/types/factories/IZNSHub__factory.ts +311 -0
- package/src/contracts/types/factories/ZAuctionV1__factory.ts +326 -0
- package/src/contracts/types/factories/ZAuction__factory.ts +1033 -0
- package/src/contracts/types/index.ts +14 -0
- package/src/index.ts +468 -0
- package/src/subgraph/actions/index.ts +4 -0
- package/src/subgraph/actions/listAllBuyNowListings.ts +69 -0
- package/src/subgraph/actions/listAllSales.ts +57 -0
- package/src/subgraph/actions/listBuyNowSales.ts +44 -0
- package/src/subgraph/actions/listSales.ts +33 -0
- package/src/subgraph/client.ts +62 -0
- package/src/subgraph/helpers/index.ts +39 -0
- package/src/subgraph/index.ts +1 -0
- package/src/subgraph/queries.ts +75 -0
- package/src/subgraph/types.ts +58 -0
- package/src/types.ts +181 -0
- package/src/utilities/index.ts +2 -0
- package/src/utilities/logging.ts +27 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
2
|
+
/* tslint:disable */
|
3
|
+
/* eslint-disable */
|
4
|
+
export type { IERC20 } from "./IERC20";
|
5
|
+
export type { IERC721 } from "./IERC721";
|
6
|
+
export type { IZNSHub } from "./IZNSHub";
|
7
|
+
export type { ZAuction } from "./ZAuction";
|
8
|
+
export type { ZAuctionV1 } from "./ZAuctionV1";
|
9
|
+
|
10
|
+
export { IERC20__factory } from "./factories/IERC20__factory";
|
11
|
+
export { IERC721__factory } from "./factories/IERC721__factory";
|
12
|
+
export { IZNSHub__factory } from "./factories/IZNSHub__factory";
|
13
|
+
export { ZAuction__factory } from "./factories/ZAuction__factory";
|
14
|
+
export { ZAuctionV1__factory } from "./factories/ZAuctionV1__factory";
|
package/src/index.ts
ADDED
@@ -0,0 +1,468 @@
|
|
1
|
+
import * as subgraph from "./subgraph";
|
2
|
+
import * as api from "./api";
|
3
|
+
import * as actions from "./actions";
|
4
|
+
|
5
|
+
import { ethers } from "ethers";
|
6
|
+
|
7
|
+
import {
|
8
|
+
PlaceBidStatusCallback,
|
9
|
+
NewBidParameters,
|
10
|
+
Config,
|
11
|
+
Instance,
|
12
|
+
Bid,
|
13
|
+
BuyNowParams,
|
14
|
+
BuyNowListing,
|
15
|
+
TokenSale,
|
16
|
+
TokenBuy,
|
17
|
+
TokenSaleCollection,
|
18
|
+
TokenBidCollection,
|
19
|
+
TokenBuyNowListingCollection,
|
20
|
+
TokenBidFilter,
|
21
|
+
} from "./types";
|
22
|
+
import {
|
23
|
+
getERC721Contract,
|
24
|
+
getZAuctionContract,
|
25
|
+
getZnsHubContract,
|
26
|
+
} from "./contracts";
|
27
|
+
import { IZNSHub } from "./contracts/types";
|
28
|
+
import { approveDomainTransfer, approveSpender } from "./actions";
|
29
|
+
import { getLogger, Maybe } from "./utilities/";
|
30
|
+
|
31
|
+
const logger = getLogger("zauction-sdk");
|
32
|
+
|
33
|
+
export * from "./types";
|
34
|
+
|
35
|
+
export const createInstance = (config: Config): Instance => {
|
36
|
+
logger.debug("Creating instance of zAuction SDK");
|
37
|
+
logger.debug(config);
|
38
|
+
|
39
|
+
const subgraphClient: subgraph.SubgraphClient = subgraph.createClient(
|
40
|
+
config.subgraphUri,
|
41
|
+
config.wildTokenAddress
|
42
|
+
);
|
43
|
+
|
44
|
+
const apiClient: api.ApiClient = api.createClient(config.apiUri);
|
45
|
+
|
46
|
+
const instance = {
|
47
|
+
listSales: async (tokenId: string): Promise<TokenSale[]> => {
|
48
|
+
const hub = await getZnsHubContract(
|
49
|
+
config.web3Provider,
|
50
|
+
config.znsHubAddress
|
51
|
+
);
|
52
|
+
const domainContract = await hub.getRegistrarForDomain(tokenId);
|
53
|
+
const tokenSales: TokenSale[] = await subgraphClient.listSales(
|
54
|
+
domainContract,
|
55
|
+
tokenId
|
56
|
+
);
|
57
|
+
return tokenSales;
|
58
|
+
},
|
59
|
+
listAllSales: async (): Promise<TokenSaleCollection> => {
|
60
|
+
const tokenSaleCollection: TokenSaleCollection =
|
61
|
+
await subgraphClient.listAllSales();
|
62
|
+
return tokenSaleCollection;
|
63
|
+
},
|
64
|
+
listAllBuyNowListings: async () => {
|
65
|
+
const tokenBuyNowListingCollection: TokenBuyNowListingCollection =
|
66
|
+
await subgraphClient.listAllBuyNowListings();
|
67
|
+
return tokenBuyNowListingCollection;
|
68
|
+
},
|
69
|
+
listBuyNowSales: async (tokenId: string): Promise<TokenBuy[]> => {
|
70
|
+
const hub = await getZnsHubContract(
|
71
|
+
config.web3Provider,
|
72
|
+
config.znsHubAddress
|
73
|
+
);
|
74
|
+
const domainContract = await hub.getRegistrarForDomain(tokenId);
|
75
|
+
const tokenBuys: TokenBuy[] = await subgraphClient.listBuyNowSales(
|
76
|
+
domainContract,
|
77
|
+
tokenId
|
78
|
+
);
|
79
|
+
return tokenBuys;
|
80
|
+
},
|
81
|
+
listBids: async (
|
82
|
+
tokenIds: string[],
|
83
|
+
filter?: TokenBidFilter
|
84
|
+
): Promise<TokenBidCollection> => {
|
85
|
+
const tokenBidCollection: TokenBidCollection =
|
86
|
+
await apiClient.listBidsForTokens(
|
87
|
+
tokenIds,
|
88
|
+
config.wildTokenAddress,
|
89
|
+
filter
|
90
|
+
);
|
91
|
+
return tokenBidCollection;
|
92
|
+
},
|
93
|
+
listBidsByAccount: async (account: string) => {
|
94
|
+
const bidsList: Bid[] = await apiClient.listBidsByAccount(
|
95
|
+
account,
|
96
|
+
config.wildTokenAddress
|
97
|
+
);
|
98
|
+
return bidsList;
|
99
|
+
},
|
100
|
+
placeBid: async (
|
101
|
+
params: NewBidParameters,
|
102
|
+
signer: ethers.Signer,
|
103
|
+
statusCallback?: PlaceBidStatusCallback
|
104
|
+
) => {
|
105
|
+
await actions.placeBid({
|
106
|
+
bid: params,
|
107
|
+
config: config,
|
108
|
+
bidder: await signer.getAddress(),
|
109
|
+
encodeBid: apiClient.encodeBid,
|
110
|
+
signMessage: (e) => signer.signMessage(e),
|
111
|
+
submitBid: apiClient.submitBid,
|
112
|
+
statusCallback,
|
113
|
+
});
|
114
|
+
},
|
115
|
+
isZAuctionApprovedToTransferNftByBid: async (
|
116
|
+
account: string,
|
117
|
+
bid: Bid
|
118
|
+
): Promise<boolean> => {
|
119
|
+
logger.trace(
|
120
|
+
`Calling to check if user ${account} has approved zAuction to transfer NFTs from ${bid.contract}`
|
121
|
+
);
|
122
|
+
const isVersion1 = bid.version === "1.0";
|
123
|
+
|
124
|
+
// route to legacy if version 1.0
|
125
|
+
const zAuctionAddress = isVersion1
|
126
|
+
? config.zAuctionLegacyAddress
|
127
|
+
: config.zAuctionAddress;
|
128
|
+
|
129
|
+
const nftContract = await getERC721Contract(
|
130
|
+
config.web3Provider,
|
131
|
+
bid.contract
|
132
|
+
);
|
133
|
+
|
134
|
+
const isApproved = await actions.isZAuctionApprovedNftTransfer(
|
135
|
+
account,
|
136
|
+
zAuctionAddress,
|
137
|
+
nftContract
|
138
|
+
);
|
139
|
+
|
140
|
+
return isApproved;
|
141
|
+
},
|
142
|
+
|
143
|
+
isZAuctionApprovedToTransferNftByDomain: async (
|
144
|
+
account: string,
|
145
|
+
tokenId: string
|
146
|
+
): Promise<boolean> => {
|
147
|
+
const hub = await getZnsHubContract(
|
148
|
+
config.web3Provider,
|
149
|
+
config.znsHubAddress
|
150
|
+
);
|
151
|
+
const domainContract = await hub.getRegistrarForDomain(tokenId);
|
152
|
+
logger.trace(
|
153
|
+
`Calling to check if user ${account} has approved zAuction to transfer NFTs from ${domainContract}`
|
154
|
+
);
|
155
|
+
const nftContract = await getERC721Contract(
|
156
|
+
config.web3Provider,
|
157
|
+
domainContract
|
158
|
+
);
|
159
|
+
|
160
|
+
const isApproved = await actions.isZAuctionApprovedNftTransfer(
|
161
|
+
account,
|
162
|
+
config.zAuctionAddress,
|
163
|
+
nftContract
|
164
|
+
);
|
165
|
+
|
166
|
+
return isApproved;
|
167
|
+
},
|
168
|
+
isZAuctionLegacyApprovedToTransferNft: async (
|
169
|
+
account: string,
|
170
|
+
tokenId: string
|
171
|
+
): Promise<boolean> => {
|
172
|
+
const hub = await getZnsHubContract(
|
173
|
+
config.web3Provider,
|
174
|
+
config.znsHubAddress
|
175
|
+
);
|
176
|
+
const domainContract = await hub.getRegistrarForDomain(tokenId);
|
177
|
+
logger.trace(
|
178
|
+
`Calling to check if user ${account} has approved zAuction to transfer NFTs from ${domainContract}`
|
179
|
+
);
|
180
|
+
const nftContract = await getERC721Contract(
|
181
|
+
config.web3Provider,
|
182
|
+
domainContract
|
183
|
+
);
|
184
|
+
|
185
|
+
const isApproved = await actions.isZAuctionApprovedNftTransfer(
|
186
|
+
account,
|
187
|
+
config.zAuctionLegacyAddress,
|
188
|
+
nftContract
|
189
|
+
);
|
190
|
+
|
191
|
+
return isApproved;
|
192
|
+
},
|
193
|
+
getZAuctionSpendAllowanceByBid: async (
|
194
|
+
account: string,
|
195
|
+
bid: Bid
|
196
|
+
): Promise<ethers.BigNumber> => {
|
197
|
+
const isVersion1 = bid.version === "1.0";
|
198
|
+
|
199
|
+
// route to legacy if version 1.0
|
200
|
+
const zAuctionAddress = isVersion1
|
201
|
+
? config.zAuctionLegacyAddress
|
202
|
+
: config.zAuctionAddress;
|
203
|
+
|
204
|
+
const bidToken = bid.bidToken ?? config.wildTokenAddress;
|
205
|
+
|
206
|
+
const allowance = await actions.getPaymentTokenAllowance(
|
207
|
+
account,
|
208
|
+
bidToken,
|
209
|
+
config.web3Provider,
|
210
|
+
zAuctionAddress
|
211
|
+
);
|
212
|
+
|
213
|
+
return allowance;
|
214
|
+
},
|
215
|
+
getZAuctionSpendAllowanceByDomain: async (
|
216
|
+
account: string,
|
217
|
+
tokenId: string
|
218
|
+
): Promise<ethers.BigNumber> => {
|
219
|
+
const contract = await getZAuctionContract(
|
220
|
+
config.web3Provider,
|
221
|
+
config.zAuctionAddress
|
222
|
+
);
|
223
|
+
const paymentToken = await contract.getPaymentTokenForDomain(tokenId);
|
224
|
+
|
225
|
+
const allowance = await actions.getPaymentTokenAllowance(
|
226
|
+
account,
|
227
|
+
paymentToken,
|
228
|
+
config.web3Provider,
|
229
|
+
config.zAuctionAddress
|
230
|
+
);
|
231
|
+
return allowance;
|
232
|
+
},
|
233
|
+
getZAuctionSpendAllowance: async (
|
234
|
+
account: string,
|
235
|
+
paymentToken: string
|
236
|
+
): Promise<ethers.BigNumber> => {
|
237
|
+
const allowance = await actions.getPaymentTokenAllowance(
|
238
|
+
account,
|
239
|
+
paymentToken,
|
240
|
+
config.web3Provider,
|
241
|
+
config.zAuctionAddress
|
242
|
+
);
|
243
|
+
return allowance;
|
244
|
+
},
|
245
|
+
getZAuctionLegacySpendAllowance: async (
|
246
|
+
account: string
|
247
|
+
): Promise<ethers.BigNumber> => {
|
248
|
+
const allowance = await actions.getPaymentTokenAllowance(
|
249
|
+
account,
|
250
|
+
config.wildTokenAddress,
|
251
|
+
config.web3Provider,
|
252
|
+
config.zAuctionLegacyAddress
|
253
|
+
);
|
254
|
+
return allowance;
|
255
|
+
},
|
256
|
+
// Set the ERC20 token for a specific domain network
|
257
|
+
setNetworkPaymentToken: async (
|
258
|
+
networkId: string,
|
259
|
+
paymentToken: string,
|
260
|
+
signer: ethers.Signer
|
261
|
+
): Promise<ethers.ContractTransaction> => {
|
262
|
+
const tx = await actions.setNetworkPaymentToken(
|
263
|
+
networkId,
|
264
|
+
paymentToken,
|
265
|
+
signer,
|
266
|
+
config
|
267
|
+
);
|
268
|
+
return tx;
|
269
|
+
},
|
270
|
+
// Return the ERC20 token used for payment in the network that domain is a part of.
|
271
|
+
// This could be either the network payment token or the default payment token
|
272
|
+
getPaymentTokenForDomain: async (
|
273
|
+
domainTokenId: string
|
274
|
+
): Promise<string> => {
|
275
|
+
const contract = await getZAuctionContract(
|
276
|
+
config.web3Provider,
|
277
|
+
config.zAuctionAddress
|
278
|
+
);
|
279
|
+
const paymentToken = await contract.getPaymentTokenForDomain(
|
280
|
+
domainTokenId
|
281
|
+
);
|
282
|
+
logger.trace(
|
283
|
+
`Payment token for domain with ID ${domainTokenId} is ${paymentToken}`
|
284
|
+
);
|
285
|
+
return paymentToken;
|
286
|
+
},
|
287
|
+
approveZAuctionSpendPaymentTokenByBid: async (
|
288
|
+
bid: Bid,
|
289
|
+
signer: ethers.Signer
|
290
|
+
): Promise<ethers.ContractTransaction> => {
|
291
|
+
const isVersion1 = bid.version === "1.0";
|
292
|
+
|
293
|
+
// route to legacy if version 1.0
|
294
|
+
const zAuctionAddress = isVersion1
|
295
|
+
? config.zAuctionLegacyAddress
|
296
|
+
: config.zAuctionAddress;
|
297
|
+
|
298
|
+
const bidToken = bid.bidToken ?? config.wildTokenAddress;
|
299
|
+
const tx = await actions.approveSpender(
|
300
|
+
bidToken,
|
301
|
+
zAuctionAddress,
|
302
|
+
signer
|
303
|
+
);
|
304
|
+
return tx;
|
305
|
+
},
|
306
|
+
approveZAuctionSpendPaymentTokenByDomain: async (
|
307
|
+
tokenId: string,
|
308
|
+
signer: ethers.Signer
|
309
|
+
): Promise<ethers.ContractTransaction> => {
|
310
|
+
const contract = await getZAuctionContract(
|
311
|
+
config.web3Provider,
|
312
|
+
config.zAuctionAddress
|
313
|
+
);
|
314
|
+
const paymentToken = await contract.getPaymentTokenForDomain(tokenId);
|
315
|
+
const tx = await approveSpender(
|
316
|
+
paymentToken,
|
317
|
+
config.zAuctionAddress,
|
318
|
+
signer
|
319
|
+
);
|
320
|
+
return tx;
|
321
|
+
},
|
322
|
+
approveZAuctionSpendPaymentToken: async (
|
323
|
+
paymentTokenAddress: string,
|
324
|
+
signer: ethers.Signer
|
325
|
+
): Promise<ethers.ContractTransaction> => {
|
326
|
+
const tx = await approveSpender(
|
327
|
+
paymentTokenAddress,
|
328
|
+
config.zAuctionAddress,
|
329
|
+
signer
|
330
|
+
);
|
331
|
+
return tx;
|
332
|
+
},
|
333
|
+
approveZAuctionTransferNftByBid: async (
|
334
|
+
bid: Bid,
|
335
|
+
signer: ethers.Signer
|
336
|
+
): Promise<ethers.ContractTransaction> => {
|
337
|
+
const isVersion1 = bid.version === "1.0";
|
338
|
+
|
339
|
+
// route to legacy if version 1.0
|
340
|
+
const zAuctionAddress = isVersion1
|
341
|
+
? config.zAuctionLegacyAddress
|
342
|
+
: config.zAuctionAddress;
|
343
|
+
|
344
|
+
const hub: IZNSHub = await getZnsHubContract(
|
345
|
+
signer,
|
346
|
+
config.znsHubAddress
|
347
|
+
);
|
348
|
+
const domainContract = await hub.getRegistrarForDomain(bid.tokenId);
|
349
|
+
|
350
|
+
const tx = await approveDomainTransfer(
|
351
|
+
domainContract,
|
352
|
+
zAuctionAddress,
|
353
|
+
signer
|
354
|
+
);
|
355
|
+
|
356
|
+
return tx;
|
357
|
+
},
|
358
|
+
approveZAuctionTransferNftByDomain: async (
|
359
|
+
tokenId: string,
|
360
|
+
signer: ethers.Signer
|
361
|
+
): Promise<ethers.ContractTransaction> => {
|
362
|
+
const hub: IZNSHub = await getZnsHubContract(
|
363
|
+
signer,
|
364
|
+
config.znsHubAddress
|
365
|
+
);
|
366
|
+
const domainContract = await hub.getRegistrarForDomain(tokenId);
|
367
|
+
|
368
|
+
const tx = approveDomainTransfer(
|
369
|
+
domainContract,
|
370
|
+
config.zAuctionAddress,
|
371
|
+
signer
|
372
|
+
);
|
373
|
+
return tx;
|
374
|
+
},
|
375
|
+
acceptBid: async (
|
376
|
+
bid: Bid,
|
377
|
+
signer: ethers.Signer
|
378
|
+
): Promise<ethers.ContractTransaction> => {
|
379
|
+
const tx = await actions.acceptBid(bid, signer, config);
|
380
|
+
return tx;
|
381
|
+
},
|
382
|
+
cancelBid: async (
|
383
|
+
bid: Bid,
|
384
|
+
cancelOnChain: boolean,
|
385
|
+
signer: ethers.Signer
|
386
|
+
): Promise<ethers.ContractTransaction | void> => {
|
387
|
+
const isVersion1 = bid.version === "1.0";
|
388
|
+
|
389
|
+
// route to legacy if version 1.0
|
390
|
+
const zAuctionAddress = isVersion1
|
391
|
+
? config.zAuctionLegacyAddress
|
392
|
+
: config.zAuctionAddress;
|
393
|
+
|
394
|
+
const tx: ethers.ContractTransaction | void = await actions.cancelBid(
|
395
|
+
bid,
|
396
|
+
cancelOnChain,
|
397
|
+
apiClient,
|
398
|
+
zAuctionAddress,
|
399
|
+
signer
|
400
|
+
);
|
401
|
+
return tx;
|
402
|
+
},
|
403
|
+
buyNow: async (
|
404
|
+
params: BuyNowParams,
|
405
|
+
signer: ethers.Signer
|
406
|
+
): Promise<ethers.ContractTransaction> => {
|
407
|
+
const tx = await actions.buyNow(params, signer, config);
|
408
|
+
return tx;
|
409
|
+
},
|
410
|
+
|
411
|
+
// IF no return value then that domain is not on sale
|
412
|
+
getBuyNowListing: async (
|
413
|
+
tokenId: string
|
414
|
+
): Promise<Maybe<BuyNowListing>> => {
|
415
|
+
const listing: Maybe<BuyNowListing> = await actions.getBuyNowListing(
|
416
|
+
tokenId,
|
417
|
+
config
|
418
|
+
);
|
419
|
+
return listing;
|
420
|
+
},
|
421
|
+
setBuyNowPrice: async (
|
422
|
+
params: BuyNowParams,
|
423
|
+
signer: ethers.Signer
|
424
|
+
): Promise<ethers.ContractTransaction> => {
|
425
|
+
const tx = await actions.setBuyNowPrice(
|
426
|
+
params,
|
427
|
+
signer,
|
428
|
+
config.znsHubAddress,
|
429
|
+
config.zAuctionAddress
|
430
|
+
);
|
431
|
+
return tx;
|
432
|
+
},
|
433
|
+
|
434
|
+
cancelBuyNow: async (
|
435
|
+
tokenId: string,
|
436
|
+
signer: ethers.Signer
|
437
|
+
): Promise<ethers.ContractTransaction> => {
|
438
|
+
const contract = await getZAuctionContract(
|
439
|
+
signer,
|
440
|
+
config.zAuctionAddress
|
441
|
+
);
|
442
|
+
|
443
|
+
const hub: IZNSHub = await getZnsHubContract(
|
444
|
+
config.web3Provider,
|
445
|
+
config.znsHubAddress
|
446
|
+
);
|
447
|
+
const domainContract = await hub.getRegistrarForDomain(tokenId);
|
448
|
+
|
449
|
+
const nftContract = await getERC721Contract(
|
450
|
+
config.web3Provider,
|
451
|
+
domainContract
|
452
|
+
);
|
453
|
+
|
454
|
+
const seller = await nftContract.ownerOf(tokenId);
|
455
|
+
const signerAddress = await signer.getAddress();
|
456
|
+
|
457
|
+
if (signerAddress !== seller)
|
458
|
+
throw Error("Cannot cancel buy now of a domain that is not yours");
|
459
|
+
|
460
|
+
const tx = await contract
|
461
|
+
.connect(signer)
|
462
|
+
.setBuyPrice(ethers.BigNumber.from("0"), tokenId);
|
463
|
+
return tx;
|
464
|
+
},
|
465
|
+
};
|
466
|
+
|
467
|
+
return instance;
|
468
|
+
};
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { ApolloClient } from "@apollo/client/core";
|
2
|
+
import {
|
3
|
+
ListAllBuyNowListingsQueryOptions,
|
4
|
+
TokenBuyNowListingsDto,
|
5
|
+
} from "../types";
|
6
|
+
import { TokenBuyNowListing, TokenBuyNowListingCollection } from "../../types";
|
7
|
+
import * as queries from "../queries";
|
8
|
+
import { getLogger } from "../../utilities";
|
9
|
+
|
10
|
+
const logger = getLogger("subgraph:actions:listAllSales");
|
11
|
+
|
12
|
+
export const listAllBuyNowListings = async <T>(
|
13
|
+
apolloClient: ApolloClient<T>,
|
14
|
+
wildToken: string
|
15
|
+
): Promise<TokenBuyNowListingCollection> => {
|
16
|
+
const collection: TokenBuyNowListingCollection = {};
|
17
|
+
|
18
|
+
const options: ListAllBuyNowListingsQueryOptions = {
|
19
|
+
count: 1000,
|
20
|
+
skipCount: 0,
|
21
|
+
};
|
22
|
+
|
23
|
+
let allListingsLength = 0;
|
24
|
+
/* eslint-disable-next-line no-constant-condition */
|
25
|
+
while (true) {
|
26
|
+
logger.trace(
|
27
|
+
`Querying for ${options.count} buy now listings starting at ${options.skipCount}`
|
28
|
+
);
|
29
|
+
|
30
|
+
const queryResult = await apolloClient.query<TokenBuyNowListingsDto>({
|
31
|
+
query: queries.getBuyNowTokenListings,
|
32
|
+
variables: {
|
33
|
+
...options,
|
34
|
+
},
|
35
|
+
});
|
36
|
+
|
37
|
+
if (queryResult.error) {
|
38
|
+
throw queryResult.error;
|
39
|
+
}
|
40
|
+
|
41
|
+
const listings: TokenBuyNowListing[] = queryResult.data.buyNowListings.map(
|
42
|
+
(e) => {
|
43
|
+
const listing: TokenBuyNowListing = {
|
44
|
+
tokenId: e.id,
|
45
|
+
amount: e.amount,
|
46
|
+
paymentToken: e.paymentToken ?? wildToken,
|
47
|
+
};
|
48
|
+
return listing;
|
49
|
+
}
|
50
|
+
);
|
51
|
+
|
52
|
+
for (const listing of listings) {
|
53
|
+
if (!collection[listing.tokenId]) {
|
54
|
+
collection[listing.tokenId] = [];
|
55
|
+
}
|
56
|
+
if (listing.amount !== "0") {
|
57
|
+
collection[listing.tokenId].push(listing);
|
58
|
+
allListingsLength++;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
if (listings.length < options.count) {
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
logger.trace(`Found ${allListingsLength} buy now listings`);
|
68
|
+
return collection;
|
69
|
+
};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { ApolloClient } from "@apollo/client/core";
|
2
|
+
import { ListAllSalesQueryOptions } from "../types";
|
3
|
+
import { getLogger } from "../../utilities";
|
4
|
+
import { TokenSaleCollection } from "../../types";
|
5
|
+
import * as queries from "../queries";
|
6
|
+
import * as helpers from "../helpers";
|
7
|
+
|
8
|
+
const logger = getLogger("subgraph:actions:listAllSales");
|
9
|
+
|
10
|
+
export const listAllSales = async <T>(
|
11
|
+
apolloClient: ApolloClient<T>,
|
12
|
+
wildToken: string
|
13
|
+
): Promise<TokenSaleCollection> => {
|
14
|
+
const collection: TokenSaleCollection = {};
|
15
|
+
const options: ListAllSalesQueryOptions = {
|
16
|
+
count: 1000,
|
17
|
+
skipCount: 0,
|
18
|
+
};
|
19
|
+
|
20
|
+
// eslint-disable-next-line no-constant-condition
|
21
|
+
let allSalesLength = 0;
|
22
|
+
/* eslint-disable-next-line no-constant-condition */
|
23
|
+
while (true) {
|
24
|
+
logger.trace(
|
25
|
+
`Querying for ${options.count} sales starting at ${options.skipCount}`
|
26
|
+
);
|
27
|
+
|
28
|
+
const sales = await helpers.listSales(
|
29
|
+
apolloClient,
|
30
|
+
queries.getAllTokenSales,
|
31
|
+
options,
|
32
|
+
wildToken
|
33
|
+
);
|
34
|
+
|
35
|
+
for (const sale of sales) {
|
36
|
+
if (!collection[sale.tokenId]) {
|
37
|
+
collection[sale.tokenId] = [];
|
38
|
+
}
|
39
|
+
|
40
|
+
collection[sale.tokenId].push(sale);
|
41
|
+
allSalesLength++;
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* We will only get back up to `queryCount` # of sales
|
46
|
+
* So if we get that many there's probably more sales we need
|
47
|
+
* to fetch. If we got back less, we can stop querying
|
48
|
+
*/
|
49
|
+
if (sales.length < options.count) {
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
options.skipCount += sales.length;
|
53
|
+
}
|
54
|
+
|
55
|
+
logger.trace(`Found ${allSalesLength} sales for all domains`);
|
56
|
+
return collection;
|
57
|
+
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { ApolloClient } from "@apollo/client/core";
|
2
|
+
import { TokenBuyNowSalesDto } from "../types";
|
3
|
+
import * as queries from "../queries";
|
4
|
+
import { TokenBuy } from "../../types";
|
5
|
+
import { getLogger } from "../../utilities";
|
6
|
+
|
7
|
+
const logger = getLogger("subgraph:actions:listBuyNowSales");
|
8
|
+
|
9
|
+
export const listBuyNowSales = async <T>(
|
10
|
+
apolloClient: ApolloClient<T>,
|
11
|
+
contractAddress: string,
|
12
|
+
tokenId: string,
|
13
|
+
wildToken: string
|
14
|
+
): Promise<TokenBuy[]> => {
|
15
|
+
logger.trace(`Querying "buy now" sales for domain with ID ${tokenId}`);
|
16
|
+
const queryResult = await apolloClient.query<TokenBuyNowSalesDto>({
|
17
|
+
query: queries.getBuyNowTokenSales,
|
18
|
+
variables: {
|
19
|
+
contractAddress: contractAddress.toLowerCase(),
|
20
|
+
tokenId,
|
21
|
+
},
|
22
|
+
});
|
23
|
+
|
24
|
+
if (queryResult.error) {
|
25
|
+
throw queryResult.error;
|
26
|
+
}
|
27
|
+
|
28
|
+
const buys: TokenBuy[] = queryResult.data.domainTokenSolds.map((e) => {
|
29
|
+
const buy: TokenBuy = {
|
30
|
+
tokenId: e.tokenId,
|
31
|
+
contract: e.contractAddress,
|
32
|
+
amount: e.amount,
|
33
|
+
seller: e.seller.id,
|
34
|
+
buyer: e.buyer.id,
|
35
|
+
timestamp: e.timestamp,
|
36
|
+
paymentToken: e.paymentToken ?? wildToken,
|
37
|
+
topLevelDomainId: e.topLevelDomainId,
|
38
|
+
};
|
39
|
+
return buy;
|
40
|
+
});
|
41
|
+
|
42
|
+
logger.trace(`Found ${buys.length} buy now sales`);
|
43
|
+
return buys;
|
44
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { ApolloClient } from "@apollo/client/core";
|
2
|
+
import { ListSalesQueryOptions } from "../types";
|
3
|
+
import * as queries from "../queries";
|
4
|
+
import { TokenSale } from "../../types";
|
5
|
+
import { getLogger } from "../../utilities";
|
6
|
+
|
7
|
+
const logger = getLogger("subgraph:actions:listSales");
|
8
|
+
|
9
|
+
import * as helpers from "../helpers";
|
10
|
+
|
11
|
+
export const listSales = async <T>(
|
12
|
+
apolloClient: ApolloClient<T>,
|
13
|
+
contract: string,
|
14
|
+
tokenId: string,
|
15
|
+
wildToken: string
|
16
|
+
): Promise<TokenSale[]> => {
|
17
|
+
logger.trace(`Querying sales for domain with ID ${tokenId}`);
|
18
|
+
|
19
|
+
const options: ListSalesQueryOptions = {
|
20
|
+
contract: contract.toLowerCase(),
|
21
|
+
tokenId,
|
22
|
+
};
|
23
|
+
|
24
|
+
const sales = await helpers.listSales(
|
25
|
+
apolloClient,
|
26
|
+
queries.getTokenSalesForNftQuery,
|
27
|
+
options,
|
28
|
+
wildToken
|
29
|
+
);
|
30
|
+
|
31
|
+
logger.trace(`Found ${sales.length} sales`);
|
32
|
+
return sales;
|
33
|
+
};
|