Skip to content

Commit

Permalink
Resolved linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andresceballosm committed Jul 31, 2024
1 parent 2f4dd0b commit b29b131
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
42 changes: 25 additions & 17 deletions packages/taco/src/conditions/base/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ const EthBaseTypes: [string, ...string[]] = [
'string',
'address',
'address payable',
...Array.from({ length: 32 }, (_v, i) => `bytes${i + 1}`), // bytes1 through bytes32
...Array.from({ length: 32 }, (_v, i) => `bytes${i + 1}`),
'bytes',
...Array.from({ length: 32 }, (_v, i) => `uint${8 * (i + 1)}`), // uint8 through uint256
...Array.from({ length: 32 }, (_v, i) => `int${8 * (i + 1)}`), // int8 through int256
...Array.from({ length: 32 }, (_v, i) => `uint${8 * (i + 1)}`),
...Array.from({ length: 32 }, (_v, i) => `int${8 * (i + 1)}`),
];

type AbiVariable = {
name: string;
type: string;
internalType: string;
};

const functionAbiVariableSchema = z
.object({
name: z.string(),
Expand Down Expand Up @@ -59,7 +65,6 @@ const functionAbiSchema = z
(functionAbi) => {
let asInterface;
try {
// `stringify` here because ethers.utils.Interface doesn't accept a Zod schema
asInterface = new ethers.utils.Interface(JSON.stringify([functionAbi]));
} catch (e) {
return false;
Expand Down Expand Up @@ -87,28 +92,31 @@ const functionAbiSchema = z
},
);

function toJsonAbiFormat(humanReadableAbi: string): any {
function toJsonAbiFormat(humanReadableAbi: string) {
const abiWithoutFunctionKeyword = humanReadableAbi.replace(
/^function\s+/,
'',
);
const fragment = ethers.utils.FunctionFragment.from(
abiWithoutFunctionKeyword,
);
const { constant, payable, ...jsonAbi } = JSON.parse(
fragment.format(ethers.utils.FormatTypes.json),
);
const jsonAbi = JSON.parse(fragment.format(ethers.utils.FormatTypes.json));

jsonAbi.inputs = jsonAbi.inputs.map((input: any) => ({
...input,
internalType: input.type,
}));
jsonAbi.outputs = jsonAbi.outputs.map((output: any) => ({
...output,
internalType: output.type,
}));
const filteredJsonAbi = {
name: jsonAbi.name,
type: jsonAbi.type,
stateMutability: jsonAbi.stateMutability,
inputs: jsonAbi.inputs.map((input: AbiVariable) => ({
...input,
internalType: input.type,
})),
outputs: jsonAbi.outputs.map((output: AbiVariable) => ({
...output,
internalType: output.type,
})),
};

return jsonAbi;
return filteredJsonAbi;
}

export type FunctionAbiProps = z.infer<typeof functionAbiSchema>;
Expand Down
4 changes: 1 addition & 3 deletions packages/taco/test/conditions/base/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,7 @@ describe('supports custom function abi', () => {
});
const invalidHumanReadableAbi = 'function invalidAbi';

expect(() =>
humanReadableAbiSchema.parse(humanReadableAbi),
).not.toThrow();
expect(() => humanReadableAbiSchema.parse(humanReadableAbi)).not.toThrow();
expect(() => humanReadableAbiSchema.parse(invalidHumanReadableAbi)).toThrow(
'Invalid Human-Readable ABI format',
);
Expand Down

0 comments on commit b29b131

Please sign in to comment.