@zoralabs/coins-sdk 0.0.2-sdkalpha.7 → 0.0.2
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/CHANGELOG.md +12 -0
- package/README.md +834 -410
- package/dist/actions/createCoin.d.ts +4 -3
- package/dist/actions/createCoin.d.ts.map +1 -1
- package/dist/actions/tradeCoin.d.ts +5 -4
- package/dist/actions/tradeCoin.d.ts.map +1 -1
- package/dist/actions/updateCoinURI.d.ts +4 -3
- package/dist/actions/updateCoinURI.d.ts.map +1 -1
- package/dist/actions/updatePayoutRecipient.d.ts +4 -3
- package/dist/actions/updatePayoutRecipient.d.ts.map +1 -1
- package/dist/api/explore.d.ts +15 -336
- package/dist/api/explore.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/queries.d.ts +100 -223
- package/dist/api/queries.d.ts.map +1 -1
- package/dist/api/query-types.d.ts +3 -0
- package/dist/api/query-types.d.ts.map +1 -0
- package/dist/index.cjs +160 -160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/actions/createCoin.ts +2 -2
- package/src/actions/tradeCoin.ts +3 -4
- package/src/actions/updateCoinURI.ts +2 -2
- package/src/actions/updatePayoutRecipient.ts +2 -2
- package/src/api/explore.ts +46 -28
- package/src/api/index.ts +2 -0
- package/src/api/queries.ts +55 -8
- package/src/api/query-types.ts +8 -0
- package/src/index.ts +4 -3
- package/dist/utils/retries.d.ts +0 -7
- package/dist/utils/retries.d.ts.map +0 -1
- package/src/utils/retries.ts +0 -49
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { zoraFactoryImplABI } from "@zoralabs/coins";
|
|
2
2
|
import {
|
|
3
3
|
Address,
|
|
4
|
-
PublicClient,
|
|
5
4
|
TransactionReceipt,
|
|
6
5
|
WalletClient,
|
|
7
6
|
SimulateContractParameters,
|
|
@@ -10,6 +9,7 @@ import {
|
|
|
10
9
|
} from "viem";
|
|
11
10
|
import { COIN_FACTORY_ADDRESS } from "../constants";
|
|
12
11
|
import { validateClientNetwork } from "../utils/validateClientNetwork";
|
|
12
|
+
import { GenericPublicClient } from "src/utils/genericPublicClient";
|
|
13
13
|
|
|
14
14
|
export type CoinDeploymentLogArgs = ContractEventArgsFromTopics<
|
|
15
15
|
typeof zoraFactoryImplABI,
|
|
@@ -83,7 +83,7 @@ export function getCoinCreateFromLogs(
|
|
|
83
83
|
export async function createCoin(
|
|
84
84
|
call: CreateCoinArgs,
|
|
85
85
|
walletClient: WalletClient,
|
|
86
|
-
publicClient:
|
|
86
|
+
publicClient: GenericPublicClient,
|
|
87
87
|
options?: {
|
|
88
88
|
gasMultiplier?: number;
|
|
89
89
|
},
|
package/src/actions/tradeCoin.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { coinABI } from "@zoralabs/coins";
|
|
|
2
2
|
import { validateClientNetwork } from "../utils/validateClientNetwork";
|
|
3
3
|
import {
|
|
4
4
|
Address,
|
|
5
|
-
PublicClient,
|
|
6
5
|
TransactionReceipt,
|
|
7
6
|
WalletClient,
|
|
8
7
|
SimulateContractParameters,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
parseEventLogs,
|
|
13
12
|
} from "viem";
|
|
14
13
|
import { baseSepolia } from "viem/chains";
|
|
15
|
-
|
|
14
|
+
import { GenericPublicClient } from "src/utils/genericPublicClient";
|
|
16
15
|
// Define trade event args type
|
|
17
16
|
|
|
18
17
|
export type SellEventArgs = ContractEventArgsFromTopics<
|
|
@@ -41,7 +40,7 @@ export async function simulateBuy({
|
|
|
41
40
|
}: {
|
|
42
41
|
target: Address;
|
|
43
42
|
requestedOrderSize: bigint;
|
|
44
|
-
publicClient:
|
|
43
|
+
publicClient: GenericPublicClient;
|
|
45
44
|
}): Promise<{ orderSize: bigint; amountOut: bigint }> {
|
|
46
45
|
const numberResult = await publicClient.simulateContract({
|
|
47
46
|
address: target,
|
|
@@ -157,7 +156,7 @@ export function getTradeFromLogs(
|
|
|
157
156
|
export async function tradeCoin(
|
|
158
157
|
params: TradeParams,
|
|
159
158
|
walletClient: WalletClient,
|
|
160
|
-
publicClient:
|
|
159
|
+
publicClient: GenericPublicClient,
|
|
161
160
|
) {
|
|
162
161
|
validateClientNetwork(publicClient);
|
|
163
162
|
const { request } = await publicClient.simulateContract({
|
|
@@ -3,10 +3,10 @@ import { validateClientNetwork } from "../utils/validateClientNetwork";
|
|
|
3
3
|
import {
|
|
4
4
|
Address,
|
|
5
5
|
parseEventLogs,
|
|
6
|
-
PublicClient,
|
|
7
6
|
SimulateContractParameters,
|
|
8
7
|
WalletClient,
|
|
9
8
|
} from "viem";
|
|
9
|
+
import { GenericPublicClient } from "src/utils/genericPublicClient";
|
|
10
10
|
|
|
11
11
|
export type UpdateCoinURIArgs = {
|
|
12
12
|
coin: Address;
|
|
@@ -32,7 +32,7 @@ export function updateCoinURICall({
|
|
|
32
32
|
export async function updateCoinURI(
|
|
33
33
|
args: UpdateCoinURIArgs,
|
|
34
34
|
walletClient: WalletClient,
|
|
35
|
-
publicClient:
|
|
35
|
+
publicClient: GenericPublicClient,
|
|
36
36
|
) {
|
|
37
37
|
validateClientNetwork(publicClient);
|
|
38
38
|
const call = updateCoinURICall(args);
|
|
@@ -3,10 +3,10 @@ import { validateClientNetwork } from "../utils/validateClientNetwork";
|
|
|
3
3
|
import {
|
|
4
4
|
Address,
|
|
5
5
|
parseEventLogs,
|
|
6
|
-
PublicClient,
|
|
7
6
|
SimulateContractParameters,
|
|
8
7
|
WalletClient,
|
|
9
8
|
} from "viem";
|
|
9
|
+
import { GenericPublicClient } from "src/utils/genericPublicClient";
|
|
10
10
|
|
|
11
11
|
export type UpdatePayoutRecipientArgs = {
|
|
12
12
|
coin: Address;
|
|
@@ -28,7 +28,7 @@ export function updatePayoutRecipientCall({
|
|
|
28
28
|
export async function updatePayoutRecipient(
|
|
29
29
|
args: UpdatePayoutRecipientArgs,
|
|
30
30
|
walletClient: WalletClient,
|
|
31
|
-
publicClient:
|
|
31
|
+
publicClient: GenericPublicClient,
|
|
32
32
|
) {
|
|
33
33
|
validateClientNetwork(publicClient);
|
|
34
34
|
const call = updatePayoutRecipientCall(args);
|
package/src/api/explore.ts
CHANGED
|
@@ -1,55 +1,73 @@
|
|
|
1
1
|
import { getExplore as getExploreSDK } from "../client/sdk.gen";
|
|
2
|
-
import type { GetExploreData } from "../client/types.gen";
|
|
3
|
-
import { Options } from "@hey-api/client-fetch";
|
|
2
|
+
import type { GetExploreData, GetExploreResponse } from "../client/types.gen";
|
|
4
3
|
import { getApiKeyMeta } from "./api-key";
|
|
4
|
+
import { RequestOptionsType } from "./query-types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The inner type for the explore queries that omits listType.
|
|
8
8
|
* This is used to create the query object for the explore queries.
|
|
9
9
|
*/
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export type QueryRequestType = Omit<GetExploreData["query"], "listType">;
|
|
11
|
+
|
|
12
|
+
type ExploreResponse = { data?: GetExploreResponse };
|
|
13
|
+
|
|
14
|
+
export type ListType = GetExploreData["query"]["listType"];
|
|
15
|
+
|
|
16
|
+
export type { ExploreResponse };
|
|
17
|
+
|
|
18
|
+
export type { GetExploreData };
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* Creates an explore query with the specified list type
|
|
16
22
|
*/
|
|
17
|
-
const createExploreQuery =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
const createExploreQuery = (
|
|
24
|
+
query: QueryRequestType,
|
|
25
|
+
listType: ListType,
|
|
26
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
27
|
+
): Promise<ExploreResponse> =>
|
|
21
28
|
getExploreSDK({
|
|
22
29
|
...options,
|
|
23
|
-
query: { ...
|
|
30
|
+
query: { ...query, listType },
|
|
24
31
|
meta: getApiKeyMeta(),
|
|
25
32
|
});
|
|
26
33
|
|
|
27
34
|
/** Get top gaining coins */
|
|
28
|
-
export const getCoinsTopGainers =
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
export const getCoinsTopGainers = (
|
|
36
|
+
query: QueryRequestType = {},
|
|
37
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
38
|
+
): Promise<ExploreResponse> =>
|
|
39
|
+
createExploreQuery(query, "TOP_GAINERS", options);
|
|
31
40
|
|
|
32
41
|
/** Get coins with highest 24h volume */
|
|
33
|
-
export const getCoinsTopVolume24h =
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
export const getCoinsTopVolume24h = (
|
|
43
|
+
query: QueryRequestType = {},
|
|
44
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
45
|
+
): Promise<ExploreResponse> =>
|
|
46
|
+
createExploreQuery(query, "TOP_VOLUME_24H", options);
|
|
36
47
|
|
|
37
48
|
/** Get most valuable coins */
|
|
38
|
-
export const getCoinsMostValuable =
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
export const getCoinsMostValuable = (
|
|
50
|
+
query: QueryRequestType = {},
|
|
51
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
52
|
+
): Promise<ExploreResponse> =>
|
|
53
|
+
createExploreQuery(query, "MOST_VALUABLE", options);
|
|
41
54
|
|
|
42
55
|
/** Get newly created coins */
|
|
43
|
-
export const getCoinsNew =
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
export const getCoinsNew = (
|
|
57
|
+
query: QueryRequestType = {},
|
|
58
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
59
|
+
): Promise<ExploreResponse> => createExploreQuery(query, "NEW", options);
|
|
46
60
|
|
|
47
61
|
/** Get recently traded coins */
|
|
48
|
-
export const getCoinsLastTraded =
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
export const getCoinsLastTraded = (
|
|
63
|
+
query: QueryRequestType = {},
|
|
64
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
65
|
+
): Promise<ExploreResponse> =>
|
|
66
|
+
createExploreQuery(query, "LAST_TRADED", options);
|
|
51
67
|
|
|
52
68
|
/** Get recently traded unique coins */
|
|
53
|
-
export const getCoinsLastTradedUnique =
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
export const getCoinsLastTradedUnique = (
|
|
70
|
+
query: QueryRequestType = {},
|
|
71
|
+
options?: RequestOptionsType<GetExploreData>,
|
|
72
|
+
): Promise<ExploreResponse> =>
|
|
73
|
+
createExploreQuery(query, "LAST_TRADED_UNIQUE", options);
|
package/src/api/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Export all of the explore queries
|
|
2
2
|
export * from "./explore";
|
|
3
|
+
export type * from "./explore";
|
|
3
4
|
// Export all of the queries
|
|
4
5
|
export * from "./queries";
|
|
6
|
+
export type * from "./queries";
|
|
5
7
|
|
|
6
8
|
// Only export the set function for external use.
|
|
7
9
|
// All other exports are for internal use.
|
package/src/api/queries.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GetCoinCommentsData,
|
|
3
|
+
GetCoinCommentsResponse,
|
|
3
4
|
GetCoinData,
|
|
5
|
+
GetCoinResponse,
|
|
6
|
+
GetCoinsData,
|
|
7
|
+
GetCoinsResponse,
|
|
4
8
|
GetProfileBalancesData,
|
|
5
9
|
GetProfileData,
|
|
10
|
+
GetProfileResponse,
|
|
6
11
|
} from "../client/types.gen";
|
|
7
12
|
import {
|
|
8
13
|
getCoin as getCoinSDK,
|
|
@@ -12,21 +17,40 @@ import {
|
|
|
12
17
|
getProfileBalances as getProfileBalancesSDK,
|
|
13
18
|
} from "../client/sdk.gen";
|
|
14
19
|
import { getApiKeyMeta } from "./api-key";
|
|
20
|
+
import { RequestOptionsType } from "./query-types";
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
type APIQueryDataResponse<T> = Promise<{ data?: T }>;
|
|
23
|
+
|
|
24
|
+
export type { APIQueryDataResponse };
|
|
25
|
+
|
|
26
|
+
type GetCoinQuery = GetCoinData["query"];
|
|
27
|
+
export type { GetCoinQuery, GetCoinData };
|
|
28
|
+
export type { GetCoinResponse } from "../client/types.gen";
|
|
29
|
+
|
|
30
|
+
export type CoinData = NonNullable<GetCoinResponse["zora20Token"]>;
|
|
31
|
+
|
|
32
|
+
export const getCoin = async (
|
|
33
|
+
query: GetCoinQuery,
|
|
34
|
+
options?: RequestOptionsType<GetCoinData>,
|
|
35
|
+
): Promise<{ data?: GetCoinResponse }> => {
|
|
17
36
|
return await getCoinSDK({
|
|
37
|
+
...options,
|
|
18
38
|
query,
|
|
19
39
|
meta: getApiKeyMeta(),
|
|
20
40
|
});
|
|
21
41
|
};
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
coinAddresses,
|
|
25
|
-
chainId,
|
|
26
|
-
}: {
|
|
43
|
+
type GetCoinsQuery = {
|
|
27
44
|
coinAddresses: string[];
|
|
28
45
|
chainId?: number;
|
|
29
|
-
}
|
|
46
|
+
};
|
|
47
|
+
export type { GetCoinsQuery, GetCoinsData };
|
|
48
|
+
export type { GetCoinsResponse } from "../client/types.gen";
|
|
49
|
+
|
|
50
|
+
export const getCoins = async (
|
|
51
|
+
{ coinAddresses, chainId }: GetCoinsQuery,
|
|
52
|
+
options?: RequestOptionsType<GetCoinsData>,
|
|
53
|
+
): APIQueryDataResponse<GetCoinsResponse> => {
|
|
30
54
|
return await getCoinsSDK({
|
|
31
55
|
query: {
|
|
32
56
|
coins: coinAddresses.map((collectionAddress) => ({
|
|
@@ -35,28 +59,51 @@ export const getCoins = async ({
|
|
|
35
59
|
})),
|
|
36
60
|
},
|
|
37
61
|
meta: getApiKeyMeta(),
|
|
62
|
+
...options,
|
|
38
63
|
});
|
|
39
64
|
};
|
|
40
65
|
|
|
41
|
-
|
|
66
|
+
type GetCoinCommentsQuery = GetCoinCommentsData["query"];
|
|
67
|
+
export type { GetCoinCommentsQuery, GetCoinCommentsData };
|
|
68
|
+
export type { GetCoinCommentsResponse } from "../client/types.gen";
|
|
69
|
+
|
|
70
|
+
export const getCoinComments = async (
|
|
71
|
+
query: GetCoinCommentsQuery,
|
|
72
|
+
options?: RequestOptionsType<GetCoinCommentsData>,
|
|
73
|
+
): APIQueryDataResponse<GetCoinCommentsResponse> => {
|
|
42
74
|
return await getCoinCommentsSDK({
|
|
43
75
|
query,
|
|
44
76
|
meta: getApiKeyMeta(),
|
|
77
|
+
...options,
|
|
45
78
|
});
|
|
46
79
|
};
|
|
47
80
|
|
|
48
|
-
|
|
81
|
+
type GetProfileQuery = GetProfileData["query"];
|
|
82
|
+
export type { GetProfileQuery, GetProfileData };
|
|
83
|
+
export type { GetProfileResponse } from "../client/types.gen";
|
|
84
|
+
|
|
85
|
+
export const getProfile = async (
|
|
86
|
+
query: GetProfileQuery,
|
|
87
|
+
options?: RequestOptionsType<GetProfileData>,
|
|
88
|
+
): APIQueryDataResponse<GetProfileResponse> => {
|
|
49
89
|
return await getProfileSDK({
|
|
50
90
|
query,
|
|
51
91
|
meta: getApiKeyMeta(),
|
|
92
|
+
...options,
|
|
52
93
|
});
|
|
53
94
|
};
|
|
54
95
|
|
|
96
|
+
type GetProfileBalancesQuery = GetProfileBalancesData["query"];
|
|
97
|
+
export type { GetProfileBalancesQuery, GetProfileBalancesData };
|
|
98
|
+
export type { GetProfileBalancesResponse } from "../client/types.gen";
|
|
99
|
+
|
|
55
100
|
export const getProfileBalances = async (
|
|
56
101
|
query: GetProfileBalancesData["query"],
|
|
102
|
+
options?: RequestOptionsType<GetProfileBalancesData>,
|
|
57
103
|
) => {
|
|
58
104
|
return await getProfileBalancesSDK({
|
|
59
105
|
query,
|
|
60
106
|
meta: getApiKeyMeta(),
|
|
107
|
+
...options,
|
|
61
108
|
});
|
|
62
109
|
};
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export {
|
|
|
6
6
|
export type { CreateCoinArgs } from "./actions/createCoin";
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
|
+
simulateBuy,
|
|
9
10
|
tradeCoin,
|
|
10
11
|
tradeCoinCall,
|
|
11
12
|
getTradeFromLogs,
|
|
@@ -27,13 +28,13 @@ export type { UpdatePayoutRecipientArgs } from "./actions/updatePayoutRecipient"
|
|
|
27
28
|
|
|
28
29
|
// API Read Actions
|
|
29
30
|
export * from "./api/queries";
|
|
31
|
+
export type * from "./api/queries";
|
|
32
|
+
|
|
30
33
|
export * from "./api/explore";
|
|
34
|
+
export type * from "./api/explore";
|
|
31
35
|
|
|
32
36
|
// API Key Setter
|
|
33
37
|
export { setApiKey } from "./api/api-key";
|
|
34
38
|
|
|
35
39
|
// Metadata Validation Utils
|
|
36
40
|
export * from "./metadata";
|
|
37
|
-
|
|
38
|
-
// API Types
|
|
39
|
-
export type * from "./client/types.gen";
|
package/dist/utils/retries.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retries.d.ts","sourceRoot":"","sources":["../../src/utils/retries.ts"],"names":[],"mappings":"AAsCA,eAAO,MAAM,cAAc,GAAU,CAAC,UAAU;IAC9C,KAAK,EAAE,MAAM,CAAC,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;CAC5C,eAKA,CAAC"}
|
package/src/utils/retries.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
async function wait(delayMs: number) {
|
|
2
|
-
return new Promise((resolve) => {
|
|
3
|
-
setTimeout(resolve, delayMs);
|
|
4
|
-
});
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const retryInternal = async <T>({
|
|
8
|
-
tryFn,
|
|
9
|
-
maxTries = 3,
|
|
10
|
-
atTry,
|
|
11
|
-
linearBackoffMS = 200,
|
|
12
|
-
shouldRetryOnError = () => true,
|
|
13
|
-
}: {
|
|
14
|
-
tryFn: () => T;
|
|
15
|
-
maxTries?: number;
|
|
16
|
-
atTry: number;
|
|
17
|
-
linearBackoffMS?: number;
|
|
18
|
-
shouldRetryOnError?: (err: any) => boolean;
|
|
19
|
-
}): Promise<T> => {
|
|
20
|
-
try {
|
|
21
|
-
return await tryFn();
|
|
22
|
-
} catch (err: any) {
|
|
23
|
-
if (shouldRetryOnError(err)) {
|
|
24
|
-
if (atTry <= maxTries) {
|
|
25
|
-
await wait(atTry * linearBackoffMS);
|
|
26
|
-
return await retryInternal({
|
|
27
|
-
tryFn,
|
|
28
|
-
maxTries,
|
|
29
|
-
atTry: atTry + 1,
|
|
30
|
-
linearBackoffMS,
|
|
31
|
-
shouldRetryOnError,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
throw err;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const retriesGeneric = async <T>(params: {
|
|
40
|
-
tryFn: () => T;
|
|
41
|
-
maxTries?: number;
|
|
42
|
-
linearBackoffMS?: number;
|
|
43
|
-
shouldRetryOnError?: (err: any) => boolean;
|
|
44
|
-
}) => {
|
|
45
|
-
return retryInternal({
|
|
46
|
-
...params,
|
|
47
|
-
atTry: 1,
|
|
48
|
-
});
|
|
49
|
-
};
|