-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
If a contract has an overloaded function with multiple signatures containing different arg names like this:
contract Overloaded {
function foo(uint256 num) public pure returns (uint256) {
return num;
}
function foo(string memory name) public pure returns (string memory) {
return name;
}
}Drift infers the args type for this function as a union of the 2:
type FooArgs = FunctionArgs<OverloadedAbi, "foo">;
// ^? type FooArgs = { name: string } | { num: bigint }This means APIs that use these args end up accepting both values:
client.read({
abi: overloadedAbi,
address: "0x...",
fn: "foo",
args: {
name: "abc",
num: 123n, // This shouldn't be allowed!
},
});The type for these args should be a discriminated union to only allow the args for one of the signatures to be used:
type FooArgs = FunctionArgs<OverloadedAbi, "foo">;
// ^? type FooArgs = OneOf<{ name: string } | { num: bigint }>client.read({
abi: overloadedAbi,
address: "0x...",
fn: "foo",
args: {
name: "abc",
num: 123n, // ❌ Type 'bigint' is not assignable to type 'undefined'
},
});This likely needs to be a change in the AbiObjectType type:
https://github.com/delvtech/drift/blob/fbbcb8f88d4ec6ef714bbee0c827b01e63cc6914/packages/drift/src/adapter/types/Abi.ts#L225-L244
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels