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

feat: factory enhancements #59

Merged
merged 67 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
cdd4e40
feat: use beacon
0xSolDev Dec 9, 2024
881ea96
feat: added configs
0xSolDev Dec 10, 2024
014d415
feat: modify symbol
0xSolDev Dec 10, 2024
0c052c1
fix: added admin modified event
0xSolDev Dec 10, 2024
c2e61a8
feat: choose exchange rate provider
0xSolDev Dec 11, 2024
39d6dd3
feat: renamed lp token contracts
0xSolDev Dec 11, 2024
3de94d1
feat: auto percision
0xSolDev Dec 11, 2024
e0d94f7
feat: wip - tests
0xSolDev Dec 11, 2024
7f42b40
feat: check balance in test
0xSolDev Dec 12, 2024
99af94b
fix: fixed build
0xSolDev Dec 12, 2024
28ec9a5
fix: fixed factory size
0xSolDev Dec 12, 2024
93d0f27
feat: added deployment scripts
0xSolDev Dec 12, 2024
466f46e
chore: fixed lint
0xSolDev Dec 12, 2024
3650acb
fix: fixed build
0xSolDev Dec 12, 2024
ad8b003
feat: deployed to testnet
0xSolDev Dec 13, 2024
c31ef7b
feat: instructions to verify contract
0xSolDev Dec 13, 2024
16a059c
feat: added create pool script
0xSolDev Dec 13, 2024
358c676
fix: redeployed
0xSolDev Dec 13, 2024
9ef1bd9
fix: updated to v1.5 audited code
0xSolDev Dec 16, 2024
b7debda
fix: fixed compiler version
0xSolDev Dec 16, 2024
38f09c2
fix: fixed lint
0xSolDev Dec 16, 2024
a655f38
fix: removed lastRedeemOrMint
0xSolDev Dec 16, 2024
77caec2
fix: removed lastRedeemOrMint
0xSolDev Dec 16, 2024
68aef87
feat: added types for token A
0xSolDev Dec 17, 2024
3b31965
feat: added a unit test
0xSolDev Dec 17, 2024
dc5e9fa
feat: added test for exchange rate tokens
0xSolDev Dec 17, 2024
1b39a88
fix: fixed lint
0xSolDev Dec 17, 2024
5274a0e
feat: convert WLPToken to ERC4626 standard
0xSolDev Dec 18, 2024
777c498
feat: use uups upgrades
0xSolDev Dec 18, 2024
3e49ab3
fix: fixed lint
0xSolDev Dec 18, 2024
64a16b2
feat: updated governance model for factory
0xSolDev Dec 19, 2024
ee4c890
fix: fixed test
0xSolDev Dec 19, 2024
30ab88e
fix: fixed scripts
0xSolDev Dec 19, 2024
ea8bfe6
fix: remove timelock from factory
0xSolDev Dec 21, 2024
421add1
feat: renamed to self pegging asset
0xSolDev Dec 23, 2024
19e12d4
feat: use custom errors
0xSolDev Dec 24, 2024
d31c92f
fix: fixed admin privilages
0xSolDev Dec 24, 2024
fd0f54d
fix: merge conflict
0xSolDev Dec 24, 2024
5677293
fix: removed application contract
0xSolDev Dec 25, 2024
d8e4540
fix: merge conflict
0xSolDev Dec 25, 2024
d7da416
feat: added netspec
0xSolDev Dec 25, 2024
846fa0c
fix: added netspec
0xSolDev Dec 25, 2024
6d763d4
fix: refactored tests
0xSolDev Dec 25, 2024
b3e76a4
feat: upgraded oz
0xSolDev Dec 28, 2024
f30361a
feat: added tests
0xSolDev Dec 28, 2024
9f2a7be
feat: added tests
0xSolDev Dec 28, 2024
790ba15
feat: added tests
0xSolDev Dec 28, 2024
8b03f90
feat: added tests
0xSolDev Dec 28, 2024
acbf81b
feat: added tests
0xSolDev Dec 28, 2024
2e87c5e
feat: reverted tests
0xSolDev Dec 28, 2024
cfe6617
feat: added lp and wlp token tests
0xSolDev Dec 29, 2024
1a28658
feat: deployed on base sepolia
0xSolDev Dec 30, 2024
88d46b4
feat: created pool
0xSolDev Dec 30, 2024
dc3116d
fix: revert contract
0xSolDev Dec 30, 2024
78e79e0
fix: updated readme
0xSolDev Dec 30, 2024
323b737
fix: fixed lint
0xSolDev Dec 31, 2024
b376364
fix: fixed lint
0xSolDev Dec 31, 2024
b443603
Merge pull request #66 from nutsfinance/feat/demo-deployment
0xSolDev Dec 31, 2024
27790a9
Merge pull request #65 from nutsfinance/feat/tests
0xSolDev Dec 31, 2024
3b60b4a
Merge pull request #64 from nutsfinance/feat/coding-standard
0xSolDev Dec 31, 2024
993b4c7
Merge pull request #63 from nutsfinance/feat/timelock-integration
0xSolDev Dec 31, 2024
db8eaed
Merge pull request #62 from nutsfinance/feat/uups-upgradable
0xSolDev Dec 31, 2024
89e99ce
feat: overwrite preview and withdraw funcs
0xSolDev Dec 31, 2024
4ff4518
fix: remove duplicate override
0xSolDev Dec 31, 2024
c07f54e
fix: added mint function override
0xSolDev Dec 31, 2024
430f9d3
Merge pull request #61 from nutsfinance/feat/erc-4626
0xSolDev Dec 31, 2024
de3d17d
Merge pull request #60 from nutsfinance/feat/token-a-types
0xSolDev Dec 31, 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
13 changes: 2 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY"
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN"
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN"
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN"
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN"
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN"
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN"
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
export TESTNET=true
export HEX_PRIV_KEY="HEX_PRIV_KEY"
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cache
coverage
node_modules
out
broadcast/**/dry-run/

