Skip to content

Commit

Permalink
Merge pull request #10 from ronin-chain/feature/innovation-zone
Browse files Browse the repository at this point in the history
feat: innovation zone
  • Loading branch information
thaixuandang authored Aug 26, 2024
2 parents e04a962 + df2a9ff commit 18265ab
Show file tree
Hide file tree
Showing 27 changed files with 740 additions and 54 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
deploy-testnet:
op run --env-file="./.env" -- \
forge script DeployKatanaV3Testnet -f ronin-testnet

deploy-testnet-broadcast:
op run --env-file="./.env" -- \
forge script DeployKatanaV3Testnet -f ronin-testnet --verify --verifier sourcify --verifier-url https://sourcify.roninchain.com/server/ --legacy --broadcast
4 changes: 1 addition & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ src = "src"
out = "out"
script = "script"
libs = ["lib"]
ffi = true

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

solc = '0.7.6'
optimizer_runs = 800
evm_version = 'istanbul'
use_literal_content = true
extra_output = ["devdoc", "userdoc", "storagelayout"]
fs_permissions = [{ access = "read-write", path = "./" }]

[fmt]
tab_width = 2
Expand Down
71 changes: 71 additions & 0 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
| Contract | Size (B) | Margin (B) |
|------------------------------------|----------|------------|
| Address | 86 | 24,490 |
| AddressStringUtil | 86 | 24,490 |
| AuthorizationLib | 86 | 24,490 |
| Base64 | 86 | 24,490 |
| BeaconProxy | 785 | 23,791 |
| BitMath | 86 | 24,490 |
| BytesLib | 86 | 24,490 |
| CallbackValidation | 86 | 24,490 |
| ChainId | 86 | 24,490 |
| ERC20 | 2,578 | 21,998 |
| ERC20Mock | 3,518 | 21,058 |
| ERC721 | 6,650 | 17,926 |
| EnumerableMap | 86 | 24,490 |
| EnumerableSet | 86 | 24,490 |
| FixedPoint128 | 86 | 24,490 |
| FixedPoint96 | 86 | 24,490 |
| FullMath | 86 | 24,490 |
| HexStrings | 86 | 24,490 |
| KatanaGovernanceMock | 2,346 | 22,230 |
| KatanaInterfaceMulticall | 1,334 | 23,242 |
| KatanaV2Library | 86 | 24,490 |
| KatanaV2LibraryTestnet | 86 | 24,490 |
| KatanaV3Factory | 2,945 | 21,631 |
| KatanaV3FactoryProxy | 5,541 | 19,035 |
| KatanaV3Pool | 22,864 | 1,712 |
| KatanaV3PoolDeployer | 288 | 24,288 |
| KatanaV3PoolProxy | 1,248 | 23,328 |
| KatanaV3PoolProxyBytecode | 2,931 | 21,645 |
| LiquidityAmounts | 86 | 24,490 |
| LiquidityMath | 86 | 24,490 |
| LowGasSafeMath | 86 | 24,490 |
| MixedRouteQuoterV1 | 7,328 | 17,248 |
| MixedRouteQuoterV1Testnet | 7,328 | 17,248 |
| NFTDescriptor | 23,833 | 743 |
| NFTSVG | 86 | 24,490 |
| NonfungiblePositionManager | 24,381 | 195 |
| NonfungibleTokenPositionDescriptor | 5,219 | 19,357 |
| Oracle | 86 | 24,490 |
| OracleLibrary | 86 | 24,490 |
| PairFlash | 5,510 | 19,066 |
| Path | 86 | 24,490 |
| PoolAddress | 86 | 24,490 |
| PoolTicksCounter | 86 | 24,490 |
| Position | 86 | 24,490 |
| PositionKey | 86 | 24,490 |
| PositionValue | 86 | 24,490 |
| Quoter | 3,944 | 20,632 |
| QuoterV2 | 7,103 | 17,473 |
| SafeCast | 86 | 24,490 |
| SafeERC20Namer | 86 | 24,490 |
| SafeMath | 86 | 24,490 |
| SignedSafeMath | 86 | 24,490 |
| SqrtPriceMath | 86 | 24,490 |
| SqrtPriceMathPartial | 86 | 24,490 |
| Strings | 86 | 24,490 |
| SwapMath | 86 | 24,490 |
| SwapRouter | 10,213 | 14,363 |
| Tick | 86 | 24,490 |
| TickBitmap | 86 | 24,490 |
| TickLens | 1,349 | 23,227 |
| TickMath | 86 | 24,490 |
| TokenRatioSortOrder | 86 | 24,490 |
| TransferHelper | 86 | 24,490 |
| TransparentUpgradeableProxy | 2,107 | 22,469 |
| UnsafeMath | 86 | 24,490 |
| UpgradeableBeacon | 1,208 | 23,368 |
| UpgradeableProxy | 738 | 23,838 |
| V3Migrator | 6,084 | 18,492 |

