Address Contract Verified
Address
0xBaE357CBAA04a68cbfD5a560Ab06C4E9A3328A90
Balance
0 ETH
Nonce
2
Code Size
8513 bytes
Creator
0xce0042B8...cf9f at tx 0x2545dc73...d30166
Indexed Transactions
0 (2 on-chain, 1.5% indexed)
Contract Bytecode
8513 bytes
0x6080604052600436101561001a575b3615610018575f80fd5b005b5f3560e01c806309c5eabe146100c95780632a3ee126146100c45780634784226e146100bf5780634c4e814c146100ba5780635b5e6516146100b55780637423eb3c146100b05780637a7eeb4f146100ab578063a9baaaf5146100a6578063b8dc491b146100a1578063c2add59d1461009c5763c5e5153b0361000e57610b9d565b610b2f565b610ae4565b610a7c565b610985565b610835565b61074d565b61067b565b61048f565b6102e9565b6101d3565b9181601f840112156100fc5782359167ffffffffffffffff83116100fc57602083818601950101116100fc57565b5f80fd5b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602080948051918291828752018686015e5f8582860101520116010190565b602081016020825282518091526040820191602060408360051b8301019401925f915b83831061017557505050505090565b90919293946020806101c4837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc086600196030187526040838b5180511515845201519181858201520190610100565b97019301930191939290610166565b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc5760043567ffffffffffffffff81116100fc575f61021f819236906004016100ce565b9061022a8282611871565b816040519283928337810183815203907f000000000000000000000000ae96419a81516f063744206d4b5e36f3168280f85af4610265610d1e565b9015610291576102818160208061028d94518301019101610d83565b60405191829182610143565b0390f35b6102c7906040519182917fa932c97a00000000000000000000000000000000000000000000000000000000835260048301610d4d565b0390fd5b73ffffffffffffffffffffffffffffffffffffffff8116036100fc57565b60607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc57600435602435610322816102cb565b6044359161032f836102cb565b610337611a24565b7f280d4be14fa09378750d86c933a0bbaa72f861b3ecaac50fb28add64cd1a66e25f5260205260405f207f000000000000000000000000000000000000000000000000000000000000000380600414610474576003146103be577f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffd5b6001905c5b0361044c576103d0611a24565b6103da3082611dbd565b91826103e257005b602073ffffffffffffffffffffffffffffffffffffffff7fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab79281851694868287155f1461043e576104339250611b6b565b6040519586521693a3005b61044792611a8b565b610433565b7f43f7ed76000000000000000000000000000000000000000000000000000000005f5260045ffd5b5060019060ff5f54165f14610489575c6103c3565b546103c3565b60807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc576004356104c5816102cb565b602435906104d2826102cb565b6044357fe8d24fc0ab3b12d83ce3d7bb06e74e2a423de5d1fa0d5414435460ede32ea6ea73ffffffffffffffffffffffffffffffffffffffff606435610517816102cb565b61051f611a24565b61057c305b61052e8188611dbd565b808711156106705761055090915b878303610631575b826105d9575b88611dbd565b9081610581575b8480604051968796169a16981696846040919493926060820195825260208201520152565b0390a4005b878516806105c9576105938386611b6b565b60405183815286861691907fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab790602090a3610557565b6105d483868b611a8b565b610593565b88861680610621576105eb848c611b6b565b604051848152878c1691907ff40cc8c1a1d17359049ba500cfc894596a692cffc9d03943cd92ec2e159cf6ae90602090a361054a565b61062c848c8c611a8b565b6105eb565b6040805189815260208101859052878c16918b8916917fbc530e98937a005fa590a15899ce2e21e1bfa93730e6dfe36bcd7a041d6abf859190a3610544565b50610550869161053c565b346100fc5760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc5760a43560043567ffffffffffffffff82116100fc576106d06100189236906004016100ce565b916106d9611a24565b611219565b60a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8201126100fc57600435610714816102cb565b91602435610721816102cb565b916044359067ffffffffffffffff82116100fc57610741916004016100ce565b90916064359060843590565b610756366106de565b929490919373ffffffffffffffffffffffffffffffffffffffff8216159485809661082c575b6107fc5761078a3084611dbd565b9586156107a75750610018966107a19136916110f7565b91611c8b565b156107d4577f891a31ae000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f22fbbd6a000000000000000000000000000000000000000000000000000000005f5260045ffd5b7fb25102da000000000000000000000000000000000000000000000000000000005f525f6004523460245260445ffd5b5034151561077c565b346100fc575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc5732330361095d577f00000000000000000000000000000000000000000000000000000000000000018015610952575b61092a576108d05f8080807f000000000000000000000000f196aeb26149ace5093cd5cf04fbafb778650f1d600a5a04fa6108cb610d1e565b501590565b6109025761001860017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff005f5416175f55565b7f70a4078f000000000000000000000000000000000000000000000000000000005f5260045ffd5b7ff45b98b0000000000000000000000000000000000000000000000000000000005f5260045ffd5b5060ff5f5416610892565b7f25994314000000000000000000000000000000000000000000000000000000005f5260045ffd5b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc576004356109bb816102cb565b60243567ffffffffffffffff81116100fc576109db9036906004016100ce565b90919073ffffffffffffffffffffffffffffffffffffffff8216610a36573415610a0e5761028d92610281923490611455565b7f891a31ae000000000000000000000000000000000000000000000000000000005f5260045ffd5b610a403383611dbd565b928315610a545761028d9361028193611455565b7f6920aa0f000000000000000000000000000000000000000000000000000000005f5260045ffd5b60607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc57600435610ab2816102cb565b60443560243567ffffffffffffffff82116100fc5761028d92610adc6102819336906004016100ce565b929091611455565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc57600435610b1a816102cb565b60243590610b27826102cb565b6103d0611a24565b346100fc575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100fc57602060405173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000ae96419a81516f063744206d4b5e36f3168280f8168152f35b610ba6366106de565b929490919373ffffffffffffffffffffffffffffffffffffffff8216155f14610be15734943415610a0e57610018966107a1915b36916110f7565b346107fc57610bf03383611dbd565b9485156107d457610018966107a191610c0b88303388611e76565b610bda565b908092918237015f815290565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040810190811067ffffffffffffffff821117610c6657604052565b610c1d565b6060810190811067ffffffffffffffff821117610c6657604052565b6080810190811067ffffffffffffffff821117610c6657604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610c6657604052565b67ffffffffffffffff8111610c6657601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b3d15610d48573d90610d2f82610ce4565b91610d3d6040519384610ca3565b82523d5f602084013e565b606090565b906020610d5e928181520190610100565b90565b67ffffffffffffffff8111610c665760051b60200190565b801515036100fc57565b6020818303126100fc5780519067ffffffffffffffff82116100fc57019080601f830112156100fc57815191610db883610d61565b92610dc66040519485610ca3565b80845260208085019160051b830101918383116100fc5760208101915b838310610df257505050505090565b825167ffffffffffffffff81116100fc5782019060407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe083880301126100fc5760405191610e3f83610c4a565b6020810151610e4d81610d79565b8352604081015167ffffffffffffffff81116100fc5760209101019086601f830112156100fc57815192610e8084610ce4565b610e8d6040519182610ca3565b84815288602086860101116100fc575f6020868197828098018386015e8301015283820152815201920191610de3565b610ec5611a24565b7f280d4be14fa09378750d86c933a0bbaa72f861b3ecaac50fb28add64cd1a66e25f5260205260405f207f000000000000000000000000000000000000000000000000000000000000000380600414610fdd57600314610f4c577f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffd5b6001905c5b0361044c57610f5e611a24565b610f683082611dbd565b9182610f7357505050565b602073ffffffffffffffffffffffffffffffffffffffff7fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab79281851694868287155f14610fcf57610fc49250611b6b565b6040519586521693a3565b610fd892611a8b565b610fc4565b5060019060ff5f54165f14610ff2575c610f51565b54610f51565b91909273ffffffffffffffffffffffffffffffffffffffff7fe8d24fc0ab3b12d83ce3d7bb06e74e2a423de5d1fa0d5414435460ede32ea6ea9161103a611a24565b61104330610524565b0390a4565b906004116100fc5790600490565b90929192836004116100fc5783116100fc57600401917ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0190565b919091357fffffffff00000000000000000000000000000000000000000000000000000000811692600481106110c5575050565b7fffffffff00000000000000000000000000000000000000000000000000000000929350829060040360031b1b161690565b92919261110382610ce4565b916111116040519384610ca3565b8294818452818301116100fc578281602093845f960137010152565b9080601f830112156100fc57816020610d5e933591016110f7565b9160a0838303126100fc57823561115e816102cb565b92602081013561116d816102cb565b9260408201359067ffffffffffffffff82116100fc5761118e91830161112d565b916080606083013592013590565b91908260409103126100fc57602082356111b5816102cb565b920135610d5e816102cb565b91908260809103126100fc5781356111d8816102cb565b9160208101356111e7816102cb565b9160606040830135920135610d5e816102cb565b908160609103126100fc57803591604060208301356111b5816102cb565b90915f92600482101561143a575b7fffffffff0000000000000000000000000000000000000000000000000000000084167f5b5e65160000000000000000000000000000000000000000000000000000000081146113f7577fb8dc491b0000000000000000000000000000000000000000000000000000000081146113b8577f4784226e000000000000000000000000000000000000000000000000000000008114611375577f2a3ee1260000000000000000000000000000000000000000000000000000000014611334577ffbdc7301000000000000000000000000000000000000000000000000000000005f527fffffffff00000000000000000000000000000000000000000000000000000000841660045260245b5ffd5b611373935061136661135e8373ffffffffffffffffffffffffffffffffffffffff95948694611056565b8101906111fb565b9094915016921690610ebd565b565b50611373935073ffffffffffffffffffffffffffffffffffffffff92506113aa6113a28385948594611056565b8101906111c1565b949094169492169116610ff8565b50611373935073ffffffffffffffffffffffffffffffffffffffff92506113e48284936113ec93611056565b81019061119c565b9290921691166115f2565b50611373935073ffffffffffffffffffffffffffffffffffffffff925061142382849361142b93611056565b810190611148565b95919392949094169116611bc1565b925061144f6114498285611048565b90611091565b92611227565b93926114618184611871565b73ffffffffffffffffffffffffffffffffffffffff85169283159283156115dc578034036115ad57505f9182915b61149e60405180938193610c10565b03907f000000000000000000000000ae96419a81516f063744206d4b5e36f3168280f85af46114cb610d1e565b901561029157806020806114e493518301019101610d83565b9381159283611554575b50509061154b575b6114fc57565b3031806115065750565b6115108133611b6b565b5f7fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab7604051806115463395829190602083019252565b0390a3565b503415156114f6565b61155e3083611dbd565b918261156b575b506114ee565b82611577913390611a8b565b60405191825233917fed679328aebf74ede77ae09efcf36e90244f83643dadac1c2d9f0b21a46f6ab790602090a35f8080611565565b7fb25102da000000000000000000000000000000000000000000000000000000005f526004523460245260445ffd5b915f92916115ed849330338b611e76565b61148f565b610f5e611a24565b6020818303126100fc5780359067ffffffffffffffff82116100fc57019080601f830112156100fc5781359161162f83610d61565b9261163d6040519485610ca3565b80845260208085019160051b830101918383116100fc5760208101915b83831061166957505050505090565b823567ffffffffffffffff81116100fc5782019060607fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe083880301126100fc57604051906116b682610c6b565b60208301356116c4816102cb565b825260408301356116d481610d79565b602083015260608301359167ffffffffffffffff83116100fc576117008860208096958196010161112d565b604082015281520192019161165a565b80518210156117245760209160051b010190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b6020818303126100fc5780359067ffffffffffffffff82116100fc57019080601f830112156100fc5781359161178683610d61565b926117946040519485610ca3565b80845260208085019160051b830101918383116100fc5760208101915b8383106117c057505050505090565b823567ffffffffffffffff81116100fc5782019060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe083880301126100fc576040519061180d82610c87565b602083013561181b816102cb565b8252604083013561182b81610d79565b60208301526060830135604083015260808301359167ffffffffffffffff83116100fc576118618860208096958196010161112d565b60608201528152019201916117b1565b600482106119f5576118866114498383611048565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f174dea71000000000000000000000000000000000000000000000000000000008103611945575050816118e8926118e092611056565b810190611751565b5f5b81518110156119415761190a60206119028385611710565b510151151590565b611916576001016118ea565b7fae701fc4000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b5050565b7f82ad56cb00000000000000000000000000000000000000000000000000000000036119a85750816119829261197a92611056565b8101906115fa565b5f5b81518110156119415761199c60206119028385611710565b61191657600101611984565b7f432df3c4000000000000000000000000000000000000000000000000000000005f527fffffffff000000000000000000000000000000000000000000000000000000001660045260245ffd5b7f432df3c4000000000000000000000000000000000000000000000000000000005f526113316024905f600452565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000bae357cbaa04a68cbfd5a560ab06c4e9a3328a90163014611a6357565b7f4f0898d2000000000000000000000000000000000000000000000000000000005f5260045ffd5b73ffffffffffffffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff604051927fa9059cbb000000000000000000000000000000000000000000000000000000005f521660045260245260205f60448180865af160015f5114811615611b4c575b604091909152155b611b0b5750565b7f5274afe7000000000000000000000000000000000000000000000000000000005f5273ffffffffffffffffffffffffffffffffffffffff1660045260245ffd5b6001811516611b62573d15833b15151616611afc565b503d5f823e3d90fd5b5f80809373ffffffffffffffffffffffffffffffffffffffff8294165af1611b91610d1e565b5015611b9957565b7ff4b3b1bc000000000000000000000000000000000000000000000000000000005f5260045ffd5b949391929092611bd13087611dbd565b938415611be2576113739596611c8b565b73ffffffffffffffffffffffffffffffffffffffff87166107d4577f891a31ae000000000000000000000000000000000000000000000000000000005f5260045ffd5b9060208201809211611c3357565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b919260a093610d5e969592845260208401526040830152151560608201528160808201520190610100565b949392948515801590611db4575b611d3c575b7f5a760595a6da847ff93bc1dfe0ee241c4edc8985ae7eeedc4e0a9255bc453d919173ffffffffffffffffffffffffffffffffffffffff8092169384155f14611d17575f80826020611d0c945191018a865af19687611cfb610d1e565b998a92604051968796169986611c60565b0390a3156102915750565b5f80611d0c92611d288a868a611f03565b60208151910182865af19687611cfb610d1e565b8251611d4787611c25565b11611d8c576020868401019184835103611d645791859052611c9e565b7fcc00c48a000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f4daf251f000000000000000000000000000000000000000000000000000000005f5260045ffd5b50831515611c99565b73ffffffffffffffffffffffffffffffffffffffff1680611ddd57503190565b9073ffffffffffffffffffffffffffffffffffffffff602460209260405194859384927f70a082310000000000000000000000000000000000000000000000000000000084521660048301525afa908115611e6b575f91611e3c575090565b90506020813d602011611e63575b81611e5760209383610ca3565b810103126100fc575190565b3d9150611e4a565b6040513d5f823e3d90fd5b73ffffffffffffffffffffffffffffffffffffffff809194929394169381604051947f23b872dd000000000000000000000000000000000000000000000000000000005f52166004521660245260445260205f60648180865af160015f5114811615611eed575b6040919091525f60605215611b04565b6001811516611b62573d15833b15151616611edd565b91906040517f095ea7b3000000000000000000000000000000000000000000000000000000005f5273ffffffffffffffffffffffffffffffffffffffff82166004528260245260205f60448180885af19060015f5114821615612014575b60405215611f6e57505050565b611f788184612023565b15611fd25790611f8891836120a9565b15611f905750565b73ffffffffffffffffffffffffffffffffffffffff907f5274afe7000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b73ffffffffffffffffffffffffffffffffffffffff837f5274afe7000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b90843b15153d15161690611f61565b919073ffffffffffffffffffffffffffffffffffffffff604051917f095ea7b3000000000000000000000000000000000000000000000000000000005f52166004525f60245260205f60448180875af19260015f5114841615612087575b50604052565b600184929415166120a0573b15153d151616915f612081565b833d5f823e3d90fd5b929173ffffffffffffffffffffffffffffffffffffffff604051927f095ea7b3000000000000000000000000000000000000000000000000000000005f521660045260245260205f60448180875af19260015f5114841615612087575060405256fea264697066735822122051a7d5a74c72625966ac32d97bd9d9b0e273b687e10c30f3e6242b6e05dfd30f64736f6c634300081e0033
Verified Source Code Full Match
Compiler: v0.8.30+commit.73712a01
EVM: prague
Optimization: Yes (4294967295 runs)
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 280 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
if (!_safeTransfer(token, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
if (!_safeTransferFrom(token, from, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _safeTransfer(token, to, value, false);
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _safeTransferFrom(token, from, to, value, false);
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
if (!_safeApprove(token, spender, value, false)) {
if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
* return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.transfer.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(to, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
/**
* @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
* value: the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param from The sender of the tokens
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value,
bool bubble
) private returns (bool success) {
bytes4 selector = IERC20.transferFrom.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(from, shr(96, not(0))))
mstore(0x24, and(to, shr(96, not(0))))
mstore(0x44, value)
success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
mstore(0x60, 0)
}
}
/**
* @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
* the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param spender The spender of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.approve.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(spender, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Tstorish.sol 251 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Tstorish {
// Declare a storage variable indicating if TSTORE support has been
// activated post-deployment.
bool private _tstoreSupport;
/*
* ------------------------------------------------------------------------+
* Opcode | Mnemonic | Stack | Memory |
* ------------------------------------------------------------------------|
* 60 0x02 | PUSH1 0x02 | 0x02 | |
* 60 0x1e | PUSH1 0x1e | 0x1e 0x02 | |
* 61 0x3d5c | PUSH2 0x3d5c | 0x3d5c 0x1e 0x02 | |
* 3d | RETURNDATASIZE | 0 0x3d5c 0x1e 0x02 | |
* |
* :: store deployed bytecode in memory: (3d) RETURNDATASIZE (5c) TLOAD :: |
* 52 | MSTORE | 0x1e 0x02 | [0..0x20): 0x3d5c |
* f3 | RETURN | | [0..0x20): 0x3d5c |
* ------------------------------------------------------------------------+
*/
uint256 constant _TLOAD_TEST_PAYLOAD = 0x6002_601e_613d5c_3d_52_f3;
uint256 constant _TLOAD_TEST_PAYLOAD_LENGTH = 0x0a;
uint256 constant _TLOAD_TEST_PAYLOAD_OFFSET = 0x16;
// Declare an immutable variable to store the tstore test contract address.
address private immutable _tloadTestContract;
// Declare an immutable variable to store the initial TSTORE support status.
bool private immutable _tstoreInitialSupport;
// Declare an immutable function type variable for the _setTstorish function
// based on chain support for tstore at time of deployment.
function(uint256,uint256) internal immutable _setTstorish;
// Declare an immutable function type variable for the _getTstorish function
// based on chain support for tstore at time of deployment.
function(uint256) view returns (uint256) internal immutable _getTstorish;
// Declare an immutable function type variable for the _clearTstorish function
// based on chain support for tstore at time of deployment.
function(uint256) internal immutable _clearTstorish;
// Declare a few custom revert error types.
error TStoreAlreadyActivated();
error TStoreNotSupported();
error TloadTestContractDeploymentFailed();
error OnlyDirectCalls();
/**
* @dev Determine TSTORE availability during deployment. This involves
* attempting to deploy a contract that utilizes TLOAD as part of the
* contract construction bytecode, and configuring initial support for
* using TSTORE in place of SSTORE based on the result.
*/
constructor() {
// Deploy the contract testing TLOAD support and store the address.
address tloadTestContract = _prepareTloadTest();
// Ensure the deployment was successful.
if (tloadTestContract == address(0)) {
revert TloadTestContractDeploymentFailed();
}
// Determine if TSTORE is supported.
bool tstoreInitialSupport = _testTload(tloadTestContract);
if (tstoreInitialSupport) {
// If TSTORE is supported, set functions to their versions that use
// tstore/tload directly without support checks.
_setTstorish = _setTstore;
_getTstorish = _getTstore;
_clearTstorish = _clearTstore;
} else {
// If TSTORE is not supported, set functions to their versions that
// fallback to sstore/sload until _tstoreSupport is true.
_setTstorish = _setTstorishWithSstoreFallback;
_getTstorish = _getTstorishWithSloadFallback;
_clearTstorish = _clearTstorishWithSstoreFallback;
}
_tstoreInitialSupport = tstoreInitialSupport;
// Set the address of the deployed TLOAD test contract as an immutable.
_tloadTestContract = tloadTestContract;
}
/**
* @dev External function to activate TSTORE usage. Does not need to be
* called if TSTORE is supported from deployment, and only needs to be
* called once. Reverts if TSTORE has already been activated or if the
* opcode is not available. Note that this must be called directly from
* an externally-owned account to avoid potential reentrancy issues.
*/
function __activateTstore() external {
// Ensure this function is triggered from an externally-owned account.
if (msg.sender != tx.origin) {
revert OnlyDirectCalls();
}
// Determine if TSTORE can potentially be activated.
if (_tstoreInitialSupport || _tstoreSupport) {
revert TStoreAlreadyActivated();
}
// Determine if TSTORE can be activated and revert if not.
if (!_testTload(_tloadTestContract)) {
revert TStoreNotSupported();
}
// Mark TSTORE as activated.
_tstoreSupport = true;
}
/**
* @dev Private function to set a TSTORISH value. Assigned to _setTstorish
* internal function variable at construction if chain has tstore support.
*
* @param storageSlot The slot to write the TSTORISH value to.
* @param value The value to write to the given storage slot.
*/
function _setTstore(uint256 storageSlot, uint256 value) private {
assembly {
tstore(storageSlot, value)
}
}
/**
* @dev Private function to set a TSTORISH value with sstore fallback.
* Assigned to _setTstorish internal function variable at construction
* if chain does not have tstore support.
*
* @param storageSlot The slot to write the TSTORISH value to.
* @param value The value to write to the given storage slot.
*/
function _setTstorishWithSstoreFallback(uint256 storageSlot, uint256 value) private {
if (_tstoreSupport) {
assembly {
tstore(storageSlot, value)
}
} else {
assembly {
sstore(storageSlot, value)
}
}
}
/**
* @dev Private function to read a TSTORISH value. Assigned to _getTstorish
* internal function variable at construction if chain has tstore support.
*
* @param storageSlot The slot to read the TSTORISH value from.
*
* @return value The TSTORISH value at the given storage slot.
*/
function _getTstore(
uint256 storageSlot
) private view returns (uint256 value) {
assembly {
value := tload(storageSlot)
}
}
/**
* @dev Private function to read a TSTORISH value with sload fallback.
* Assigned to _getTstorish internal function variable at construction
* if chain does not have tstore support.
*
* @param storageSlot The slot to read the TSTORISH value from.
*
* @return value The TSTORISH value at the given storage slot.
*/
function _getTstorishWithSloadFallback(
uint256 storageSlot
) private view returns (uint256 value) {
if (_tstoreSupport) {
assembly {
value := tload(storageSlot)
}
} else {
assembly {
value := sload(storageSlot)
}
}
}
/**
* @dev Private function to clear a TSTORISH value. Assigned to _clearTstorish internal
* function variable at construction if chain has tstore support.
*
* @param storageSlot The slot to clear the TSTORISH value for.
*/
function _clearTstore(uint256 storageSlot) private {
assembly {
tstore(storageSlot, 0)
}
}
/**
* @dev Private function to clear a TSTORISH value with sstore fallback.
* Assigned to _clearTstorish internal function variable at construction
* if chain does not have tstore support.
*
* @param storageSlot The slot to clear the TSTORISH value for.
*/
function _clearTstorishWithSstoreFallback(uint256 storageSlot) private {
if (_tstoreSupport) {
assembly {
tstore(storageSlot, 0)
}
} else {
assembly {
sstore(storageSlot, 0)
}
}
}
/**
* @dev Private function to deploy a test contract that utilizes TLOAD as
* part of its fallback logic.
*/
function _prepareTloadTest() private returns (address contractAddress) {
// Utilize assembly to deploy a contract testing TLOAD support.
assembly {
// Write the contract deployment code payload to scratch space.
mstore(0, _TLOAD_TEST_PAYLOAD)
// Deploy the contract.
contractAddress := create(
0,
_TLOAD_TEST_PAYLOAD_OFFSET,
_TLOAD_TEST_PAYLOAD_LENGTH
)
}
}
/**
* @dev Private view function to determine if TSTORE/TLOAD are supported by
* the current EVM implementation by attempting to call the test
* contract, which utilizes TLOAD as part of its fallback logic.
*/
function _testTload(
address tloadTestContract
) private view returns (bool ok) {
// Call the test contract, which will perform a TLOAD test. If the call
// does not revert, then TLOAD/TSTORE is supported. Do not forward all
// available gas, as all forwarded gas will be consumed on revert.
(ok, ) = tloadTestContract.staticcall{ gas: gasleft() / 10 }("");
}
}
IDelegatedExtension.sol 25 lines
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.27;
/// @title IDelegatedExtension
/// @author Agustin Aguilar
/// @notice Interface for the delegated extension module
interface IDelegatedExtension {
/// @notice Handle a sequence delegate call
/// @param _opHash The operation hash
/// @param _startingGas The starting gas
/// @param _index The index
/// @param _numCalls The number of calls
/// @param _space The space
/// @param _data The data
function handleSequenceDelegateCall(
bytes32 _opHash,
uint256 _startingGas,
uint256 _index,
uint256 _numCalls,
uint256 _space,
bytes calldata _data
) external;
}
TrailsRouter.sol 418 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IDelegatedExtension} from "wallet-contracts-v3/modules/interfaces/IDelegatedExtension.sol";
import {Tstorish} from "tstorish/Tstorish.sol";
import {DelegatecallGuard} from "./guards/DelegatecallGuard.sol";
import {IMulticall3} from "./interfaces/IMulticall3.sol";
import {ITrailsRouter} from "./interfaces/ITrailsRouter.sol";
import {TrailsSentinelLib} from "./libraries/TrailsSentinelLib.sol";
/// @title TrailsRouter
/// @author Miguel Mota, Shun Kakinoki
/// @notice Consolidated router for Trails operations including multicall routing, balance injection, and token sweeping
/// @dev Must be delegatecalled via the Sequence delegated extension module to access wallet storage/balances.
contract TrailsRouter is IDelegatedExtension, ITrailsRouter, DelegatecallGuard, Tstorish {
// -------------------------------------------------------------------------
// Libraries
// -------------------------------------------------------------------------
using SafeERC20 for IERC20;
// -------------------------------------------------------------------------
// Immutable Variables
// -------------------------------------------------------------------------
address public immutable MULTICALL3;
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
constructor(address _multicall3) {
MULTICALL3 = _multicall3;
}
// -------------------------------------------------------------------------
// Errors
// -------------------------------------------------------------------------
error NativeTransferFailed();
error InvalidDelegatedSelector(bytes4 selector);
error InvalidFunctionSelector(bytes4 selector);
error AllowFailureMustBeFalse(uint256 callIndex);
error SuccessSentinelNotSet();
error NoValueAvailable();
error NoTokensToPull();
error IncorrectValue(uint256 required, uint256 received);
error NoTokensToSweep();
error AmountOffsetOutOfBounds();
error PlaceholderMismatch();
error TargetCallFailed(bytes revertData);
// -------------------------------------------------------------------------
// Receive ETH
// -------------------------------------------------------------------------
/// @notice Allow direct native token transfers when contract is used standalone.
receive() external payable {}
// -------------------------------------------------------------------------
// Multicall3 Router Functions
// -------------------------------------------------------------------------
/// @inheritdoc ITrailsRouter
function execute(bytes calldata data) public payable returns (IMulticall3.Result[] memory returnResults) {
_validateRouterCall(data);
(bool success, bytes memory returnData) = MULTICALL3.delegatecall(data);
if (!success) revert TargetCallFailed(returnData);
return abi.decode(returnData, (IMulticall3.Result[]));
}
/// @inheritdoc ITrailsRouter
function pullAndExecute(address token, bytes calldata data)
public
payable
returns (IMulticall3.Result[] memory returnResults)
{
uint256 amount;
if (token == address(0)) {
if (msg.value == 0) revert NoValueAvailable();
amount = msg.value;
} else {
amount = _getBalance(token, msg.sender);
if (amount == 0) revert NoTokensToPull();
}
return pullAmountAndExecute(token, amount, data);
}
/// @inheritdoc ITrailsRouter
function pullAmountAndExecute(address token, uint256 amount, bytes calldata data)
public
payable
returns (IMulticall3.Result[] memory returnResults)
{
_validateRouterCall(data);
if (token == address(0)) {
if (msg.value != amount) revert IncorrectValue(amount, msg.value);
} else {
_safeTransferFrom(token, msg.sender, address(this), amount);
}
(bool success, bytes memory returnData) = MULTICALL3.delegatecall(data);
if (!success) revert TargetCallFailed(returnData);
returnResults = abi.decode(returnData, (IMulticall3.Result[]));
// Sweep remaining balance back to msg.sender to prevent dust from EXACT_OUTPUT swaps getting stuck.
// We sweep the full balance (not tracking initial) since TrailsRouter is stateless by design.
if (token != address(0)) {
uint256 remaining = _getSelfBalance(token);
if (remaining > 0) {
_transferERC20(token, msg.sender, remaining);
emit Sweep(token, msg.sender, remaining);
}
}
if (token == address(0) || msg.value > 0) {
uint256 remainingNative = _getSelfBalance(address(0));
if (remainingNative > 0) {
_transferNative(msg.sender, remainingNative);
emit Sweep(address(0), msg.sender, remainingNative);
}
}
}
// -------------------------------------------------------------------------
// Balance Injection Functions
// -------------------------------------------------------------------------
/// @inheritdoc ITrailsRouter
function injectSweepAndCall(
address token,
address target,
bytes calldata callData,
uint256 amountOffset,
bytes32 placeholder
) external payable {
uint256 callerBalance;
if (token == address(0)) {
callerBalance = msg.value;
if (callerBalance == 0) revert NoValueAvailable();
} else {
if (msg.value != 0) revert IncorrectValue(0, msg.value);
callerBalance = _getBalance(token, msg.sender);
if (callerBalance == 0) revert NoTokensToSweep();
_safeTransferFrom(token, msg.sender, address(this), callerBalance);
}
_injectAndExecuteCall(token, target, callData, amountOffset, placeholder, callerBalance);
}
/// @inheritdoc ITrailsRouter
function injectAndCall(
address token,
address target,
bytes calldata callData,
uint256 amountOffset,
bytes32 placeholder
) public payable {
if (token == address(0) && msg.value != 0) {
revert IncorrectValue(0, msg.value);
}
uint256 callerBalance = _getSelfBalance(token);
if (callerBalance == 0) {
if (token == address(0)) {
revert NoValueAvailable();
} else {
revert NoTokensToSweep();
}
}
_injectAndExecuteCall(token, target, callData, amountOffset, placeholder, callerBalance);
}
// -------------------------------------------------------------------------
// Token Sweeper Functions
// -------------------------------------------------------------------------
/// @inheritdoc ITrailsRouter
function sweep(address _token, address _recipient) public payable onlyDelegatecall {
uint256 amount = _getSelfBalance(_token);
if (amount > 0) {
if (_token == address(0)) {
_transferNative(_recipient, amount);
} else {
_transferERC20(_token, _recipient, amount);
}
emit Sweep(_token, _recipient, amount);
}
}
/// @inheritdoc ITrailsRouter
function refundAndSweep(address _token, address _refundRecipient, uint256 _refundAmount, address _sweepRecipient)
public
payable
onlyDelegatecall
{
uint256 current = _getSelfBalance(_token);
uint256 actualRefund = _refundAmount > current ? current : _refundAmount;
if (actualRefund != _refundAmount) {
emit ActualRefund(_token, _refundRecipient, _refundAmount, actualRefund);
}
if (actualRefund > 0) {
if (_token == address(0)) {
_transferNative(_refundRecipient, actualRefund);
} else {
_transferERC20(_token, _refundRecipient, actualRefund);
}
emit Refund(_token, _refundRecipient, actualRefund);
}
uint256 remaining = _getSelfBalance(_token);
if (remaining > 0) {
if (_token == address(0)) {
_transferNative(_sweepRecipient, remaining);
} else {
_transferERC20(_token, _sweepRecipient, remaining);
}
emit Sweep(_token, _sweepRecipient, remaining);
}
emit RefundAndSweep(_token, _refundRecipient, _refundAmount, _sweepRecipient, actualRefund, remaining);
}
/// @inheritdoc ITrailsRouter
function validateOpHashAndSweep(bytes32 opHash, address _token, address _recipient)
public
payable
onlyDelegatecall
{
uint256 slot = TrailsSentinelLib.successSlot(opHash);
if (_getTstorish(slot) != TrailsSentinelLib.SUCCESS_VALUE) {
revert SuccessSentinelNotSet();
}
sweep(_token, _recipient);
}
// -------------------------------------------------------------------------
// Sequence Delegated Extension Entry Point
// -------------------------------------------------------------------------
/// @inheritdoc IDelegatedExtension
function handleSequenceDelegateCall(
bytes32 _opHash,
uint256, /* _startingGas */
uint256, /* _index */
uint256, /* _numCalls */
uint256, /* _space */
bytes calldata _data
)
external
override(IDelegatedExtension, ITrailsRouter)
onlyDelegatecall
{
bytes4 selector;
if (_data.length >= 4) {
selector = bytes4(_data[0:4]);
}
// Balance Injection selectors
if (selector == this.injectAndCall.selector) {
(address token, address target, bytes memory callData, uint256 amountOffset, bytes32 placeholder) =
abi.decode(_data[4:], (address, address, bytes, uint256, bytes32));
_injectAndCallDelegated(token, target, callData, amountOffset, placeholder);
return;
}
// Token Sweeper selectors
if (selector == this.sweep.selector) {
(address token, address recipient) = abi.decode(_data[4:], (address, address));
sweep(token, recipient);
return;
}
if (selector == this.refundAndSweep.selector) {
(address token, address refundRecipient, uint256 refundAmount, address sweepRecipient) =
abi.decode(_data[4:], (address, address, uint256, address));
refundAndSweep(token, refundRecipient, refundAmount, sweepRecipient);
return;
}
if (selector == this.validateOpHashAndSweep.selector) {
(, address token, address recipient) = abi.decode(_data[4:], (bytes32, address, address));
validateOpHashAndSweep(_opHash, token, recipient);
return;
}
revert InvalidDelegatedSelector(selector);
}
// -------------------------------------------------------------------------
// Internal Helpers
// -------------------------------------------------------------------------
/// forge-lint: disable-next-line(mixed-case-function)
function _safeTransferFrom(address token, address from, address to, uint256 amount) internal {
IERC20 erc20 = IERC20(token);
SafeERC20.safeTransferFrom(erc20, from, to, amount);
}
/// forge-lint: disable-next-line(mixed-case-function)
function _transferNative(address _to, uint256 _amount) internal {
(bool success,) = payable(_to).call{value: _amount}("");
if (!success) revert NativeTransferFailed();
}
/// forge-lint: disable-next-line(mixed-case-function)
function _transferERC20(address _token, address _to, uint256 _amount) internal {
IERC20 erc20 = IERC20(_token);
SafeERC20.safeTransfer(erc20, _to, _amount);
}
/// forge-lint: disable-next-line(mixed-case-function)
function _getBalance(address token, address account) internal view returns (uint256) {
return token == address(0) ? account.balance : IERC20(token).balanceOf(account);
}
/// forge-lint: disable-next-line(mixed-case-function)
function _getSelfBalance(address token) internal view returns (uint256) {
return _getBalance(token, address(this));
}
/// forge-lint: disable-next-line(mixed-case-function)
function _injectAndCallDelegated(
address token,
address target,
bytes memory callData,
uint256 amountOffset,
bytes32 placeholder
) internal {
uint256 callerBalance = _getSelfBalance(token);
if (callerBalance == 0) {
if (token == address(0)) {
revert NoValueAvailable();
} else {
revert NoTokensToSweep();
}
}
_injectAndExecuteCall(token, target, callData, amountOffset, placeholder, callerBalance);
}
/// forge-lint: disable-next-line(mixed-case-function)
function _injectAndExecuteCall(
address token,
address target,
bytes memory callData,
uint256 amountOffset,
bytes32 placeholder,
uint256 callerBalance
) internal {
// Replace placeholder with actual balance if needed
bool shouldReplace = (amountOffset != 0 || placeholder != bytes32(0));
if (shouldReplace) {
if (callData.length < amountOffset + 32) revert AmountOffsetOutOfBounds();
bytes32 found;
assembly {
found := mload(add(add(callData, 32), amountOffset))
}
if (found != placeholder) revert PlaceholderMismatch();
assembly {
mstore(add(add(callData, 32), amountOffset), callerBalance)
}
}
// Execute call based on token type
if (token == address(0)) {
(bool success, bytes memory result) = target.call{value: callerBalance}(callData);
emit BalanceInjectorCall(token, target, placeholder, callerBalance, amountOffset, success, result);
if (!success) revert TargetCallFailed(result);
} else {
IERC20 erc20 = IERC20(token);
SafeERC20.forceApprove(erc20, target, callerBalance);
(bool success, bytes memory result) = target.call(callData);
emit BalanceInjectorCall(token, target, placeholder, callerBalance, amountOffset, success, result);
if (!success) revert TargetCallFailed(result);
}
}
/// forge-lint: disable-next-line(mixed-case-function)
function _validateRouterCall(bytes calldata callData) internal pure {
// Extract function selector
if (callData.length < 4) revert InvalidFunctionSelector(bytes4(0));
bytes4 selector = bytes4(callData[0:4]);
// Only allow `aggregate3Value` or `aggregate3` (0x174dea71 or 0x82ad56cb)
if (selector == 0x174dea71) {
// Decode and validate the Call3Value[] array to ensure allowFailure=false for all calls
IMulticall3.Call3Value[] memory calls = abi.decode(callData[4:], (IMulticall3.Call3Value[]));
// Iterate through all calls and verify allowFailure is false
for (uint256 i = 0; i < calls.length; i++) {
if (calls[i].allowFailure) {
revert AllowFailureMustBeFalse(i);
}
}
} else if (selector == 0x82ad56cb) {
// Decode and validate the Call3[] array to ensure allowFailure=false for all calls
IMulticall3.Call3[] memory calls = abi.decode(callData[4:], (IMulticall3.Call3[]));
// Iterate through all calls and verify allowFailure is false
for (uint256 i = 0; i < calls.length; i++) {
if (calls[i].allowFailure) {
revert AllowFailureMustBeFalse(i);
}
}
} else {
revert InvalidFunctionSelector(selector);
}
}
}
DelegatecallGuard.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
/// @notice Abstract contract providing a reusable delegatecall-only guard.
abstract contract DelegatecallGuard {
// -------------------------------------------------------------------------
// Errors
// -------------------------------------------------------------------------
/// @dev Error thrown when a function expected to be delegatecalled is invoked directly
error NotDelegateCall();
// -------------------------------------------------------------------------
// Immutable Variables
// -------------------------------------------------------------------------
/// @dev Cached address of this contract to detect delegatecall context
address internal immutable _SELF = address(this);
// -------------------------------------------------------------------------
// Modifiers
// -------------------------------------------------------------------------
/// @dev Modifier restricting functions to only be executed via delegatecall
modifier onlyDelegatecall() {
_onlyDelegatecall();
_;
}
// -------------------------------------------------------------------------
// Internal Functions
// -------------------------------------------------------------------------
/// @dev Internal check enforcing delegatecall context
function _onlyDelegatecall() internal view {
if (address(this) == _SELF) revert NotDelegateCall();
}
}
IMulticall3.sol 37 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
/// @title IMulticall3
/// @notice Minimal subset of Multicall3 used by Trails router.
/// @dev Matches the canonical implementation deployed at `0xcA11bde05977b3631167028862bE2a173976CA11`.
interface IMulticall3 {
// -------------------------------------------------------------------------
// Structs
// -------------------------------------------------------------------------
struct Call3 {
address target;
bool allowFailure;
bytes callData;
}
struct Call3Value {
address target;
bool allowFailure;
uint256 value;
bytes callData;
}
struct Result {
bool success;
bytes returnData;
}
// -------------------------------------------------------------------------
// Functions
// -------------------------------------------------------------------------
function aggregate3(Call3[] calldata calls) external payable returns (Result[] memory returnData);
function aggregate3Value(Call3Value[] calldata calls) external payable returns (Result[] memory returnData);
}
ITrailsRouter.sol 139 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
import {IDelegatedExtension} from "wallet-contracts-v3/modules/interfaces/IDelegatedExtension.sol";
import {IMulticall3} from "./IMulticall3.sol";
/// @title ITrailsRouter
/// @notice Interface describing the delegate-call router utilities exposed to Sequence wallets.
interface ITrailsRouter is IDelegatedExtension {
// ---------------------------------------------------------------------
// Events
// ---------------------------------------------------------------------
event BalanceInjectorCall(
address indexed token,
address indexed target,
bytes32 placeholder,
uint256 amountReplaced,
uint256 amountOffset,
bool success,
bytes result
);
event Refund(address indexed token, address indexed recipient, uint256 amount);
event Sweep(address indexed token, address indexed recipient, uint256 amount);
event RefundAndSweep(
address indexed token,
address indexed refundRecipient,
uint256 refundAmount,
address indexed sweepRecipient,
uint256 actualRefund,
uint256 remaining
);
event ActualRefund(address indexed token, address indexed recipient, uint256 expected, uint256 actual);
// ---------------------------------------------------------------------
// Multicall Operations
// ---------------------------------------------------------------------
/// @notice Delegates to Multicall3 to preserve msg.sender context.
/// @dev Delegates to Multicall3 to preserve msg.sender context.
/// @param data The data to execute.
/// @return returnResults The result of the execution.
function execute(bytes calldata data) external payable returns (IMulticall3.Result[] memory returnResults);
/// @notice Pull tokens from msg.sender, then delegatecall into Multicall3.
/// @dev For ERC20: pulls entire balance and requires prior approval. For ETH: uses msg.value.
/// @param token The ERC20 token to pull, or address(0) for ETH.
/// @param data The calldata for Multicall3.
/// @return returnResults The result of the execution.
function pullAndExecute(address token, bytes calldata data)
external
payable
returns (IMulticall3.Result[] memory returnResults);
/// @notice Pull specific amount of tokens from msg.sender, then delegatecall into Multicall3.
/// @dev For ERC20: requires prior approval. For ETH: requires msg.value.
/// @param token The ERC20 token to pull, or address(0) for ETH.
/// @param amount The amount to pull.
/// @param data The calldata for Multicall3.
/// @return returnResults The result of the execution.
function pullAmountAndExecute(address token, uint256 amount, bytes calldata data)
external
payable
returns (IMulticall3.Result[] memory returnResults);
// ---------------------------------------------------------------------
// Balance Injection
// ---------------------------------------------------------------------
/// @notice Sweeps tokens from msg.sender and calls target with modified calldata.
/// @dev Transfers tokens from msg.sender to this contract first.
/// @param token The ERC-20 token to sweep, or address(0) for ETH.
/// @param target The address to call with modified calldata.
/// @param callData The original calldata (must include a 32-byte placeholder).
/// @param amountOffset The byte offset in calldata where the placeholder is located.
/// @param placeholder The 32-byte placeholder that will be replaced with balance.
function injectSweepAndCall(
address token,
address target,
bytes calldata callData,
uint256 amountOffset,
bytes32 placeholder
) external payable;
/// @notice Injects balance and calls target (for delegatecall context).
/// @param token The ERC-20 token to sweep, or address(0) for ETH.
/// @param target The address to call with modified calldata.
/// @param callData The original calldata (must include a 32-byte placeholder).
/// @param amountOffset The byte offset in calldata where the placeholder is located.
/// @param placeholder The 32-byte placeholder that will be replaced with balance.
function injectAndCall(
address token,
address target,
bytes calldata callData,
uint256 amountOffset,
bytes32 placeholder
) external payable;
/// @notice Validates that the success sentinel for an opHash is set, then sweeps tokens.
/// @dev For delegatecall context. Used to ensure prior operation succeeded.
/// @param opHash The operation hash to validate.
/// @param token The token to sweep.
/// @param recipient The recipient of the sweep.
function validateOpHashAndSweep(bytes32 opHash, address token, address recipient) external payable;
// ---------------------------------------------------------------------
// Sweeper
// ---------------------------------------------------------------------
/// @notice Sweeps the entire balance to recipient.
/// @dev For delegatecall context. Transfers all tokens/ETH held by the wallet to the recipient.
/// @param token The address of the token to sweep. Use address(0) for the native token.
/// @param recipient The address to send the swept tokens to.
function sweep(address token, address recipient) external payable;
/// @notice Refunds up to `_refundAmount` to `_refundRecipient`, then sweeps any remaining balance to `_sweepRecipient`.
/// @dev For delegatecall context.
/// @param token The token address to operate on. Use address(0) for native.
/// @param refundRecipient Address receiving the refund portion.
/// @param refundAmount Maximum amount to refund.
/// @param sweepRecipient Address receiving the remaining balance.
function refundAndSweep(address token, address refundRecipient, uint256 refundAmount, address sweepRecipient)
external
payable;
// ---------------------------------------------------------------------
// Delegate Entry
// ---------------------------------------------------------------------
/// @inheritdoc IDelegatedExtension
function handleSequenceDelegateCall(
bytes32 opHash,
uint256 startingGas,
uint256 index,
uint256 numCalls,
uint256 space,
bytes calldata data
) external;
}
TrailsSentinelLib.sol 26 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
// -------------------------------------------------------------------------
// Library
// -------------------------------------------------------------------------
library TrailsSentinelLib {
// -------------------------------------------------------------------------
// Constants
// -------------------------------------------------------------------------
bytes32 public constant SENTINEL_NAMESPACE = keccak256("org.sequence.trails.router.sentinel");
uint256 public constant SUCCESS_VALUE = uint256(1);
// -------------------------------------------------------------------------
// Storage Slot Helpers
// -------------------------------------------------------------------------
function successSlot(bytes32 opHash) internal pure returns (uint256 result) {
// return keccak256(abi.encode(SENTINEL_NAMESPACE, opHash));
bytes32 namespace = SENTINEL_NAMESPACE;
assembly {
mstore(0x00, namespace)
mstore(0x20, opHash)
result := keccak256(0x00, 0x40)
}
}
}
Read Contract
MULTICALL3 0xc2add59d → address
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
__activateTstore 0x7423eb3c
No parameters
execute 0x09c5eabe
bytes data
returns: tuple[]
handleSequenceDelegateCall 0x4c4e814c
bytes32 _opHash
uint256
uint256
uint256
uint256
bytes _data
injectAndCall 0x5b5e6516
address token
address target
bytes callData
uint256 amountOffset
bytes32 placeholder
injectSweepAndCall 0xc5e5153b
address token
address target
bytes callData
uint256 amountOffset
bytes32 placeholder
pullAmountAndExecute 0xa9baaaf5
address token
uint256 amount
bytes data
returns: tuple[]
pullAndExecute 0x7a7eeb4f
address token
bytes data
returns: tuple[]
refundAndSweep 0x4784226e
address _token
address _refundRecipient
uint256 _refundAmount
address _sweepRecipient
sweep 0xb8dc491b
address _token
address _recipient
validateOpHashAndSweep 0x2a3ee126
bytes32 opHash
address _token
address _recipient
Recent Transactions
This address has 2 on-chain transactions, but only 1.5% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →