More Info
Private Name Tags
ContractCreator
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
401809 | 4 days ago | Contract Creation | 0 S |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
SonicSettlerMetaTxn
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 2000 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity =0.8.25 >=0.6.2 >=0.8.25 ^0.8.0 ^0.8.25; // lib/forge-std/src/interfaces/IERC20.sol /// @dev Interface of the ERC20 standard as defined in the EIP. /// @dev This includes the optional name, symbol, and decimals metadata. interface IERC20 { /// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`). event Transfer(address indexed from, address indexed to, uint256 value); /// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value` /// is the new allowance. event Approval(address indexed owner, address indexed spender, uint256 value); /// @notice Returns the amount of tokens in existence. function totalSupply() external view returns (uint256); /// @notice Returns the amount of tokens owned by `account`. function balanceOf(address account) external view returns (uint256); /// @notice Moves `amount` tokens from the caller's account to `to`. function transfer(address to, uint256 amount) external returns (bool); /// @notice Returns the remaining number of tokens that `spender` is allowed /// to spend on behalf of `owner` function allowance(address owner, address spender) external view returns (uint256); /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens. /// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 function approve(address spender, uint256 amount) external returns (bool); /// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism. /// `amount` is then deducted from the caller's allowance. function transferFrom(address from, address to, uint256 amount) external returns (bool); /// @notice Returns the name of the token. function name() external view returns (string memory); /// @notice Returns the symbol of the token. function symbol() external view returns (string memory); /// @notice Returns the decimals places of the token. function decimals() external view returns (uint8); } // lib/permit2/src/interfaces/IEIP712.sol interface IEIP712 { function DOMAIN_SEPARATOR() external view returns (bytes32); } // src/Context.sol abstract contract AbstractContext { function _msgSender() internal view virtual returns (address); function _msgData() internal view virtual returns (bytes calldata); function _isForwarded() internal view virtual returns (bool); } abstract contract Context is AbstractContext { function _msgSender() internal view virtual override returns (address) { return msg.sender; } function _msgData() internal view virtual override returns (bytes calldata) { return msg.data; } function _isForwarded() internal view virtual override returns (bool) { return false; } } // src/IERC721Owner.sol interface IERC721Owner { function ownerOf(uint256) external view returns (address); } // src/allowanceholder/IAllowanceHolder.sol interface IAllowanceHolder { /// @notice Executes against `target` with the `data` payload. Prior to execution, token permits /// are temporarily stored for the duration of the transaction. These permits can be /// consumed by the `operator` during the execution /// @notice `operator` consumes the funds during its operations by calling back into /// `AllowanceHolder` with `transferFrom`, consuming a token permit. /// @dev Neither `exec` nor `transferFrom` check that `token` contains code. /// @dev msg.sender is forwarded to target appended to the msg data (similar to ERC-2771) /// @param operator An address which is allowed to consume the token permits /// @param token The ERC20 token the caller has authorised to be consumed /// @param amount The quantity of `token` the caller has authorised to be consumed /// @param target A contract to execute operations with `data` /// @param data The data to forward to `target` /// @return result The returndata from calling `target` with `data` /// @notice If calling `target` with `data` reverts, the revert is propagated function exec(address operator, address token, uint256 amount, address payable target, bytes calldata data) external payable returns (bytes memory result); /// @notice The counterpart to `exec` which allows for the consumption of token permits later /// during execution /// @dev *DOES NOT* check that `token` contains code. This function vacuously succeeds if /// `token` is empty. /// @dev can only be called by the `operator` previously registered in `exec` /// @param token The ERC20 token to transfer /// @param owner The owner of tokens to transfer /// @param recipient The destination/beneficiary of the ERC20 `transferFrom` /// @param amount The quantity of `token` to transfer` /// @return true function transferFrom(address token, address owner, address recipient, uint256 amount) external returns (bool); } // src/core/univ3forks/SpookySwap.sol address constant spookySwapFactory = 0x3D91B700252e0E3eE7805d12e048a988Ab69C8ad; uint8 constant spookySwapForkId = 27; // src/core/univ3forks/UniswapV3.sol address constant uniswapV3MainnetFactory = 0x1F98431c8aD98523631AE4a59f267346ea31F984; address constant uniswapV3SepoliaFactory = 0x0227628f3F023bb0B980b67D528571c95c6DaC1c; address constant uniswapV3BaseFactory = 0x33128a8fC17869897dcE68Ed026d694621f6FDfD; address constant uniswapV3BnbFactory = 0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7; address constant uniswapV3AvalancheFactory = 0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD; address constant uniswapV3BlastFactory = 0x792edAdE80af5fC680d96a2eD80A44247D2Cf6Fd; address constant uniswapV3ScrollFactory = 0x70C62C8b8e801124A4Aa81ce07b637A3e83cb919; address constant uniswapV3LineaFactory = 0x31FAfd4889FA1269F7a13A66eE0fB458f27D72A9; address constant uniswapV3MantleFactory = 0x0d922Fb1Bc191F64970ac40376643808b4B74Df9; address constant uniswapV3TaikoFactory = 0x75FC67473A91335B5b8F8821277262a13B38c9b3; address constant uniswapV3WorldChainFactory = 0x7a5028BDa40e7B173C278C5342087826455ea25a; address constant uniswapV3GnosisFactory = 0xe32F7dD7e3f098D518ff19A22d5f028e076489B1; address constant uniswapV3SonicFactory = 0xcb2436774C3e191c85056d248EF4260ce5f27A9D; bytes32 constant uniswapV3InitHash = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; uint8 constant uniswapV3ForkId = 0; interface IUniswapV3Callback { function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external; } // src/utils/FreeMemory.sol abstract contract FreeMemory { modifier DANGEROUS_freeMemory() { uint256 freeMemPtr; assembly ("memory-safe") { freeMemPtr := mload(0x40) } _; assembly ("memory-safe") { mstore(0x40, freeMemPtr) } } } // src/utils/Panic.sol library Panic { function panic(uint256 code) internal pure { assembly ("memory-safe") { mstore(0x00, 0x4e487b71) // selector for `Panic(uint256)` mstore(0x20, code) revert(0x1c, 0x24) } } // https://docs.soliditylang.org/en/latest/control-structures.html#panic-via-assert-and-error-via-require uint8 internal constant GENERIC = 0x00; uint8 internal constant ASSERT_FAIL = 0x01; uint8 internal constant ARITHMETIC_OVERFLOW = 0x11; uint8 internal constant DIVISION_BY_ZERO = 0x12; uint8 internal constant ENUM_CAST = 0x21; uint8 internal constant CORRUPT_STORAGE_ARRAY = 0x22; uint8 internal constant POP_EMPTY_ARRAY = 0x31; uint8 internal constant ARRAY_OUT_OF_BOUNDS = 0x32; uint8 internal constant OUT_OF_MEMORY = 0x41; uint8 internal constant ZERO_FUNCTION_POINTER = 0x51; } // src/utils/Revert.sol library Revert { function _revert(bytes memory reason) internal pure { assembly ("memory-safe") { revert(add(reason, 0x20), mload(reason)) } } function maybeRevert(bool success, bytes memory reason) internal pure { if (!success) { _revert(reason); } } } // src/utils/UnsafeMath.sol library UnsafeMath { function unsafeInc(uint256 x) internal pure returns (uint256) { unchecked { return x + 1; } } function unsafeInc(int256 x) internal pure returns (int256) { unchecked { return x + 1; } } function unsafeDec(uint256 x) internal pure returns (uint256) { unchecked { return x - 1; } } function unsafeDec(int256 x) internal pure returns (int256) { unchecked { return x - 1; } } function unsafeNeg(int256 x) internal pure returns (int256) { unchecked { return -x; } } function unsafeDiv(uint256 numerator, uint256 denominator) internal pure returns (uint256 quotient) { assembly ("memory-safe") { quotient := div(numerator, denominator) } } function unsafeDiv(int256 numerator, int256 denominator) internal pure returns (int256 quotient) { assembly ("memory-safe") { quotient := sdiv(numerator, denominator) } } function unsafeMod(uint256 numerator, uint256 denominator) internal pure returns (uint256 remainder) { assembly ("memory-safe") { remainder := mod(numerator, denominator) } } function unsafeMod(int256 numerator, int256 denominator) internal pure returns (int256 remainder) { assembly ("memory-safe") { remainder := smod(numerator, denominator) } } function unsafeMulMod(uint256 a, uint256 b, uint256 m) internal pure returns (uint256 r) { assembly ("memory-safe") { r := mulmod(a, b, m) } } function unsafeAddMod(uint256 a, uint256 b, uint256 m) internal pure returns (uint256 r) { assembly ("memory-safe") { r := addmod(a, b, m) } } } // lib/permit2/src/interfaces/ISignatureTransfer.sol /// @title SignatureTransfer /// @notice Handles ERC20 token transfers through signature based actions /// @dev Requires user's token approval on the Permit2 contract interface ISignatureTransfer is IEIP712 { /// @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(); /// @notice Emits an event when the owner successfully invalidates an unordered nonce. event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask); /// @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 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; } // src/core/SettlerErrors.sol /// @notice Thrown when an offset is not the expected value error InvalidOffset(); /// @notice Thrown when a validating a target contract to avoid certain types of targets error ConfusedDeputy(); /// @notice Thrown when a target contract is invalid given the context error InvalidTarget(); /// @notice Thrown when validating the caller against the expected caller error InvalidSender(); /// @notice Thrown in cases when using a Trusted Forwarder / AllowanceHolder is not allowed error ForwarderNotAllowed(); /// @notice Thrown when a signature length is not the expected length error InvalidSignatureLen(); /// @notice Thrown when a slippage limit is exceeded error TooMuchSlippage(IERC20 token, uint256 expected, uint256 actual); /// @notice Thrown when a byte array that is supposed to encode a function from ISettlerActions is /// not recognized in context. error ActionInvalid(uint256 i, bytes4 action, bytes data); /// @notice Thrown when the encoded fork ID as part of UniswapV3 fork path is not on the list of /// recognized forks for this chain. error UnknownForkId(uint8 forkId); /// @notice Thrown when an AllowanceHolder transfer's permit is past its deadline error SignatureExpired(uint256 deadline); /// @notice An internal error that should never be thrown. Thrown when a callback reenters the /// entrypoint and attempts to clobber the existing callback. error ReentrantCallback(uint256 callbackInt); /// @notice An internal error that should never be thrown. This error can only be thrown by /// non-metatx-supporting Settler instances. Thrown when a callback-requiring liquidity /// source is called, but Settler never receives the callback. error CallbackNotSpent(uint256 callbackInt); /// @notice Thrown when a metatransaction has reentrancy. error ReentrantMetatransaction(bytes32 oldWitness); /// @notice Thrown when any transaction has reentrancy, not just taker-submitted or metatransaction. error ReentrantPayer(address oldPayer); /// @notice An internal error that should never be thrown. Thrown when a metatransaction fails to /// spend a coupon. error WitnessNotSpent(bytes32 oldWitness); /// @notice An internal error that should never be thrown. Thrown when the payer is unset /// unexpectedly. error PayerSpent(); error DeltaNotPositive(IERC20 token); error DeltaNotNegative(IERC20 token); error ZeroSellAmount(IERC20 token); error ZeroBuyAmount(IERC20 buyToken); error BoughtSellToken(IERC20 sellToken); error TokenHashCollision(IERC20 token0, IERC20 token1); error ZeroToken(); // src/vendor/SafeTransferLib.sol /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Modified from Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller. library SafeTransferLib { /*////////////////////////////////////////////////////////////// ETH OPERATIONS //////////////////////////////////////////////////////////////*/ function safeTransferETH(address payable to, uint256 amount) internal { assembly ("memory-safe") { // Transfer the ETH and revert if it fails. if iszero(call(gas(), to, amount, 0x00, 0x00, 0x00, 0x00)) { let ptr := mload(0x40) returndatacopy(ptr, 0x00, returndatasize()) revert(ptr, returndatasize()) } } } /*////////////////////////////////////////////////////////////// ERC20 OPERATIONS //////////////////////////////////////////////////////////////*/ function fastBalanceOf(IERC20 token, address acct) internal view returns (uint256 r) { assembly ("memory-safe") { mstore(0x14, acct) // Store the `acct` argument. mstore(0x00, 0x70a08231000000000000000000000000) // Selector for `balanceOf(address)`, with `acct`'s padding. // Call and check for revert. Storing the selector with padding in // memory at 0 results in a start of calldata at offset 16. Calldata // is 36 bytes long (4 bytes selector, 32 bytes argument) if iszero(staticcall(gas(), token, 0x10, 0x24, 0x00, 0x20)) { let ptr := mload(0x40) returndatacopy(ptr, 0x00, returndatasize()) revert(ptr, returndatasize()) } // Check for short calldata and missing code if iszero(gt(returndatasize(), 0x1f)) { revert(0x00, 0x00) } r := mload(0x00) } } function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal { assembly ("memory-safe") { let ptr := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(0x60, from)) // Store the `from` argument. (Clears `to`'s padding.) mstore(0x0c, 0x23b872dd000000000000000000000000) // Selector for `transferFrom(address,address,uint256)`, with `from`'s padding. // Calldata starts at offset 28 and is 100 bytes long (3 * 32 + 4). // If there is returndata (optional) we copy the first 32 bytes into the first slot of memory. if iszero(call(gas(), token, 0x00, 0x1c, 0x64, 0x00, 0x20)) { returndatacopy(ptr, 0x00, returndatasize()) revert(ptr, returndatasize()) } // We check that the call either returned exactly 1 [true] (can't just be non-zero // data), or had no return data. if iszero(or(and(eq(mload(0x00), 0x01), gt(returndatasize(), 0x1f)), iszero(returndatasize()))) { mstore(0x00, 0x7939f424) // Selector for `TransferFromFailed()` revert(0x1c, 0x04) } mstore(0x60, 0x00) // Restore the zero slot to zero. mstore(0x40, ptr) // Restore the free memory pointer. } } function safeTransfer(IERC20 token, address to, uint256 amount) internal { assembly ("memory-safe") { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. // Storing `amount` clobbers the upper bits of the free memory pointer, but those bits // can never be set without running into an OOG, so it's safe. We'll restore them to // zero at the end. mstore(0x00, 0xa9059cbb000000000000000000000000) // Selector for `transfer(address,uint256)`, with `to`'s padding. // Calldata starts at offset 16 and is 68 bytes long (2 * 32 + 4). // If there is returndata (optional) we copy the first 32 bytes into the first slot of memory. if iszero(call(gas(), token, 0x00, 0x10, 0x44, 0x00, 0x20)) { let ptr := mload(0x40) returndatacopy(ptr, 0x00, returndatasize()) revert(ptr, returndatasize()) } // We check that the call either returned exactly 1 [true] (can't just be non-zero // data), or had no return data. if iszero(or(and(eq(mload(0x00), 0x01), gt(returndatasize(), 0x1f)), iszero(returndatasize()))) { mstore(0x00, 0x90b8ec18) // Selector for `TransferFailed()` revert(0x1c, 0x04) } mstore(0x34, 0x00) // Restore the part of the free memory pointer that was overwritten. } } function safeApprove(IERC20 token, address to, uint256 amount) internal { assembly ("memory-safe") { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. // Storing `amount` clobbers the upper bits of the free memory pointer, but those bits // can never be set without running into an OOG, so it's safe. We'll restore them to // zero at the end. mstore(0x00, 0x095ea7b3000000000000000000000000) // Selector for `approve(address,uint256)`, with `to`'s padding. // Calldata starts at offset 16 and is 68 bytes long (2 * 32 + 4). // If there is returndata (optional) we copy the first 32 bytes into the first slot of memory. if iszero(call(gas(), token, 0x00, 0x10, 0x44, 0x00, 0x20)) { let ptr := mload(0x40) returndatacopy(ptr, 0x00, returndatasize()) revert(ptr, returndatasize()) } // We check that the call either returned exactly 1 [true] (can't just be non-zero // data), or had no return data. if iszero(or(and(eq(mload(0x00), 0x01), gt(returndatasize(), 0x1f)), iszero(returndatasize()))) { mstore(0x00, 0x3e3f8f73) // Selector for `ApproveFailed()` revert(0x1c, 0x04) } mstore(0x34, 0x00) // Restore the part of the free memory pointer that was overwritten. } } function safeApproveIfBelow(IERC20 token, address spender, uint256 amount) internal { uint256 allowance = token.allowance(address(this), spender); if (allowance < amount) { if (allowance != 0) { safeApprove(token, spender, 0); } safeApprove(token, spender, type(uint256).max); } } } // src/ISettlerActions.sol interface ISettlerActions { /// @dev Transfer funds from msg.sender Permit2. function TRANSFER_FROM(address recipient, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig) external; /// @dev Transfer funds from metatransaction requestor into the Settler contract using Permit2. Only for use in `Settler.executeMetaTxn` where the signature is provided as calldata function METATXN_TRANSFER_FROM(address recipient, ISignatureTransfer.PermitTransferFrom memory permit) external; /// @dev Settle an RfqOrder between maker and taker transfering funds directly between the parties // Post-req: Payout if recipient != taker function RFQ_VIP( address recipient, ISignatureTransfer.PermitTransferFrom memory makerPermit, address maker, bytes memory makerSig, ISignatureTransfer.PermitTransferFrom memory takerPermit, bytes memory takerSig ) external; /// @dev Settle an RfqOrder between maker and taker transfering funds directly between the parties for the entire amount function METATXN_RFQ_VIP( address recipient, ISignatureTransfer.PermitTransferFrom memory makerPermit, address maker, bytes memory makerSig, ISignatureTransfer.PermitTransferFrom memory takerPermit ) external; /// @dev Settle an RfqOrder between Maker and Settler. Transfering funds from the Settler contract to maker. /// Retaining funds in the settler contract. // Pre-req: Funded // Post-req: Payout function RFQ( address recipient, ISignatureTransfer.PermitTransferFrom memory permit, address maker, bytes memory makerSig, address takerToken, uint256 maxTakerAmount ) external; function UNISWAPV4( address recipient, address sellToken, uint256 bps, bool feeOnTransfer, uint256 hashMul, uint256 hashMod, bytes memory fills, uint256 amountOutMin ) external; function UNISWAPV4_VIP( address recipient, bool feeOnTransfer, uint256 hashMul, uint256 hashMod, bytes memory fills, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig, uint256 amountOutMin ) external; function METATXN_UNISWAPV4_VIP( address recipient, bool feeOnTransfer, uint256 hashMul, uint256 hashMod, bytes memory fills, ISignatureTransfer.PermitTransferFrom memory permit, uint256 amountOutMin ) external; /// @dev Trades against UniswapV3 using the contracts balance for funding // Pre-req: Funded // Post-req: Payout function UNISWAPV3(address recipient, uint256 bps, bytes memory path, uint256 amountOutMin) external; /// @dev Trades against UniswapV3 using user funds via Permit2 for funding function UNISWAPV3_VIP( address recipient, bytes memory path, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig, uint256 amountOutMin ) external; /// @dev Trades against UniswapV3 using user funds via Permit2 for funding. Metatransaction variant. Signature is over all actions. function METATXN_UNISWAPV3_VIP( address recipient, bytes memory path, ISignatureTransfer.PermitTransferFrom memory permit, uint256 amountOutMin ) external; function MAKERPSM(address recipient, uint256 bps, bool buyGem, uint256 amountOutMin) external; function CURVE_TRICRYPTO_VIP( address recipient, uint80 poolInfo, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig, uint256 minBuyAmount ) external; function METATXN_CURVE_TRICRYPTO_VIP( address recipient, uint80 poolInfo, ISignatureTransfer.PermitTransferFrom memory permit, uint256 minBuyAmount ) external; function DODOV1(address sellToken, uint256 bps, address pool, bool quoteForBase, uint256 minBuyAmount) external; function DODOV2( address recipient, address sellToken, uint256 bps, address pool, bool quoteForBase, uint256 minBuyAmount ) external; function VELODROME(address recipient, uint256 bps, address pool, uint24 swapInfo, uint256 minBuyAmount) external; /// @dev Trades against MaverickV2 using the contracts balance for funding /// This action does not use the MaverickV2 callback, so it takes an arbitrary pool address to make calls against. /// Passing `tokenAIn` as a parameter actually saves gas relative to introspecting the pool's `tokenA()` accessor. function MAVERICKV2( address recipient, address sellToken, uint256 bps, address pool, bool tokenAIn, uint256 minBuyAmount ) external; /// @dev Trades against MaverickV2, spending the taker's coupon inside the callback /// This action requires the use of the MaverickV2 callback, so we take the MaverickV2 CREATE2 salt as an argument to derive the pool address from the trusted factory and inithash. /// @param salt is formed as `keccak256(abi.encode(feeAIn, feeBIn, tickSpacing, lookback, tokenA, tokenB, kinds, address(0)))` function MAVERICKV2_VIP( address recipient, bytes32 salt, bool tokenAIn, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig, uint256 minBuyAmount ) external; /// @dev Trades against MaverickV2, spending the taker's coupon inside the callback; metatransaction variant function METATXN_MAVERICKV2_VIP( address recipient, bytes32 salt, bool tokenAIn, ISignatureTransfer.PermitTransferFrom memory permit, uint256 minBuyAmount ) external; /// @dev Trades against UniswapV2 using the contracts balance for funding /// @param swapInfo is encoded as the upper 16 bits as the fee of the pool in bps, the second /// lowest bit as "sell token has transfer fee", and the lowest bit as the /// "token0 for token1" flag. function UNISWAPV2( address recipient, address sellToken, uint256 bps, address pool, uint24 swapInfo, uint256 amountOutMin ) external; function POSITIVE_SLIPPAGE(address recipient, address token, uint256 expectedAmount) external; /// @dev Trades against a basic AMM which follows the approval, transferFrom(msg.sender) interaction // Pre-req: Funded // Post-req: Payout function BASIC(address sellToken, uint256 bps, address pool, uint256 offset, bytes calldata data) external; } // src/allowanceholder/AllowanceHolderContext.sol abstract contract AllowanceHolderContext is Context { IAllowanceHolder internal constant _ALLOWANCE_HOLDER = IAllowanceHolder(0x0000000000001fF3684f28c67538d4D072C22734); function _isForwarded() internal view virtual override returns (bool) { return super._isForwarded() || super._msgSender() == address(_ALLOWANCE_HOLDER); } function _msgSender() internal view virtual override returns (address sender) { sender = super._msgSender(); if (sender == address(_ALLOWANCE_HOLDER)) { // ERC-2771 like usage where the _trusted_ `AllowanceHolder` has appended the appropriate // msg.sender to the msg data assembly ("memory-safe") { sender := shr(0x60, calldataload(sub(calldatasize(), 0x14))) } } } // this is here to avoid foot-guns and make it very explicit that we intend // to pass the confused deputy check in AllowanceHolder function balanceOf(address) external pure { assembly ("memory-safe") { mstore8(0x00, 0x00) return(0x00, 0x01) } } } // src/utils/AddressDerivation.sol library AddressDerivation { using UnsafeMath for uint256; uint256 internal constant _SECP256K1_P = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F; uint256 internal constant _SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141; uint256 internal constant SECP256K1_GX = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798; uint256 internal constant SECP256K1_GY = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8; error InvalidCurve(uint256 x, uint256 y); // keccak256(abi.encodePacked(ECMUL([x, y], k)))[12:] function deriveEOA(uint256 x, uint256 y, uint256 k) internal pure returns (address) { if (k == 0) { Panic.panic(Panic.DIVISION_BY_ZERO); } if (k >= _SECP256K1_N || x >= _SECP256K1_P || y >= _SECP256K1_P) { Panic.panic(Panic.ARITHMETIC_OVERFLOW); } // +/-7 are neither square nor cube mod p, so we only have to check one // coordinate against 0. if it is 0, then the other is too (the point at // infinity) or the point is invalid if ( x == 0 || y.unsafeMulMod(y, _SECP256K1_P) != x.unsafeMulMod(x, _SECP256K1_P).unsafeMulMod(x, _SECP256K1_P).unsafeAddMod(7, _SECP256K1_P) ) { revert InvalidCurve(x, y); } unchecked { // https://ethresear.ch/t/you-can-kinda-abuse-ecrecover-to-do-ecmul-in-secp256k1-today/2384 return ecrecover( bytes32(0), uint8(27 + (y & 1)), bytes32(x), bytes32(UnsafeMath.unsafeMulMod(x, k, _SECP256K1_N)) ); } } // keccak256(RLP([deployer, nonce]))[12:] function deriveContract(address deployer, uint64 nonce) internal pure returns (address result) { if (nonce == 0) { assembly ("memory-safe") { mstore( 0x00, or( 0xd694000000000000000000000000000000000000000080, shl(8, and(0xffffffffffffffffffffffffffffffffffffffff, deployer)) ) ) result := keccak256(0x09, 0x17) } } else if (nonce < 0x80) { assembly ("memory-safe") { // we don't care about dirty bits in `deployer`; they'll be overwritten later mstore(0x14, deployer) mstore(0x00, 0xd694) mstore8(0x34, nonce) result := keccak256(0x1e, 0x17) } } else { // compute ceil(log_256(nonce)) + 1 uint256 nonceLength = 8; unchecked { if ((uint256(nonce) >> 32) != 0) { nonceLength += 32; if (nonce == type(uint64).max) { Panic.panic(Panic.ARITHMETIC_OVERFLOW); } } if ((uint256(nonce) >> 8) >= (1 << nonceLength)) { nonceLength += 16; } if (uint256(nonce) >= (1 << nonceLength)) { nonceLength += 8; } // ceil if ((uint256(nonce) << 8) >= (1 << nonceLength)) { nonceLength += 8; } // bytes, not bits nonceLength >>= 3; } assembly ("memory-safe") { // we don't care about dirty bits in `deployer` or `nonce`. they'll be overwritten later mstore(nonceLength, nonce) mstore8(0x20, add(0x7f, nonceLength)) mstore(0x00, deployer) mstore8(0x0a, add(0xd5, nonceLength)) mstore8(0x0b, 0x94) result := keccak256(0x0a, add(0x16, nonceLength)) } } } // keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, initHash))[12:] function deriveDeterministicContract(address deployer, bytes32 salt, bytes32 initHash) internal pure returns (address result) { assembly ("memory-safe") { let ptr := mload(0x40) // we don't care about dirty bits in `deployer`; they'll be overwritten later mstore(ptr, deployer) mstore8(add(ptr, 0x0b), 0xff) mstore(add(ptr, 0x20), salt) mstore(add(ptr, 0x40), initHash) result := keccak256(add(ptr, 0x0b), 0x55) } } } // src/vendor/FullMath.sol /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv library FullMath { using UnsafeMath for uint256; /// @notice 512-bit multiply [prod1 prod0] = a * b /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return prod0 Least significant 256 bits of the product /// @return prod1 Most significant 256 bits of the product /// @return remainder Remainder of full-precision division function _mulDivSetup(uint256 a, uint256 b, uint256 denominator) private pure returns (uint256 prod0, uint256 prod1, uint256 remainder) { // Compute the product mod 2**256 and mod 2**256 - 1 then use the Chinese // Remainder Theorem to reconstruct the 512 bit result. The result is stored // in two 256 variables such that product = prod1 * 2**256 + prod0 assembly ("memory-safe") { // Full-precision multiplication { let mm := mulmod(a, b, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } remainder := mulmod(a, b, denominator) } } /// @notice 512-bit by 256-bit division. /// @param prod0 Least significant 256 bits of the product /// @param prod1 Most significant 256 bits of the product /// @param denominator The divisor /// @param remainder Remainder of full-precision division /// @return The 256-bit result /// @dev Overflow and division by zero aren't checked and are GIGO errors function _mulDivInvert(uint256 prod0, uint256 prod1, uint256 denominator, uint256 remainder) private pure returns (uint256) { uint256 inv; assembly ("memory-safe") { // Make division exact by rounding [prod1 prod0] down to a multiple of // denominator // Subtract 256 bit number from 512 bit number prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) // Factor powers of two out of denominator { // Compute largest power of two divisor of denominator. // Always >= 1. let twos := and(sub(0, denominator), denominator) // Divide denominator by power of two denominator := div(denominator, twos) // Divide [prod1 prod0] by the factors of two prod0 := div(prod0, twos) // Shift in bits from prod1 into prod0. For this we need to flip `twos` // such that it is 2**256 / twos. // If twos is zero, then it becomes one twos := add(div(sub(0, twos), twos), 1) prod0 := or(prod0, mul(prod1, twos)) } // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse modulo 2**256 // such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct correct for // four bits. That is, denominator * inv = 1 mod 2**4 inv := xor(mul(3, denominator), 2) // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**8 inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**16 inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**32 inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**64 inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**128 inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**256 } // Because the division is now exact we can divide by multiplying with the // modular inverse of denominator. This will give us the correct result // modulo 2**256. Since the precoditions guarantee that the outcome is less // than 2**256, this is the final result. We don't need to compute the high // bits of the result and prod1 is no longer required. unchecked { return prod0 * inv; } } /// @notice Calculates a×b÷denominator with full precision then rounds towards 0. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return The 256-bit result function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) { (uint256 prod0, uint256 prod1, uint256 remainder) = _mulDivSetup(a, b, denominator); // Make sure the result is less than 2**256. // Also prevents denominator == 0 if (denominator <= prod1) { Panic.panic(denominator == 0 ? Panic.DIVISION_BY_ZERO : Panic.ARITHMETIC_OVERFLOW); } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { return prod0.unsafeDiv(denominator); } return _mulDivInvert(prod0, prod1, denominator, remainder); } /// @notice Calculates a×b÷denominator with full precision then rounds towards 0. Overflowing a uint256 or denominator == 0 are GIGO errors /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return The 256-bit result function unsafeMulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) { (uint256 prod0, uint256 prod1, uint256 remainder) = _mulDivSetup(a, b, denominator); // Overflow and zero-division checks are skipped // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { return prod0.unsafeDiv(denominator); } return _mulDivInvert(prod0, prod1, denominator, remainder); } /// @notice Calculates a×b÷denominator with full precision then rounds towards 0. Overflowing a uint256 or denominator == 0 are GIGO errors /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @dev This is the branchless, straight line version of `unsafeMulDiv`. If we know that `prod1 != 0` this may be faster. Also this gives Solc a better chance to optimize. /// @return The 256-bit result function unsafeMulDivAlt(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) { (uint256 prod0, uint256 prod1, uint256 remainder) = _mulDivSetup(a, b, denominator); return _mulDivInvert(prod0, prod1, denominator, remainder); } } // src/core/Permit2PaymentAbstract.sol abstract contract Permit2PaymentAbstract is AbstractContext { string internal constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)"; function _isRestrictedTarget(address) internal view virtual returns (bool); function _operator() internal view virtual returns (address); function _permitToSellAmountCalldata(ISignatureTransfer.PermitTransferFrom calldata permit) internal view virtual returns (uint256 sellAmount); function _permitToSellAmount(ISignatureTransfer.PermitTransferFrom memory permit) internal view virtual returns (uint256 sellAmount); function _permitToTransferDetails(ISignatureTransfer.PermitTransferFrom memory permit, address recipient) internal view virtual returns (ISignatureTransfer.SignatureTransferDetails memory transferDetails, uint256 sellAmount); function _transferFromIKnowWhatImDoing( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, address from, bytes32 witness, string memory witnessTypeString, bytes memory sig, bool isForwarded ) internal virtual; function _transferFromIKnowWhatImDoing( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, address from, bytes32 witness, string memory witnessTypeString, bytes memory sig ) internal virtual; function _transferFrom( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, bytes memory sig, bool isForwarded ) internal virtual; function _transferFrom( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, bytes memory sig ) internal virtual; function _setOperatorAndCall( address target, bytes memory data, uint32 selector, function (bytes calldata) internal returns (bytes memory) callback ) internal virtual returns (bytes memory); modifier metaTx(address msgSender, bytes32 witness) virtual; modifier takerSubmitted() virtual; function _allowanceHolderTransferFrom(address token, address owner, address recipient, uint256 amount) internal virtual; } // src/SettlerAbstract.sol abstract contract SettlerAbstract is Permit2PaymentAbstract { // Permit2 Witness for meta transactions string internal constant SLIPPAGE_AND_ACTIONS_TYPE = "SlippageAndActions(address recipient,address buyToken,uint256 minAmountOut,bytes[] actions)"; bytes32 internal constant SLIPPAGE_AND_ACTIONS_TYPEHASH = 0x615e8d716cef7295e75dd3f1f10d679914ad6d7759e8e9459f0109ef75241701; uint256 internal constant BASIS = 10_000; IERC20 internal constant ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE); constructor() { assert(SLIPPAGE_AND_ACTIONS_TYPEHASH == keccak256(bytes(SLIPPAGE_AND_ACTIONS_TYPE))); } function _hasMetaTxn() internal pure virtual returns (bool); function _dispatch(uint256 i, uint256 action, bytes calldata data) internal virtual returns (bool); } // src/core/UniswapV2.sol interface IUniV2Pair { function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112, uint112, uint32); function swap(uint256, uint256, address, bytes calldata) external; } abstract contract UniswapV2 is SettlerAbstract { using SafeTransferLib for IERC20; // bytes4(keccak256("getReserves()")) uint32 private constant UNI_PAIR_RESERVES_SELECTOR = 0x0902f1ac; // bytes4(keccak256("swap(uint256,uint256,address,bytes)")) uint32 private constant UNI_PAIR_SWAP_SELECTOR = 0x022c0d9f; // bytes4(keccak256("transfer(address,uint256)")) uint32 private constant ERC20_TRANSFER_SELECTOR = 0xa9059cbb; // bytes4(keccak256("balanceOf(address)")) uint32 private constant ERC20_BALANCEOF_SELECTOR = 0x70a08231; /// @dev Sell a token for another token using UniswapV2. function sellToUniswapV2( address recipient, address sellToken, uint256 bps, address pool, uint24 swapInfo, uint256 minBuyAmount ) internal { // Preventing calls to Permit2 or AH is not explicitly required as neither of these contracts implement the `swap` nor `transfer` selector // |7|6|5|4|3|2|1|0| - bit positions in swapInfo (uint8) // |0|0|0|0|0|0|F|Z| - Z: zeroForOne flag, F: sellTokenHasFee flag bool zeroForOne = (swapInfo & 1) == 1; // Extract the least significant bit (bit 0) bool sellTokenHasFee = (swapInfo & 2) >> 1 == 1; // Extract the second least significant bit (bit 1) and shift it right uint256 feeBps = swapInfo >> 8; uint256 sellAmount; uint256 buyAmount; // If bps is zero we assume there are no funds within this contract, skip the updating sellAmount. // This case occurs if the pool is being chained, in which the funds have been sent directly to the pool if (bps != 0) { // We don't care about phantom overflow here because reserves are // limited to 112 bits. Any token balance that would overflow here would // also break UniV2. // It is *possible* to set `bps` above the basis and therefore // cause an overflow on this multiplication. However, `bps` is // passed as authenticated calldata, so this is a GIGO error that we // do not attempt to fix. unchecked { sellAmount = IERC20(sellToken).fastBalanceOf(address(this)) * bps / BASIS; } } assembly ("memory-safe") { let ptr := mload(0x40) // transfer sellAmount (a non zero amount) of sellToken to the pool if sellAmount { mstore(ptr, ERC20_TRANSFER_SELECTOR) mstore(add(ptr, 0x20), pool) mstore(add(ptr, 0x40), sellAmount) // ...||ERC20_TRANSFER_SELECTOR|pool|sellAmount| if iszero(call(gas(), sellToken, 0, add(ptr, 0x1c), 0x44, 0x00, 0x20)) { bubbleRevert(ptr) } if iszero(or(iszero(returndatasize()), and(iszero(lt(returndatasize(), 0x20)), eq(mload(0x00), 1)))) { revert(0, 0) } } // get pool reserves let sellReserve let buyReserve mstore(0x00, UNI_PAIR_RESERVES_SELECTOR) // ||UNI_PAIR_RESERVES_SELECTOR| if iszero(staticcall(gas(), pool, 0x1c, 0x04, 0x00, 0x40)) { bubbleRevert(ptr) } if lt(returndatasize(), 0x40) { revert(0, 0) } { let r := shl(5, zeroForOne) buyReserve := mload(r) sellReserve := mload(xor(0x20, r)) } // Update the sell amount in the following cases: // the funds are in the pool already (flagged by sellAmount being 0) // the sell token has a fee (flagged by sellTokenHasFee) if or(iszero(sellAmount), sellTokenHasFee) { // retrieve the sellToken balance of the pool mstore(0x00, ERC20_BALANCEOF_SELECTOR) mstore(0x20, and(0xffffffffffffffffffffffffffffffffffffffff, pool)) // ||ERC20_BALANCEOF_SELECTOR|pool| if iszero(staticcall(gas(), sellToken, 0x1c, 0x24, 0x00, 0x20)) { bubbleRevert(ptr) } if lt(returndatasize(), 0x20) { revert(0, 0) } let bal := mload(0x00) // determine real sellAmount by comparing pool's sellToken balance to reserve amount if lt(bal, sellReserve) { mstore(0x00, 0x4e487b71) // selector for `Panic(uint256)` mstore(0x20, 0x11) // panic code for arithmetic underflow revert(0x1c, 0x24) } sellAmount := sub(bal, sellReserve) } // compute buyAmount based on sellAmount and reserves let sellAmountWithFee := mul(sellAmount, sub(10000, feeBps)) buyAmount := div(mul(sellAmountWithFee, buyReserve), add(sellAmountWithFee, mul(sellReserve, 10000))) let swapCalldata := add(ptr, 0x1c) // set up swap call selector and empty callback data mstore(ptr, UNI_PAIR_SWAP_SELECTOR) mstore(add(ptr, 0x80), 0x80) // offset to length of data mstore(add(ptr, 0xa0), 0) // length of data // set amount0Out and amount1Out { // If `zeroForOne`, offset is 0x24, else 0x04 let offset := add(0x04, shl(5, zeroForOne)) mstore(add(swapCalldata, offset), buyAmount) mstore(add(swapCalldata, xor(0x20, offset)), 0) } mstore(add(swapCalldata, 0x44), and(0xffffffffffffffffffffffffffffffffffffffff, recipient)) // ...||UNI_PAIR_SWAP_SELECTOR|amount0Out|amount1Out|recipient|data| // perform swap at the pool sending bought tokens to the recipient if iszero(call(gas(), pool, 0, swapCalldata, 0xa4, 0, 0)) { bubbleRevert(swapCalldata) } // revert with the return data from the most recent call function bubbleRevert(p) { returndatacopy(p, 0, returndatasize()) revert(p, returndatasize()) } } if (buyAmount < minBuyAmount) { revert TooMuchSlippage( IERC20(zeroForOne ? IUniV2Pair(pool).token1() : IUniV2Pair(pool).token0()), minBuyAmount, buyAmount ); } } } // src/core/RfqOrderSettlement.sol abstract contract RfqOrderSettlement is SettlerAbstract { using SafeTransferLib for IERC20; using FullMath for uint256; struct Consideration { IERC20 token; uint256 amount; address counterparty; bool partialFillAllowed; } string internal constant CONSIDERATION_TYPE = "Consideration(address token,uint256 amount,address counterparty,bool partialFillAllowed)"; // `string.concat` isn't recognized by solc as compile-time constant, but `abi.encodePacked` is string internal constant CONSIDERATION_WITNESS = string(abi.encodePacked("Consideration consideration)", CONSIDERATION_TYPE, TOKEN_PERMISSIONS_TYPE)); bytes32 internal constant CONSIDERATION_TYPEHASH = 0x7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa; string internal constant RFQ_ORDER_TYPE = "RfqOrder(Consideration makerConsideration,Consideration takerConsideration)"; string internal constant RFQ_ORDER_TYPE_RECURSIVE = string(abi.encodePacked(RFQ_ORDER_TYPE, CONSIDERATION_TYPE)); bytes32 internal constant RFQ_ORDER_TYPEHASH = 0x49fa719b76f0f6b7e76be94b56c26671a548e1c712d5b13dc2874f70a7598276; function _hashConsideration(Consideration memory consideration) internal pure returns (bytes32 result) { assembly ("memory-safe") { let ptr := sub(consideration, 0x20) let oldValue := mload(ptr) mstore(ptr, CONSIDERATION_TYPEHASH) result := keccak256(ptr, 0xa0) mstore(ptr, oldValue) } } function _logRfqOrder(bytes32 makerConsiderationHash, bytes32 takerConsiderationHash, uint128 makerFilledAmount) private { assembly ("memory-safe") { mstore(0x00, RFQ_ORDER_TYPEHASH) mstore(0x20, makerConsiderationHash) let ptr := mload(0x40) mstore(0x40, takerConsiderationHash) let orderHash := keccak256(0x00, 0x60) mstore(0x40, ptr) mstore(0x10, makerFilledAmount) mstore(0x00, orderHash) log0(0x00, 0x30) } } constructor() { assert(CONSIDERATION_TYPEHASH == keccak256(bytes(CONSIDERATION_TYPE))); assert(RFQ_ORDER_TYPEHASH == keccak256(bytes(RFQ_ORDER_TYPE_RECURSIVE))); } /// @dev Settle an RfqOrder between maker and taker transfering funds directly between the counterparties. Either /// two Permit2 signatures are consumed, with the maker Permit2 containing a witness of the RfqOrder, or /// AllowanceHolder is supported for the taker payment. The Maker has signed the same order as the /// Taker. Submission may be directly by the taker or via a third party with the Taker signing a witness. /// @dev if used, the taker's witness is not calculated nor verified here as calling function is trusted function fillRfqOrderVIP( address recipient, ISignatureTransfer.PermitTransferFrom memory makerPermit, address maker, bytes memory makerSig, ISignatureTransfer.PermitTransferFrom memory takerPermit, bytes memory takerSig ) internal { if (!_hasMetaTxn()) { assert(makerPermit.permitted.amount <= type(uint256).max - BASIS); } (ISignatureTransfer.SignatureTransferDetails memory makerTransferDetails, uint256 makerAmount) = _permitToTransferDetails(makerPermit, recipient); // In theory, the taker permit could invoke the balance-proportional sell amount logic. However, // because we hash the sell amount computed here into the maker's consideration (witness) only a // balance-proportional sell amount that corresponds exactly to the signed order would avoid a // revert. In other words, no unexpected behavior is possible. It's pointless to prohibit the // use of that logic. (ISignatureTransfer.SignatureTransferDetails memory takerTransferDetails, uint256 takerAmount) = _permitToTransferDetails(takerPermit, maker); bytes32 witness = _hashConsideration( Consideration({ token: IERC20(takerPermit.permitted.token), amount: takerAmount, counterparty: _msgSender(), partialFillAllowed: false }) ); _transferFrom(takerPermit, takerTransferDetails, takerSig); _transferFromIKnowWhatImDoing( makerPermit, makerTransferDetails, maker, witness, CONSIDERATION_WITNESS, makerSig, false ); _logRfqOrder( witness, _hashConsideration( Consideration({ token: IERC20(makerPermit.permitted.token), amount: makerAmount, counterparty: maker, partialFillAllowed: false }) ), uint128(makerAmount) ); } /// @dev Settle an RfqOrder between maker and Settler retaining funds in this contract. /// @dev pre-condition: msgSender has been authenticated against the requestor /// One Permit2 signature is consumed, with the maker Permit2 containing a witness of the RfqOrder. // In this variant, Maker pays recipient and Settler pays Maker function fillRfqOrderSelfFunded( address recipient, ISignatureTransfer.PermitTransferFrom memory permit, address maker, bytes memory makerSig, IERC20 takerToken, uint256 maxTakerAmount ) internal { if (!_hasMetaTxn()) { assert(permit.permitted.amount <= type(uint256).max - BASIS); } // Compute witnesses. These are based on the quoted maximum amounts. We will modify them // later to adjust for the actual settled amount, which may be modified by encountered // slippage. (ISignatureTransfer.SignatureTransferDetails memory transferDetails, uint256 makerAmount) = _permitToTransferDetails(permit, recipient); bytes32 takerWitness = _hashConsideration( Consideration({ token: IERC20(permit.permitted.token), amount: makerAmount, counterparty: maker, partialFillAllowed: true }) ); bytes32 makerWitness = _hashConsideration( Consideration({ token: takerToken, amount: maxTakerAmount, counterparty: _msgSender(), partialFillAllowed: true }) ); // Now we adjust the transfer amounts to compensate for encountered slippage. Rounding is // performed in the maker's favor. uint256 takerAmount = takerToken.fastBalanceOf(address(this)); if (takerAmount > maxTakerAmount) { takerAmount = maxTakerAmount; } transferDetails.requestedAmount = makerAmount = makerAmount.unsafeMulDiv(takerAmount, maxTakerAmount); // Now that we have all the relevant information, make the transfers and log the order. takerToken.safeTransfer(maker, takerAmount); _transferFromIKnowWhatImDoing( permit, transferDetails, maker, makerWitness, CONSIDERATION_WITNESS, makerSig, false ); _logRfqOrder(makerWitness, takerWitness, uint128(makerAmount)); } } // src/core/UniswapV3Fork.sol interface IUniswapV3Pool { /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), /// or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); } abstract contract UniswapV3Fork is SettlerAbstract { using UnsafeMath for uint256; using UnsafeMath for int256; using SafeTransferLib for IERC20; /// @dev Minimum size of an encoded swap path: /// sizeof(address(inputToken) | uint8(forkId) | uint24(poolId) | address(outputToken)) uint256 private constant SINGLE_HOP_PATH_SIZE = 0x2c; /// @dev How many bytes to skip ahead in an encoded path to start at the next hop: /// sizeof(address(inputToken) | uint8(forkId) | uint24(poolId)) uint256 private constant PATH_SKIP_HOP_SIZE = 0x18; /// @dev The size of the swap callback prefix data before the Permit2 data. uint256 private constant SWAP_CALLBACK_PREFIX_DATA_SIZE = 0x28; /// @dev The offset from the pointer to the length of the swap callback prefix data to the start of the Permit2 data. uint256 private constant SWAP_CALLBACK_PERMIT2DATA_OFFSET = 0x48; uint256 private constant PERMIT_DATA_SIZE = 0x60; uint256 private constant ISFORWARDED_DATA_SIZE = 0x01; /// @dev Minimum tick price sqrt ratio. uint160 private constant MIN_PRICE_SQRT_RATIO = 4295128739; /// @dev Minimum tick price sqrt ratio. uint160 private constant MAX_PRICE_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @dev Mask of lower 20 bytes. uint256 private constant ADDRESS_MASK = 0x00ffffffffffffffffffffffffffffffffffffffff; /// @dev Mask of lower 3 bytes. uint256 private constant UINT24_MASK = 0xffffff; /// @dev Sell a token for another token directly against uniswap v3. /// @param encodedPath Uniswap-encoded path. /// @param bps proportion of current balance of the first token in the path to sell. /// @param minBuyAmount Minimum amount of the last token in the path to buy. /// @param recipient The recipient of the bought tokens. /// @return buyAmount Amount of the last token in the path bought. function sellToUniswapV3(address recipient, uint256 bps, bytes memory encodedPath, uint256 minBuyAmount) internal returns (uint256 buyAmount) { buyAmount = _uniV3ForkSwap( recipient, encodedPath, // We don't care about phantom overflow here because reserves are // limited to 128 bits. Any token balance that would overflow here // would also break UniV3. (IERC20(address(bytes20(encodedPath))).fastBalanceOf(address(this)) * bps).unsafeDiv(BASIS), minBuyAmount, address(this), // payer new bytes(SWAP_CALLBACK_PREFIX_DATA_SIZE) ); } /// @dev Sell a token for another token directly against uniswap v3. Payment is using a Permit2 signature (or AllowanceHolder). /// @param encodedPath Uniswap-encoded path. /// @param minBuyAmount Minimum amount of the last token in the path to buy. /// @param recipient The recipient of the bought tokens. /// @param permit The PermitTransferFrom allowing this contract to spend the taker's tokens /// @param sig The taker's signature for Permit2 /// @return buyAmount Amount of the last token in the path bought. function sellToUniswapV3VIP( address recipient, bytes memory encodedPath, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig, uint256 minBuyAmount ) internal returns (uint256 buyAmount) { bytes memory swapCallbackData = new bytes(SWAP_CALLBACK_PREFIX_DATA_SIZE + PERMIT_DATA_SIZE + ISFORWARDED_DATA_SIZE + sig.length); _encodePermit2Data(swapCallbackData, permit, sig, _isForwarded()); buyAmount = _uniV3ForkSwap( recipient, encodedPath, _permitToSellAmount(permit), minBuyAmount, address(0), // payer swapCallbackData ); } // Executes successive swaps along an encoded uniswap path. function _uniV3ForkSwap( address recipient, bytes memory encodedPath, uint256 sellAmount, uint256 minBuyAmount, address payer, bytes memory swapCallbackData ) internal returns (uint256 buyAmount) { if (sellAmount > uint256(type(int256).max)) { Panic.panic(Panic.ARITHMETIC_OVERFLOW); } IERC20 outputToken; while (true) { bool isPathMultiHop = _isPathMultiHop(encodedPath); bool zeroForOne; IUniswapV3Pool pool; uint32 callbackSelector; { (IERC20 token0, uint8 forkId, uint24 poolId, IERC20 token1) = _decodeFirstPoolInfoFromPath(encodedPath); IERC20 sellToken = token0; outputToken = token1; if (!(zeroForOne = token0 < token1)) { (token0, token1) = (token1, token0); } address factory; bytes32 initHash; (factory, initHash, callbackSelector) = _uniV3ForkInfo(forkId); pool = _toPool(factory, initHash, token0, token1, poolId); _updateSwapCallbackData(swapCallbackData, sellToken, payer); } int256 amount0; int256 amount1; if (isPathMultiHop) { uint256 freeMemPtr; assembly ("memory-safe") { freeMemPtr := mload(0x40) } (amount0, amount1) = abi.decode( _setOperatorAndCall( address(pool), abi.encodeCall( pool.swap, ( // Intermediate tokens go to this contract. address(this), zeroForOne, int256(sellAmount), zeroForOne ? MIN_PRICE_SQRT_RATIO + 1 : MAX_PRICE_SQRT_RATIO - 1, swapCallbackData ) ), callbackSelector, _uniV3ForkCallback ), (int256, int256) ); assembly ("memory-safe") { mstore(0x40, freeMemPtr) } } else { (amount0, amount1) = abi.decode( _setOperatorAndCall( address(pool), abi.encodeCall( pool.swap, ( recipient, zeroForOne, int256(sellAmount), zeroForOne ? MIN_PRICE_SQRT_RATIO + 1 : MAX_PRICE_SQRT_RATIO - 1, swapCallbackData ) ), callbackSelector, _uniV3ForkCallback ), (int256, int256) ); } { int256 _buyAmount = (zeroForOne ? amount1 : amount0).unsafeNeg(); if (_buyAmount < 0) { Panic.panic(Panic.ARITHMETIC_OVERFLOW); } buyAmount = uint256(_buyAmount); } if (!isPathMultiHop) { // Done. break; } // Continue with next hop. payer = address(this); // Subsequent hops are paid for by us. sellAmount = buyAmount; // Skip to next hop along path. encodedPath = _shiftHopFromPathInPlace(encodedPath); assembly ("memory-safe") { mstore(swapCallbackData, SWAP_CALLBACK_PREFIX_DATA_SIZE) } } if (buyAmount < minBuyAmount) { revert TooMuchSlippage(outputToken, minBuyAmount, buyAmount); } } // Return whether or not an encoded uniswap path contains more than one hop. function _isPathMultiHop(bytes memory encodedPath) private pure returns (bool) { return encodedPath.length > SINGLE_HOP_PATH_SIZE; } function _decodeFirstPoolInfoFromPath(bytes memory encodedPath) private pure returns (IERC20 inputToken, uint8 forkId, uint24 poolId, IERC20 outputToken) { if (encodedPath.length < SINGLE_HOP_PATH_SIZE) { Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS); } assembly ("memory-safe") { // Solidity cleans dirty bits automatically inputToken := mload(add(encodedPath, 0x14)) forkId := mload(add(encodedPath, 0x15)) poolId := mload(add(encodedPath, 0x18)) outputToken := mload(add(encodedPath, SINGLE_HOP_PATH_SIZE)) } } // Skip past the first hop of an encoded uniswap path in-place. function _shiftHopFromPathInPlace(bytes memory encodedPath) private pure returns (bytes memory) { if (encodedPath.length < PATH_SKIP_HOP_SIZE) { Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS); } assembly ("memory-safe") { let length := sub(mload(encodedPath), PATH_SKIP_HOP_SIZE) encodedPath := add(encodedPath, PATH_SKIP_HOP_SIZE) mstore(encodedPath, length) } return encodedPath; } function _encodePermit2Data( bytes memory swapCallbackData, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig, bool isForwarded ) private pure { assembly ("memory-safe") { mstore(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, swapCallbackData), mload(add(0x20, mload(permit)))) mcopy(add(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, 0x20), swapCallbackData), add(0x20, permit), 0x40) mstore8(add(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, PERMIT_DATA_SIZE), swapCallbackData), isForwarded) mcopy( add( add(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, PERMIT_DATA_SIZE), ISFORWARDED_DATA_SIZE), swapCallbackData ), add(0x20, sig), mload(sig) ) } } // Update `swapCallbackData` in place with new values. function _updateSwapCallbackData(bytes memory swapCallbackData, IERC20 sellToken, address payer) private pure { assembly ("memory-safe") { let length := mload(swapCallbackData) mstore(add(0x28, swapCallbackData), sellToken) mstore(add(0x14, swapCallbackData), payer) mstore(swapCallbackData, length) } } // Compute the pool address given two tokens and a poolId. function _toPool(address factory, bytes32 initHash, IERC20 token0, IERC20 token1, uint24 poolId) private pure returns (IUniswapV3Pool) { // address(keccak256(abi.encodePacked( // hex"ff", // factory, // keccak256(abi.encode(token0, token1, poolId)), // initHash // ))) bytes32 salt; assembly ("memory-safe") { token0 := and(ADDRESS_MASK, token0) token1 := and(ADDRESS_MASK, token1) poolId := and(UINT24_MASK, poolId) let ptr := mload(0x40) mstore(0x00, token0) mstore(0x20, token1) mstore(0x40, poolId) salt := keccak256(0x00, sub(0x60, shl(0x05, iszero(poolId)))) mstore(0x40, ptr) } return IUniswapV3Pool(AddressDerivation.deriveDeterministicContract(factory, salt, initHash)); } function _uniV3ForkInfo(uint8 forkId) internal view virtual returns (address, bytes32, uint32); function _uniV3ForkCallback(bytes calldata data) private returns (bytes memory) { require(data.length >= 0x80); int256 amount0Delta; int256 amount1Delta; assembly ("memory-safe") { amount0Delta := calldataload(data.offset) amount1Delta := calldataload(add(0x20, data.offset)) data.offset := add(data.offset, calldataload(add(0x40, data.offset))) data.length := calldataload(data.offset) data.offset := add(0x20, data.offset) } uniswapV3SwapCallback(amount0Delta, amount1Delta, data); return new bytes(0); } /// @dev The UniswapV3 pool swap callback which pays the funds requested /// by the caller/pool to the pool. Can only be called by a valid /// UniswapV3 pool. /// @param amount0Delta Token0 amount owed. /// @param amount1Delta Token1 amount owed. /// @param data Arbitrary data forwarded from swap() caller. A packed encoding of: payer, sellToken, (optionally: permit[0x20:], isForwarded, sig) function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) private { address payer; assembly ("memory-safe") { payer := shr(0x60, calldataload(data.offset)) data.length := sub(data.length, 0x14) data.offset := add(0x14, data.offset) // We don't check for underflow/array-out-of-bounds here because the trusted inithash // ensures that `data` was passed unmodified from `_updateSwapCallbackData`. Therefore, // it is at least 40 bytes long. } uint256 sellAmount = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta); _pay(payer, sellAmount, data); } function _pay(address payer, uint256 amount, bytes calldata permit2Data) private { if (payer == address(this)) { IERC20 token; assembly ("memory-safe") { token := shr(0x60, calldataload(permit2Data.offset)) } token.safeTransfer(msg.sender, amount); } else { assert(payer == address(0)); ISignatureTransfer.PermitTransferFrom calldata permit; bool isForwarded; bytes calldata sig; assembly ("memory-safe") { // this is super dirty, but it works because although `permit` is aliasing in the // middle of `payer`, because `payer` is all zeroes, it's treated as padding for the // first word of `permit`, which is the sell token permit := sub(permit2Data.offset, 0x0c) isForwarded := and(0x01, calldataload(add(0x55, permit2Data.offset))) sig.offset := add(0x75, permit2Data.offset) sig.length := sub(permit2Data.length, 0x75) } ISignatureTransfer.SignatureTransferDetails memory transferDetails = ISignatureTransfer.SignatureTransferDetails({to: msg.sender, requestedAmount: amount}); _transferFrom(permit, transferDetails, sig, isForwarded); } } } // src/core/Velodrome.sol //import {Panic} from "../utils/Panic.sol"; interface IVelodromePair { function metadata() external view returns ( uint256 basis0, uint256 basis1, uint256 reserve0, uint256 reserve1, bool stable, IERC20 token0, IERC20 token1 ); function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external; } abstract contract Velodrome is SettlerAbstract { using UnsafeMath for uint256; using FullMath for uint256; using SafeTransferLib for IERC20; // This is the basis used for token balances. The original token may have fewer decimals, in // which case we scale up by the appropriate factor to give this basis. uint256 internal constant _VELODROME_TOKEN_BASIS = 1 ether; // When computing `k`, to minimize rounding error, we use a significantly larger basis. This // also allows us to save work in the Newton-Raphson step because dividing a quantity with this // basis by a quantity with `_VELODROME_TOKEN_BASIS` basis gives that same // `_VELODROME_TOKEN_BASIS` basis. Convenient *and* accurate. uint256 private constant _VELODROME_INTERNAL_BASIS = _VELODROME_TOKEN_BASIS * _VELODROME_TOKEN_BASIS; uint256 private constant _VELODROME_INTERNAL_TO_TOKEN_RATIO = _VELODROME_INTERNAL_BASIS / _VELODROME_TOKEN_BASIS; // When computing `d` we need to compute the cube of a token quantity and format the result with // `_VELODROME_TOKEN_BASIS`. In order to avoid overflow, we must divide the squared token // quantity by this before multiplying again by the token quantity. Setting this value as small // as possible preserves precision. This gives a result in an awkward basis, but we'll correct // that with `_VELODROME_CUBE_STEP_BASIS` after the cubing uint256 private constant _VELODROME_SQUARE_STEP_BASIS = 54210109; // After squaring a token quantity (in `_VELODROME_TOKEN_BASIS`), we need to multiply again by a // token quantity and then divide out the awkward basis to get back to // `_VELODROME_TOKEN_BASIS`. This constant is what gets us back to the original token quantity // basis. `_VELODROME_TOKEN_BASIS * _VELODROME_TOKEN_BASIS / _VELODROME_SQUARE_STEP_BASIS * // _VELODROME_TOKEN_BASIS / _VELODROME_CUBE_STEP_BASIS == _VELODROME_TOKEN_BASIS` uint256 private constant _VELODROME_CUBE_STEP_BASIS = 18446743945857035631490798146; // The maximum balance in the AMM's implementation of `k` is `b` such that `b * b / 1 ether * b // / 1 ether * b` does not overflow. This that quantity, `b`. uint256 internal constant _VELODROME_MAX_BALANCE = 18446744073709551616000000000; // This is the `k = x^3 * y + y^3 * x` constant function. Unlike the original formulation, the // result has a basis of `_VELODROME_INTERNAL_BASIS` instead of `_VELODROME_TOKEN_BASIS` function _k(uint256 x, uint256 y) private pure returns (uint256) { unchecked { return _k(x, y, x * x); } } function _k(uint256 x, uint256 y, uint256 x_squared) private pure returns (uint256) { unchecked { return _k(x, y, x_squared, y * y); } } function _k(uint256 x, uint256 y, uint256 x_squared, uint256 y_squared) private pure returns (uint256) { unchecked { return (x * y).unsafeMulDivAlt(x_squared + y_squared, _VELODROME_INTERNAL_BASIS); } } function _k_compat(uint256 x, uint256 y) internal pure returns (uint256) { unchecked { return (x * y).unsafeMulDivAlt(x * x + y * y, _VELODROME_INTERNAL_BASIS * _VELODROME_TOKEN_BASIS); } } // For numerically approximating a solution to the `k = x^3 * y + y^3 * x` constant function // using Newton-Raphson, this is `∂k/∂y = 3 * x * y^2 + x^3`. The result has a basis of // `_VELODROME_TOKEN_BASIS`. function _d(uint256 y, uint256 x) private pure returns (uint256) { unchecked { return _d(y, 3 * x, x * x / _VELODROME_SQUARE_STEP_BASIS * x / _VELODROME_CUBE_STEP_BASIS); } } function _d(uint256 y, uint256 three_x, uint256 x_cubed) private pure returns (uint256) { unchecked { return _d(y, three_x, x_cubed, y * y / _VELODROME_SQUARE_STEP_BASIS); } } function _d(uint256, uint256 three_x, uint256 x_cubed, uint256 y_squared) private pure returns (uint256) { unchecked { return y_squared * three_x / _VELODROME_CUBE_STEP_BASIS + x_cubed; } } error NotConverged(); // Using Newton-Raphson iterations, compute the smallest `new_y` such that `_k(x + dx, new_y) >= // _k(x, y)`. As a function of `new_y`, we find the root of `_k(x + dx, new_y) - _k(x, y)`. function _get_y(uint256 x, uint256 dx, uint256 y) internal pure returns (uint256) { unchecked { uint256 k_orig = _k(x, y); // `k_orig` has a basis much greater than is actually required for correctness. To // achieve wei-level accuracy, we perform our final comparisons agains `k_target` // instead, which has the same precision as the AMM itself. uint256 k_target = k_orig / _VELODROME_INTERNAL_TO_TOKEN_RATIO; // Now that we have `k` computed, we offset `x` to account for the sell amount and use // the constant-product formula to compute an initial estimate for `y`. x += dx; y -= (dx * y).unsafeDiv(x); // These intermediate values do not change throughout the Newton-Raphson iterations, so // precomputing and caching them saves us gas. uint256 three_x = 3 * x; uint256 x_squared_raw = x * x; uint256 x_cubed = x_squared_raw / _VELODROME_SQUARE_STEP_BASIS * x / _VELODROME_CUBE_STEP_BASIS; for (uint256 i; i < 255; i++) { uint256 y_squared_raw = y * y; uint256 k = _k(x, y, x_squared_raw, y_squared_raw); uint256 d = _d(y, three_x, x_cubed, y_squared_raw / _VELODROME_SQUARE_STEP_BASIS); if (k < k_orig) { uint256 dy = (k_orig - k).unsafeDiv(d); // there are two cases where `dy == 0` // case 1: The `y` is converged and we find the correct answer // case 2: `_d(y, x)` is too large compare to `(k_orig - k)` and the rounding // error screwed us. // In this case, we need to increase `y` by 1 if (dy == 0) { uint256 k_next = _k(x, y + 1, x_squared_raw) / _VELODROME_INTERNAL_TO_TOKEN_RATIO; if (k_next >= k_target) { // If `_k(x, y + 1) >= k_orig`, then we are close to the correct answer. // There's no closer answer than `y + 1` return y + 1; } // `y + 1` does not give us the condition `k >= k_orig`, so we have to do at // least 1 more iteration to find a satisfactory `y` value dy = 2; } y += dy; if (y > _VELODROME_MAX_BALANCE) { y = _VELODROME_MAX_BALANCE; } } else { uint256 dy = (k - k_orig).unsafeDiv(d); if (dy == 0) { if (k / _VELODROME_INTERNAL_TO_TOKEN_RATIO == k_target) { // Likewise, if `k == k_orig`, we found the correct answer. return y; } uint256 k_next = _k(x, y - 1, x_squared_raw) / _VELODROME_INTERNAL_TO_TOKEN_RATIO; if (k_next < k_target) { // If `_k(x, y - 1) < k_orig`, then we are close to the correct answer. // There's no closer answer than `y` // It's worth mentioning that we need to find `y` where `_k(x, y) >= // k_orig` // As a result, we can't return `y - 1` even it's closer to the correct // answer return y; } if (k_next == k_target) { return y - 1; } // It's possible that `y - 1` is the correct answer. To know that, we must // check that `y - 2` gives `k < k_orig`. We must do at least 1 more // iteration to determine this. dy = 2; } y -= dy; } } revert NotConverged(); } } function sellToVelodrome(address recipient, uint256 bps, IVelodromePair pair, uint24 swapInfo, uint256 minAmountOut) internal { // Preventing calls to Permit2 or AH is not explicitly required as neither of these contracts implement the `swap` nor `transfer` selector // |7|6|5|4|3|2|1|0| - bit positions in swapInfo (uint8) // |0|0|0|0|0|0|F|Z| - Z: zeroForOne flag, F: sellTokenHasFee flag bool zeroForOne = (swapInfo & 1) == 1; // Extract the least significant bit (bit 0) bool sellTokenHasFee = (swapInfo & 2) >> 1 == 1; // Extract the second least significant bit (bit 1) and shift it right uint256 feeBps = swapInfo >> 8; ( uint256 sellBasis, uint256 buyBasis, uint256 sellReserve, uint256 buyReserve, bool stable, IERC20 sellToken, IERC20 buyToken ) = pair.metadata(); assert(stable); if (!zeroForOne) { (sellBasis, buyBasis, sellReserve, buyReserve, sellToken, buyToken) = (buyBasis, sellBasis, buyReserve, sellReserve, buyToken, sellToken); } uint256 buyAmount; unchecked { // Compute sell amount in native units uint256 sellAmount; if (bps != 0) { // It must be possible to square the sell token balance of the pool, otherwise it // will revert with an overflow. Therefore, it can't be so large that multiplying by // a "reasonable" `bps` value could overflow. We don't care to protect against // unreasonable `bps` values because that just means the taker is griefing themself. sellAmount = (sellToken.fastBalanceOf(address(this)) * bps).unsafeDiv(BASIS); } if (sellAmount != 0) { sellToken.safeTransfer(address(pair), sellAmount); } if (sellAmount == 0 || sellTokenHasFee) { sellAmount = sellToken.fastBalanceOf(address(pair)) - sellReserve; } // Convert reserves from native units to `_VELODROME_TOKEN_BASIS` sellReserve = (sellReserve * _VELODROME_TOKEN_BASIS).unsafeDiv(sellBasis); buyReserve = (buyReserve * _VELODROME_TOKEN_BASIS).unsafeDiv(buyBasis); // This check is commented because values that are too large will // result in reverts inside the pool anyways. We don't need to // bother. /* // Check for overflow if (buyReserve > _VELODROME_MAX_BALANCE) { Panic.panic(Panic.ARITHMETIC_OVERFLOW); } if (sellReserve + (sellAmount * _VELODROME_TOKEN_BASIS).unsafeDiv(sellBasis) > _VELODROME_MAX_BALANCE) { Panic.panic(Panic.ARITHMETIC_OVERFLOW); } */ // Apply the fee in native units sellAmount -= sellAmount * feeBps / 10_000; // can't overflow // Convert sell amount from native units to `_VELODROME_TOKEN_BASIS` sellAmount = (sellAmount * _VELODROME_TOKEN_BASIS).unsafeDiv(sellBasis); // Solve the constant function numerically to get `buyAmount` from `sellAmount` buyAmount = buyReserve - _get_y(sellReserve, sellAmount, buyReserve); // Convert `buyAmount` from `_VELODROME_TOKEN_BASIS` to native units buyAmount = buyAmount * buyBasis / _VELODROME_TOKEN_BASIS; } buyAmount--; if (buyAmount < minAmountOut) { revert TooMuchSlippage(sellToken, minAmountOut, buyAmount); } { (uint256 buyAmount0, uint256 buyAmount1) = zeroForOne ? (uint256(0), buyAmount) : (buyAmount, uint256(0)); pair.swap(buyAmount0, buyAmount1, recipient, new bytes(0)); } } } // src/core/Basic.sol abstract contract Basic is SettlerAbstract { using SafeTransferLib for IERC20; using FullMath for uint256; using Revert for bool; /// @dev Sell to a pool with a generic approval, transferFrom interaction. /// offset in the calldata is used to update the sellAmount given a proportion of the sellToken balance function basicSellToPool(IERC20 sellToken, uint256 bps, address pool, uint256 offset, bytes memory data) internal { if (_isRestrictedTarget(pool)) { revert ConfusedDeputy(); } bool success; bytes memory returnData; uint256 value; if (sellToken == ETH_ADDRESS) { value = address(this).balance.mulDiv(bps, BASIS); if (data.length == 0) { if (offset != 0) revert InvalidOffset(); (success, returnData) = payable(pool).call{value: value}(""); success.maybeRevert(returnData); return; } else { if ((offset += 32) > data.length) { Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS); } assembly ("memory-safe") { mstore(add(data, offset), value) } } } else if (address(sellToken) == address(0)) { // TODO: check for zero `bps` if (offset != 0) revert InvalidOffset(); } else { uint256 amount = sellToken.fastBalanceOf(address(this)).mulDiv(bps, BASIS); if ((offset += 32) > data.length) { Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS); } assembly ("memory-safe") { mstore(add(data, offset), amount) } if (address(sellToken) != pool) { sellToken.safeApproveIfBelow(pool, amount); } } (success, returnData) = payable(pool).call{value: value}(data); success.maybeRevert(returnData); // forbid sending data to EOAs if (returnData.length == 0 && pool.code.length == 0) revert InvalidTarget(); } } // src/core/Permit2Payment.sol library TransientStorage { // bytes32(uint256(keccak256("operator slot")) - 1) bytes32 private constant _OPERATOR_SLOT = 0x009355806b743562f351db2e3726091207f49fa1cdccd5c65a7d4860ce3abbe9; // bytes32(uint256(keccak256("witness slot")) - 1) bytes32 private constant _WITNESS_SLOT = 0x1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa; // bytes32(uint256(keccak256("payer slot")) - 1) bytes32 private constant _PAYER_SLOT = 0x46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde893; // We assume (and our CI enforces) that internal function pointers cannot be // greater than 2 bytes. On chains not supporting the ViaIR pipeline, not // supporting EOF, and where the Spurious Dragon size limit is not enforced, // it might be possible to violate this assumption. However, our // `foundry.toml` enforces the use of the IR pipeline, so the point is moot. // // `operator` must not be `address(0)`. This is not checked. // `callback` must not be zero. This is checked in `_invokeCallback`. function setOperatorAndCallback( address operator, uint32 selector, function (bytes calldata) internal returns (bytes memory) callback ) internal { address currentSigner; assembly ("memory-safe") { currentSigner := tload(_PAYER_SLOT) } if (operator == currentSigner) { revert ConfusedDeputy(); } uint256 callbackInt; assembly ("memory-safe") { callbackInt := tload(_OPERATOR_SLOT) } if (callbackInt != 0) { // It should be impossible to reach this error because the first thing the fallback does // is clear the operator. It's also not possible to reenter the entrypoint function // because `_PAYER_SLOT` is an implicit reentrancy guard. revert ReentrantCallback(callbackInt); } assembly ("memory-safe") { tstore( _OPERATOR_SLOT, or( shl(0xe0, selector), or(shl(0xa0, and(0xffff, callback)), and(0xffffffffffffffffffffffffffffffffffffffff, operator)) ) ) } } function checkSpentOperatorAndCallback() internal view { uint256 callbackInt; assembly ("memory-safe") { callbackInt := tload(_OPERATOR_SLOT) } if (callbackInt != 0) { revert CallbackNotSpent(callbackInt); } } function getAndClearOperatorAndCallback() internal returns (bytes4 selector, function (bytes calldata) internal returns (bytes memory) callback, address operator) { assembly ("memory-safe") { selector := tload(_OPERATOR_SLOT) callback := and(0xffff, shr(0xa0, selector)) operator := selector tstore(_OPERATOR_SLOT, 0x00) } } // `newWitness` must not be `bytes32(0)`. This is not checked. function setWitness(bytes32 newWitness) internal { bytes32 currentWitness; assembly ("memory-safe") { currentWitness := tload(_WITNESS_SLOT) } if (currentWitness != bytes32(0)) { // It should be impossible to reach this error because the first thing a metatransaction // does on entry is to spend the `witness` (either directly or via a callback) revert ReentrantMetatransaction(currentWitness); } assembly ("memory-safe") { tstore(_WITNESS_SLOT, newWitness) } } function checkSpentWitness() internal view { bytes32 currentWitness; assembly ("memory-safe") { currentWitness := tload(_WITNESS_SLOT) } if (currentWitness != bytes32(0)) { revert WitnessNotSpent(currentWitness); } } function getAndClearWitness() internal returns (bytes32 witness) { assembly ("memory-safe") { witness := tload(_WITNESS_SLOT) tstore(_WITNESS_SLOT, 0x00) } } function setPayer(address payer) internal { if (payer == address(0)) { revert ConfusedDeputy(); } address oldPayer; assembly ("memory-safe") { oldPayer := tload(_PAYER_SLOT) } if (oldPayer != address(0)) { revert ReentrantPayer(oldPayer); } assembly ("memory-safe") { tstore(_PAYER_SLOT, and(0xffffffffffffffffffffffffffffffffffffffff, payer)) } } function getPayer() internal view returns (address payer) { assembly ("memory-safe") { payer := tload(_PAYER_SLOT) } } function clearPayer(address expectedOldPayer) internal { address oldPayer; assembly ("memory-safe") { oldPayer := tload(_PAYER_SLOT) } if (oldPayer != expectedOldPayer) { revert PayerSpent(); } assembly ("memory-safe") { tstore(_PAYER_SLOT, 0x00) } } } abstract contract Permit2PaymentBase is SettlerAbstract { using Revert for bool; /// @dev Permit2 address ISignatureTransfer internal constant _PERMIT2 = ISignatureTransfer(0x000000000022D473030F116dDEE9F6B43aC78BA3); function _isRestrictedTarget(address target) internal pure virtual override returns (bool) { return target == address(_PERMIT2); } function _msgSender() internal view virtual override returns (address) { return TransientStorage.getPayer(); } /// @dev You must ensure that `target` is derived by hashing trusted initcode or another /// equivalent mechanism that guarantees "reasonable"ness. `target` must not be /// user-supplied or attacker-controlled. This is required for security and is not checked /// here. For example, it must not do something weird like modifying the spender (possibly /// setting it to itself). If the callback is expected to relay a /// `ISignatureTransfer.PermitTransferFrom` struct, then the computation of `target` using /// the trusted initcode (or equivalent) must ensure that that calldata is relayed /// unmodified. The library function `AddressDerivation.deriveDeterministicContract` is /// recommended. function _setOperatorAndCall( address payable target, uint256 value, bytes memory data, uint32 selector, function (bytes calldata) internal returns (bytes memory) callback ) internal returns (bytes memory) { TransientStorage.setOperatorAndCallback(target, selector, callback); (bool success, bytes memory returndata) = target.call{value: value}(data); success.maybeRevert(returndata); TransientStorage.checkSpentOperatorAndCallback(); return returndata; } function _setOperatorAndCall( address target, bytes memory data, uint32 selector, function (bytes calldata) internal returns (bytes memory) callback ) internal override returns (bytes memory) { return _setOperatorAndCall(payable(target), 0, data, selector, callback); } function _invokeCallback(bytes calldata data) internal returns (bytes memory) { // Retrieve callback and perform call with untrusted calldata (bytes4 selector, function (bytes calldata) internal returns (bytes memory) callback, address operator) = TransientStorage.getAndClearOperatorAndCallback(); require(bytes4(data) == selector); require(msg.sender == operator); return callback(data[4:]); } } abstract contract Permit2Payment is Permit2PaymentBase { fallback(bytes calldata) external virtual returns (bytes memory) { return _invokeCallback(_msgData()); } function _permitToTransferDetails(ISignatureTransfer.PermitTransferFrom memory permit, address recipient) internal view override returns (ISignatureTransfer.SignatureTransferDetails memory transferDetails, uint256 sellAmount) { transferDetails.to = recipient; transferDetails.requestedAmount = sellAmount = _permitToSellAmount(permit); } // This function is provided *EXCLUSIVELY* for use here and in RfqOrderSettlement. Any other use // of this function is forbidden. You must use the version that does *NOT* take a `from` or // `witness` argument. function _transferFromIKnowWhatImDoing( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, address from, bytes32 witness, string memory witnessTypeString, bytes memory sig, bool isForwarded ) internal override { if (isForwarded) revert ForwarderNotAllowed(); _PERMIT2.permitWitnessTransferFrom(permit, transferDetails, from, witness, witnessTypeString, sig); } // See comment in above overload; don't use this function function _transferFromIKnowWhatImDoing( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, address from, bytes32 witness, string memory witnessTypeString, bytes memory sig ) internal override { _transferFromIKnowWhatImDoing(permit, transferDetails, from, witness, witnessTypeString, sig, _isForwarded()); } function _transferFrom( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, bytes memory sig ) internal override { _transferFrom(permit, transferDetails, sig, _isForwarded()); } } abstract contract Permit2PaymentTakerSubmitted is AllowanceHolderContext, Permit2Payment { using FullMath for uint256; using SafeTransferLib for IERC20; constructor() { assert(!_hasMetaTxn()); } function _permitToSellAmountCalldata(ISignatureTransfer.PermitTransferFrom calldata permit) internal view override returns (uint256 sellAmount) { sellAmount = permit.permitted.amount; if (sellAmount > type(uint256).max - BASIS) { unchecked { sellAmount -= type(uint256).max - BASIS; } sellAmount = IERC20(permit.permitted.token).fastBalanceOf(_msgSender()).mulDiv(sellAmount, BASIS); } } function _permitToSellAmount(ISignatureTransfer.PermitTransferFrom memory permit) internal view override returns (uint256 sellAmount) { sellAmount = permit.permitted.amount; if (sellAmount > type(uint256).max - BASIS) { unchecked { sellAmount -= type(uint256).max - BASIS; } sellAmount = IERC20(permit.permitted.token).fastBalanceOf(_msgSender()).mulDiv(sellAmount, BASIS); } } function _isRestrictedTarget(address target) internal pure virtual override returns (bool) { return target == address(_ALLOWANCE_HOLDER) || super._isRestrictedTarget(target); } function _operator() internal view override returns (address) { return AllowanceHolderContext._msgSender(); } function _msgSender() internal view virtual override(Permit2PaymentBase, AllowanceHolderContext) returns (address) { return Permit2PaymentBase._msgSender(); } function _transferFrom( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, bytes memory sig, bool isForwarded ) internal override { if (isForwarded) { if (sig.length != 0) revert InvalidSignatureLen(); if (permit.nonce != 0) Panic.panic(Panic.ARITHMETIC_OVERFLOW); if (block.timestamp > permit.deadline) revert SignatureExpired(permit.deadline); // we don't check `requestedAmount` because it's checked by AllowanceHolder itself _allowanceHolderTransferFrom( permit.permitted.token, _msgSender(), transferDetails.to, transferDetails.requestedAmount ); } else { _PERMIT2.permitTransferFrom(permit, transferDetails, _msgSender(), sig); } } function _allowanceHolderTransferFrom(address token, address owner, address recipient, uint256 amount) internal override { // `owner` is always `_msgSender()` _ALLOWANCE_HOLDER.transferFrom(token, owner, recipient, amount); } modifier takerSubmitted() override { address msgSender = _operator(); TransientStorage.setPayer(msgSender); _; TransientStorage.clearPayer(msgSender); } modifier metaTx(address, bytes32) override { revert(); _; } } abstract contract Permit2PaymentMetaTxn is Context, Permit2Payment { constructor() { assert(_hasMetaTxn()); } function _permitToSellAmountCalldata(ISignatureTransfer.PermitTransferFrom calldata permit) internal pure override returns (uint256) { return permit.permitted.amount; } function _permitToSellAmount(ISignatureTransfer.PermitTransferFrom memory permit) internal pure override returns (uint256) { return permit.permitted.amount; } function _operator() internal view override returns (address) { return Context._msgSender(); } function _msgSender() internal view virtual override(Permit2PaymentBase, Context) returns (address) { return Permit2PaymentBase._msgSender(); } // `string.concat` isn't recognized by solc as compile-time constant, but `abi.encodePacked` is // This is defined here as `private` and not in `SettlerAbstract` as `internal` because no other // contract/file should reference it. The *ONLY* approved way to make a transfer using this // witness string is by setting the witness with modifier `metaTx` string private constant _SLIPPAGE_AND_ACTIONS_WITNESS = string( abi.encodePacked("SlippageAndActions slippageAndActions)", SLIPPAGE_AND_ACTIONS_TYPE, TOKEN_PERMISSIONS_TYPE) ); function _transferFrom( ISignatureTransfer.PermitTransferFrom memory permit, ISignatureTransfer.SignatureTransferDetails memory transferDetails, bytes memory sig, bool isForwarded // must be false ) internal override { bytes32 witness = TransientStorage.getAndClearWitness(); if (witness == bytes32(0)) { revert ConfusedDeputy(); } _transferFromIKnowWhatImDoing( permit, transferDetails, _msgSender(), witness, _SLIPPAGE_AND_ACTIONS_WITNESS, sig, isForwarded ); } function _allowanceHolderTransferFrom(address, address, address, uint256) internal pure override { revert ConfusedDeputy(); } modifier takerSubmitted() override { revert(); _; } modifier metaTx(address msgSender, bytes32 witness) override { if (_isForwarded()) { revert ForwarderNotAllowed(); } TransientStorage.setWitness(witness); TransientStorage.setPayer(msgSender); _; TransientStorage.clearPayer(msgSender); // It should not be possible for this check to revert because the very first thing that a // metatransaction does is spend the witness. TransientStorage.checkSpentWitness(); } } // src/SettlerBase.sol /// @dev This library's ABIDeocding is more lax than the Solidity ABIDecoder. This library omits index bounds/overflow /// checking when accessing calldata arrays for gas efficiency. It also omits checks against `calldatasize()`. This /// means that it is possible that `args` will run off the end of calldata and be implicitly padded with zeroes. That we /// don't check for overflow means that offsets can be negative. This can also result in `args` that alias other parts /// of calldata, or even the `actions` array itself. library CalldataDecoder { function decodeCall(bytes[] calldata data, uint256 i) internal pure returns (uint256 selector, bytes calldata args) { assembly ("memory-safe") { // initially, we set `args.offset` to the pointer to the length. this is 32 bytes before the actual start of data args.offset := add( data.offset, // We allow the indirection/offset to `calls[i]` to be negative calldataload( add(shl(5, i), data.offset) // can't overflow; we assume `i` is in-bounds ) ) // now we load `args.length` and set `args.offset` to the start of data args.length := calldataload(args.offset) args.offset := add(args.offset, 0x20) // slice off the first 4 bytes of `args` as the selector selector := shr(0xe0, calldataload(args.offset)) args.length := sub(args.length, 0x04) args.offset := add(args.offset, 0x04) } } } abstract contract SettlerBase is Basic, RfqOrderSettlement, UniswapV3Fork, UniswapV2, Velodrome { using SafeTransferLib for IERC20; using SafeTransferLib for address payable; receive() external payable {} event GitCommit(bytes20 indexed); constructor(bytes20 gitCommit, uint256 tokenId) { if (block.chainid != 31337) { emit GitCommit(gitCommit); assert(IERC721Owner(0x00000000000004533Fe15556B1E086BB1A72cEae).ownerOf(tokenId) == address(this)); } else { assert(gitCommit == bytes20(0)); } } struct AllowedSlippage { address recipient; IERC20 buyToken; uint256 minAmountOut; } function _checkSlippageAndTransfer(AllowedSlippage calldata slippage) internal { // This final slippage check effectively prohibits custody optimization on the // final hop of every swap. This is gas-inefficient. This is on purpose. Because // ISettlerActions.BASIC could interact with an intents-based settlement // mechanism, we must ensure that the user's want token increase is coming // directly from us instead of from some other form of exchange of value. (address recipient, IERC20 buyToken, uint256 minAmountOut) = (slippage.recipient, slippage.buyToken, slippage.minAmountOut); if (minAmountOut != 0 || address(buyToken) != address(0)) { if (buyToken == ETH_ADDRESS) { uint256 amountOut = address(this).balance; if (amountOut < minAmountOut) { revert TooMuchSlippage(buyToken, minAmountOut, amountOut); } payable(recipient).safeTransferETH(amountOut); } else { uint256 amountOut = buyToken.fastBalanceOf(address(this)); if (amountOut < minAmountOut) { revert TooMuchSlippage(buyToken, minAmountOut, amountOut); } buyToken.safeTransfer(recipient, amountOut); } } } function _dispatch(uint256, uint256 action, bytes calldata data) internal virtual override returns (bool) { if (action == uint32(ISettlerActions.TRANSFER_FROM.selector)) { (address recipient, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig) = abi.decode(data, (address, ISignatureTransfer.PermitTransferFrom, bytes)); (ISignatureTransfer.SignatureTransferDetails memory transferDetails,) = _permitToTransferDetails(permit, recipient); _transferFrom(permit, transferDetails, sig); } else if (action == uint32(ISettlerActions.RFQ.selector)) { ( address recipient, ISignatureTransfer.PermitTransferFrom memory permit, address maker, bytes memory makerSig, IERC20 takerToken, uint256 maxTakerAmount ) = abi.decode(data, (address, ISignatureTransfer.PermitTransferFrom, address, bytes, IERC20, uint256)); fillRfqOrderSelfFunded(recipient, permit, maker, makerSig, takerToken, maxTakerAmount); } else if (action == uint32(ISettlerActions.UNISWAPV3.selector)) { (address recipient, uint256 bps, bytes memory path, uint256 amountOutMin) = abi.decode(data, (address, uint256, bytes, uint256)); sellToUniswapV3(recipient, bps, path, amountOutMin); } else if (action == uint32(ISettlerActions.UNISWAPV2.selector)) { (address recipient, address sellToken, uint256 bps, address pool, uint24 swapInfo, uint256 amountOutMin) = abi.decode(data, (address, address, uint256, address, uint24, uint256)); sellToUniswapV2(recipient, sellToken, bps, pool, swapInfo, amountOutMin); } else if (action == uint32(ISettlerActions.BASIC.selector)) { (IERC20 sellToken, uint256 bps, address pool, uint256 offset, bytes memory _data) = abi.decode(data, (IERC20, uint256, address, uint256, bytes)); basicSellToPool(sellToken, bps, pool, offset, _data); } else if (action == uint32(ISettlerActions.VELODROME.selector)) { (address recipient, uint256 bps, IVelodromePair pool, uint24 swapInfo, uint256 minAmountOut) = abi.decode(data, (address, uint256, IVelodromePair, uint24, uint256)); sellToVelodrome(recipient, bps, pool, swapInfo, minAmountOut); } else if (action == uint32(ISettlerActions.POSITIVE_SLIPPAGE.selector)) { (address recipient, IERC20 token, uint256 expectedAmount) = abi.decode(data, (address, IERC20, uint256)); if (token == ETH_ADDRESS) { uint256 balance = address(this).balance; if (balance > expectedAmount) { unchecked { payable(recipient).safeTransferETH(balance - expectedAmount); } } } else { uint256 balance = token.fastBalanceOf(address(this)); if (balance > expectedAmount) { unchecked { token.safeTransfer(recipient, balance - expectedAmount); } } } } else { return false; } return true; } } // src/SettlerMetaTxn.sol abstract contract SettlerMetaTxn is Permit2PaymentMetaTxn, SettlerBase { using UnsafeMath for uint256; using CalldataDecoder for bytes[]; // When/if you change this, you must make corresponding changes to // `sh/deploy_new_chain.sh` and 'sh/common_deploy_settler.sh' to set // `constructor_args`. constructor(bytes20 gitCommit) SettlerBase(gitCommit, 3) {} function _hasMetaTxn() internal pure override returns (bool) { return true; } function _msgSender() internal view virtual // Solidity inheritance is so stupid override(Permit2PaymentMetaTxn, AbstractContext) returns (address) { return super._msgSender(); } function _hashArrayOfBytes(bytes[] calldata actions) internal pure returns (bytes32 result) { // This function deliberately does no bounds checking on `actions` for // gas efficiency. We assume that `actions` will get used elsewhere in // this context and any OOB or other malformed calldata will result in a // revert later. assembly ("memory-safe") { let ptr := mload(0x40) let hashesLength := shl(5, actions.length) for { let i := actions.offset let dst := ptr let end := add(i, hashesLength) } lt(i, end) { i := add(i, 0x20) dst := add(dst, 0x20) } { let src := add(actions.offset, calldataload(i)) let length := calldataload(src) calldatacopy(dst, add(src, 0x20), length) mstore(dst, keccak256(dst, length)) } result := keccak256(ptr, hashesLength) } } function _hashActionsAndSlippage(bytes[] calldata actions, AllowedSlippage calldata slippage) internal pure returns (bytes32 result) { // This function does not check for or clean any dirty bits that might // exist in `slippage`. We assume that `slippage` will be used elsewhere // in this context and that if there are dirty bits it will result in a // revert later. bytes32 arrayOfBytesHash = _hashArrayOfBytes(actions); assembly ("memory-safe") { let ptr := mload(0x40) mstore(ptr, SLIPPAGE_AND_ACTIONS_TYPEHASH) calldatacopy(add(ptr, 0x20), slippage, 0x60) mstore(add(ptr, 0x80), arrayOfBytesHash) result := keccak256(ptr, 0xa0) } } function _dispatchVIP(uint256 action, bytes calldata data, bytes calldata sig) internal virtual returns (bool) { if (action == uint32(ISettlerActions.METATXN_RFQ_VIP.selector)) { // An optimized path involving a maker/taker in a single trade // The RFQ order is signed by both maker and taker, validation is // performed inside the RfqOrderSettlement so there is no need to // validate `sig` against `actions` here ( address recipient, ISignatureTransfer.PermitTransferFrom memory makerPermit, address maker, bytes memory makerSig, ISignatureTransfer.PermitTransferFrom memory takerPermit ) = abi.decode( data, (address, ISignatureTransfer.PermitTransferFrom, address, bytes, ISignatureTransfer.PermitTransferFrom) ); fillRfqOrderVIP(recipient, makerPermit, maker, makerSig, takerPermit, sig); } else if (action == uint32(ISettlerActions.METATXN_TRANSFER_FROM.selector)) { (address recipient, ISignatureTransfer.PermitTransferFrom memory permit) = abi.decode(data, (address, ISignatureTransfer.PermitTransferFrom)); (ISignatureTransfer.SignatureTransferDetails memory transferDetails,) = _permitToTransferDetails(permit, recipient); // We simultaneously transfer-in the taker's tokens and authenticate the // metatransaction. _transferFrom(permit, transferDetails, sig); } else if (action == uint32(ISettlerActions.METATXN_UNISWAPV3_VIP.selector)) { ( address recipient, bytes memory path, ISignatureTransfer.PermitTransferFrom memory permit, uint256 amountOutMin ) = abi.decode(data, (address, bytes, ISignatureTransfer.PermitTransferFrom, uint256)); sellToUniswapV3VIP(recipient, path, permit, sig, amountOutMin); } else { return false; } return true; } function executeMetaTxn( AllowedSlippage calldata slippage, bytes[] calldata actions, bytes32, /* zid & affiliate */ address msgSender, bytes calldata sig ) public metaTx(msgSender, _hashActionsAndSlippage(actions, slippage)) returns (bool) { require(actions.length != 0); { (uint256 action, bytes calldata data) = actions.decodeCall(0); // By forcing the first action to be one of the witness-aware // actions, we ensure that the entire sequence of actions is // authorized. `msgSender` is the signer of the metatransaction. if (!_dispatchVIP(action, data, sig)) { revert ActionInvalid(0, bytes4(uint32(action)), data); } } for (uint256 i = 1; i < actions.length; i = i.unsafeInc()) { (uint256 action, bytes calldata data) = actions.decodeCall(i); if (!_dispatch(i, action, data)) { revert ActionInvalid(i, bytes4(uint32(action)), data); } } _checkSlippageAndTransfer(slippage); return true; } } // src/chains/Sonic/Common.sol // Solidity inheritance is stupid abstract contract SonicMixin is FreeMemory, SettlerBase { constructor() { assert(block.chainid == 146 || block.chainid == 31337); } function _dispatch(uint256 i, uint256 action, bytes calldata data) internal virtual override(/* SettlerAbstract, */ SettlerBase) DANGEROUS_freeMemory returns (bool) { if (super._dispatch(i, action, data)) { return true; } else { return false; } return true; } function _uniV3ForkInfo(uint8 forkId) internal pure override returns (address factory, bytes32 initHash, uint32 callbackSelector) { if (forkId == uniswapV3ForkId) { factory = uniswapV3SonicFactory; initHash = uniswapV3InitHash; callbackSelector = uint32(IUniswapV3Callback.uniswapV3SwapCallback.selector); } else if (forkId == spookySwapForkId) { factory = spookySwapFactory; initHash = uniswapV3InitHash; callbackSelector = uint32(IUniswapV3Callback.uniswapV3SwapCallback.selector); } else { revert UnknownForkId(forkId); } } } // src/chains/Sonic/MetaTxn.sol // Solidity inheritance is stupid /// @custom:security-contact [email protected] contract SonicSettlerMetaTxn is SettlerMetaTxn, SonicMixin { constructor(bytes20 gitCommit) SettlerMetaTxn(gitCommit) {} function _dispatchVIP(uint256 action, bytes calldata data, bytes calldata sig) internal override DANGEROUS_freeMemory returns (bool) { if (super._dispatchVIP(action, data, sig)) { return true; } else { return false; } return true; } // Solidity inheritance is stupid function _dispatch(uint256 i, uint256 action, bytes calldata data) internal override(SettlerAbstract, SettlerBase, SonicMixin) returns (bool) { return super._dispatch(i, action, data); } function _msgSender() internal view override(SettlerMetaTxn, AbstractContext) returns (address) { return super._msgSender(); } }
{ "remappings": [ "@solmate/=lib/solmate/src/", "@permit2/=lib/permit2/src/", "@forge-std/=lib/forge-std/src/", "@forge-gas-snapshot/=lib/forge-gas-snapshot/src/", "@uniswapv4/=lib/v4-core/src/", "forge-std/src/=lib/forge-std/src/", "solmate/=lib/solmate/" ], "optimizer": { "enabled": true, "runs": 2000, "details": { "constantOptimizer": true, "yul": true } }, "metadata": { "useLiteralContent": false, "bytecodeHash": "none", "appendCBOR": false }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "cancun", "viaIR": true, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"bytes20","name":"gitCommit","type":"bytes20"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"},{"internalType":"bytes4","name":"action","type":"bytes4"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"ActionInvalid","type":"error"},{"inputs":[{"internalType":"uint256","name":"callbackInt","type":"uint256"}],"name":"CallbackNotSpent","type":"error"},{"inputs":[],"name":"ConfusedDeputy","type":"error"},{"inputs":[],"name":"ForwarderNotAllowed","type":"error"},{"inputs":[],"name":"InvalidOffset","type":"error"},{"inputs":[],"name":"InvalidTarget","type":"error"},{"inputs":[],"name":"NotConverged","type":"error"},{"inputs":[],"name":"PayerSpent","type":"error"},{"inputs":[{"internalType":"uint256","name":"callbackInt","type":"uint256"}],"name":"ReentrantCallback","type":"error"},{"inputs":[{"internalType":"bytes32","name":"oldWitness","type":"bytes32"}],"name":"ReentrantMetatransaction","type":"error"},{"inputs":[{"internalType":"address","name":"oldPayer","type":"address"}],"name":"ReentrantPayer","type":"error"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"expected","type":"uint256"},{"internalType":"uint256","name":"actual","type":"uint256"}],"name":"TooMuchSlippage","type":"error"},{"inputs":[{"internalType":"uint8","name":"forkId","type":"uint8"}],"name":"UnknownForkId","type":"error"},{"inputs":[{"internalType":"bytes32","name":"oldWitness","type":"bytes32"}],"name":"WitnessNotSpent","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes20","name":"","type":"bytes20"}],"name":"GitCommit","type":"event"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"contract IERC20","name":"buyToken","type":"address"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"internalType":"struct SettlerBase.AllowedSlippage","name":"slippage","type":"tuple"},{"internalType":"bytes[]","name":"actions","type":"bytes[]"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"msgSender","type":"address"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"executeMetaTxn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
6080604090808252346102e65780612fba803803809161001f828561033f565b83396020928391810103126102e657516001600160601b0319811691908290036102e6576100ef605b845161005381610310565b8181527f6e416d6f756e744f75742c62797465735b5d20616374696f6e732900000000006060858301927f536c697070616765416e64416374696f6e73286164647265737320726563697084527f69656e742c6164647265737320627579546f6b656e2c75696e74323536206d69898201520152207f615e8d716cef7295e75dd3f1f10d679914ad6d7759e8e9459f0109ef7524170114610362565b6101276100fa61037d565b8281519101207f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa14610362565b610200835161013581610310565b604b81528281017f5266714f7264657228436f6e73696465726174696f6e206d616b6572436f6e7381527f696465726174696f6e2c436f6e73696465726174696f6e2074616b6572436f6e868301526a73696465726174696f6e2960a81b60608301526101d6846101a461037d565b9281895194859282840197518091895e8301908282015f8152815193849201905e015f8382015203808452018261033f565b5190207f49fa719b76f0f6b7e76be94b56c26671a548e1c712d5b13dc2874f70a759827614610362565b46617a691491826102fb578351907f16fbd3a71aa6d159973eb9ff1e1199f9fe242767e6f30ac662a492f92ac704115f80a26331a9108f60e11b81526003600482015281816024816d04533fe15556b1e086bb1a72ceae5afa9182156102f1575f926102a9575b50610294929161028291506001600160a01b03163014610362565b609246149081156102a1575b50610362565b51612bb790816104038239f35b90505f61028e565b90809250813d83116102ea575b6102c0818361033f565b810103126102e65751906001600160a01b03821682036102e65790610282610294610267565b5f80fd5b503d6102b6565b84513d5f823e3d90fd5b61029492915061030b9015610362565b610282565b608081019081106001600160401b0382111761032b57604052565b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b0382119082101761032b57604052565b1561036957565b634e487b7160e01b5f52600160045260245ffd5b6040519061038a82610310565b605882527f626f6f6c207061727469616c46696c6c416c6c6f7765642900000000000000006060837f436f6e73696465726174696f6e286164647265737320746f6b656e2c75696e7460208201527f32353620616d6f756e742c6164647265737320636f756e74657270617274792c6040820152015256fe6080604052600436108015610447575b361561044557346103ce577e9355806b743562f351db2e3726091207f49fa1cdccd5c65a7d4860ce3abbe9905f825c925d7fffffffff000000000000000000000000000000000000000000000000000000005f3581811692610430575b508083169116036103ce576001600160a01b0380821633036103ce57366004116103ce576003199160a01c61ffff166001146100b657634e487b7160e01b5f52605160045260245ffd5b6080823601106103ce5760443591602483013560601c91906004355f81131561042657925b308103610108575050506100f79160383391013560601c6112a8565b60405161010381610aab565b5f9052005b6101159093929315611334565b6040519161012283610a4b565b338352602083015261013736602c8601610b76565b9061016c367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7787600401350160ad8801610b22565b907f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa955f875c975d86156103fc577f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c96608d604051926101cc84610a7b565b605b84526102d0604660208601957f536c697070616765416e64416374696f6e73286164647265737320726563697087527f69656e742c6164647265737320627579546f6b656e2c75696e74323536206d6960408201527f6e416d6f756e744f75742c62797465735b5d20616374696f6e732900000000006060820152602061025361134f565b6040519889937f536c697070616765416e64416374696f6e7320736c697070616765416e644163848601527f74696f6e7329000000000000000000000000000000000000000000000000000060408601525180918686015e8301908482015f8152815193849201905e015f83820152036026810187520185610ae3565b01356001166103d2576e22d473030f116ddee9f6b43ac78ba396873b156103ce576040517f137c29fe000000000000000000000000000000000000000000000000000000008152865180516001600160a01b03166004830152602001516024820152988997889760208181015160448b015260409091015160648a015281516001600160a01b031660848a0152015160a48801521660c486015260e4850152610104840161014090526101448401610387916121a8565b908382030161012484015261039b916121a8565b03815a5f948591f180156103c3576103b4575b506100f7565b6103bd90610a97565b5f6103ae565b6040513d5f823e3d90fd5b5f80fd5b60046040517f1c500e5c000000000000000000000000000000000000000000000000000000008152fd5b60046040517fe758b8d5000000000000000000000000000000000000000000000000000000008152fd5b50602435926100db565b818093503660040360031b1b1616905f61006c565b005b5f3560e01c63fd3ad6d40361000f57346103ce57600319360160e081126103ce576060136103ce5767ffffffffffffffff606435116103ce573660236064350112156103ce5767ffffffffffffffff60643560040135116103ce573660246064356004013560051b6064350101116103ce576001600160a01b0360a4351660a435036103ce5767ffffffffffffffff60c435116103ce5736602360c4350112156103ce5767ffffffffffffffff60c43560040135116103ce5736602460c4356004013560c4350101116103ce5760806064356024015b60246064356004013560051b606435010181106109d95760a06064356004013560051b608020604051907f615e8d716cef7295e75dd3f1f10d679914ad6d7759e8e9459f0109ef7524170182526060600460208401376080820152207f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5c806109a857507f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5d6001600160a01b0360a43516156103fc576001600160a01b037f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c16806109775760a4356001600160a01b03167f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935d60643560040135156103ce57602460643501356064350160448101359060486003196024830135019101916040519261067c60c43560040135602460c4350185848660e01c610a30565b84604052156109105760015b60643560040135811061085d576004356001600160a01b0381168082036103ce57602435906001600160a01b038216928383036103ce57604435938415801590610854575b6107c3575b50505050506001600160a01b0360a435166001600160a01b037f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c1603610799575f7f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935d7f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5c8061076857602060405160018152f35b602490604051907fe25527c20000000000000000000000000000000000000000000000000000000082526004820152fd5b60046040517f5149e795000000000000000000000000000000000000000000000000000000008152fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee03610831575047918383106107fc57506107f292506112f8565b80808080806106d2565b6040516397a6f3b960e01b81526001600160a01b039190911660048201526024810193909352506044820152606490fd5b0390fd5b905061083d3083611274565b918383106107fc5761084f93506112a8565b6107f2565b508015156106cd565b60246064358260051b0101356064350190604482013591604860031960248301350191016040519161089381838760e01c611269565b83604052156108a9575050506001915001610688565b7fffffffff00000000000000000000000000000000000000000000000000000000839584957f3c74eed60000000000000000000000000000000000000000000000000000000061082d96526004870152166024850152606060448501526064840191610a10565b83927fffffffff0000000000000000000000000000000000000000000000000000000061082d937f3c74eed60000000000000000000000000000000000000000000000000000000086525f6004870152166024850152606060448501526064840191610a10565b602490604051907f7407c0f80000000000000000000000000000000000000000000000000000000082526004820152fd5b602490604051907f9936cbab0000000000000000000000000000000000000000000000000000000082526004820152fd5b60448135606435016024810135918291018437822082526020918201910161051d565b35906001600160a01b03821682036103ce57565b601f8260209493601f1993818652868601375f8582860101520116010190565b90610a3d94939291610be1565b15610a4757600190565b5f90565b6040810190811067ffffffffffffffff821117610a6757604052565b634e487b7160e01b5f52604160045260245ffd5b6080810190811067ffffffffffffffff821117610a6757604052565b67ffffffffffffffff8111610a6757604052565b6020810190811067ffffffffffffffff821117610a6757604052565b6060810190811067ffffffffffffffff821117610a6757604052565b90601f601f19910116810190811067ffffffffffffffff821117610a6757604052565b67ffffffffffffffff8111610a6757601f01601f191660200190565b929192610b2e82610b06565b91610b3c6040519384610ae3565b8294818452818301116103ce578281602093845f960137010152565b9080601f830112156103ce57816020610b7393359101610b22565b90565b8092910391608083126103ce57604051906060820182811067ffffffffffffffff821117610a67578060405260408395126103ce5760409181610bba606093610a4b565b610bc3826109fc565b81526020820135608086015284528281013560208501520135910152565b909190635228831d8103610d9d57508101610160828203126103ce57610c06826109fc565b90610c148160208501610b76565b94610c2160a085016109fc565b9460c08501359667ffffffffffffffff88116103ce57610d3a866fffffffffffffffffffffffffffffffff96610c94610c738860e0610c6c610d989f9b610d909c610d299f01610b58565b9501610b76565b9a610c8c6001600160a01b039788809316993691610b22565b921685611307565b9990918b610d238880610ca78c85611307565b929094515116917f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c9060405193610cde85610a7b565b845260208401521660408201525f6060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b9c612219565b8986610d336113ae565b9286612387565b5151169060405191610d4b83610a7b565b825284602083015260408201525f6060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b911691612482565b600190565b92939192630dfeb4198103610df85750820160a0838203126103ce57610d9893610de96001600160a01b03610de1610df2946020610dda896109fc565b9801610b76565b951685611307565b50923691610b22565b91612219565b9294919392639ebf8e8d036112605784019360e0818603126103ce57610e1d816109fc565b9260208201359067ffffffffffffffff82116103ce57610e4f610e4588610e57948601610b58565b9760408501610b76565b953691610b22565b8051608901948560891161124c57602091601f19610e8d610e7789610b06565b98610e856040519a8b610ae3565b808a52610b06565b013684890137815183015187604801526040828401886068015e5f8760a8015380519083018760a9015e5101515f937f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82116110f55795905b815190602c821061109457866014840151601585015197601886015190602c870151948386879c6001600160a01b0389166001600160a01b0388161015611241575b60ff16806111a757506001600160a01b0391605591604073cb2436774c3e191c85056d248ef4260ce5f27a9d927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e33995b62ffffff169083519288165f5287166020528083521560051b6060035f20938183528152600b81019360ff855360208201520152201691855190858760280152866014015285528c602c88115f1461112c57506110396001600160a01b0393878594611034611048956110266040519b8c9586938d8c8084169116105f1461110e578d8c806401000276a4945b630251596160e31b60208a01521691161030602487016121cd565b03601f198101845283610ae3565b6127f9565b60208082518301019101612203565b9590946040525b169116101561110757505b5f03945f86126110f557602c869211156110a657505030939060188151106110945780516017190160189091019081526028865290610ee6565b634e487b715f5260326020526024601cfd5b939650935050925060c083013582106110c157505050600190565b6040516397a6f3b960e01b81526001600160a01b0391909116600482015260c0929092013560248301526044820152606490fd5b634e487b715f5260116020526024601cfd5b905061105a565b8d8c8073fffd8963efd1fc6a506488495d951d5263988d259461100b565b926001600160a01b036111839361103489611026849b9a8a61103998879b888616898416105f1461118b57886401000276a4935b816040519b8c99630251596160e31b60208c0152169116109116602487016121cd565b94909361104f565b8873fffd8963efd1fc6a506488495d951d5263988d2593611160565b9091929394959650601b81145f14611210575060558d96959493926001600160a01b03926040733d91b700252e0e3ee7805d12e048a988ab69c8ad927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e3399610f7e565b602490604051907fd3b1276d0000000000000000000000000000000000000000000000000000000082526004820152fd5b889250869150610f28565b634e487b7160e01b5f52601160045260245ffd5b50925050505f90565b90610a3d92916114a8565b602460105f926020946014526f70a0823100000000000000000000000084525afa156103c357601f3d11156103ce575f5190565b60105f60449260209582956014526034526fa9059cbb00000000000000000000000082525af1156103c3573d15601f3d1160015f51141617156112eb575f603452565b6390b8ec185f526004601cfd5b5f80809381935af1156103c357565b909160206040519261131884610a4b565b818401935f85526001600160a01b038196169052510151809252565b1561133b57565b634e487b7160e01b5f52600160045260245ffd5b6040519061135c82610ac7565b602e82527f696e7432353620616d6f756e74290000000000000000000000000000000000006040837f546f6b656e5065726d697373696f6e73286164647265737320746f6b656e2c7560208201520152565b6040516113ba81610a7b565b60588152610b73603c60208301927f436f6e73696465726174696f6e286164647265737320746f6b656e2c75696e7484527f32353620616d6f756e742c6164647265737320636f756e74657270617274792c60408201527f626f6f6c207061727469616c46696c6c416c6c6f7765642900000000000000006060820152602061144161134f565b6040519586937f436f6e73696465726174696f6e20636f6e73696465726174696f6e2900000000848601525180918686015e8301908482015f8152815193849201905e015f8382015203601c810184520182610ae3565b359062ffffff821682036103ce57565b90919063c1fb425e81036115185750810160c0828203126103ce576114cc826109fc565b906114da8160208501610b76565b9060a084013567ffffffffffffffff81116103ce57611509611511926001600160a01b0392610d989701610b58565b931682611307565b5090612219565b63d92aadfb81036116e957508101610120828203126103ce5761153a826109fc565b916115488260208301610b76565b9161155560a083016109fc565b9160c08101359167ffffffffffffffff83116103ce57610d98956115c1956115936116d8936fffffffffffffffffffffffffffffffff968601610b58565b916101006115a360e087016109fc565b950135906116ca6001600160a01b03998a809a169a8b931685611307565b61169d6116238c88959495515116604051906115dc82610a7b565b815283602082015286604082015260016060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b604051909c7f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c61165383610a7b565b818d16835288602084015216604082015260016060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b9b8c956116aa308c611274565b928184116116df575b90836116be92612aec565b998a60208601526112a8565b6116d26113ae565b93612387565b1691612482565b90925082906116b3565b919291638d68a1568103611aa057508201906080838303126103ce5761170e836109fc565b9060208401359260408501359067ffffffffffffffff82116103ce57611735918601610b58565b9261177d84516020860151907fffffffffffffffffffffffffffffffffffffffff000000000000000000000000918281169160148110611a8b575b503092505060601c611274565b81810291818304149015171561124c57612710900493604051936117a085610ac7565b6028855260403660208701379430937f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82116110f55795905b815190602c821061109457866014840151601585015197601886015190602c870151948386879c6001600160a01b0389166001600160a01b0388161015611a80575b60ff1680611a1757506001600160a01b0391605591604073cb2436774c3e191c85056d248ef4260ce5f27a9d927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e33995b62ffffff169083519288165f5287166020528083521560051b6060035f20938183528152600b81019360ff855360208201520152201691855190858760280152866014015285528c602c88115f146119b957506110396001600160a01b0393878594611034611917956110266040519b8c9586938d8c8084169116105f1461110e57630251596160e31b60208601526401000276a4918c168c8f161030602487016121cd565b9590946040525b16911610156119b257505b5f03945f86126110f557602c86921115611963575050309390601881511061109457805160171901601890910190815260288652906117d9565b93965093505092506060830135821061197e57505050600190565b6040516397a6f3b960e01b81526001600160a01b039190911660048201526060929092013560248301526044820152606490fd5b9050611929565b926001600160a01b03611a0f9361103489611026849b9a8a61103998879b888616898416105f1461118b57886401000276a493816040519b8c99630251596160e31b60208c0152169116109116602487016121cd565b94909361191e565b9091929394959650601b81145f14611210575060558d96959493926001600160a01b03926040733d91b700252e0e3ee7805d12e048a988ab69c8ad927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e3399611871565b88925086915061181b565b8391925060140360031b1b1616805f80611770565b928363103b48be829495145f14611d92575060c091810103126103ce57611ac6816109fc565b602091611ad48382016109fc565b9160409182810135611ae8606083016109fc565b60a0611af660808501611498565b930135926001600160a01b03808098169216926001928380841614935f9280611d79575b50928293895193611d43575b630902f1ac5f52895f6004601c8a5afa15611d3a57893d106103ce578b8b928760051b9687519288811851948084811c1614821517611ced575b506060955061ffff6127109260081c1682030292028201910204975f601c8d8187019763022c0d9f88526080808901528360a08901528c82828a0101526004011886010152169101525f8060a48382875af115611ce55750828410611bcb5750505050505050600190565b600491879115611c81578551928380927fd21220a70000000000000000000000000000000000000000000000000000000082525afa908115611c775761082d9495965f92611c4a575b5050935b519485946397a6f3b960e01b865216600485016040919493926001600160a01b03606083019616825260208201520152565b611c699250803d10611c70575b611c618183610ae3565b8101906127da565b8680611c14565b503d611c57565b84513d5f823e3d90fd5b8551928380927f0dfe16810000000000000000000000000000000000000000000000000000000082525afa908115611c775761082d9495965f92611cc8575b505093611c18565b611cde9250803d10611c7057611c618183610ae3565b8680611cc0565b3d5f823e3d90fd5b9294505091936024601c5f926370a0823184528b85525afa15611d3a578b3d106103ce575f51838110611d29579183916060948d94038e611b60565b60118d634e487b715f52526024601cfd5b833d5f823e3d90fd5b63a9059cbb8452868c850152848a8501528b5f6044601c870182875af115611d3a57805f51148c3d1015163d1517611b26575f80fd5b612710919350611d893084611274565b0204915f611b1a565b6338c9c1478103611dff5750019060a0818303126103ce57611db3816109fc565b90611dc0604082016109fc565b90608081013567ffffffffffffffff81116103ce57610d9894611de4918301610b58565b9260206001600160a01b036060840135941692013590612508565b63f5b9918981036120ef575060a091810103126103ce57611e1f816109fc565b602082013591604091828201356001600160a01b03948582168092036103ce576080611e4d60608601611498565b940135600180861614918651957f392f37e900000000000000000000000000000000000000000000000000000000875260e087600481885afa80156120e5575f975f905f945f809b5f935f9661206c575b5080948098809784969f611eb190611334565b8c15612053575b5050505050928286611f1b9461271098979461ffff978f8e87915f938061203c575b5083158015908161202c575b9061201e575b612009575b505050670de0b6b3a76400009a8b948580940204998a9860081c1682020490030204920204612909565b90030204801561124c575f190194818610611fd857505015611fd2575f925b8451611f4581610aab565b5f8152823b156103ce575f94611fa386928851998a97889687957f022c0d9f000000000000000000000000000000000000000000000000000000008752600487015260248601521660448401526080606484015260848301906121a8565b03925af1908115611fc95750611fba575b50600190565b611fc390610a97565b5f611fb4565b513d5f823e3d90fd5b5f611f3a565b86516397a6f3b960e01b81526001600160a01b03919091166004820152602481019190915260448101859052606490fd5b612014929350611274565b038f8e8791611ef1565b506001808b811c1614611eec565b6120378685856112a8565b611ee6565b8e91945061204a3086611274565b0204925f611eda565b9e50919850919550909350915088868c8461ffff611eb8565b9c505050945050505060e0873d60e0116120dd575b8161208e60e09383610ae3565b810103126103ce578651602088015190898901519060608a01519460808b015180151581036103ce576120cf60c06120c860a08f016124c5565b9d016124c5565b92949396909b92945f611e9e565b3d9150612081565b88513d5f823e3d90fd5b63c876d21d141590506121a25781606091810103126103ce57612111816109fc565b604061211f602084016109fc565b920135916001600160a01b0391821691811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036121715750479180831161215e575b505050600190565b6121699203906112f8565b5f8080612156565b9061217c3083611274565b9280841161218e575b50505050600190565b6121999303916112a8565b5f808080612185565b50505f90565b90601f19601f602080948051918291828752018686015e5f8582860101520116010190565b919360a093610b7396956001600160a01b03809416855215156020850152604084015216606082015281608082015201906121a8565b91908260409103126103ce576020825192015190565b9190917f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5f815c915d80156103fc57612385937f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c906040519361227c85610a7b565b605b8552612380604660208701967f536c697070616765416e64416374696f6e73286164647265737320726563697088527f69656e742c6164647265737320627579546f6b656e2c75696e74323536206d6960408201527f6e416d6f756e744f75742c62797465735b5d20616374696f6e732900000000006060820152602061230361134f565b604051998a937f536c697070616765416e64416374696f6e7320736c697070616765416e644163848601527f74696f6e7329000000000000000000000000000000000000000000000000000060408601525180918686015e8301908482015f8152815193849201905e015f83820152036026810188520186610ae3565b612387565b565b91909294936e22d473030f116ddee9f6b43ac78ba392833b156103ce576124685f9661245588946124369a6001600160a01b0360409889519d8e9c8d9b8c9a7f137c29fe000000000000000000000000000000000000000000000000000000008c5261240a60048d018251602080916001600160a01b0381511684520151910152565b60208181015160448e015291015160648c015281516001600160a01b031660848c0152015160a48a0152565b1660c487015260e48601526101406101048601526101448501906121a8565b90600319848303016101248501526121a8565b03925af180156103c3576124795750565b61238590610a97565b9190917f49fa719b76f0f6b7e76be94b56c26671a548e1c712d5b13dc2874f70a75982765f526020526040519160405260605f20916040526010525f5260305fa0565b51906001600160a01b03821682036103ce57565b3d15612503573d906124ea82610b06565b916124f86040519384610ae3565b82523d5f602084013e565b606090565b9291906001600160a01b03808316946e22d473030f116ddee9f6b43ac78ba386146103fc575f91811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee8103612630575050506125599047612a88565b938051155f146125b457505061258a575f80809381935af16125796124d9565b90156125825750565b602081519101fd5b60046040517f01da1572000000000000000000000000000000000000000000000000000000008152fd5b9093926020830180841161124c5782511061109457835f9460208695850101525b602083519301915af16125e66124d9565b90156125825751159081612626575b506125fc57565b60046040517f82d5d76a000000000000000000000000000000000000000000000000000000008152fd5b90503b155f6125f5565b9091949281979497155f1461264f5750505061258a575f9283926125d5565b612665906126609695963085611274565b612a88565b9060209384810180821161124c578751106127c95784839188010152868103612697575b50505050905f9283926125d5565b9083604492604051938480927fdd62ed3e0000000000000000000000000000000000000000000000000000000082523060048301528b60248301525afa9182156103c3575f9261279a575b5081106126f0575b80612689565b939293612752575b604460105f8093896014525f196034526f095ea7b300000000000000000000000082525af1156103c3573d15601f3d1160015f5114161715612745575f92839283603452919281946126ea565b633e3f8f735f526004601cfd5b856014525f6034526f095ea7b30000000000000000000000005f52815f6044601082855af1156103c3573d15601f3d1160015f511416176126f857633e3f8f735f526004601cfd5b9091508381813d83116127c2575b6127b28183610ae3565b810103126103ce5751905f6126e2565b503d6127a8565b603285634e487b715f52526024601cfd5b908160209103126103ce57516001600160a01b03811681036103ce5790565b6001600160a01b03809116907f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c1681146103fc577e9355806b743562f351db2e3726091207f49fa1cdccd5c65a7d4860ce3abbe992835c806128d857509181740100000000000000000000000000000000000000005f9493859460e01b1717855d82602083519301915af19061288e6124d9565b91156128cf575c8061289e575090565b602490604051907fd66fcc380000000000000000000000000000000000000000000000000000000082526004820152fd5b50602081519101fd5b602490604051907fab7646c40000000000000000000000000000000000000000000000000000000082526004820152fd5b91909161291c8280028280028484612b5c565b9282670de0b6b3a7640000918083870494019485910204900391838002916b3b9ac9f911b09e1a8f6092429563033b2e3d878782870402045f965b60ff88106129895760046040517f481b61af000000000000000000000000000000000000000000000000000000008152fd5b808002828b60038c8761299e868e8985612b5c565b95040202040190878787831015612a1c5750508503049081156129e8575b01966b3b9aca0000000000000000008089116129df575b506001905b0196612957565b975060016129d3565b90506001810186866129fe8380028b858f612b5c565b041015612a0e57506002906129bc565b995050505050505050505090565b90919287840304928315612a38575b50505060019103976129d8565b04149050612a7b575f19810185612a538280028a848e612b5c565b04878110612a6c578714612a0e5750600286865f612a2b565b50509850505050505050505090565b9850505050505050505090565b5f198282098282029182808310920391808303916127109586910992828611156110f55714612ae6577fbc01a36e2eb1c432ca57a786c226809d495182a9930be0ded288ce703afb7e919350828211900360fc1b910360041c170290565b50500490565b915f198284098183850293848084109303950990808514612b545782805f0316809304600280826003021880830282030280830282030280830282030280830282030280830282030280920290030294600184805f0304019185841191030302920304170290565b505091500490565b7f356317ffa45f828d2a41175b2aed3a20e7fdd4a4e46cc11944d93b01be7b171193910291016ec097ce7bc90715b34b9f10000000005f198284099180840293099082821190838082109103030360dc1b910360241c170290561e79df53e941fa0d994ea65cdee2fc560c4e7d9b000000000000000000000000
Deployed Bytecode
0x6080604052600436108015610447575b361561044557346103ce577e9355806b743562f351db2e3726091207f49fa1cdccd5c65a7d4860ce3abbe9905f825c925d7fffffffff000000000000000000000000000000000000000000000000000000005f3581811692610430575b508083169116036103ce576001600160a01b0380821633036103ce57366004116103ce576003199160a01c61ffff166001146100b657634e487b7160e01b5f52605160045260245ffd5b6080823601106103ce5760443591602483013560601c91906004355f81131561042657925b308103610108575050506100f79160383391013560601c6112a8565b60405161010381610aab565b5f9052005b6101159093929315611334565b6040519161012283610a4b565b338352602083015261013736602c8601610b76565b9061016c367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7787600401350160ad8801610b22565b907f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa955f875c975d86156103fc577f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c96608d604051926101cc84610a7b565b605b84526102d0604660208601957f536c697070616765416e64416374696f6e73286164647265737320726563697087527f69656e742c6164647265737320627579546f6b656e2c75696e74323536206d6960408201527f6e416d6f756e744f75742c62797465735b5d20616374696f6e732900000000006060820152602061025361134f565b6040519889937f536c697070616765416e64416374696f6e7320736c697070616765416e644163848601527f74696f6e7329000000000000000000000000000000000000000000000000000060408601525180918686015e8301908482015f8152815193849201905e015f83820152036026810187520185610ae3565b01356001166103d2576e22d473030f116ddee9f6b43ac78ba396873b156103ce576040517f137c29fe000000000000000000000000000000000000000000000000000000008152865180516001600160a01b03166004830152602001516024820152988997889760208181015160448b015260409091015160648a015281516001600160a01b031660848a0152015160a48801521660c486015260e4850152610104840161014090526101448401610387916121a8565b908382030161012484015261039b916121a8565b03815a5f948591f180156103c3576103b4575b506100f7565b6103bd90610a97565b5f6103ae565b6040513d5f823e3d90fd5b5f80fd5b60046040517f1c500e5c000000000000000000000000000000000000000000000000000000008152fd5b60046040517fe758b8d5000000000000000000000000000000000000000000000000000000008152fd5b50602435926100db565b818093503660040360031b1b1616905f61006c565b005b5f3560e01c63fd3ad6d40361000f57346103ce57600319360160e081126103ce576060136103ce5767ffffffffffffffff606435116103ce573660236064350112156103ce5767ffffffffffffffff60643560040135116103ce573660246064356004013560051b6064350101116103ce576001600160a01b0360a4351660a435036103ce5767ffffffffffffffff60c435116103ce5736602360c4350112156103ce5767ffffffffffffffff60c43560040135116103ce5736602460c4356004013560c4350101116103ce5760806064356024015b60246064356004013560051b606435010181106109d95760a06064356004013560051b608020604051907f615e8d716cef7295e75dd3f1f10d679914ad6d7759e8e9459f0109ef7524170182526060600460208401376080820152207f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5c806109a857507f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5d6001600160a01b0360a43516156103fc576001600160a01b037f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c16806109775760a4356001600160a01b03167f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935d60643560040135156103ce57602460643501356064350160448101359060486003196024830135019101916040519261067c60c43560040135602460c4350185848660e01c610a30565b84604052156109105760015b60643560040135811061085d576004356001600160a01b0381168082036103ce57602435906001600160a01b038216928383036103ce57604435938415801590610854575b6107c3575b50505050506001600160a01b0360a435166001600160a01b037f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c1603610799575f7f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935d7f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5c8061076857602060405160018152f35b602490604051907fe25527c20000000000000000000000000000000000000000000000000000000082526004820152fd5b60046040517f5149e795000000000000000000000000000000000000000000000000000000008152fd5b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee03610831575047918383106107fc57506107f292506112f8565b80808080806106d2565b6040516397a6f3b960e01b81526001600160a01b039190911660048201526024810193909352506044820152606490fd5b0390fd5b905061083d3083611274565b918383106107fc5761084f93506112a8565b6107f2565b508015156106cd565b60246064358260051b0101356064350190604482013591604860031960248301350191016040519161089381838760e01c611269565b83604052156108a9575050506001915001610688565b7fffffffff00000000000000000000000000000000000000000000000000000000839584957f3c74eed60000000000000000000000000000000000000000000000000000000061082d96526004870152166024850152606060448501526064840191610a10565b83927fffffffff0000000000000000000000000000000000000000000000000000000061082d937f3c74eed60000000000000000000000000000000000000000000000000000000086525f6004870152166024850152606060448501526064840191610a10565b602490604051907f7407c0f80000000000000000000000000000000000000000000000000000000082526004820152fd5b602490604051907f9936cbab0000000000000000000000000000000000000000000000000000000082526004820152fd5b60448135606435016024810135918291018437822082526020918201910161051d565b35906001600160a01b03821682036103ce57565b601f8260209493601f1993818652868601375f8582860101520116010190565b90610a3d94939291610be1565b15610a4757600190565b5f90565b6040810190811067ffffffffffffffff821117610a6757604052565b634e487b7160e01b5f52604160045260245ffd5b6080810190811067ffffffffffffffff821117610a6757604052565b67ffffffffffffffff8111610a6757604052565b6020810190811067ffffffffffffffff821117610a6757604052565b6060810190811067ffffffffffffffff821117610a6757604052565b90601f601f19910116810190811067ffffffffffffffff821117610a6757604052565b67ffffffffffffffff8111610a6757601f01601f191660200190565b929192610b2e82610b06565b91610b3c6040519384610ae3565b8294818452818301116103ce578281602093845f960137010152565b9080601f830112156103ce57816020610b7393359101610b22565b90565b8092910391608083126103ce57604051906060820182811067ffffffffffffffff821117610a67578060405260408395126103ce5760409181610bba606093610a4b565b610bc3826109fc565b81526020820135608086015284528281013560208501520135910152565b909190635228831d8103610d9d57508101610160828203126103ce57610c06826109fc565b90610c148160208501610b76565b94610c2160a085016109fc565b9460c08501359667ffffffffffffffff88116103ce57610d3a866fffffffffffffffffffffffffffffffff96610c94610c738860e0610c6c610d989f9b610d909c610d299f01610b58565b9501610b76565b9a610c8c6001600160a01b039788809316993691610b22565b921685611307565b9990918b610d238880610ca78c85611307565b929094515116917f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c9060405193610cde85610a7b565b845260208401521660408201525f6060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b9c612219565b8986610d336113ae565b9286612387565b5151169060405191610d4b83610a7b565b825284602083015260408201525f6060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b911691612482565b600190565b92939192630dfeb4198103610df85750820160a0838203126103ce57610d9893610de96001600160a01b03610de1610df2946020610dda896109fc565b9801610b76565b951685611307565b50923691610b22565b91612219565b9294919392639ebf8e8d036112605784019360e0818603126103ce57610e1d816109fc565b9260208201359067ffffffffffffffff82116103ce57610e4f610e4588610e57948601610b58565b9760408501610b76565b953691610b22565b8051608901948560891161124c57602091601f19610e8d610e7789610b06565b98610e856040519a8b610ae3565b808a52610b06565b013684890137815183015187604801526040828401886068015e5f8760a8015380519083018760a9015e5101515f937f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82116110f55795905b815190602c821061109457866014840151601585015197601886015190602c870151948386879c6001600160a01b0389166001600160a01b0388161015611241575b60ff16806111a757506001600160a01b0391605591604073cb2436774c3e191c85056d248ef4260ce5f27a9d927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e33995b62ffffff169083519288165f5287166020528083521560051b6060035f20938183528152600b81019360ff855360208201520152201691855190858760280152866014015285528c602c88115f1461112c57506110396001600160a01b0393878594611034611048956110266040519b8c9586938d8c8084169116105f1461110e578d8c806401000276a4945b630251596160e31b60208a01521691161030602487016121cd565b03601f198101845283610ae3565b6127f9565b60208082518301019101612203565b9590946040525b169116101561110757505b5f03945f86126110f557602c869211156110a657505030939060188151106110945780516017190160189091019081526028865290610ee6565b634e487b715f5260326020526024601cfd5b939650935050925060c083013582106110c157505050600190565b6040516397a6f3b960e01b81526001600160a01b0391909116600482015260c0929092013560248301526044820152606490fd5b634e487b715f5260116020526024601cfd5b905061105a565b8d8c8073fffd8963efd1fc6a506488495d951d5263988d259461100b565b926001600160a01b036111839361103489611026849b9a8a61103998879b888616898416105f1461118b57886401000276a4935b816040519b8c99630251596160e31b60208c0152169116109116602487016121cd565b94909361104f565b8873fffd8963efd1fc6a506488495d951d5263988d2593611160565b9091929394959650601b81145f14611210575060558d96959493926001600160a01b03926040733d91b700252e0e3ee7805d12e048a988ab69c8ad927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e3399610f7e565b602490604051907fd3b1276d0000000000000000000000000000000000000000000000000000000082526004820152fd5b889250869150610f28565b634e487b7160e01b5f52601160045260245ffd5b50925050505f90565b90610a3d92916114a8565b602460105f926020946014526f70a0823100000000000000000000000084525afa156103c357601f3d11156103ce575f5190565b60105f60449260209582956014526034526fa9059cbb00000000000000000000000082525af1156103c3573d15601f3d1160015f51141617156112eb575f603452565b6390b8ec185f526004601cfd5b5f80809381935af1156103c357565b909160206040519261131884610a4b565b818401935f85526001600160a01b038196169052510151809252565b1561133b57565b634e487b7160e01b5f52600160045260245ffd5b6040519061135c82610ac7565b602e82527f696e7432353620616d6f756e74290000000000000000000000000000000000006040837f546f6b656e5065726d697373696f6e73286164647265737320746f6b656e2c7560208201520152565b6040516113ba81610a7b565b60588152610b73603c60208301927f436f6e73696465726174696f6e286164647265737320746f6b656e2c75696e7484527f32353620616d6f756e742c6164647265737320636f756e74657270617274792c60408201527f626f6f6c207061727469616c46696c6c416c6c6f7765642900000000000000006060820152602061144161134f565b6040519586937f436f6e73696465726174696f6e20636f6e73696465726174696f6e2900000000848601525180918686015e8301908482015f8152815193849201905e015f8382015203601c810184520182610ae3565b359062ffffff821682036103ce57565b90919063c1fb425e81036115185750810160c0828203126103ce576114cc826109fc565b906114da8160208501610b76565b9060a084013567ffffffffffffffff81116103ce57611509611511926001600160a01b0392610d989701610b58565b931682611307565b5090612219565b63d92aadfb81036116e957508101610120828203126103ce5761153a826109fc565b916115488260208301610b76565b9161155560a083016109fc565b9160c08101359167ffffffffffffffff83116103ce57610d98956115c1956115936116d8936fffffffffffffffffffffffffffffffff968601610b58565b916101006115a360e087016109fc565b950135906116ca6001600160a01b03998a809a169a8b931685611307565b61169d6116238c88959495515116604051906115dc82610a7b565b815283602082015286604082015260016060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b604051909c7f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c61165383610a7b565b818d16835288602084015216604082015260016060820152601f19019081517f7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa835260a083209252565b9b8c956116aa308c611274565b928184116116df575b90836116be92612aec565b998a60208601526112a8565b6116d26113ae565b93612387565b1691612482565b90925082906116b3565b919291638d68a1568103611aa057508201906080838303126103ce5761170e836109fc565b9060208401359260408501359067ffffffffffffffff82116103ce57611735918601610b58565b9261177d84516020860151907fffffffffffffffffffffffffffffffffffffffff000000000000000000000000918281169160148110611a8b575b503092505060601c611274565b81810291818304149015171561124c57612710900493604051936117a085610ac7565b6028855260403660208701379430937f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82116110f55795905b815190602c821061109457866014840151601585015197601886015190602c870151948386879c6001600160a01b0389166001600160a01b0388161015611a80575b60ff1680611a1757506001600160a01b0391605591604073cb2436774c3e191c85056d248ef4260ce5f27a9d927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e33995b62ffffff169083519288165f5287166020528083521560051b6060035f20938183528152600b81019360ff855360208201520152201691855190858760280152866014015285528c602c88115f146119b957506110396001600160a01b0393878594611034611917956110266040519b8c9586938d8c8084169116105f1461110e57630251596160e31b60208601526401000276a4918c168c8f161030602487016121cd565b9590946040525b16911610156119b257505b5f03945f86126110f557602c86921115611963575050309390601881511061109457805160171901601890910190815260288652906117d9565b93965093505092506060830135821061197e57505050600190565b6040516397a6f3b960e01b81526001600160a01b039190911660048201526060929092013560248301526044820152606490fd5b9050611929565b926001600160a01b03611a0f9361103489611026849b9a8a61103998879b888616898416105f1461118b57886401000276a493816040519b8c99630251596160e31b60208c0152169116109116602487016121cd565b94909361191e565b9091929394959650601b81145f14611210575060558d96959493926001600160a01b03926040733d91b700252e0e3ee7805d12e048a988ab69c8ad927fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b549263fa461e3399611871565b88925086915061181b565b8391925060140360031b1b1616805f80611770565b928363103b48be829495145f14611d92575060c091810103126103ce57611ac6816109fc565b602091611ad48382016109fc565b9160409182810135611ae8606083016109fc565b60a0611af660808501611498565b930135926001600160a01b03808098169216926001928380841614935f9280611d79575b50928293895193611d43575b630902f1ac5f52895f6004601c8a5afa15611d3a57893d106103ce578b8b928760051b9687519288811851948084811c1614821517611ced575b506060955061ffff6127109260081c1682030292028201910204975f601c8d8187019763022c0d9f88526080808901528360a08901528c82828a0101526004011886010152169101525f8060a48382875af115611ce55750828410611bcb5750505050505050600190565b600491879115611c81578551928380927fd21220a70000000000000000000000000000000000000000000000000000000082525afa908115611c775761082d9495965f92611c4a575b5050935b519485946397a6f3b960e01b865216600485016040919493926001600160a01b03606083019616825260208201520152565b611c699250803d10611c70575b611c618183610ae3565b8101906127da565b8680611c14565b503d611c57565b84513d5f823e3d90fd5b8551928380927f0dfe16810000000000000000000000000000000000000000000000000000000082525afa908115611c775761082d9495965f92611cc8575b505093611c18565b611cde9250803d10611c7057611c618183610ae3565b8680611cc0565b3d5f823e3d90fd5b9294505091936024601c5f926370a0823184528b85525afa15611d3a578b3d106103ce575f51838110611d29579183916060948d94038e611b60565b60118d634e487b715f52526024601cfd5b833d5f823e3d90fd5b63a9059cbb8452868c850152848a8501528b5f6044601c870182875af115611d3a57805f51148c3d1015163d1517611b26575f80fd5b612710919350611d893084611274565b0204915f611b1a565b6338c9c1478103611dff5750019060a0818303126103ce57611db3816109fc565b90611dc0604082016109fc565b90608081013567ffffffffffffffff81116103ce57610d9894611de4918301610b58565b9260206001600160a01b036060840135941692013590612508565b63f5b9918981036120ef575060a091810103126103ce57611e1f816109fc565b602082013591604091828201356001600160a01b03948582168092036103ce576080611e4d60608601611498565b940135600180861614918651957f392f37e900000000000000000000000000000000000000000000000000000000875260e087600481885afa80156120e5575f975f905f945f809b5f935f9661206c575b5080948098809784969f611eb190611334565b8c15612053575b5050505050928286611f1b9461271098979461ffff978f8e87915f938061203c575b5083158015908161202c575b9061201e575b612009575b505050670de0b6b3a76400009a8b948580940204998a9860081c1682020490030204920204612909565b90030204801561124c575f190194818610611fd857505015611fd2575f925b8451611f4581610aab565b5f8152823b156103ce575f94611fa386928851998a97889687957f022c0d9f000000000000000000000000000000000000000000000000000000008752600487015260248601521660448401526080606484015260848301906121a8565b03925af1908115611fc95750611fba575b50600190565b611fc390610a97565b5f611fb4565b513d5f823e3d90fd5b5f611f3a565b86516397a6f3b960e01b81526001600160a01b03919091166004820152602481019190915260448101859052606490fd5b612014929350611274565b038f8e8791611ef1565b506001808b811c1614611eec565b6120378685856112a8565b611ee6565b8e91945061204a3086611274565b0204925f611eda565b9e50919850919550909350915088868c8461ffff611eb8565b9c505050945050505060e0873d60e0116120dd575b8161208e60e09383610ae3565b810103126103ce578651602088015190898901519060608a01519460808b015180151581036103ce576120cf60c06120c860a08f016124c5565b9d016124c5565b92949396909b92945f611e9e565b3d9150612081565b88513d5f823e3d90fd5b63c876d21d141590506121a25781606091810103126103ce57612111816109fc565b604061211f602084016109fc565b920135916001600160a01b0391821691811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036121715750479180831161215e575b505050600190565b6121699203906112f8565b5f8080612156565b9061217c3083611274565b9280841161218e575b50505050600190565b6121999303916112a8565b5f808080612185565b50505f90565b90601f19601f602080948051918291828752018686015e5f8582860101520116010190565b919360a093610b7396956001600160a01b03809416855215156020850152604084015216606082015281608082015201906121a8565b91908260409103126103ce576020825192015190565b9190917f1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa5f815c915d80156103fc57612385937f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c906040519361227c85610a7b565b605b8552612380604660208701967f536c697070616765416e64416374696f6e73286164647265737320726563697088527f69656e742c6164647265737320627579546f6b656e2c75696e74323536206d6960408201527f6e416d6f756e744f75742c62797465735b5d20616374696f6e732900000000006060820152602061230361134f565b604051998a937f536c697070616765416e64416374696f6e7320736c697070616765416e644163848601527f74696f6e7329000000000000000000000000000000000000000000000000000060408601525180918686015e8301908482015f8152815193849201905e015f83820152036026810188520186610ae3565b612387565b565b91909294936e22d473030f116ddee9f6b43ac78ba392833b156103ce576124685f9661245588946124369a6001600160a01b0360409889519d8e9c8d9b8c9a7f137c29fe000000000000000000000000000000000000000000000000000000008c5261240a60048d018251602080916001600160a01b0381511684520151910152565b60208181015160448e015291015160648c015281516001600160a01b031660848c0152015160a48a0152565b1660c487015260e48601526101406101048601526101448501906121a8565b90600319848303016101248501526121a8565b03925af180156103c3576124795750565b61238590610a97565b9190917f49fa719b76f0f6b7e76be94b56c26671a548e1c712d5b13dc2874f70a75982765f526020526040519160405260605f20916040526010525f5260305fa0565b51906001600160a01b03821682036103ce57565b3d15612503573d906124ea82610b06565b916124f86040519384610ae3565b82523d5f602084013e565b606090565b9291906001600160a01b03808316946e22d473030f116ddee9f6b43ac78ba386146103fc575f91811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee8103612630575050506125599047612a88565b938051155f146125b457505061258a575f80809381935af16125796124d9565b90156125825750565b602081519101fd5b60046040517f01da1572000000000000000000000000000000000000000000000000000000008152fd5b9093926020830180841161124c5782511061109457835f9460208695850101525b602083519301915af16125e66124d9565b90156125825751159081612626575b506125fc57565b60046040517f82d5d76a000000000000000000000000000000000000000000000000000000008152fd5b90503b155f6125f5565b9091949281979497155f1461264f5750505061258a575f9283926125d5565b612665906126609695963085611274565b612a88565b9060209384810180821161124c578751106127c95784839188010152868103612697575b50505050905f9283926125d5565b9083604492604051938480927fdd62ed3e0000000000000000000000000000000000000000000000000000000082523060048301528b60248301525afa9182156103c3575f9261279a575b5081106126f0575b80612689565b939293612752575b604460105f8093896014525f196034526f095ea7b300000000000000000000000082525af1156103c3573d15601f3d1160015f5114161715612745575f92839283603452919281946126ea565b633e3f8f735f526004601cfd5b856014525f6034526f095ea7b30000000000000000000000005f52815f6044601082855af1156103c3573d15601f3d1160015f511416176126f857633e3f8f735f526004601cfd5b9091508381813d83116127c2575b6127b28183610ae3565b810103126103ce5751905f6126e2565b503d6127a8565b603285634e487b715f52526024601cfd5b908160209103126103ce57516001600160a01b03811681036103ce5790565b6001600160a01b03809116907f46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde8935c1681146103fc577e9355806b743562f351db2e3726091207f49fa1cdccd5c65a7d4860ce3abbe992835c806128d857509181740100000000000000000000000000000000000000005f9493859460e01b1717855d82602083519301915af19061288e6124d9565b91156128cf575c8061289e575090565b602490604051907fd66fcc380000000000000000000000000000000000000000000000000000000082526004820152fd5b50602081519101fd5b602490604051907fab7646c40000000000000000000000000000000000000000000000000000000082526004820152fd5b91909161291c8280028280028484612b5c565b9282670de0b6b3a7640000918083870494019485910204900391838002916b3b9ac9f911b09e1a8f6092429563033b2e3d878782870402045f965b60ff88106129895760046040517f481b61af000000000000000000000000000000000000000000000000000000008152fd5b808002828b60038c8761299e868e8985612b5c565b95040202040190878787831015612a1c5750508503049081156129e8575b01966b3b9aca0000000000000000008089116129df575b506001905b0196612957565b975060016129d3565b90506001810186866129fe8380028b858f612b5c565b041015612a0e57506002906129bc565b995050505050505050505090565b90919287840304928315612a38575b50505060019103976129d8565b04149050612a7b575f19810185612a538280028a848e612b5c565b04878110612a6c578714612a0e5750600286865f612a2b565b50509850505050505050505090565b9850505050505050505090565b5f198282098282029182808310920391808303916127109586910992828611156110f55714612ae6577fbc01a36e2eb1c432ca57a786c226809d495182a9930be0ded288ce703afb7e919350828211900360fc1b910360041c170290565b50500490565b915f198284098183850293848084109303950990808514612b545782805f0316809304600280826003021880830282030280830282030280830282030280830282030280830282030280920290030294600184805f0304019185841191030302920304170290565b505091500490565b7f356317ffa45f828d2a41175b2aed3a20e7fdd4a4e46cc11944d93b01be7b171193910291016ec097ce7bc90715b34b9f10000000005f198284099180840293099082821190838082109103030360dc1b910360241c17029056
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
1e79df53e941fa0d994ea65cdee2fc560c4e7d9b000000000000000000000000
-----Decoded View---------------
Arg [0] : gitCommit (bytes20): 0x1e79df53e941fa0d994ea65cdee2fc560c4e7d9b
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 1e79df53e941fa0d994ea65cdee2fc560c4e7d9b000000000000000000000000
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.