40 changes: 40 additions & 0 deletions script/DeployKatanaV3Core.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.6;

import { Script, console } from "forge-std/Script.sol";
import { KatanaV3Factory } from "@katana/v3-contracts/core/KatanaV3Factory.sol";
import { KatanaV3FactoryProxy } from "@katana/v3-contracts/core/KatanaV3FactoryProxy.sol";

abstract contract DeployKatanaV3Core is Script {
address public proxyAdmin;
address public governance;
address public treasury;

address public factory;

function setUp() public virtual {
require(proxyAdmin != address(0));
require(governance != address(0));
require(treasury != address(0));
logParams();
}

function run() public virtual {
vm.startBroadcast();

address factoryImplementation = address(new KatanaV3Factory());
factory = address(
new KatanaV3FactoryProxy(
factoryImplementation, proxyAdmin, abi.encodeWithSelector(KatanaV3Factory.initialize.selector, governance, treasury)
)
);
console.log("KatanaV3Factory deployed:", factory);

vm.stopBroadcast();
}

function logParams() internal virtual {
console.log("governance:", governance);
console.log("treasury:", treasury);
}
}
74 changes: 74 additions & 0 deletions script/DeployKatanaV3Periphery.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.6;

import { Script, console } from "forge-std/Script.sol";
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol";
import { NonfungibleTokenPositionDescriptor } from
"@katana/v3-contracts/periphery/NonfungibleTokenPositionDescriptor.sol";
import { NonfungiblePositionManager } from "@katana/v3-contracts/periphery/NonfungiblePositionManager.sol";
import { V3Migrator } from "@katana/v3-contracts/periphery/V3Migrator.sol";
import { TickLens } from "@katana/v3-contracts/periphery/lens/TickLens.sol";
import { QuoterV2 } from "@katana/v3-contracts/periphery/lens/QuoterV2.sol";
import { KatanaInterfaceMulticall } from "@katana/v3-contracts/periphery/lens/KatanaInterfaceMulticall.sol";
import { DeployKatanaV3Core } from "./DeployKatanaV3Core.s.sol";

