Skip to content

Commit

Permalink
refactor: simplify contract method signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Feb 23, 2024
1 parent b66e4a0 commit 3f3bfe5
Show file tree
Hide file tree
Showing 27 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function prepareDeployTransactionViaCloneFactory(
return prepareContractCall({
contract: factory,
method:
"function deployProxyByImplementation(address _implementation, bytes memory _data, bytes32 _salt) returns (address deployedProxy)",
"function deployProxyByImplementation(address, bytes, bytes32) returns (address)",
params: async () => {
const implementation = getContract({
client,
Expand Down
3 changes: 1 addition & 2 deletions packages/thirdweb/src/extensions/erc1155/read/balanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export function balanceOf(
): Promise<bigint> {
return readContract({
...options,
method:
"function balanceOf(owner address, tokenId uint256) view returns (uint256)",
method: "function balanceOf(address, uint256) view returns (uint256)",
params: [options.address, options.tokenId],
});
}

Check warning on line 28 in packages/thirdweb/src/extensions/erc1155/read/balanceOf.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/balanceOf.ts#L1-L28

Added lines #L1 - L28 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export function balanceOfBatch(
): Promise<readonly bigint[]> {
return readContract({
...options,
method:
"function balanceOfBatch(owners address[], tokenIds uint256[]) view returns (uint256[])",
method: "function balanceOfBatch(address[], uint256[]) returns (uint256[])",
params: [options.owners, options.tokenIds],
});
}

Check warning on line 28 in packages/thirdweb/src/extensions/erc1155/read/balanceOfBatch.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/balanceOfBatch.ts#L1-L28

Added lines #L1 - L28 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export function nextTokenIdToMint(
): Promise<bigint> {
return readContract({
...options,
method: "function nextTokenIdToMint() view returns (uint256)",
method: "function nextTokenIdToMint() returns (uint256)",
});
}

Check warning on line 22 in packages/thirdweb/src/extensions/erc1155/read/nextTokenIdToMint.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/nextTokenIdToMint.ts#L1-L22

Added lines #L1 - L22 were not covered by tests
3 changes: 1 addition & 2 deletions packages/thirdweb/src/extensions/erc1155/read/tokenURI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export function tokenURI(
): Promise<string> {
return readContract({
...options,
method:
"function tokenURI(tokenId uint256) external view returns (string memory)",
method: "function tokenURI(uint256) returns (string)",
params: [options.tokenId],
});
}

Check warning on line 25 in packages/thirdweb/src/extensions/erc1155/read/tokenURI.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/tokenURI.ts#L1-L25

Added lines #L1 - L25 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function totalSupply(
): Promise<bigint> {
return readContract({
...options,
method: "function totalSupply(tokenId uint256) view returns (uint256)",
method: "function totalSupply(uint256) returns (uint256)",
params: [options.tokenId],
});
}

Check warning on line 25 in packages/thirdweb/src/extensions/erc1155/read/totalSupply.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc1155/read/totalSupply.ts#L1-L25

Added lines #L1 - L25 were not covered by tests
3 changes: 1 addition & 2 deletions packages/thirdweb/src/extensions/erc20/read/allowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export function allowance(
): Promise<bigint> {
return readContract({
...options,
method:
"function allowance(address owner, address spender) view returns (uint256)",
method: "function allowance(address, address) returns (uint256)",
params: [options.owner, options.spender],
});
}

Check warning on line 29 in packages/thirdweb/src/extensions/erc20/read/allowance.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc20/read/allowance.ts#L1-L29

Added lines #L1 - L29 were not covered by tests
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc20/read/balanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { readContract } from "../../../transaction/read-contract.js";
import type { BaseTransactionOptions } from "../../../transaction/types.js";
import { toTokens } from "../../../utils/units.js";

const METHOD = "function balanceOf(address) view returns (uint256)" as const;
const METHOD = "function balanceOf(address) returns (uint256)" as const;

type BalanceOfParams = { address: string };

Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc20/read/decimals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { detectMethod } from "../../../utils/bytecode/detectExtension.js";

const cache = new WeakMap<ThirdwebContract<any>, Promise<number>>();

const METHOD = "function decimals() view returns (uint8)" as const;
const METHOD = "function decimals() returns (uint8)" as const;

/**
* Detects if the contract has a function to retrieve the number of decimals.
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc20/read/totalSupply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ import type { BaseTransactionOptions } from "../../../transaction/types.js";
export function totalSupply(options: BaseTransactionOptions): Promise<bigint> {
return readContract({
...options,
method: "function totalSupply() view returns (uint256)",
method: "function totalSupply() returns (uint256)",
});
}
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc20/write/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type ApproveParams = Prettify<
export function approve(options: BaseTransactionOptions<ApproveParams>) {
return prepareContractCall({
...options,
method: "function approve(address spender, uint256 value) returns (bool)",
method: "function approve(address, uint256) returns (bool)",
params: async () => {
let amount: bigint;
if ("amount" in options) {
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc20/write/mintTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type MintToParams = Prettify<
export function mintTo(options: BaseTransactionOptions<MintToParams>) {
return prepareContractCall({
...options,
method: "function mintTo(address to, uint256 amount)",
method: "function mintTo(address, uint256)",
params: async () => {
let amount: bigint;
if ("amount" in options) {
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc20/write/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type TransferParams = Prettify<
export function transfer(options: BaseTransactionOptions<TransferParams>) {
return prepareContractCall({
contract: options.contract,
method: "function transfer(address to, uint256 value)",
method: "function transfer(address, uint256)",
params: async () => {
let amount: bigint;
if ("amount" in options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function transferFrom(
) {
return prepareContractCall({
...options,
method: "function transferFrom(address from, address to, uint256 value)",
method: "function transferFrom(address, address, uint256)",
params: async () => {
let amount: bigint;
if ("amount" in options) {
Expand Down
3 changes: 1 addition & 2 deletions packages/thirdweb/src/extensions/erc721/read/balanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export function balanceOf(
): Promise<bigint> {
return readContract({
...options,
method:
"function balanceOf(address owner) external view returns (uint256 balance)",
method: "function balanceOf(address) returns (uint256)",
params: [options.address],
});
}

Check warning on line 25 in packages/thirdweb/src/extensions/erc721/read/balanceOf.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/balanceOf.ts#L1-L25

Added lines #L1 - L25 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export function nextTokenIdToMint(
): Promise<bigint> {
return readContract({
...options,
method: "function nextTokenIdToMint() view returns (uint256)",
method: "function nextTokenIdToMint() returns (uint256)",
});
}

Check warning on line 22 in packages/thirdweb/src/extensions/erc721/read/nextTokenIdToMint.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/nextTokenIdToMint.ts#L1-L22

Added lines #L1 - L22 were not covered by tests
3 changes: 1 addition & 2 deletions packages/thirdweb/src/extensions/erc721/read/ownerOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export function ownerOf(
): Promise<string> {
return readContract({
...options,
method:
"function ownerOf(uint256 tokenId) external view returns (address owner)",
method: "function ownerOf(uint256) returns (address)",
params: [BigInt(options.tokenId)],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ import type { BaseTransactionOptions } from "../../../transaction/types.js";
export function startTokenId(options: BaseTransactionOptions): Promise<bigint> {
return readContract({
...options,
method: "function startTokenId() view returns (uint256)",
method: "function startTokenId() returns (uint256)",
});
}

Check warning on line 20 in packages/thirdweb/src/extensions/erc721/read/startTokenId.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/startTokenId.ts#L1-L20

Added lines #L1 - L20 were not covered by tests
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc721/read/tokenURI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function tokenURI(
): Promise<string> {
return readContract({
...options,
method: "function tokenURI(uint256 tokenId) returns (string memory)",
method: "function tokenURI(uint256) returns (string)",
params: [options.tokenId],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ import type { BaseTransactionOptions } from "../../../transaction/types.js";
export function totalSupply(options: BaseTransactionOptions): Promise<bigint> {
return readContract({
...options,
method: "function totalSupply() view returns (uint256)",
method: "function totalSupply() returns (uint256)",
});
}

Check warning on line 20 in packages/thirdweb/src/extensions/erc721/read/totalSupply.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/read/totalSupply.ts#L1-L20

Added lines #L1 - L20 were not covered by tests
2 changes: 1 addition & 1 deletion packages/thirdweb/src/extensions/erc721/write/mintTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type MintToParams = {
export function mintTo(options: BaseTransactionOptions<MintToParams>) {
return prepareContractCall({
contract: options.contract,
method: "function mintTo(address _to, string memory _tokenURI)",
method: "function mintTo(address, string)",
params: async () => {
let tokenUri: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function transferFrom(
) {
return prepareContractCall({
contract: options.contract,
method: "function transferFrom(address from, address to, uint256 tokenId)",
method: "function transferFrom(address, address, uint256)",
params: [options.from, options.to, options.tokenId],
});
}

Check warning on line 38 in packages/thirdweb/src/extensions/erc721/write/transferFrom.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/extensions/erc721/write/transferFrom.ts#L1-L38

Added lines #L1 - L38 were not covered by tests
2 changes: 1 addition & 1 deletion packages/thirdweb/src/transaction/actions/encode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("transaction: encode", () => {
it("should encode correctly (human-readable)", async () => {
const tx = prepareContractCall({
contract: USDC_CONTRACT,
method: "function transfer(address to, uint256 value) returns (bool)",
method: "function transfer(address, uint256) returns (bool)",
params: [TEST_WALLET_A, 100n],
});
const encoded = await encode(tx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("transaction: estimate-gas", () => {
it("should estimate gas correctly (human-readable)", async () => {
const tx = prepareContractCall({
contract: USDC_CONTRACT,
method: "function transfer(address to, uint256 value) returns (bool)",
method: "function transfer(address, uint256) returns (bool)",
params: [TEST_WALLET_A, 100n],
});
const gasEstimate = await estimateGas({
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/transaction/actions/simulate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("transaction: simulate", () => {
it("should simulate correctly (human-readable)", async () => {
const tx = prepareContractCall({
contract: USDC_CONTRACT,
method: "function transfer(address to, uint256 value) returns (bool)",
method: "function transfer(address, uint256) returns (bool)",
params: [TEST_WALLET_A, 100n],
});
const result = await simulateTransaction({
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/transaction/read-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("transaction: read", () => {
it("should read from the contract correctly", async () => {
const result = await readContract({
contract: USDC_CONTRACT,
method: "function balanceOf(address owner) returns (uint256)",
method: "function balanceOf(address) returns (uint256)",
params: [VITALIK_WALLET],
});

Expand Down
5 changes: 2 additions & 3 deletions packages/thirdweb/src/wallets/smart/lib/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function prepareCreateAccount(args: {
}
return prepareContractCall({
contract: factoryContract,
method: "function createAccount(address, bytes) public returns (address)",
method: "function createAccount(address, bytes) returns (address)",
params: [
options.overrides?.accountAddress || options.personalAccount.address,
stringToHex(options.overrides?.accountSalt ?? ""),
Expand Down Expand Up @@ -87,8 +87,7 @@ export function prepareBatchExecute(args: {
}
return prepareContractCall({
contract: accountContract,
method:
"function executeBatch(address[] calldata _target,uint256[] calldata _value,bytes[] calldata _calldata)",
method: "function executeBatch(address[], uint256[], bytes[])",
params: [
transactions.map((tx) => tx.to || ""),
transactions.map((tx) => tx.value || 0n),
Expand Down

0 comments on commit 3f3bfe5

Please sign in to comment.