Address Contract Partially Verified
Address
0x3f671e11b07080950F0cAc8602F418C66cC05899
Balance
0 ETH
Nonce
1
Code Size
4829 bytes
Creator
0x057E3986...1860 at tx 0x078e6a00...dfa00b
Indexed Transactions
0
Contract Bytecode
4829 bytes
0x6080604052600436106100c1575f3560e01c80636c5ffe9c1161007c578063abc2840d11610057578063abc2840d14610250578063cea8054a1461026f578063f2fde38b1461028e578063fb167dea146102ad575f5ffd5b80636c5ffe9c146101ed578063715018a6146102205780638da5cb5b14610234575f5ffd5b806264934a146101005780630baef8b5146101325780630d5847ed14610151578063211dbfd21461019c57806345092201146101bb5780635f3e849f146101ce575f5ffd5b366100fc573373c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2146100fa57604051637e8abdaf60e01b815260040160405180910390fd5b005b5f5ffd5b34801561010b575f5ffd5b5061011f61011a366004610ff5565b6102cc565b6040519081526020015b60405180910390f35b34801561013d575f5ffd5b5061011f61014c36600461102a565b6103a3565b34801561015c575f5ffd5b506101847f000000000000000000000000aad0a80fb8f0da4799e457b5ae8ea70fa61a45fc81565b6040516001600160a01b039091168152602001610129565b3480156101a7575f5ffd5b5061011f6101b636600461102a565b61046e565b61011f6101c9366004611092565b6106c8565b3480156101d9575f5ffd5b506100fa6101e83660046110bc565b610704565b3480156101f8575f5ffd5b506101847f000000000000000000000000734eec7930bc84ec5732022b9eb949a81fb89abe81565b34801561022b575f5ffd5b506100fa61073d565b34801561023f575f5ffd5b505f546001600160a01b0316610184565b34801561025b575f5ffd5b5061011f61026a36600461102a565b610750565b34801561027a575f5ffd5b5061011f610289366004610ff5565b61080f565b348015610299575f5ffd5b506100fa6102a83660046110e9565b6108de565b3480156102b8575f5ffd5b5061011f6102c7366004610ff5565b610920565b5f6001600160a01b0383166102f45760405163e99d5ac560e01b815260040160405180910390fd5b5f198403610370576040516370a0823160e01b815233600482015273ae7ab96520de3a18e5e111b5eaab095312d7fe84906370a0823190602401602060405180830381865afa158015610349573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061036d919061110b565b93505b61039073ae7ab96520de3a18e5e111b5eaab095312d7fe843330876109ef565b61039b848484610a5c565b949350505050565b5f6001600160a01b0387166103cb5760405163e99d5ac560e01b815260040160405180910390fd5b60405163d505accf60e01b815273ae7ab96520de3a18e5e111b5eaab095312d7fe849063d505accf9061040e90339030908d908b908b908b908b90600401611122565b5f604051808303815f87803b158015610425575f5ffd5b505af1925050508015610436575060015b5061045773ae7ab96520de3a18e5e111b5eaab095312d7fe8433308b6109ef565b610462888888610a5c565b98975050505050505050565b5f6001600160a01b0387166104965760405163e99d5ac560e01b815260040160405180910390fd5b60405163927da10560e01b815233600482015273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc260248201523060448201525f906e22d473030f116ddee9f6b43ac78ba39063927da10590606401606060405180830381865afa158015610500573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610524919061117d565b6040805160e08101825273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2606082019081526001600160a01b038f16608083015265ffffffffffff60a08301819052841660c08301528152306020808301919091528183018c905291519295506e22d473030f116ddee9f6b43ac78ba39450632b67b5709350339290916105d1918a918a9160f88e901b910192835260208301919091526001600160f81b031916604082015260410190565b6040516020818303038152906040526040518463ffffffff1660e01b81526004016105fe93929190611202565b5f604051808303815f87803b158015610615575f5ffd5b505af1925050508015610626575060015b50604051631b63c28b60e11b81523360048201523060248201526001600160a01b038a16604482015273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc260648201526e22d473030f116ddee9f6b43ac78ba3906336c78516906084015f604051808303815f87803b15801561069a575f5ffd5b505af11580156106ac573d5f5f3e3d5ffd5b505050506106bb898989610ae9565b9998505050505050505050565b5f6001600160a01b0383166106f05760405163e99d5ac560e01b815260040160405180910390fd5b6106fb348484610b52565b90505b92915050565b61070c610c7d565b6001600160a01b038316610729576107248282610ca9565b505050565b6107246001600160a01b0384168383610d08565b610745610c7d565b61074e5f610d39565b565b5f6001600160a01b0387166107785760405163e99d5ac560e01b815260040160405180910390fd5b60405163d505accf60e01b8152737f39c581f595b53c5cb19bd0b3f8da6c935e2ca09063d505accf906107bb90339030908d908b908b908b908b90600401611122565b5f604051808303815f87803b1580156107d2575f5ffd5b505af19250505080156107e3575060015b50610804737f39c581f595b53c5cb19bd0b3f8da6c935e2ca033308b6109ef565b610462888888610d88565b5f6001600160a01b0383166108375760405163e99d5ac560e01b815260040160405180910390fd5b5f1984036108b3576040516370a0823160e01b815233600482015273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906370a0823190602401602060405180830381865afa15801561088c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108b0919061110b565b93505b6108d373c02aaa39b223fe8d0a0e5c4f27ead9083c756cc23330876109ef565b61039b848484610ae9565b6108e6610c7d565b6001600160a01b03811661091457604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b61091d81610d39565b50565b5f6001600160a01b0383166109485760405163e99d5ac560e01b815260040160405180910390fd5b5f1984036109c4576040516370a0823160e01b8152336004820152737f39c581f595b53c5cb19bd0b3f8da6c935e2ca0906370a0823190602401602060405180830381865afa15801561099d573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109c1919061110b565b93505b6109e4737f39c581f595b53c5cb19bd0b3f8da6c935e2ca03330876109ef565b61039b848484610d88565b6040516001600160a01b038481166024830152838116604483015260648201839052610a569186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050610f75565b50505050565b604051630ea598cb60e41b8152600481018490525f908190737f39c581f595b53c5cb19bd0b3f8da6c935e2ca09063ea598cb0906024016020604051808303815f875af1158015610aaf573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ad3919061110b565b9050610ae0818585610d88565b95945050505050565b604051632e1a7d4d60e01b8152600481018490525f9073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d906024015f604051808303815f87803b158015610b35575f5ffd5b505af1158015610b47573d5f5f3e3d5ffd5b5050505061039b8484845b6040516370a0823160e01b81523060048201525f908190737f39c581f595b53c5cb19bd0b3f8da6c935e2ca0906370a0823190602401602060405180830381865afa158015610ba3573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bc7919061110b565b9050610be7737f39c581f595b53c5cb19bd0b3f8da6c935e2ca086610ca9565b6040516370a0823160e01b81523060048201525f908290737f39c581f595b53c5cb19bd0b3f8da6c935e2ca0906370a0823190602401602060405180830381865afa158015610c38573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c5c919061110b565b610c669190611288565b9050610c73818686610d88565b9695505050505050565b5f546001600160a01b0316331461074e5760405163118cdaa760e01b815233600482015260240161090b565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f8114610cf2576040519150601f19603f3d011682016040523d82523d5f602084013e610cf7565b606091505b5050905080610724573d5f5f3e3d5ffd5b6040516001600160a01b0383811660248301526044820183905261072491859182169063a9059cbb90606401610a24565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516370a0823160e01b81523060048201525f9081906001600160a01b037f000000000000000000000000734eec7930bc84ec5732022b9eb949a81fb89abe16906370a0823190602401602060405180830381865afa158015610dee573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e12919061110b565b604051639f1d0f5960e01b8152737f39c581f595b53c5cb19bd0b3f8da6c935e2ca0600482015260248101879052604481018590529091507f000000000000000000000000aad0a80fb8f0da4799e457b5ae8ea70fa61a45fc6001600160a01b031690639f1d0f59906064015f604051808303815f87803b158015610e95575f5ffd5b505af1158015610ea7573d5f5f3e3d5ffd5b50506040516370a0823160e01b81523060048201525f92508391506001600160a01b037f000000000000000000000000734eec7930bc84ec5732022b9eb949a81fb89abe16906370a0823190602401602060405180830381865afa158015610f11573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f35919061110b565b610f3f9190611288565b9050610ae06001600160a01b037f000000000000000000000000734eec7930bc84ec5732022b9eb949a81fb89abe168683610d08565b5f5f60205f8451602086015f885af180610f94576040513d5f823e3d81fd5b50505f513d91508115610fab578060011415610fb8565b6001600160a01b0384163b155b15610a5657604051635274afe760e01b81526001600160a01b038516600482015260240161090b565b6001600160a01b038116811461091d575f5ffd5b5f5f5f60608486031215611007575f5ffd5b83359250602084013561101981610fe1565b929592945050506040919091013590565b5f5f5f5f5f5f5f60e0888a031215611040575f5ffd5b87359650602088013561105281610fe1565b95506040880135945060608801359350608088013560ff81168114611075575f5ffd5b9699959850939692959460a0840135945060c09093013592915050565b5f5f604083850312156110a3575f5ffd5b82356110ae81610fe1565b946020939093013593505050565b5f5f5f606084860312156110ce575f5ffd5b83356110d981610fe1565b9250602084013561101981610fe1565b5f602082840312156110f9575f5ffd5b813561110481610fe1565b9392505050565b5f6020828403121561111b575f5ffd5b5051919050565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b805165ffffffffffff81168114611178575f5ffd5b919050565b5f5f5f6060848603121561118f575f5ffd5b835161119a81610fe1565b92506111a860208501611163565b91506111b660408501611163565b90509250925092565b5f81518084525f5b818110156111e3576020818501810151868301820152016111c7565b505f602082860101526020601f19601f83011685010191505092915050565b60018060a01b03841681525f835160018060a01b03815116602084015260018060a01b03602082015116604084015265ffffffffffff604082015116606084015265ffffffffffff60608201511660808401525060018060a01b0360208501511660a0830152604084015160c083015261010060e0830152610ae06101008301846111bf565b818103818111156106fe57634e487b7160e01b5f52601160045260245ffdfea2646970667358221220a56da004796f39cdd15b2369ae4630e96ff57a157c2906d217ae3741fd842ce464736f6c634300081c0033
Verified Source Code Partial Match
Compiler: v0.8.28+commit.7893614a
EVM: shanghai
Optimization: Yes (200 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
SafeERC20.sol 199 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
constants.sol 46 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.28;
/* Contracts */
bytes32 constant CONTRACT_TOKEN_MAPPING = keccak256("CONTRACT_TOKEN_MAPPING");
bytes32 constant CONTRACT_ORACLE = keccak256("CONTRACT_ORACLE");
bytes32 constant CONTRACT_TREASURY = keccak256("CONTRACT_TREASURY");
bytes32 constant CONTRACT_YIELD_TREASURY = keccak256("CONTRACT_YIELD_TREASURY");
bytes32 constant CONTRACT_DAO_COLLATERAL = keccak256("CONTRACT_DAO_COLLATERAL");
bytes32 constant CONTRACT_ETH0 = keccak256("CONTRACT_ETH0");
/* Registry */
bytes32 constant CONTRACT_REGISTRY = keccak256("CONTRACT_REGISTRY"); // Not set on production
/* Mainnet USD0 Deployment */
address constant REGISTRY_CONTRACT_MAINNET = 0x0594cb5ca47eFE1Ff25C7B8B43E221683B4Db34c;
address constant USUAL_USD0_MAINNET = 0x73A15FeD60Bf67631dC6cd7Bc5B6e8da8190aCF5;
address constant USUAL_USD0PP_MAINNET = 0x35D8949372D46B7a3D5A56006AE77B215fc69bC0;
address constant USUAL_M_MAINNET = 0x4Cbc25559DbBD1272EC5B64c7b5F48a2405e6470;
address constant USUAL_USDTB_MAINNET = 0x58073531a2809744D1bF311D30FD76B27D662abB;
address constant USUAL_USL_MAINNET = 0xd001f0a15D272542687b2677BA627f48A4333b5d;
address constant USDTB_MAINNET = 0xC139190F447e929f090Edeb554D95AbB8b18aC1C;
address constant USYC_MAINNET = 0x136471a34f6ef19fE571EFFC1CA711fdb8E49f2b;
/* Mainnet ETH0 Deployment */
address constant ETH0_REGISTRY_CONTRACT_MAINNET = 0xfE35066Ce9b91026E0C0056d6F4520e409B793cA;
address constant WETH_MAINNET = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant STETH_MAINNET = 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;
address constant WSTETH_MAINNET = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;
/* Constants */
uint256 constant SCALAR_ONE = 1e18;
/* Oracles */
address constant USUAL_USD0_ORACLE = 0x7e891DEbD8FA0A4Cf6BE58Ddff5a8ca174FebDCB;
address constant USUAL_USD0PP_ORACLE = 0xFC9e30Cf89f8A00dba3D34edf8b65BCDAdeCC1cB;
address constant USUAL_M_ORACLE = 0x51A01E76Be1ff5F98AF7D45F6224110888CdE7FC;
address constant USUAL_USDTB_ORACLE = 0xD96f2aD5F40fCe3FfFa7a06e7d7ac5bacfD8E987;
address constant USUAL_USL_ORACLE = 0xe1DeE60c516a8350704Ec24a6E856c9F533d1c1b;
address constant USDTB_ORACLE = 0xD96f2aD5F40fCe3FfFa7a06e7d7ac5bacfD8E987;
address constant USYC_ORACLE = 0x4c48bcb2160F8e0aDbf9D4F3B034f1e36d1f8b3e;
address constant USDC_ORACLE = 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6;
/* Others */
address constant PERMIT2_MAINNET = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
errors.sol 5 lines
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.28; error NullAddress();
IDaoCollateral.sol 259 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.28;
struct Approval {
uint256 deadline;
uint8 v; // Changes at each new signature because of ERC20 Permit nonce
bytes32 r;
bytes32 s;
}
struct Intent {
address recipient;
address rwaToken;
uint256 amountInTokenDecimals;
uint256 deadline;
bytes signature;
}
interface IDaoCollateral {
/*//////////////////////////////////////////////////////////////
Events
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when tokens are swapped.
/// @param owner The address of the owner
/// @param tokenSwapped The address of the token swapped
/// @param amount The amount of tokens swapped
/// @param amountInUSD The amount in USD
event Swap(
address indexed owner, address indexed tokenSwapped, uint256 amount, uint256 amountInUSD
);
/// @notice Emitted when tokens are redeemed.
/// @param redeemer The address of the redeemer
/// @param rwaToken The address of the rwaToken
/// @param amountRedeemed The amount of tokens redeemed
/// @param returnedRwaAmount The amount of rwaToken returned
/// @param stableFeeAmount The amount of stableToken fee
event Redeem(
address indexed redeemer,
address indexed rwaToken,
uint256 amountRedeemed,
uint256 returnedRwaAmount,
uint256 stableFeeAmount
);
/// @notice Emitted when an intent is matched.
/// @param owner The address of the owner
/// @param nonce The nonce of the intent
/// @param tokenSwapped The address of the token swapped
/// @param amountInTokenDecimals The amount in token decimals
/// @param amountInUSD The amount in USD
event IntentMatched(
address indexed owner,
uint256 indexed nonce,
address indexed tokenSwapped,
uint256 amountInTokenDecimals,
uint256 amountInUSD
);
/// @notice Emitted when an intent and associated nonce is consumed.
/// @param owner The address of the owner
/// @param nonce The nonce of the intent
/// @param tokenSwapped The address of the token swapped
/// @param totalAmountInTokenDecimals The total amount in token decimals
event IntentConsumed(
address indexed owner,
uint256 indexed nonce,
address indexed tokenSwapped,
uint256 totalAmountInTokenDecimals
);
/// @notice Emitted when a nonce is invalidated.
/// @param signer The address of the signer
/// @param nonceInvalidated The nonce of the intent
event NonceInvalidated(address indexed signer, uint256 indexed nonceInvalidated);
/// @notice Emitted when redeem functionality is paused.
event RedeemPaused();
/// @notice Emitted when redeem functionality is unpaused.
event RedeemUnPaused();
/// @notice Emitted when swap functionality is paused.
event SwapPaused();
/// @notice Emitted when swap functionality is unpaused.
event SwapUnPaused();
/// @notice Emitted when the Counter Bank Run (CBR) mechanism is activated.
/// @param cbrCoef The Counter Bank Run (CBR) coefficient.
event CBRActivated(uint256 cbrCoef);
/// @notice Emitted when the Counter Bank Run (CBR) mechanism is deactivated.
event CBRDeactivated();
/// @notice Emitted when the redeem fee is updated.
/// @param redeemFee The new redeem fee.
event RedeemFeeUpdated(uint256 redeemFee);
/// @notice Emitted when the nonce threshold is set.
/// @param newThreshold The new threshold value
event NonceThresholdSet(uint256 newThreshold);
/*//////////////////////////////////////////////////////////////
Functions
//////////////////////////////////////////////////////////////*/
/// @notice Activates the Counter Bank Run (CBR) mechanism.
/// @param coefficient the CBR coefficient to activate
function activateCBR(uint256 coefficient) external;
/// @notice Deactivates the Counter Bank Run (CBR) mechanism.
function deactivateCBR() external;
/// @notice Sets the redeem fee.
/// @param _redeemFee The new redeem fee to set.
function setRedeemFee(uint256 _redeemFee) external;
/// @notice Pauses the redeem functionality.
function pauseRedeem() external;
/// @notice Unpauses the redeem functionality.
function unpauseRedeem() external;
/// @notice Pauses the swap functionality.
function pauseSwap() external;
/// @notice Unpauses the swap functionality.
function unpauseSwap() external;
/// @notice Pauses the contract.
function pause() external;
/// @notice Unpauses the contract.
function unpause() external;
/// @notice swap method
/// @dev Function that enable you to swap your rwaToken for stablecoin
/// @dev Will exchange RWA (rwaToken) for USD0 (stableToken)
/// @param rwaToken address of the token to swap
/// @param amount amount of rwaToken to swap
/// @param minAmountOut minimum amount of stableToken to receive
function swap(address rwaToken, uint256 amount, uint256 minAmountOut) external;
/// @notice swap method with permit
/// @dev Function that enable you to swap your rwaToken for stablecoin with permit
/// @dev Will exchange RWA (rwaToken) for USD0 (stableToken)
/// @param rwaToken address of the token to swap
/// @param amount amount of rwaToken to swap
/// @param deadline The deadline for the permit
/// @param v The v value for the permit
/// @param r The r value for the permit
/// @param s The s value for the permit
function swapWithPermit(
address rwaToken,
uint256 amount,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/// @notice redeem method
/// @dev Function that enable you to redeem your stable token for rwaToken
/// @dev Will exchange USD0 (stableToken) for RWA (rwaToken)
/// @param rwaToken address of the token that will be sent to the you
/// @param amount amount of stableToken to redeem
/// @param minAmountOut minimum amount of rwaToken to receive
function redeem(address rwaToken, uint256 amount, uint256 minAmountOut) external;
/// @notice Swap RWA for USDC through offers on the SwapperContract
/// @dev Takes USYC, mints USD0 and provides it to the Swapper Contract directly
/// Sends USD0 to the offer's creator and sends USDC to the recipient
/// @dev the recipient Address to receive the USDC is msg.sender
/// @param rwaToken Address of the RWA to swap for USDC
/// @param amountInTokenDecimals Address of the RWA to swap for USDC
/// @param orderIdsToTake orderIds to be taken
/// @param approval ERC20Permit approval data and signature of data
/// @param partialMatching flag to allow partial matching
function swapRWAtoStbc(
address rwaToken,
uint256 amountInTokenDecimals,
bool partialMatching,
uint256[] calldata orderIdsToTake,
Approval calldata approval
) external;
/// @notice Swap RWA for USDC through offers on the SwapperContract
/// @dev Takes USYC, mints USD0 and provides it to the Swapper Contract directly
/// Sends USD0 to the offer's creator and sends USDC to the recipient
/// @dev the recipient Address to receive the USDC is the offer's creator
/// @param orderIdsToTake orderIds to be taken
/// @param approval ERC20Permit approval data and signature of data
/// @param intent Intent data and signature of data
/// @param partialMatching flag to allow partial matching
function swapRWAtoStbcIntent(
uint256[] calldata orderIdsToTake,
Approval calldata approval,
Intent calldata intent,
bool partialMatching
) external;
// * Getter functions
/// @notice get the redeem fee percentage
/// @return the fee value
function redeemFee() external view returns (uint256);
/// @notice check if the CBR (Counter Bank Run) is activated
/// @dev flag indicate the status of the CBR (see documentation for more details)
/// @return the status of the CBR
function isCBROn() external view returns (bool);
/// @notice Returns the cbrCoef value.
function cbrCoef() external view returns (uint256);
/// @notice get the status of pause for the redeem function
/// @return the status of the pause
function isRedeemPaused() external view returns (bool);
/// @notice get the status of pause for the swap function
/// @return the status of the pause
function isSwapPaused() external view returns (bool);
// * Restricted functions
/// @notice redeem method for DAO
/// @dev Function that enables DAO to redeem stableToken for rwaToken
/// @dev Will exchange USD0 (stableToken) for RWA (rwaToken)
/// @param rwaToken address of the token that will be sent to the you
/// @param amount amount of stableToken to redeem
function redeemDao(address rwaToken, uint256 amount) external;
/// @notice Invalidates the current nonce for the message sender
/// @dev This function increments the nonce counter for the msg.sender and emits a NonceInvalidated event
function invalidateNonce() external;
/// @notice Invalidates all nonces up to a certain value for the message sender
/// @dev This function increments the nonce counter for the msg.sender and emits a NonceInvalidated event
function invalidateUpToNonce(uint256 newNonce) external;
/// @notice Returns the amount of tokens taken for the current nonce
/// @param owner The address of the owner
/// @return The amount of tokens taken for the current nonce
function orderAmountTakenCurrentNonce(address owner) external view returns (uint256);
/// @notice Set the lower bound for the intent nonce to be considered consumed
/// @dev An intent with an amount less than this threshold after a partial match will be invalidated by incrementing the nonce
/// @dev emits a NonceThresholdSet event
/// @param threshold The new threshold value
function setNonceThreshold(uint256 threshold) external;
/// @notice Check the current threshold for the intent nonce to be considered consumed
/// @return The current threshold value
function nonceThreshold() external view returns (uint256);
}
IRegistryContract.sol 9 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.28;
interface IRegistryContract {
function setContract(bytes32 name, address contractAddress) external;
function getContract(bytes32 name) external view returns (address);
}
IWETH.sol 32 lines
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
pragma solidity ^0.8.0;
interface IWETH {
event Deposit(address indexed dst, uint256 wad);
event Withdrawal(address indexed src, uint256 wad);
function deposit() external payable;
function withdraw(uint256 wad) external;
}
IWstETH.sol 12 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IWstETH {
function wrap(uint256 _stETHAmount) external returns (uint256);
function unwrap(uint256 _wstETHAmount) external returns (uint256);
function stETH() external view returns (address);
function stEthPerToken() external view returns (uint256);
}
IEth0MintZap.sol 111 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.28;
interface IEth0MintZap {
/// @notice Allows receiving ETH from the WETH contract during an unwrap.
/// @dev Any other native ETH transfer reverts. Use `swapETH` instead.
receive() external payable;
/// @notice Swaps WETH for ETH0 after granting allowance through a permit.
/// @dev Uses `wstETH` as collateral.
/// @param amount The amount of WETH to swap. Transferred from `msg.sender`.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @param deadline The deadline for the permit.
/// @param v The v value of the permit signature.
/// @param r The r value of the permit signature.
/// @param s The s value of the permit signature.
/// @return The amount of ETH0 minted.
function swapWETHWithPermit2(
uint256 amount,
address receiver,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256);
/// @notice Swaps stETH for ETH0 after granting allowance through a permit.
/// @param amount The amount of stETH to swap. Transferred from `msg.sender`.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @param deadline The deadline for the permit.
/// @param v The v value of the permit signature.
/// @param r The r value of the permit signature.
/// @param s The s value of the permit signature.
/// @return The amount of ETH0 minted.
function swapStETHWithPermit(
uint256 amount,
address receiver,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256);
/// @notice Swaps wstETH for ETH0 after granting allowance through a permit.
/// @param amount The amount of wstETH to swap. Transferred from `msg.sender`.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @param deadline The deadline for the permit.
/// @param v The v value of the permit signature.
/// @param r The r value of the permit signature.
/// @param s The s value of the permit signature.
/// @return The amount of ETH0 minted.
function swapWstETHWithPermit(
uint256 amount,
address receiver,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256);
/// @notice Safety feature to recover tokens stuck on this contract.
/// @dev Only the owner is allowed to call this function.
/// @param token The address of the token to transfer. Pass `address(0)` for native ETH.
/// @param receiver The recipient of the token transfer.
/// @param amount The amount of tokens to transfer.
function recoverTokens(address token, address receiver, uint256 amount) external;
/// @notice Swaps `msg.value` native ETH for ETH0.
/// @dev Uses `wstETH` as collateral.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @return The amount of ETH0 minted.
function swapETH(address receiver, uint256 minAmountOut) external payable returns (uint256);
/// @notice Swaps WETH for ETH0.
/// @dev Uses `wstETH` as collateral.
/// @param amount The amount of WETH to swap. Transferred from `msg.sender`.
/// Pass `type(uint256).max` to swap the entire `msg.sender`'s WETH balance.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @return The amount of ETH0 minted.
function swapWETH(uint256 amount, address receiver, uint256 minAmountOut)
external
returns (uint256);
/// @notice Swaps stETH for ETH0.
/// @param amount The amount of stETH to swap. Transferred from `msg.sender`.
/// Pass `type(uint256).max` to swap the entire `msg.sender`'s stETH balance.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @return The amount of ETH0 minted.
function swapStETH(uint256 amount, address receiver, uint256 minAmountOut)
external
returns (uint256);
/// @notice Swaps wstETH for ETH0.
/// @param amount The amount of wstETH to swap. Transferred from `msg.sender`.
/// Pass `type(uint256).max` to swap the entire `msg.sender`'s wstETH balance.
/// @param receiver The address to which to send the resulting ETH0.
/// @param minAmountOut The minimum amount of ETH0 to receive. Reverts if not met.
/// @return The amount of ETH0 minted.
function swapWstETH(uint256 amount, address receiver, uint256 minAmountOut)
external
returns (uint256);
}
IPermit2.sol 300 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @notice Permit2 handles signature-based transfers in SignatureTransfer and allowance-based transfers in AllowanceTransfer.
/// @dev Users must approve Permit2 before calling any of the transfer functions.
interface IPermit2 {
/// @notice The permit data for a token
struct PermitDetails {
// ERC20 token address
address token;
// the maximum amount allowed to spend
uint160 amount;
// timestamp at which a spender's token allowances become invalid
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice The permit message signed for a single token allowance
struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The permit message signed for multiple token allowances
struct PermitBatch {
// the permit data for multiple token allowances
PermitDetails[] details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The saved permissions
/// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
/// @dev Setting amount to type(uint160).max sets an unlimited approval
struct PackedAllowance {
// amount allowed
uint160 amount;
// permission expiry
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice A token spender pair.
struct TokenSpenderPair {
// the token the spender is approved
address token;
// the spender address
address spender;
}
/// @notice Details for a token transfer.
struct AllowanceTransferDetails {
// the owner of the token
address from;
// the recipient of the token
address to;
// the amount of the token
uint160 amount;
// the token to be transferred
address token;
}
/// @notice The token and amount details for a transfer signed in the permit transfer signature
struct TokenPermissions {
// ERC20 token address
address token;
// the maximum amount that can be spent
uint256 amount;
}
/// @notice The signed permit message for a single token transfer
struct PermitTransferFrom {
TokenPermissions permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice Specifies the recipient address and amount for batched transfers.
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
struct SignatureTransferDetails {
// recipient address
address to;
// spender requested amount
uint256 requestedAmount;
}
/// @notice Used to reconstruct the signed permit message for multiple token transfers
/// @dev Do not need to pass in spender address as it is required that it is msg.sender
/// @dev Note that a user still signs over a spender address
struct PermitBatchTransferFrom {
// the tokens and corresponding amounts permitted for a transfer
TokenPermissions[] permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice Emits an event when the owner successfully invalidates an ordered nonce.
event NonceInvalidation(
address indexed owner,
address indexed token,
address indexed spender,
uint48 newNonce,
uint48 oldNonce
);
/// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
event Approval(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration
);
/// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
/// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
event Lockdown(address indexed owner, address token, address spender);
/// @notice Emits an event when the owner successfully invalidates an unordered nonce.
event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);
/// @notice Thrown when an allowance on a token has expired.
/// @param deadline The timestamp at which the allowed amount is no longer valid
error AllowanceExpired(uint256 deadline);
/// @notice Thrown when an allowance on a token has been depleted.
/// @param amount The maximum amount allowed
error InsufficientAllowance(uint256 amount);
/// @notice Thrown when too many nonces are invalidated.
error ExcessiveInvalidation();
/// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
/// @param maxAmount The maximum amount a spender can request to transfer
error InvalidAmount(uint256 maxAmount);
/// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
/// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
error LengthMismatch();
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitSingle Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature)
external;
/// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitBatch Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature)
external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Transfer approved tokens in a batch
/// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
/// @dev Requires the from addresses to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity
/// by batch revoking approvals
/// @param approvals Array of approvals to revoke.
function lockdown(TokenSpenderPair[] calldata approvals) external;
/// @notice Invalidate nonces for a given (token, spender) pair
/// @param token The token to invalidate nonces for
/// @param spender The spender to invalidate nonces for
/// @param newNonce The new nonce to set. Invalidates all nonces less than it.
/// @dev Can't invalidate more than 2**16 nonces per transaction.
function invalidateNonces(address token, address spender, uint48 newNonce) external;
/// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
/// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
/// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
/// @dev It returns a uint256 bitmap
/// @dev The index, or wordPosition is capped at type(uint248).max
function nonceBitmap(address, uint256) external view returns (uint256);
/// @notice Transfers a token using a signed permit message
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param signature The signature to verify
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers a token using a signed permit message
/// @notice Includes extra data provided by the caller to verify signature over
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param signature The signature to verify
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @notice Includes extra data provided by the caller to verify signature over
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Invalidates the bits specified in mask for the bitmap at the word position
/// @dev The wordPos is maxed at type(uint248).max
/// @param wordPos A number to index the nonceBitmap at
/// @param mask A bitmap masked against msg.sender's current bitmap at the word position
function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
}
Eth0MintZap.sol 277 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.28;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IPermit2} from "src/interfaces/zaps/IPermit2.sol";
import {IEth0MintZap} from "src/interfaces/zaps/IEth0MintZap.sol";
import {IRegistryContract} from "src/interfaces/registry/IRegistryContract.sol";
import {IDaoCollateral} from "src/interfaces/IDaoCollateral.sol";
import {IWETH} from "src/interfaces/tokens/IWETH.sol";
import {IWstETH} from "src/interfaces/tokens/IWstETH.sol";
import {
WETH_MAINNET,
STETH_MAINNET,
WSTETH_MAINNET,
PERMIT2_MAINNET,
CONTRACT_DAO_COLLATERAL,
CONTRACT_ETH0
} from "src/constants.sol";
import {NullAddress} from "src/errors.sol";
/// @title ETH0 Mint Zap
/// @notice A helper to swap common tokens to ETH0 atomically.
/// @author Usual Labs
contract Eth0MintZap is Ownable, IEth0MintZap {
using SafeERC20 for IERC20;
IDaoCollateral public immutable DAO_COLLATERAL;
IERC20 public immutable ETH0;
error NativeTransferNotAllowed();
constructor(address _registry) Ownable(msg.sender) {
if (_registry == address(0)) {
revert NullAddress();
}
DAO_COLLATERAL =
IDaoCollateral(IRegistryContract(_registry).getContract(CONTRACT_DAO_COLLATERAL));
ETH0 = IERC20(IRegistryContract(_registry).getContract(CONTRACT_ETH0));
IERC20(STETH_MAINNET).approve(WSTETH_MAINNET, type(uint256).max);
IERC20(WSTETH_MAINNET).approve(address(DAO_COLLATERAL), type(uint256).max);
}
/// @inheritdoc IEth0MintZap
receive() external payable {
if (msg.sender != WETH_MAINNET) revert NativeTransferNotAllowed();
}
/*//////////////////////////////////////////////////////////////
Permits
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IEth0MintZap
function swapWETHWithPermit2(
uint256 amount,
address receiver,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256) {
if (receiver == address(0)) {
revert NullAddress();
}
(,, uint48 nonce) =
IPermit2(PERMIT2_MAINNET).allowance(msg.sender, WETH_MAINNET, address(this));
try IPermit2(PERMIT2_MAINNET).permit(
msg.sender,
IPermit2.PermitSingle({
details: IPermit2.PermitDetails({
token: WETH_MAINNET,
amount: uint160(amount),
expiration: type(uint48).max,
nonce: nonce
}),
spender: address(this),
sigDeadline: deadline
}),
bytes.concat(r, s, bytes1(v))
) {} catch {} // solhint-disable-line no-empty-blocks
IPermit2(PERMIT2_MAINNET).transferFrom(
msg.sender, address(this), uint160(amount), WETH_MAINNET
);
return _swapWETH(amount, receiver, minAmountOut);
}
/// @inheritdoc IEth0MintZap
function swapStETHWithPermit(
uint256 amount,
address receiver,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256) {
if (receiver == address(0)) {
revert NullAddress();
}
try IERC20Permit(STETH_MAINNET).permit(msg.sender, address(this), amount, deadline, v, r, s)
{} catch {} // solhint-disable-line no-empty-blocks
IERC20(STETH_MAINNET).safeTransferFrom(msg.sender, address(this), amount);
return _swapStETH(amount, receiver, minAmountOut);
}
/// @inheritdoc IEth0MintZap
function swapWstETHWithPermit(
uint256 amount,
address receiver,
uint256 minAmountOut,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256) {
if (receiver == address(0)) {
revert NullAddress();
}
try IERC20Permit(WSTETH_MAINNET).permit(
msg.sender, address(this), amount, deadline, v, r, s
) {} catch {} // solhint-disable-line no-empty-blocks
IERC20(WSTETH_MAINNET).safeTransferFrom(msg.sender, address(this), amount);
return _swapWstETH(amount, receiver, minAmountOut);
}
/*//////////////////////////////////////////////////////////////
Admin
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IEth0MintZap
function recoverTokens(address token, address receiver, uint256 amount) external onlyOwner {
if (token == address(0)) {
_transferETH(receiver, amount);
} else {
IERC20(token).safeTransfer(receiver, amount);
}
}
/*//////////////////////////////////////////////////////////////
Functions
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IEth0MintZap
function swapETH(address receiver, uint256 minAmountOut) external payable returns (uint256) {
if (receiver == address(0)) {
revert NullAddress();
}
return _swapETH(msg.value, receiver, minAmountOut);
}
/// @inheritdoc IEth0MintZap
function swapWETH(uint256 amount, address receiver, uint256 minAmountOut)
external
returns (uint256)
{
if (receiver == address(0)) {
revert NullAddress();
}
if (amount == type(uint256).max) {
amount = IERC20(WETH_MAINNET).balanceOf(msg.sender);
}
IERC20(WETH_MAINNET).safeTransferFrom(msg.sender, address(this), amount);
return _swapWETH(amount, receiver, minAmountOut);
}
/// @inheritdoc IEth0MintZap
function swapStETH(uint256 amount, address receiver, uint256 minAmountOut)
external
returns (uint256)
{
if (receiver == address(0)) {
revert NullAddress();
}
if (amount == type(uint256).max) {
amount = IERC20(STETH_MAINNET).balanceOf(msg.sender);
}
IERC20(STETH_MAINNET).safeTransferFrom(msg.sender, address(this), amount);
return _swapStETH(amount, receiver, minAmountOut);
}
/// @inheritdoc IEth0MintZap
function swapWstETH(uint256 amount, address receiver, uint256 minAmountOut)
external
returns (uint256)
{
if (receiver == address(0)) {
revert NullAddress();
}
if (amount == type(uint256).max) {
amount = IERC20(WSTETH_MAINNET).balanceOf(msg.sender);
}
IERC20(WSTETH_MAINNET).safeTransferFrom(msg.sender, address(this), amount);
return _swapWstETH(amount, receiver, minAmountOut);
}
/*//////////////////////////////////////////////////////////////
Private
//////////////////////////////////////////////////////////////*/
function _swapWETH(uint256 amount, address receiver, uint256 minAmountOut)
private
returns (uint256)
{
IWETH(WETH_MAINNET).withdraw(amount);
return _swapETH(amount, receiver, minAmountOut);
}
function _swapETH(uint256 amount, address receiver, uint256 minAmountOut)
private
returns (uint256)
{
uint256 initialShares = IERC20(WSTETH_MAINNET).balanceOf(address(this));
_transferETH(WSTETH_MAINNET, amount);
uint256 shares = IERC20(WSTETH_MAINNET).balanceOf(address(this)) - initialShares;
return _swapWstETH(shares, receiver, minAmountOut);
}
function _swapStETH(uint256 amount, address receiver, uint256 minAmountOut)
private
returns (uint256)
{
uint256 shares = IWstETH(WSTETH_MAINNET).wrap(amount);
return _swapWstETH(shares, receiver, minAmountOut);
}
function _swapWstETH(uint256 shares, address receiver, uint256 minAmountOut)
private
returns (uint256)
{
uint256 initialBalance = IERC20(ETH0).balanceOf(address(this));
DAO_COLLATERAL.swap(WSTETH_MAINNET, shares, minAmountOut);
uint256 amount = IERC20(ETH0).balanceOf(address(this)) - initialBalance;
IERC20(ETH0).safeTransfer(receiver, amount);
return amount;
}
function _transferETH(address receiver, uint256 value) private {
(bool success,) = receiver.call{value: value}("");
if (!success) {
// solhint-disable-next-line no-inline-assembly
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
}
}
Read Contract
DAO_COLLATERAL 0x0d5847ed → address
ETH0 0x6c5ffe9c → address
owner 0x8da5cb5b → address
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
recoverTokens 0x5f3e849f
address token
address receiver
uint256 amount
renounceOwnership 0x715018a6
No parameters
swapETH 0x45092201
address receiver
uint256 minAmountOut
returns: uint256
swapStETH 0x0064934a
uint256 amount
address receiver
uint256 minAmountOut
returns: uint256
swapStETHWithPermit 0x0baef8b5
uint256 amount
address receiver
uint256 minAmountOut
uint256 deadline
uint8 v
bytes32 r
bytes32 s
returns: uint256
swapWETH 0xcea8054a
uint256 amount
address receiver
uint256 minAmountOut
returns: uint256
swapWETHWithPermit2 0x211dbfd2
uint256 amount
address receiver
uint256 minAmountOut
uint256 deadline
uint8 v
bytes32 r
bytes32 s
returns: uint256
swapWstETH 0xfb167dea
uint256 amount
address receiver
uint256 minAmountOut
returns: uint256
swapWstETHWithPermit 0xabc2840d
uint256 amount
address receiver
uint256 minAmountOut
uint256 deadline
uint8 v
bytes32 r
bytes32 s
returns: uint256
transferOwnership 0xf2fde38b
address newOwner
Recent Transactions
No transactions found for this address