Skip to content

Commit

Permalink
use safeIncreaseAllowance (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
matYang authored Dec 5, 2023
1 parent 469d873 commit 4b8569f
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 20 deletions.
21 changes: 12 additions & 9 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,21 @@ AggregateTokenLimiter_setAdmin:testOwnerSuccess() (gas: 18631)
AggregateTokenLimiter_setRateLimiterConfig:testOnlyOnlyCallableByAdminOrOwnerReverts() (gas: 21600)
AggregateTokenLimiter_setRateLimiterConfig:testOwnerSuccess() (gas: 41514)
AggregateTokenLimiter_setRateLimiterConfig:testTokenLimitAdminSuccess() (gas: 48156)
BurnFromMintTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 14336)
BurnFromMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 55728)
BurnFromMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 201167)
BurnMintTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 14336)
BurnMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 55728)
BurnMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 199084)
BurnFromMintTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 14362)
BurnFromMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 55754)
BurnFromMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 201188)
BurnFromMintTokenPool_lockOrBurn:testSetupSuccess() (gas: 19786)
BurnMintTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 14362)
BurnMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 55754)
BurnMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 199105)
BurnMintTokenPool_lockOrBurn:testSetupSuccess() (gas: 13887)
BurnMintTokenPool_releaseOrMint:testPermissionsErrorReverts() (gas: 19990)
BurnMintTokenPool_releaseOrMint:testPoolMintNotHealthyReverts() (gas: 51240)
BurnMintTokenPool_releaseOrMint:testPoolMintSuccess() (gas: 89541)
BurnWithFromMintTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 14336)
BurnWithFromMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 55728)
BurnWithFromMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 201193)
BurnWithFromMintTokenPool_lockOrBurn:testPermissionsErrorReverts() (gas: 14362)
BurnWithFromMintTokenPool_lockOrBurn:testPoolBurnRevertNotHealthyReverts() (gas: 55754)
BurnWithFromMintTokenPool_lockOrBurn:testPoolBurnSuccess() (gas: 201214)
BurnWithFromMintTokenPool_lockOrBurn:testSetupSuccess() (gas: 20126)
CCIPClientExample_sanity:testExamples() (gas: 2218000)
CommitStore_constructor:testConstructorSuccess() (gas: 3344466)
CommitStore_isUnpausedAndARMHealthy:testARMSuccess() (gas: 71321)
Expand Down
8 changes: 6 additions & 2 deletions contracts/src/v0.8/ccip/pools/BurnFromMintTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import {IBurnMintERC20} from "../../shared/token/ERC20/IBurnMintERC20.sol";
import {TokenPool} from "./TokenPool.sol";
import {BurnMintTokenPoolAbstract} from "./BurnMintTokenPoolAbstract.sol";

import {SafeERC20} from "../../vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";

