Skip to content

Commit

Permalink
Merge pull request #53 from rainlanguage/2024-01-07-rm-meeta
Browse files Browse the repository at this point in the history
2024 01 07 rm meeta
  • Loading branch information
thedavidmeister authored Jan 8, 2024
2 parents 38db479 + c8a4996 commit 002435b
Show file tree
Hide file tree
Showing 30 changed files with 118 additions and 474 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/test-metadata.yaml

This file was deleted.

45 changes: 18 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,31 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = rainix.pkgs.${system};

in rec {
packages = rec {
concrete-contracts = ["OrderBook" "GenericPoolOrderBookV3FlashBorrower" "GenericPoolOrderBookV3ArbOrderTaker" "RouteProcessorOrderBookV3ArbOrderTaker"];
build-meta-cmd = contract: ''
rain meta build \
-i <(rain meta solc artifact -c abi -i out/${contract}.sol/${contract}.json) -m solidity-abi-v2 -t json -e deflate -l en \
-i src/concrete/${contract}.meta.json -m interpreter-caller-meta-v1 -t json -e deflate -l en \
'';
build-single-meta = contract: ''
${(build-meta-cmd contract)} -o meta/${contract}.rain.meta;
'';

build-meta = rainix.mkTask.${system} { name = "build-meta"; body = (''
set -x;
mkdir -p meta;
forge build --force;
'' + pkgs.lib.concatStrings (map build-single-meta concrete-contracts)); };

deploy-single-contract = contract: ''
forge script script/Deploy${contract}.sol:Deploy${contract} --legacy --verify --broadcast --rpc-url "''${CI_DEPLOY_RPC_URL}" --etherscan-api-key "''${EXPLORER_VERIFICATION_KEY}" \
--sig='run(bytes)' \
"$( ${(build-meta-cmd contract)} -E hex )" \
;
'';
concrete-contracts = ["OrderBook" "GenericPoolOrderBookV3FlashBorrower" "GenericPoolOrderBookV3ArbOrderTaker" "RouteProcessorOrderBookV3ArbOrderTaker"];
deploy-single-contract = contract: ''
forge script script/Deploy${contract}.sol:Deploy${contract} \
--legacy \
--verify \
--broadcast \
--rpc-url "''${CI_DEPLOY_RPC_URL}" \
--etherscan-api-key "''${EXPLORER_VERIFICATION_KEY}" \
;
'';
in {
packages = {
deploy-contracts = rainix.mkTask.${system} { name = "deploy-contracts"; body = (''
set -euo pipefail;
forge build --force;
echo 'deploy pubkey:'
cast wallet address "''${DEPLOYMENT_KEY}";
'' + pkgs.lib.concatStrings (map deploy-single-contract concrete-contracts)); };

default = build-meta;
ci-prep = build-meta;
ci-prep = rainix.mkTask.${system} { name = "ci-prep"; body = ''
set -euo pipefail;
forge install --shallow;
forge build --force;
''; };

} // rainix.packages.${system};

devShells = rainix.devShells.${system};
Expand Down
17 changes: 4 additions & 13 deletions script/DeployGenericPoolOrderBookV3ArbOrderTaker.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import {Script, console2} from "forge-std/Script.sol";
import {
GenericPoolOrderBookV3ArbOrderTaker,
DeployerDiscoverableMetaV3ConstructionConfig
} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol";
import {Script} from "forge-std/Script.sol";
import {GenericPoolOrderBookV3ArbOrderTaker} from "src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol";
import {I9R_DEPLOYER} from "./DeployConstants.sol";

/// @title DeployGenericPoolOrderBookV3ArbOrderTaker
/// @notice A script that deploys a `GenericPoolOrderBookV3ArbOrderTaker`. This
/// is intended to be run on every commit by CI to a testnet such as mumbai, then
/// cross chain deployed to whatever mainnet is required, by users.
contract DeployGenericPoolOrderBookV3ArbOrderTaker is Script {
/// We are avoiding using ffi here, instead forcing the script runner to
/// provide the built metadata. On CI this is achieved by using the rain cli.
function run(bytes memory meta) external {
function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY");

console2.log("GenericPoolOrderBookV3ArbOrderTaker meta hash:");
console2.logBytes32(keccak256(meta));

vm.startBroadcast(deployerPrivateKey);
GenericPoolOrderBookV3ArbOrderTaker deployed =
new GenericPoolOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta));
GenericPoolOrderBookV3ArbOrderTaker deployed = new GenericPoolOrderBookV3ArbOrderTaker(I9R_DEPLOYER);
(deployed);
vm.stopBroadcast();
}
Expand Down
17 changes: 4 additions & 13 deletions script/DeployGenericPoolOrderBookV3FlashBorrower.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import {Script, console2} from "forge-std/Script.sol";
import {
GenericPoolOrderBookV3FlashBorrower,
DeployerDiscoverableMetaV3ConstructionConfig
} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol";
import {Script} from "forge-std/Script.sol";
import {GenericPoolOrderBookV3FlashBorrower} from "src/concrete/GenericPoolOrderBookV3FlashBorrower.sol";
import {I9R_DEPLOYER} from "./DeployConstants.sol";

/// @title DeployGenericPoolOrderBookV3FlashBorrower
/// @notice A script that deploys a `GenericPoolOrderBookV3FlashBorrower`. This
/// is intended to be run on every commit by CI to a testnet such as mumbai, then
/// cross chain deployed to whatever mainnet is required, by users.
contract DeployGenericPoolOrderBookV3FlashBorrower is Script {
/// We are avoiding using ffi here, instead forcing the script runner to
/// provide the built metadata. On CI this is achieved by using the rain cli.
function run(bytes memory meta) external {
function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY");

console2.log("DeployGenericPoolOrderBookV3FlashBorrower meta hash:");
console2.logBytes32(keccak256(meta));

vm.startBroadcast(deployerPrivateKey);
GenericPoolOrderBookV3FlashBorrower deployed =
new GenericPoolOrderBookV3FlashBorrower(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta));
GenericPoolOrderBookV3FlashBorrower deployed = new GenericPoolOrderBookV3FlashBorrower(I9R_DEPLOYER);
(deployed);
vm.stopBroadcast();
}
Expand Down
11 changes: 4 additions & 7 deletions script/DeployOrderBook.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import {Script, console2} from "forge-std/Script.sol";
import {OrderBook, DeployerDiscoverableMetaV3ConstructionConfig} from "src/concrete/OrderBook.sol";
import {Script} from "forge-std/Script.sol";
import {OrderBook} from "src/concrete/OrderBook.sol";
import {I9R_DEPLOYER} from "./DeployConstants.sol";

contract DeployOrderBook is Script {
function run(bytes memory meta) external {
function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY");

console2.log("DeployOrderBook meta hash:");
console2.logBytes32(keccak256(meta));

vm.startBroadcast(deployerPrivateKey);
OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta));
OrderBook deployed = new OrderBook(I9R_DEPLOYER);
(deployed);
vm.stopBroadcast();
}
Expand Down
17 changes: 4 additions & 13 deletions script/DeployRouteProcessorOrderBookV3ArbOrderTaker.sol
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import {Script, console2} from "forge-std/Script.sol";
import {
RouteProcessorOrderBookV3ArbOrderTaker,
DeployerDiscoverableMetaV3ConstructionConfig
} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol";
import {Script} from "forge-std/Script.sol";
import {RouteProcessorOrderBookV3ArbOrderTaker} from "src/concrete/RouteProcessorOrderBookV3ArbOrderTaker.sol";
import {I9R_DEPLOYER} from "./DeployConstants.sol";

/// @title DeployRouteProcessorOrderBookV3ArbOrderTaker
/// @notice A script that deploys a `RouteProcessorOrderBookV3ArbOrderTaker`. This
/// is intended to be run on every commit by CI to a testnet such as mumbai, then
/// cross chain deployed to whatever mainnet is required, by users.
contract DeployRouteProcessorOrderBookV3ArbOrderTaker is Script {
/// We are avoiding using ffi here, instead forcing the script runner to
/// provide the built metadata. On CI this is achieved by using the rain cli.
function run(bytes memory meta) external {
function run() external {
uint256 deployerPrivateKey = vm.envUint("DEPLOYMENT_KEY");

console2.log("RouteProcessorOrderBookV3ArbOrderTaker meta hash:");
console2.logBytes32(keccak256(meta));

vm.startBroadcast(deployerPrivateKey);
RouteProcessorOrderBookV3ArbOrderTaker deployed =
new RouteProcessorOrderBookV3ArbOrderTaker(DeployerDiscoverableMetaV3ConstructionConfig(I9R_DEPLOYER, meta));
RouteProcessorOrderBookV3ArbOrderTaker deployed = new RouteProcessorOrderBookV3ArbOrderTaker(I9R_DEPLOYER);
(deployed);
vm.stopBroadcast();
}
Expand Down
13 changes: 4 additions & 9 deletions src/abstract/OrderBookV3ArbOrderTaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {Initializable} from "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol";
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol";
import {
DeployerDiscoverableMetaV3,
DeployerDiscoverableMetaV3ConstructionConfig,
LibMeta
} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol";
import {LibDeployerDiscoverable} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol";
import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter/src/interface/IInterpreterCallerV2.sol";
import {SourceIndexV2} from "rain.interpreter/src/interface/unstable/IInterpreterV2.sol";
import {ICloneableV2, ICLONEABLE_V2_SUCCESS} from "rain.factory/src/interface/ICloneableV2.sol";
Expand Down Expand Up @@ -55,7 +51,6 @@ abstract contract OrderBookV3ArbOrderTaker is
ReentrancyGuard,
Initializable,
ICloneableV2,
DeployerDiscoverableMetaV3,
ERC165
{
using SafeERC20 for IERC20;
Expand All @@ -67,9 +62,9 @@ abstract contract OrderBookV3ArbOrderTaker is
IInterpreterV2 public sI9r;
IInterpreterStoreV1 public sI9rStore;

constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config)
DeployerDiscoverableMetaV3(metaHash, config)
{
constructor(address deployer) {
LibDeployerDiscoverable.touchDeployerV3(deployer);

_disableInitializers();
}

Expand Down
13 changes: 4 additions & 9 deletions src/abstract/OrderBookV3FlashBorrower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuard} from "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol";
import {Initializable} from "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol";
import {
DeployerDiscoverableMetaV3,
DeployerDiscoverableMetaV3ConstructionConfig,
LibMeta
} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol";
import {LibDeployerDiscoverable} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV3.sol";
import {LibEncodedDispatch, EncodedDispatch} from "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol";
import {LibContext} from "rain.interpreter/src/lib/caller/LibContext.sol";
import {LibBytecode} from "rain.interpreter/src/lib/bytecode/LibBytecode.sol";
Expand Down Expand Up @@ -98,7 +94,6 @@ abstract contract OrderBookV3FlashBorrower is
ICloneableV2,
ReentrancyGuard,
Initializable,
DeployerDiscoverableMetaV3,
ERC165
{
using Address for address;
Expand All @@ -119,9 +114,9 @@ abstract contract OrderBookV3FlashBorrower is
/// The associated store for the interpreter.
IInterpreterStoreV1 public sI9rStore;

constructor(bytes32 metaHash, DeployerDiscoverableMetaV3ConstructionConfig memory config)
DeployerDiscoverableMetaV3(metaHash, config)
{
constructor(address deployer) {
LibDeployerDiscoverable.touchDeployerV3(deployer);

// Arb contracts are expected to be cloned proxies so allowing
// initialization of the implementation is a security risk.
_disableInitializers();
Expand Down
18 changes: 0 additions & 18 deletions src/concrete/GenericPoolOrderBookV3ArbOrderTaker.meta.json

This file was deleted.

6 changes: 1 addition & 5 deletions src/concrete/GenericPoolOrderBookV3ArbOrderTaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.so
import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {Address} from "lib/openzeppelin-contracts/contracts/utils/Address.sol";

bytes32 constant CALLER_META_HASH = bytes32(0xe1d075e6f17f6706d942759ec359deb7f354ab4ac55e58eda2870c0ab3a89fa5);

contract GenericPoolOrderBookV3ArbOrderTaker is OrderBookV3ArbOrderTaker {
using SafeERC20 for IERC20;
using Address for address;

constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config)
OrderBookV3ArbOrderTaker(CALLER_META_HASH, config)
{}
constructor(address deployer) OrderBookV3ArbOrderTaker(deployer) {}

/// @inheritdoc OrderBookV3ArbOrderTaker
function onTakeOrders(
Expand Down
18 changes: 0 additions & 18 deletions src/concrete/GenericPoolOrderBookV3FlashBorrower.meta.json

This file was deleted.

26 changes: 14 additions & 12 deletions src/concrete/GenericPoolOrderBookV3FlashBorrower.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// SPDX-License-Identifier: CAL
pragma solidity =0.8.19;

import "src/interface/ierc3156/IERC3156FlashLender.sol";
import "src/interface/ierc3156/IERC3156FlashBorrower.sol";

import "src/abstract/OrderBookV3FlashBorrower.sol";

/// @dev Metadata hash for `DeployerDiscoverableMetaV1`.
/// - ABI for GenericPoolOrderBookV3FlashBorrower
/// - Interpreter caller metadata V1 for GenericPoolOrderBookV3FlashBorrower
bytes32 constant CALLER_META_HASH = bytes32(0x52cdec296c4ecb0b2452c9e314df50e1b5d52fef03927934b7426ff6f150f0fe);
import {IERC3156FlashLender} from "src/interface/ierc3156/IERC3156FlashLender.sol";
import {IERC3156FlashBorrower} from "src/interface/ierc3156/IERC3156FlashBorrower.sol";

import {
OrderBookV3FlashBorrower,
OrderBookV3FlashBorrowerConfigV2,
ICloneableV2,
MinimumOutput,
SafeERC20,
IERC20,
Address,
TakeOrdersConfigV2
} from "src/abstract/OrderBookV3FlashBorrower.sol";

/// @title GenericPoolOrderBookV3FlashBorrower
/// Implements the OrderBookV3FlashBorrower interface for a external liquidity
Expand All @@ -25,9 +29,7 @@ contract GenericPoolOrderBookV3FlashBorrower is OrderBookV3FlashBorrower {
using SafeERC20 for IERC20;
using Address for address;

constructor(DeployerDiscoverableMetaV3ConstructionConfig memory config)
OrderBookV3FlashBorrower(CALLER_META_HASH, config)
{}
constructor(address deployer) OrderBookV3FlashBorrower(deployer) {}

/// @inheritdoc OrderBookV3FlashBorrower
function _exchange(TakeOrdersConfigV2 memory takeOrders, bytes memory exchangeData) internal virtual override {
Expand Down
Loading

0 comments on commit 002435b

Please sign in to comment.