-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathERC20Outbox.sol
More file actions
39 lines (32 loc) · 1.59 KB
/
ERC20Outbox.sol
File metadata and controls
39 lines (32 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.9;
import "./AbsOutbox.sol";
import {IERC20Bridge} from "./IERC20Bridge.sol";
import {DecimalsConverterHelper} from "../libraries/DecimalsConverterHelper.sol";
contract ERC20Outbox is AbsOutbox {
/// @dev it is assumed that arb-os never assigns this value to a valid leaf to be redeemed
uint256 private constant AMOUNT_DEFAULT_CONTEXT = type(uint256).max;
function l2ToL1WithdrawalAmount() external view returns (uint256) {
uint256 amount = context.withdrawalAmount;
if (amount == AMOUNT_DEFAULT_CONTEXT) return 0;
return amount;
}
/// @inheritdoc AbsOutbox
function _defaultContextAmount() internal pure override returns (uint256) {
// we use type(uint256).max as representation of 0 native token withdrawal amount
return AMOUNT_DEFAULT_CONTEXT;
}
/// @inheritdoc AbsOutbox
function _getAmountToUnlock(uint256 value) internal view override returns (uint256) {
uint8 nativeTokenDecimals = IERC20Bridge(address(bridge)).nativeTokenDecimals();
// this might revert due to overflow, but we assume the token supply is less than 2^256
return DecimalsConverterHelper.adjustDecimals(value, 18, nativeTokenDecimals);
}
/// @inheritdoc AbsOutbox
function _amountToSetInContext(uint256 value) internal pure override returns (uint256) {
// native token withdrawal amount which can be fetched from context
return value;
}
}