From 3f31910b400db3de6108804e2460f6010b8b664f Mon Sep 17 00:00:00 2001 From: mejango Date: Sat, 4 Jan 2025 23:46:31 -0300 Subject: [PATCH 1/3] cantina/11 --- src/JBMultiTerminal.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/JBMultiTerminal.sol b/src/JBMultiTerminal.sol index ad81a448..48fbf3ee 100644 --- a/src/JBMultiTerminal.sol +++ b/src/JBMultiTerminal.sol @@ -406,15 +406,15 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal { knownInvalidDecimals = true; } else if (accountingContext.token != JBConstants.NATIVE_TOKEN) { // slither-disable-next-line calls-loop - try IERC165(accountingContext.token).supportsInterface(type(IERC20Metadata).interfaceId) returns ( - bool doesSupport - ) { + try IERC20Metadata(accountingContext.token).decimals() returns (uint8 decimals) { // slither-disable-next-line calls-loop - if (doesSupport && accountingContext.decimals != IERC20Metadata(accountingContext.token).decimals()) - { + if (accountingContext.decimals != decimals) { knownInvalidDecimals = true; } - } catch {} + } catch { + // The token didn't support `decimals`. + knownInvalidDecimals = true; + } } // Make sure the decimals are correct. From 2012140b13572ad6b803386d454786f5e185c661 Mon Sep 17 00:00:00 2001 From: simplemachine92 Date: Tue, 7 Jan 2025 16:54:45 -0600 Subject: [PATCH 2/3] remove supportsInterface mocks --- .../TestAccountingContextsOf.sol | 10 ++------- .../TestAddAccountingContextsFor.sol | 22 +------------------ test/units/static/JBMultiTerminal/TestPay.sol | 7 ------ 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol b/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol index c3a9af75..bb754b74 100644 --- a/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol +++ b/test/units/static/JBMultiTerminal/TestAccountingContextsOf.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.23; import /* {*} from */ "../../../helpers/TestBaseWorkflow.sol"; import {JBMultiTerminalSetup} from "./JBMultiTerminalSetup.sol"; -contract TestAccountingContextsFor_Local is JBMultiTerminalSetup { +contract TestAccountingContextsOf_Local is JBMultiTerminalSetup { uint256 _projectId = 1; address _usdc = makeAddr("USDC"); uint256 _usdcCurrency = uint32(uint160(_usdc)); @@ -29,8 +29,6 @@ contract TestAccountingContextsFor_Local is JBMultiTerminalSetup { // mock call to tokens decimals() mockExpect(_usdc, abi.encodeCall(IERC20Metadata.decimals, ()), abi.encode(6)); - // mock call to rulesets currentOf returning 0 to bypass ruleset checking - // setup: return data JBRuleset memory ruleset = JBRuleset({ cycleNumber: 1, @@ -44,13 +42,9 @@ contract TestAccountingContextsFor_Local is JBMultiTerminalSetup { metadata: 0 }); + // mock call to rulesets currentOf returning 0 to bypass ruleset checking mockExpect(address(rulesets), abi.encodeCall(IJBRulesets.currentOf, (_projectId)), abi.encode(ruleset)); - // mock supports interface call - mockExpect( - _usdc, abi.encodeCall(IERC165.supportsInterface, (type(IERC20Metadata).interfaceId)), abi.encode(true) - ); - // call params JBAccountingContext[] memory _tokens = new JBAccountingContext[](1); _tokens[0] = JBAccountingContext({token: _usdc, decimals: 6, currency: uint32(uint160(_usdc))}); diff --git a/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol b/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol index 9cf0a908..da960c7c 100644 --- a/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol +++ b/test/units/static/JBMultiTerminal/TestAddAccountingContextsFor.sol @@ -79,8 +79,6 @@ contract TestAddAccountingContextsFor_Local is JBMultiTerminalSetup { // mock call to tokens decimals() mockExpect(_usdc, abi.encodeCall(IERC20Metadata.decimals, ()), abi.encode(6)); - // mock call to rulesets currentOf returning 0 to bypass ruleset checking - // setup: return data JBRuleset memory ruleset = JBRuleset({ cycleNumber: 1, @@ -94,13 +92,9 @@ contract TestAddAccountingContextsFor_Local is JBMultiTerminalSetup { metadata: 0 }); + // mock call to rulesets currentOf returning 0 to bypass ruleset checking mockExpect(address(rulesets), abi.encodeCall(IJBRulesets.currentOf, (_projectId)), abi.encode(ruleset)); - // mock supports interface call - mockExpect( - _usdc, abi.encodeCall(IERC165.supportsInterface, (type(IERC20Metadata).interfaceId)), abi.encode(true) - ); - // call params JBAccountingContext[] memory _tokens = new JBAccountingContext[](1); _tokens[0] = JBAccountingContext({token: _usdc, decimals: 6, currency: uint32(uint160(_usdc))}); @@ -284,13 +278,6 @@ contract TestAddAccountingContextsFor_Local is JBMultiTerminalSetup { // mock rulesets call mockExpect(address(rulesets), abi.encodeCall(IJBRulesets.currentOf, (_projectId)), abi.encode(ruleset)); - // mock token interface support call - mockExpect( - address(someToken), - abi.encodeCall(IERC165.supportsInterface, (type(IERC20Metadata).interfaceId)), - abi.encode(true) - ); - // mock token call mockExpect(address(someToken), abi.encodeCall(IERC20Metadata.decimals, ()), abi.encode(18)); @@ -323,13 +310,6 @@ contract TestAddAccountingContextsFor_Local is JBMultiTerminalSetup { // mock rulesets call mockExpect(address(rulesets), abi.encodeCall(IJBRulesets.currentOf, (_projectId)), abi.encode(ruleset)); - // mock token interface support call - mockExpect( - address(someToken), - abi.encodeCall(IERC165.supportsInterface, (type(IERC20Metadata).interfaceId)), - abi.encode(true) - ); - // mock token call mockExpect(address(someToken), abi.encodeCall(IERC20Metadata.decimals, ()), abi.encode(18)); diff --git a/test/units/static/JBMultiTerminal/TestPay.sol b/test/units/static/JBMultiTerminal/TestPay.sol index aaaa1a78..77c246c1 100644 --- a/test/units/static/JBMultiTerminal/TestPay.sol +++ b/test/units/static/JBMultiTerminal/TestPay.sol @@ -72,13 +72,6 @@ contract TestPay_Local is JBMultiTerminalSetup { address(directory), abi.encodeCall(IJBDirectory.controllerOf, (_projectId)), abi.encode(address(this)) ); - // mock supports interface call - mockExpect( - address(_mockToken), - abi.encodeCall(IERC165.supportsInterface, (type(IERC20Metadata).interfaceId)), - abi.encode(true) - ); - // mock call to token decimals mockExpect(address(_mockToken), abi.encodeCall(IERC20Metadata.decimals, ()), abi.encode(6)); From 427a5d2ecd259c52ddbba529527566a0d52bf1d9 Mon Sep 17 00:00:00 2001 From: mejango Date: Wed, 8 Jan 2025 14:33:31 -0300 Subject: [PATCH 3/3] allow custom decimals if the contract doesnt have a decimals() function --- src/JBMultiTerminal.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JBMultiTerminal.sol b/src/JBMultiTerminal.sol index 48fbf3ee..98f4bd25 100644 --- a/src/JBMultiTerminal.sol +++ b/src/JBMultiTerminal.sol @@ -413,7 +413,7 @@ contract JBMultiTerminal is JBPermissioned, ERC2771Context, IJBMultiTerminal { } } catch { // The token didn't support `decimals`. - knownInvalidDecimals = true; + knownInvalidDecimals = false; } }