Skip to content

Commit

Permalink
Real: AMM adapter, SetupSwapper, add routes, Forking and RPC setup, S…
Browse files Browse the repository at this point in the history
…hanghai
  • Loading branch information
a17 committed Oct 26, 2024
1 parent f0c6372 commit bbbc7aa
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ POLYGON_RPC_URL=
BASE_RPC_URL=
ARBITRUM_RPC_URL=
ETHEREUM_RPC_URL=
REAL_RPC_URL=
POLYGONSCAN_API_KEY=
BASESCAN_API_KEY=
ARBITRUMSCAN_API_KEY=
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
BASE_RPC_URL: ${{secrets.BASE_RPC_URL}}
ARBITRUM_RPC_URL: ${{secrets.ARBITRUM_RPC_URL}}
ETHEREUM_RPC_URL: ${{secrets.ETHEREUM_RPC_URL}}
REAL_RPC_URL: ${{secrets.REAL_RPC_URL}}
id: test

- name: Run Forge coverage
Expand All @@ -55,6 +56,7 @@ jobs:
BASE_RPC_URL: ${{secrets.BASE_RPC_URL}}
ARBITRUM_RPC_URL: ${{secrets.ARBITRUM_RPC_URL}}
ETHEREUM_RPC_URL: ${{secrets.ETHEREUM_RPC_URL}}
REAL_RPC_URL: ${{secrets.REAL_RPC_URL}}
id: coverage

- name: Upload coverage lcov report to Codecov
Expand Down
10 changes: 6 additions & 4 deletions chains/RealLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.23;
import "../script/libs/LogDeployLib.sol";
import {CommonLib} from "../src/core/libs/CommonLib.sol";
import {IPlatformDeployer} from "../src/interfaces/IPlatformDeployer.sol";
import {AmmAdapterIdLib} from "../src/adapters/libs/AmmAdapterIdLib.sol";
import {ISwapper} from "../src/interfaces/ISwapper.sol";
import {IFactory} from "../src/interfaces/IFactory.sol";
import {StrategyDeveloperLib} from "../src/strategies/libs/StrategyDeveloperLib.sol";
Expand Down Expand Up @@ -137,18 +138,19 @@ library RealLib {
//endregion -- BC pools ----

//region ----- Pools ----
pools = new ISwapper.AddPoolData[](8);
pools = new ISwapper.AddPoolData[](11);
uint i;
// UniswapV3
pools[i++] = _makePoolData(POOL_PEARL_arcUSD_USDC_100, AmmAdapterIdLib.UNISWAPV3, TOKEN_USDC, TOKEN_arcUSD);
pools[i++] = _makePoolData(POOL_PEARL_arcUSD_USDC_100, AmmAdapterIdLib.UNISWAPV3, TOKEN_arcUSD, TOKEN_USDC);
pools[i++] = _makePoolData(POOL_PEARL_reETH_USDC_500, AmmAdapterIdLib.UNISWAPV3, TOKEN_WREETH, TOKEN_USDC);
pools[i++] = _makePoolData(POOL_PEARL_MORE_USDC_100, AmmAdapterIdLib.UNISWAPV3, TOKEN_MORE, TOKEN_USDC);
pools[i++] = _makePoolData(POOL_PEARL_UKRE_arcUSD_500, AmmAdapterIdLib.UNISWAPV3, TOKEN_UKRE, TOKEN_arcUSD);
pools[i++] = _makePoolData(POOL_PEARL_CVR_PEARL_500, AmmAdapterIdLib.UNISWAPV3, TOKEN_CVR, TOKEN_PEARL);
pools[i++] = _makePoolData(POOL_PEARL_USDC_PEARL_10000, AmmAdapterIdLib.UNISWAPV3, TOKEN_PEARL, TOKEN_USDC);
pools[i++] = _makePoolData(POOL_PEARL_DAI_USDC_100, AmmAdapterIdLib.UNISWAPV3, TOKEN_DAI, TOKEN_USDC);
pools[i++] = _makePoolData(POOL_PEARL_MORE_USTB_100, AmmAdapterIdLib.UNISWAPV3, TOKEN_USTB, TOKEN_MORE);
pools[i++] = _makePoolData(POOL_PEARL_RWA_reETH_3000, AmmAdapterIdLib.UNISWAPV3, TOKEN_RWA, TOKEN_WREETH);
pools[i++] = _makePoolData(POOL_PEARL_SACRA_reETH_10000, AmmAdapterIdLib.UNISWAPV3, TOKEN_RWA, TOKEN_WREETH);

pools[i++] = _makePoolData(POOL_PEARL_SACRA_reETH_10000, AmmAdapterIdLib.UNISWAPV3, TOKEN_SACRA, TOKEN_WREETH);
//endregion -- Pools ----
}

