Skip to content

Commit

Permalink
use IERC20Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
shileiwill committed Apr 18, 2024
1 parent a6642aa commit e9c06b9
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 33 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";

interface IWrappedNative is IERC20 {
function deposit() external payable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.19;
import {BaseTest} from "./BaseTest.t.sol";
import {IAutomationRegistryMaster2_3} from "../interfaces/v2_3/IAutomationRegistryMaster2_3.sol";
import {AutomationRegistrar2_3} from "../v2_3/AutomationRegistrar2_3.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {AutomationRegistryBase2_3 as AutoBase} from "../v2_3/AutomationRegistryBase2_3.sol";
import {IWrappedNative} from "../interfaces/v2_3/IWrappedNative.sol";

Expand Down
45 changes: 36 additions & 9 deletions contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {AutomationRegistryBase2_3 as AutoBase} from "../v2_3/AutomationRegistryB
import {AutomationRegistrar2_3 as Registrar} from "../v2_3/AutomationRegistrar2_3.sol";
import {IAutomationRegistryMaster2_3 as Registry, AutomationRegistryBase2_3} from "../interfaces/v2_3/IAutomationRegistryMaster2_3.sol";
import {ChainModuleBase} from "../../chains/ChainModuleBase.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IWrappedNative} from "../interfaces/v2_3/IWrappedNative.sol";

// forge test --match-path src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol
Expand Down Expand Up @@ -358,7 +358,7 @@ contract SetConfig is SetUp {
(uint32 configCount, uint32 blockNumber, ) = registry.latestConfigDetails();
assertEq(configCount, 1);

address billingTokenAddress = address(0x1111111111111111111111111111111111111111);
address billingTokenAddress = address(usdToken18);
address[] memory billingTokens = new address[](1);
billingTokens[0] = billingTokenAddress;

Expand Down Expand Up @@ -429,8 +429,8 @@ contract SetConfig is SetUp {
(uint32 configCount, , ) = registry.latestConfigDetails();
assertEq(configCount, 1);

address billingTokenAddress1 = address(0x1111111111111111111111111111111111111111);
address billingTokenAddress2 = address(0x1111111111111111111111111111111111111112);
address billingTokenAddress1 = address(linkToken);
address billingTokenAddress2 = address(usdToken18);
address[] memory billingTokens = new address[](2);
billingTokens[0] = billingTokenAddress1;
billingTokens[1] = billingTokenAddress2;
Expand Down Expand Up @@ -493,7 +493,7 @@ contract SetConfig is SetUp {
assertEq(configCount, 1);

// BillingConfig1
address billingTokenAddress1 = address(0x1111111111111111111111111111111111111111);
address billingTokenAddress1 = address(usdToken18);
address[] memory billingTokens1 = new address[](1);
billingTokens1[0] = billingTokenAddress1;

Expand All @@ -510,7 +510,7 @@ contract SetConfig is SetUp {
bytes memory onchainConfigBytesWithBilling1 = abi.encode(cfg, billingTokens1, billingConfigs1);

// BillingConfig2
address billingTokenAddress2 = address(0x1111111111111111111111111111111111111112);
address billingTokenAddress2 = address(usdToken18);
address[] memory billingTokens2 = new address[](1);
billingTokens2[0] = billingTokenAddress2;

Expand Down Expand Up @@ -567,8 +567,8 @@ contract SetConfig is SetUp {
(uint32 configCount, , ) = registry.latestConfigDetails();
assertEq(configCount, 1);

address billingTokenAddress1 = address(0x1111111111111111111111111111111111111111);
address billingTokenAddress2 = address(0x1111111111111111111111111111111111111111);
address billingTokenAddress1 = address(linkToken);
address billingTokenAddress2 = address(linkToken);
address[] memory billingTokens = new address[](2);
billingTokens[0] = billingTokenAddress1;
billingTokens[1] = billingTokenAddress2;
Expand Down Expand Up @@ -635,13 +635,40 @@ contract SetConfig is SetUp {
);
}

function testSetConfigRevertDueToInvalidDecimals() public {
address[] memory billingTokens = new address[](1);
billingTokens[0] = address(linkToken);

AutomationRegistryBase2_3.BillingConfig[] memory billingConfigs = new AutomationRegistryBase2_3.BillingConfig[](1);
billingConfigs[0] = AutomationRegistryBase2_3.BillingConfig({
gasFeePPB: 5_000,
flatFeeMilliCents: 20_000,
priceFeed: address(USDTOKEN_USD_FEED),
fallbackPrice: 2_000_000_000, // $20
minSpend: 100_000,
decimals: 6 // link token should have 18 decimals
});

vm.expectRevert(abi.encodeWithSelector(Registry.InvalidToken.selector));
registry.setConfigTypeSafe(
SIGNERS,
TRANSMITTERS,
F,
cfg,
OFFCHAIN_CONFIG_VERSION,
offchainConfigBytes,
billingTokens,
billingConfigs
);
}

function testSetConfigWithNewTransmittersSuccess() public {
registry = deployRegistry(AutoBase.PayoutMode.OFF_CHAIN);

(uint32 configCount, uint32 blockNumber, ) = registry.latestConfigDetails();
assertEq(configCount, 0);

address billingTokenAddress = address(0x1111111111111111111111111111111111111111);
address billingTokenAddress = address(usdToken18);
address[] memory billingTokens = new address[](1);
billingTokens[0] = billingTokenAddress;

Expand Down
7 changes: 4 additions & 3 deletions contracts/src/v0.8/automation/dev/test/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "forge-std/Test.sol";

import {LinkToken} from "../../../shared/token/ERC677/LinkToken.sol";
import {ERC20Mock} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/mocks/ERC20Mock.sol";
import {ERC20Mock6Decimals} from "../../mocks/ERC20Mock6Decimals.sol";
import {MockV3Aggregator} from "../../../tests/MockV3Aggregator.sol";
import {AutomationForwarderLogic} from "../../AutomationForwarderLogic.sol";
import {UpkeepTranscoder5_0 as Transcoder} from "../v2_3/UpkeepTranscoder5_0.sol";
Expand All @@ -16,7 +17,7 @@ import {AutomationRegistryLogicC2_3} from "../v2_3/AutomationRegistryLogicC2_3.s
import {IAutomationRegistryMaster2_3 as Registry, AutomationRegistryBase2_3} from "../interfaces/v2_3/IAutomationRegistryMaster2_3.sol";
import {AutomationRegistrar2_3} from "../v2_3/AutomationRegistrar2_3.sol";
import {ChainModuleBase} from "../../chains/ChainModuleBase.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {MockUpkeep} from "../../mocks/MockUpkeep.sol";
import {IWrappedNative} from "../interfaces/v2_3/IWrappedNative.sol";
import {WETH9} from "./WETH9.sol";
Expand All @@ -40,7 +41,7 @@ contract BaseTest is Test {

// contracts
LinkToken internal linkToken;
ERC20Mock internal usdToken6;
ERC20Mock6Decimals internal usdToken6;
ERC20Mock internal usdToken18;
WETH9 internal weth;
MockV3Aggregator internal LINK_USD_FEED;
Expand Down Expand Up @@ -75,7 +76,7 @@ contract BaseTest is Test {
linkToken = new LinkToken();
linkToken.grantMintRole(OWNER);
usdToken18 = new ERC20Mock("MOCK_ERC20_18Decimals", "MOCK_ERC20_18Decimals", OWNER, 0);
usdToken6 = new ERC20Mock("MOCK_ERC20_6Decimals", "MOCK_ERC20_6Decimals", OWNER, 0);
usdToken6 = new ERC20Mock6Decimals("MOCK_ERC20_6Decimals", "MOCK_ERC20_6Decimals", OWNER, 0);
weth = new WETH9();

LINK_USD_FEED = new MockV3Aggregator(8, 2_000_000_000); // $20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IAutomationRegistryMaster2_3} from "../interfaces/v2_3/IAutomationRegist
import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterface.sol";
import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol";
import {IERC677Receiver} from "../../../shared/interfaces/IERC677Receiver.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IWrappedNative} from "../interfaces/v2_3/IWrappedNative.sol";
import {SafeCast} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/math/SafeCast.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {AutomationRegistryLogicC2_3} from "./AutomationRegistryLogicC2_3.sol";
import {Chainable} from "../../Chainable.sol";
import {IERC677Receiver} from "../../../shared/interfaces/IERC677Receiver.sol";
import {OCR2Abstract} from "../../../shared/ocr2/OCR2Abstract.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";

/**
* @notice Registry for adding work for Chainlink nodes to perform on client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {AggregatorV3Interface} from "../../../shared/interfaces/AggregatorV3Inte
import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol";
import {KeeperCompatibleInterface} from "../../interfaces/KeeperCompatibleInterface.sol";
import {IChainModule} from "../../interfaces/IChainModule.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeCast} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/math/SafeCast.sol";
import {IWrappedNative} from "../interfaces/v2_3/IWrappedNative.sol";

Expand Down Expand Up @@ -1085,9 +1085,8 @@ abstract contract AutomationRegistryBase2_3 is ConfirmedOwner {
IERC20 token = billingTokens[i];
BillingConfig memory config = billingConfigs[i];

// most ERC20 tokens are 18 decimals, we support tokens with up to 24 decimals
// priceFeed must be 8 decimals
if (config.decimals > 24 || config.priceFeed.decimals() != 8) {
// most ERC20 tokens are 18 decimals, priceFeed must be 8 decimals
if (config.decimals != token.decimals() || config.priceFeed.decimals() != 8) {
revert InvalidToken();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {AutomationForwarder} from "../../AutomationForwarder.sol";
import {IAutomationForwarder} from "../../interfaces/IAutomationForwarder.sol";
import {UpkeepTranscoderInterfaceV2} from "../../interfaces/UpkeepTranscoderInterfaceV2.sol";
import {MigratableKeeperRegistryInterfaceV2} from "../../interfaces/MigratableKeeperRegistryInterfaceV2.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v4.7.3/contra
import {Address} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol";
import {AutomationRegistryLogicC2_3} from "./AutomationRegistryLogicC2_3.sol";
import {Chainable} from "../../Chainable.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/utils/SafeERC20.sol";
import {SafeCast} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/math/SafeCast.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v4.7.3/contra
import {Address} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/Address.sol";
import {IAutomationForwarder} from "../../interfaces/IAutomationForwarder.sol";
import {IChainModule} from "../../interfaces/IChainModule.sol";
import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata as IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IAutomationV21PlusCommon} from "../../interfaces/IAutomationV21PlusCommon.sol";

contract AutomationRegistryLogicC2_3 is AutomationRegistryBase2_3 {
Expand Down
17 changes: 17 additions & 0 deletions contracts/src/v0.8/automation/mocks/ERC20Mock6Decimals.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.8.0;

import {ERC20Mock} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/mocks/ERC20Mock.sol";

// mock ERC20 with 6 decimals
contract ERC20Mock6Decimals is ERC20Mock {
constructor(
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) payable ERC20Mock(name, symbol, initialAccount, initialBalance) {}

function decimals() public view virtual override returns (uint8) {
return 6;
}
}
Loading

0 comments on commit e9c06b9

Please sign in to comment.