Skip to content

Update: SDK V5 #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
82aec69
updated to new alpha & updated balance-of
farhanW3 Feb 23, 2024
872b6a1
Merge branch 'main' into fk/sdk-unified
farhanW3 Feb 27, 2024
d988100
updated generalized contract read to use new SDK
farhanW3 Feb 27, 2024
a0516f5
update + new endpoints + caching
farhanW3 Feb 29, 2024
cf1838a
v5sdk updated to latest beta
farhanW3 Mar 1, 2024
2fc7889
Merge branch 'main' into fk/sdk-unified
farhanW3 Mar 1, 2024
d6ee10b
using extension. updated few erc1155
farhanW3 Mar 1, 2024
d5ee2d9
Merge branch 'main' into fk/sdk-unified
farhanW3 Mar 1, 2024
6ae5b90
updated totalSupply, totalCount 721/1155
farhanW3 Mar 4, 2024
888a6fe
Merge branch 'main' into fk/sdk-unified
farhanW3 Mar 5, 2024
26fdfe6
updated SDK to latest beta
farhanW3 Mar 5, 2024
14ad27e
updated end-points
farhanW3 Mar 5, 2024
1fa040e
Merge branch 'main' into fk/sdk-unified
farhanW3 Mar 7, 2024
7e2a77b
more v5 updates for reads
farhanW3 Mar 8, 2024
97d7c74
Added mnemonist/lru-cache
farhanW3 Mar 8, 2024
e51802b
Merge branch 'main' into fk/sdk-unified
farhanW3 Apr 3, 2024
4952f3d
got latest from main
farhanW3 Apr 3, 2024
ad281a3
Merge branch 'main' into fk/sdk-unified
farhanW3 Apr 8, 2024
3c579e6
thirdweb package updated to latest
farhanW3 Apr 8, 2024
6bac546
upd: using typebox convert
farhanW3 Apr 8, 2024
3037f70
Merge branch 'main' into fk/sdk-unified
farhanW3 Apr 16, 2024
745a266
yarn locl upds
farhanW3 Apr 16, 2024
e322b2f
pushed v5 version update
farhanW3 Apr 16, 2024
0a70d82
Merge branch 'main' into fk/sdk-unified
farhanW3 Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"pino": "^8.15.1",
"pino-pretty": "^10.0.0",
"prisma": "^5.2.0",
"thirdweb": "^5.1.0",
"thirdweb": "^5.3.1",
"uuid": "^9.0.1",
"viem": "^1.14.0",
"zod": "^3.21.4"
Expand Down
17 changes: 10 additions & 7 deletions src/server/routes/contract/extensions/erc1155/read/balanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";

