Skip to content

Commit 9b1a781

Browse files
authored
Claim Condition End-points (#358)
* Added ERC721 ClaimConditions Read End-points * Added all claim-conditions end-points * updated cron logic to not run multiple servers and avoid connection pool issues * Added Prisma INFO level logging to get connection_pool details * updated all claim end-points after testing * updated setBatch conditions * Added Erc20 & Erc1155 routes to index files * updates
1 parent 3f8d9bb commit 9b1a781

31 files changed

+2015
-23
lines changed

src/db/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import pg, { Knex } from "knex";
33
import { PrismaTransaction } from "../schema/prisma";
44
import { env } from "../utils/env";
55

6-
export const prisma = new PrismaClient();
6+
export const prisma = new PrismaClient({
7+
log: ["info"],
8+
});
79

810
export const getPrismaWithPostgresTx = (pgtx?: PrismaTransaction) => {
911
return pgtx || prisma;

src/server/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ const main = async () => {
7070
},
7171
);
7272

73+
logger({
74+
service: "server",
75+
level: "info",
76+
message: `Listening on ${env.ENABLE_HTTPS ? "https://" : "http://"}${
77+
env.HOST
78+
}:${env.PORT}`,
79+
});
80+
7381
writeOpenApiToFile(server);
7482
};
7583

src/server/routes/contract/extensions/erc1155/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { FastifyInstance } from "fastify";
2+
import { erc1155BalanceOf } from "./read/balanceOf";
3+
import { erc1155CanClaim } from "./read/canClaim";
24
import { erc1155Get } from "./read/get";
5+
import { erc1155GetActiveClaimConditions } from "./read/getActiveClaimConditions";
36
import { erc1155GetAll } from "./read/getAll";
4-
import { erc1155BalanceOf } from "./read/balanceOf";
5-
import { erc1155IsApproved } from "./read/isApproved";
7+
import { erc1155GetAllClaimConditions } from "./read/getAllClaimConditions";
8+
import { erc1155GetClaimIneligibilityReasons } from "./read/getClaimIneligibilityReasons";
9+
import { erc1155GetClaimerProofs } from "./read/getClaimerProofs";
610
import { erc1155GetOwned } from "./read/getOwned";
7-
import { erc1155TotalSupply } from "./read/totalSupply";
11+
import { erc1155IsApproved } from "./read/isApproved";
12+
import { erc1155SignatureGenerate } from "./read/signatureGenerate";
813
import { erc1155TotalCount } from "./read/totalCount";
14+
import { erc1155TotalSupply } from "./read/totalSupply";
915
import { erc1155airdrop } from "./write/airdrop";
1016
import { erc1155burn } from "./write/burn";
1117
import { erc1155burnBatch } from "./write/burnBatch";
@@ -15,10 +21,12 @@ import { erc1155mintAdditionalSupplyTo } from "./write/mintAdditionalSupplyTo";
1521
import { erc1155mintBatchTo } from "./write/mintBatchTo";
1622
import { erc1155mintTo } from "./write/mintTo";
1723
import { erc1155SetApprovalForAll } from "./write/setApprovalForAll";
24+
import { erc1155SetBatchClaimConditions } from "./write/setBatchClaimConditions";
25+
import { erc1155SetClaimCondition } from "./write/setClaimConditions";
26+
import { erc1155SignatureMint } from "./write/signatureMint";
1827
import { erc1155transfer } from "./write/transfer";
1928
import { erc1155transferFrom } from "./write/transferFrom";
20-
import { erc1155SignatureGenerate } from "./read/signatureGenerate";
21-
import { erc1155SignatureMint } from "./write/signatureMint";
29+
import { erc1155UpdateClaimConditions } from "./write/updateClaimConditions";
2230

2331
export const erc1155Routes = async (fastify: FastifyInstance) => {
2432
// GET
@@ -30,6 +38,11 @@ export const erc1155Routes = async (fastify: FastifyInstance) => {
3038
await fastify.register(erc1155TotalCount);
3139
await fastify.register(erc1155TotalSupply);
3240
await fastify.register(erc1155SignatureGenerate);
41+
await fastify.register(erc1155CanClaim);
42+
await fastify.register(erc1155GetActiveClaimConditions);
43+
await fastify.register(erc1155GetAllClaimConditions);
44+
await fastify.register(erc1155GetClaimerProofs);
45+
await fastify.register(erc1155GetClaimIneligibilityReasons);
3346

3447
// POST
3548
await fastify.register(erc1155airdrop);
@@ -44,4 +57,7 @@ export const erc1155Routes = async (fastify: FastifyInstance) => {
4457
await fastify.register(erc1155transfer);
4558
await fastify.register(erc1155transferFrom);
4659
await fastify.register(erc1155SignatureMint);
60+
await fastify.register(erc1155SetClaimCondition);
61+
await fastify.register(erc1155SetBatchClaimConditions);
62+
await fastify.register(erc1155UpdateClaimConditions);
4763
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { getContract } from "../../../../../../utils/cache/getContract";
5+
import {
6+
contractParamSchema,
7+
standardResponseSchema,
8+
} from "../../../../../schemas/sharedApiSchemas";
9+
import { getChainIdFromChain } from "../../../../../utils/chain";
10+
11+
// INPUT
12+
const requestSchema = contractParamSchema;
13+
const requestQueryString = Type.Object({
14+
quantity: Type.String({
15+
description: "The amount of tokens to claim.",
16+
}),
17+
tokenId: Type.String({
18+
description: "The token ID of the NFT you want to claim.",
19+
}),
20+
addressToCheck: Type.Optional(
21+
Type.String({
22+
description:
23+
"The wallet address to check if it can claim tokens. This considers all aspects of the active claim phase, including allowlists, previous claims, etc.",
24+
examples: ["0x1946267d81Fb8aDeeEa28e6B98bcD446c8248473"],
25+
}),
26+
),
27+
});
28+
29+
// OUPUT
30+
const responseSchema = Type.Object({
31+
result: Type.Boolean(),
32+
});
33+
34+
// LOGIC
35+
export async function erc1155CanClaim(fastify: FastifyInstance) {
36+
fastify.route<{
37+
Params: Static<typeof requestSchema>;
38+
Reply: Static<typeof responseSchema>;
39+
Querystring: Static<typeof requestQueryString>;
40+
}>({
41+
method: "GET",
42+
url: "/contract/:chain/:contractAddress/erc1155/claim-conditions/can-claim",
43+
schema: {
44+
summary: "Check if tokens are available for claiming",
45+
description:
46+
"Check if tokens are currently available for claiming, optionally specifying if a specific wallet address can claim.",
47+
tags: ["ERC1155"],
48+
operationId: "canClaim",
49+
params: requestSchema,
50+
querystring: requestQueryString,
51+
response: {
52+
...standardResponseSchema,
53+
[StatusCodes.OK]: responseSchema,
54+
},
55+
},
56+
handler: async (request, reply) => {
57+
const { chain, contractAddress } = request.params;
58+
const { quantity, tokenId, addressToCheck } = request.query;
59+
60+
const chainId = await getChainIdFromChain(chain);
61+
const contract = await getContract({
62+
chainId,
63+
contractAddress,
64+
});
65+
const returnData = await contract.erc1155.claimConditions.canClaim(
66+
quantity,
67+
tokenId,
68+
addressToCheck,
69+
);
70+
reply.status(StatusCodes.OK).send({
71+
result: returnData,
72+
});
73+
},
74+
});
75+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { getContract } from "../../../../../../utils/cache/getContract";
5+
import { claimConditionOutputSchema } from "../../../../../schemas/claimConditions";
6+
import {
7+
contractParamSchema,
8+
standardResponseSchema,
9+
} from "../../../../../schemas/sharedApiSchemas";
10+
import { getChainIdFromChain } from "../../../../../utils/chain";
11+
12+
// INPUT
13+
const requestSchema = contractParamSchema;
14+
const requestQueryString = Type.Object({
15+
tokenId: Type.Union([Type.String(), Type.Number()], {
16+
description: "The token ID of the NFT you want to claim.",
17+
}),
18+
withAllowList: Type.Optional(
19+
Type.Boolean({
20+
description:
21+
"Provide a boolean value to include the allowlist in the response.",
22+
}),
23+
),
24+
});
25+
26+
// OUPUT
27+
const responseSchema = Type.Object({
28+
result: claimConditionOutputSchema,
29+
});
30+
31+
// LOGIC
32+
export async function erc1155GetActiveClaimConditions(
33+
fastify: FastifyInstance,
34+
) {
35+
fastify.route<{
36+
Params: Static<typeof requestSchema>;
37+
Reply: Static<typeof responseSchema>;
38+
Querystring: Static<typeof requestQueryString>;
39+
}>({
40+
method: "GET",
41+
url: "/contract/:chain/:contractAddress/erc1155/claim-conditions/get-active",
42+
schema: {
43+
summary: "Get currently active claim phase for a specific token ID.",
44+
description:
45+
"Retrieve the currently active claim phase for a specific token ID, if any.",
46+
tags: ["ERC1155"],
47+
operationId: "getActiveClaimConditions",
48+
params: requestSchema,
49+
querystring: requestQueryString,
50+
response: {
51+
...standardResponseSchema,
52+
[StatusCodes.OK]: responseSchema,
53+
},
54+
},
55+
handler: async (request, reply) => {
56+
const { chain, contractAddress } = request.params;
57+
const { tokenId, withAllowList } = request.query;
58+
59+
const chainId = await getChainIdFromChain(chain);
60+
const contract = await getContract({
61+
chainId,
62+
contractAddress,
63+
});
64+
const returnData = await contract.erc1155.claimConditions.getActive(
65+
tokenId,
66+
{
67+
withAllowList,
68+
},
69+
);
70+
reply.status(StatusCodes.OK).send({
71+
result: {
72+
...returnData,
73+
price: returnData.price.toString(),
74+
waitInSeconds: returnData.waitInSeconds.toString(),
75+
currencyMetadata: {
76+
...returnData.currencyMetadata,
77+
value: returnData.currencyMetadata.value.toString(),
78+
},
79+
startTime: returnData.startTime.toISOString(),
80+
},
81+
});
82+
},
83+
});
84+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { getContract } from "../../../../../../utils/cache/getContract";
5+
import { claimConditionOutputSchema } from "../../../../../schemas/claimConditions";
6+
import {
7+
contractParamSchema,
8+
standardResponseSchema,
9+
} from "../../../../../schemas/sharedApiSchemas";
10+
import { getChainIdFromChain } from "../../../../../utils/chain";
11+
12+
// INPUT
13+
const requestSchema = contractParamSchema;
14+
const requestQueryString = Type.Object({
15+
tokenId: Type.Union([Type.String(), Type.Number()], {
16+
description:
17+
"The token ID of the NFT you want to get the claim conditions for.",
18+
}),
19+
withAllowList: Type.Optional(
20+
Type.Boolean({
21+
description:
22+
"Provide a boolean value to include the allowlist in the response.",
23+
}),
24+
),
25+
});
26+
27+
// OUPUT
28+
const responseSchema = Type.Object({
29+
result: Type.Array(claimConditionOutputSchema),
30+
});
31+
32+
// LOGIC
33+
export async function erc1155GetAllClaimConditions(fastify: FastifyInstance) {
34+
fastify.route<{
35+
Params: Static<typeof requestSchema>;
36+
Reply: Static<typeof responseSchema>;
37+
Querystring: Static<typeof requestQueryString>;
38+
}>({
39+
method: "GET",
40+
url: "/contract/:chain/:contractAddress/erc1155/claim-conditions/get-all",
41+
schema: {
42+
summary: "Get all the claim phases configured for a specific token ID.",
43+
description:
44+
"Get all the claim phases configured for a specific token ID.",
45+
tags: ["ERC1155"],
46+
operationId: "getAllClaimConditions",
47+
params: requestSchema,
48+
querystring: requestQueryString,
49+
response: {
50+
...standardResponseSchema,
51+
[StatusCodes.OK]: responseSchema,
52+
},
53+
},
54+
handler: async (request, reply) => {
55+
const { chain, contractAddress } = request.params;
56+
const { tokenId, withAllowList } = request.query;
57+
58+
const chainId = await getChainIdFromChain(chain);
59+
const contract = await getContract({
60+
chainId,
61+
contractAddress,
62+
});
63+
const returnData = await contract.erc1155.claimConditions.getAll(
64+
tokenId,
65+
{
66+
withAllowList,
67+
},
68+
);
69+
70+
const sanitizedReturnData = returnData.map((item) => {
71+
return {
72+
...item,
73+
price: item.price.toString(),
74+
waitInSeconds: item.waitInSeconds.toString(),
75+
currencyMetadata: {
76+
...item.currencyMetadata,
77+
value: item.currencyMetadata.value.toString(),
78+
},
79+
startTime: item.startTime.toISOString(),
80+
};
81+
});
82+
83+
reply.status(StatusCodes.OK).send({
84+
result: sanitizedReturnData,
85+
});
86+
},
87+
});
88+
}

0 commit comments

Comments
 (0)