|
1 | 1 | // SPDX-License-Identifier: MIT
|
2 | 2 | pragma solidity ^0.8.27;
|
3 | 3 |
|
4 |
| -import { ResetPeriod } from "../types/ResetPeriod.sol"; |
5 |
| -import { Scope } from "../types/Scope.sol"; |
6 |
| - |
7 |
| -import { EfficiencyLib } from "./EfficiencyLib.sol"; |
8 |
| -import { IdLib } from "./IdLib.sol"; |
9 |
| -import { RegistrationLogic } from "./RegistrationLogic.sol"; |
10 |
| -import { TransferLogic } from "./TransferLogic.sol"; |
11 |
| -import { ValidityLib } from "./ValidityLib.sol"; |
| 4 | +import { ConstructorLogic } from "./ConstructorLogic.sol"; |
12 | 5 |
|
13 | 6 | import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
|
14 |
| -import { ISignatureTransfer } from "permit2/src/interfaces/ISignatureTransfer.sol"; |
15 | 7 |
|
16 |
| -contract DepositLogic is TransferLogic, RegistrationLogic { |
17 |
| - using IdLib for uint96; |
18 |
| - using IdLib for uint256; |
19 |
| - using IdLib for address; |
20 |
| - using EfficiencyLib for bool; |
21 |
| - using ValidityLib for address; |
| 8 | +contract DepositLogic is ConstructorLogic { |
22 | 9 | using SafeTransferLib for address;
|
23 | 10 |
|
24 | 11 | uint256 private constant _ERC6909_MASTER_SLOT_SEED = 0xedcaa89a82293940;
|
25 | 12 |
|
26 | 13 | /// @dev `keccak256(bytes("Transfer(address,address,address,uint256,uint256)"))`.
|
27 | 14 | uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0x1b3d7edb2e9c0b0e7c525b20aaaef0f5940d2ed71663c7d39266ecafac728859;
|
28 | 15 |
|
29 |
| - function _performBasicNativeTokenDeposit(address allocator) internal returns (uint256 id) { |
30 |
| - id = address(0).toIdIfRegistered(Scope.Multichain, ResetPeriod.TenMinutes, allocator); |
31 |
| - |
32 |
| - _deposit(msg.sender, id, msg.value); |
33 |
| - } |
34 |
| - |
35 |
| - function _processBatchDeposit(uint256[2][] calldata idsAndAmounts, address recipient) internal { |
36 |
| - _setReentrancyGuard(); |
37 |
| - uint256 totalIds = idsAndAmounts.length; |
38 |
| - bool firstUnderlyingTokenIsNative; |
39 |
| - uint256 id; |
40 |
| - |
41 |
| - assembly ("memory-safe") { |
42 |
| - let idsAndAmountsOffset := idsAndAmounts.offset |
43 |
| - id := calldataload(idsAndAmountsOffset) |
44 |
| - firstUnderlyingTokenIsNative := iszero(shr(96, shl(96, id))) |
45 |
| - // Revert if: |
46 |
| - // * the array is empty |
47 |
| - // * the callvalue is zero but the first token is native |
48 |
| - // * the callvalue is nonzero but the first token is non-native |
49 |
| - // * the first token is non-native and the callvalue doesn't equal the first amount |
50 |
| - if or(iszero(totalIds), or(eq(firstUnderlyingTokenIsNative, iszero(callvalue())), and(firstUnderlyingTokenIsNative, iszero(eq(callvalue(), calldataload(add(idsAndAmountsOffset, 0x20))))))) |
51 |
| - { |
52 |
| - // revert InvalidBatchDepositStructure() |
53 |
| - mstore(0, 0xca0fc08e) |
54 |
| - revert(0x1c, 0x04) |
55 |
| - } |
56 |
| - } |
57 |
| - |
58 |
| - uint96 currentAllocatorId = id.toRegisteredAllocatorId(); |
59 |
| - |
60 |
| - if (firstUnderlyingTokenIsNative) { |
61 |
| - _deposit(recipient, id, msg.value); |
62 |
| - } |
63 |
| - |
64 |
| - unchecked { |
65 |
| - for (uint256 i = firstUnderlyingTokenIsNative.asUint256(); i < totalIds; ++i) { |
66 |
| - uint256[2] calldata idAndAmount = idsAndAmounts[i]; |
67 |
| - id = idAndAmount[0]; |
68 |
| - uint256 amount = idAndAmount[1]; |
69 |
| - |
70 |
| - uint96 newAllocatorId = id.toAllocatorId(); |
71 |
| - if (newAllocatorId != currentAllocatorId) { |
72 |
| - newAllocatorId.mustHaveARegisteredAllocator(); |
73 |
| - currentAllocatorId = newAllocatorId; |
74 |
| - } |
75 |
| - |
76 |
| - _transferAndDeposit(id.toToken(), recipient, id, amount); |
77 |
| - } |
78 |
| - } |
79 |
| - |
80 |
| - _clearReentrancyGuard(); |
81 |
| - } |
82 |
| - |
83 |
| - function _performBasicERC20Deposit(address token, address allocator, uint256 amount) internal returns (uint256 id) { |
84 |
| - id = token.excludingNative().toIdIfRegistered(Scope.Multichain, ResetPeriod.TenMinutes, allocator); |
85 |
| - |
86 |
| - _transferAndDepositWithReentrancyGuard(token, msg.sender, id, amount); |
87 |
| - } |
88 |
| - |
89 |
| - function _performCustomNativeTokenDeposit(address allocator, ResetPeriod resetPeriod, Scope scope, address recipient) internal returns (uint256 id) { |
90 |
| - id = address(0).toIdIfRegistered(scope, resetPeriod, allocator); |
91 |
| - |
92 |
| - _deposit(recipient, id, msg.value); |
93 |
| - } |
94 |
| - |
95 |
| - function _performCustomERC20Deposit(address token, address allocator, ResetPeriod resetPeriod, Scope scope, uint256 amount, address recipient) internal returns (uint256 id) { |
96 |
| - id = token.excludingNative().toIdIfRegistered(scope, resetPeriod, allocator); |
97 |
| - |
98 |
| - _transferAndDepositWithReentrancyGuard(token, recipient, id, amount); |
99 |
| - } |
100 |
| - |
101 | 16 | /// @dev Retrieves a token balance, compares against `initialBalance`, and mints the resulting balance
|
102 | 17 | /// change of `id` to `to`. Emits a {Transfer} event.
|
103 | 18 | function _checkBalanceAndDeposit(address token, address to, uint256 id, uint256 initialBalance) internal {
|
@@ -143,24 +58,4 @@ contract DepositLogic is TransferLogic, RegistrationLogic {
|
143 | 58 | log4(0, 0x40, _TRANSFER_EVENT_SIGNATURE, 0, recipient, id)
|
144 | 59 | }
|
145 | 60 | }
|
146 |
| - |
147 |
| - /// @dev Transfers `amount` of `token` and mints the resulting balance change of `id` to `to`. |
148 |
| - /// Emits a {Transfer} event. |
149 |
| - function _transferAndDeposit(address token, address to, uint256 id, uint256 amount) private { |
150 |
| - uint256 initialBalance = token.balanceOf(address(this)); |
151 |
| - |
152 |
| - token.safeTransferFrom(msg.sender, address(this), amount); |
153 |
| - |
154 |
| - _checkBalanceAndDeposit(token, to, id, initialBalance); |
155 |
| - } |
156 |
| - |
157 |
| - /// @dev Transfers `amount` of `token` and mints the resulting balance change of `id` to `to`. |
158 |
| - /// Emits a {Transfer} event. |
159 |
| - function _transferAndDepositWithReentrancyGuard(address token, address to, uint256 id, uint256 amount) private { |
160 |
| - _setReentrancyGuard(); |
161 |
| - |
162 |
| - _transferAndDeposit(token, to, id, amount); |
163 |
| - |
164 |
| - _clearReentrancyGuard(); |
165 |
| - } |
166 | 61 | }
|
0 commit comments