Aperture-Finance / uniswap-v3-automation-sdk

14 stars 7 forks source link

viem getAutomanRebalanceCalldata fail with permitInfo (v3.2.21) #250

Open Nix-01 opened 2 months ago

Nix-01 commented 2 months ago

This function do not works if you provide perimtInfo path : \viem\automan\automan.js

Error : Uncaught AbiEncodingLengthMismatchError AbiEncodingLengthMismatchError: ABI encoding params/values length mismatch. Expected length (params): 4 Given length (values): 8

function getAutomanRebalanceCalldata(mintParams, tokenId, feeBips = BigInt(0), permitInfo, swapData = '0x') {
    if (permitInfo === undefined) {
        return (0, viem_1.encodeFunctionData)({
            abi: index_1.Automan__factory.abi,
            args: [mintParams, tokenId, feeBips, swapData],
            functionName: 'rebalance',
        });
    }
    const { v, r, s } = (0, viem_1.hexToSignature)(permitInfo.signature);
    return (0, viem_1.encodeFunctionData)({
        abi: index_1.Automan__factory.abi,
        args: [
            mintParams,
            tokenId,
            feeBips,
            swapData,
            BigInt(permitInfo.deadline),
            Number(v),
            r,
            s,
        ],
        functionName: 'rebalance',
    });
}

I hope this feedback will be helpful

Nix-01 commented 2 months ago

I tested with the MethodID: 0xc9ccb402 and it works, it's not a clean way to fix, but I can confirm this works if we force the right MethodID

function getAutomanRebalanceCalldata(mintParams, tokenId, feeBips = BigInt(0), permitInfo, swapData = '0x') {
    if (permitInfo === undefined) {
        return (0, viem_1.encodeFunctionData)({
            abi: index_1.Automan__factory.abi,
            args: [mintParams, tokenId, feeBips, swapData],
            functionName: 'rebalance',
        });
    }
    const { v, r, s } = (0, viem_1.hexToSignature)(permitInfo.signature);
    return (0, viem_1.encodeFunctionData)({
        abi: index_1.Automan__factory.abi,
        args: [
            mintParams,
            tokenId,
            feeBips,
            swapData,
            BigInt(permitInfo.deadline),
            Number(v),
            r,
            s,
        ],
        functionName: '0xc9ccb402',
    });
}
lanceaper commented 3 weeks ago

Ack, will check later, but I think this function should be working for our frontend