Skip to content

Commit

Permalink
build(pkg): make package build
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed May 16, 2024
1 parent 8fe3e34 commit 09a6523
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 303 deletions.
11 changes: 5 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: "🐛 Bug Report"
about: Report a reproducible bug or regression.
title: ''
title: ""
labels: bug
assignees: ''

assignees: ""
---

## Current Behavior
Expand All @@ -17,9 +16,9 @@ assignees: ''

## Steps to Reproduce the Problem

1.
1.
1.
1.
1.
1.

## Environment

Expand Down
8 changes: 5 additions & 3 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
---
name: 🌈 Feature request
about: Suggest an amazing new idea for this project
title: ''
title: ""
labels: enhancement
assignees: ''

assignees: ""
---

## Feature Request

**Is your feature request related to a problem? Please describe.**

<!-- A clear and concise description of what the problem is. Ex. I have an issue when [...] -->

**Describe the solution you'd like**

<!-- A clear and concise description of what you want to happen. Add any considered drawbacks. -->

**Describe alternatives you've considered**

<!-- A clear and concise description of any alternative solutions or features you've considered. -->

## Are you willing to resolve this issue by submitting a Pull Request?
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/types/
65 changes: 43 additions & 22 deletions contracts/Executor.sol
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.25;

import {IExecutor, ExecContext} from "./interfaces/IExecutor.sol";
import {IExecutor} from "./interfaces/IExecutor.sol";

uint96 constant UNSET_DATA_INDEX = type(uint96).max;
uint256 constant ENABLE_FALLBACK_TLOC = 0;
uint256 constant FALLBACK_DATA_INDEX_TLOC = 1;

