From 3b5e9ec6330c34c2350f1248344dbb6d2372b876 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Sat, 10 Feb 2024 16:26:52 -0500 Subject: [PATCH] Implement fix to function encoding when parameter includes bool --- src/utils/crypto.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index dc889b9c97..0edc9a1e66 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -61,10 +61,32 @@ export const encodeFunction = ( } }); + const boolify = (parameter: string) => { + if (['false'].includes(parameter.toLowerCase())) { + return false; + } else if (['true'].includes(parameter.toLowerCase())) { + return true; + } else { + return parameter; + } + }; + + const parametersFixedWithBool = parametersFixed?.map(parameter => { + if (typeof parameter === 'string') { + return boolify(parameter); + } else if (Array.isArray(parameter)) { + return parameter.map(innerParameter => { + return boolify(innerParameter); + }); + } else { + throw new Error('parameter type not as expected'); + } + }); + try { return new utils.Interface([functionSignature]).encodeFunctionData( _functionName, - parametersFixed + parametersFixedWithBool ); } catch (e) { logError(e);