├── gas_calculations └── .gitkeep ├── .npmrc ├── .env-example ├── octanerc.json ├── .solhintignore ├── src ├── integrations │ ├── interfaces │ │ ├── qidao │ │ │ ├── IQiDaoRegistry.sol │ │ │ └── IStablecoin.sol │ │ ├── balancer │ │ │ ├── IPool.sol │ │ │ ├── IFlashLoans.sol │ │ │ ├── IMerkleRedeem.sol │ │ │ ├── IFlashLoanRecipient.sol │ │ │ └── IVault.sol │ │ ├── rari │ │ │ ├── IFuseAsset.sol │ │ │ ├── IFundController.sol │ │ │ ├── IFundProxy.sol │ │ │ └── IFundManager.sol │ │ ├── euler │ │ │ ├── IDToken.sol │ │ │ └── IEulerMarkets.sol │ │ ├── IBotRegistry.sol │ │ ├── LSTs │ │ │ ├── ICBETH.sol │ │ │ ├── IRETH.sol │ │ │ └── IWstETH.sol │ │ ├── aaveV2 │ │ │ ├── IStakedToken.sol │ │ │ ├── IPriceOracleGetterAave.sol │ │ │ ├── ILendingPoolAddressesProviderV2.sol │ │ │ └── IAaveProtocolDataProviderV2.sol │ │ ├── bprotocol │ │ │ └── IBAMM.sol │ │ ├── reflexer │ │ │ ├── IMedianOracle.sol │ │ │ ├── IFSMWrapper.sol │ │ │ ├── ICoinJoin.sol │ │ │ ├── ITaxCollector.sol │ │ │ ├── IOracleRelayer.sol │ │ │ ├── IBasicTokenAdapters.sol │ │ │ ├── ISAFESaviour.sol │ │ │ ├── IGetSafes.sol │ │ │ ├── ISAFEManager.sol │ │ │ └── ISAFEEngine.sol │ │ ├── aave │ │ │ ├── ILendToAaveMigrator.sol │ │ │ ├── IAToken.sol │ │ │ ├── IStkAave.sol │ │ │ └── ILendingPoolAddressesProvider.sol │ │ ├── mcd │ │ │ ├── IDSPause.sol │ │ │ ├── ICropJoin.sol │ │ │ ├── IPipInterface.sol │ │ │ ├── IOsm.sol │ │ │ ├── IDssSpell.sol │ │ │ ├── IJug.sol │ │ │ ├── ISpotter.sol │ │ │ ├── ICat.sol │ │ │ ├── IDaiJoin.sol │ │ │ ├── IJoin.sol │ │ │ ├── IPot.sol │ │ │ ├── ICdpRegistry.sol │ │ │ ├── ICropper.sol │ │ │ ├── IGetCdps.sol │ │ │ ├── IGem.sol │ │ │ ├── IManager.sol │ │ │ └── IVat.sol │ │ ├── curve │ │ │ ├── IFeeDistributor.sol │ │ │ ├── IMinter.sol │ │ │ ├── IDepositZap.sol │ │ │ ├── IAddressProvider.sol │ │ │ ├── IVotingEscrow.sol │ │ │ ├── stethPool │ │ │ │ └── ICurveStethPool.sol │ │ │ ├── ICurve3PoolZap.sol │ │ │ ├── ILiquidityGauge.sol │ │ │ ├── ICurveFactory.sol │ │ │ └── IRegistry.sol │ │ ├── insta │ │ │ ├── IInstaAccountV2.sol │ │ │ ├── IInstaIndex.sol │ │ │ └── IInstaMakerDAOMerkleDistributor.sol │ │ ├── IProxyERC20.sol │ │ ├── compound │ │ │ ├── ICompoundOracle.sol │ │ │ ├── IComptroller.sol │ │ │ └── ICToken.sol │ │ ├── guni │ │ │ ├── IGUniPool.sol │ │ │ └── IGUniRouter02.sol │ │ ├── liquity │ │ │ ├── IPriceFeed.sol │ │ │ ├── IBondNFTArtwork.sol │ │ │ ├── IHintHelpers.sol │ │ │ ├── ICollSurplusPool.sol │ │ │ ├── IBondNFT.sol │ │ │ ├── ILQTYStaking.sol │ │ │ ├── ISortedTroves.sol │ │ │ └── IBorrowerOperations.sol │ │ ├── convex │ │ │ ├── IRewardPool.sol │ │ │ ├── IConvexToken.sol │ │ │ ├── IBooster.sol │ │ │ └── IBaseRewardPool.sol │ │ ├── uniswap │ │ │ ├── v3 │ │ │ │ ├── IUniswapV3FlashCallback.sol │ │ │ │ ├── IUniswapV3Factory.sol │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ └── IUniswapV3SwapCallback.sol │ │ │ ├── IUniswapV2Pair.sol │ │ │ └── IUniswapV2Factory.sol │ │ ├── IProxyRegistry.sol │ │ ├── morpho │ │ │ └── IRewardsDistributor.sol │ │ ├── strategy │ │ │ └── ISubStorage.sol │ │ ├── IFLParamGetter.sol │ │ ├── ITrigger.sol │ │ ├── yearn │ │ │ ├── IYearnRegistry.sol │ │ │ └── IYVault.sol │ │ ├── flashloan │ │ │ ├── IFlashLoanBase.sol │ │ │ ├── IERC3156FlashBorrower.sol │ │ │ └── IERC3156FlashLender.sol │ │ ├── IERC721Enumerable.sol │ │ ├── chainlink │ │ │ ├── IPhaseAggregator.sol │ │ │ └── IAggregatorV3.sol │ │ ├── lido │ │ │ └── IWStEth.sol │ │ ├── exchange │ │ │ ├── IOffchainWrapper.sol.bak │ │ │ ├── IPair.sol │ │ │ ├── IExchangeV3.sol │ │ │ ├── IOasis.sol │ │ │ ├── IExchangeWrapper.sol │ │ │ └── IKyberNetworkProxy.sol │ │ ├── spark │ │ │ └── IsDAI.sol │ │ ├── ISubscriptions.sol │ │ ├── compoundV3 │ │ │ ├── ICometExt.sol │ │ │ └── ICometRewards.sol │ │ ├── IMCDPriceVerifier.sol │ │ ├── IGasToken.sol │ │ ├── kyber │ │ │ ├── IAggregationExecutor.sol │ │ │ └── IMetaAggregationRouterV2.sol │ │ ├── IDSProxy.sol │ │ ├── IWETH.sol │ │ ├── IDFSRegistry.sol │ │ ├── IERC721.sol │ │ ├── aaveV3 │ │ │ ├── IPriceOracleGetter.sol │ │ │ ├── IAaveProtocolDataProvider.sol │ │ │ ├── IPriceOracleSentinel.sol │ │ │ └── IAaveV3Oracle.sol │ │ ├── IERC20.sol │ │ ├── IERC4626.sol │ │ └── mstable │ │ │ └── ISavingsContractV2.sol │ ├── uniswap │ │ ├── helpers │ │ │ └── MainnetAddresses.sol │ │ └── MockUniswap.sol │ ├── registry │ │ └── FactoryBase.sol │ ├── ERC721.sol │ └── ERC4626.sol ├── accounts │ ├── kernel │ │ ├── types │ │ │ └── Structs.sol │ │ ├── interfaces │ │ │ ├── IKernelFactory.sol │ │ │ ├── IAccountExecute.sol │ │ │ └── IValidationManager.sol │ │ └── mock │ │ │ └── MockFallback.sol │ ├── safe │ │ ├── types │ │ │ └── DataTypes.sol │ │ └── interfaces │ │ │ ├── ISafeProxyFactory.sol │ │ │ └── IERC7484.sol │ ├── factory │ │ ├── template │ │ │ └── FactoryTemplate.sol │ │ └── interface │ │ │ └── IAccountFactory.sol │ ├── erc7579 │ │ └── interfaces │ │ │ ├── IERC7579Bootstrap.sol │ │ │ └── IMSA.sol │ └── nexus │ │ └── interfaces │ │ ├── INexusAccountFactory.sol │ │ └── INexus.sol ├── module-bases │ ├── interfaces │ │ ├── IERC712.sol │ │ ├── IStatelessValidator.sol │ │ ├── IERC1271.sol │ │ ├── IERC7484.sol │ │ └── Flashloan.sol │ ├── ERC7579PolicyBase.sol │ ├── utils │ │ ├── ERC7579Constants.sol │ │ └── TrustedForwarder.sol │ ├── mocks │ │ ├── MockTarget.sol │ │ ├── MockFallback.sol │ │ ├── MockStatelessValidator.sol │ │ ├── MockHook.sol │ │ ├── MockExecutor.sol │ │ ├── MockValidator.sol │ │ ├── MockRegistry.sol │ │ ├── MockHybridValidator.sol │ │ └── MockPolicy.sol │ ├── ERC7579ActionPolicy.sol │ ├── ERC7579UserOpPolicy.sol │ ├── ERC7579StatelessValidatorBase.sol │ ├── ERC7484RegistryAdapter.sol │ ├── ERC1271Policy.sol │ ├── ERC7579HybridValidatorBase.sol │ ├── ERC7579ModuleBase.sol │ ├── ERC7579FallbackBase.sol │ ├── ERC7579HookBase.sol │ ├── ERC7579ValidatorBase.sol │ └── ERC7579ValidatorMaster.sol ├── test │ ├── utils │ │ ├── ECDSA.sol │ │ ├── Log.sol │ │ └── gas │ │ │ └── UserOpGasLog.sol │ ├── helpers │ │ └── interfaces │ │ │ └── IAccountModulesPaginated.sol │ └── Auxiliary.sol ├── deployment │ ├── predeploy │ │ ├── Registry.sol │ │ ├── MockFactory.sol │ │ └── EntryPoint.sol │ ├── registry │ │ └── interfaces │ │ │ ├── IExternalSchemaValidator.sol │ │ │ ├── IERC7484.sol │ │ │ └── IExternalResolver.sol │ └── precompiles │ │ └── BytecodeDeployer.sol ├── ModuleKit.sol ├── Integrations.sol ├── Accounts.sol ├── Interfaces.sol ├── Mocks.sol ├── Helpers.sol ├── external │ └── ERC4337.sol └── Modules.sol ├── .gitignore ├── .changeset ├── config.json └── README.md ├── remappings.txt ├── .solhint.json ├── test ├── GasCalculationsTest.sol ├── BaseTest.t.sol └── mocks │ ├── MockValidatorFalse.sol │ ├── MockK1ValidatorUncompliantUninstall.sol │ └── MockK1Validator.sol ├── foundry.toml ├── .github └── workflows │ ├── ci.yaml │ └── dependency.yml └── package.json /gas_calculations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | -------------------------------------------------------------------------------- /.env-example: -------------------------------------------------------------------------------- 1 | MAINNET_RPC_URL= 2 | 3 | -------------------------------------------------------------------------------- /octanerc.json: -------------------------------------------------------------------------------- 1 | { 2 | "pathsToAnalyze": ["**/src/integrations/.*", "**/src/module-bases/.*"] 3 | } 4 | -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | lib/ 3 | src/integrations/interfaces/ 4 | src/core/Licensing/ 5 | test/ 6 | -------------------------------------------------------------------------------- /src/integrations/interfaces/qidao/IQiDaoRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | -------------------------------------------------------------------------------- /src/integrations/interfaces/balancer/IPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IPool { 5 | function getPoolId() external view returns (bytes32); 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/rari/IFuseAsset.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IFuseAsset { 6 | function getCash() external returns (uint256); 7 | } 8 | -------------------------------------------------------------------------------- /src/accounts/kernel/types/Structs.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | struct Execution { 5 | address target; 6 | uint256 value; 7 | bytes callData; 8 | } 9 | -------------------------------------------------------------------------------- /src/module-bases/interfaces/IERC712.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface IERC712 { 5 | function domainSeparator() external view returns (bytes32); 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/euler/IDToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IDToken { 5 | function flashLoan(uint256 amount, bytes calldata data) external; 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IBotRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IBotRegistry { 6 | function botList(address) public view virtual returns (bool); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/LSTs/ICBETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface ICBETH { 6 | function exchangeRate() external view returns (uint256 wethAmountPerCBETH); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV2/IStakedToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IStakedToken { 5 | function getTotalRewardsBalance(address) external view returns (uint256); 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/bprotocol/IBAMM.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IBAMM { 5 | function deposit(uint256) external; 6 | function withdraw(uint256) external; 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/IMedianOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IMedianOracle { 6 | function read() external view virtual returns (uint256); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aave/ILendToAaveMigrator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ILendToAaveMigrator { 6 | function migrateFromLEND(uint256 amount) external virtual; 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/euler/IEulerMarkets.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IEulerMarkets { 5 | function underlyingToDToken(address underlying) external view returns (address); 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/rari/IFundController.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IFundController { 6 | function fuseAssets(uint8, string memory) external view returns (address); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IDSPause.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IDSPause { 6 | function plot(address usr, bytes32 tag, bytes memory fax, uint256 eta) public virtual; 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/IFSMWrapper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IFSMWrapper { 5 | function getNextResultWithValidity() external view returns (uint256 price, bool valid); 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/IFeeDistributor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | pragma experimental ABIEncoderV2; 4 | 5 | interface IFeeDistributor { 6 | function claim(address) external returns (uint256); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/insta/IInstaAccountV2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | pragma abicoder v2; 4 | 5 | interface IInstaAccountV2 { 6 | function cast(string[] memory, bytes[] memory, address) external; 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IProxyERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IProxyERC20 { 6 | function target() external returns (address); 7 | function tokenState() external returns (address); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/ICropJoin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IJoin.sol"; 6 | 7 | abstract contract ICropJoin is IJoin { 8 | function bonus() external virtual returns (IGem); 9 | } 10 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IPipInterface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IPipInterface { 6 | function read() public virtual returns (bytes32); 7 | function poke() external virtual; 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/compound/ICompoundOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ICompoundOracle { 6 | function getUnderlyingPrice(address cToken) external view virtual returns (uint256); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/guni/IGUniPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma solidity ^0.8.10; 3 | 4 | interface IGUniPool { 5 | function token0() external view returns (address); 6 | function token1() external view returns (address); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IOsm.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | abstract contract IOsm { 5 | mapping(address => uint256) public bud; 6 | 7 | function peep() external view virtual returns (bytes32, bool); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/IPriceFeed.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IPriceFeed { 6 | function lastGoodPrice() external pure returns (uint256); 7 | function fetchPrice() external returns (uint256); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/convex/IRewardPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IRewardPool { 5 | function rewardToken() external view returns (address); 6 | function earned(address) external view returns (uint256); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/uniswap/v3/IUniswapV3FlashCallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.10; 3 | 4 | interface IUniswapV3FlashCallback { 5 | function uniswapV3FlashCallback(uint256 fee0, uint256 fee1, bytes memory data) external; 6 | } 7 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/IMinter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | pragma experimental ABIEncoderV2; 4 | 5 | interface IMinter { 6 | function mint(address _gaugeAddr) external; 7 | function mint_many(address[8] memory _gaugeAddrs) external; 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IProxyRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IProxyRegistry { 6 | function proxies(address _owner) public view virtual returns (address); 7 | function build(address) public virtual returns (address); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/IDepositZap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IDepositZap { 5 | function pool() external view returns (address); 6 | function curve() external view returns (address); 7 | function token() external view returns (address); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/LSTs/IRETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IRETH { 6 | function getEthValue(uint256 rethAmount) external view returns (uint256 wethAmount); 7 | function getRethValue(uint256 wethAmount) external view returns (uint256 rethAmount); 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiler files 2 | cache/ 3 | out/ 4 | 5 | # Ignores development broadcast logs 6 | !/broadcast 7 | /broadcast/*/31337/ 8 | /broadcast/**/dry-run/ 9 | 10 | packages/modulekit/gas_calculations/*.json 11 | 12 | 13 | # Dotenv file 14 | .env 15 | node_modules 16 | 17 | gas_calculations/**.json 18 | 19 | .DS_Store -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IDssSpell.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IDssSpell { 6 | function cast() public virtual; 7 | function done() public view virtual returns (bool); 8 | function nextCastTime() public view virtual returns (uint256); 9 | } 10 | -------------------------------------------------------------------------------- /src/integrations/interfaces/morpho/IRewardsDistributor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IRewardsDistributor { 5 | function claimed(address account) external view returns (uint256); 6 | 7 | function claim(address _account, uint256 _claimable, bytes32[] calldata _proof) external; 8 | } 9 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "restricted", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/LSTs/IWstETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IWstETH { 6 | function getStETHByWstETH(uint256 wstethAmount) external view returns (uint256 wethAmount); 7 | function getWstETHByStETH(uint256 wethAmount) external view returns (uint256 wstethAmount); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/insta/IInstaIndex.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IInstaIndex { 5 | function build( 6 | address _owner, 7 | uint256 accountVersion, 8 | address _origin 9 | ) 10 | external 11 | returns (address _account); 12 | } 13 | -------------------------------------------------------------------------------- /src/accounts/kernel/interfaces/IKernelFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface IKernelFactory { 5 | function createAccount(bytes calldata data, bytes32 salt) external payable returns (address); 6 | function getAddress(bytes calldata data, bytes32 salt) external returns (address); 7 | } 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/ICoinJoin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | abstract contract ICoinJoin { 5 | uint256 public decimals; 6 | 7 | function join(address account, uint256 wad) external virtual; 8 | 9 | function exit(address account, uint256 wad) external virtual; 10 | } 11 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IJug.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IJug { 6 | struct Ilk { 7 | uint256 duty; 8 | uint256 rho; 9 | } 10 | 11 | mapping(bytes32 => Ilk) public ilks; 12 | 13 | function drip(bytes32) public virtual returns (uint256); 14 | } 15 | -------------------------------------------------------------------------------- /src/integrations/interfaces/balancer/IFlashLoans.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IFlashLoans { 5 | function flashLoan( 6 | address recipient, 7 | address[] memory tokens, 8 | uint256[] memory amounts, 9 | bytes memory userData 10 | ) 11 | external; 12 | } 13 | -------------------------------------------------------------------------------- /src/integrations/interfaces/strategy/ISubStorage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ISubStorage { 6 | function updateSubTriggerData( 7 | uint256 _subId, 8 | bytes memory _triggerData, 9 | uint256 _triggerNum 10 | ) 11 | public 12 | virtual; 13 | } 14 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IFLParamGetter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IFLParamGetter { 6 | function getFlashLoanParams(bytes memory _data) 7 | public 8 | view 9 | virtual 10 | returns (address[] memory tokens, uint256[] memory amount, uint256[] memory modes); 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/ISpotter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IPipInterface.sol"; 6 | 7 | abstract contract ISpotter { 8 | struct Ilk { 9 | IPipInterface pip; 10 | uint256 mat; 11 | } 12 | 13 | mapping(bytes32 => Ilk) public ilks; 14 | 15 | uint256 public par; 16 | } 17 | -------------------------------------------------------------------------------- /src/test/utils/ECDSA.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Utils 5 | import { sign as vmSign } from "./Vm.sol"; 6 | 7 | function ecdsaSign(uint256 privKey, bytes32 digest) pure returns (bytes memory signature) { 8 | (uint8 v, bytes32 r, bytes32 s) = vmSign(privKey, digest); 9 | return abi.encodePacked(r, s, v); 10 | } 11 | -------------------------------------------------------------------------------- /src/integrations/interfaces/ITrigger.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ITrigger { 6 | function isTriggered(bytes memory, bytes memory) public virtual returns (bool); 7 | function isChangeable() public virtual returns (bool); 8 | function changedSubData(bytes memory) public virtual returns (bytes memory); 9 | } 10 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aave/IAToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IAToken { 6 | function redeem(uint256 _amount) external virtual; 7 | function balanceOf(address _owner) external view virtual returns (uint256 balance); 8 | function UNDERLYING_ASSET_ADDRESS() external view virtual returns (address); 9 | } 10 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/ICat.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ICat { 6 | struct Ilk { 7 | address flip; // Liquidator 8 | uint256 chop; // Liquidation Penalty [ray] 9 | uint256 lump; // Liquidation Quantity [wad] 10 | } 11 | 12 | mapping(bytes32 => Ilk) public ilks; 13 | } 14 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/IAddressProvider.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | pragma experimental ABIEncoderV2; 4 | 5 | interface IAddressProvider { 6 | function admin() external view returns (address); 7 | function get_registry() external view returns (address); 8 | function get_address(uint256 _id) external view returns (address); 9 | } 10 | -------------------------------------------------------------------------------- /src/module-bases/interfaces/IStatelessValidator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | interface IStatelessValidator { 5 | function validateSignatureWithData( 6 | bytes32 hash, 7 | bytes calldata signature, 8 | bytes calldata data 9 | ) 10 | external 11 | view 12 | returns (bool); 13 | } 14 | -------------------------------------------------------------------------------- /src/integrations/interfaces/uniswap/v3/IUniswapV3Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IUniswapV3Factory { 6 | function getPool( 7 | address token0, 8 | address token1, 9 | uint24 fee 10 | ) 11 | external 12 | view 13 | virtual 14 | returns (address poolAddress); 15 | } 16 | -------------------------------------------------------------------------------- /src/integrations/interfaces/convex/IConvexToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "../../interfaces/IERC20.sol"; 5 | 6 | interface IConvexToken is IERC20 { 7 | function reductionPerCliff() external view returns (uint256); 8 | function totalCliffs() external view returns (uint256); 9 | function maxSupply() external view returns (uint256); 10 | } 11 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/IBondNFTArtwork.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IBondNFT.sol"; 6 | 7 | interface IBondNFTArtwork { 8 | function tokenURI( 9 | uint256 _tokenID, 10 | IBondNFT.BondExtraData calldata _bondExtraData 11 | ) 12 | external 13 | view 14 | returns (string memory); 15 | } 16 | -------------------------------------------------------------------------------- /src/integrations/interfaces/yearn/IYearnRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IYearnRegistry { 6 | function latestVault(address) external view virtual returns (address); 7 | function numVaults(address) external view virtual returns (uint256); 8 | function vaults(address, uint256) external view virtual returns (address); 9 | } 10 | -------------------------------------------------------------------------------- /src/integrations/interfaces/balancer/IMerkleRedeem.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | pragma experimental ABIEncoderV2; 5 | 6 | interface IMerkleRedeem { 7 | struct Claim { 8 | uint256 week; 9 | uint256 balance; 10 | bytes32[] merkleProof; 11 | } 12 | 13 | function claimWeeks(address _liquidityProvider, Claim[] memory claims) external; 14 | } 15 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/ITaxCollector.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ITaxCollector { 6 | struct CollateralType { 7 | uint256 stabilityFee; 8 | uint256 updateTime; 9 | } 10 | 11 | mapping(bytes32 => CollateralType) public collateralTypes; 12 | 13 | function taxSingle(bytes32) public virtual returns (uint256); 14 | } 15 | -------------------------------------------------------------------------------- /src/integrations/interfaces/rari/IFundProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IFundProxy { 6 | function getRawFundBalancesAndPrices() 7 | external 8 | returns ( 9 | string[] memory, 10 | uint256[] memory, 11 | uint8[][] memory, 12 | uint256[][] memory, 13 | uint256[] memory 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /src/integrations/interfaces/uniswap/IUniswapV2Pair.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IUniswapV2Pair { 5 | function token0() external view returns (address); 6 | function token1() external view returns (address); 7 | function getReserves() 8 | external 9 | view 10 | returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/IVotingEscrow.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | pragma experimental ABIEncoderV2; 4 | 5 | interface IVotingEscrow { 6 | function create_lock(uint256 _amount, uint256 _unlockTime) external; 7 | function increase_amount(uint256 _amount) external; 8 | function increase_unlock_time(uint256 _unlockTime) external; 9 | function withdraw() external; 10 | } 11 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IDaiJoin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "./IVat.sol"; 5 | import "./IGem.sol"; 6 | 7 | abstract contract IDaiJoin { 8 | function vat() public virtual returns (IVat); 9 | function dai() public virtual returns (IGem); 10 | function join(address, uint256) public payable virtual; 11 | function exit(address, uint256) public virtual; 12 | } 13 | -------------------------------------------------------------------------------- /src/integrations/uniswap/helpers/MainnetAddresses.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | address payable constant SWAPROUTER_ADDRESS = payable(0xE592427A0AEce92De3Edee1F18E0157C05861564); 5 | uint24 constant SWAPROUTER_DEFAULTFEE = 3000; 6 | address constant QUOTER_ADDRESS = 0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6; 7 | address constant FACTORY_ADDRESS = 0x1F98431c8aD98523631AE4a59f267346ea31F984; 8 | -------------------------------------------------------------------------------- /src/integrations/interfaces/flashloan/IFlashLoanBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | abstract contract IFlashLoanBase { 5 | struct FlashLoanParams { 6 | address[] tokens; 7 | uint256[] amounts; 8 | uint256[] modes; 9 | address onBehalfOf; 10 | address flParamGetterAddr; 11 | bytes flParamGetterData; 12 | bytes recipeData; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IERC721.sol"; 6 | 7 | interface IERC721Enumerable is IERC721 { 8 | function totalSupply() external view returns (uint256); 9 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); 10 | function tokenByIndex(uint256 index) external view returns (uint256); 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/chainlink/IPhaseAggregator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IPhaseAggregator { 5 | function latestRoundData() 6 | external 7 | view 8 | returns ( 9 | uint80 roundId, 10 | int256 answer, 11 | uint256 startedAt, 12 | uint256 updatedAt, 13 | uint80 answeredInRound 14 | ); 15 | } 16 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/stethPool/ICurveStethPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ICurveStethPool { 5 | function add_liquidity(uint256[2] memory, uint256) external payable returns (uint256); 6 | function remove_liquidity(uint256, uint256[2] memory) external returns (uint256[2] memory); 7 | function remove_liquidity_imbalance(uint256[2] memory, uint256) external returns (uint256); 8 | } 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IJoin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IGem.sol"; 6 | 7 | abstract contract IJoin { 8 | bytes32 public ilk; 9 | 10 | function dec() public view virtual returns (uint256); 11 | function gem() public view virtual returns (IGem); 12 | function join(address, uint256) public payable virtual; 13 | function exit(address, uint256) public virtual; 14 | } 15 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/IOracleRelayer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IOracleRelayer { 6 | struct CollateralType { 7 | address orcl; 8 | uint256 safetyCRatio; 9 | } 10 | 11 | mapping(bytes32 => CollateralType) public collateralTypes; 12 | 13 | function redemptionPrice() public virtual returns (uint256); 14 | 15 | uint256 public redemptionRate; 16 | } 17 | -------------------------------------------------------------------------------- /src/integrations/interfaces/lido/IWStEth.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | // Interface for wrapping and unwrapping StEth 6 | interface IWStEth { 7 | function wrap(uint256 _stETHAmount) external returns (uint256); 8 | function unwrap(uint256 _wstETHAmount) external returns (uint256); 9 | function stEthPerToken() external view returns (uint256); 10 | function tokensPerStEth() external view returns (uint256); 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/exchange/IOffchainWrapper.sol.bak: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "../../exchangeV3/DFSExchangeData.sol"; 6 | 7 | abstract contract IOffchainWrapper is DFSExchangeData { 8 | function takeOrder( 9 | ExchangeData memory _exData, 10 | ExchangeActionType _type 11 | ) 12 | public 13 | payable 14 | virtual 15 | returns (bool success, uint256); 16 | } 17 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/IBasicTokenAdapters.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IBasicTokenAdapters { 6 | bytes32 public collateralType; 7 | 8 | function decimals() public view virtual returns (uint256); 9 | function collateral() public view virtual returns (address); 10 | function join(address, uint256) public payable virtual; 11 | function exit(address, uint256) public virtual; 12 | } 13 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/ICurve3PoolZap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ICurve3PoolZap { 5 | function add_liquidity(address, uint256[4] memory, uint256) external; 6 | function remove_liquidity(address, uint256, uint256[4] memory) external; 7 | function remove_liquidity_one_coin(address, uint256, int128, uint256) external; 8 | function remove_liquidity_imbalance(address, uint256[4] memory, uint256) external; 9 | } 10 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aave/IStkAave.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IStkAave { 6 | function cooldown() external virtual; 7 | function redeem(address to, uint256 amount) external virtual; 8 | function REWARD_TOKEN() external view virtual returns (address); 9 | function stake(address onBehalfOf, uint256 amount) external virtual; 10 | function claimRewards(address to, uint256 amount) external virtual; 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/spark/IsDAI.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "../IERC20.sol"; 5 | 6 | interface IsDAI is IERC20 { 7 | function deposit(uint256 _amount, address _receiver) external; 8 | function mint(uint256 _shares, address _receiver) external; 9 | function withdraw(uint256 _amount, address _receiver, address _owner) external; 10 | function redeem(uint256 _shares, address _receiver, address _owner) external; 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IPot.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IPot { 5 | function pie(address) external view returns (uint256); 6 | function vat() external view returns (address); 7 | function chi() external view returns (uint256); 8 | function rho() external view returns (uint256); 9 | function drip() external returns (uint256); 10 | function join(uint256) external; 11 | function exit(uint256) external; 12 | } 13 | -------------------------------------------------------------------------------- /src/integrations/interfaces/ISubscriptions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ISubscriptions { 5 | function unsubscribe() external; 6 | function unsubscribe(uint256 _cdpId) external; 7 | function subscribersPos(uint256) external view returns (uint256 arrPos, bool subscribed); 8 | function subscribersPos(address) external view returns (uint256 arrPos, bool subscribed); 9 | function isSubscribed(address _user) external view returns (bool); 10 | } 11 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/ICdpRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IVat.sol"; 6 | import "./IGem.sol"; 7 | 8 | abstract contract ICdpRegistry { 9 | function open(bytes32 ilk, address usr) public virtual returns (uint256); 10 | 11 | function cdps(bytes32, address) public view virtual returns (uint256); 12 | function owns(uint256) public view virtual returns (address); 13 | function ilks(uint256) public view virtual returns (bytes32); 14 | } 15 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579PolicyBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579ModuleBase } from "./ERC7579ModuleBase.sol"; 5 | import { IPolicy, ConfigId } from "./interfaces/IPolicy.sol"; 6 | 7 | abstract contract ERC7579PolicyBase is ERC7579ModuleBase, IPolicy { 8 | function initializeWithMultiplexer( 9 | address account, 10 | ConfigId configId, 11 | bytes calldata initData 12 | ) 13 | external 14 | virtual; 15 | } 16 | -------------------------------------------------------------------------------- /src/integrations/interfaces/compoundV3/ICometExt.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ICometExt { 6 | function allow(address manager, bool isAllowed) external virtual; 7 | function collateralBalanceOf( 8 | address account, 9 | address asset 10 | ) 11 | external 12 | view 13 | virtual 14 | returns (uint128); 15 | function allowance(address owner, address spender) external view virtual returns (uint256); 16 | } 17 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IMCDPriceVerifier.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IMCDPriceVerifier { 6 | function verifyVaultNextPrice( 7 | uint256 _nextPrice, 8 | uint256 _cdpId 9 | ) 10 | public 11 | view 12 | virtual 13 | returns (bool); 14 | function verifyNextPrice(uint256 _nextPrice, bytes32 _ilk) public view virtual returns (bool); 15 | function setAuthorized(address _address, bool _allowed) public virtual; 16 | } 17 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/ISAFESaviour.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ISAFESaviour { 6 | function deposit(uint256 safeID, uint256 lpTokenAmount) public virtual; 7 | function withdraw(uint256 safeID, uint256 lpTokenAmount, address dst) public virtual; 8 | function lpToken() public view virtual returns (address); 9 | function lpTokenCover(address) public view virtual returns (uint256); 10 | function getReserves(uint256, address) public virtual; 11 | } 12 | -------------------------------------------------------------------------------- /src/test/helpers/interfaces/IAccountModulesPaginated.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface IAccountModulesPaginated { 5 | function getValidatorsPaginated( 6 | address, 7 | uint256 8 | ) 9 | external 10 | view 11 | returns (address[] memory, address); 12 | 13 | function getExecutorsPaginated( 14 | address, 15 | uint256 16 | ) 17 | external 18 | view 19 | returns (address[] memory, address); 20 | } 21 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IGasToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "./IERC20.sol"; 6 | 7 | abstract contract IGasToken is IERC20 { 8 | function free(uint256 value) public virtual returns (bool success); 9 | 10 | function freeUpTo(uint256 value) public virtual returns (uint256 freed); 11 | 12 | function freeFrom(address from, uint256 value) public virtual returns (bool success); 13 | 14 | function freeFromUpTo(address from, uint256 value) public virtual returns (uint256 freed); 15 | } 16 | -------------------------------------------------------------------------------- /src/integrations/interfaces/rari/IFundManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IFundManager { 6 | function depositTo(address to, string memory currencyCode, uint256 amount) external; 7 | function withdraw(string calldata currencyCode, uint256 amount) external returns (uint256); 8 | function getRawFundBalance(string memory currencyCode) external returns (uint256); 9 | function rariFundToken() external view returns (address); 10 | function getFundBalance() external returns (uint256); 11 | } 12 | -------------------------------------------------------------------------------- /src/integrations/interfaces/kyber/IAggregationExecutor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IAggregationExecutor { 5 | function callBytes(bytes calldata data) external payable; // 0xd9c45357 6 | 7 | // callbytes per swap sequence 8 | function swapSingleSequence(bytes calldata data) external; 9 | 10 | function finalTransactionProcessing( 11 | address tokenIn, 12 | address tokenOut, 13 | address to, 14 | bytes calldata destTokenFeeData 15 | ) 16 | external; 17 | } 18 | -------------------------------------------------------------------------------- /src/integrations/interfaces/uniswap/IUniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IUniswapV2Factory { 6 | function getPair(address tokenA, address tokenB) external view virtual returns (address pair); 7 | function allPairs(uint256) external view virtual returns (address pair); 8 | function allPairsLength() external view virtual returns (uint256); 9 | function feeTo() external view virtual returns (address); 10 | function feeToSetter() external view virtual returns (address); 11 | } 12 | -------------------------------------------------------------------------------- /src/module-bases/utils/ERC7579Constants.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | uint256 constant MODULE_TYPE_VALIDATOR = 1; 5 | uint256 constant MODULE_TYPE_EXECUTOR = 2; 6 | uint256 constant MODULE_TYPE_FALLBACK = 3; 7 | uint256 constant MODULE_TYPE_HOOK = 4; 8 | uint256 constant MODULE_TYPE_POLICY = 5; 9 | uint256 constant MODULE_TYPE_SIGNER = 6; 10 | uint256 constant MODULE_TYPE_STATELESS_VALIDATOR = 7; 11 | uint256 constant MODULE_TYPE_PREVALIDATION_HOOK_ERC1271 = 8; 12 | uint256 constant MODULE_TYPE_PREVALIDATION_HOOK_ERC4337 = 9; 13 | -------------------------------------------------------------------------------- /src/integrations/interfaces/convex/IBooster.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: SEE LICENSE IN LICENSE 2 | pragma solidity ^0.8.10; 3 | 4 | interface IBooster { 5 | struct PoolInfo { 6 | address lpToken; 7 | address token; 8 | address gauge; 9 | address crvRewards; 10 | address stash; 11 | bool shutdown; 12 | } 13 | 14 | function poolInfo(uint256) external view returns (PoolInfo memory); 15 | function deposit(uint256, uint256, bool) external returns (bool); 16 | function withdraw(uint256, uint256) external returns (bool); 17 | } 18 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/ICropper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface ICropper { 6 | function proxy(address) external view returns (address); 7 | function getOrCreateProxy(address) external returns (address); 8 | function join(address, address, uint256) external; 9 | function exit(address, address, uint256) external; 10 | function flee(address, address, uint256) external; 11 | function frob(bytes32, address, address, address, int256, int256) external; 12 | function quit(bytes32, address, address) external; 13 | } 14 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockTarget.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | contract MockTarget { 5 | error Unauthorized(); 6 | 7 | uint256 public value; 8 | 9 | function set(uint256 _value) public payable returns (uint256) { 10 | value = _value; 11 | return _value; 12 | } 13 | 14 | function setAccessControl(uint256 _value) public returns (uint256) { 15 | if (msg.sender != address(this)) { 16 | revert Unauthorized(); 17 | } 18 | value = _value; 19 | return _value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV2/IPriceOracleGetterAave.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IPriceOracleGetterAave { 6 | function getAssetPrice(address _asset) external view virtual returns (uint256); 7 | function getAssetsPrices(address[] calldata _assets) 8 | external 9 | view 10 | virtual 11 | returns (uint256[] memory); 12 | function getSourceOfAsset(address _asset) external view virtual returns (address); 13 | function getFallbackOracle() external view virtual returns (address); 14 | } 15 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579ActionPolicy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579PolicyBase } from "./ERC7579PolicyBase.sol"; 5 | import { ConfigId, IActionPolicy } from "./interfaces/IPolicy.sol"; 6 | 7 | abstract contract ERC7579ActionPolicy is ERC7579PolicyBase, IActionPolicy { 8 | function checkAction( 9 | ConfigId id, 10 | address account, 11 | address target, 12 | uint256 value, 13 | bytes calldata data 14 | ) 15 | external 16 | virtual 17 | returns (uint256); 18 | } 19 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579UserOpPolicy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579PolicyBase } from "./ERC7579PolicyBase.sol"; 5 | import { ConfigId, IUserOpPolicy } from "./interfaces/IPolicy.sol"; 6 | import { PackedUserOperation } from "../external/ERC4337.sol"; 7 | 8 | abstract contract ERC7579UserOpPolicy is ERC7579PolicyBase, IUserOpPolicy { 9 | function checkUserOp( 10 | ConfigId id, 11 | PackedUserOperation calldata userOp 12 | ) 13 | external 14 | virtual 15 | returns (uint256); 16 | } 17 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579StatelessValidatorBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579ModuleBase } from "./ERC7579ModuleBase.sol"; 5 | import { IStatelessValidator } from "./interfaces/IStatelessValidator.sol"; 6 | 7 | abstract contract ERC7579StatelessValidatorBase is ERC7579ModuleBase, IStatelessValidator { 8 | function validateSignatureWithData( 9 | bytes32, 10 | bytes calldata, 11 | bytes calldata 12 | ) 13 | external 14 | view 15 | virtual 16 | returns (bool validSig); 17 | } 18 | -------------------------------------------------------------------------------- /src/module-bases/ERC7484RegistryAdapter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { IERC7484 } from "./interfaces/IERC7484.sol"; 5 | 6 | abstract contract ERC7484RegistryAdapter { 7 | // registry address 8 | IERC7484 public immutable REGISTRY; 9 | 10 | /** 11 | * Contract constructor 12 | * @dev sets the registry as an immutable variable 13 | * 14 | * @param _registry The registry address 15 | */ 16 | constructor(IERC7484 _registry) { 17 | // set the registry 18 | REGISTRY = _registry; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/module-bases/ERC1271Policy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579PolicyBase } from "./ERC7579PolicyBase.sol"; 5 | import { ConfigId, I1271Policy } from "./interfaces/IPolicy.sol"; 6 | 7 | abstract contract ERC1271Policy is ERC7579PolicyBase, I1271Policy { 8 | function check1271SignedAction( 9 | ConfigId id, 10 | address requestSender, 11 | address account, 12 | bytes32 hash, 13 | bytes calldata signature 14 | ) 15 | external 16 | view 17 | virtual 18 | returns (bool); 19 | } 20 | -------------------------------------------------------------------------------- /src/accounts/safe/types/DataTypes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC7484 } from "../interfaces/IERC7484.sol"; 6 | 7 | // Types 8 | import { CallType } from "../../common/lib/ModeLib.sol"; 9 | 10 | struct FallbackHandler { 11 | address handler; 12 | CallType calltype; 13 | } 14 | 15 | enum HookType { 16 | GLOBAL, 17 | SIG 18 | } 19 | 20 | struct ModuleInit { 21 | address module; 22 | bytes initData; 23 | } 24 | 25 | struct RegistryInit { 26 | IERC7484 registry; 27 | address[] attesters; 28 | uint8 threshold; 29 | } 30 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IGetCdps.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | abstract contract IGetCdps { 5 | function getCdpsAsc( 6 | address manager, 7 | address guy 8 | ) 9 | external 10 | view 11 | virtual 12 | returns (uint256[] memory ids, address[] memory urns, bytes32[] memory ilks); 13 | 14 | function getCdpsDesc( 15 | address manager, 16 | address guy 17 | ) 18 | external 19 | view 20 | virtual 21 | returns (uint256[] memory ids, address[] memory urns, bytes32[] memory ilks); 22 | } 23 | -------------------------------------------------------------------------------- /remappings.txt: -------------------------------------------------------------------------------- 1 | erc4337-validation/=node_modules/@rhinestone/erc4337-validation/src/ 2 | @ERC4337/=node_modules/@ERC4337/ 3 | account-abstraction/=node_modules/@ERC4337/account-abstraction/contracts/ 4 | account-abstraction-v0.6/=node_modules/@ERC4337/account-abstraction-v0.6/contracts/ 5 | modulekit/=node_modules/@rhinestone/modulekit/src/ 6 | @openzeppelin/=node_modules/@openzeppelin/ 7 | ds-test/=node_modules/ds-test/src/ 8 | forge-std/=node_modules/forge-std/src/ 9 | solady/=node_modules/solady/src/ 10 | solarray/=node_modules/solarray/src/ 11 | @prb/math/=node_modules/@prb/math/src/ 12 | ExcessivelySafeCall/=node_modules/excessively-safe-call/src/ -------------------------------------------------------------------------------- /src/deployment/predeploy/Registry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC7484 } from "../../Interfaces.sol"; 6 | 7 | // Mocks 8 | import { MockRegistry } from "../../Mocks.sol"; 9 | 10 | // Utils 11 | import { etch } from "../../test/utils/Vm.sol"; 12 | 13 | /// @dev Preset registry address 14 | address constant REGISTRY_ADDR = 0x000000000069E2a187AEFFb852bF3cCdC95151B2; 15 | 16 | function etchRegistry() returns (IERC7484) { 17 | address _registry = address(new MockRegistry()); 18 | etch(REGISTRY_ADDR, _registry.code); 19 | return IERC7484(REGISTRY_ADDR); 20 | } 21 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "rules": { 4 | "avoid-low-level-calls": "off", 5 | "code-complexity": ["error", 11], 6 | "compiler-version": ["error", ">=0.8.0"], 7 | "contract-name-camelcase": "off", 8 | "const-name-snakecase": "off", 9 | "func-name-mixedcase": "off", 10 | "func-visibility": ["error", { "ignoreConstructors": true }], 11 | "max-line-length": ["error", 123], 12 | "named-parameters-mapping": "warn", 13 | "no-empty-blocks": "off", 14 | "not-rely-on-time": "off", 15 | "one-contract-per-file": "off", 16 | "var-name-mixedcase": "off", 17 | "no-global-import": "off" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/IGetSafes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IGetSafes { 6 | function getSafesAsc( 7 | address manager, 8 | address guy 9 | ) 10 | external 11 | view 12 | virtual 13 | returns (uint256[] memory ids, address[] memory safes, bytes32[] memory collateralTypes); 14 | function getSafesDesc( 15 | address manager, 16 | address guy 17 | ) 18 | external 19 | view 20 | virtual 21 | returns (uint256[] memory ids, address[] memory safes, bytes32[] memory collateralTypes); 22 | } 23 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IDSProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IDSProxy { 6 | // function execute(bytes memory _code, bytes memory _data) 7 | // public 8 | // payable 9 | // virtual 10 | // returns (address, bytes32); 11 | 12 | function execute( 13 | address _target, 14 | bytes memory _data 15 | ) 16 | public 17 | payable 18 | virtual 19 | returns (bytes32); 20 | 21 | function setCache(address _cacheAddr) public payable virtual returns (bool); 22 | 23 | function owner() public view virtual returns (address); 24 | } 25 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579HybridValidatorBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | import { 7 | PackedUserOperation, 8 | _packValidationData as _packValidationData4337 9 | } from "../external/ERC4337.sol"; 10 | import { ERC7579ValidatorBase } from "./ERC7579ValidatorBase.sol"; 11 | import { ERC7579StatelessValidatorBase } from "./ERC7579StatelessValidatorBase.sol"; 12 | 13 | /// @notice Base contract for hybrid validators, which are both stateful and stateless. 14 | abstract contract ERC7579HybridValidatorBase is 15 | ERC7579ValidatorBase, 16 | ERC7579StatelessValidatorBase 17 | { } 18 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IWETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "forge-std/interfaces/IERC20.sol"; 6 | 7 | abstract contract IWETH { 8 | function allowance(address, address) public view virtual returns (uint256); 9 | 10 | function balanceOf(address) public view virtual returns (uint256); 11 | 12 | function approve(address, uint256) public virtual; 13 | 14 | function transfer(address, uint256) public virtual returns (bool); 15 | 16 | function transferFrom(address, address, uint256) public virtual returns (bool); 17 | 18 | function deposit() public payable virtual; 19 | 20 | function withdraw(uint256) public virtual; 21 | } 22 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/ILiquidityGauge.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | pragma experimental ABIEncoderV2; 4 | 5 | interface ILiquidityGauge { 6 | function lp_token() external view returns (address); 7 | function balanceOf(address) external view returns (uint256); 8 | 9 | function deposit(uint256 _amount, address _receiver) external; 10 | function approved_to_deposit( 11 | address _depositor, 12 | address _recipient 13 | ) 14 | external 15 | view 16 | returns (bool); 17 | function set_approve_deposit(address _depositor, bool _canDeposit) external; 18 | 19 | function withdraw(uint256 _amount) external; 20 | } 21 | -------------------------------------------------------------------------------- /src/integrations/interfaces/convex/IBaseRewardPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: SEE LICENSE IN LICENSE 2 | pragma solidity ^0.8.10; 3 | 4 | interface IBaseRewardPool { 5 | function extraRewardsLength() external view returns (uint256); 6 | function extraRewards(uint256) external view returns (address); 7 | 8 | function earned(address) external view returns (uint256); 9 | function balanceOf(address) external view returns (uint256); 10 | 11 | function getReward(address, bool) external returns (bool); 12 | function stakeFor(address, uint256) external; 13 | 14 | function withdraw(uint256, bool) external returns (bool); 15 | function withdrawAndUnwrap(uint256, bool) external returns (bool); 16 | } 17 | -------------------------------------------------------------------------------- /src/integrations/interfaces/insta/IInstaMakerDAOMerkleDistributor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IInstaMakerDAOMerkleDistributor { 5 | function claim( 6 | uint256 index, 7 | uint256 vaultId, 8 | address dsa, 9 | address owner, 10 | uint256 rewardAmount, 11 | uint256 networthAmount, 12 | bytes32[] calldata merkleProof 13 | ) 14 | external; 15 | 16 | function getPosition( 17 | uint256 id, 18 | uint256 rewardAmount, 19 | uint256 networthAmount 20 | ) 21 | external 22 | view 23 | returns (uint256 claimableRewardAmount, uint256 claimableNetworth); 24 | } 25 | -------------------------------------------------------------------------------- /src/integrations/interfaces/yearn/IYVault.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.8.0 <0.9.0; 4 | 5 | interface IYVault { 6 | function withdraw(uint256 _shares) external; 7 | function deposit(uint256 _amount, address _recipient) external; 8 | function token() external view returns (address); 9 | 10 | function totalSupply() external view returns (uint256); 11 | function totalAssets() external view returns (uint256); 12 | function withdrawalQueue(uint256 i) external view returns (address); 13 | 14 | function strategies(address) 15 | external 16 | view 17 | returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256); 18 | } 19 | -------------------------------------------------------------------------------- /src/integrations/interfaces/exchange/IPair.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "../IERC20.sol"; 6 | 7 | abstract contract IPair is IERC20 { 8 | function token0() external view virtual returns (address); 9 | function token1() external view virtual returns (address); 10 | function getReserves() 11 | external 12 | view 13 | virtual 14 | returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 15 | function price0CumulativeLast() external view virtual returns (uint256); 16 | function price1CumulativeLast() external view virtual returns (uint256); 17 | function kLast() external view virtual returns (uint256); 18 | } 19 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IDFSRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IDFSRegistry { 6 | function getAddr(bytes4 _id) public view virtual returns (address); 7 | 8 | function addNewContract( 9 | bytes32 _id, 10 | address _contractAddr, 11 | uint256 _waitPeriod 12 | ) 13 | public 14 | virtual; 15 | 16 | function startContractChange(bytes32 _id, address _newContractAddr) public virtual; 17 | 18 | function approveContractChange(bytes32 _id) public virtual; 19 | 20 | function cancelContractChange(bytes32 _id) public virtual; 21 | 22 | function changeWaitPeriod(bytes32 _id, uint256 _newWaitPeriod) public virtual; 23 | } 24 | -------------------------------------------------------------------------------- /src/integrations/registry/FactoryBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC7484 } from "../../Interfaces.sol"; 6 | 7 | abstract contract FactoryBase { 8 | IERC7484 public immutable REGISTRY; 9 | 10 | address[] public trustedAttesters; 11 | uint8 public threshold; 12 | 13 | constructor(address _registry, address[] memory _trustedAttesters, uint8 _threshold) { 14 | REGISTRY = IERC7484(_registry); 15 | trustedAttesters = _trustedAttesters; 16 | threshold = _threshold; 17 | } 18 | 19 | function _checkRegistry(address module, uint256 moduleType) internal view { 20 | REGISTRY.check(module, moduleType, trustedAttesters, threshold); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IGem.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IGem { 6 | function dec() public virtual returns (uint256); 7 | function gem() public virtual returns (IGem); 8 | function join(address, uint256) public payable virtual; 9 | function exit(address, uint256) public virtual; 10 | 11 | function approve(address, uint256) public virtual; 12 | function transfer(address, uint256) public virtual returns (bool); 13 | function transferFrom(address, address, uint256) public virtual returns (bool); 14 | function deposit() public payable virtual; 15 | function withdraw(uint256) public virtual; 16 | function allowance(address, address) public virtual returns (uint256); 17 | } 18 | -------------------------------------------------------------------------------- /test/GasCalculationsTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "ds-test/test.sol"; 5 | import "src/test/utils/gas/GasCalculations.sol"; 6 | 7 | contract GasCalculationsTest is DSTest { 8 | function test_formatGasValue() public { 9 | uint256 prevValue = 37_054; 10 | uint256 newValue = 187_170; 11 | 12 | string memory result = formatGasValue(prevValue, newValue); 13 | 14 | // Log the result 15 | emit log_named_string("Result", result); 16 | } 17 | 18 | function test_formatGas() public { 19 | int256 value = 2_550_948; 20 | 21 | string memory result = formatGas(value); 22 | 23 | // Log the result 24 | emit log_named_string("Result", result); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/ModuleKit.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | MODULEKIT 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { 11 | UserOpData, 12 | AccountInstance, 13 | RhinestoneModuleKit, 14 | AccountType 15 | } from "./test/RhinestoneModuleKit.sol"; 16 | import { ModuleKitHelpers } from "./test/ModuleKitHelpers.sol"; 17 | 18 | /*////////////////////////////////////////////////////////////// 19 | 4337 20 | ////////////////////////////////////////////////////////////*/ 21 | 22 | import { PackedUserOperation } from "./external/ERC4337.sol"; 23 | -------------------------------------------------------------------------------- /foundry.toml: -------------------------------------------------------------------------------- 1 | [profile.default] 2 | solc_version = "0.8.25" 3 | evm_version = "cancun" 4 | src = "src" 5 | out = "out" 6 | script = "script" 7 | libs = ["node_modules"] 8 | fs_permissions = [{ access = "read", path = "out-optimized" }, { access = "read-write", path = "gas_calculations" }] 9 | allow_paths = ["*", "/"] 10 | ignored_warnings_from = ["node_modules", "src/integrations"] 11 | gas_limit = "18446744073709551615" 12 | memory_limit = 2147483648 13 | verbosity = 3 14 | 15 | [rpc_endpoints] 16 | mainnet = "${MAINNET_RPC_URL}" 17 | testnet = "${TESTNET_RPC_URL}" 18 | 19 | [fmt] 20 | bracket_spacing = true 21 | int_types = "long" 22 | line_length = 100 23 | multiline_func_header = "all" 24 | number_underscore = "thousands" 25 | quote_style = "double" 26 | tab_width = 4 27 | wrap_comments = true 28 | -------------------------------------------------------------------------------- /src/Integrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | ERCs 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { ERC20Integration } from "./integrations/ERC20.sol"; 11 | import { ERC721Integration } from "./integrations/ERC721.sol"; 12 | import { ERC4626Integration } from "./integrations/ERC4626.sol"; 13 | 14 | /*////////////////////////////////////////////////////////////// 15 | UNIV3 16 | //////////////////////////////////////////////////////////////*/ 17 | 18 | import { UniswapV3Integration, SWAPROUTER_ADDRESS } from "./integrations/uniswap/v3/Uniswap.sol"; 19 | -------------------------------------------------------------------------------- /src/deployment/predeploy/MockFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | /* solhint-enable no-unused-import */ 4 | 5 | // Dependencies 6 | import { MockUniswap, ISwapRouter } from "../../integrations/uniswap/MockUniswap.sol"; 7 | import { SWAPROUTER_ADDRESS } from "../../integrations/uniswap/helpers/MainnetAddresses.sol"; 8 | 9 | // Utils 10 | import { etch } from "../../test/utils/Vm.sol"; 11 | 12 | contract MockFactory { 13 | ISwapRouter public uniswap; 14 | 15 | constructor() { 16 | if (SWAPROUTER_ADDRESS.code.length == 0) { 17 | MockUniswap _mockUniswap = new MockUniswap(); 18 | etch(SWAPROUTER_ADDRESS, address(_mockUniswap).code); 19 | uniswap = ISwapRouter(SWAPROUTER_ADDRESS); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/deployment/registry/interfaces/IExternalSchemaValidator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC165 } from "forge-std/interfaces/IERC165.sol"; 6 | 7 | // Types 8 | import { AttestationRecord } from "../types/DataTypes.sol"; 9 | 10 | /** 11 | * @title The interface of an optional schema resolver. 12 | */ 13 | interface IExternalSchemaValidator is IERC165 { 14 | /** 15 | * @notice Validates an attestation request. 16 | */ 17 | function validateSchema(AttestationRecord calldata attestation) external returns (bool); 18 | 19 | /** 20 | * @notice Validates an array of attestation requests. 21 | */ 22 | function validateSchema(AttestationRecord[] calldata attestations) external returns (bool); 23 | } 24 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockFallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579FallbackBase } from "../ERC7579FallbackBase.sol"; 5 | 6 | contract MockFallback is ERC7579FallbackBase { 7 | function onInstall(bytes calldata data) external override { } 8 | 9 | function onUninstall(bytes calldata data) external override { } 10 | 11 | function targetFunction() external pure returns (bool) { 12 | return true; 13 | } 14 | 15 | function isModuleType(uint256 typeID) external pure returns (bool) { 16 | return typeID == TYPE_FALLBACK; 17 | } 18 | 19 | function isInitialized( 20 | address // smartAccount 21 | ) 22 | external 23 | pure 24 | returns (bool) 25 | { 26 | return false; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/utils/Log.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | library ModuleKitLogs { 5 | /* solhint-disable event-name-camelcase */ 6 | event ModuleKit_NewAccount(address account, string accountType); 7 | event ModuleKit_Exec4337(address sender); 8 | 9 | event ModuleKit_AddExecutor(address account, address executor); 10 | event ModuleKit_RemoveExecutor(address account, address executor); 11 | 12 | event ModuleKit_AddValidator(address account, address validator); 13 | event ModuleKit_RemoveValidator(address account, address validator); 14 | 15 | event ModuleKit_SetFallback(address account, bytes4 functionSig, address handler); 16 | 17 | event ModuleKit_SetCondition(address account, address executor); 18 | /* solhint-enable event-name-camelcase */ 19 | } 20 | -------------------------------------------------------------------------------- /src/integrations/interfaces/flashloan/IERC3156FlashBorrower.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IERC3156FlashBorrower { 5 | /** 6 | * @dev Receive a flash loan. 7 | * @param initiator The initiator of the loan. 8 | * @param token The loan currency. 9 | * @param amount The amount of tokens lent. 10 | * @param fee The additional amount of tokens to repay. 11 | * @param data Arbitrary data structure, intended to contain user-defined parameters. 12 | * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan" 13 | */ 14 | function onFlashLoan( 15 | address initiator, 16 | address token, 17 | uint256 amount, 18 | uint256 fee, 19 | bytes calldata data 20 | ) 21 | external 22 | returns (bytes32); 23 | } 24 | -------------------------------------------------------------------------------- /test/BaseTest.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | import "forge-std/Test.sol"; 5 | import "src/ModuleKit.sol"; 6 | import "src/Accounts.sol"; 7 | import "src/Mocks.sol"; 8 | import { Execution } from "src/accounts/erc7579/lib/ExecutionLib.sol"; 9 | 10 | contract BaseTest is RhinestoneModuleKit, Test { 11 | using ModuleKitHelpers for AccountInstance; 12 | 13 | AccountInstance internal instance; 14 | AccountInstance internal instanceSafe; 15 | 16 | address recipient; 17 | 18 | function setUp() public virtual { 19 | instance = makeAccountInstance("account1"); 20 | 21 | // MockValidator defaultValidator = new MockValidator(); 22 | // MockExecutor defaultExecutor = new MockExecutor(); 23 | vm.deal(instanceSafe.account, 1000 ether); 24 | vm.deal(instance.account, 2 ether); 25 | 26 | recipient = makeAddr("recipient"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/integrations/interfaces/balancer/IFlashLoanRecipient.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IFlashLoanRecipient { 5 | /** 6 | * @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the 7 | * recipient. 8 | * 9 | * At the time of the call, the Vault will have transferred `amounts` for `tokens` to the 10 | * recipient. Before this 11 | * call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token 12 | * back to the 13 | * Vault, or else the entire flash loan will revert. 14 | * 15 | * `userData` is the same value passed in the `IVault.flashLoan` call. 16 | */ 17 | function receiveFlashLoan( 18 | address[] memory tokens, 19 | uint256[] memory amounts, 20 | uint256[] memory feeAmounts, 21 | bytes memory userData 22 | ) 23 | external; 24 | } 25 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockStatelessValidator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579StatelessValidatorBase } from "../ERC7579StatelessValidatorBase.sol"; 5 | 6 | contract MockStatelessValidator is ERC7579StatelessValidatorBase { 7 | function onInstall(bytes calldata data) external virtual { } 8 | 9 | function onUninstall(bytes calldata data) external virtual { } 10 | 11 | function isModuleType(uint256 typeID) external pure returns (bool) { 12 | return typeID == 7; 13 | } 14 | 15 | function isInitialized(address) external pure returns (bool) { 16 | return true; 17 | } 18 | 19 | function validateSignatureWithData( 20 | bytes32, 21 | bytes calldata, 22 | bytes calldata 23 | ) 24 | external 25 | pure 26 | override 27 | returns (bool validSig) 28 | { 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/module-bases/interfaces/IERC1271.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | // bytes4(keccak256("isValidSignature(bytes32,bytes)") 5 | bytes4 constant EIP1271_MAGIC_VALUE = 0x1626ba7e; 6 | 7 | interface IERC1271 { 8 | /** 9 | * @dev Should return whether the signature provided is valid for the provided data 10 | * @param _dataHash Arbitrary length data signed on behalf of address(this) 11 | * @param _signature Signature byte array associated with _data 12 | * 13 | * MUST return the bytes4 magic value 0x1626ba7e when function passes. 14 | * MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 15 | * 0.5) 16 | * MUST allow external calls 17 | */ 18 | function isValidSignature( 19 | bytes32 _dataHash, 20 | bytes calldata _signature 21 | ) 22 | external 23 | view 24 | returns (bytes4); 25 | } 26 | -------------------------------------------------------------------------------- /src/accounts/factory/template/FactoryTemplate.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | abstract contract FactoryTemplate { 5 | constructor() { 6 | // Deploy any required contracts 7 | } 8 | 9 | function createAccountName( 10 | bytes32 salt, 11 | bytes memory initCode 12 | ) 13 | public 14 | returns (address account) 15 | { 16 | // Deploy the account 17 | } 18 | 19 | function getAddressAccountName( 20 | bytes32 salt, 21 | bytes memory initCode 22 | ) 23 | public 24 | view 25 | returns (address) 26 | { 27 | // Return the address of the account 28 | } 29 | 30 | function getInitDataAccountName( 31 | address validator, 32 | bytes memory initData 33 | ) 34 | public 35 | returns (bytes memory init) 36 | { 37 | // Return the init data 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IERC721 { 6 | function balanceOf(address owner) external view returns (uint256 balance); 7 | function ownerOf(uint256 tokenId) external view returns (address owner); 8 | function safeTransferFrom( 9 | address from, 10 | address to, 11 | uint256 tokenId, 12 | bytes calldata data 13 | ) 14 | external; 15 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 16 | function transferFrom(address from, address to, uint256 tokenId) external; 17 | function approve(address to, uint256 tokenId) external; 18 | function setApprovalForAll(address operator, bool _approved) external; 19 | function getApproved(uint256 tokenId) external view returns (address operator); 20 | function isApprovedForAll(address owner, address operator) external view returns (bool); 21 | } 22 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV3/IPriceOracleGetter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.10; 3 | 4 | interface IPriceOracleGetter { 5 | /** 6 | * @notice Returns the base currency address 7 | * @dev Address 0x0 is reserved for USD as base currency. 8 | * @return Returns the base currency address. 9 | * 10 | */ 11 | function BASE_CURRENCY() external view returns (address); 12 | 13 | /** 14 | * @notice Returns the base currency unit 15 | * @dev 1 ether for ETH, 1e8 for USD. 16 | * @return Returns the base currency unit. 17 | * 18 | */ 19 | function BASE_CURRENCY_UNIT() external view returns (uint256); 20 | 21 | /** 22 | * @notice Returns the asset price in the base currency 23 | * @param asset The address of the asset 24 | * @return The price of the asset 25 | * 26 | */ 27 | function getAssetPrice(address asset) external view returns (uint256); 28 | } 29 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/ICurveFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ICurveFactoryLP { 5 | function minter() external view returns (address); 6 | function name() external view returns (string memory); 7 | } 8 | 9 | interface ICurveFactoryPool { 10 | function token() external view returns (address); 11 | function factory() external view returns (address); 12 | function get_virtual_price() external view returns (uint256); 13 | } 14 | 15 | interface ICurveFactory { 16 | function get_coins(address) external view returns (address[2] memory); 17 | function get_decimals(address) external view returns (uint256[2] memory); 18 | function get_balances(address) external view returns (uint256[2] memory); 19 | function get_gauge(address) external view returns (address); 20 | } 21 | 22 | interface IGaugeController { 23 | function gauge_types(address) external view returns (int128); 24 | } 25 | -------------------------------------------------------------------------------- /src/integrations/interfaces/compoundV3/ICometRewards.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ICometRewards { 6 | struct RewardConfig { 7 | address token; 8 | uint64 rescaleFactor; 9 | bool shouldUpscale; 10 | } 11 | 12 | struct RewardOwed { 13 | address token; 14 | uint256 owed; 15 | } 16 | 17 | function rewardConfig(address) external virtual returns (RewardConfig memory); 18 | 19 | function claimTo(address comet, address src, address to, bool shouldAccrue) external virtual; 20 | 21 | function rewardsClaimed( 22 | address _market, 23 | address _user 24 | ) 25 | external 26 | view 27 | virtual 28 | returns (uint256); 29 | function getRewardOwed( 30 | address _market, 31 | address _user 32 | ) 33 | external 34 | virtual 35 | returns (RewardOwed memory); 36 | } 37 | -------------------------------------------------------------------------------- /src/accounts/kernel/interfaces/IAccountExecute.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Types 5 | import { PackedUserOperation } from 6 | "@ERC4337/account-abstraction/contracts/core/UserOperationLib.sol"; 7 | 8 | interface IAccountExecute { 9 | /** 10 | * Account may implement this execute method. 11 | * passing this methodSig at the beginning of callData will cause the entryPoint to pass the 12 | * full UserOp (and hash) 13 | * to the account. 14 | * The account should skip the methodSig, and use the callData (and optionally, other UserOp 15 | * fields) 16 | * 17 | * @param userOp - The operation that was just validated. 18 | * @param userOpHash - Hash of the user's request data. 19 | */ 20 | function executeUserOp( 21 | PackedUserOperation calldata userOp, 22 | bytes32 userOpHash 23 | ) 24 | external 25 | payable; 26 | } 27 | -------------------------------------------------------------------------------- /src/accounts/safe/interfaces/ISafeProxyFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface ISafeProxyFactory { 5 | function proxyCreationCode() external pure returns (bytes memory); 6 | 7 | function createProxyWithNonce( 8 | address _singleton, 9 | bytes memory initializer, 10 | uint256 saltNonce 11 | ) 12 | external 13 | returns (address proxy); 14 | 15 | function createChainSpecificProxyWithNonce( 16 | address _singleton, 17 | bytes memory initializer, 18 | uint256 saltNonce 19 | ) 20 | external 21 | returns (address proxy); 22 | 23 | function createProxyWithCallback( 24 | address _singleton, 25 | bytes memory initializer, 26 | uint256 saltNonce, 27 | address callback 28 | ) 29 | external 30 | returns (address proxy); 31 | 32 | function getChainId() external view returns (uint256); 33 | } 34 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockHook.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579HookBase } from "../ERC7579HookBase.sol"; 5 | 6 | contract MockHook is ERC7579HookBase { 7 | function onInstall(bytes calldata data) external override { } 8 | 9 | function onUninstall(bytes calldata data) external override { } 10 | 11 | function _preCheck( 12 | address account, 13 | address msgSender, 14 | uint256 msgValue, 15 | bytes calldata msgData 16 | ) 17 | internal 18 | override 19 | returns (bytes memory hookData) 20 | { } 21 | function _postCheck(address account, bytes calldata hookData) internal override { } 22 | 23 | function isInitialized( 24 | address // smartAccount 25 | ) 26 | external 27 | pure 28 | returns (bool) 29 | { 30 | return false; 31 | } 32 | 33 | function isModuleType(uint256 typeID) external pure returns (bool) { 34 | return typeID == TYPE_HOOK; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579ModuleBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { IModule as IERC7579Module } from "../accounts/common/interfaces/IERC7579Module.sol"; 5 | import { 6 | MODULE_TYPE_VALIDATOR, 7 | MODULE_TYPE_EXECUTOR, 8 | MODULE_TYPE_FALLBACK, 9 | MODULE_TYPE_HOOK, 10 | MODULE_TYPE_POLICY, 11 | MODULE_TYPE_SIGNER, 12 | MODULE_TYPE_STATELESS_VALIDATOR 13 | } from "./utils/ERC7579Constants.sol"; 14 | 15 | abstract contract ERC7579ModuleBase is IERC7579Module { 16 | uint256 internal constant TYPE_VALIDATOR = MODULE_TYPE_VALIDATOR; 17 | uint256 internal constant TYPE_EXECUTOR = MODULE_TYPE_EXECUTOR; 18 | uint256 internal constant TYPE_FALLBACK = MODULE_TYPE_FALLBACK; 19 | uint256 internal constant TYPE_HOOK = MODULE_TYPE_HOOK; 20 | uint256 internal constant TYPE_POLICY = MODULE_TYPE_POLICY; 21 | uint256 internal constant TYPE_SIGNER = MODULE_TYPE_SIGNER; 22 | uint256 internal constant TYPE_STATELESS_VALIDATOR = MODULE_TYPE_STATELESS_VALIDATOR; 23 | } 24 | -------------------------------------------------------------------------------- /src/integrations/interfaces/exchange/IExchangeV3.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IExchangeV3 { 6 | function sell( 7 | address _srcAddr, 8 | address _destAddr, 9 | uint256 _srcAmount, 10 | bytes memory _additionalData 11 | ) 12 | external 13 | returns (uint256); 14 | 15 | function buy( 16 | address _srcAddr, 17 | address _destAddr, 18 | uint256 _destAmount, 19 | bytes memory _additionalData 20 | ) 21 | external 22 | returns (uint256); 23 | 24 | function getSellRate( 25 | address _srcAddr, 26 | address _destAddr, 27 | uint256 _srcAmount, 28 | bytes memory _additionalData 29 | ) 30 | external 31 | returns (uint256); 32 | 33 | function getBuyRate( 34 | address _srcAddr, 35 | address _destAddr, 36 | uint256 _srcAmount, 37 | bytes memory _additionalData 38 | ) 39 | external 40 | returns (uint256); 41 | } 42 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/IHintHelpers.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IHintHelpers { 6 | function getRedemptionHints( 7 | uint256 _LUSDamount, 8 | uint256 _price, 9 | uint256 _maxIterations 10 | ) 11 | external 12 | view 13 | returns ( 14 | address firstRedemptionHint, 15 | uint256 partialRedemptionHintNICR, 16 | uint256 truncatedLUSDamount 17 | ); 18 | 19 | function getApproxHint( 20 | uint256 _CR, 21 | uint256 _numTrials, 22 | uint256 _inputRandomSeed 23 | ) 24 | external 25 | view 26 | returns (address hintAddress, uint256 diff, uint256 latestRandomSeed); 27 | 28 | function computeNominalCR(uint256 _coll, uint256 _debt) external pure returns (uint256); 29 | 30 | function computeCR( 31 | uint256 _coll, 32 | uint256 _debt, 33 | uint256 _price 34 | ) 35 | external 36 | pure 37 | returns (uint256); 38 | } 39 | -------------------------------------------------------------------------------- /src/accounts/factory/interface/IAccountFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface IAccountFactory { 5 | struct ModuleInitData { 6 | address module; 7 | bytes data; 8 | } 9 | 10 | function init() external; 11 | 12 | function createAccount( 13 | bytes32 salt, 14 | bytes memory initCode 15 | ) 16 | external 17 | returns (address account); 18 | 19 | function getAddress(bytes32 salt, bytes memory initCode) external returns (address); 20 | 21 | function getInitData( 22 | address validator, 23 | bytes memory initData 24 | ) 25 | external 26 | returns (bytes memory init); 27 | 28 | function getInitData( 29 | IAccountFactory.ModuleInitData[] memory validators, 30 | IAccountFactory.ModuleInitData[] memory executors, 31 | IAccountFactory.ModuleInitData memory hook, 32 | IAccountFactory.ModuleInitData[] memory fallbacks 33 | ) 34 | external 35 | returns (bytes memory _init); 36 | } 37 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/ICollSurplusPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ICollSurplusPool { 5 | // --- Events --- 6 | 7 | event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress); 8 | event TroveManagerAddressChanged(address _newTroveManagerAddress); 9 | event ActivePoolAddressChanged(address _newActivePoolAddress); 10 | 11 | event CollBalanceUpdated(address indexed _account, uint256 _newBalance); 12 | event EtherSent(address _to, uint256 _amount); 13 | 14 | // --- Contract setters --- 15 | 16 | function setAddresses( 17 | address _borrowerOperationsAddress, 18 | address _troveManagerAddress, 19 | address _activePoolAddress 20 | ) 21 | external; 22 | 23 | function getETH() external view returns (uint256); 24 | 25 | function getCollateral(address _account) external view returns (uint256); 26 | 27 | function accountSurplus(address _account, uint256 _amount) external; 28 | 29 | function claimColl(address _account) external; 30 | } 31 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IERC20 { 6 | function name() external view returns (string memory); 7 | function symbol() external view returns (string memory); 8 | function decimals() external view returns (uint256 digits); 9 | function totalSupply() external view returns (uint256 supply); 10 | 11 | function balanceOf(address _owner) external view returns (uint256 balance); 12 | 13 | function transfer(address _to, uint256 _value) external returns (bool success); 14 | 15 | function transferFrom( 16 | address _from, 17 | address _to, 18 | uint256 _value 19 | ) 20 | external 21 | returns (bool success); 22 | 23 | function approve(address _spender, uint256 _value) external returns (bool success); 24 | 25 | function allowance( 26 | address _owner, 27 | address _spender 28 | ) 29 | external 30 | view 31 | returns (uint256 remaining); 32 | 33 | event Approval(address indexed _owner, address indexed _spender, uint256 _value); 34 | } 35 | -------------------------------------------------------------------------------- /src/integrations/interfaces/exchange/IOasis.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IOasis { 6 | function getBuyAmount( 7 | address tokenToBuy, 8 | address tokenToPay, 9 | uint256 amountToPay 10 | ) 11 | external 12 | view 13 | virtual 14 | returns (uint256 amountBought); 15 | 16 | function getPayAmount( 17 | address tokenToPay, 18 | address tokenToBuy, 19 | uint256 amountToBuy 20 | ) 21 | public 22 | view 23 | virtual 24 | returns (uint256 amountPaid); 25 | 26 | function sellAllAmount( 27 | address pay_gem, 28 | uint256 pay_amt, 29 | address buy_gem, 30 | uint256 min_fill_amount 31 | ) 32 | public 33 | virtual 34 | returns (uint256 fill_amt); 35 | 36 | function buyAllAmount( 37 | address buy_gem, 38 | uint256 buy_amt, 39 | address pay_gem, 40 | uint256 max_fill_amount 41 | ) 42 | public 43 | virtual 44 | returns (uint256 fill_amt); 45 | } 46 | -------------------------------------------------------------------------------- /src/integrations/interfaces/IERC4626.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "./IERC20.sol"; 5 | 6 | interface IERC4626 is IERC20 { 7 | function deposit(uint256 _assets, address _receiver) external returns (uint256 shares); 8 | function mint(uint256 _shares, address _receiver) external returns (uint256 assets); 9 | function withdraw( 10 | uint256 _assets, 11 | address _receiver, 12 | address _owner 13 | ) 14 | external 15 | returns (uint256 shares); 16 | function redeem( 17 | uint256 _shares, 18 | address _receiver, 19 | address _owner 20 | ) 21 | external 22 | returns (uint256 assets); 23 | 24 | function previewDeposit(uint256 _assets) external view returns (uint256 shares); 25 | function previewMint(uint256 _shares) external view returns (uint256 assets); 26 | function previewWithdraw(uint256 _assets) external view returns (uint256 shares); 27 | function previewRedeem(uint256 _shares) external view returns (uint256 assets); 28 | 29 | function asset() external view returns (address); 30 | } 31 | -------------------------------------------------------------------------------- /src/integrations/interfaces/exchange/IExchangeWrapper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface IExchangeWrapper { 6 | function sell( 7 | address _srcAddr, 8 | address _destAddr, 9 | uint256 _srcAmount, 10 | bytes memory _additionalData 11 | ) 12 | external 13 | payable 14 | returns (uint256); 15 | 16 | function buy( 17 | address _srcAddr, 18 | address _destAddr, 19 | uint256 _destAmount, 20 | bytes memory _additionalData 21 | ) 22 | external 23 | payable 24 | returns (uint256); 25 | 26 | function getSellRate( 27 | address _srcAddr, 28 | address _destAddr, 29 | uint256 _srcAmount, 30 | bytes memory _additionalData 31 | ) 32 | external 33 | view 34 | returns (uint256); 35 | 36 | function getBuyRate( 37 | address _srcAddr, 38 | address _destAddr, 39 | uint256 _srcAmount, 40 | bytes memory _additionalData 41 | ) 42 | external 43 | view 44 | returns (uint256); 45 | } 46 | -------------------------------------------------------------------------------- /src/accounts/kernel/interfaces/IValidationManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IHook, ISigner } from "../../../accounts/common/interfaces/IERC7579Module.sol"; 6 | 7 | // Types 8 | import { PassFlag, PolicyData, ValidationId, PermissionId } from "../lib/ValidationTypeLib.sol"; 9 | 10 | // erc7579 plugins 11 | struct ValidationConfig { 12 | uint32 nonce; // 4 bytes 13 | IHook hook; // 20 bytes address(1) : hook not required, address(0) : validator not installed 14 | } 15 | 16 | struct PermissionConfig { 17 | PassFlag permissionFlag; 18 | ISigner signer; 19 | PolicyData[] policyData; 20 | } 21 | 22 | struct ValidationStorage { 23 | ValidationId rootValidator; 24 | uint32 currentNonce; 25 | uint32 validNonceFrom; 26 | mapping(ValidationId => ValidationConfig) validationConfig; 27 | mapping(ValidationId => mapping(bytes4 => bool)) allowedSelectors; 28 | // validation = validator | permission 29 | // validator == 1 validator 30 | // permission == 1 signer + N policies 31 | mapping(PermissionId => PermissionConfig) permissionConfig; 32 | } 33 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockExecutor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579ExecutorBase } from "../ERC7579ExecutorBase.sol"; 5 | // solhint-disable-next-line no-unused-import 6 | import { IERC7579Account } from "../../accounts/common/interfaces/IERC7579Account.sol"; 7 | 8 | contract MockExecutor is ERC7579ExecutorBase { 9 | function onInstall(bytes calldata data) external override { } 10 | 11 | function onUninstall(bytes calldata data) external override { } 12 | 13 | function exec( 14 | address account, 15 | address to, 16 | uint256 value, 17 | bytes calldata callData 18 | ) 19 | external 20 | returns (bytes memory) 21 | { 22 | return _execute(account, to, value, callData); 23 | } 24 | 25 | function isModuleType(uint256 typeID) external pure override returns (bool) { 26 | return typeID == TYPE_EXECUTOR; 27 | } 28 | 29 | function isInitialized( 30 | address // smartAccount 31 | ) 32 | external 33 | pure 34 | returns (bool) 35 | { 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/integrations/interfaces/balancer/IVault.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | pragma experimental ABIEncoderV2; 5 | 6 | interface IAsset { } 7 | 8 | interface IVault { 9 | function joinPool( 10 | bytes32 poolId, 11 | address sender, 12 | address recipient, 13 | JoinPoolRequest memory request 14 | ) 15 | external 16 | payable; 17 | 18 | struct JoinPoolRequest { 19 | IAsset[] assets; 20 | uint256[] maxAmountsIn; 21 | bytes userData; 22 | bool fromInternalBalance; 23 | } 24 | 25 | function exitPool( 26 | bytes32 poolId, 27 | address sender, 28 | address payable recipient, 29 | ExitPoolRequest memory request 30 | ) 31 | external; 32 | 33 | struct ExitPoolRequest { 34 | IAsset[] assets; 35 | uint256[] minAmountsOut; 36 | bytes userData; 37 | bool toInternalBalance; 38 | } 39 | 40 | function getPoolTokens(bytes32 poolId) 41 | external 42 | view 43 | returns (address[] memory tokens, uint256[] memory balances, uint256 lastChangeBlock); 44 | } 45 | -------------------------------------------------------------------------------- /src/integrations/ERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC721 } from "forge-std/interfaces/IERC721.sol"; 6 | 7 | // Types 8 | import { Execution } from "../accounts/erc7579/lib/ExecutionLib.sol"; 9 | 10 | library ERC721Integration { 11 | function approve( 12 | IERC721 token, 13 | address spender, 14 | uint256 tokenId 15 | ) 16 | internal 17 | pure 18 | returns (Execution memory exec) 19 | { 20 | exec = Execution({ 21 | target: address(token), 22 | value: 0, 23 | callData: abi.encodeCall(IERC721.approve, (spender, tokenId)) 24 | }); 25 | } 26 | 27 | function transferFrom( 28 | IERC721 token, 29 | address from, 30 | address to, 31 | uint256 tokenId 32 | ) 33 | internal 34 | pure 35 | returns (Execution memory exec) 36 | { 37 | exec = Execution({ 38 | target: address(token), 39 | value: 0, 40 | callData: abi.encodeCall(IERC721.transferFrom, (from, to, tokenId)) 41 | }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Accounts.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | COMMON 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { IERC7579Account } from "./accounts/common/interfaces/IERC7579Account.sol"; 11 | 12 | /*////////////////////////////////////////////////////////////// 13 | 7579 REFERENCE 14 | //////////////////////////////////////////////////////////////*/ 15 | 16 | import { IMSA } from "./accounts/erc7579/interfaces/IMSA.sol"; 17 | 18 | /*////////////////////////////////////////////////////////////// 19 | KERNEL 20 | //////////////////////////////////////////////////////////////*/ 21 | 22 | import { IERC7579Account as IKernelAccount } from "./accounts/kernel/interfaces/IERC7579Account.sol"; 23 | 24 | /*////////////////////////////////////////////////////////////// 25 | SAFE 26 | //////////////////////////////////////////////////////////////*/ 27 | 28 | import { ISafe7579 } from "./accounts/safe/interfaces/ISafe7579.sol"; 29 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IManager { 6 | function last(address) public virtual returns (uint256); 7 | function cdpCan(address, uint256, address) public view virtual returns (uint256); 8 | function ilks(uint256) public view virtual returns (bytes32); 9 | function owns(uint256) public view virtual returns (address); 10 | function urns(uint256) public view virtual returns (address); 11 | function vat() public view virtual returns (address); 12 | function open(bytes32, address) public virtual returns (uint256); 13 | function give(uint256, address) public virtual; 14 | function cdpAllow(uint256, address, uint256) public virtual; 15 | function urnAllow(address, uint256) public virtual; 16 | function frob(uint256, int256, int256) public virtual; 17 | function flux(uint256, address, uint256) public virtual; 18 | function move(uint256, address, uint256) public virtual; 19 | function exit(address, uint256, address, uint256) public virtual; 20 | function quit(uint256, address) public virtual; 21 | function enter(address, uint256) public virtual; 22 | function shift(uint256, uint256) public virtual; 23 | } 24 | -------------------------------------------------------------------------------- /src/accounts/erc7579/interfaces/IERC7579Bootstrap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IModule } from "../../common/interfaces/IERC7579Module.sol"; 6 | 7 | // Structs 8 | struct BootstrapConfig { 9 | address module; 10 | bytes data; 11 | } 12 | 13 | interface IERC7579Bootstrap { 14 | function singleInitMSA(IModule validator, bytes calldata data) external; 15 | 16 | /** 17 | * This function is intended to be called by the MSA with a delegatecall. 18 | * Make sure that the MSA already initilazed the linked lists in the ModuleManager prior to 19 | * calling this function 20 | */ 21 | function initMSA( 22 | BootstrapConfig[] calldata $valdiators, 23 | BootstrapConfig[] calldata $executors, 24 | BootstrapConfig calldata _hook, 25 | BootstrapConfig[] calldata _fallbacks 26 | ) 27 | external; 28 | 29 | function _getInitMSACalldata( 30 | BootstrapConfig[] calldata $valdiators, 31 | BootstrapConfig[] calldata $executors, 32 | BootstrapConfig calldata _hook, 33 | BootstrapConfig[] calldata _fallbacks 34 | ) 35 | external 36 | view 37 | returns (bytes memory init); 38 | } 39 | -------------------------------------------------------------------------------- /src/integrations/interfaces/curve/IRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IRegistry { 5 | function get_lp_token(address) external view returns (address); 6 | function get_pool_from_lp_token(address) external view returns (address); 7 | function get_pool_name(address) external view returns (string memory); 8 | function get_coins(address) external view returns (address[8] memory); 9 | function get_n_coins(address) external view returns (uint256[2] memory); 10 | function get_underlying_coins(address) external view returns (address[8] memory); 11 | function get_decimals(address) external view returns (uint256[8] memory); 12 | function get_underlying_decimals(address) external view returns (uint256[8] memory); 13 | function get_balances(address) external view returns (uint256[8] memory); 14 | function get_underlying_balances(address) external view returns (uint256[8] memory); 15 | function get_virtual_price_from_lp_token(address) external view returns (uint256); 16 | function get_gauges(address) external view returns (address[10] memory, int128[10] memory); 17 | function pool_count() external view returns (uint256); 18 | function pool_list(uint256) external view returns (address); 19 | } 20 | -------------------------------------------------------------------------------- /src/integrations/interfaces/guni/IGUniRouter02.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | pragma solidity ^0.8.10; 3 | pragma abicoder v2; 4 | 5 | interface IGUniRouter02 { 6 | function removeLiquidity( 7 | address pool, 8 | uint256 burnAmount, 9 | uint256 amount0Min, 10 | uint256 amount1Min, 11 | address receiver 12 | ) 13 | external 14 | returns (uint256 amount0, uint256 amount1, uint128 liquidityBurned); 15 | 16 | function rebalanceAndAddLiquidity( 17 | address pool, 18 | uint256 amount0In, 19 | uint256 amount1In, 20 | uint256 amountSwap, 21 | bool zeroForOne, 22 | address[] memory swapActions, 23 | bytes[] memory swapDatas, 24 | uint256 amount0Min, 25 | uint256 amount1Min, 26 | address receiver 27 | ) 28 | external 29 | returns (uint256 amount0, uint256 amount1, uint256 mintAmount); 30 | 31 | function addLiquidity( 32 | address pool, 33 | uint256 amount0Max, 34 | uint256 amount1Max, 35 | uint256 amount0Min, 36 | uint256 amount1Min, 37 | address receiver 38 | ) 39 | external 40 | returns (uint256 amount0, uint256 amount1, uint256 mintAmount); 41 | } 42 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mcd/IVat.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IVat { 6 | struct Urn { 7 | uint256 ink; // Locked Collateral [wad] 8 | uint256 art; // Normalised Debt [wad] 9 | } 10 | 11 | struct Ilk { 12 | uint256 Art; // Total Normalised Debt [wad] 13 | uint256 rate; // Accumulated Rates [ray] 14 | uint256 spot; // Price with Safety Margin [ray] 15 | uint256 line; // Debt Ceiling [rad] 16 | uint256 dust; // Urn Debt Floor [rad] 17 | } 18 | 19 | mapping(bytes32 => mapping(address => Urn)) public urns; 20 | mapping(bytes32 => Ilk) public ilks; 21 | mapping(bytes32 => mapping(address => uint256)) public gem; // [wad] 22 | 23 | function can(address, address) public view virtual returns (uint256); 24 | function dai(address) public view virtual returns (uint256); 25 | function frob(bytes32, address, address, address, int256, int256) public virtual; 26 | function hope(address) public virtual; 27 | function nope(address) public virtual; 28 | function move(address, address, uint256) public virtual; 29 | function fork(bytes32, address, address, int256, int256) public virtual; 30 | } 31 | -------------------------------------------------------------------------------- /src/Interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | ERCs/EIPs 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { IERC1271, EIP1271_MAGIC_VALUE } from "./module-bases/interfaces/IERC1271.sol"; 11 | import { IERC7484 } from "./module-bases/interfaces/IERC7484.sol"; 12 | import { 13 | IERC6682, 14 | IERC3156FlashLender, 15 | IERC3156FlashBorrower 16 | } from "./module-bases/interfaces/Flashloan.sol"; 17 | import { IERC712 } from "./module-bases/interfaces/IERC712.sol"; 18 | 19 | /*////////////////////////////////////////////////////////////// 20 | MODULES 21 | //////////////////////////////////////////////////////////////*/ 22 | 23 | import { IStatelessValidator } from "./module-bases/interfaces/IStatelessValidator.sol"; 24 | import { IPolicy } from "./module-bases/interfaces/IPolicy.sol"; 25 | 26 | /*////////////////////////////////////////////////////////////// 27 | TYPES 28 | //////////////////////////////////////////////////////////////*/ 29 | 30 | import { FlashLoanType } from "./module-bases/interfaces/Flashloan.sol"; 31 | -------------------------------------------------------------------------------- /src/accounts/nexus/interfaces/INexusAccountFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface INexusAccountFactory { 5 | /// @notice Creates a new Nexus account with the provided initialization data. 6 | /// @param initData Initialization data to be called on the new Smart Account. 7 | /// @param salt Unique salt for the Smart Account creation. 8 | /// @return The address of the newly created Nexus account. 9 | function createAccount( 10 | bytes calldata initData, 11 | bytes32 salt 12 | ) 13 | external 14 | payable 15 | returns (address payable); 16 | 17 | /// @notice Computes the expected address of a Nexus contract using the factory's deterministic 18 | /// deployment algorithm. 19 | /// @param initData Initialization data to be called on the new Smart Account. 20 | /// @param salt Unique salt for the Smart Account creation. 21 | /// @return expectedAddress The expected address at which the Nexus contract will be deployed if 22 | /// the provided parameters are used. 23 | function computeAccountAddress( 24 | bytes calldata initData, 25 | bytes32 salt 26 | ) 27 | external 28 | view 29 | returns (address payable expectedAddress); 30 | } 31 | -------------------------------------------------------------------------------- /src/deployment/precompiles/BytecodeDeployer.sol: -------------------------------------------------------------------------------- 1 | // // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /// @dev Deploys contracts using CREATE and CREATE2 5 | contract BytecodeDeployer { 6 | /// @notice Deploys a contract using CREATE, reverts on failure 7 | function _deploy(bytes memory creationBytecode) internal returns (address contractAddress) { 8 | // solhint-disable-next-line no-inline-assembly 9 | assembly { 10 | contractAddress := create(0, add(creationBytecode, 0x20), mload(creationBytecode)) 11 | } 12 | // solhint-disable-next-line gas-custom-errors 13 | require(contractAddress != address(0), "Deployer: deployment failed"); 14 | } 15 | 16 | /// @notice Deploys a contract using CREATE2, reverts on failure 17 | function _deploy2( 18 | bytes memory creationBytecode, 19 | bytes32 salt 20 | ) 21 | internal 22 | returns (address contractAddress) 23 | { 24 | // solhint-disable-next-line no-inline-assembly 25 | assembly { 26 | contractAddress := 27 | create2(0, add(creationBytecode, 0x20), mload(creationBytecode), salt) 28 | } 29 | // solhint-disable-next-line gas-custom-errors 30 | require(contractAddress != address(0), "Deployer: deployment failed"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579FallbackBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { IFallback as IERC7579Fallback } from "../accounts/common/interfaces/IERC7579Module.sol"; 5 | import { ERC7579ModuleBase } from "./ERC7579ModuleBase.sol"; 6 | 7 | abstract contract ERC7579FallbackBase is IERC7579Fallback, ERC7579ModuleBase { 8 | /** 9 | * @notice Allows fetching the original caller address. 10 | * @dev This is only reliable in combination with a FallbackManager that supports this (e.g. Safe 11 | * contract >=1.3.0). 12 | * When using this functionality make sure that the linked _manager (aka msg.sender) 13 | * supports this. 14 | * This function does not rely on a trusted forwarder. Use the returned value only to 15 | * check information against the calling manager. 16 | * @return sender Original caller address. 17 | */ 18 | function _msgSender() internal pure returns (address sender) { 19 | // The assembly code is more direct than the Solidity version using `abi.decode`. 20 | /* solhint-disable no-inline-assembly */ 21 | /// @solidity memory-safe-assembly 22 | assembly { 23 | sender := shr(96, calldataload(sub(calldatasize(), 20))) 24 | } 25 | /* solhint-enable no-inline-assembly */ 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/accounts/erc7579/interfaces/IMSA.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC7579Account } from "../../common/interfaces/IERC7579Account.sol"; 6 | import { IERC4337Account } from "../../common/interfaces/IERC4337Account.sol"; 7 | 8 | // Types 9 | import { CallType, ExecType } from "../../common/lib/ModeLib.sol"; 10 | 11 | interface IMSA is IERC7579Account, IERC4337Account { 12 | // Error thrown when an unsupported ModuleType is requested 13 | error UnsupportedModuleType(uint256 moduleTypeId); 14 | // Error thrown when an execution with an unsupported CallType was made 15 | error UnsupportedCallType(CallType callType); 16 | // Error thrown when an execution with an unsupported ExecType was made 17 | error UnsupportedExecType(ExecType execType); 18 | // Error thrown when account initialization fails 19 | error AccountInitializationFailed(); 20 | // Error thrown when account installs/unistalls module with mismatched input `moduleTypeId` 21 | error MismatchModuleTypeId(uint256 moduleTypeId); 22 | 23 | /** 24 | * @dev Initializes the account. Function might be called directly, or by a Factory 25 | * @param data. encoded data that can be used during the initialization phase 26 | */ 27 | function initializeAccount(bytes calldata data) external payable; 28 | } 29 | -------------------------------------------------------------------------------- /src/integrations/uniswap/MockUniswap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { ISwapRouter } from "../interfaces/uniswap/v3/ISwapRouter.sol"; 6 | 7 | contract MockUniswap is ISwapRouter { 8 | function uniswapV3SwapCallback( 9 | int256 amount0Delta, 10 | int256 amount1Delta, 11 | bytes calldata data 12 | ) 13 | external 14 | override 15 | { } 16 | 17 | function exactInputSingle(ExactInputSingleParams calldata params) 18 | external 19 | payable 20 | override 21 | returns (uint256 amountOut) 22 | { 23 | return params.amountIn; 24 | } 25 | 26 | function exactInput(ExactInputParams calldata params) 27 | external 28 | payable 29 | override 30 | returns (uint256 amountOut) 31 | { 32 | return params.amountIn; 33 | } 34 | 35 | function exactOutputSingle(ExactOutputSingleParams calldata params) 36 | external 37 | payable 38 | override 39 | returns (uint256 amountIn) 40 | { 41 | return params.amountOut; 42 | } 43 | 44 | function exactOutput(ExactOutputParams calldata params) 45 | external 46 | payable 47 | override 48 | returns (uint256 amountIn) 49 | { 50 | return params.amountOut; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/integrations/interfaces/flashloan/IERC3156FlashLender.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "./IERC3156FlashBorrower.sol"; 5 | 6 | interface IERC3156FlashLender { 7 | /** 8 | * @dev The amount of currency available to be lent. 9 | * @param token The loan currency. 10 | * @return The amount of `token` that can be borrowed. 11 | */ 12 | function maxFlashLoan(address token) external view returns (uint256); 13 | 14 | /** 15 | * @dev The fee to be charged for a given loan. 16 | * @param token The loan currency. 17 | * @param amount The amount of tokens lent. 18 | * @return The amount of `token` to be charged for the loan, on top of the returned principal. 19 | */ 20 | function flashFee(address token, uint256 amount) external view returns (uint256); 21 | 22 | /** 23 | * @dev Initiate a flash loan. 24 | * @param receiver The receiver of the tokens in the loan, and the receiver of the callback. 25 | * @param token The loan currency. 26 | * @param amount The amount of tokens lent. 27 | * @param data Arbitrary data structure, intended to contain user-defined parameters. 28 | */ 29 | function flashLoan( 30 | IERC3156FlashBorrower receiver, 31 | address token, 32 | uint256 amount, 33 | bytes calldata data 34 | ) 35 | external 36 | returns (bool); 37 | } 38 | -------------------------------------------------------------------------------- /src/integrations/interfaces/uniswap/v3/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IUniswapV3Pool { 6 | struct Slot0 { 7 | // the current price 8 | uint160 sqrtPriceX96; 9 | // the current tick 10 | int24 tick; 11 | // the most-recently updated index of the observations array 12 | uint16 observationIndex; 13 | // the current maximum number of observations that are being stored 14 | uint16 observationCardinality; 15 | // the next maximum number of observations to store, triggered in observations.write 16 | uint16 observationCardinalityNext; 17 | // the current protocol fee as a percentage of the swap fee taken on withdrawal 18 | // represented as an integer denominator (1/x)% 19 | uint8 feeProtocol; 20 | // whether the pool is locked 21 | bool unlocked; 22 | } 23 | 24 | function slot0() external view virtual returns (Slot0 memory); 25 | 26 | function fee() external view virtual returns (uint24 fee); 27 | 28 | function flash( 29 | address recipient, 30 | uint256 amount0, 31 | uint256 amount1, 32 | bytes memory data 33 | ) 34 | external 35 | virtual; 36 | 37 | function token0() external view virtual returns (address); 38 | function token1() external view virtual returns (address); 39 | } 40 | -------------------------------------------------------------------------------- /src/integrations/interfaces/uniswap/v3/IUniswapV3SwapCallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.8.0; 3 | 4 | /// @title Callback for IUniswapV3PoolActions#swap 5 | /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface 6 | interface IUniswapV3SwapCallback { 7 | /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. 8 | /// @dev In the implementation you must pay the pool tokens owed for the swap. 9 | /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical 10 | /// UniswapV3Factory. 11 | /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. 12 | /// @param amount0Delta The amount of token0 that was sent (negative) or must be received 13 | /// (positive) by the pool by 14 | /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. 15 | /// @param amount1Delta The amount of token1 that was sent (negative) or must be received 16 | /// (positive) by the pool by 17 | /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. 18 | /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call 19 | function uniswapV3SwapCallback( 20 | int256 amount0Delta, 21 | int256 amount1Delta, 22 | bytes calldata data 23 | ) 24 | external; 25 | } 26 | -------------------------------------------------------------------------------- /src/integrations/interfaces/chainlink/IAggregatorV3.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IAggregatorV3 { 5 | function decimals() external view returns (uint8); 6 | 7 | function description() external view returns (string memory); 8 | 9 | function version() external view returns (uint256); 10 | 11 | // getRoundData and latestRoundData should both raise "No data present" 12 | // if they do not have data to report, instead of returning unset values 13 | // which could be misinterpreted as actual reported values. 14 | function getRoundData(uint80 _roundId) 15 | external 16 | view 17 | returns ( 18 | uint80 roundId, 19 | int256 answer, 20 | uint256 startedAt, 21 | uint256 updatedAt, 22 | uint80 answeredInRound 23 | ); 24 | 25 | function latestRoundData() 26 | external 27 | view 28 | returns ( 29 | uint80 roundId, 30 | int256 answer, 31 | uint256 startedAt, 32 | uint256 updatedAt, 33 | uint80 answeredInRound 34 | ); 35 | 36 | function latestAnswer() external view returns (uint256); 37 | 38 | function getTimestamp(uint256 _roundId) external view returns (uint256); 39 | 40 | function phaseId() external view returns (uint16); 41 | 42 | function phaseAggregators(uint16 _phaseId) external view returns (address); 43 | } 44 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/IBondNFT.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "../IERC721Enumerable.sol"; 6 | 7 | interface IBondNFT is IERC721Enumerable { 8 | struct BondExtraData { 9 | uint80 initialHalfDna; 10 | uint80 finalHalfDna; 11 | uint32 troveSize; // Debt in LUSD 12 | uint32 lqtyAmount; // Holding LQTY, staking or deposited into Pickle 13 | uint32 curveGaugeSlopes; // For 3CRV and Frax pools combined 14 | } 15 | 16 | function getBondAmount(uint256 _tokenID) external view returns (uint256 amount); 17 | function getBondStartTime(uint256 _tokenID) external view returns (uint256 startTime); 18 | function getBondEndTime(uint256 _tokenID) external view returns (uint256 endTime); 19 | function getBondInitialHalfDna(uint256 _tokenID) 20 | external 21 | view 22 | returns (uint80 initialHalfDna); 23 | function getBondInitialDna(uint256 _tokenID) external view returns (uint256 initialDna); 24 | function getBondFinalHalfDna(uint256 _tokenID) external view returns (uint80 finalHalfDna); 25 | function getBondFinalDna(uint256 _tokenID) external view returns (uint256 finalDna); 26 | function getBondStatus(uint256 _tokenID) external view returns (uint8 status); 27 | function getBondExtraData(uint256 _tokenID) external view returns (BondExtraData memory); 28 | function tokenURI(uint256 _tokenID) external view returns (string memory); 29 | } 30 | -------------------------------------------------------------------------------- /src/integrations/interfaces/mstable/ISavingsContractV2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ISavingsContractV2 { 5 | // DEPRECATED but still backwards compatible 6 | function redeem(uint256 _amount) external returns (uint256 massetReturned); 7 | 8 | function creditBalances(address) external view returns (uint256); // V1 & V2 (use balanceOf) 9 | 10 | // -------------------------------------------- 11 | 12 | function approve(address, uint256) external; 13 | function depositInterest(uint256 _amount) external; // V1 & V2 14 | 15 | function depositSavings(uint256 _amount) external returns (uint256 creditsIssued); // V1 & V2 16 | 17 | function depositSavings( 18 | uint256 _amount, 19 | address _beneficiary 20 | ) 21 | external 22 | returns (uint256 creditsIssued); // V2 23 | 24 | function redeemCredits(uint256 _amount) external returns (uint256 underlyingReturned); // V2 25 | 26 | function redeemUnderlying(uint256 _amount) external returns (uint256 creditsBurned); // V2 27 | 28 | function exchangeRate() external view returns (uint256); // V1 & V2 29 | 30 | function balanceOfUnderlying(address _user) external view returns (uint256 balance); // V2 31 | 32 | function underlyingToCredits(uint256 _credits) external view returns (uint256 underlying); // V2 33 | 34 | function creditsToUnderlying(uint256 _underlying) external view returns (uint256 credits); // V2 35 | } 36 | -------------------------------------------------------------------------------- /src/integrations/interfaces/kyber/IMetaAggregationRouterV2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import { IERC20 } from "../IERC20.sol"; 5 | import { IAggregationExecutor } from "./IAggregationExecutor.sol"; 6 | 7 | interface IMetaAggregationRouterV2 { 8 | struct SwapDescriptionV2 { 9 | IERC20 srcToken; 10 | IERC20 dstToken; 11 | address[] srcReceivers; // transfer src token to these addresses, default 12 | uint256[] srcAmounts; 13 | address[] feeReceivers; 14 | uint256[] feeAmounts; 15 | address dstReceiver; 16 | uint256 amount; 17 | uint256 minReturnAmount; 18 | uint256 flags; 19 | bytes permit; 20 | } 21 | 22 | /// @dev use for swapGeneric and swap to avoid stack too deep 23 | struct SwapExecutionParams { 24 | address callTarget; // call this address 25 | address approveTarget; // approve this address if _APPROVE_FUND set 26 | bytes targetData; 27 | SwapDescriptionV2 desc; 28 | bytes clientData; 29 | } 30 | 31 | function swap(SwapExecutionParams calldata execution) 32 | external 33 | payable 34 | returns (uint256, uint256); 35 | 36 | function swapSimpleMode( 37 | IAggregationExecutor caller, 38 | SwapDescriptionV2 memory desc, 39 | bytes calldata executorData, 40 | bytes calldata clientData 41 | ) 42 | external 43 | returns (uint256, uint256); 44 | } 45 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/ISAFEManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ISAFEManager { 6 | function lastSAFEID(address) public view virtual returns (uint256); 7 | function safeCan(address, uint256, address) public view virtual returns (uint256); 8 | function collateralTypes(uint256) public view virtual returns (bytes32); 9 | function ownsSAFE(uint256) public view virtual returns (address); 10 | function safes(uint256) public view virtual returns (address); 11 | function safeEngine() public view virtual returns (address); 12 | function openSAFE(bytes32, address) public virtual returns (uint256); 13 | function transferSAFEOwnership(uint256, address) public virtual; 14 | function allowSAFE(uint256, address, uint256) public virtual; 15 | function handlerAllowed(address, uint256) public virtual; 16 | function modifySAFECollateralization(uint256, int256, int256) public virtual; 17 | function transferCollateral(uint256, address, uint256) public virtual; 18 | function transferInternalCoins(uint256, address, uint256) public virtual; 19 | function quitSystem(uint256, address) public virtual; 20 | function enterSystem(address, uint256) public virtual; 21 | function moveSAFE(uint256, uint256) public virtual; 22 | function safeCount(address) public view virtual returns (uint256); 23 | function safei() public view virtual returns (uint256); 24 | function protectSAFE(uint256, address, address) public virtual; 25 | } 26 | -------------------------------------------------------------------------------- /src/Mocks.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | AUX 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { MockRegistry } from "./module-bases/mocks/MockRegistry.sol"; 11 | import { MockTarget } from "./module-bases/mocks/MockTarget.sol"; 12 | import { MockHookMultiPlexer } from "./module-bases/mocks/MockHookMultiPlexer.sol"; 13 | import { MockPolicy } from "./module-bases/mocks/MockPolicy.sol"; 14 | 15 | /*////////////////////////////////////////////////////////////// 16 | MODULES 17 | //////////////////////////////////////////////////////////////*/ 18 | 19 | import { MockValidator } from "./module-bases/mocks/MockValidator.sol"; 20 | import { MockStatelessValidator } from "./module-bases/mocks/MockStatelessValidator.sol"; 21 | import { MockHybridValidator } from "./module-bases/mocks/MockHybridValidator.sol"; 22 | import { MockExecutor } from "./module-bases/mocks/MockExecutor.sol"; 23 | import { MockHook } from "./module-bases/mocks/MockHook.sol"; 24 | import { MockFallback } from "./module-bases/mocks/MockFallback.sol"; 25 | 26 | /*////////////////////////////////////////////////////////////// 27 | TOKENS 28 | //////////////////////////////////////////////////////////////*/ 29 | 30 | import { MockERC20 } from "./mocks/MockERC20.sol"; 31 | import { MockERC721 } from "./mocks/MockERC721.sol"; 32 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockValidator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | /* solhint-disable no-unused-vars */ 5 | import { ERC7579ValidatorBase } from "../ERC7579ValidatorBase.sol"; 6 | import { PackedUserOperation } from "../../external/ERC4337.sol"; 7 | 8 | contract MockValidator is ERC7579ValidatorBase { 9 | function onInstall(bytes calldata data) external virtual override { } 10 | 11 | function onUninstall(bytes calldata data) external virtual override { } 12 | 13 | function validateUserOp( 14 | PackedUserOperation calldata, // userOp 15 | bytes32 // userOpHash 16 | ) 17 | external 18 | virtual 19 | override 20 | returns (ValidationData) 21 | { 22 | return 23 | _packValidationData({ sigFailed: false, validUntil: type(uint48).max, validAfter: 0 }); 24 | } 25 | 26 | function isValidSignatureWithSender( 27 | address, // sender 28 | bytes32, // hash 29 | bytes calldata // data 30 | ) 31 | external 32 | view 33 | virtual 34 | override 35 | returns (bytes4) 36 | { 37 | return EIP1271_SUCCESS; 38 | } 39 | 40 | function isModuleType(uint256 typeID) external pure override returns (bool) { 41 | return typeID == TYPE_VALIDATOR; 42 | } 43 | 44 | function isInitialized( 45 | address // smartAccount 46 | ) 47 | external 48 | pure 49 | returns (bool) 50 | { 51 | return false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockRegistry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { IERC7484 } from "../interfaces/IERC7484.sol"; 5 | 6 | /// @title MockRegistry 7 | /// @author zeroknots 8 | contract MockRegistry is IERC7484 { 9 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 10 | /* Check with Registry internal attesters */ 11 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 12 | function check(address module) external view { } 13 | 14 | function checkForAccount(address smartAccount, address module) external view { } 15 | 16 | function check(address module, uint256 moduleType) external view { } 17 | 18 | function checkForAccount( 19 | address smartAccount, 20 | address module, 21 | uint256 moduleType 22 | ) 23 | external 24 | view 25 | { } 26 | 27 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 28 | /* Check with external attester(s) */ 29 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 30 | 31 | function check(address module, address[] calldata attesters, uint256 threshold) external view { } 32 | 33 | function check( 34 | address module, 35 | uint256 moduleType, 36 | address[] calldata attesters, 37 | uint256 threshold 38 | ) 39 | external 40 | view 41 | { } 42 | 43 | function trustAttesters(uint8 threshold, address[] calldata attesters) external { } 44 | } 45 | -------------------------------------------------------------------------------- /src/Helpers.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | 4337 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { ERC4337Helpers } from "./test/utils/ERC4337Helpers.sol"; 11 | 12 | /*////////////////////////////////////////////////////////////// 13 | 7579 REFERENCE 14 | //////////////////////////////////////////////////////////////*/ 15 | 16 | import { ERC7579Helpers } from "./test/helpers/ERC7579Helpers.sol"; 17 | 18 | /*////////////////////////////////////////////////////////////// 19 | KERNEL 20 | //////////////////////////////////////////////////////////////*/ 21 | 22 | import { KernelHelpers } from "./test/helpers/KernelHelpers.sol"; 23 | 24 | /*////////////////////////////////////////////////////////////// 25 | NEXUS 26 | //////////////////////////////////////////////////////////////*/ 27 | 28 | import { NexusHelpers } from "./test/helpers/NexusHelpers.sol"; 29 | 30 | /*////////////////////////////////////////////////////////////// 31 | SAFE 32 | //////////////////////////////////////////////////////////////*/ 33 | 34 | import { SafeHelpers } from "./test/helpers/SafeHelpers.sol"; 35 | 36 | /*////////////////////////////////////////////////////////////// 37 | UTIL 38 | //////////////////////////////////////////////////////////////*/ 39 | 40 | import { ecdsaSign } from "./test/utils/ECDSA.sol"; 41 | -------------------------------------------------------------------------------- /src/integrations/interfaces/qidao/IStablecoin.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IStablecoin { 5 | function getDebtCeiling() external view returns (uint256); 6 | 7 | function balanceOf(address account) external view returns (uint256); 8 | 9 | function getClosingFee() external view returns (uint256); 10 | 11 | function getOpeningFee() external view returns (uint256); 12 | 13 | function getTokenPriceSource() external view returns (uint256); 14 | 15 | function getEthPriceSource() external view returns (uint256); 16 | 17 | function createVault() external returns (uint256); 18 | 19 | function destroyVault(uint256 vaultID) external; 20 | 21 | function transferVault(uint256 vaultID, address to) external; 22 | 23 | function depositCollateral(uint256 vaultID) external payable; 24 | 25 | function depositCollateral(uint256 vaultID, uint256 amount) external payable; 26 | 27 | function withdrawCollateral(uint256 vaultID, uint256 amount) external; 28 | 29 | function borrowToken(uint256 vaultID, uint256 amount) external; 30 | 31 | function vaultDebt(uint256 vaultId) external view returns (uint256); 32 | 33 | function payBackToken(uint256 vaultID, uint256 amount) external; 34 | 35 | function buyRiskyVault(uint256 vaultID) external; 36 | 37 | function collateral() external view returns (address); 38 | 39 | function tokenOfOwnerByIndex( 40 | address owner, 41 | uint256 index 42 | ) 43 | external 44 | view 45 | returns (uint256 tokenId); 46 | 47 | function vaultCollateral(uint256 vaultId) external view returns (uint256 collAmount); 48 | } 49 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV3/IAaveProtocolDataProvider.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.10; 3 | 4 | interface IAaveProtocolDataProvider { 5 | /** 6 | * @notice Returns the user data in a reserve 7 | * @param asset The address of the underlying asset of the reserve 8 | * @param user The address of the user 9 | * @return currentATokenBalance The current AToken balance of the user 10 | * @return currentStableDebt The current stable debt of the user 11 | * @return currentVariableDebt The current variable debt of the user 12 | * @return principalStableDebt The principal stable debt of the user 13 | * @return scaledVariableDebt The scaled variable debt of the user 14 | * @return stableBorrowRate The stable borrow rate of the user 15 | * @return liquidityRate The liquidity rate of the reserve 16 | * @return stableRateLastUpdated The timestamp of the last update of the user stable rate 17 | * @return usageAsCollateralEnabled True if the user is using the asset as collateral, false 18 | * otherwise 19 | * 20 | */ 21 | function getUserReserveData( 22 | address asset, 23 | address user 24 | ) 25 | external 26 | view 27 | returns ( 28 | uint256 currentATokenBalance, 29 | uint256 currentStableDebt, 30 | uint256 currentVariableDebt, 31 | uint256 principalStableDebt, 32 | uint256 scaledVariableDebt, 33 | uint256 stableBorrowRate, 34 | uint256 liquidityRate, 35 | uint40 stableRateLastUpdated, 36 | bool usageAsCollateralEnabled 37 | ); 38 | function getSiloedBorrowing(address asset) external view returns (bool); 39 | } 40 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/ILQTYStaking.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | interface ILQTYStaking { 6 | // --- Events -- 7 | 8 | event LQTYTokenAddressSet(address _lqtyTokenAddress); 9 | event LUSDTokenAddressSet(address _lusdTokenAddress); 10 | event TroveManagerAddressSet(address _troveManager); 11 | event BorrowerOperationsAddressSet(address _borrowerOperationsAddress); 12 | event ActivePoolAddressSet(address _activePoolAddress); 13 | 14 | event StakeChanged(address indexed staker, uint256 newStake); 15 | event StakingGainsWithdrawn(address indexed staker, uint256 LUSDGain, uint256 ETHGain); 16 | event F_ETHUpdated(uint256 _F_ETH); 17 | event F_LUSDUpdated(uint256 _F_LUSD); 18 | event TotalLQTYStakedUpdated(uint256 _totalLQTYStaked); 19 | event EtherSent(address _account, uint256 _amount); 20 | event StakerSnapshotsUpdated(address _staker, uint256 _F_ETH, uint256 _F_LUSD); 21 | 22 | // --- Functions --- 23 | 24 | function setAddresses( 25 | address _lqtyTokenAddress, 26 | address _lusdTokenAddress, 27 | address _troveManagerAddress, 28 | address _borrowerOperationsAddress, 29 | address _activePoolAddress 30 | ) 31 | external; 32 | 33 | function stake(uint256 _LQTYamount) external; 34 | 35 | function unstake(uint256 _LQTYamount) external; 36 | 37 | function increaseF_ETH(uint256 _ETHFee) external; 38 | 39 | function increaseF_LUSD(uint256 _LQTYFee) external; 40 | 41 | function getPendingETHGain(address _user) external view returns (uint256); 42 | 43 | function getPendingLUSDGain(address _user) external view returns (uint256); 44 | 45 | function stakes(address) external view returns (uint256); 46 | } 47 | -------------------------------------------------------------------------------- /src/deployment/predeploy/EntryPoint.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Utils 5 | import { etch } from "../../test/utils/Vm.sol"; 6 | 7 | // Interfaces 8 | import { IEntryPoint } from "../../external/ERC4337.sol"; 9 | 10 | // External Dependencies 11 | import { SenderCreator } from "@ERC4337/account-abstraction/contracts/core/EntryPoint.sol"; 12 | import { EntryPointSimulations } from 13 | "@ERC4337/account-abstraction/contracts/core/EntryPointSimulations.sol"; 14 | 15 | contract EntryPointSimulationsPatch is EntryPointSimulations { 16 | address public _entrypointAddr = address(this); 17 | 18 | SenderCreator public _newSenderCreator; 19 | 20 | function init(address entrypointAddr) public { 21 | _entrypointAddr = entrypointAddr; 22 | initSenderCreator(); 23 | } 24 | 25 | function initSenderCreator() internal override { 26 | //this is the address of the first contract created with CREATE by this address. 27 | address createdObj = address( 28 | uint160(uint256(keccak256(abi.encodePacked(hex"d694", _entrypointAddr, hex"01")))) 29 | ); 30 | _newSenderCreator = SenderCreator(createdObj); 31 | } 32 | 33 | function senderCreator() internal view virtual override returns (SenderCreator) { 34 | return _newSenderCreator; 35 | } 36 | } 37 | 38 | /// @dev Preset entrypoint address 39 | address constant ENTRYPOINT_ADDR = 0x0000000071727De22E5E9d8BAf0edAc6f37da032; 40 | 41 | function etchEntrypoint() returns (IEntryPoint) { 42 | address payable entryPoint = payable(address(new EntryPointSimulationsPatch())); 43 | etch(ENTRYPOINT_ADDR, entryPoint.code); 44 | EntryPointSimulationsPatch(payable(ENTRYPOINT_ADDR)).init(entryPoint); 45 | 46 | return IEntryPoint(ENTRYPOINT_ADDR); 47 | } 48 | -------------------------------------------------------------------------------- /src/accounts/safe/interfaces/IERC7484.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | interface IERC7484 { 5 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 6 | /* Check with Registry internal attesters */ 7 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 8 | 9 | function check(address module) external view; 10 | 11 | function checkForAccount(address smartAccount, address module) external view; 12 | 13 | function check(address module, uint256 moduleType) external view; 14 | 15 | function checkForAccount( 16 | address smartAccount, 17 | address module, 18 | uint256 moduleType 19 | ) 20 | external 21 | view; 22 | 23 | /** 24 | * Allows Smart Accounts - the end users of the registry - to appoint 25 | * one or many attesters as trusted. 26 | * @dev this function reverts, if address(0), or duplicates are provided in attesters[] 27 | * 28 | * @param threshold The minimum number of attestations required for a module 29 | * to be considered secure. 30 | * @param attesters The addresses of the attesters to be trusted. 31 | */ 32 | function trustAttesters(uint8 threshold, address[] calldata attesters) external; 33 | 34 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 35 | /* Check with external attester(s) */ 36 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 37 | 38 | function check(address module, address[] calldata attesters, uint256 threshold) external view; 39 | 40 | function check( 41 | address module, 42 | uint256 moduleType, 43 | address[] calldata attesters, 44 | uint256 threshold 45 | ) 46 | external 47 | view; 48 | } 49 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockHybridValidator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { ERC7579HybridValidatorBase } from "../ERC7579HybridValidatorBase.sol"; 5 | import { PackedUserOperation } from "../../external/ERC4337.sol"; 6 | 7 | contract MockHybridValidator is ERC7579HybridValidatorBase { 8 | function onInstall(bytes calldata data) external virtual override { } 9 | 10 | function onUninstall(bytes calldata data) external virtual override { } 11 | 12 | function validateUserOp( 13 | PackedUserOperation calldata, // userOp 14 | bytes32 // userOpHash 15 | ) 16 | external 17 | virtual 18 | override 19 | returns (ValidationData) 20 | { 21 | return 22 | _packValidationData({ sigFailed: false, validUntil: type(uint48).max, validAfter: 0 }); 23 | } 24 | 25 | function isValidSignatureWithSender( 26 | address, // sender 27 | bytes32, // hash 28 | bytes calldata // data 29 | ) 30 | external 31 | view 32 | virtual 33 | override 34 | returns (bytes4) 35 | { 36 | return EIP1271_SUCCESS; 37 | } 38 | 39 | function isModuleType(uint256 typeID) external pure override returns (bool) { 40 | return typeID == TYPE_VALIDATOR || typeID == TYPE_STATELESS_VALIDATOR; 41 | } 42 | 43 | function isInitialized( 44 | address // smartAccount 45 | ) 46 | external 47 | pure 48 | returns (bool) 49 | { 50 | return false; 51 | } 52 | 53 | function validateSignatureWithData( 54 | bytes32, 55 | bytes calldata, 56 | bytes calldata 57 | ) 58 | external 59 | pure 60 | override 61 | returns (bool validSig) 62 | { 63 | return true; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/module-bases/interfaces/IERC7484.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IERC7484 { 5 | event NewTrustedAttesters(); 6 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 7 | /* Check with Registry internal attesters */ 8 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 9 | 10 | function check(address module) external view; 11 | 12 | function checkForAccount(address smartAccount, address module) external view; 13 | 14 | function check(address module, uint256 moduleType) external view; 15 | 16 | function checkForAccount( 17 | address smartAccount, 18 | address module, 19 | uint256 moduleType 20 | ) 21 | external 22 | view; 23 | 24 | /** 25 | * Allows Smart Accounts - the end users of the registry - to appoint 26 | * one or many attesters as trusted. 27 | * @dev this function reverts, if address(0), or duplicates are provided in attesters[] 28 | * 29 | * @param threshold The minimum number of attestations required for a module 30 | * to be considered secure. 31 | * @param attesters The addresses of the attesters to be trusted. 32 | */ 33 | function trustAttesters(uint8 threshold, address[] calldata attesters) external; 34 | 35 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 36 | /* Check with external attester(s) */ 37 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 38 | 39 | function check(address module, address[] calldata attesters, uint256 threshold) external view; 40 | 41 | function check( 42 | address module, 43 | uint256 moduleType, 44 | address[] calldata attesters, 45 | uint256 threshold 46 | ) 47 | external 48 | view; 49 | } 50 | -------------------------------------------------------------------------------- /test/mocks/MockValidatorFalse.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-vars */ 5 | import { ERC7579StatelessValidatorBase } from "src/Modules.sol"; 6 | import { ERC7579ValidatorBase } from "src/Modules.sol"; 7 | import { PackedUserOperation } from "src/external/ERC4337.sol"; 8 | 9 | contract MockValidatorFalse is ERC7579StatelessValidatorBase, ERC7579ValidatorBase { 10 | function onInstall(bytes calldata data) external virtual override { } 11 | 12 | function onUninstall(bytes calldata data) external virtual override { } 13 | 14 | function validateUserOp( 15 | PackedUserOperation calldata, // userOp 16 | bytes32 // userOpHash 17 | ) 18 | external 19 | virtual 20 | override 21 | returns (ValidationData) 22 | { 23 | return _packValidationData({ sigFailed: true, validUntil: type(uint48).max, validAfter: 0 }); 24 | } 25 | 26 | function isValidSignatureWithSender( 27 | address, // sender 28 | bytes32, // hash 29 | bytes calldata // signature 30 | ) 31 | external 32 | view 33 | virtual 34 | override 35 | returns (bytes4) 36 | { 37 | return EIP1271_FAILED; 38 | } 39 | 40 | function isModuleType(uint256 typeID) external pure override returns (bool) { 41 | return typeID == TYPE_VALIDATOR; 42 | } 43 | 44 | function isInitialized( 45 | address // smartAccount 46 | ) 47 | external 48 | pure 49 | returns (bool) 50 | { 51 | return false; 52 | } 53 | 54 | function validateSignatureWithData( 55 | bytes32, 56 | bytes calldata, 57 | bytes calldata 58 | ) 59 | external 60 | pure 61 | override 62 | returns (bool validSig) 63 | { 64 | return false; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | push: 4 | branches: 5 | - "main" 6 | pull_request: 7 | 8 | jobs: 9 | lint: 10 | uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-lint.yaml@main" 11 | 12 | build: 13 | uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-build.yaml@main" 14 | 15 | test: 16 | needs: ["lint", "build"] 17 | uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-test.yaml@main" 18 | with: 19 | foundry-fuzz-runs: 5000 20 | foundry-profile: "test" 21 | match-path: "test/**/*.sol" 22 | foundry-verbosity: 3 23 | foundry-gas-limit: "18446744073709551615" 24 | foundry-memory-limit: 2147483648 25 | secrets: 26 | MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} 27 | TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }} 28 | 29 | test-simulate: 30 | needs: ["lint", "build"] 31 | uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-test-simulate.yaml@main" 32 | with: 33 | foundry-fuzz-runs: 5000 34 | foundry-profile: "test" 35 | match-path: "test/**/*.sol" 36 | foundry-verbosity: 3 37 | foundry-gas-limit: "18446744073709551615" 38 | foundry-memory-limit: 2147483648 39 | secrets: 40 | MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} 41 | TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }} 42 | 43 | test-multi-account: 44 | needs: ["lint", "build"] 45 | uses: "rhinestonewtf/reusable-workflows/.github/workflows/forge-test-multi-account.yaml@main" 46 | with: 47 | foundry-fuzz-runs: 5000 48 | foundry-profile: "test" 49 | match-path: "test/**/*.sol" 50 | foundry-verbosity: 3 51 | foundry-gas-limit: "18446744073709551615" 52 | foundry-memory-limit: 2147483648 53 | secrets: 54 | MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }} 55 | TESTNET_RPC_URL: ${{ secrets.TESTNET_RPC_URL }} 56 | -------------------------------------------------------------------------------- /src/external/ERC4337.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | USEROP 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { PackedUserOperation } from 11 | "@ERC4337/account-abstraction/contracts/interfaces/PackedUserOperation.sol"; 12 | import { UserOperationLib } from "@ERC4337/account-abstraction/contracts/core/UserOperationLib.sol"; 13 | 14 | /*////////////////////////////////////////////////////////////// 15 | ENTRYPOINT 16 | //////////////////////////////////////////////////////////////*/ 17 | 18 | import { EntryPointSimulations } from 19 | "@ERC4337/account-abstraction/contracts/core/EntryPointSimulations.sol"; 20 | 21 | /*////////////////////////////////////////////////////////////// 22 | VALIDATION 23 | //////////////////////////////////////////////////////////////*/ 24 | 25 | import { 26 | ValidationData, 27 | _packValidationData 28 | } from "@ERC4337/account-abstraction/contracts/core/Helpers.sol"; 29 | 30 | /*////////////////////////////////////////////////////////////// 31 | INTERFACES 32 | //////////////////////////////////////////////////////////////*/ 33 | 34 | import { IStakeManager } from "@ERC4337/account-abstraction/contracts/interfaces/IStakeManager.sol"; 35 | import { IAccount as IERC4337 } from 36 | "@ERC4337/account-abstraction/contracts/interfaces/IAccount.sol"; 37 | import { IAccountExecute } from 38 | "@ERC4337/account-abstraction/contracts/interfaces/IAccountExecute.sol"; 39 | import { IEntryPoint } from "@ERC4337/account-abstraction/contracts/interfaces/IEntryPoint.sol"; 40 | import { IEntryPointSimulations } from 41 | "@ERC4337/account-abstraction/contracts/interfaces/IEntryPointSimulations.sol"; 42 | -------------------------------------------------------------------------------- /src/integrations/interfaces/reflexer/ISAFEEngine.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ISAFEEngine { 6 | struct SAFE { 7 | uint256 lockedCollateral; 8 | uint256 generatedDebt; 9 | } 10 | 11 | struct CollateralType { 12 | // Total debt issued for this specific collateral type 13 | uint256 debtAmount; // [wad] 14 | // Accumulator for interest accrued on this collateral type 15 | uint256 accumulatedRate; // [ray] 16 | // Floor price at which a SAFE is allowed to generate debt 17 | uint256 safetyPrice; // [ray] 18 | // Maximum amount of debt that can be generated with this collateral type 19 | uint256 debtCeiling; // [rad] 20 | // Minimum amount of debt that must be generated by a SAFE using this collateral 21 | uint256 debtFloor; // [rad] 22 | // Price at which a SAFE gets liquidated 23 | uint256 liquidationPrice; // [ray] 24 | } 25 | 26 | mapping(bytes32 => mapping(address => SAFE)) public safes; 27 | mapping(bytes32 => CollateralType) public collateralTypes; 28 | mapping(bytes32 => mapping(address => uint256)) public tokenCollateral; 29 | 30 | function safeRights(address, address) public view virtual returns (uint256); 31 | function coinBalance(address) public view virtual returns (uint256); 32 | function modifySAFECollateralization( 33 | bytes32, 34 | address, 35 | address, 36 | address, 37 | int256, 38 | int256 39 | ) 40 | public 41 | virtual; 42 | function approveSAFEModification(address) public virtual; 43 | function transferInternalCoins(address, address, uint256) public virtual; 44 | function transferSAFECollateralAndDebt( 45 | bytes32, 46 | address, 47 | address, 48 | int256, 49 | int256 50 | ) 51 | public 52 | virtual; 53 | } 54 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/ISortedTroves.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | // Common interface for the SortedTroves Doubly Linked List. 6 | interface ISortedTroves { 7 | // --- Events --- 8 | 9 | event SortedTrovesAddressChanged(address _sortedDoublyLLAddress); 10 | event BorrowerOperationsAddressChanged(address _borrowerOperationsAddress); 11 | event NodeAdded(address _id, uint256 _NICR); 12 | event NodeRemoved(address _id); 13 | 14 | // --- Functions --- 15 | 16 | function setParams( 17 | uint256 _size, 18 | address _TroveManagerAddress, 19 | address _borrowerOperationsAddress 20 | ) 21 | external; 22 | 23 | function insert(address _id, uint256 _ICR, address _prevId, address _nextId) external; 24 | 25 | function remove(address _id) external; 26 | 27 | function reInsert(address _id, uint256 _newICR, address _prevId, address _nextId) external; 28 | 29 | function contains(address _id) external view returns (bool); 30 | 31 | function isFull() external view returns (bool); 32 | 33 | function isEmpty() external view returns (bool); 34 | 35 | function getSize() external view returns (uint256); 36 | 37 | function getMaxSize() external view returns (uint256); 38 | 39 | function getFirst() external view returns (address); 40 | 41 | function getLast() external view returns (address); 42 | 43 | function getNext(address _id) external view returns (address); 44 | 45 | function getPrev(address _id) external view returns (address); 46 | 47 | function validInsertPosition( 48 | uint256 _ICR, 49 | address _prevId, 50 | address _nextId 51 | ) 52 | external 53 | view 54 | returns (bool); 55 | 56 | function findInsertPosition( 57 | uint256 _ICR, 58 | address _prevId, 59 | address _nextId 60 | ) 61 | external 62 | view 63 | returns (address, address); 64 | } 65 | -------------------------------------------------------------------------------- /src/module-bases/utils/TrustedForwarder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | abstract contract TrustedForwarder { 5 | // account => trustedForwarder 6 | mapping(address account => address trustedForwarder) public trustedForwarder; 7 | 8 | /** 9 | * Set the trusted forwarder for an account 10 | * 11 | * @param forwarder The address of the trusted forwarder 12 | */ 13 | function setTrustedForwarder(address forwarder) external { 14 | trustedForwarder[msg.sender] = forwarder; 15 | } 16 | 17 | /** 18 | * Clear the trusted forwarder for an account 19 | */ 20 | function clearTrustedForwarder() public { 21 | trustedForwarder[msg.sender] = address(0); 22 | } 23 | 24 | /** 25 | * Check if a forwarder is trusted for an account 26 | * 27 | * @param forwarder The address of the forwarder 28 | * @param account The address of the account 29 | * 30 | * @return true if the forwarder is trusted for the account 31 | */ 32 | function isTrustedForwarder(address forwarder, address account) public view returns (bool) { 33 | return forwarder == trustedForwarder[account]; 34 | } 35 | 36 | /** 37 | * Get the sender of the transaction 38 | * 39 | * @return account the sender of the transaction 40 | */ 41 | function _getAccount() internal view returns (address account) { 42 | account = msg.sender; 43 | address _account; 44 | address forwarder; 45 | if (msg.data.length >= 40) { 46 | // solhint-disable-next-line no-inline-assembly 47 | assembly { 48 | _account := shr(96, calldataload(sub(calldatasize(), 20))) 49 | forwarder := shr(96, calldataload(sub(calldatasize(), 40))) 50 | } 51 | if (forwarder == msg.sender && isTrustedForwarder(forwarder, _account)) { 52 | account = _account; 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/deployment/registry/interfaces/IERC7484.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | // Types 5 | import { ModuleType } from "../types/DataTypes.sol"; 6 | 7 | interface IERC7484 { 8 | event NewTrustedAttesters(address indexed smartAccount); 9 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 10 | /* Check with Registry internal attesters */ 11 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 12 | 13 | function check(address module) external view; 14 | 15 | function checkForAccount(address smartAccount, address module) external view; 16 | 17 | function check(address module, ModuleType moduleType) external view; 18 | 19 | function checkForAccount( 20 | address smartAccount, 21 | address module, 22 | ModuleType moduleType 23 | ) 24 | external 25 | view; 26 | 27 | /** 28 | * Allows Smart Accounts - the end users of the registry - to appoint 29 | * one or many attesters as trusted. 30 | * @dev this function reverts, if address(0), or duplicates are provided in attesters[] 31 | * 32 | * @param threshold The minimum number of attestations required for a module 33 | * to be considered secure. 34 | * @param attesters The addresses of the attesters to be trusted. 35 | */ 36 | function trustAttesters(uint8 threshold, address[] calldata attesters) external; 37 | 38 | /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ 39 | /* Check with external attester(s) */ 40 | /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ 41 | 42 | function check(address module, address[] calldata attesters, uint256 threshold) external view; 43 | 44 | function check( 45 | address module, 46 | ModuleType moduleType, 47 | address[] calldata attesters, 48 | uint256 threshold 49 | ) 50 | external 51 | view; 52 | } 53 | -------------------------------------------------------------------------------- /src/integrations/ERC4626.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC4626 } from "forge-std/interfaces/IERC4626.sol"; 6 | 7 | // Types 8 | import { Execution } from "../accounts/erc7579/lib/ExecutionLib.sol"; 9 | 10 | library ERC4626Integration { 11 | function deposit( 12 | IERC4626 vault, 13 | uint256 assets, 14 | address receiver 15 | ) 16 | internal 17 | pure 18 | returns (Execution memory exec) 19 | { 20 | exec = Execution({ 21 | target: address(vault), 22 | value: 0, 23 | callData: abi.encodeCall(IERC4626.deposit, (assets, receiver)) 24 | }); 25 | } 26 | 27 | function mint( 28 | IERC4626 vault, 29 | uint256 shares, 30 | address receiver 31 | ) 32 | internal 33 | pure 34 | returns (Execution memory exec) 35 | { 36 | exec = Execution({ 37 | target: address(vault), 38 | value: 0, 39 | callData: abi.encodeCall(IERC4626.mint, (shares, receiver)) 40 | }); 41 | } 42 | 43 | function withdraw( 44 | IERC4626 vault, 45 | uint256 assets, 46 | address receiver, 47 | address owner 48 | ) 49 | internal 50 | pure 51 | returns (Execution memory exec) 52 | { 53 | exec = Execution({ 54 | target: address(vault), 55 | value: 0, 56 | callData: abi.encodeCall(IERC4626.withdraw, (assets, receiver, owner)) 57 | }); 58 | } 59 | 60 | function redeem( 61 | IERC4626 vault, 62 | uint256 shares, 63 | address receiver, 64 | address owner 65 | ) 66 | internal 67 | pure 68 | returns (Execution memory exec) 69 | { 70 | exec = Execution({ 71 | target: address(vault), 72 | value: 0, 73 | callData: abi.encodeCall(IERC4626.redeem, (shares, receiver, owner)) 74 | }); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV2/ILendingPoolAddressesProviderV2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity ^0.8.10; 3 | 4 | interface ILendingPoolAddressesProviderV2 { 5 | event LendingPoolUpdated(address indexed newAddress); 6 | event ConfigurationAdminUpdated(address indexed newAddress); 7 | event EmergencyAdminUpdated(address indexed newAddress); 8 | event LendingPoolConfiguratorUpdated(address indexed newAddress); 9 | event LendingPoolCollateralManagerUpdated(address indexed newAddress); 10 | event PriceOracleUpdated(address indexed newAddress); 11 | event LendingRateOracleUpdated(address indexed newAddress); 12 | event ProxyCreated(bytes32 id, address indexed newAddress); 13 | event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy); 14 | 15 | function setAddress(bytes32 id, address newAddress) external; 16 | 17 | function setAddressAsProxy(bytes32 id, address impl) external; 18 | 19 | function getAddress(bytes32 id) external view returns (address); 20 | 21 | function getLendingPool() external view returns (address); 22 | 23 | function setLendingPoolImpl(address pool) external; 24 | 25 | function getLendingPoolConfigurator() external view returns (address); 26 | 27 | function setLendingPoolConfiguratorImpl(address configurator) external; 28 | 29 | function getLendingPoolCollateralManager() external view returns (address); 30 | 31 | function setLendingPoolCollateralManager(address manager) external; 32 | 33 | function getPoolAdmin() external view returns (address); 34 | 35 | function setPoolAdmin(address admin) external; 36 | 37 | function getEmergencyAdmin() external view returns (address); 38 | 39 | function setEmergencyAdmin(address admin) external; 40 | 41 | function getPriceOracle() external view returns (address); 42 | 43 | function setPriceOracle(address priceOracle) external; 44 | 45 | function getLendingRateOracle() external view returns (address); 46 | 47 | function setLendingRateOracle(address lendingRateOracle) external; 48 | } 49 | -------------------------------------------------------------------------------- /src/module-bases/mocks/MockPolicy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { PackedUserOperation } from 5 | "@ERC4337/account-abstraction/contracts/interfaces/PackedUserOperation.sol"; 6 | 7 | contract MockPolicy { 8 | mapping(address account => uint256 validation) public validationData; 9 | mapping( 10 | bytes32 id => mapping(address msgSender => mapping(address userOpSender => uint256 calls)) 11 | ) public userOpState; 12 | mapping( 13 | bytes32 id => mapping(address msgSender => mapping(address userOpSender => uint256 calls)) 14 | ) public actionState; 15 | 16 | function setValidationData(address account, uint256 validation) external { 17 | validationData[account] = validation; 18 | } 19 | 20 | function initializeWithMultiplexer( 21 | address account, 22 | bytes32 configId, 23 | bytes calldata 24 | ) 25 | external 26 | { 27 | userOpState[configId][msg.sender][account] = 1; 28 | } 29 | 30 | function checkUserOpPolicy( 31 | bytes32 id, 32 | PackedUserOperation calldata userOp 33 | ) 34 | external 35 | returns (uint256) 36 | { 37 | userOpState[id][msg.sender][userOp.sender] += 1; 38 | return validationData[userOp.sender]; 39 | } 40 | 41 | function checkAction( 42 | bytes32 id, 43 | address account, 44 | address, 45 | uint256, 46 | bytes calldata 47 | ) 48 | external 49 | returns (uint256) 50 | { 51 | actionState[id][msg.sender][account] += 1; 52 | return validationData[account]; 53 | } 54 | 55 | function supportsInterface(bytes4) external pure returns (bool) { 56 | return true; 57 | } 58 | 59 | function check1271SignedAction( 60 | bytes32, 61 | address, 62 | address, 63 | bytes32, 64 | bytes calldata 65 | ) 66 | external 67 | pure 68 | returns (bool) 69 | { 70 | return true; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/integrations/interfaces/compound/IComptroller.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IComptroller { 6 | struct CompMarketState { 7 | uint224 index; 8 | uint32 block; 9 | } 10 | 11 | mapping(address => uint256) public compSpeeds; 12 | 13 | mapping(address => uint256) public borrowCaps; 14 | 15 | mapping(address => uint256) public compBorrowSpeeds; 16 | mapping(address => uint256) public compSupplySpeeds; 17 | 18 | function claimComp(address holder) public virtual; 19 | function claimComp(address holder, address[] memory cTokens) public virtual; 20 | function claimComp( 21 | address[] memory holders, 22 | address[] memory cTokens, 23 | bool borrowers, 24 | bool suppliers 25 | ) 26 | public 27 | virtual; 28 | 29 | function compSupplyState(address) public view virtual returns (CompMarketState memory); 30 | function compSupplierIndex(address, address) public view virtual returns (uint256); 31 | function compAccrued(address) public view virtual returns (uint256); 32 | 33 | function compBorrowState(address) public view virtual returns (CompMarketState memory); 34 | function compBorrowerIndex(address, address) public view virtual returns (uint256); 35 | 36 | function enterMarkets(address[] calldata cTokens) external virtual returns (uint256[] memory); 37 | 38 | function exitMarket(address cToken) external virtual returns (uint256); 39 | 40 | function getAssetsIn(address account) external view virtual returns (address[] memory); 41 | 42 | function markets(address account) public view virtual returns (bool, uint256); 43 | 44 | function getAccountLiquidity(address account) 45 | external 46 | view 47 | virtual 48 | returns (uint256, uint256, uint256); 49 | 50 | function oracle() public view virtual returns (address); 51 | 52 | function mintGuardianPaused(address cToken) external view virtual returns (bool); 53 | function borrowGuardianPaused(address cToken) external view virtual returns (bool); 54 | } 55 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV3/IPriceOracleSentinel.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.0; 3 | 4 | interface IPriceOracleSentinel { 5 | /** 6 | * @dev Emitted after the sequencer oracle is updated 7 | * @param newSequencerOracle The new sequencer oracle 8 | */ 9 | event SequencerOracleUpdated(address newSequencerOracle); 10 | 11 | /** 12 | * @dev Emitted after the grace period is updated 13 | * @param newGracePeriod The new grace period value 14 | */ 15 | event GracePeriodUpdated(uint256 newGracePeriod); 16 | 17 | /** 18 | * @notice Returns true if the `borrow` operation is allowed. 19 | * @dev Operation not allowed when PriceOracle is down or grace period not passed. 20 | * @return True if the `borrow` operation is allowed, false otherwise. 21 | */ 22 | function isBorrowAllowed() external view returns (bool); 23 | 24 | /** 25 | * @notice Returns true if the `liquidation` operation is allowed. 26 | * @dev Operation not allowed when PriceOracle is down or grace period not passed. 27 | * @return True if the `liquidation` operation is allowed, false otherwise. 28 | */ 29 | function isLiquidationAllowed() external view returns (bool); 30 | 31 | /** 32 | * @notice Updates the address of the sequencer oracle 33 | * @param newSequencerOracle The address of the new Sequencer Oracle to use 34 | */ 35 | function setSequencerOracle(address newSequencerOracle) external; 36 | 37 | /** 38 | * @notice Updates the duration of the grace period 39 | * @param newGracePeriod The value of the new grace period duration 40 | */ 41 | function setGracePeriod(uint256 newGracePeriod) external; 42 | 43 | /** 44 | * @notice Returns the SequencerOracle 45 | * @return The address of the sequencer oracle contract 46 | */ 47 | function getSequencerOracle() external view returns (address); 48 | 49 | /** 50 | * @notice Returns the grace period 51 | * @return The duration of the grace period 52 | */ 53 | function getGracePeriod() external view returns (uint256); 54 | } 55 | -------------------------------------------------------------------------------- /src/test/utils/gas/UserOpGasLog.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Types 5 | import { 6 | PackedUserOperation, 7 | EntryPointSimulations, 8 | IEntryPointSimulations 9 | } from "src/external/ERC4337.sol"; 10 | 11 | // Utils 12 | import "../Log.sol"; 13 | 14 | contract UserOpGasLog { 15 | EntryPointSimulations public immutable simulation = new EntryPointSimulations(); 16 | 17 | struct GasLog { 18 | uint256 gasValidation; 19 | uint256 gasExecution; 20 | } 21 | 22 | mapping(bytes32 userOpHash => GasLog log) internal _log; 23 | 24 | function getLog(bytes32 userOpHash) 25 | external 26 | view 27 | returns (uint256 gasValidation, uint256 gasExecution) 28 | { 29 | GasLog memory log = _log[userOpHash]; 30 | return (log.gasValidation, log.gasExecution); 31 | } 32 | 33 | function calcValidationGas( 34 | PackedUserOperation memory userOp, 35 | bytes32 userOpHash, 36 | address, /* sender */ 37 | bytes memory /* initCode */ 38 | ) 39 | external 40 | returns (uint256 gasValidation) 41 | { 42 | IEntryPointSimulations.ValidationResult memory validationResult = 43 | simulation.simulateValidation(userOp); 44 | 45 | gasValidation = validationResult.returnInfo.preOpGas; 46 | 47 | _log[userOpHash].gasValidation = gasValidation; 48 | } 49 | 50 | function calcExecutionGas( 51 | PackedUserOperation memory userOp, 52 | bytes32 userOpHash, 53 | address sender, 54 | bytes memory initCode 55 | ) 56 | external 57 | returns (uint256 gasExecution) 58 | { 59 | IEntryPointSimulations.ExecutionResult memory executionResult = 60 | simulation.simulateHandleOp(userOp, sender, initCode); 61 | 62 | gasExecution = executionResult.paid; 63 | // gasValidation = executionResult.gasUsedInValidation; 64 | 65 | // _log[userOpHash].gasValidation = executionResult.gasUsedInValidation; 66 | _log[userOpHash].gasExecution = gasExecution; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579HookBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { IHook as IERC7579Hook } from "../accounts/common/interfaces/IERC7579Module.sol"; 5 | import { ERC7579ModuleBase } from "./ERC7579ModuleBase.sol"; 6 | import { TrustedForwarder } from "./utils/TrustedForwarder.sol"; 7 | 8 | abstract contract ERC7579HookBase is IERC7579Hook, ERC7579ModuleBase, TrustedForwarder { 9 | /** 10 | * Precheck hook 11 | * 12 | * @param msgSender sender of the transaction 13 | * @param msgValue value of the transaction 14 | * @param msgData data of the transaction 15 | * 16 | * @return hookData data for the postcheck hook 17 | */ 18 | function preCheck( 19 | address msgSender, 20 | uint256 msgValue, 21 | bytes calldata msgData 22 | ) 23 | external 24 | virtual 25 | returns (bytes memory hookData) 26 | { 27 | // route to internal function 28 | return _preCheck(_getAccount(), msgSender, msgValue, msgData); 29 | } 30 | 31 | /** 32 | * Postcheck hook 33 | * 34 | * @param hookData data from the precheck hook 35 | */ 36 | function postCheck(bytes calldata hookData) external virtual { 37 | // route to internal function 38 | _postCheck(_getAccount(), hookData); 39 | } 40 | 41 | /** 42 | * Precheck hook 43 | * 44 | * @param account account of the transaction 45 | * @param msgSender sender of the transaction 46 | * @param msgValue value of the transaction 47 | * @param msgData data of the transaction 48 | * 49 | * @return hookData data for the postcheck hook 50 | */ 51 | function _preCheck( 52 | address account, 53 | address msgSender, 54 | uint256 msgValue, 55 | bytes calldata msgData 56 | ) 57 | internal 58 | virtual 59 | returns (bytes memory hookData); 60 | 61 | /** 62 | * Postcheck hook 63 | * 64 | * @param account account of the transaction 65 | * @param hookData data from the precheck hook 66 | */ 67 | function _postCheck(address account, bytes calldata hookData) internal virtual; 68 | } 69 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aave/ILendingPoolAddressesProvider.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract ILendingPoolAddressesProvider { 6 | function getLendingPool() public view virtual returns (address); 7 | 8 | function setLendingPoolImpl(address _pool) public virtual; 9 | 10 | function getLendingPoolCore() public view virtual returns (address payable); 11 | 12 | function setLendingPoolCoreImpl(address _lendingPoolCore) public virtual; 13 | 14 | function getLendingPoolConfigurator() public view virtual returns (address); 15 | 16 | function setLendingPoolConfiguratorImpl(address _configurator) public virtual; 17 | 18 | function getLendingPoolDataProvider() public view virtual returns (address); 19 | 20 | function setLendingPoolDataProviderImpl(address _provider) public virtual; 21 | 22 | function getLendingPoolParametersProvider() public view virtual returns (address); 23 | 24 | function setLendingPoolParametersProviderImpl(address _parametersProvider) public virtual; 25 | 26 | function getTokenDistributor() public view virtual returns (address); 27 | 28 | function setTokenDistributor(address _tokenDistributor) public virtual; 29 | 30 | function getFeeProvider() public view virtual returns (address); 31 | 32 | function setFeeProviderImpl(address _feeProvider) public virtual; 33 | 34 | function getLendingPoolLiquidationManager() public view virtual returns (address); 35 | 36 | function setLendingPoolLiquidationManager(address _manager) public virtual; 37 | 38 | function getLendingPoolManager() public view virtual returns (address); 39 | 40 | function setLendingPoolManager(address _lendingPoolManager) public virtual; 41 | 42 | function getPriceOracle() public view virtual returns (address); 43 | 44 | function setPriceOracle(address _priceOracle) public virtual; 45 | 46 | function getLendingRateOracle() public view virtual returns (address); 47 | 48 | function setLendingRateOracle(address _lendingRateOracle) public virtual; 49 | } 50 | 51 | library EthAddressLib { 52 | function ethAddress() internal pure returns (address) { 53 | return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/deployment/registry/interfaces/IExternalResolver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | // Interfaces 5 | import { IERC165 } from "forge-std/interfaces/IERC165.sol"; 6 | 7 | // Types 8 | import { AttestationRecord, ModuleRecord } from "../types/DataTypes.sol"; 9 | 10 | /** 11 | * @title The interface of an optional schema resolver. 12 | * @dev The resolver is responsible for validating the schema and attestation data. 13 | * @dev The resolver is also responsible for processing the attestation and revocation requests. 14 | * 15 | */ 16 | interface IExternalResolver is IERC165 { 17 | /** 18 | * @dev Processes an attestation and verifies whether it's valid. 19 | * 20 | * @param attestation The new attestation. 21 | * 22 | * @return Whether the attestation is valid. 23 | */ 24 | function resolveAttestation(AttestationRecord calldata attestation) 25 | external 26 | payable 27 | returns (bool); 28 | 29 | function resolveAttestation(AttestationRecord[] calldata attestation) 30 | external 31 | payable 32 | returns (bool); 33 | 34 | /** 35 | * @dev Processes an attestation revocation and verifies if it can be revoked. 36 | * 37 | * @param attestation The existing attestation to be revoked. 38 | * 39 | * @return Whether the attestation can be revoked. 40 | */ 41 | function resolveRevocation(AttestationRecord calldata attestation) 42 | external 43 | payable 44 | returns (bool); 45 | function resolveRevocation(AttestationRecord[] calldata attestation) 46 | external 47 | payable 48 | returns (bool); 49 | 50 | /** 51 | * @dev Processes a Module Registration 52 | * 53 | * @param sender The msg.sender of the module registration 54 | * @param moduleAddress address of the module 55 | * @param record Module registration artefact 56 | * 57 | * @return Whether the registration is valid 58 | */ 59 | function resolveModuleRegistration( 60 | address sender, 61 | address moduleAddress, 62 | ModuleRecord calldata record, 63 | bytes calldata resolverContext 64 | ) 65 | external 66 | payable 67 | returns (bool); 68 | } 69 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579ValidatorBase.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { 5 | PackedUserOperation, 6 | _packValidationData as _packValidationData4337 7 | } from "../external/ERC4337.sol"; 8 | import { ERC7579ModuleBase } from "./ERC7579ModuleBase.sol"; 9 | 10 | abstract contract ERC7579ValidatorBase is ERC7579ModuleBase { 11 | type ValidationData is uint256; 12 | 13 | ValidationData internal constant VALIDATION_SUCCESS = ValidationData.wrap(0); 14 | ValidationData internal constant VALIDATION_FAILED = ValidationData.wrap(1); 15 | bytes4 internal constant EIP1271_SUCCESS = 0x1626ba7e; 16 | bytes4 internal constant EIP1271_FAILED = 0xFFFFFFFF; 17 | 18 | /** 19 | * Helper to pack the return value for validateUserOp, when not using an aggregator. 20 | * @param sigFailed - True for signature failure, false for success. 21 | * @param validUntil - Last timestamp this UserOperation is valid (or zero for 22 | * infinite). 23 | * @param validAfter - First timestamp this UserOperation is valid. 24 | */ 25 | function _packValidationData( 26 | bool sigFailed, 27 | uint48 validUntil, 28 | uint48 validAfter 29 | ) 30 | internal 31 | pure 32 | returns (ValidationData) 33 | { 34 | return ValidationData.wrap(_packValidationData4337(sigFailed, validUntil, validAfter)); 35 | } 36 | 37 | function _unpackValidationData(ValidationData _packedData) 38 | internal 39 | pure 40 | returns (bool sigFailed, uint48 validUntil, uint48 validAfter) 41 | { 42 | uint256 packedData = ValidationData.unwrap(_packedData); 43 | sigFailed = (packedData & 1) == 1; 44 | validUntil = uint48((packedData >> 160) & ((1 << 48) - 1)); 45 | validAfter = uint48((packedData >> (160 + 48)) & ((1 << 48) - 1)); 46 | } 47 | 48 | function validateUserOp( 49 | PackedUserOperation calldata userOp, 50 | bytes32 userOpHash 51 | ) 52 | external 53 | virtual 54 | returns (ValidationData); 55 | 56 | function isValidSignatureWithSender( 57 | address sender, 58 | bytes32 hash, 59 | bytes calldata data 60 | ) 61 | external 62 | view 63 | virtual 64 | returns (bytes4); 65 | } 66 | -------------------------------------------------------------------------------- /src/integrations/interfaces/exchange/IKyberNetworkProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "../IERC20.sol"; 6 | 7 | abstract contract KyberNetworkProxyInterface { 8 | function maxGasPrice() external view virtual returns (uint256); 9 | 10 | function getUserCapInWei(address user) external view virtual returns (uint256); 11 | 12 | function getUserCapInTokenWei( 13 | address user, 14 | IERC20 token 15 | ) 16 | external 17 | view 18 | virtual 19 | returns (uint256); 20 | 21 | function enabled() external view virtual returns (bool); 22 | 23 | function info(bytes32 id) external view virtual returns (uint256); 24 | 25 | function getExpectedRate( 26 | IERC20 src, 27 | IERC20 dest, 28 | uint256 srcQty 29 | ) 30 | public 31 | view 32 | virtual 33 | returns (uint256 expectedRate, uint256 slippageRate); 34 | 35 | function tradeWithHint( 36 | IERC20 src, 37 | uint256 srcAmount, 38 | IERC20 dest, 39 | address destAddress, 40 | uint256 maxDestAmount, 41 | uint256 minConversionRate, 42 | address walletId, 43 | bytes memory hint 44 | ) 45 | public 46 | payable 47 | virtual 48 | returns (uint256); 49 | 50 | function trade( 51 | IERC20 src, 52 | uint256 srcAmount, 53 | IERC20 dest, 54 | address destAddress, 55 | uint256 maxDestAmount, 56 | uint256 minConversionRate, 57 | address walletId 58 | ) 59 | public 60 | payable 61 | virtual 62 | returns (uint256); 63 | 64 | function swapEtherToToken( 65 | IERC20 token, 66 | uint256 minConversionRate 67 | ) 68 | external 69 | payable 70 | virtual 71 | returns (uint256); 72 | 73 | function swapTokenToEther( 74 | IERC20 token, 75 | uint256 tokenQty, 76 | uint256 minRate 77 | ) 78 | external 79 | payable 80 | virtual 81 | returns (uint256); 82 | 83 | function swapTokenToToken( 84 | IERC20 src, 85 | uint256 srcAmount, 86 | IERC20 dest, 87 | uint256 minConversionRate 88 | ) 89 | public 90 | virtual 91 | returns (uint256); 92 | } 93 | -------------------------------------------------------------------------------- /src/module-bases/ERC7579ValidatorMaster.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | import { 5 | PackedUserOperation, 6 | _packValidationData as _packValidationData4337 7 | } from "../external/ERC4337.sol"; 8 | import { ERC7579ModuleBase } from "./ERC7579ModuleBase.sol"; 9 | 10 | abstract contract ERC7579ValidatorBase is ERC7579ModuleBase { 11 | type ValidationData is uint256; 12 | 13 | ValidationData internal constant VALIDATION_FAILED = ValidationData.wrap(1); 14 | bytes4 internal constant EIP1271_SUCCESS = 0x1626ba7e; 15 | bytes4 internal constant EIP1271_FAILED = 0xFFFFFFFF; 16 | 17 | modifier notInitialized() virtual; 18 | modifier alreadyInitialized() virtual; 19 | 20 | // Modules may be intalled without being added to the account 21 | function onInstall(bytes calldata data) external virtual override notInitialized { 22 | _onInstall(data); 23 | } 24 | 25 | function onUninstall(bytes calldata data) external virtual override alreadyInitialized { 26 | _onUninstall(data); 27 | } 28 | 29 | function _onInstall(bytes calldata data) internal virtual; 30 | function _onUninstall(bytes calldata data) internal virtual; 31 | 32 | /** 33 | * Helper to pack the return value for validateUserOp, when not using an aggregator. 34 | * @param sigFailed - True for signature failure, false for success. 35 | * @param validUntil - Last timestamp this UserOperation is valid (or zero for 36 | * infinite). 37 | * @param validAfter - First timestamp this UserOperation is valid. 38 | */ 39 | function _packValidationData( 40 | bool sigFailed, 41 | uint48 validUntil, 42 | uint48 validAfter 43 | ) 44 | internal 45 | pure 46 | returns (ValidationData) 47 | { 48 | return ValidationData.wrap(_packValidationData4337(sigFailed, validUntil, validAfter)); 49 | } 50 | 51 | function validateUserOp( 52 | PackedUserOperation calldata userOp, 53 | bytes32 userOpHash 54 | ) 55 | external 56 | virtual 57 | returns (ValidationData); 58 | 59 | function isValidSignatureWithSender( 60 | address sender, 61 | bytes32 hash, 62 | bytes calldata data 63 | ) 64 | external 65 | view 66 | virtual 67 | returns (bytes4); 68 | } 69 | -------------------------------------------------------------------------------- /src/Modules.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | /*////////////////////////////////////////////////////////////// 7 | INTERFACES 8 | //////////////////////////////////////////////////////////////*/ 9 | 10 | import { 11 | IValidator as IERC7579Validator, 12 | IExecutor as IERC7579Executor, 13 | IFallback as IERC7579Fallback, 14 | IHook as IERC7579Hook, 15 | IModule as IERC7579Module 16 | } from "./accounts/common/interfaces/IERC7579Module.sol"; 17 | 18 | /*////////////////////////////////////////////////////////////// 19 | BASES 20 | //////////////////////////////////////////////////////////////*/ 21 | 22 | // Core 23 | import { ERC7579ModuleBase } from "./module-bases/ERC7579ModuleBase.sol"; 24 | 25 | // Validators 26 | import { ERC7579ValidatorBase } from "./module-bases/ERC7579ValidatorBase.sol"; 27 | import { ERC7579StatelessValidatorBase } from "./module-bases/ERC7579StatelessValidatorBase.sol"; 28 | import { ERC7579HybridValidatorBase } from "./module-bases/ERC7579HybridValidatorBase.sol"; 29 | 30 | // Executors 31 | import { ERC7579ExecutorBase } from "./module-bases/ERC7579ExecutorBase.sol"; 32 | 33 | // Hooks 34 | import { ERC7579HookBase } from "./module-bases/ERC7579HookBase.sol"; 35 | import { ERC7579HookDestruct } from "./module-bases/ERC7579HookDestruct.sol"; 36 | import { ERC7579HookDestructSingleHook } from "./module-bases/ERC7579HookDestructSingleHook.sol"; 37 | 38 | // Fallbacks 39 | import { ERC7579FallbackBase } from "./module-bases/ERC7579FallbackBase.sol"; 40 | 41 | // Misc 42 | import { SchedulingBase } from "./module-bases/SchedulingBase.sol"; 43 | import { ERC7484RegistryAdapter } from "./module-bases/ERC7484RegistryAdapter.sol"; 44 | 45 | // Policies 46 | import { ERC7579PolicyBase } from "./module-bases/ERC7579PolicyBase.sol"; 47 | import { ERC1271Policy } from "./module-bases/ERC1271Policy.sol"; 48 | import { ERC7579ActionPolicy } from "./module-bases/ERC7579ActionPolicy.sol"; 49 | import { ERC7579UserOpPolicy } from "./module-bases/ERC7579UserOpPolicy.sol"; 50 | 51 | /*////////////////////////////////////////////////////////////// 52 | UTIL 53 | //////////////////////////////////////////////////////////////*/ 54 | 55 | import { TrustedForwarder } from "./module-bases/utils/TrustedForwarder.sol"; 56 | -------------------------------------------------------------------------------- /src/accounts/nexus/interfaces/INexus.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // ────────────────────────────────────────────────────────────────────────────── 5 | // _ __ _ __ 6 | // / | / /__ | |/ /_ _______ 7 | // / |/ / _ \| / / / / ___/ 8 | // / /| / __/ / /_/ (__ ) 9 | // /_/ |_/\___/_/|_\__,_/____/ 10 | // 11 | // ────────────────────────────────────────────────────────────────────────────── 12 | // Nexus: A suite of contracts for Modular Smart Accounts compliant with ERC-7579 and ERC-4337, 13 | // developed by Biconomy. 14 | // Learn more at https://biconomy.io. To report security issues, please contact us at: 15 | // security@biconomy.io 16 | 17 | import { IERC4337Account } from "../../common/interfaces/IERC4337Account.sol"; 18 | import { IERC7579Account } from "../../common/interfaces/IERC7579Account.sol"; 19 | 20 | /// @title Nexus - INexus Interface 21 | /// @notice Integrates ERC-4337 and ERC-7579 standards to manage smart accounts within the Nexus 22 | /// suite. 23 | /// @dev Consolidates ERC-4337 user operations and ERC-7579 configurations into a unified interface 24 | /// for smart account management. 25 | /// It extends both IERC4337Account and IERC7579Account, enhancing modular capabilities and 26 | /// supporting advanced contract architectures. 27 | /// Includes error definitions for robust handling of common issues such as unsupported module types 28 | /// and execution failures. 29 | /// The initialize function sets up the account with validators and configurations, ensuring 30 | /// readiness for use. 31 | /// @author @livingrockrises | Biconomy | chirag@biconomy.io 32 | /// @author @aboudjem | Biconomy | adam.boudjemaa@biconomy.io 33 | /// @author @filmakarov | Biconomy | filipp.makarov@biconomy.io 34 | /// @author @zeroknots | Rhinestone.wtf | zeroknots.eth 35 | /// Special thanks to the Solady team for foundational contributions: 36 | /// https://github.com/Vectorized/solady 37 | interface INexus is IERC4337Account, IERC7579Account { 38 | /// @notice Initializes the smart account with a validator and custom data. 39 | /// @dev This method sets up the account for operation, linking it with a validator and 40 | /// initializing it with specific data. 41 | /// Can be called directly or via a factory. 42 | /// @param initData Encoded data used for the account's configuration during initialization. 43 | function initializeAccount(bytes calldata initData) external payable; 44 | } 45 | -------------------------------------------------------------------------------- /src/accounts/kernel/mock/MockFallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | /* solhint-disable no-unused-import */ 5 | 6 | // Interfaces 7 | import { IERC7579Account } from "../interfaces/IERC7579Account.sol"; 8 | import { IFallback } from "../interfaces/IERC7579Module.sol"; 9 | 10 | // Types 11 | import { CallType, ExecType, ExecMode, ExecLib } from "../lib/ExecLib.sol"; 12 | import { EXEC_MODE_DEFAULT } from "../types/Constants.sol"; 13 | 14 | contract Callee { 15 | address public lastCaller; 16 | 17 | function calleeTest() external { 18 | lastCaller = msg.sender; 19 | } 20 | } 21 | 22 | contract MockFallback is IFallback { 23 | mapping(address account => bytes accountData) public data; 24 | 25 | uint256 public valueStored; 26 | 27 | bool public isExecutor; 28 | 29 | Callee public callee; 30 | 31 | constructor() { 32 | callee = new Callee(); 33 | } 34 | 35 | function setExecutorMode(bool _isExecutor) external payable { 36 | isExecutor = _isExecutor; 37 | } 38 | 39 | function onInstall(bytes calldata _data) external payable override { 40 | data[msg.sender] = _data; 41 | } 42 | 43 | function onUninstall(bytes calldata) external payable override { 44 | delete data[msg.sender]; 45 | } 46 | 47 | function isModuleType(uint256 moduleTypeId) external view override returns (bool) { 48 | return moduleTypeId == 3 || (isExecutor && moduleTypeId == 2); 49 | } 50 | 51 | function isInitialized(address smartAccount) external view override returns (bool) { 52 | return data[smartAccount].length > 0; 53 | } 54 | 55 | function fallbackFunction(uint256 v) external pure returns (uint256) { 56 | return v * v; 57 | } 58 | 59 | function getData() external view returns (bytes memory) { 60 | return data[msg.sender]; 61 | } 62 | 63 | function getCaller() external pure returns (address) { 64 | return address(bytes20(msg.data[msg.data.length - 20:])); 65 | } 66 | 67 | function setData(uint256 value) external { 68 | valueStored = value; 69 | if (isExecutor) { 70 | IERC7579Account(msg.sender).executeFromExecutor( 71 | ExecLib.encodeSimpleSingle(), 72 | ExecLib.encodeSingle( 73 | address(callee), 0, abi.encodeWithSelector(Callee.calleeTest.selector) 74 | ) 75 | ); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV2/IAaveProtocolDataProviderV2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | abstract contract IAaveProtocolDataProviderV2 { 6 | struct TokenData { 7 | string symbol; 8 | address tokenAddress; 9 | } 10 | 11 | function getAllReservesTokens() external view virtual returns (TokenData[] memory); 12 | 13 | function getAllATokens() external view virtual returns (TokenData[] memory); 14 | 15 | function getReserveConfigurationData(address asset) 16 | external 17 | view 18 | virtual 19 | returns ( 20 | uint256 decimals, 21 | uint256 ltv, 22 | uint256 liquidationThreshold, 23 | uint256 liquidationBonus, 24 | uint256 reserveFactor, 25 | bool usageAsCollateralEnabled, 26 | bool borrowingEnabled, 27 | bool stableBorrowRateEnabled, 28 | bool isActive, 29 | bool isFrozen 30 | ); 31 | 32 | function getReserveData(address asset) 33 | external 34 | view 35 | virtual 36 | returns ( 37 | uint256 availableLiquidity, 38 | uint256 totalStableDebt, 39 | uint256 totalVariableDebt, 40 | uint256 liquidityRate, 41 | uint256 variableBorrowRate, 42 | uint256 stableBorrowRate, 43 | uint256 averageStableBorrowRate, 44 | uint256 liquidityIndex, 45 | uint256 variableBorrowIndex, 46 | uint40 lastUpdateTimestamp 47 | ); 48 | 49 | function getUserReserveData( 50 | address asset, 51 | address user 52 | ) 53 | external 54 | view 55 | virtual 56 | returns ( 57 | uint256 currentATokenBalance, 58 | uint256 currentStableDebt, 59 | uint256 currentVariableDebt, 60 | uint256 principalStableDebt, 61 | uint256 scaledVariableDebt, 62 | uint256 stableBorrowRate, 63 | uint256 liquidityRate, 64 | uint40 stableRateLastUpdated, 65 | bool usageAsCollateralEnabled 66 | ); 67 | 68 | function getReserveTokensAddresses(address asset) 69 | external 70 | view 71 | virtual 72 | returns ( 73 | address aTokenAddress, 74 | address stableDebtTokenAddress, 75 | address variableDebtTokenAddress 76 | ); 77 | } 78 | -------------------------------------------------------------------------------- /src/integrations/interfaces/compound/ICToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | import "../IERC20.sol"; 6 | 7 | abstract contract ICToken is IERC20 { 8 | function mint(uint256 mintAmount) external virtual returns (uint256); 9 | function mint() external payable virtual; 10 | 11 | function accrueInterest() public virtual returns (uint256); 12 | 13 | function redeem(uint256 redeemTokens) external virtual returns (uint256); 14 | 15 | function redeemUnderlying(uint256 redeemAmount) external virtual returns (uint256); 16 | 17 | function borrow(uint256 borrowAmount) external virtual returns (uint256); 18 | function borrowIndex() public view virtual returns (uint256); 19 | function borrowBalanceStored(address) public view virtual returns (uint256); 20 | 21 | function repayBorrow(uint256 repayAmount) external virtual returns (uint256); 22 | 23 | function repayBorrow() external payable virtual; 24 | 25 | function repayBorrowBehalf( 26 | address borrower, 27 | uint256 repayAmount 28 | ) 29 | external 30 | virtual 31 | returns (uint256); 32 | 33 | function repayBorrowBehalf(address borrower) external payable virtual; 34 | 35 | function liquidateBorrow( 36 | address borrower, 37 | uint256 repayAmount, 38 | address cTokenCollateral 39 | ) 40 | external 41 | virtual 42 | returns (uint256); 43 | 44 | function liquidateBorrow(address borrower, address cTokenCollateral) external payable virtual; 45 | 46 | function exchangeRateCurrent() external virtual returns (uint256); 47 | 48 | function supplyRatePerBlock() external virtual returns (uint256); 49 | 50 | function borrowRatePerBlock() external virtual returns (uint256); 51 | 52 | function totalReserves() external virtual returns (uint256); 53 | 54 | function reserveFactorMantissa() external virtual returns (uint256); 55 | 56 | function borrowBalanceCurrent(address account) external virtual returns (uint256); 57 | 58 | function totalBorrowsCurrent() external virtual returns (uint256); 59 | 60 | function getCash() external virtual returns (uint256); 61 | 62 | function balanceOfUnderlying(address owner) external virtual returns (uint256); 63 | 64 | function underlying() external virtual returns (address); 65 | 66 | function getAccountSnapshot(address account) 67 | external 68 | view 69 | virtual 70 | returns (uint256, uint256, uint256, uint256); 71 | } 72 | -------------------------------------------------------------------------------- /test/mocks/MockK1ValidatorUncompliantUninstall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | import { 5 | IValidator, 6 | VALIDATION_SUCCESS, 7 | VALIDATION_FAILED, 8 | MODULE_TYPE_VALIDATOR 9 | } from "src/accounts/common/interfaces/IERC7579Module.sol"; 10 | import { PackedUserOperation } from "src/external/ERC4337.sol"; 11 | import { ECDSA } from "solady/utils/ECDSA.sol"; 12 | import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; 13 | import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; 14 | import { EIP1271_MAGIC_VALUE, IERC1271 } from "src/module-bases/interfaces/IERC1271.sol"; 15 | 16 | contract MockK1ValidatorUncompliantUninstall is IValidator { 17 | bytes4 constant ERC1271_INVALID = 0xffffffff; 18 | mapping(address => address) public smartAccountOwners; 19 | 20 | function validateUserOp( 21 | PackedUserOperation calldata userOp, 22 | bytes32 userOpHash 23 | ) 24 | external 25 | payable 26 | returns (uint256 validation) 27 | { 28 | return ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(userOpHash), userOp.signature) 29 | == smartAccountOwners[msg.sender] ? VALIDATION_SUCCESS : VALIDATION_FAILED; 30 | } 31 | 32 | function isValidSignatureWithSender( 33 | address, 34 | bytes32 hash, 35 | bytes calldata signature 36 | ) 37 | external 38 | view 39 | returns (bytes4) 40 | { 41 | return ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(hash), signature) 42 | == smartAccountOwners[msg.sender] ? EIP1271_MAGIC_VALUE : ERC1271_INVALID; 43 | } 44 | 45 | function onInstall(bytes calldata data) external { 46 | address owner = abi.decode(data, (address)); 47 | smartAccountOwners[msg.sender] = owner; 48 | } 49 | 50 | function onUninstall(bytes calldata data) external pure { 51 | data; 52 | } 53 | 54 | function isModuleType(uint256 moduleTypeId) external pure returns (bool) { 55 | return moduleTypeId == MODULE_TYPE_VALIDATOR; 56 | } 57 | 58 | function isOwner(address account, address owner) external view returns (bool) { 59 | return smartAccountOwners[account] == owner; 60 | } 61 | 62 | function isInitialized(address) external pure returns (bool) { 63 | return false; 64 | } 65 | 66 | function getOwner(address account) external view returns (address) { 67 | return smartAccountOwners[account]; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /test/mocks/MockK1Validator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | import { 5 | IValidator, 6 | VALIDATION_SUCCESS, 7 | VALIDATION_FAILED, 8 | MODULE_TYPE_VALIDATOR 9 | } from "src/accounts/common/interfaces/IERC7579Module.sol"; 10 | import { PackedUserOperation } from "src/external/ERC4337.sol"; 11 | import { ECDSA } from "solady/utils/ECDSA.sol"; 12 | import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; 13 | import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; 14 | import { EIP1271_MAGIC_VALUE, IERC1271 } from "src/module-bases/interfaces/IERC1271.sol"; 15 | 16 | contract MockK1Validator is IValidator { 17 | bytes4 constant ERC1271_INVALID = 0xffffffff; 18 | mapping(address => address) public smartAccountOwners; 19 | 20 | function validateUserOp( 21 | PackedUserOperation calldata userOp, 22 | bytes32 userOpHash 23 | ) 24 | external 25 | payable 26 | returns (uint256 validation) 27 | { 28 | return ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(userOpHash), userOp.signature) 29 | == smartAccountOwners[msg.sender] ? VALIDATION_SUCCESS : VALIDATION_FAILED; 30 | } 31 | 32 | function isValidSignatureWithSender( 33 | address, 34 | bytes32 hash, 35 | bytes calldata signature 36 | ) 37 | external 38 | view 39 | returns (bytes4) 40 | { 41 | return ECDSA.recover(MessageHashUtils.toEthSignedMessageHash(hash), signature) 42 | == smartAccountOwners[msg.sender] ? EIP1271_MAGIC_VALUE : ERC1271_INVALID; 43 | } 44 | 45 | function onInstall(bytes calldata data) external { 46 | address owner = abi.decode(data, (address)); 47 | smartAccountOwners[msg.sender] = owner; 48 | } 49 | 50 | function onUninstall(bytes calldata data) external { 51 | data; 52 | delete smartAccountOwners[msg.sender]; 53 | } 54 | 55 | function isModuleType(uint256 moduleTypeId) external pure returns (bool) { 56 | return moduleTypeId == MODULE_TYPE_VALIDATOR; 57 | } 58 | 59 | function isOwner(address account, address owner) external view returns (bool) { 60 | return smartAccountOwners[account] == owner; 61 | } 62 | 63 | function isInitialized(address) external pure returns (bool) { 64 | return false; 65 | } 66 | 67 | function getOwner(address account) external view returns (address) { 68 | return smartAccountOwners[account]; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/integrations/interfaces/liquity/IBorrowerOperations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.10; 4 | 5 | // Common interface for the Trove Manager. 6 | interface IBorrowerOperations { 7 | // --- Events --- 8 | 9 | event TroveManagerAddressChanged(address _newTroveManagerAddress); 10 | event ActivePoolAddressChanged(address _activePoolAddress); 11 | event DefaultPoolAddressChanged(address _defaultPoolAddress); 12 | event StabilityPoolAddressChanged(address _stabilityPoolAddress); 13 | event GasPoolAddressChanged(address _gasPoolAddress); 14 | event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress); 15 | event PriceFeedAddressChanged(address _newPriceFeedAddress); 16 | event SortedTrovesAddressChanged(address _sortedTrovesAddress); 17 | event LUSDTokenAddressChanged(address _lusdTokenAddress); 18 | event LQTYStakingAddressChanged(address _lqtyStakingAddress); 19 | 20 | event TroveCreated(address indexed _borrower, uint256 arrayIndex); 21 | event TroveUpdated( 22 | address indexed _borrower, uint256 _debt, uint256 _coll, uint256 stake, uint8 operation 23 | ); 24 | event LUSDBorrowingFeePaid(address indexed _borrower, uint256 _LUSDFee); 25 | 26 | // --- Functions --- 27 | 28 | function openTrove( 29 | uint256 _maxFee, 30 | uint256 _LUSDAmount, 31 | address _upperHint, 32 | address _lowerHint 33 | ) 34 | external 35 | payable; 36 | 37 | function addColl(address _upperHint, address _lowerHint) external payable; 38 | 39 | function moveETHGainToTrove( 40 | address _user, 41 | address _upperHint, 42 | address _lowerHint 43 | ) 44 | external 45 | payable; 46 | 47 | function withdrawColl(uint256 _amount, address _upperHint, address _lowerHint) external; 48 | 49 | function withdrawLUSD( 50 | uint256 _maxFee, 51 | uint256 _amount, 52 | address _upperHint, 53 | address _lowerHint 54 | ) 55 | external; 56 | 57 | function repayLUSD(uint256 _amount, address _upperHint, address _lowerHint) external; 58 | 59 | function closeTrove() external; 60 | 61 | function adjustTrove( 62 | uint256 _maxFee, 63 | uint256 _collWithdrawal, 64 | uint256 _debtChange, 65 | bool isDebtIncrease, 66 | address _upperHint, 67 | address _lowerHint 68 | ) 69 | external 70 | payable; 71 | 72 | function claimCollateral() external; 73 | 74 | function getCompositeDebt(uint256 _debt) external pure returns (uint256); 75 | } 76 | -------------------------------------------------------------------------------- /src/test/Auxiliary.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.23 <0.9.0; 3 | 4 | // Interfaces 5 | import { IEntryPoint, PackedUserOperation } from "../external/ERC4337.sol"; 6 | import { IERC7579Bootstrap } from "../accounts/erc7579/interfaces/IERC7579Bootstrap.sol"; 7 | import { IERC7484 } from "../Interfaces.sol"; 8 | import { ISmartSession } from "../integrations/interfaces/ISmartSession.sol"; 9 | 10 | // Deployments 11 | import { etchEntrypoint } from "../deployment/predeploy/EntryPoint.sol"; 12 | import { etchSmartSessions } from "../deployment/precompiles/SmartSessionsPrecompiles.sol"; 13 | import { etchRegistry } from "../deployment/predeploy/Registry.sol"; 14 | 15 | // External Dependencies 16 | import { EntryPointSimulations } from 17 | "@ERC4337/account-abstraction/contracts/core/EntryPointSimulations.sol"; 18 | import { IEntryPointSimulations } from 19 | "@ERC4337/account-abstraction/contracts/interfaces/IEntryPointSimulations.sol"; 20 | 21 | // Mocks 22 | import { MockFactory } from "../deployment/predeploy/MockFactory.sol"; 23 | 24 | // Utils 25 | import { UserOpGasLog } from "./utils/gas/UserOpGasLog.sol"; 26 | import "./utils/Vm.sol"; 27 | import "./utils/Log.sol"; 28 | 29 | /// @notice Auxiliary structs to hold all the necessary auxiliary contracts for testing. 30 | /// @param entrypoint The entrypoint contract. 31 | /// @param gasSimulation The gas simulation contract. 32 | /// @param registry The registry contract. 33 | /// @param mockFactory The mock factory contract. 34 | /// @param smartSession The smart session contract. 35 | struct Auxiliary { 36 | IEntryPoint entrypoint; 37 | UserOpGasLog gasSimulation; 38 | IERC7484 registry; 39 | MockFactory mockFactory; 40 | ISmartSession smartSession; 41 | } 42 | 43 | /// @notice Auxiliary factory to deploy all the necessary auxiliary contracts for testing. 44 | contract AuxiliaryFactory { 45 | /// @notice Stores the auxiliary contracts. 46 | Auxiliary public auxiliary; 47 | 48 | /// @notice Initializes and labels all the auxiliary contracts. 49 | function init() internal virtual { 50 | auxiliary.mockFactory = new MockFactory(); 51 | label(address(auxiliary.mockFactory), "Mock Factory"); 52 | auxiliary.gasSimulation = new UserOpGasLog(); 53 | auxiliary.entrypoint = etchEntrypoint(); 54 | label(address(auxiliary.entrypoint), "EntryPoint"); 55 | auxiliary.registry = etchRegistry(); 56 | label(address(auxiliary.registry), "ERC7484Registry"); 57 | auxiliary.smartSession = etchSmartSessions(); 58 | label(address(auxiliary.smartSession), "SmartSession"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/integrations/interfaces/aaveV3/IAaveV3Oracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.10; 3 | 4 | import { IPriceOracleGetter } from "./IPriceOracleGetter.sol"; 5 | import { IPoolAddressesProvider } from "./IPoolAddressesProvider.sol"; 6 | 7 | interface IAaveV3Oracle is IPriceOracleGetter { 8 | /** 9 | * @dev Emitted after the base currency is set 10 | * @param baseCurrency The base currency of used for price quotes 11 | * @param baseCurrencyUnit The unit of the base currency 12 | */ 13 | event BaseCurrencySet(address indexed baseCurrency, uint256 baseCurrencyUnit); 14 | 15 | /** 16 | * @dev Emitted after the price source of an asset is updated 17 | * @param asset The address of the asset 18 | * @param source The price source of the asset 19 | */ 20 | event AssetSourceUpdated(address indexed asset, address indexed source); 21 | 22 | /** 23 | * @dev Emitted after the address of fallback oracle is updated 24 | * @param fallbackOracle The address of the fallback oracle 25 | */ 26 | event FallbackOracleUpdated(address indexed fallbackOracle); 27 | 28 | /** 29 | * @notice Returns the PoolAddressesProvider 30 | * @return The address of the PoolAddressesProvider contract 31 | */ 32 | function ADDRESSES_PROVIDER() external view returns (IPoolAddressesProvider); 33 | 34 | /** 35 | * @notice Sets or replaces price sources of assets 36 | * @param assets The addresses of the assets 37 | * @param sources The addresses of the price sources 38 | */ 39 | function setAssetSources(address[] calldata assets, address[] calldata sources) external; 40 | 41 | /** 42 | * @notice Sets the fallback oracle 43 | * @param fallbackOracle The address of the fallback oracle 44 | */ 45 | function setFallbackOracle(address fallbackOracle) external; 46 | 47 | /** 48 | * @notice Returns a list of prices from a list of assets addresses 49 | * @param assets The list of assets addresses 50 | * @return The prices of the given assets 51 | */ 52 | function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory); 53 | 54 | /** 55 | * @notice Returns the address of the source for an asset address 56 | * @param asset The address of the asset 57 | * @return The address of the source 58 | */ 59 | function getSourceOfAsset(address asset) external view returns (address); 60 | 61 | /** 62 | * @notice Returns the address of the fallback oracle 63 | * @return The address of the fallback oracle 64 | */ 65 | function getFallbackOracle() external view returns (address); 66 | } 67 | -------------------------------------------------------------------------------- /src/module-bases/interfaces/Flashloan.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0 <0.9.0; 3 | 4 | enum FlashLoanType { 5 | ERC20, 6 | ERC721 7 | } 8 | 9 | interface IERC6682 { 10 | function flashFeeToken() external view returns (address); 11 | function flashFee(address token, uint256 tokenId) external view returns (uint256); 12 | function availableForFlashLoan(address token, uint256 tokenId) external view returns (bool); 13 | } 14 | 15 | /** 16 | * @dev Interface of the ERC3156 FlashLender, as defined in 17 | * https://eips.ethereum.org/EIPS/eip-3156. 18 | */ 19 | interface IERC3156FlashLender { 20 | /** 21 | * @dev The amount of currency available to be lended. 22 | * @param token The loan currency. 23 | * @return The amount of `token` that can be borrowed. 24 | */ 25 | function maxFlashLoan(address token) external view returns (uint256); 26 | 27 | /** 28 | * @dev The fee to be charged for a given loan. 29 | * @param token The loan currency. 30 | * @param amount The amount of tokens lent. 31 | * @return The amount of `token` to be charged for the loan, on top of the returned principal. 32 | */ 33 | function flashFee(address token, uint256 amount) external view returns (uint256); 34 | 35 | /** 36 | * @dev Initiate a flash loan. 37 | * @param receiver The receiver of the tokens in the loan, and the receiver of the callback. 38 | * @param token The loan currency. 39 | * @param amount The amount of tokens lent. 40 | * @param data Arbitrary data structure, intended to contain user-defined parameters. 41 | */ 42 | function flashLoan( 43 | IERC3156FlashBorrower receiver, 44 | address token, 45 | uint256 amount, 46 | bytes calldata data 47 | ) 48 | external 49 | returns (bool); 50 | } 51 | 52 | /** 53 | * @dev Interface of the ERC3156 FlashBorrower, as defined in 54 | * https://eips.ethereum.org/EIPS/eip-3156. 55 | */ 56 | interface IERC3156FlashBorrower { 57 | /** 58 | * @dev Receive a flash loan. 59 | * @param initiator The initiator of the loan. 60 | * @param token The loan currency. 61 | * @param amount The amount of tokens lent. 62 | * @param fee The additional amount of tokens to repay. 63 | * @param data Arbitrary data structure, intended to contain user-defined parameters. 64 | * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan" 65 | */ 66 | function onFlashLoan( 67 | address initiator, 68 | address token, 69 | uint256 amount, 70 | uint256 fee, 71 | bytes calldata data 72 | ) 73 | external 74 | returns (bytes32); 75 | } 76 | -------------------------------------------------------------------------------- /.github/workflows/dependency.yml: -------------------------------------------------------------------------------- 1 | name: Check Dependency Installation of ModuleKit 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - "main" 8 | pull_request: 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v2 16 | 17 | - name: Install Foundry 18 | uses: foundry-rs/foundry-toolchain@v1.2.0 19 | 20 | - name: Set up Node.js 21 | uses: actions/setup-node@v4 22 | with: 23 | node-version: "20" 24 | 25 | - name: Install pnpm 26 | uses: pnpm/action-setup@v4 27 | with: 28 | version: 9.0.6 29 | 30 | - name: Pack the package 31 | id: npm-pack 32 | run: | 33 | PACKAGE_NAME=$(npm pack) 34 | echo "package=$PACKAGE_NAME" >> $GITHUB_ENV 35 | 36 | - name: Run npm test 37 | run: | 38 | mkdir test-npm-install 39 | cd test-npm-install 40 | npm init -y 41 | npm install "../${{ env.package }}" 42 | mkdir -p src 43 | echo 'import "modulekit/ModuleKit.sol";' > src/TestImport.sol 44 | echo '[profile.default] 45 | evm_version = "cancun" 46 | src = "src" 47 | out = "out" 48 | libs = ["node_modules"]' > foundry.toml 49 | cp node_modules/@rhinestone/modulekit/remappings.txt remappings.txt 50 | forge build 51 | 52 | - name: Run pnpm test 53 | run: | 54 | mkdir test-pnpm-install 55 | cd test-pnpm-install 56 | pnpm init 57 | pnpm install "../${{ env.package }}" --shamefully-hoist 58 | mkdir -p src 59 | echo 'import "modulekit/ModuleKit.sol";' > src/TestImport.sol 60 | echo '[profile.default] 61 | evm_version = "cancun" 62 | src = "src" 63 | out = "out" 64 | libs = ["node_modules"]' > foundry.toml 65 | cp node_modules/@rhinestone/modulekit/remappings.txt remappings.txt 66 | forge build 67 | 68 | - name: Run via-ir test 69 | run: | 70 | mkdir test-via-ir 71 | cd test-via-ir 72 | pnpm init 73 | pnpm install "../${{ env.package }}" --shamefully-hoist 74 | mkdir -p src 75 | echo 'import "modulekit/ModuleKit.sol";' > src/TestImport.sol 76 | echo '[profile.default] 77 | evm_version = "cancun" 78 | src = "src" 79 | out = "out" 80 | libs = ["node_modules"]' > foundry.toml 81 | cp node_modules/@rhinestone/modulekit/remappings.txt remappings.txt 82 | forge build --via-ir 83 | 84 | - name: Clean up 85 | run: | 86 | rm "${{ env.package }}" 87 | rm -rf test-npm-install 88 | rm -rf test-pnpm-install 89 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@rhinestone/modulekit", 3 | "version": "0.5.9", 4 | "description": "A development kit for building and testing smart account modules.", 5 | "license": "GPL-3.0", 6 | "author": { 7 | "name": "Rhinestone", 8 | "url": "https://rhinestone.wtf" 9 | }, 10 | "scripts": { 11 | "build": "forge build", 12 | "fmt": "forge fmt", 13 | "fmt:check": "forge fmt --check", 14 | "build:optimized": "FOUNDRY_PROFILE=optimized forge build", 15 | "build:smt": "FOUNDRY_PROFILE=smt forge build", 16 | "clean": "rm -rf artifacts broadcast cache docs out out-optimized out-svg", 17 | "gas:report": "forge test --gas-report --mp \"./test/integration/**/*.sol\" --nmt \"test(Fuzz)?_RevertWhen_\\w{1,}?\"", 18 | "gas:snapshot": "forge snapshot --mp \"./test/integration/**/*.sol\" --nmt \"test(Fuzz)?_RevertWhen_\\w{1,}?\"", 19 | "gas:snapshot:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge snapshot --mp \"./test/integration/**/*.sol\" --nmt \"test(Fork)?(Fuzz)?_RevertWhen_\\w{1,}?\"", 20 | "lint:sol": "forge fmt --check && pnpm solhint \"{script,src,test}/**/*.sol\"", 21 | "test": "forge test", 22 | "test:lite": "FOUNDRY_PROFILE=lite forge test", 23 | "test:via-ir": "forge test --via-ir", 24 | "test:optimized": "pnpm run build:optimized && FOUNDRY_PROFILE=test-optimized forge test", 25 | "test:accounts": "forge test && ACCOUNT_TYPE=SAFE forge test && ACCOUNT_TYPE=KERNEL forge test && ACCOUNT_TYPE=NEXUS forge test", 26 | "changeset": "changeset", 27 | "changeset:release": "pnpm build && changeset publish", 28 | "changeset:version": "changeset version && pnpm install --lockfile-only" 29 | }, 30 | "dependencies": { 31 | "@ERC4337/account-abstraction": "github:kopy-kat/account-abstraction#develop", 32 | "@ERC4337/account-abstraction-v0.6": "github:eth-infinitism/account-abstraction#v0.6.0", 33 | "@prb/math": "^4.1.0", 34 | "@rhinestone/erc4337-validation": "^0.0.5", 35 | "@rhinestone/sentinellist": "github:rhinestonewtf/sentinellist", 36 | "ds-test": "github:dapphub/ds-test", 37 | "excessively-safe-call": "github:nomad-xyz/ExcessivelySafeCall", 38 | "forge-std": "github:foundry-rs/forge-std", 39 | "solady": "github:vectorized/solady", 40 | "solarray": "github:sablier-labs/solarray", 41 | "solhint": "^5.0.5" 42 | }, 43 | "devDependencies": { 44 | "@changesets/cli": "^2.27.12" 45 | }, 46 | "files": [ 47 | "src", 48 | "foundry.toml", 49 | "remappings.txt" 50 | ], 51 | "homepage": "https://docs.rhinestone.wtf/modulekit", 52 | "repository": { 53 | "type": "git", 54 | "url": "git+https://github.com/rhinestonewtf/modulekit.git" 55 | }, 56 | "bugs": { 57 | "url": "https://github.com/rhinestonewtf/modulekit/issues" 58 | }, 59 | "keywords": [ 60 | "account abstraction", 61 | "smart account modules" 62 | ], 63 | "publishConfig": { 64 | "access": "public" 65 | } 66 | } 67 | --------------------------------------------------------------------------------