contract Executor is IExecutor {
ExecContext internal _context;
address public owner;

constructor(address _owner) {
_context = ExecContext({owner: _owner, fallbackDataIndex: UNSET_DATA_INDEX});
owner = _owner;
}

/* EXTERNAL */

/// @notice Returns the owner of the contract.
function owner() external view returns (address) {
return _context.owner;
}

/// @notice Transfers ownership of the contract.
function transferOwnership(address newOwner) external payable {
require(msg.sender == _context.owner);
require(msg.sender == owner);

_context.owner = newOwner;
owner = newOwner;
}

/// @notice Executes a batch of calls.
function exec_606BaXt(bytes[] memory data) external payable {
require(msg.sender == _context.owner);
require(msg.sender == owner);

_tstore(ENABLE_FALLBACK_TLOC, 1);

_multicall(data);

_tstore(ENABLE_FALLBACK_TLOC, 0);
}

/// @notice Executes a normal call, requiring its success.
/// @param config The address to call concatenated to the corresponding fallback data index to use in a callback.
/// Set the fallback data index to type(uint96).max to prevent any callback.
/// @param value The value of the call.
/// @param callData the calldata of the call.
function call_m08sKaj(bytes32 config, uint256 value, bytes memory callData) external payable {
require(msg.sender == address(this));

address target = address(uint160(uint256(config)));
uint96 prevFallbackDataIndex = _context.fallbackDataIndex;
uint256 prevFallbackDataIndex = _tload(FALLBACK_DATA_INDEX_TLOC);

_context.fallbackDataIndex = uint96(uint256(config >> 160));
_tstore(FALLBACK_DATA_INDEX_TLOC, uint256(config >> 160));

(bool success, bytes memory returnData) = target.call{value: value}(callData);
if (!success) _revert(returnData);

_context.fallbackDataIndex = prevFallbackDataIndex;
_tstore(FALLBACK_DATA_INDEX_TLOC, prevFallbackDataIndex);
}

/// @notice Transfers ETH to the recipient.
/// @param recipient The recipient of the transfer. Set to address(0) to transfer to the coinbase.
/// @param amount The amount to transfer. Automatically minimumed to the current ETH balance.
function transfer(address recipient, uint256 amount) external payable {
require(msg.sender == address(this));

Expand All @@ -60,9 +68,11 @@ contract Executor is IExecutor {

receive() external payable {}

fallback(bytes calldata) external payable returns (bytes memory) {
uint96 dataIndex = _context.fallbackDataIndex;
require(dataIndex != UNSET_DATA_INDEX);
fallback(bytes calldata) external payable returns (bytes memory returnData) {
require(_tload(ENABLE_FALLBACK_TLOC) == 1);

uint256 dataIndex = _tload(FALLBACK_DATA_INDEX_TLOC);
require(dataIndex != type(uint96).max);

bytes memory fallbackData;
assembly ("memory-safe") {
Expand All @@ -76,11 +86,10 @@ contract Executor is IExecutor {
mstore(0x40, add(fallbackData, add(32, length)))
}

(bytes[] memory multicallData, bytes memory returnData) = abi.decode(fallbackData, (bytes[], bytes));
bytes[] memory multicallData;
(multicallData, returnData) = abi.decode(fallbackData, (bytes[], bytes));

_multicall(multicallData);

return returnData;
}

/* INTERNAL */
Expand All @@ -104,6 +113,18 @@ contract Executor is IExecutor {
}
}

function _tload(uint256 tloc) internal view returns (uint256 value) {
assembly ("memory-safe") {
value := tload(tloc)
}
}

function _tstore(uint256 tloc, uint256 value) internal {
assembly ("memory-safe") {
tstore(tloc, value)
}
}

function _min(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
Expand Down
7 changes: 1 addition & 6 deletions contracts/interfaces/IExecutor.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

struct ExecContext {
address owner;
uint96 fallbackDataIndex;
}

interface IExecutor {
function owner() external view returns (address);

Expand Down
26 changes: 8 additions & 18 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-ethers";
import "@nomicfoundation/hardhat-foundry";
import "@typechain/hardhat";
import "dotenv/config";
import "evm-maths";
import "hardhat-deal";
import "hardhat-tracer";
import "hardhat-gas-reporter";
import { HardhatUserConfig } from "hardhat/config";
import "solidity-coverage";
import "evm-maths";
import "dotenv/config";

import "@typechain/hardhat";
import "@nomicfoundation/hardhat-ethers";
import "@nomicfoundation/hardhat-foundry";
import "@nomicfoundation/hardhat-chai-matchers";

export const rpcUrl = process.env.MAINNET_RPC_URL;
if (!rpcUrl) throw Error(`no RPC url provided`);
Expand All @@ -21,15 +19,11 @@ const config: HardhatUserConfig = {
chainId: 1,
forking: {
url: rpcUrl,
blockNumber: 19881284,
blockNumber: 18_843_810,
},
allowBlocksWithSameTimestamp: true,
accounts: { count: 2 },
},
mainnet: {
chainId: 1,
url: rpcUrl,
},
},
solidity: {
compilers: [
Expand All @@ -55,10 +49,6 @@ const config: HardhatUserConfig = {
typechain: {
outDir: "src/types/",
},
tracer: {
defaultVerbosity: 1,
gasCost: true,
},
};

export default config;
40 changes: 22 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@
"smart contract"
],
"dependencies": {
"ethers": "^6.11.1",
"ethers-types": "^3.7.0"
"ethers": "^6.12.1",
"ethers-types": "^3.15.0"
},
"devDependencies": {
"@commitlint/cli": "^17.8.0",
"@commitlint/config-conventional": "^17.8.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-foundry": "^1.1.2",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.12",
"@types/lodash": "^4.17.0",
"@types/chai": "^4.3.16",
"@types/mocha": "^10.0.6",
"@types/simple-mock": "^0.8.6",
"chai": "^4.4.1",
Expand All @@ -55,27 +56,31 @@
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.4.5",
"evm-maths": "^6.0.3",
"hardhat": "2.20.1",
"hardhat": "2.22.4",
"hardhat-deal": "^3.0.2",
"hardhat-gas-reporter": "^1.0.10",
"hardhat-tracer": "^2.8.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"simple-mock": "^0.8.0",
"solidity-coverage": "^0.8.11",
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.4.2"
"typescript": "^5.4.5"
},
"lint-staged": {
"*.sol": "forge fmt",
"*.ts": "prettier"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"lint-staged": {
"*.sol": "forge fmt",
"*.ts": "prettier"
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"release": {
"branches": [
Expand Down Expand Up @@ -125,13 +130,12 @@
"prettier": {
"printWidth": 120,
"importOrder": [
"^(?<!(src|types|test|scripts)).*",
"^src",
"^types",
"^test",
"^scripts",
"^ethers",
"^\\."
],
"importOrderSeparation": true
"importOrderSeparation": true,
"plugins": [
"@trivago/prettier-plugin-sort-imports"
]
}
}
4 changes: 2 additions & 2 deletions src/ExecutorEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
toBigInt,
toUtf8Bytes,
} from "ethers";

import {
CErc20__factory,
AaveV2LendingPool__factory,
Expand All @@ -26,9 +25,10 @@ import {
ERC20__factory,
BalancerVault__factory,
} from "ethers-types";
import { PayableOverrides } from "ethers-types/dist/common";
import { MarketParamsStruct } from "ethers-types/dist/protocols/morpho/blue/MorphoBlue";

import { Executor, Executor__factory } from "./types";
import { PayableOverrides } from "ethers-types/dist/common";

export type PromiseOrValue<T> = T | Promise<T>;

Expand Down
2 changes: 1 addition & 1 deletion src/types/factories/Executor__factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const _abi = [
] as const;

const _bytecode =
"0x60803460ab576001600160401b0390601f61059238819003918201601f19168301918483118484101760975780849260209460405283398101031260ab57516001600160a01b038116919082900360ab576040519060408201908282109082111760975760409081528282526001600160601b036020909201919091526001600160a01b03199091175f55516104e290816100b08239f35b634e487b7160e01b5f52604160045260245ffd5b5f80fdfe60406080815260048036101561011d575b361561011b575f546bffffffffffffffffffffffff8160a01c146100f2576c1fffffffffffffffffffffffe090609b1c1681013501803590825190602092839181830190843782010183528051810183828483019203126100f257828201519067ffffffffffffffff918281116100f25783019481603f870112156100f25784860151956100a56100a0886103d3565b610341565b96828789838152019160051b830101918483116100f257838101915b8383106100f657505050508301519182116100f257836100e6926100ec940101610426565b92610470565b81519101f35b5f80fd5b82518781116100f257899161011088888594870101610426565b8152019201916100c1565b005b5f3560e01c80156102b857806001146102125780638da5cb5b146101eb578063a9059cbb1461018c5763f2fde38b036100105760203660031901126100f2576101646103eb565b5f54906001600160a01b039081831633036100f2576001600160a01b03199092169116175f55005b826003193601126100f25761019f6103eb565b806024353033036100f2575f918291829182916001600160a01b038716156101e3575b478181109082180218905af16101d6610401565b90156101de57005b610462565b4191506101c2565b82346100f2575f3660031901126100f2575f5490516001600160a01b039091168152602090f35b506020806003193601126100f257813567ffffffffffffffff928382116100f257366023830112156100f2578101356024906102506100a0826103d3565b946024602087848152019260051b850101933685116100f25760248101925b858410610292575f5488906001600160a01b031633036100f25761011b90610470565b83358381116100f25787916102ad8392883691870101610397565b81520193019261026f565b5060603660031901126100f2578035906044359067ffffffffffffffff82116100f2576102e791369101610397565b903033036100f25760018060a01b03905f808054946bffffffffffffffffffffffff60a01b93848116868816178355602082519201908660243591165af161032d610401565b90156101de57505f5492169116175f555f80f35b6040519190601f01601f1916820167ffffffffffffffff81118382101761036757604052565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff811161036757601f01601f191660200190565b81601f820112156100f2578035906103b16100a08361037b565b92828452602083830101116100f257815f926020809301838601378301015290565b67ffffffffffffffff81116103675760051b60200190565b600435906001600160a01b03821682036100f257565b3d15610421573d906104156100a08361037b565b9182523d5f602084013e565b606090565b81601f820112156100f2578051906104406100a08361037b565b92828452602083830101116100f257815f9260208093018386015e8301015290565b80519081156100f257602001fd5b5f5b81518110156104a8575f806020808460051b86010151908151910182305af1610499610401565b90156101de5750600101610472565b505056fea26469706673582212207fd2bf43cd578d0b215fcc488e3dce3252853693bde8641f0c8ce880d3c9408c64736f6c63430008190033";
"0x608034606f57601f61054f38819003918201601f19168301916001600160401b03831184841017607357808492602094604052833981010312606f57516001600160a01b03811690819003606f575f80546001600160a01b0319169190911790556040516104c790816100888239f35b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe604060808152600480361015610114575b36156101125760015f5c036100e95760015c6bffffffffffffffffffffffff81146100e95760051b81013501803590825190602092839181830190843782010183528051810183828483019203126100e957828201519067ffffffffffffffff918281116100e95783019481603f870112156100e957848601519561009c610097886103b8565b610326565b96828789838152019160051b830101918483116100e957838101915b8383106100ed57505050508301519182116100e957836100dd926100e394010161040b565b92610455565b81519101f35b5f80fd5b82518781116100e95789916101078888859487010161040b565b8152019201916100b8565b005b5f3560e01c80156102b857806001146102095780638da5cb5b146101e2578063a9059cbb146101835763f2fde38b036100105760203660031901126100e95761015b6103d0565b5f54906001600160a01b039081831633036100e9576001600160a01b03199092169116175f55005b826003193601126100e9576101966103d0565b806024353033036100e9575f918291829182916001600160a01b038716156101da575b478181109082180218905af16101cd6103e6565b90156101d557005b610447565b4191506101b9565b82346100e9575f3660031901126100e9575f5490516001600160a01b039091168152602090f35b506020806003193601126100e957813567ffffffffffffffff928382116100e957366023830112156100e957810135602490610247610097826103b8565b946024602087848152019260051b850101933685116100e95760248101925b858410610292575f5488906001600160a01b031633036100e95761028d9060015f5d610455565b5f805d005b83358381116100e95787916102ad839288369187010161037c565b815201930192610266565b5060603660031901126100e9578035906044359067ffffffffffffffff82116100e9576102e79136910161037c565b3033036100e9575f809160015c938060a01c60015d81519160200190602435906001600160a01b03165af161031a6103e6565b90156101d5575060015d005b6040519190601f01601f1916820167ffffffffffffffff81118382101761034c57604052565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff811161034c57601f01601f191660200190565b81601f820112156100e95780359061039661009783610360565b92828452602083830101116100e957815f926020809301838601378301015290565b67ffffffffffffffff811161034c5760051b60200190565b600435906001600160a01b03821682036100e957565b3d15610406573d906103fa61009783610360565b9182523d5f602084013e565b606090565b81601f820112156100e95780519061042561009783610360565b92828452602083830101116100e957815f9260208093018386015e8301015290565b80519081156100e957602001fd5b5f5b815181101561048d575f806020808460051b86010151908151910182305af161047e6103e6565b90156101d55750600101610457565b505056fea26469706673582212207c02be93ba952bdf6b53c3f4f81e3b6bd26d62d8286d57ffd0a5ad6ea27aa01a64736f6c63430008190033";

type ExecutorConstructorParams =
| [signer?: Signer]
Expand Down
Loading

0 comments on commit 09a6523

Please sign in to comment.