Skip to content

Commit

Permalink
Merge pull request #7 from Axis-Fi/baseline-v2-dtl
Browse files Browse the repository at this point in the history
Baseline V2 DTL
  • Loading branch information
0xJem authored Jul 19, 2024
2 parents 3e1c38d + cdbd4c3 commit 521f43d
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 89 deletions.
30 changes: 3 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
# axis-utils

This repository contains utility scripts and contracts related to the [Axis system](https://axis.finance/). This includes:
This monorepo contains two packages:

- Example scripts (to accompany our [developer guides](https://axis.finance/developer/))
- TODO: callback salt generation scripts

## Requirements

- [foundry](https://getfoundry.sh/)

## Usage

### Install Dependencies

```shell
pnpm install
```

### Build

```shell
forge build
```

### Linting

```shell
pnpm run lint
```
- [axis-utils](packages/axis-utils/)
- [oz-merkle-tree](packages/oz-merkle-tree/)
10 changes: 10 additions & 0 deletions packages/axis-utils/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Chain names based on: https://github.com/alloy-rs/chains/blob/main/src/named.rs
CHAIN=CHANGEME
RPC_URL=CHANGEME
ETHERSCAN_API_KEY=CHANGEME

DEPLOYER_PRIVATE_KEY=CHANGEME
DEPLOYER_ADDRESS=CHANGEME

# Set to override the default verifier URL for the chain
#VERIFIER_URL=
55 changes: 55 additions & 0 deletions packages/axis-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# axis-utils

This package in the monorepo contains:

- Example scripts (to accompany our [developer guides](https://axis.finance/developer/))
- Scripts for testing installations of the Axis Finance protocol

## Developer Guide

### Requirements

- [foundry](https://getfoundry.sh/)

### Usage

#### Install Dependencies

```shell
pnpm install
```

#### Build

```shell
forge build
```

#### Linting

```shell
pnpm run lint
```

### Dependencies

[soldeer](https://soldeer.xyz/) is used as the dependency manager, as it solves many of the problems inherent in forge's use of git submodules. Soldeer is integrated into `forge`, so should not require any additional installations.

NOTE: The import path of each dependency is versioned. This ensures that any changes to the dependency version result in clear errors to highlight the potentially-breaking change.

#### Updating Dependencies

When updating the version of a dependency provided through soldeer, the following must be performed:

1. Update the version of the dependency in `foundry.toml` or through `forge soldeer`
2. Re-run the [installation script](#install-dependencies)
3. If the version number has changed:
- Change the existing entry in [remappings.txt](remappings.txt) to point to the new dependency version
- Update imports to use the new remapping

#### Updating axis-core or axis-periphery

Updating the version of the `axis-core` or `axis-periphery` dependencies is a special case, as some files are accessed directly and bypass remappings. Perform the following after following the [steps above](#updating-dependencies):

1. Update the version in the `axis-core` or `axis-periphery` entry (as appropriate) for the `fs_permissions` key in [foundry.toml](foundry.toml)
2. Update the version mentioned in `_loadEnv()` in the [WithEnvironment](script/WithEnvironment.s.sol) contract
8 changes: 7 additions & 1 deletion packages/axis-utils/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [
{access = "read", path = "./dependencies/axis-core-1.0.0/script/env.json"},
{access = "read", path = "./dependencies/axis-periphery-0.9.0/script/env.json"},
]
ffi = true
solc_version = "0.8.19"
evm_version = "paris"

Expand All @@ -28,9 +33,10 @@ ignore = [
forge-std = "1.9.1"
solmate = { version = "6.7.0", url = "git@github.com:transmissions11/solmate.git", commit = "c892309933b25c03d32b1b0d674df7ae292ba925" }
axis-core = { version = "1.0.0" }
axis-periphery = { version = "0.9.0", git = "git@github.com:Axis-Fi/axis-periphery.git", rev = "631c877c9fd4d0cbb5aa3f51b9bd37ae0ce28a38" }
axis-periphery = { version = "0.9.0", git = "git@github.com:Axis-Fi/axis-periphery.git", rev = "a87edb37c610315dd46cd2d780863bb477f5c0c6" }
solady = { version = "0.0.124" }
clones-with-immutable-args = { version = "1.1.1", git = "git@github.com:wighawag/clones-with-immutable-args.git", rev = "f5ca191afea933d50a36d101009b5644dc28bc99" }
"@openzeppelin-contracts" = { version = "4.9.2" }
"@uniswap-v2-core" = { version = "1.0.1" }
"@uniswap-v2-periphery" = { version = "1.0.1", git = "git@github.com:Axis-Fi/uniswap-v2-periphery.git", rev = "19be650786731dfe43cac3aac7a2d1f0731d18e2" }
"@uniswap-v3-core" = { version = "1.0.1-solc-0.8-simulate" }
3 changes: 2 additions & 1 deletion packages/axis-utils/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
@clones-with-immutable-args-1.1.1=dependencies/clones-with-immutable-args-1.1.1/src
@openzeppelin-contracts-4.9.2=dependencies/@openzeppelin-contracts-4.9.2
@uniswap-v2-core-1.0.1=dependencies/@uniswap-v2-core-1.0.1/contracts
@uniswap-v2-periphery-1.0.1=dependencies/@uniswap-v2-periphery-1.0.1/contracts
@uniswap-v2-periphery-1.0.1=dependencies/@uniswap-v2-periphery-1.0.1/contracts
@uniswap-v3-core-1.0.1-solc-0.8-simulate=dependencies/@uniswap-v3-core-1.0.1-solc-0.8-simulate/contracts
67 changes: 67 additions & 0 deletions packages/axis-utils/script/WithEnvironment.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

// Scripting libraries
import {Script, console2} from "@forge-std-1.9.1/Script.sol";
import {stdJson} from "@forge-std-1.9.1/StdJson.sol";

abstract contract WithEnvironment is Script {
using stdJson for string;

string public chain;
string public envAxisCore;
string public envAxisPeriphery;

function _loadEnv(string calldata chain_) internal {
chain = chain_;
console2.log("Using chain:", chain_);

// Load environment file
envAxisCore = vm.readFile("dependencies/axis-core-1.0.0/script/env.json");
envAxisPeriphery = vm.readFile("dependencies/axis-periphery-0.9.0/script/env.json");
}

/// @notice Get address from environment file
/// @dev First checks in axis-periphery's environment file, then in axis-core's environment file
///
/// @param key_ The key to look up in the environment file
/// @return address The address from the environment file, or the zero address
function _envAddress(string memory key_) internal view returns (address) {
console2.log(" Checking in axis-periphery/env.json");
string memory fullKey = string.concat(".current.", chain, ".", key_);
address addr;
bool keyExists = vm.keyExists(envAxisPeriphery, fullKey);

if (keyExists) {
addr = envAxisPeriphery.readAddress(fullKey);
console2.log(" %s: %s (from axis-periphery/env.json)", key_, addr);
} else {
keyExists = vm.keyExists(envAxisCore, fullKey);

if (keyExists) {
addr = envAxisCore.readAddress(fullKey);
console2.log(" %s: %s (from axis-core/env.json)", key_, addr);
} else {
console2.log(" %s: *** NOT FOUND ***", key_);
}
}

return addr;
}

/// @notice Get a non-zero address from environment file
/// @dev First checks in axis-periphery's environment file, then in axis-core's environment file
///
/// Reverts if the key is not found
///
/// @param key_ The key to look up in the environment file
/// @return address The address from the environment file
function _envAddressNotZero(string memory key_) internal view returns (address) {
address addr = _envAddress(key_);
require(
addr != address(0), string.concat("WithEnvironment: key '", key_, "' has zero address")
);

return addr;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FixedPriceBatch - Uniswap DTL Testing
# FixedPriceBatch - With Optional Uniswap DTL Testing

## How to Test

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.19;

// Scripting libraries
import {Script, console2} from "@forge-std-1.9.1/Script.sol";
import {WithEnvironment} from "@axis-periphery-0.9.0-script/deploy/WithEnvironment.s.sol";
import {WithEnvironment} from "../../WithEnvironment.s.sol";

// System contracts
import {IBatchAuctionHouse} from "@axis-core-1.0.0/interfaces/IBatchAuctionHouse.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.19;

// Scripting libraries
import {Script, console2} from "@forge-std-1.9.1/Script.sol";
import {WithEnvironment} from "@axis-periphery-0.9.0-script/deploy/WithEnvironment.s.sol";
import {WithEnvironment} from "../../WithEnvironment.s.sol";

// System contracts
import {IBatchAuctionHouse} from "@axis-core-1.0.0/interfaces/IBatchAuctionHouse.sol";
Expand All @@ -13,9 +13,10 @@ import {toKeycode} from "@axis-core-1.0.0/modules/Modules.sol";
import {ICallback} from "@axis-core-1.0.0/interfaces/ICallback.sol";
import {IFixedPriceBatch} from "@axis-core-1.0.0/interfaces/modules/auctions/IFixedPriceBatch.sol";
import {IAuction} from "@axis-core-1.0.0/interfaces/modules/IAuction.sol";
// import {BaselineAxisLaunch} from "@axis-core-1.0.0/callbacks/liquidity/BaselineV2/BaselineAxisLaunch.sol";
// import {BALwithAllocatedAllowlist} from
// "@axis-core-1.0.0/callbacks/liquidity/BaselineV2/BALwithAllocatedAllowlist.sol";

// Baseline
import {BaselineAxisLaunch} from
"@axis-periphery-0.9.0/callbacks/liquidity/BaselineV2/BaselineAxisLaunch.sol";

// Generic contracts
import {ERC20} from "@solmate-6.7.0/tokens/ERC20.sol";
Expand Down Expand Up @@ -51,12 +52,14 @@ contract TestData is Script, WithEnvironment {
routingParams.callbacks = ICallback(callback_);
if (callback_ != address(0)) {
console2.log("Setting callback parameters");
// routingParams.callbackData = abi.encode(
// BaselineAxisLaunch.CreateData({
// discoveryTickWidth: 100,
// allowlistParams: abi.encode(merkleRoot)
// })
// );
routingParams.callbackData = abi.encode(
BaselineAxisLaunch.CreateData({
floorReservesPercent: 50e2, // 50%
anchorTickWidth: 3,
discoveryTickWidth: 100,
allowlistParams: abi.encode(merkleRoot)
})
);

// No spending approval necessary, since the callback will handle it
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ else
fi

# Create auction
forge script ./script/test/FixedPriceBatch/TestData.s.sol:TestData --sig "createAuction(string,address,address,address,bytes32)()" $CHAIN $quoteToken $baseToken $callback $allowlistMerkleRoot \
forge script ./script/test/FixedPriceBatch-Baseline/TestData.s.sol:TestData --sig "createAuction(string,address,address,address,bytes32)()" $CHAIN $quoteToken $baseToken $callback $allowlistMerkleRoot \
--rpc-url $RPC_URL --private-key $DEPLOYER_PRIVATE_KEY --froms $DEPLOYER_ADDRESS --slow -vvvv \
$BROADCAST_FLAG
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ else
fi

# Create auction
forge script ./script/test/FixedPriceBatch/TestData.s.sol:TestData --sig "placeBid(string,uint96,uint256,bytes32,uint256)()" $CHAIN $lotId $amount $merkleProof $allocatedAmount \
forge script ./script/test/FixedPriceBatch-Baseline/TestData.s.sol:TestData --sig "placeBid(string,uint96,uint256,bytes32,uint256)()" $CHAIN $lotId $amount $merkleProof $allocatedAmount \
--rpc-url $RPC_URL --private-key $DEPLOYER_PRIVATE_KEY --froms $DEPLOYER_ADDRESS --slow -vvvv \
$BROADCAST_FLAG
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ else
fi

# Create auction
forge script ./script/test/FixedPriceBatch/TestData.s.sol:TestData --sig "settleAuction(string,uint96)()" $CHAIN $lotId \
forge script ./script/test/FixedPriceBatch-Baseline/TestData.s.sol:TestData --sig "settleAuction(string,uint96)()" $CHAIN $lotId \
--rpc-url $RPC_URL --private-key $DEPLOYER_PRIVATE_KEY --froms $DEPLOYER_ADDRESS --slow -vvvv \
$BROADCAST_FLAG
44 changes: 0 additions & 44 deletions packages/axis-utils/script/test/FixedPriceBatch/warp.sh

This file was deleted.

File renamed without changes.
8 changes: 7 additions & 1 deletion packages/axis-utils/soldeer.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ checksum = "9b5716ade218b4064bba7cca7d31065e6aa66574ad92386aaf2cc71b5c21bbb4"
name = "axis-periphery"
version = "0.9.0"
source = "git@github.com:Axis-Fi/axis-periphery.git"
checksum = "631c877c9fd4d0cbb5aa3f51b9bd37ae0ce28a38"
checksum = "a87edb37c610315dd46cd2d780863bb477f5c0c6"

[[dependencies]]
name = "solady"
Expand Down Expand Up @@ -52,3 +52,9 @@ name = "@uniswap-v2-periphery"
version = "1.0.1"
source = "git@github.com:Axis-Fi/uniswap-v2-periphery.git"
checksum = "19be650786731dfe43cac3aac7a2d1f0731d18e2"

[[dependencies]]
name = "@uniswap-v3-core"
version = "1.0.1-solc-0.8-simulate"
source = "https://soldeer-revisions.s3.amazonaws.com/@uniswap-v3-core/1_0_1-solc-0_8-simulate_22-01-2024_13:19:52_v3-core.zip"
checksum = "566fc479fe846f41b211a0ddd66f875cd37e2ccb86b3fc4f7fa18bd55266ec7d"

0 comments on commit 521f43d

Please sign in to comment.