# files
*.env
Expand All @@ -11,9 +12,4 @@ out
.pnp.*
lcov.info
package-lock.json
pnpm-lock.yaml

# broadcasts
!broadcast
broadcast/*
broadcast/*/31337/
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"code-complexity": ["error", 10],
"code-complexity": ["error", 12],
"compiler-version": ["error", ">=0.8.25"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
Expand Down
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,27 @@ Get a test coverage report:
$ forge coverage
```

### Deploy
### Deploy to Testnet

Deploy to Anvil:
Deploy to Base Testnet:

```sh
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
$ forge script ./script/Testnet.s.sol -vvv --rpc-url basesepolia --broadcast
```

For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
[BIP39 mnemonic](https://iancoleman.io/bip39/).
Before deploying make sure you configure the neccessary variables in `.env` file. To just test the scripts with just a
dry run remove the `--broadcast` flag.

For instructions on how to deploy to a testnet or mainnet, check out the
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial.
### Verifying Contracts on Testnet Explorer

Here is an example on how to verify a contract on base sepolia:

```sh
$ forge verify-contract <contract-address> <contract-name> --watch --etherscan-api-key <basescan-api-key> --chain-id 84532 --constructor-args <encoded-constructor-args>
```

You can find the contract name and constructor args in the broadcast directory. To encode the constructor args you can
use: https://abi.hashex.org/

### Format

Expand Down
646 changes: 646 additions & 0 deletions broadcast/Testnet.s.sol/84532/run-1734076338.json

Large diffs are not rendered by default.

646 changes: 646 additions & 0 deletions broadcast/Testnet.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions broadcast/testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Factory": "0xe9d56BCB586055ceFCF4b6F2c2c1d6609FaF2220",
"LPTokenBeacon": "0xBee14A59a6320517C10CE1CEdC155A91D14d4707",
"StableAssetBeacon": "0xA3c7eD546862d36a05A54fC17698C77153A1a8CE",
"USDC": "0xA0a69B70015288515316D5DEd2e4D4f84bd11854",
"USDT": "0xA0AC882fD07D63C7e660a54729fDEF62a908Ac8D",
"WLPTokenBeacon": "0x1D7AdEBAd4b28C0BfD8A62cc4E66EE8D6b33e5BF"
}
14 changes: 2 additions & 12 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,12 @@
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"forge-std/=node_modules/forge-std/src/",
]
fs_permissions = [{ access = "read-write", path = "./"}]

[profile.ci]
fuzz = { runs = 10_000 }
verbosity = 4

[etherscan]
arbitrum = { key = "${API_KEY_ARBISCAN}" }
avalanche = { key = "${API_KEY_SNOWTRACE}" }
base = { key = "${API_KEY_BASESCAN}" }
bnb_smart_chain = { key = "${API_KEY_BSCSCAN}" }
gnosis_chain = { key = "${API_KEY_GNOSISSCAN}" }
goerli = { key = "${API_KEY_ETHERSCAN}" }
mainnet = { key = "${API_KEY_ETHERSCAN}" }
optimism = { key = "${API_KEY_OPTIMISTIC_ETHERSCAN}" }
polygon = { key = "${API_KEY_POLYGONSCAN}" }
sepolia = { key = "${API_KEY_ETHERSCAN}" }

[fmt]
bracket_spacing = true
int_types = "long"
Expand All @@ -59,3 +48,4 @@
optimism = "https://optimism-mainnet.infura.io/v3/${API_KEY_INFURA}"
polygon = "https://polygon-mainnet.infura.io/v3/${API_KEY_INFURA}"
sepolia = "https://sepolia.infura.io/v3/${API_KEY_INFURA}"
basesepolia = "https://sepolia.base.org"
43 changes: 0 additions & 43 deletions script/Base.s.sol

This file was deleted.

41 changes: 41 additions & 0 deletions script/Config.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";

Check warning on line 5 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

imported name console is not used
import { StableAssetFactory } from "../src/StableAssetFactory.sol";

contract Config is Script {
bool testnet = vm.envBool("TESTNET");

Check warning on line 9 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

uint256 deployerPrivateKey;

Check warning on line 11 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state
uint256 initialMinterPrivateKey;

Check warning on line 12 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

address GOVERNANCE;

Check warning on line 14 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check warning on line 14 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Variable name must be in mixedCase
address DEPLOYER;

Check warning on line 15 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check warning on line 15 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Variable name must be in mixedCase
address INITIAL_MINTER;

Check warning on line 16 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check warning on line 16 in script/Config.sol

View workflow job for this annotation

GitHub Actions / lint

Variable name must be in mixedCase

address usdc;
address usdt;

StableAssetFactory factory;
address stableAssetBeacon;
address lpTokenBeacon;
address wlpTokenBeacon;

struct JSONData {
address Factory;
address LPTokenBeacon;
address StableAssetBeacon;
address USDC;
address USDT;
address WLPTokenBeacon;
}

function loadConfig() internal {
if (!testnet) {
usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
usdt = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
}
}
}
56 changes: 56 additions & 0 deletions script/CreatePool.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { stdJson } from "forge-std/StdJson.sol";
import { console } from "forge-std/console.sol";

import { Deploy } from "script/Deploy.sol";
import { Setup } from "script/Setup.sol";
import { Pool } from "script/Pool.sol";
import { StableAssetFactory } from "../src/StableAssetFactory.sol";
import { StableAsset } from "../src/StableAsset.sol";
import { MockToken } from "../src/mock/MockToken.sol";

contract Testnet is Deploy, Setup, Pool {
function init() internal {
if (vm.envUint("HEX_PRIV_KEY") == 0) revert("No private key found");
initialMinterPrivateKey = vm.envUint("HEX_PRIV_KEY");
INITIAL_MINTER = vm.addr(initialMinterPrivateKey);
}

function run() public payable {
init();
loadConfig();

vm.startBroadcast(initialMinterPrivateKey);

string memory root = vm.projectRoot();
string memory path;
if (testnet) {
path = string.concat(root, "/broadcast/testnet.json");
} else {
path = string.concat(root, "/broadcast/mainnet.json");
}

string memory json = vm.readFile(path);
bytes memory data = vm.parseJson(json);

JSONData memory jsonData = abi.decode(data, (JSONData));

factory = StableAssetFactory(jsonData.Factory);
stableAssetBeacon = jsonData.StableAssetBeacon;
lpTokenBeacon = jsonData.LPTokenBeacon;
wlpTokenBeacon = jsonData.WLPTokenBeacon;
usdc = jsonData.USDC;
usdt = jsonData.USDT;

(, address stableAsset,) = createStandardPool();

MockToken(usdc).mint(INITIAL_MINTER, 100e18);
MockToken(usdt).mint(INITIAL_MINTER, 100e18);

initialMintAndUnpause(100e18, 100e18, StableAsset(stableAsset));

vm.stopBroadcast();
}
}
15 changes: 0 additions & 15 deletions script/Deploy.s.sol

This file was deleted.

56 changes: 56 additions & 0 deletions script/Deploy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { console } from "forge-std/console.sol";
import { StableAsset } from "../src/StableAsset.sol";
import { LPToken } from "../src/LPToken.sol";
import { WLPToken } from "../src/WLPToken.sol";
import { StableAssetFactory } from "../src/StableAssetFactory.sol";
import { Config } from "script/Config.sol";
import "../src/misc/ConstantExchangeRateProvider.sol";

contract Deploy is Config {
function deployBeacons() internal {
console.log("---------------");
console.log("deploy-beacon-logs");
console.log("---------------");

address stableAssetImplentation = address(new StableAsset());
address lpTokenImplentation = address(new LPToken());
address wlpTokenImplentation = address(new WLPToken());

UpgradeableBeacon beacon = new UpgradeableBeacon(stableAssetImplentation);
beacon.transferOwnership(GOVERNANCE);
stableAssetBeacon = address(beacon);

beacon = new UpgradeableBeacon(lpTokenImplentation);
beacon.transferOwnership(GOVERNANCE);
lpTokenBeacon = address(beacon);

beacon = new UpgradeableBeacon(wlpTokenImplentation);
beacon.transferOwnership(GOVERNANCE);
wlpTokenBeacon = address(beacon);
}

function deployFactory() internal {
console.log("---------------");
console.log("deploy-factory-logs");
console.log("---------------");

factory = new StableAssetFactory();

factory.initialize(
GOVERNANCE,
0,
0,
0,
100,
stableAssetBeacon,
lpTokenBeacon,
wlpTokenBeacon,
new ConstantExchangeRateProvider()
);
}
}
63 changes: 63 additions & 0 deletions script/Pool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import { Vm } from "forge-std/Vm.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { console } from "forge-std/console.sol";
import { Config } from "script/Config.sol";
import { StableAssetFactory } from "../src/StableAssetFactory.sol";
import { StableAsset } from "../src/StableAsset.sol";
import { MockToken } from "../src/mock/MockToken.sol";

contract Pool is Config {
function createStandardPool() internal returns (address, address, address) {
console.log("---------------");
console.log("create-pool-logs");
console.log("---------------");

StableAssetFactory.CreatePoolArgument memory arg = StableAssetFactory.CreatePoolArgument({
tokenA: usdc,
tokenB: usdt,
initialMinter: INITIAL_MINTER,
tokenBType: StableAssetFactory.TokenBType.Standard,
tokenBOracle: address(0),
tokenBFunctionSig: ""
});

vm.recordLogs();
factory.createPool(arg);
Vm.Log[] memory entries = vm.getRecordedLogs();
bytes32 eventSig = keccak256("PoolCreated(address,address,address)");

address decodedPoolToken;
address decodedStableAsset;
address decodedWrappedPoolToken;

for (uint256 i = 0; i < entries.length; i++) {
Vm.Log memory log = entries[i];

if (log.topics[0] == eventSig) {
(decodedPoolToken, decodedStableAsset, decodedWrappedPoolToken) =
abi.decode(log.data, (address, address, address));
}
}

return (decodedPoolToken, decodedStableAsset, decodedWrappedPoolToken);
}

function initialMintAndUnpause(uint256 usdcAmount, uint256 usdtAmount, StableAsset stableAsset) internal {
console.log("---------------");
console.log("initial-mint-logs");
console.log("---------------");

MockToken(usdc).approve(address(factory), usdcAmount);
MockToken(usdt).approve(address(factory), usdtAmount);

uint256[] memory amounts = new uint256[](2);
amounts[0] = usdcAmount;
amounts[1] = usdtAmount;

stableAsset.mint(amounts, 0);
stableAsset.unpause();
}
}
Loading
Loading