Skip to content

Commit

Permalink
feat: added deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSolDev committed Dec 12, 2024
1 parent 28ec9a5 commit 93d0f27
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 77 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ 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 API_KEY_BASESCAN="YOUR_API_KEY_BASESCAN"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
export FOUNDRY_PROFILE="default"
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@ out
.pnp.*
lcov.info
package-lock.json
pnpm-lock.yaml

# broadcasts
!broadcast
broadcast/*
broadcast/*/31337/
pnpm-lock.yaml
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";
import { StableAssetFactory } from "../src/StableAssetFactory.sol";

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

uint256 deployerPrivateKey;
uint256 initialMinterPrivateKey;

address GOVERNANCE;
address DEPLOYER;
address INITIAL_MINTER;

address usdc;
address usdt;

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

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

function loadConfig() internal {
if (!testnet) {
usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
usdt = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
}
}
}
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()
);
}
}
65 changes: 65 additions & 0 deletions script/Pool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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";

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,
address decodedStableAsset,
) internal {
console.log("---------------");
console.log("initial-mint-logs");
console.log("---------------");

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

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

StableAsset stableAsset = StableAsset(decodedStableAsset);
stableAsset.mint(amounts, 0);
}
}
18 changes: 18 additions & 0 deletions script/Setup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;


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

contract Setup is Config {
function deployMocks() internal {
MockToken tokenA = new MockToken("USDC", "USDC", 6);
MockToken tokenB = new MockToken("USDT", "USDT", 6);

usdc = address(tokenA);
usdt = address(tokenB);
}
}
65 changes: 65 additions & 0 deletions script/Testnet.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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";

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

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

vm.startBroadcast(deployerPrivateKey);

deployMocks();
deployBeacons();
deployFactory();

vm.writeJson(
vm.serializeAddress("contracts", "USDC", usdc),
"./broadcast/testnet.json"
);

vm.writeJson(
vm.serializeAddress("contracts", "USDT", usdt),
"./broadcast/testnet.json"
);

vm.writeJson(
vm.serializeAddress("contracts", "Factory", address(factory)),
"./broadcast/testnet.json"
);

vm.writeJson(
vm.serializeAddress("contracts", "StableAssetBeacon", stableAssetBeacon),
"./broadcast/testnet.json"
);

vm.writeJson(
vm.serializeAddress("contracts", "LPTokenBeacon", lpTokenBeacon),
"./broadcast/testnet.json"
);

vm.writeJson(
vm.serializeAddress("contracts", "WLPTokenBeacon", wlpTokenBeacon),
"./broadcast/testnet.json"
);



vm.stopBroadcast();
}
}

0 comments on commit 93d0f27

Please sign in to comment.