import { Static, Type } from "@sinclair/typebox";
import { getContract } from "../../../../../../utils/cache/getContract";
import { balanceOf } from "thirdweb/extensions/erc1155";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import {
erc1155ContractParamSchema,
standardResponseSchema,
Expand Down Expand Up @@ -59,16 +60,18 @@ export async function erc1155BalanceOf(fastify: FastifyInstance) {
const { chain, contractAddress } = request.params;
const { walletAddress, tokenId } = request.query;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const returnData = await contract.erc1155.balanceOf(
walletAddress,
tokenId,
);

const balance = await balanceOf({
contract,
owner: walletAddress,
tokenId: BigInt(tokenId),
});
reply.status(StatusCodes.OK).send({
result: returnData.toString(),
result: balance.toString(),
});
},
});
Expand Down
19 changes: 14 additions & 5 deletions src/server/routes/contract/extensions/erc1155/read/get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Static, Type } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getContract } from "../../../../../../utils/cache/getContract";
import { nftSchema } from "../../../../../schemas/nft";
import { getNFT } from "thirdweb/extensions/erc1155";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import { v5NFTSchema } from "../../../../../schemas/nft";
import {
erc1155ContractParamSchema,
standardResponseSchema,
Expand All @@ -22,7 +24,7 @@ const querystringSchema = Type.Object({

// OUTPUT
const responseSchema = Type.Object({
result: nftSchema,
result: v5NFTSchema,
});

responseSchema.examples = [
Expand Down Expand Up @@ -68,11 +70,18 @@ export async function erc1155Get(fastify: FastifyInstance) {
const { chain, contractAddress } = request.params;
const { tokenId } = request.query;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const result = await contract.erc1155.get(tokenId);
const nftData = await getNFT({
contract,
tokenId: BigInt(tokenId),
});
const result = Value.Convert(v5NFTSchema, nftData) as Static<
typeof v5NFTSchema
>;

reply.status(StatusCodes.OK).send({
result,
});
Expand Down
17 changes: 12 additions & 5 deletions src/server/routes/contract/extensions/erc1155/read/getAll.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Static, Type } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getContract } from "../../../../../../utils/cache/getContract";
import { nftSchema } from "../../../../../schemas/nft";
import { getNFTs } from "thirdweb/extensions/erc1155";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import { v5NFTSchema } from "../../../../../schemas/nft";
import {
erc1155ContractParamSchema,
standardResponseSchema,
Expand All @@ -28,7 +30,7 @@ const querystringSchema = Type.Object({

// OUTPUT
const responseSchema = Type.Object({
result: Type.Array(nftSchema),
result: Type.Array(v5NFTSchema),
});

responseSchema.examples = [
Expand Down Expand Up @@ -77,14 +79,19 @@ export async function erc1155GetAll(fastify: FastifyInstance) {
const { chain, contractAddress } = request.params;
const { start, count } = request.query;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const result = await contract.erc1155.getAll({
const nftData = await getNFTs({
contract,
start,
count,
});
const result = nftData.map(
(nft) => Value.Convert(v5NFTSchema, nft) as Static<typeof v5NFTSchema>,
);

reply.status(StatusCodes.OK).send({
result,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export async function erc1155TotalCount(fastify: FastifyInstance) {
method: "GET",
url: "/contract/:chain/:contractAddress/erc1155/total-count",
schema: {
summary: "Get total supply",
summary: "Get the total count of NFTs minted",
description:
"Get the total supply in circulation for this ERC-1155 contract.",
"This returns the total number of NFTs minted in this contract, not the total supply of a given token.",
tags: ["ERC1155"],
operationId: "totalCount",
params: requestSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Static, Type } from "@sinclair/typebox";
import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getContract } from "../../../../../../utils/cache/getContract";
import { totalSupply } from "thirdweb/extensions/erc1155";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import {
erc1155ContractParamSchema,
standardResponseSchema,
Expand Down Expand Up @@ -54,11 +55,14 @@ export async function erc1155TotalSupply(fastify: FastifyInstance) {
const { chain, contractAddress } = request.params;
const { tokenId } = request.query;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const returnData = await contract.erc1155.totalSupply(tokenId);
const returnData = await totalSupply({
contract,
id: BigInt(tokenId),
});
reply.status(StatusCodes.OK).send({
result: returnData.toString(),
});
Expand Down
39 changes: 16 additions & 23 deletions src/server/routes/contract/extensions/erc20/read/allowanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";

import { Static, Type } from "@sinclair/typebox";
import { getContract } from "../../../../../../utils/cache/getContract";
import { erc20MetadataSchema } from "../../../../../schemas/erc20";
import { Value } from "@sinclair/typebox/value";
import { allowance } from "thirdweb/extensions/erc20";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import {
erc20ContractParamSchema,
standardResponseSchema,
} from "../../../../../schemas/sharedApiSchemas";
import { getChainIdFromChain } from "../../../../../utils/chain";

// INPUTS
const requestSchema = erc20ContractParamSchema;
const querystringSchema = Type.Object({
Expand All @@ -25,17 +25,13 @@ const querystringSchema = Type.Object({

// OUTPUT
const responseSchema = Type.Object({
result: erc20MetadataSchema,
result: Type.String({
description: "The allowance of the wallet for the ERC-20 contract",
}),
});

responseSchema.example = {
result: {
name: "ERC20",
symbol: "",
decimals: "18",
value: "0",
displayValue: "0.0",
},
result: "0",
};

// LOGIC
Expand Down Expand Up @@ -64,22 +60,19 @@ export async function erc20AllowanceOf(fastify: FastifyInstance) {
const { chain, contractAddress } = request.params;
const { spenderWallet, ownerWallet } = request.query;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const returnData: any = await contract.erc20.allowanceOf(
ownerWallet ? ownerWallet : "",
spenderWallet ? spenderWallet : "",
);
const returnData = await allowance({
contract,
owner: ownerWallet,
spender: spenderWallet,
});
reply.status(StatusCodes.OK).send({
result: {
name: returnData.name,
symbol: returnData.symbol,
decimals: returnData.decimals.toString(),
displayValue: returnData.displayValue,
value: returnData.value.toString(),
},
...(Value.Convert(responseSchema, { result: returnData }) as Static<
typeof responseSchema
>),
});
},
});
Expand Down
34 changes: 15 additions & 19 deletions src/server/routes/contract/extensions/erc20/read/balanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";

import { Static, Type } from "@sinclair/typebox";
import { getContract } from "../../../../../../utils/cache/getContract";
import { erc20MetadataSchema } from "../../../../../schemas/erc20";
import { Value } from "@sinclair/typebox/value";
import { getBalance } from "thirdweb/extensions/erc20";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import {
erc20ContractParamSchema,
standardResponseSchema,
Expand All @@ -21,18 +22,14 @@ const querystringSchema = Type.Object({

// OUTPUT
const responseSchema = Type.Object({
result: erc20MetadataSchema,
result: Type.String({
description: "The balance of the wallet for the ERC-20 contract",
}),
});

responseSchema.example = [
{
result: {
name: "ERC20",
symbol: "",
decimals: "18",
value: "7799999999615999974",
displayValue: "7.799999999615999974",
},
result: "7799999999615999974",
},
];

Expand Down Expand Up @@ -62,19 +59,18 @@ export async function erc20BalanceOf(fastify: FastifyInstance) {
const { chain, contractAddress } = request.params;
const { wallet_address } = request.query;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const returnData = await contract.erc20.balanceOf(wallet_address);
const returnData = await getBalance({
contract,
address: wallet_address,
});
reply.status(StatusCodes.OK).send({
result: {
name: returnData.name,
symbol: returnData.symbol,
decimals: returnData.decimals.toString(),
displayValue: returnData.displayValue,
value: returnData.value.toString(),
},
...(Value.Convert(responseSchema, { result: returnData }) as Static<
typeof responseSchema
>),
});
},
});
Expand Down
34 changes: 15 additions & 19 deletions src/server/routes/contract/extensions/erc20/read/totalSupply.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Static, Type } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
import { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { getContract } from "../../../../../../utils/cache/getContract";
import { erc20MetadataSchema } from "../../../../../schemas/erc20";
import { totalSupply } from "thirdweb/extensions/erc20";
import { getContractV5 } from "../../../../../../utils/cache/getContractV5";
import {
erc20ContractParamSchema,
standardResponseSchema,
Expand All @@ -14,18 +15,14 @@ const requestSchema = erc20ContractParamSchema;

// OUTPUT
const responseSchema = Type.Object({
result: erc20MetadataSchema,
result: Type.String({
description: "The total supply of the ERC-20 contract",
}),
});

responseSchema.example = [
{
result: {
name: "Mumba20",
symbol: "",
decimals: "18",
value: "10000000000000000000",
displayValue: "10.0",
},
result: "10000000000000000000",
},
];

Expand All @@ -52,19 +49,18 @@ export async function erc20TotalSupply(fastify: FastifyInstance) {
handler: async (request, reply) => {
const { chain, contractAddress } = request.params;
const chainId = await getChainIdFromChain(chain);
const contract = await getContract({
const contract = await getContractV5({
chainId,
contractAddress,
});
const returnData = await contract.erc20.totalSupply();
const returnData = await totalSupply({
contract,
});

reply.status(StatusCodes.OK).send({
result: {
value: returnData.value.toString(),
symbol: returnData.symbol,
name: returnData.name,
decimals: returnData.decimals.toString(),
displayValue: returnData.displayValue,
},
...(Value.Convert(responseSchema, { result: returnData }) as Static<
typeof responseSchema
>),
});
},
});
Expand Down
Loading
Loading