Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradual Dutch Auction Module #177

Open
wants to merge 71 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2df6a18
forge install: prb-math
Oighty Apr 30, 2024
aa3fa81
git: use modified prb-math
Oighty May 1, 2024
f8fa62f
chore: update install script
Oighty May 1, 2024
6025353
feat: initial GDA implementation
Oighty May 1, 2024
bf170a7
fix: minor GDA updates and add'l TODOs
Oighty May 1, 2024
ef82640
fix: change gda timestamps to be uint256
Oighty May 1, 2024
43ddff1
Remove prb-math submodule
0xJem May 1, 2024
7208c4b
Re-add prb-math
0xJem May 1, 2024
3c75f34
If the deployed address of a required contract (UniV2/V3 factory, GUn…
0xJem May 1, 2024
19bd856
chore: linting
0xJem May 1, 2024
bb3b8de
Add forge test config into foundry.toml
0xJem May 1, 2024
81ab2bc
feat: handle positive and negative T in GDA
Oighty May 1, 2024
ad504e9
refactor: simplify gda inputs and add some bounds
Oighty May 1, 2024
e140c16
fix: compile error
Oighty May 2, 2024
c71aeb2
fix: use constant bounds for GDA and rename target
Oighty May 2, 2024
b4c65a5
fix: convert times to fixed point days in GDA and add bounds
Oighty May 2, 2024
79375d6
chore: remove previously added constant and clarify docs
Oighty May 2, 2024
fe594b3
chore: switch out solady for prb-math in GDA
Oighty May 2, 2024
57c69e7
feat: avoid overflows and clean-up TODOs
Oighty May 8, 2024
c916291
chore: only one math lib in GDA
Oighty May 15, 2024
68bf9fa
test: add GDA test base contract
Oighty May 15, 2024
b0e0c96
fix: remove extra checks and update min decay period
Oighty May 21, 2024
a464b8e
fix: divide decay constant seconds by one day
Oighty May 21, 2024
212da97
test: wip on create auction tests for GDA
Oighty May 21, 2024
a05403f
test: finish GDA create auction tests
Oighty May 22, 2024
e9e1c6f
Merge branch 'fixed-batch' into gda-new
Oighty May 22, 2024
954de7a
refactor: add GDA interface and fix test compile
Oighty May 22, 2024
24d04a6
chore: update test salts
Oighty May 22, 2024
f26456d
test: GDA priceFor tests
Oighty May 22, 2024
d5ca25f
test: more priceFor test updates
Oighty May 22, 2024
6ef438d
fix: gda price equations, includes temp logging
Oighty May 23, 2024
a127c22
test: wip GDA payoutFor tests
Oighty May 23, 2024
3b0ddad
fix: add'l validation and temp logging in GDA
Oighty May 23, 2024
ab575b7
test: add'l GDA tests, still some TODOs
Oighty May 24, 2024
bee920c
chore: update prb-math dependency
Oighty May 24, 2024
b52abc6
fix: reduce error correction based on library improvements
Oighty May 24, 2024
849f40c
fix: compile error in test
Oighty May 24, 2024
1492909
wip: more GDA error bounds
Oighty May 28, 2024
73744fe
fix: update and clarify decay constant + min price bounds
Oighty May 28, 2024
fa46470
test: update GDA create auction tests
Oighty May 28, 2024
2e3e463
test: max amount out GDA test updates
Oighty May 28, 2024
af65d5c
wip: GDA priceFor test updates
Oighty May 28, 2024
1371ddd
chore: remove default verbosity from foundry config
Oighty May 28, 2024
1b0fba9
chore: lint
Oighty May 28, 2024
70a9655
test: GDA test improvements, most passing
Oighty May 29, 2024
83498e2
fix: priceFor rounding behavior
Oighty Sep 17, 2024
c7d754c
test: update failing GDA payoutFor and priceFor tests
Oighty Sep 17, 2024
8f86132
Merge branch 'develop' into gda-new
Oighty Sep 17, 2024
421c131
chore: lint
Oighty Sep 17, 2024
0fbc3cb
chore: fix remapping and compile issues
Oighty Sep 17, 2024
fb9a252
chore: lint
Oighty Sep 17, 2024
ffa9761
chore: soldeer updates
Oighty Sep 19, 2024
cc1c3b9
chore: remove submodule dep
Oighty Sep 19, 2024
18ded86
chore: update GDA deps
Oighty Sep 19, 2024
e9dc8d4
chore: lint (new forge fmt)
Oighty Sep 19, 2024
a47af6b
chore: minor cleanup
Oighty Sep 19, 2024
40a9d88
test: gda test updates to catch edge cases
Oighty Sep 19, 2024
a4781f5
test: update test salts
Oighty Sep 19, 2024
d8109fd
NatSpec for error
0xJem Sep 24, 2024
cad6b71
Cleanup
0xJem Sep 24, 2024
43338b8
Improve NatSpec output
0xJem Sep 24, 2024
131581e
Typos
0xJem Sep 25, 2024
b471433
Test TODOs
0xJem Sep 25, 2024
858a216
Additional test coverage
0xJem Sep 26, 2024
3c08fdf
Update soldeer.lock
0xJem Sep 26, 2024
8a91bec
Additional fuzz tests
0xJem Sep 26, 2024
fe5037d
chore: linting
0xJem Sep 26, 2024
c9f4790
Decimal tests
0xJem Sep 27, 2024
7e2b780
Attempt at pre-calculated tests
0xJem Sep 27, 2024
1f79e10
Amendments to calculations in tests
0xJem Sep 30, 2024
58eaf95
Adjustments to calculations. New test cases for days 1 and 2.
0xJem Sep 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ Then, the test suite can be run with:
pnpm run test
```

Or:

```shell
forge test
```

This command usually performs faster than the `pnpm` command.

#### Address Mismatch

Many of the contracts (e.g. callbacks) require a specific address prefix or have a deterministic address. If tests are failing for this reason, the cause is usually one of:
Expand Down
9 changes: 6 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ fs_permissions = [{access = "read-write", path = "./bytecode/"}, {access = "read
ffi = true
solc_version = "0.8.19"
evm_version = "paris"
no-match-test = "optimal"

[fuzz]
runs = 1024
runs = 4096
max_test_rejects = 20000000

# Remappings are setup using remappings.txt, since forge seems to ignore remappings here

Expand All @@ -27,7 +29,8 @@ ignore = [

[dependencies]
forge-std = { version = "1.9.1" }
solmate = { version = "6.7.0", url = "git@github.com:transmissions11/solmate.git", commit = "c892309933b25c03d32b1b0d674df7ae292ba925" }
solmate = { version = "6.7.0", git = "https://github.com/transmissions11/solmate.git", rev = "c892309933b25c03d32b1b0d674df7ae292ba925" }
solady = { version = "0.0.124" }
"@openzeppelin-contracts" = { version = "4.9.2" }
clones-with-immutable-args = { version = "1.1.1", git = "[email protected]:wighawag/clones-with-immutable-args.git", rev = "f5ca191afea933d50a36d101009b5644dc28bc99" }
clones-with-immutable-args = { version = "1.1.1", git = "https://github.com/wighawag/clones-with-immutable-args.git", rev = "f5ca191afea933d50a36d101009b5644dc28bc99" }
prb-math = { version = "4.0-axis", git = "https://github.com/Oighty/prb-math" }
7 changes: 4 additions & 3 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@clones-with-immutable-args-1.1.1=dependencies/clones-with-immutable-args-1.1.1/src
@forge-std-1.9.1=dependencies/forge-std-1.9.1/src
@solmate-6.7.0=dependencies/solmate-6.7.0/src
@solady-0.0.124=dependencies/solady-0.0.124/src
@openzeppelin-contracts-4.9.2=dependencies/@openzeppelin-contracts-4.9.2
@clones-with-immutable-args-1.1.1=dependencies/clones-with-immutable-args-1.1.1/src
@solady-0.0.124=dependencies/solady-0.0.124/src
@solmate-6.7.0=dependencies/solmate-6.7.0/src
prb-math-4.0-axis/=dependencies/prb-math-4.0-axis/src
36 changes: 27 additions & 9 deletions script/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ contract Deploy is Script, WithEnvironment, WithSalts {
if (saveDeployment) _saveDeployment(chain_);
}

function _saveDeployment(string memory chain_) internal {
function _saveDeployment(
string memory chain_
) internal {
// Create the deployments folder if it doesn't exist
if (!vm.isDir("./deployments")) {
console2.log("Creating deployments directory");
Expand Down Expand Up @@ -349,7 +351,9 @@ contract Deploy is Script, WithEnvironment, WithSalts {

// ========== CATALOGUE DEPLOYMENTS ========== //

function deployAtomicCatalogue(bytes memory) public virtual returns (address, string memory) {
function deployAtomicCatalogue(
bytes memory
) public virtual returns (address, string memory) {
// No args used
console2.log("");
console2.log("Deploying AtomicCatalogue");
Expand Down Expand Up @@ -378,7 +382,9 @@ contract Deploy is Script, WithEnvironment, WithSalts {
return (address(atomicCatalogue), _PREFIX_DEPLOYMENT_ROOT);
}

function deployBatchCatalogue(bytes memory) public virtual returns (address, string memory) {
function deployBatchCatalogue(
bytes memory
) public virtual returns (address, string memory) {
// No args used
console2.log("");
console2.log("Deploying BatchCatalogue");
Expand Down Expand Up @@ -442,7 +448,9 @@ contract Deploy is Script, WithEnvironment, WithSalts {
return (address(amEmp), _PREFIX_AUCTION_MODULES);
}

function deployFixedPriceSale(bytes memory) public virtual returns (address, string memory) {
function deployFixedPriceSale(
bytes memory
) public virtual returns (address, string memory) {
// No args used
console2.log("");
console2.log("Deploying FixedPriceSale");
Expand Down Expand Up @@ -471,7 +479,9 @@ contract Deploy is Script, WithEnvironment, WithSalts {
return (address(amFps), _PREFIX_AUCTION_MODULES);
}

function deployFixedPriceBatch(bytes memory) public virtual returns (address, string memory) {
function deployFixedPriceBatch(
bytes memory
) public virtual returns (address, string memory) {
// No args used
console2.log("");
console2.log("Deploying FixedPriceBatch");
Expand Down Expand Up @@ -566,17 +576,23 @@ contract Deploy is Script, WithEnvironment, WithSalts {

// ========== HELPER FUNCTIONS ========== //

function _isAtomicAuctionHouse(string memory deploymentName) internal pure returns (bool) {
function _isAtomicAuctionHouse(
string memory deploymentName
) internal pure returns (bool) {
return keccak256(bytes(deploymentName)) == keccak256(_ATOMIC_AUCTION_HOUSE_NAME)
|| keccak256(bytes(deploymentName)) == keccak256(_BLAST_ATOMIC_AUCTION_HOUSE_NAME);
}

function _isBatchAuctionHouse(string memory deploymentName) internal pure returns (bool) {
function _isBatchAuctionHouse(
string memory deploymentName
) internal pure returns (bool) {
return keccak256(bytes(deploymentName)) == keccak256(_BATCH_AUCTION_HOUSE_NAME)
|| keccak256(bytes(deploymentName)) == keccak256(_BLAST_BATCH_AUCTION_HOUSE_NAME);
}

function _isAuctionHouse(string memory deploymentName) internal pure returns (bool) {
function _isAuctionHouse(
string memory deploymentName
) internal pure returns (bool) {
return _isAtomicAuctionHouse(deploymentName) || _isBatchAuctionHouse(deploymentName);
}

Expand Down Expand Up @@ -623,7 +639,9 @@ contract Deploy is Script, WithEnvironment, WithSalts {
///
/// @param key_ Key to look for
/// @return address Returns the address
function _getAddressNotZero(string memory key_) internal view returns (address) {
function _getAddressNotZero(
string memory key_
) internal view returns (address) {
// Get from the deployed addresses first
address deployedAddress = deployedTo[key_];

Expand Down
8 changes: 6 additions & 2 deletions script/deploy/DeployBlast.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ contract DeployBlast is Deploy {
return (address(amEmp), _PREFIX_AUCTION_MODULES);
}

function deployFixedPriceSale(bytes memory) public override returns (address, string memory) {
function deployFixedPriceSale(
bytes memory
) public override returns (address, string memory) {
// No args used
console2.log("");
console2.log("Deploying BlastFPS (Fixed Price Sale)");
Expand Down Expand Up @@ -152,7 +154,9 @@ contract DeployBlast is Deploy {
return (address(amFps), _PREFIX_AUCTION_MODULES);
}

function deployFixedPriceBatch(bytes memory) public override returns (address, string memory) {
function deployFixedPriceBatch(
bytes memory
) public override returns (address, string memory) {
// No args used
console2.log("");
console2.log("Deploying BlastFPB (Fixed Price Batch)");
Expand Down
12 changes: 9 additions & 3 deletions script/deploy/WithEnvironment.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ abstract contract WithEnvironment is Script {
string public chain;
string public env;

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

Expand All @@ -24,7 +26,9 @@ abstract contract WithEnvironment is Script {
///
/// @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) {
function _envAddress(
string memory key_
) internal view returns (address) {
console2.log(" Checking in env.json");
string memory fullKey = string.concat(".current.", chain, ".", key_);
address addr;
Expand All @@ -47,7 +51,9 @@ abstract contract WithEnvironment is Script {
///
/// @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) {
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")
Expand Down
8 changes: 6 additions & 2 deletions script/ops/Batch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ abstract contract Batch is BatchScript {
string internal chain;
address safe;

modifier isBatch(bool send_) {
modifier isBatch(
bool send_
) {
// Load environment addresses for chain
chain = vm.envString("CHAIN");
env = vm.readFile("./script/env.json");
Expand All @@ -26,7 +28,9 @@ abstract contract Batch is BatchScript {
executeBatch(safe, send_);
}

function envAddress(string memory key) internal view returns (address) {
function envAddress(
string memory key
) internal view returns (address) {
return env.readAddress(string.concat(".", chain, ".", key));
}
}
16 changes: 12 additions & 4 deletions script/ops/lib/BatchScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ abstract contract BatchScript is Script, DelegatePrank {
}

// Encodes the stored encoded transactions into a single Multisend transaction
function _createBatch(address safe_) internal returns (Batch memory batch) {
function _createBatch(
address safe_
) internal returns (Batch memory batch) {
// Set initial batch fields
batch.to = SAFE_MULTISEND_ADDRESS;
batch.value = 0;
Expand Down Expand Up @@ -359,7 +361,9 @@ abstract contract BatchScript is Script, DelegatePrank {
return payload;
}

function _stripSlashQuotes(string memory str_) internal returns (string memory) {
function _stripSlashQuotes(
string memory str_
) internal returns (string memory) {
// solhint-disable quotes
// Remove slash quotes from string
string memory command = string.concat(
Expand All @@ -386,7 +390,9 @@ abstract contract BatchScript is Script, DelegatePrank {
return string(res);
}

function _getNonce(address safe_) internal returns (uint256) {
function _getNonce(
address safe_
) internal returns (uint256) {
string memory endpoint = string.concat(SAFE_API_BASE_URL, vm.toString(safe_), "/");
(uint256 status, bytes memory data) = endpoint.get();
if (status == 200) {
Expand All @@ -397,7 +403,9 @@ abstract contract BatchScript is Script, DelegatePrank {
}
}

function _getSafeAPIEndpoint(address safe_) internal view returns (string memory) {
function _getSafeAPIEndpoint(
address safe_
) internal view returns (string memory) {
return string.concat(SAFE_API_BASE_URL, vm.toString(safe_), SAFE_API_MULTISIG_SEND);
}

Expand Down
20 changes: 15 additions & 5 deletions script/ops/lib/Surl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {Vm} from "@forge-std-1.9.1/Vm.sol";
library Surl {
Vm constant vm = Vm(address(bytes20(uint160(uint256(keccak256("hevm cheat code"))))));

function get(string memory self) internal returns (uint256 status, bytes memory data) {
function get(
string memory self
) internal returns (uint256 status, bytes memory data) {
string[] memory empty = new string[](0);
return get(self, empty);
}
Expand All @@ -18,7 +20,9 @@ library Surl {
return curl(self, headers, "", "GET");
}

function del(string memory self) internal returns (uint256 status, bytes memory data) {
function del(
string memory self
) internal returns (uint256 status, bytes memory data) {
string[] memory empty = new string[](0);
return curl(self, empty, "", "DELETE");
}
Expand All @@ -39,7 +43,9 @@ library Surl {
return curl(self, headers, body, "DELETE");
}

function patch(string memory self) internal returns (uint256 status, bytes memory data) {
function patch(
string memory self
) internal returns (uint256 status, bytes memory data) {
string[] memory empty = new string[](0);
return curl(self, empty, "", "PATCH");
}
Expand All @@ -60,7 +66,9 @@ library Surl {
return curl(self, headers, body, "PATCH");
}

function post(string memory self) internal returns (uint256 status, bytes memory data) {
function post(
string memory self
) internal returns (uint256 status, bytes memory data) {
string[] memory empty = new string[](0);
return curl(self, empty, "", "POST");
}
Expand All @@ -81,7 +89,9 @@ library Surl {
return curl(self, headers, body, "POST");
}

function put(string memory self) internal returns (uint256 status, bytes memory data) {
function put(
string memory self
) internal returns (uint256 status, bytes memory data) {
string[] memory empty = new string[](0);
return curl(self, empty, "", "PUT");
}
Expand Down
15 changes: 15 additions & 0 deletions script/salts/TestSaltConstants.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

abstract contract TestSaltConstants {
address internal constant _OWNER = address(0x1);
address internal constant _AUCTION_HOUSE = address(0x000000000000000000000000000000000000000A);

address internal constant _UNISWAP_V2_FACTORY =
address(0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);
address internal constant _UNISWAP_V2_ROUTER =
address(0x1EBC400fd43aC56937d4e14B8495B0f021e7c876);
address internal constant _UNISWAP_V3_FACTORY =
address(0x7F1bb763E9acE13Ad3488E3d48D4AE1cde6E9604);
address internal constant _GUNI_FACTORY = address(0x2Bc907bF89D72479e6b6A38CC89fdE71672ba90e);
}
4 changes: 3 additions & 1 deletion script/salts/WithSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ contract WithSalts is Script {
return string.concat("./", _BYTECODE_DIR);
}

function _getBytecodePath(string memory name_) internal pure returns (string memory) {
function _getBytecodePath(
string memory name_
) internal pure returns (string memory) {
return string.concat(_getBytecodeDirectory(), "/", name_, ".bin");
}

Expand Down
4 changes: 3 additions & 1 deletion script/salts/auctionHouse/AuctionHouseSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ contract AuctionHouseSalts is Script, WithEnvironment, WithSalts {
address internal _envPermit2;
address internal _envProtocol;

function _setUp(string calldata chain_) internal {
function _setUp(
string calldata chain_
) internal {
_loadEnv(chain_);
_createBytecodeDirectory();

Expand Down
4 changes: 3 additions & 1 deletion script/salts/auctionHouse/AuctionHouseSaltsBlast.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ contract AuctionHouseSaltsBlast is Script, WithEnvironment, WithSalts {
address internal _envWeth;
address internal _envUsdb;

function _setUp(string calldata chain_) internal {
function _setUp(
string calldata chain_
) internal {
_loadEnv(chain_);

// Cache required variables
Expand Down
Loading
Loading