/// @notice This pool mints and burns a 3rd-party token.
/// @dev Pool whitelisting mode is set in the constructor and cannot be modified later.
/// It either accepts any address as originalSender, or only accepts whitelisted originalSender.
/// The only way to change whitelisting mode is to deploy a new pool.
/// If that is expected, please make sure the token's burner/minter roles are adjustable.
contract BurnFromMintTokenPool is BurnMintTokenPoolAbstract, ITypeAndVersion {
using SafeERC20 for IBurnMintERC20;

// solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables
string public constant override typeAndVersion = "BurnFromMintTokenPool 1.2.0";
string public constant override typeAndVersion = "BurnFromMintTokenPool 1.3.0-dev";

constructor(
IBurnMintERC20 token,
Expand All @@ -23,7 +27,7 @@ contract BurnFromMintTokenPool is BurnMintTokenPoolAbstract, ITypeAndVersion {
) TokenPool(token, allowlist, armProxy) {
// Some tokens allow burning from the sender without approval, but not all do.
// To be safe, we approve the pool to burn from the pool.
token.approve(address(this), type(uint256).max);
token.safeIncreaseAllowance(address(this), type(uint256).max);
}

/// @inheritdoc BurnMintTokenPoolAbstract
Expand Down
8 changes: 6 additions & 2 deletions contracts/src/v0.8/ccip/pools/BurnWithFromMintTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import {IBurnMintERC20} from "../../shared/token/ERC20/IBurnMintERC20.sol";
import {TokenPool} from "./TokenPool.sol";
import {BurnMintTokenPoolAbstract} from "./BurnMintTokenPoolAbstract.sol";

import {SafeERC20} from "../../vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol";

/// @notice This pool mints and burns a 3rd-party token.
/// @dev Pool whitelisting mode is set in the constructor and cannot be modified later.
/// It either accepts any address as originalSender, or only accepts whitelisted originalSender.
/// The only way to change whitelisting mode is to deploy a new pool.
/// If that is expected, please make sure the token's burner/minter roles are adjustable.
contract BurnWithFromMintTokenPool is BurnMintTokenPoolAbstract, ITypeAndVersion {
using SafeERC20 for IBurnMintERC20;

// solhint-disable-next-line chainlink-solidity/all-caps-constant-storage-variables
string public constant override typeAndVersion = "BurnWithFromMintTokenPool 1.2.0";
string public constant override typeAndVersion = "BurnWithFromMintTokenPool 1.3.0-dev";

constructor(
IBurnMintERC20 token,
Expand All @@ -23,7 +27,7 @@ contract BurnWithFromMintTokenPool is BurnMintTokenPoolAbstract, ITypeAndVersion
) TokenPool(token, allowlist, armProxy) {
// Some tokens allow burning from the sender without approval, but not all do.
// To be safe, we approve the pool to burn from the pool.
token.approve(address(this), type(uint256).max);
token.safeIncreaseAllowance(address(this), type(uint256).max);
}

/// @inheritdoc BurnMintTokenPoolAbstract
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/pools/USDC/USDCTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract USDCTokenPool is TokenPool, ITypeAndVersion {
i_tokenMessenger = tokenMessenger;
i_messageTransmitter = transmitter;
i_localDomainIdentifier = transmitter.localDomain();
i_token.safeApprove(address(i_tokenMessenger), type(uint256).max);
i_token.safeIncreaseAllowance(address(i_tokenMessenger), type(uint256).max);
emit ConfigSet(address(tokenMessenger));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ contract BurnFromMintTokenPoolSetup is BurnMintSetup {
}

contract BurnFromMintTokenPool_lockOrBurn is BurnFromMintTokenPoolSetup {
function testSetupSuccess() public {
assertEq(address(s_burnMintERC677), address(s_pool.getToken()));
assertEq(address(s_mockARM), s_pool.getArmProxy());
assertEq(false, s_pool.getAllowListEnabled());
assertEq(type(uint256).max, s_burnMintERC677.allowance(address(s_pool), address(s_pool)));
assertEq("BurnFromMintTokenPool 1.3.0-dev", s_pool.typeAndVersion());
}

function testPoolBurnSuccess() public {
uint256 burnAmount = 20_000e18;

Expand Down
7 changes: 7 additions & 0 deletions contracts/src/v0.8/ccip/test/pools/BurnMintTokenPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ contract BurnMintTokenPoolSetup is BurnMintSetup {
}

contract BurnMintTokenPool_lockOrBurn is BurnMintTokenPoolSetup {
function testSetupSuccess() public {
assertEq(address(s_burnMintERC677), address(s_pool.getToken()));
assertEq(address(s_mockARM), s_pool.getArmProxy());
assertEq(false, s_pool.getAllowListEnabled());
assertEq("BurnMintTokenPool 1.2.0", s_pool.typeAndVersion());
}

function testPoolBurnSuccess() public {
uint256 burnAmount = 20_000e18;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ contract BurnWithFromMintTokenPoolSetup is BurnMintSetup {
}

contract BurnWithFromMintTokenPool_lockOrBurn is BurnWithFromMintTokenPoolSetup {
function testSetupSuccess() public {
assertEq(address(s_burnMintERC677), address(s_pool.getToken()));
assertEq(address(s_mockARM), s_pool.getArmProxy());
assertEq(false, s_pool.getAllowListEnabled());
assertEq(type(uint256).max, s_burnMintERC677.allowance(address(s_pool), address(s_pool)));
assertEq("BurnWithFromMintTokenPool 1.3.0-dev", s_pool.typeAndVersion());
}

function testPoolBurnSuccess() public {
uint256 burnAmount = 20_000e18;

Expand Down
Loading

0 comments on commit 4b8569f

Please sign in to comment.