Expand Down
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fs_permissions = [{ access = "read-write", path = "./"}]
solc_version = "0.8.23"
gas_limit = "18446744073709551615"
optimizer-runs = 200
evm_version = "Shanghai"

[profile.lite]
optimizer = false
Expand All @@ -25,6 +26,7 @@ polygon = "${POLYGON_RPC_URL}"
base = "${BASE_RPC_URL}"
arbitrum = "${ARBITRUM_RPC_URL}"
ethereum = "${ETHEREUM_RPC_URL}"
real = "${REAL_RPC_URL}"

[etherscan]
polygon = { key = "${POLYGONSCAN_API_KEY}", chain = 137 }
Expand Down
31 changes: 31 additions & 0 deletions test/base/chains/RealSetup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "../../../chains/RealLib.sol";
import "../ChainSetup.sol";
import "../../../src/core/Platform.sol";
import "../../../src/core/Factory.sol";
import {DeployCore} from "../../../script/base/DeployCore.sol";

abstract contract RealSetup is ChainSetup, DeployCore {
bool public showDeployLog;

constructor() {
vm.selectFork(vm.createFork(vm.envString("REAL_RPC_URL")));
vm.rollFork(910000); // Oct 25 2024 23:54:31 PM (+03:00 UTC)
}

function testSetupStub() external {}

function _init() internal override {
//region ----- DeployCore.sol -----
platform = Platform(_deployCore(RealLib.platformDeployParams()));
RealLib.deployAndSetupInfrastructure(address(platform), showDeployLog);
factory = Factory(address(platform.factory()));
//endregion -- DeployCore.sol -----
}

function _deal(address token, address to, uint amount) internal override {
deal(token, to, amount);
}
}
47 changes: 47 additions & 0 deletions test/core/Swapper.Real.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {Test} from "forge-std/Test.sol";
import "../../chains/RealLib.sol";
import "../base/chains/RealSetup.sol";

contract SwapperRealTest is Test, RealSetup {
ISwapper public swapper;

function setUp() public {
_init();
swapper = ISwapper(platform.swapper());
_deal(RealLib.TOKEN_USDC, address(this), 1000e6);
IERC20(RealLib.TOKEN_USDC).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_DAI).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_USTB).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_MORE).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_WREETH).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_PEARL).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_CVR).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_UKRE).approve(address(swapper), type(uint).max);
IERC20(RealLib.TOKEN_RWA).approve(address(swapper), type(uint).max);
}

function testSwaps() public {
uint got;
swapper.swap(RealLib.TOKEN_USDC, RealLib.TOKEN_DAI, 100e6, 1_000); // 1%
got = IERC20(RealLib.TOKEN_DAI).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_DAI, RealLib.TOKEN_USTB, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_USTB).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_USTB, RealLib.TOKEN_MORE, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_MORE).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_MORE, RealLib.TOKEN_WREETH, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_WREETH).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_WREETH, RealLib.TOKEN_PEARL, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_PEARL).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_PEARL, RealLib.TOKEN_CVR, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_CVR).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_CVR, RealLib.TOKEN_UKRE, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_UKRE).balanceOf(address(this));
swapper.swap(RealLib.TOKEN_UKRE, RealLib.TOKEN_RWA, got, 1_000); // 1%
got = IERC20(RealLib.TOKEN_RWA).balanceOf(address(this));
// console.log(got);
// swapper.swap(RealLib.TOKEN_RWA, RealLib.TOKEN_USDC, got/5, 1_000); // 1%
}
}

0 comments on commit bbbc7aa

Please sign in to comment.