Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ env:

jobs:
check:
name: Foundry project
strategy:
fail-fast: true

name: Fmt - V1-Periphery
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.V1_PERIPHERY_CI_TOKEN }}
submodules: recursive

- name: Install Foundry
Expand All @@ -32,9 +36,4 @@ jobs:
- name: Run Forge build
run: |
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
id: build-sizes
31 changes: 31 additions & 0 deletions .github/workflows/lintspec-periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Lintspec - V1-Periphery
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.V1_PERIPHERY_CI_TOKEN }}
submodules: recursive
- uses: beeb/lintspec@v0.4.1
with:
paths: "[]"
fail-on-problem: "false"

- name: Run Lintspec
run: |
lintspec src
id: lintspec
37 changes: 37 additions & 0 deletions .github/workflows/solhint-periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Solhint - V1-Periphery
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.V1_PERIPHERY_CI_TOKEN }}
submodules: recursive
- uses: beeb/lintspec@v0.4.1
with:
paths: "[]"
fail-on-problem: "false"

- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: pnpm install

- name: Run Solhint
run: |
pnpm solhint
id: solhint
39 changes: 39 additions & 0 deletions .github/workflows/test-periphery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Tests - V1-Periphery
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.V1_PERIPHERY_CI_TOKEN }}
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Show Forge version
run: |
forge --version

- name: Run Forge build (no sizes)
run: |
forge build
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## Foundry
## V1-Periphery

**Periphery contracts for the Buttonwood-V1 Protocol**

Periphery consists of:

- **Router**: A router that auto-wraps USD stablecoins into USDX/Consol before interacting with Core Contracts
- **Router**: A router that auto-wraps USD stablecoins into USDX/Consol before interacting with Core Contracts
- **RolloverVault**: A vault that auto-deposits USDX into the next available OriginationPool
- **FulfillmentVault**: A vault used by the fulfiller for increasing liquidity to fill orders

## Documentation

Expand Down
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ additional_compiler_profiles = [
]

compilation_restrictions = [
{ paths = "../contracts/src/LoanManager.sol", optimizer_runs = 500 },
{ paths = "../contracts/src/GeneralManager.sol", optimizer_runs = 500 },
{ paths = "./lib/cash/src/LoanManager.sol", optimizer_runs = 500 },
{ paths = "./lib/cash/src/GeneralManager.sol", optimizer_runs = 500 },
]