abstract contract DeployKatanaV3Periphery is DeployKatanaV3Core {
address public wron;
address public factoryV2;

address public tokenDescriptor;
address public nonfungiblePositionManager;
address public v3migrator;
address public tickLens;
address public quoterV2;
address public katanaInterfaceMulticall;

function setUp() public virtual override {
require(wron != address(0));
require(factoryV2 != address(0));

super.setUp();
}

function run() public virtual override {
super.run();

vm.startBroadcast();

tokenDescriptor = address(new NonfungibleTokenPositionDescriptor(wron, "RON"));
console.log("NonfungibleTokenPositionDescriptor deployed:", tokenDescriptor);

address nonfungiblePositionManagerImplementation =
address(new NonfungiblePositionManager(factory, wron, tokenDescriptor));
nonfungiblePositionManager = address(
new TransparentUpgradeableProxy(
nonfungiblePositionManagerImplementation,
proxyAdmin,
abi.encodeWithSelector(NonfungiblePositionManager.initialize.selector)
)
);
require(NonfungiblePositionManager(payable(nonfungiblePositionManager)).governance() == governance, "governance mismatch");
console.log("NonfungiblePositionManager deployed:", nonfungiblePositionManager);

v3migrator = address(new V3Migrator(factory, wron, nonfungiblePositionManager));
console.log("V3Migrator deployed:", v3migrator);

tickLens = address(new TickLens());
console.log("TickLens deployed:", tickLens);

quoterV2 = address(new QuoterV2(factory, wron));
console.log("QuoterV2 deployed:", quoterV2);

katanaInterfaceMulticall = address(new KatanaInterfaceMulticall());
console.log("KatanaInterfaceMulticall deployed:", katanaInterfaceMulticall);

vm.stopBroadcast();
}

function logParams() internal virtual override {
super.logParams();

console.log("WRON:", wron);
console.log("factoryV2:", factoryV2);
}
}
31 changes: 31 additions & 0 deletions script/local/DeployKatanaV3Local.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.6;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { DeployKatanaV3Periphery } from "../DeployKatanaV3Periphery.s.sol";
import { MixedRouteQuoterV1 } from "@katana/v3-contracts/periphery/lens/MixedRouteQuoterV1.sol";
import { KatanaGovernanceMock } from "@katana/v3-contracts/external/KatanaGovernanceMock.sol";
import { ERC20Mock } from "@openzeppelin/contracts/mocks/ERC20Mock.sol";

contract DeployKatanaV3Local is DeployKatanaV3Periphery {
address mixedRouteQuoterV1;

function setUp() public override {
proxyAdmin = makeAddr("ProxyAdmin");
governance = address(new KatanaGovernanceMock(address(0), address(0), true));
treasury = makeAddr("RoninTreasury");
wron = address(new ERC20Mock("Wrapped Ronin", "WRON", address(this), 10 ** 9 * 10 ** 9));
factoryV2 = makeAddr("KatanaV2Factory");

super.setUp();
}

function run() public override {
super.run();

vm.broadcast();
mixedRouteQuoterV1 = address(new MixedRouteQuoterV1(factory, factoryV2, wron));
console.log("MixedRouteQuoterV1 deployed:", mixedRouteQuoterV1);
}
}
31 changes: 31 additions & 0 deletions script/ronin-mainnet/DeployKatanaV3Mainnet.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.6;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { DeployKatanaV3Periphery } from "../DeployKatanaV3Periphery.s.sol";
import { MixedRouteQuoterV1 } from "@katana/v3-contracts/periphery/lens/MixedRouteQuoterV1.sol";

contract DeployKatanaV3Mainnet is DeployKatanaV3Periphery {
address mixedRouteQuoterV1;

function setUp() public override {
proxyAdmin = 0xA3e7d085E65CB0B916f6717da876b7bE5cC92f03; // Proxy Admin
governance = 0x2C1726346d83cBF848bD3C2B208ec70d32a9E44a; // Governance Proxy
treasury = 0x22cEfc91E9b7c0f3890eBf9527EA89053490694e; // Ronin Treasury
wron = 0xe514d9DEB7966c8BE0ca922de8a064264eA6bcd4; // WRON
factoryV2 = 0xB255D6A720BB7c39fee173cE22113397119cB930; // Katana V2 Factory

vm.rememberKey(vm.envUint("MAINNET_PK"));

super.setUp();
}

function run() public override {
super.run();

vm.broadcast();
mixedRouteQuoterV1 = address(new MixedRouteQuoterV1(factory, factoryV2, wron));
console.log("MixedRouteQuoterV1 deployed:", mixedRouteQuoterV1);
}
}
31 changes: 31 additions & 0 deletions script/ronin-testnet/DeployKatanaV3Testnet.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.6;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { DeployKatanaV3Periphery } from "../DeployKatanaV3Periphery.s.sol";
import { MixedRouteQuoterV1Testnet } from "@katana/v3-contracts/periphery/lens/MixedRouteQuoterV1Testnet.sol";

