@zero-tech/zauction-sdk 0.2.10 → 0.2.12
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/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,62 @@
|
|
1
|
+
import * as apollo from "@apollo/client/core";
|
2
|
+
import fetch from "cross-fetch";
|
3
|
+
import {
|
4
|
+
TokenBuy,
|
5
|
+
TokenBuyNowListingCollection,
|
6
|
+
TokenSale,
|
7
|
+
TokenSaleCollection,
|
8
|
+
} from "../types";
|
9
|
+
import * as actions from "./actions";
|
10
|
+
import { getLogger } from "../utilities";
|
11
|
+
|
12
|
+
export interface SubgraphClient {
|
13
|
+
listSales: (contract: string, tokenId: string) => Promise<TokenSale[]>;
|
14
|
+
listBuyNowSales: (contract: string, tokenId: string) => Promise<TokenBuy[]>;
|
15
|
+
listAllSales: () => Promise<TokenSaleCollection>;
|
16
|
+
listAllBuyNowListings: () => Promise<TokenBuyNowListingCollection>;
|
17
|
+
}
|
18
|
+
|
19
|
+
const createApolloClient = (
|
20
|
+
subgraphUri: string
|
21
|
+
): apollo.ApolloClient<apollo.NormalizedCacheObject> => {
|
22
|
+
const client = new apollo.ApolloClient({
|
23
|
+
link: new apollo.HttpLink({ uri: subgraphUri, fetch }),
|
24
|
+
cache: new apollo.InMemoryCache(),
|
25
|
+
});
|
26
|
+
|
27
|
+
return client;
|
28
|
+
};
|
29
|
+
|
30
|
+
export const createClient = (
|
31
|
+
subgraphUri: string,
|
32
|
+
wildToken: string
|
33
|
+
): SubgraphClient => {
|
34
|
+
const apolloClient = createApolloClient(subgraphUri);
|
35
|
+
|
36
|
+
const logger = getLogger("subgraph:client");
|
37
|
+
const subgraphClient: SubgraphClient = {
|
38
|
+
listSales: (contract: string, tokenId: string) => {
|
39
|
+
logger.debug(`Get sales for domain: ${tokenId}`);
|
40
|
+
return actions.listSales(apolloClient, contract, tokenId, wildToken);
|
41
|
+
},
|
42
|
+
listBuyNowSales: (contract: string, tokenId: string) => {
|
43
|
+
logger.debug(`Get "buy now" sales for domain: ${tokenId}`);
|
44
|
+
return actions.listBuyNowSales(
|
45
|
+
apolloClient,
|
46
|
+
contract,
|
47
|
+
tokenId,
|
48
|
+
wildToken
|
49
|
+
);
|
50
|
+
},
|
51
|
+
listAllSales: () => {
|
52
|
+
logger.debug(`Get all sales`);
|
53
|
+
return actions.listAllSales(apolloClient, wildToken);
|
54
|
+
},
|
55
|
+
listAllBuyNowListings: () => {
|
56
|
+
logger.debug(`Get all buy now listings`);
|
57
|
+
return actions.listAllBuyNowListings(apolloClient, wildToken);
|
58
|
+
},
|
59
|
+
};
|
60
|
+
|
61
|
+
return subgraphClient;
|
62
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { ApolloClient, DocumentNode } from "@apollo/client/core";
|
2
|
+
import {
|
3
|
+
ListAllSalesQueryOptions,
|
4
|
+
ListSalesQueryOptions,
|
5
|
+
TokenSalesDto,
|
6
|
+
} from "../types";
|
7
|
+
import { TokenSale } from "../../types";
|
8
|
+
|
9
|
+
export const listSales = async <T>(
|
10
|
+
apolloClient: ApolloClient<T>,
|
11
|
+
query: DocumentNode,
|
12
|
+
variables: ListSalesQueryOptions | ListAllSalesQueryOptions,
|
13
|
+
wildToken: string
|
14
|
+
): Promise<TokenSale[]> => {
|
15
|
+
const queryResult = await apolloClient.query<TokenSalesDto>({
|
16
|
+
query: query,
|
17
|
+
variables: variables,
|
18
|
+
});
|
19
|
+
|
20
|
+
if (queryResult.error) {
|
21
|
+
throw queryResult.error;
|
22
|
+
}
|
23
|
+
|
24
|
+
const sales: TokenSale[] = queryResult.data.tokenSales.map((e) => {
|
25
|
+
const sale: TokenSale = {
|
26
|
+
bidNonce: e.bidNonce,
|
27
|
+
timestamp: e.timestamp,
|
28
|
+
tokenId: e.tokenId,
|
29
|
+
contract: e.contractAddress,
|
30
|
+
saleAmount: e.amount,
|
31
|
+
seller: e.seller.id,
|
32
|
+
buyer: e.buyer.id,
|
33
|
+
paymentToken: e.paymentToken ?? wildToken,
|
34
|
+
topLevelDomainId: e.topLevelDomainId,
|
35
|
+
};
|
36
|
+
return sale;
|
37
|
+
});
|
38
|
+
return sales;
|
39
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./client";
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { gql } from "@apollo/client/core";
|
2
|
+
|
3
|
+
export const getTokenSalesForNftQuery = gql`
|
4
|
+
query TokenSales($contract: Bytes!, $tokenId: ID!) {
|
5
|
+
tokenSales(where: { tokenId: $tokenId, contractAddress: $contract }) {
|
6
|
+
id
|
7
|
+
bidNonce
|
8
|
+
tokenId
|
9
|
+
contractAddress
|
10
|
+
amount
|
11
|
+
buyer {
|
12
|
+
id
|
13
|
+
}
|
14
|
+
seller {
|
15
|
+
id
|
16
|
+
}
|
17
|
+
timestamp
|
18
|
+
paymentToken
|
19
|
+
topLevelDomainId
|
20
|
+
}
|
21
|
+
}
|
22
|
+
`;
|
23
|
+
|
24
|
+
export const getBuyNowTokenSales = gql`
|
25
|
+
query DomainTokenSolds($tokenId: String!, $contractAddress: Bytes!) {
|
26
|
+
domainTokenSolds(
|
27
|
+
where: { tokenId: $tokenId, contractAddress: $contractAddress }
|
28
|
+
) {
|
29
|
+
id
|
30
|
+
buyer {
|
31
|
+
id
|
32
|
+
}
|
33
|
+
seller {
|
34
|
+
id
|
35
|
+
}
|
36
|
+
amount
|
37
|
+
tokenId
|
38
|
+
contractAddress
|
39
|
+
timestamp
|
40
|
+
paymentToken
|
41
|
+
topLevelDomainId
|
42
|
+
}
|
43
|
+
}
|
44
|
+
`;
|
45
|
+
|
46
|
+
export const getBuyNowTokenListings = gql`
|
47
|
+
query BuyNowListings($count: Int!, $skipCount: Int!) {
|
48
|
+
buyNowListings(first: $count, skip: $skipCount) {
|
49
|
+
id
|
50
|
+
amount
|
51
|
+
paymentToken
|
52
|
+
}
|
53
|
+
}
|
54
|
+
`;
|
55
|
+
|
56
|
+
export const getAllTokenSales = gql`
|
57
|
+
query TokenSales($count: Int!, $skipCount: Int!) {
|
58
|
+
tokenSales(first: $count, skip: $skipCount) {
|
59
|
+
id
|
60
|
+
bidNonce
|
61
|
+
tokenId
|
62
|
+
contractAddress
|
63
|
+
amount
|
64
|
+
buyer {
|
65
|
+
id
|
66
|
+
}
|
67
|
+
seller {
|
68
|
+
id
|
69
|
+
}
|
70
|
+
timestamp
|
71
|
+
paymentToken
|
72
|
+
topLevelDomainId
|
73
|
+
}
|
74
|
+
}
|
75
|
+
`;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
export interface AccountDto {
|
2
|
+
id: string;
|
3
|
+
}
|
4
|
+
|
5
|
+
export interface BuyNowListingDto {
|
6
|
+
id: string; // Will be the tokenId
|
7
|
+
amount: string;
|
8
|
+
paymentToken: string;
|
9
|
+
}
|
10
|
+
|
11
|
+
export interface TokenBuyNowListingsDto {
|
12
|
+
buyNowListings: BuyNowListingDto[];
|
13
|
+
}
|
14
|
+
|
15
|
+
export interface TokenSaleDto {
|
16
|
+
id: string;
|
17
|
+
bidNonce: string;
|
18
|
+
tokenId: string;
|
19
|
+
contractAddress: string;
|
20
|
+
amount: string;
|
21
|
+
buyer: AccountDto;
|
22
|
+
seller: AccountDto;
|
23
|
+
timestamp: string;
|
24
|
+
paymentToken?: string;
|
25
|
+
topLevelDomainId: string;
|
26
|
+
}
|
27
|
+
|
28
|
+
export interface TokenSalesDto {
|
29
|
+
tokenSales: TokenSaleDto[];
|
30
|
+
}
|
31
|
+
|
32
|
+
export interface TokenBuyNowSaleDto {
|
33
|
+
id: string;
|
34
|
+
buyer: AccountDto;
|
35
|
+
seller: AccountDto;
|
36
|
+
amount: string;
|
37
|
+
tokenId: string;
|
38
|
+
contractAddress: string;
|
39
|
+
timestamp: string;
|
40
|
+
paymentToken?: string;
|
41
|
+
topLevelDomainId: string;
|
42
|
+
}
|
43
|
+
|
44
|
+
export interface TokenBuyNowSalesDto {
|
45
|
+
domainTokenSolds: TokenBuyNowSaleDto[];
|
46
|
+
}
|
47
|
+
|
48
|
+
export interface ListAllSalesQueryOptions {
|
49
|
+
count: number;
|
50
|
+
skipCount: number;
|
51
|
+
}
|
52
|
+
|
53
|
+
export type ListAllBuyNowListingsQueryOptions = ListAllSalesQueryOptions;
|
54
|
+
|
55
|
+
export interface ListSalesQueryOptions {
|
56
|
+
contract: string;
|
57
|
+
tokenId: string;
|
58
|
+
}
|
package/src/types.ts
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
import { Bid } from "./api/types";
|
3
|
+
import { Maybe } from "./utilities";
|
4
|
+
export { Bid };
|
5
|
+
|
6
|
+
export interface Config {
|
7
|
+
apiUri: string;
|
8
|
+
subgraphUri: string;
|
9
|
+
zAuctionAddress: string;
|
10
|
+
zAuctionLegacyAddress: string;
|
11
|
+
wildTokenAddress: string;
|
12
|
+
znsHubAddress: string;
|
13
|
+
web3Provider: ethers.providers.Web3Provider;
|
14
|
+
}
|
15
|
+
|
16
|
+
export interface Instance {
|
17
|
+
listSales: (tokenId: string) => Promise<TokenSale[]>;
|
18
|
+
listAllSales: () => Promise<TokenSaleCollection>;
|
19
|
+
listAllBuyNowListings: () => Promise<TokenBuyNowListingCollection>;
|
20
|
+
listBuyNowSales: (tokenId: string) => Promise<TokenBuy[]>;
|
21
|
+
listBids: (
|
22
|
+
tokenIds: string[],
|
23
|
+
filter?: TokenBidFilter
|
24
|
+
) => Promise<TokenBidCollection>;
|
25
|
+
listBidsByAccount: (account: string) => Promise<Bid[]>;
|
26
|
+
placeBid: (
|
27
|
+
params: NewBidParameters,
|
28
|
+
signer: ethers.Signer,
|
29
|
+
statusCallback?: PlaceBidStatusCallback
|
30
|
+
) => Promise<void>;
|
31
|
+
isZAuctionApprovedToTransferNftByBid: (
|
32
|
+
account: string,
|
33
|
+
bid: Bid
|
34
|
+
) => Promise<boolean>;
|
35
|
+
isZAuctionApprovedToTransferNftByDomain: (
|
36
|
+
account: string,
|
37
|
+
tokenId: string
|
38
|
+
) => Promise<boolean>;
|
39
|
+
isZAuctionLegacyApprovedToTransferNft: (
|
40
|
+
account: string,
|
41
|
+
tokenId: string
|
42
|
+
) => Promise<boolean>;
|
43
|
+
getZAuctionSpendAllowanceByBid: (
|
44
|
+
account: string,
|
45
|
+
bid: Bid
|
46
|
+
) => Promise<ethers.BigNumber>;
|
47
|
+
getZAuctionSpendAllowanceByDomain: (
|
48
|
+
account: string,
|
49
|
+
tokenId: string
|
50
|
+
) => Promise<ethers.BigNumber>;
|
51
|
+
getZAuctionSpendAllowance: (
|
52
|
+
account: string,
|
53
|
+
paymentTokenAddress: string
|
54
|
+
) => Promise<ethers.BigNumber>;
|
55
|
+
getZAuctionLegacySpendAllowance: (
|
56
|
+
account: string
|
57
|
+
) => Promise<ethers.BigNumber>;
|
58
|
+
setNetworkPaymentToken: (
|
59
|
+
networkId: string,
|
60
|
+
domainNetworkToken: string,
|
61
|
+
signer: ethers.Signer
|
62
|
+
) => Promise<ethers.ContractTransaction>;
|
63
|
+
getPaymentTokenForDomain: (domainTokenId: string) => Promise<string>;
|
64
|
+
approveZAuctionSpendPaymentTokenByBid: (
|
65
|
+
bid: Bid,
|
66
|
+
signer: ethers.Signer
|
67
|
+
) => Promise<ethers.ContractTransaction>;
|
68
|
+
approveZAuctionSpendPaymentTokenByDomain: (
|
69
|
+
tokenId: string,
|
70
|
+
signer: ethers.Signer
|
71
|
+
) => Promise<ethers.ContractTransaction>;
|
72
|
+
approveZAuctionSpendPaymentToken: (
|
73
|
+
paymentTokenAddress: string,
|
74
|
+
signer: ethers.Signer
|
75
|
+
) => Promise<ethers.ContractTransaction>;
|
76
|
+
approveZAuctionTransferNftByBid: (
|
77
|
+
bid: Bid,
|
78
|
+
signer: ethers.Signer
|
79
|
+
) => Promise<ethers.ContractTransaction>;
|
80
|
+
approveZAuctionTransferNftByDomain: (
|
81
|
+
tokenId: string,
|
82
|
+
signer: ethers.Signer
|
83
|
+
) => Promise<ethers.ContractTransaction>;
|
84
|
+
acceptBid: (
|
85
|
+
bid: Bid,
|
86
|
+
signer: ethers.Signer
|
87
|
+
) => Promise<ethers.ContractTransaction>;
|
88
|
+
cancelBid: (
|
89
|
+
bid: Bid,
|
90
|
+
cancelOnChain: boolean,
|
91
|
+
signer: ethers.Signer
|
92
|
+
) => Promise<ethers.ContractTransaction | void>;
|
93
|
+
buyNow: (
|
94
|
+
params: BuyNowParams,
|
95
|
+
signer: ethers.Signer
|
96
|
+
) => Promise<ethers.ContractTransaction>;
|
97
|
+
getBuyNowListing: (tokenId: string) => Promise<Maybe<BuyNowListing>>;
|
98
|
+
setBuyNowPrice: (
|
99
|
+
params: BuyNowParams,
|
100
|
+
signer: ethers.Signer
|
101
|
+
) => Promise<ethers.ContractTransaction>;
|
102
|
+
cancelBuyNow: (
|
103
|
+
tokenId: string,
|
104
|
+
signer: ethers.Signer
|
105
|
+
) => Promise<ethers.ContractTransaction>;
|
106
|
+
}
|
107
|
+
|
108
|
+
export interface TokenSale {
|
109
|
+
contract: string;
|
110
|
+
bidNonce: string;
|
111
|
+
tokenId: string;
|
112
|
+
saleAmount: string;
|
113
|
+
buyer: string;
|
114
|
+
seller: string;
|
115
|
+
timestamp: string;
|
116
|
+
paymentToken: string;
|
117
|
+
topLevelDomainId: string;
|
118
|
+
}
|
119
|
+
|
120
|
+
export interface TokenBuy {
|
121
|
+
buyer: string;
|
122
|
+
seller: string;
|
123
|
+
amount: string;
|
124
|
+
contract: string;
|
125
|
+
tokenId: string;
|
126
|
+
timestamp: string;
|
127
|
+
paymentToken: string;
|
128
|
+
topLevelDomainId: string;
|
129
|
+
}
|
130
|
+
|
131
|
+
export interface TokenBuyNowListing {
|
132
|
+
tokenId: string;
|
133
|
+
amount: string;
|
134
|
+
paymentToken: string;
|
135
|
+
}
|
136
|
+
|
137
|
+
export interface TokenBuyNowListingCollection {
|
138
|
+
[tokenId: string]: TokenBuyNowListing[];
|
139
|
+
}
|
140
|
+
|
141
|
+
export interface TokenSaleCollection {
|
142
|
+
[tokenId: string]: TokenSale[];
|
143
|
+
}
|
144
|
+
|
145
|
+
export interface TokenBidCollection {
|
146
|
+
[tokenId: string]: Bid[];
|
147
|
+
}
|
148
|
+
|
149
|
+
export enum TokenBidFilter {
|
150
|
+
All,
|
151
|
+
Active,
|
152
|
+
Cancelled,
|
153
|
+
}
|
154
|
+
|
155
|
+
export type PlaceBidStatusCallback = (status: PlaceBidStatus) => void;
|
156
|
+
|
157
|
+
export enum PlaceBidStatus {
|
158
|
+
Encoding,
|
159
|
+
Signing,
|
160
|
+
Submitting,
|
161
|
+
Completed,
|
162
|
+
}
|
163
|
+
|
164
|
+
export interface NewBidParameters {
|
165
|
+
tokenId: string;
|
166
|
+
bidAmount: string; // in wei
|
167
|
+
startBlock?: string;
|
168
|
+
expireBlock?: string;
|
169
|
+
}
|
170
|
+
|
171
|
+
export interface BuyNowParams {
|
172
|
+
amount: string;
|
173
|
+
tokenId: string;
|
174
|
+
paymentToken: string;
|
175
|
+
}
|
176
|
+
|
177
|
+
export interface BuyNowListing {
|
178
|
+
price: ethers.BigNumber;
|
179
|
+
holder: string;
|
180
|
+
paymentToken: string;
|
181
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { Consola, LogLevel } from "consola";
|
2
|
+
|
3
|
+
// For details on logging levels
|
4
|
+
// https://github.com/unjs/consola/blob/master/types/consola.d.ts
|
5
|
+
const logger = new Consola({ level: LogLevel.Info });
|
6
|
+
|
7
|
+
export const getLogger = (tag?: string): Consola => {
|
8
|
+
if (tag) {
|
9
|
+
return logger.withTag(tag);
|
10
|
+
}
|
11
|
+
return logger;
|
12
|
+
};
|
13
|
+
|
14
|
+
export const setLogLevel = (level?: LogLevel): void => {
|
15
|
+
if (!level || typeof level != "number") {
|
16
|
+
console.log("Provide a number");
|
17
|
+
Object.entries(LogLevel).forEach(([key, value]) => {
|
18
|
+
console.log(`${key}=${value}`);
|
19
|
+
});
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
logger.level = level;
|
24
|
+
};
|
25
|
+
|
26
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
27
|
+
(global as any).setZAuctionSDKLogLevel = setLogLevel;
|