diff --git a/contracts/arbitrum/README.md b/contracts/arbitrum/README.md index cf76c5c1..26f3c4fb 100644 --- a/contracts/arbitrum/README.md +++ b/contracts/arbitrum/README.md @@ -695,36 +695,6 @@ Returns a `bool` value indicating whether the operation succeeded. Transfers `amount` of token from the `from_` account to `to_` using the allowance mechanism. `amount_` is then deducted from the caller's allowance. Returns a `bool` value indicating whether the operation succeed. -#### `increaseAllowance(address,uint256)` - -> **Visibility:**     `external` -> -> **Returns**        `(bool)` -> -> **Arguments:** -> -> - **`spender_`** - an address of the tokens spender -> - **`addedValue_`** - a number to increase allowance -> -> **Emits:** `Approval(address indexed owner, address indexed spender, uint256 value)` - -Atomically increases the allowance granted to `spender` by the caller. Returns a `bool` value indicating whether the operation succeed. - -#### `decreaseAllowance(address,uint256)` - -> **Visibility:**     `external` -> -> **Returns**        `(bool)` -> -> **Arguments:** -> -> - **`spender_`** - an address of the tokens spender -> - **`subtractedValue_`** - a number to decrease allowance -> -> **Emits:** `Approval(address indexed owner, address indexed spender, uint256 value)` - -Atomically decreases the allowance granted to `spender` by the caller. Returns a `bool` value indicating whether the operation succeed. - ## `ERC20Bridged` **Implements:** [`IERC20Bridged`](https://github.com/lidofinance/lido-l2/blob/main/contracts/token/interfaces/IERC20Bridged.sol) diff --git a/contracts/optimism/README.md b/contracts/optimism/README.md index 598f7b99..954556d6 100644 --- a/contracts/optimism/README.md +++ b/contracts/optimism/README.md @@ -512,36 +512,6 @@ Returns a `bool` value indicating whether the operation succeeded. Transfers `amount` of token from the `from_` account to `to_` using the allowance mechanism. `amount_` is then deducted from the caller's allowance. Returns a `bool` value indicating whether the operation succeed. -#### `increaseAllowance(address,uint256)` - -> **Visibility:**     `external` -> -> **Returns**        `(bool)` -> -> **Arguments:** -> -> - **`spender_`** - an address of the tokens spender -> - **`addedValue_`** - a number to increase allowance -> -> **Emits:** `Approval(address indexed owner, address indexed spender, uint256 value)` - -Atomically increases the allowance granted to `spender` by the caller. Returns a `bool` value indicating whether the operation succeed. - -#### `decreaseAllowance(address,uint256)` - -> **Visibility:**     `external` -> -> **Returns**        `(bool)` -> -> **Arguments:** -> -> - **`spender_`** - an address of the tokens spender -> - **`subtractedValue_`** - a number to decrease allowance -> -> **Emits:** `Approval(address indexed owner, address indexed spender, uint256 value)` - -Atomically decreases the allowance granted to `spender` by the caller. Returns a `bool` value indicating whether the operation succeed. - ## `ERC20Bridged` **Implements:** [`IERC20Bridged`](https://github.com/lidofinance/lido-l2/blob/main/contracts/token/interfaces/IERC20Bridged.sol) diff --git a/contracts/token/ERC20Core.sol b/contracts/token/ERC20Core.sol index bf4e67db..354c28bd 100644 --- a/contracts/token/ERC20Core.sol +++ b/contracts/token/ERC20Core.sol @@ -44,38 +44,6 @@ contract ERC20Core is IERC20 { return true; } - /// @notice Atomically increases the allowance granted to spender by the caller. - /// @param spender_ An address of the tokens spender - /// @param addedValue_ An amount to increase the allowance - function increaseAllowance(address spender_, uint256 addedValue_) - external - returns (bool) - { - _approve( - msg.sender, - spender_, - allowance[msg.sender][spender_] + addedValue_ - ); - return true; - } - - /// @notice Atomically decreases the allowance granted to spender by the caller. - /// @param spender_ An address of the tokens spender - /// @param subtractedValue_ An amount to decrease the allowance - function decreaseAllowance(address spender_, uint256 subtractedValue_) - external - returns (bool) - { - uint256 currentAllowance = allowance[msg.sender][spender_]; - if (currentAllowance < subtractedValue_) { - revert ErrorDecreasedAllowanceBelowZero(); - } - unchecked { - _approve(msg.sender, spender_, currentAllowance - subtractedValue_); - } - return true; - } - /// @dev Moves amount_ of tokens from sender_ to recipient_ /// @param from_ An address of the sender of the tokens /// @param to_ An address of the recipient of the tokens diff --git a/contracts/token/ERC20Rebasable.sol b/contracts/token/ERC20Rebasable.sol index 81c4eb09..ba69ba13 100644 --- a/contracts/token/ERC20Rebasable.sol +++ b/contracts/token/ERC20Rebasable.sol @@ -161,38 +161,6 @@ contract ERC20Rebasable is IERC20, IERC20Wrapper, IERC20BridgedShares, ERC20Meta return true; } - /// @notice Atomically increases the allowance granted to spender by the caller. - /// @param spender_ An address of the tokens spender - /// @param addedValue_ An amount to increase the allowance - function increaseAllowance(address spender_, uint256 addedValue_) - external - returns (bool) - { - _approve( - msg.sender, - spender_, - _getTokenAllowance()[msg.sender][spender_] + addedValue_ - ); - return true; - } - - /// @notice Atomically decreases the allowance granted to spender by the caller. - /// @param spender_ An address of the tokens spender - /// @param subtractedValue_ An amount to decrease the allowance - function decreaseAllowance(address spender_, uint256 subtractedValue_) - external - returns (bool) - { - uint256 currentAllowance = _getTokenAllowance()[msg.sender][spender_]; - if (currentAllowance < subtractedValue_) { - revert ErrorDecreasedAllowanceBelowZero(); - } - unchecked { - _approve(msg.sender, spender_, currentAllowance - subtractedValue_); - } - return true; - } - function _getTokenAllowance() internal pure returns (mapping(address => mapping(address => uint256)) storage) { return TOKEN_ALLOWANCE_POSITION.storageMapAddressMapAddressUint256(); } diff --git a/test/token/ERC20Bridged.unit.test.ts b/test/token/ERC20Bridged.unit.test.ts index 2ec65bfa..a3359635 100644 --- a/test/token/ERC20Bridged.unit.test.ts +++ b/test/token/ERC20Bridged.unit.test.ts @@ -306,175 +306,6 @@ unit("ERC20Bridged", ctxFactory) ); }) - .test("increaseAllowance() :: initial allowance is zero", async (ctx) => { - const { erc20Bridged } = ctx; - const { holder, spender } = ctx.accounts; - - // validate allowance before increasing - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - "0" - ); - - const allowanceIncrease = wei`1 ether`; - - // increase allowance - const tx = await erc20Bridged.increaseAllowance( - spender.address, - allowanceIncrease - ); - - // validate Approval event was emitted - await assert.emits(erc20Bridged, tx, "Approval", [ - holder.address, - spender.address, - allowanceIncrease, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - allowanceIncrease - ); - }) - - .test("increaseAllowance() :: initial allowance is not zero", async (ctx) => { - const { erc20Bridged } = ctx; - const { holder, spender } = ctx.accounts; - - const initialAllowance = wei`2 ether`; - - // set initial allowance - await erc20Bridged.approve(spender.address, initialAllowance); - - // validate allowance before increasing - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - initialAllowance - ); - - const allowanceIncrease = wei`1 ether`; - - // increase allowance - const tx = await erc20Bridged.increaseAllowance( - spender.address, - allowanceIncrease - ); - - const expectedAllowance = wei - .toBigNumber(initialAllowance) - .add(allowanceIncrease); - - // validate Approval event was emitted - await assert.emits(erc20Bridged, tx, "Approval", [ - holder.address, - spender.address, - expectedAllowance, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - expectedAllowance - ); - }) - - .test("increaseAllowance() :: the increase is not zero", async (ctx) => { - const { erc20Bridged } = ctx; - const { holder, spender } = ctx.accounts; - - const initialAllowance = wei`2 ether`; - - // set initial allowance - await erc20Bridged.approve(spender.address, initialAllowance); - - // validate allowance before increasing - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - initialAllowance - ); - - // increase allowance - const tx = await erc20Bridged.increaseAllowance(spender.address, "0"); - - // validate Approval event was emitted - await assert.emits(erc20Bridged, tx, "Approval", [ - holder.address, - spender.address, - initialAllowance, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - initialAllowance - ); - }) - - .test( - "decreaseAllowance() :: decrease is greater than current allowance", - async (ctx) => { - const { erc20Bridged } = ctx; - const { holder, spender } = ctx.accounts; - - // validate allowance before increasing - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - "0" - ); - - const allowanceDecrease = wei`1 ether`; - - // decrease allowance - await assert.revertsWith( - erc20Bridged.decreaseAllowance(spender.address, allowanceDecrease), - "ErrorDecreasedAllowanceBelowZero()" - ); - } - ) - - .group([wei`1 ether`, "0"], (allowanceDecrease) => [ - `decreaseAllowance() :: the decrease is ${allowanceDecrease} wei`, - async (ctx) => { - const { erc20Bridged } = ctx; - const { holder, spender } = ctx.accounts; - - const initialAllowance = wei`2 ether`; - - // set initial allowance - await erc20Bridged.approve(spender.address, initialAllowance); - - // validate allowance before increasing - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - initialAllowance - ); - - // decrease allowance - const tx = await erc20Bridged.decreaseAllowance( - spender.address, - allowanceDecrease - ); - - const expectedAllowance = wei - .toBigNumber(initialAllowance) - .sub(allowanceDecrease); - - // validate Approval event was emitted - await assert.emits(erc20Bridged, tx, "Approval", [ - holder.address, - spender.address, - expectedAllowance, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await erc20Bridged.allowance(holder.address, spender.address), - expectedAllowance - ); - }, - ]) - .test("bridgeMint() :: not owner", async (ctx) => { const { erc20Bridged } = ctx; const { stranger } = ctx.accounts; diff --git a/test/token/ERC20Rebasable.unit.test.ts b/test/token/ERC20Rebasable.unit.test.ts index b8cb3e47..201a1551 100644 --- a/test/token/ERC20Rebasable.unit.test.ts +++ b/test/token/ERC20Rebasable.unit.test.ts @@ -706,175 +706,6 @@ unit("ERC20Rebasable", ctxFactory) ); }) - .test("increaseAllowance() :: initial allowance is zero", async (ctx) => { - const { rebasableProxied } = ctx.contracts; - const { holder, spender } = ctx.accounts; - - // validate allowance before increasing - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - "0" - ); - - const allowanceIncrease = wei`1 ether`; - - // increase allowance - const tx = await rebasableProxied.increaseAllowance( - spender.address, - allowanceIncrease - ); - - // validate Approval event was emitted - await assert.emits(rebasableProxied, tx, "Approval", [ - holder.address, - spender.address, - allowanceIncrease, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - allowanceIncrease - ); - }) - - .test("increaseAllowance() :: initial allowance is not zero", async (ctx) => { - const { rebasableProxied } = ctx.contracts; - const { holder, spender } = ctx.accounts; - - const initialAllowance = wei`2 ether`; - - // set initial allowance - await rebasableProxied.approve(spender.address, initialAllowance); - - // validate allowance before increasing - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - initialAllowance - ); - - const allowanceIncrease = wei`1 ether`; - - // increase allowance - const tx = await rebasableProxied.increaseAllowance( - spender.address, - allowanceIncrease - ); - - const expectedAllowance = wei - .toBigNumber(initialAllowance) - .add(allowanceIncrease); - - // validate Approval event was emitted - await assert.emits(rebasableProxied, tx, "Approval", [ - holder.address, - spender.address, - expectedAllowance, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - expectedAllowance - ); - }) - - .test("increaseAllowance() :: the increase is not zero", async (ctx) => { - const { rebasableProxied } = ctx.contracts; - const { holder, spender } = ctx.accounts; - - const initialAllowance = wei`2 ether`; - - // set initial allowance - await rebasableProxied.approve(spender.address, initialAllowance); - - // validate allowance before increasing - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - initialAllowance - ); - - // increase allowance - const tx = await rebasableProxied.increaseAllowance(spender.address, "0"); - - // validate Approval event was emitted - await assert.emits(rebasableProxied, tx, "Approval", [ - holder.address, - spender.address, - initialAllowance, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - initialAllowance - ); - }) - - .test( - "decreaseAllowance() :: decrease is greater than current allowance", - async (ctx) => { - const { rebasableProxied } = ctx.contracts; - const { holder, spender } = ctx.accounts; - - // validate allowance before increasing - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - "0" - ); - - const allowanceDecrease = wei`1 ether`; - - // decrease allowance - await assert.revertsWith( - rebasableProxied.decreaseAllowance(spender.address, allowanceDecrease), - "ErrorDecreasedAllowanceBelowZero()" - ); - } - ) - - .group([wei`1 ether`, "0"], (allowanceDecrease) => [ - `decreaseAllowance() :: the decrease is ${allowanceDecrease} wei`, - async (ctx) => { - const { rebasableProxied } = ctx.contracts; - const { holder, spender } = ctx.accounts; - - const initialAllowance = wei`2 ether`; - - // set initial allowance - await rebasableProxied.approve(spender.address, initialAllowance); - - // validate allowance before increasing - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - initialAllowance - ); - - // decrease allowance - const tx = await rebasableProxied.decreaseAllowance( - spender.address, - allowanceDecrease - ); - - const expectedAllowance = wei - .toBigNumber(initialAllowance) - .sub(allowanceDecrease); - - // validate Approval event was emitted - await assert.emits(rebasableProxied, tx, "Approval", [ - holder.address, - spender.address, - expectedAllowance, - ]); - - // validate allowance was updated correctly - assert.equalBN( - await rebasableProxied.allowance(holder.address, spender.address), - expectedAllowance - ); - }, - ]) - .test("bridgeMint() :: not owner", async (ctx) => { const { rebasableProxied } = ctx.contracts; const { stranger } = ctx.accounts;