fs_permissions = [
Expand Down
2 changes: 1 addition & 1 deletion src/RolloverVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract RolloverVault is LiquidityVault, IRolloverVault {
uint256 ogPoolConsolBalance = IERC20(consol()).balanceOf(address(ogPool));
uint256 ogPoolBalance = ogPool.balanceOf(address(this));
total += Math.mulDiv(ogPoolBalance, ogPoolUsdxBalance, ogPoolTotalSupply)
+ Math.mulDiv(ogPoolBalance, ogPoolConsolBalance, ogPoolTotalSupply);
+ Math.mulDiv(ogPoolBalance, ogPoolConsolBalance, ogPoolTotalSupply);
}
// Add the USDX and Consol balances that are currently in the rollover vault
total += IERC20(usdx()).balanceOf(address(this)) + IERC20(consol()).balanceOf(address(this));
Expand Down
19 changes: 11 additions & 8 deletions src/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ contract Router is
if (creationRequest.base.isCompounding) {
for (uint256 i = 0; i < creationRequest.base.originationPools.length; i++) {
// If compounding, need to collect 1/2 of the collateral amount + commission fee (this is in the form of collateral)
collateralCollected += IOriginationPool(creationRequest.base.originationPools[i]).calculateReturnAmount(
(creationRequest.base.collateralAmounts[i] + 1) / 2
);
collateralCollected += IOriginationPool(creationRequest.base.originationPools[i])
.calculateReturnAmount((creationRequest.base.collateralAmounts[i] + 1) / 2);
(uint256 _cost, uint8 _collateralDecimals) =
_calculateCost(creationRequest.collateral, creationRequest.base.collateralAmounts[i] / 2);
collateralDecimals = _collateralDecimals;
paymentAmount +=
(2 * _cost) - IOriginationPool(creationRequest.base.originationPools[i]).calculateReturnAmount(_cost);
paymentAmount += (2 * _cost)
- IOriginationPool(creationRequest.base.originationPools[i]).calculateReturnAmount(_cost);
}
} else {
for (uint256 i = 0; i < creationRequest.base.originationPools.length; i++) {
Expand Down Expand Up @@ -351,9 +350,13 @@ contract Router is
* @param oPoolConfigId The OPoolConfigId of the origination pool config
* @return originationPool The origination pool
*/
function _getOrCreateOriginationPool(OPoolConfigId oPoolConfigId) internal returns (IOriginationPool originationPool) {
originationPool =
IOriginationPool(IOriginationPoolScheduler(originationPoolScheduler).predictOriginationPool(oPoolConfigId));
function _getOrCreateOriginationPool(OPoolConfigId oPoolConfigId)
internal
returns (IOriginationPool originationPool)
{
originationPool = IOriginationPool(
IOriginationPoolScheduler(originationPoolScheduler).predictOriginationPool(oPoolConfigId)
);
if (!IOriginationPoolScheduler(originationPoolScheduler).isRegistered(address(originationPool))) {
IOriginationPool(IOriginationPoolScheduler(originationPoolScheduler).deployOriginationPool(oPoolConfigId));
}
Expand Down
32 changes: 0 additions & 32 deletions test/RolloverVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,17 @@ import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ILiquidityVault} from "../src/interfaces/ILiquidityVault/ILiquidityVault.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {CoreSimulatorLib} from "@hyper-evm-lib/test/simulation/CoreSimulatorLib.sol";
import {PrecompileLib} from "@hyper-evm-lib/src/PrecompileLib.sol";
import {HyperCore} from "@hyper-evm-lib/test/simulation/HyperCore.sol";
import {TokenRegistry} from "@hyper-evm-lib/src/registry/TokenRegistry.sol";
import {HLConstants} from "@hyper-evm-lib/src/common/HLConstants.sol";
import {IOriginationPoolScheduler} from "@core/interfaces/IOriginationPoolScheduler/IOriginationPoolScheduler.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

contract RolloverVaultTest is BaseTest {
using Math for uint256;

HyperCore public hyperCore;

using PrecompileLib for address;

string NAME = "Test Rollover Vault";
string SYMBOL = "tRV";
uint8 DECIMALS = 26; // ToDo: Make this 8 + usdx decimals????
uint8 DECIMALS_OFFSET = 8;

// Hyper-EVM-Lib Values
TokenRegistry public tokenRegistry;
address public HYPER_CORE_ADDRESS = 0x9999999999999999999999999999999999999999;
address TOKEN_INFO_PRECOMPILE_ADDRESS = 0x000000000000000000000000000000000000080C;
address SPOT_INFO_PRECOMPILE_ADDRESS = 0x000000000000000000000000000000000000080b;
address SPOT_PX_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000808;
address public TOKEN_REGISTRY_ADDRESS = 0x0b51d1A9098cf8a72C325003F44C194D41d7A85B;
uint32 public HYPE_TOKEN_INDEX = uint32(HLConstants.hypeTokenIndex());
uint32 public USDC_TOKEN_INDEX = 0;
uint32 public USDT_TOKEN_INDEX = 268;
uint32 public USDH_TOKEN_INDEX = 360;

RolloverVault public rolloverVault;

address public user = makeAddr("user");
Expand Down Expand Up @@ -106,20 +85,9 @@ contract RolloverVaultTest is BaseTest {
vm.startPrank(admin);
rolloverVault.grantRole(rolloverVault.KEEPER_ROLE(), keeper);
vm.stopPrank();

// Force the rolloverVault to be activated on hypercore
vm.mockCall(HLConstants.CORE_USER_EXISTS_PRECOMPILE_ADDRESS, abi.encode(address(rolloverVault)), abi.encode(true));
CoreSimulatorLib.forceAccountActivation(address(rolloverVault));

// Force activate the HYPE system address so bridging works
vm.mockCall(
HLConstants.CORE_USER_EXISTS_PRECOMPILE_ADDRESS, abi.encode(HLConstants.HYPE_SYSTEM_ADDRESS), abi.encode(true)
);
CoreSimulatorLib.forceAccountActivation(0x2222222222222222222222222222222222222222);
}

function test_initialize() public {
CoreSimulatorLib.forceSpotBalance(address(rolloverVault), USDT_TOKEN_INDEX, 0);
assertEq(rolloverVault.name(), NAME);
assertEq(rolloverVault.symbol(), SYMBOL);
assertEq(rolloverVault.decimals(), DECIMALS);
Expand Down
Loading