Skip to content

Commit

Permalink
remove increaseAllowance and decreaseAllowance from tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalgek committed Apr 3, 2024
1 parent 624219c commit 5f86091
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 462 deletions.
30 changes: 0 additions & 30 deletions contracts/arbitrum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 0 additions & 30 deletions contracts/optimism/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 0 additions & 32 deletions contracts/token/ERC20Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions contracts/token/ERC20Rebasable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
169 changes: 0 additions & 169 deletions test/token/ERC20Bridged.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 5f86091

Please sign in to comment.