contract DeployKatanaV3Testnet is DeployKatanaV3Periphery {
address mixedRouteQuoterV1Testnet;

function setUp() public override {
proxyAdmin = 0x505d91E8fd2091794b45b27f86C045529fa92CD7;
governance = 0x247F12836A421CDC5e22B93Bf5A9AAa0f521f986;
treasury = 0x968D0Cd7343f711216817E617d3f92a23dC91c07;
wron = 0xA959726154953bAe111746E265E6d754F48570E6;
factoryV2 = 0x86587380C4c815Ba0066c90aDB2B45CC9C15E72c;

vm.rememberKey(vm.envUint("TESTNET_PK"));

super.setUp();
}

function run() public override {
super.run();

vm.broadcast();
mixedRouteQuoterV1Testnet = address(new MixedRouteQuoterV1Testnet(factory, factoryV2, wron));
console.log("MixedRouteQuoterV1Testnet deployed:", mixedRouteQuoterV1Testnet);
}
}
4 changes: 4 additions & 0 deletions src/core/KatanaV3Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import "./KatanaV3PoolDeployer.sol";

import "./KatanaV3Pool.sol";

import "../external/libraries/AuthorizationLib.sol";

/// @title Canonical Katana V3 factory
/// @notice Deploys Katana V3 pools and manages ownership and control over pool protocol fees
contract KatanaV3Factory is IKatanaV3Factory, KatanaV3PoolDeployer {
Expand Down Expand Up @@ -60,6 +62,8 @@ contract KatanaV3Factory is IKatanaV3Factory, KatanaV3PoolDeployer {

/// @inheritdoc IKatanaV3Factory
function createPool(address tokenA, address tokenB, uint24 fee) external override returns (address pool) {
AuthorizationLib.checkPositionManager(owner);

require(tokenA != tokenB);
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0));
Expand Down
13 changes: 11 additions & 2 deletions src/core/KatanaV3FactoryProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts/proxy/UpgradeableBeacon.sol";

import "./interfaces/IKatanaV3FactoryImmutables.sol";
import "./interfaces/IKatanaV3Factory.sol";

import "./KatanaV3Pool.sol";
import "./KatanaV3PoolProxy.sol";
Expand All @@ -18,13 +19,21 @@ contract KatanaV3FactoryProxy is TransparentUpgradeableProxy, IKatanaV3FactoryIm
/// @inheritdoc IKatanaV3FactoryImmutables
address public immutable override BEACON;

constructor(address _logic, address admin_, bytes memory _data) TransparentUpgradeableProxy(_logic, admin_, _data) {
constructor(address _logic, address proxyAdmin, bytes memory _data) TransparentUpgradeableProxy(_logic, proxyAdmin, _data) {
POOL_PROXY_BYTECODE_POINTER = address(new KatanaV3PoolProxyBytecode());

address poolImplementation = address(new KatanaV3Pool());
address governance;
assembly {
// the first 32 bytes of _data is the length of the bytes array
// the next 4 bytes is the function selector of the initialize function (initialize(address,address))
// the next 32 bytes (start at offset 36) is the owner (governance) address
governance := mload(add(_data, 36))
}
address poolImplementation = address(new KatanaV3Pool(address(this), governance));
BEACON = address(new UpgradeableBeacon(poolImplementation));
}

/// @notice Upgrades the beacon to a new pool implementation
function upgradeBeaconTo(address newImplementation) external ifAdmin {
UpgradeableBeacon(BEACON).upgradeTo(newImplementation);
}
Expand Down
Loading

0 comments on commit 18265ab

Please sign in to comment.