Skip to content

Commit

Permalink
Merge pull request #1 from centrifuge/unit-tests
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
hieronx authored Feb 27, 2024
2 parents 8b9df5c + fb2b270 commit 3ff8715
Show file tree
Hide file tree
Showing 8 changed files with 663 additions and 76 deletions.
57 changes: 13 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1

- name: Run tests
run: forge test --no-match-path "test/invariant/**/*.sol"
run: forge test --no-match-path "test/fork/**/*.sol"
env:
FOUNDRY_PROFILE: ci
FORK_TESTS: false

test-invariant:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# test-fork:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3

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

- name: Run tests
run: forge test --match-path "test/invariant/**/*.sol"
env:
FOUNDRY_PROFILE: ci
FORK_TESTS: false
# - name: Run tests
# run: forge test --match-path "test/fork/**/*.sol"
# env:
# FOUNDRY_PROFILE: ci
# FORK_TESTS: false

lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -102,35 +102,4 @@ jobs:
uses: zgosalvez/github-actions-report-lcov@v2
with:
coverage-files: ./lcov.info
minimum-coverage: 60 # Set coverage threshold.

# slither-analyze:
# runs-on: "ubuntu-latest"
# permissions:
# actions: "read"
# contents: "read"
# security-events: "write"
# steps:
# - name: "Check out the repo"
# uses: "actions/checkout@v3"
# with:
# submodules: "recursive"

# - name: "Run Slither analysis"
# uses: "crytic/[email protected]"
# id: "slither"
# with:
# fail-on: "none"
# sarif: "results.sarif"
# solc-version: "0.8.21"
# target: "src/"

# - name: Upload SARIF file
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: ${{ steps.slither.outputs.sarif }}

# - name: "Add Slither summary"
# run: |
# echo "## Slither result" >> $GITHUB_STEP_SUMMARY
# echo "✅ Uploaded to GitHub code scanning" >> $GITHUB_STEP_SUMMARY
minimum-coverage: 60 # Set coverage threshold.
31 changes: 16 additions & 15 deletions src/Conduit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pragma solidity 0.8.21;
interface ERC20Like {
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function balanceOf(address user) external returns (uint256 amount);
function mint(address user, uint256 amount) external;
function burn(address user, uint256 amount) external;
function approve(address user, uint256 amount) external;
}

interface OutputConduitLike {
Expand Down Expand Up @@ -37,7 +37,6 @@ interface PoolManagerLike {
function transfer(address currency, bytes32 recipient, uint128 amount) external;
}

// https://forum.makerdao.com/t/rwa015-project-andromeda-technical-assessment/20974#drawing-dai-swapping-for-stablecoin-and-investing-into-bonds-13
contract Conduit {
address public immutable psm;
ERC20Like public immutable dai;
Expand All @@ -63,9 +62,9 @@ contract Conduit {
address public withdrawal;

// Centrifuge pool
ERC7540Like pool;
PoolManagerLike poolManager;
bytes32 claimRecipient;
ERC7540Like public pool;
PoolManagerLike public poolManager;
bytes32 public depositRecipient;

mapping(address => uint256) public wards;
mapping(address => uint256) public can;
Expand Down Expand Up @@ -172,8 +171,8 @@ contract Conduit {
}

function file(bytes32 what, bytes32 data) external onlyOperator {
if (what == "claimRecipient") {
claimRecipient = data;
if (what == "depositRecipient") {
depositRecipient = data;
} else {
revert("AndromedaPaymentConduit/unrecognised-param");
}
Expand All @@ -184,16 +183,17 @@ contract Conduit {
/// -- Invest --
/// @notice Submit investment request for LTF tokens
function requestDeposit() public onlyMate {
// Get USDC from outputConduit
// Get gem from outputConduit
outputConduit.pick(address(this));
outputConduit.hook(psm);
outputConduit.push();

// Mint deposit tokens
uint256 amount = gem.balanceOf(address(this));
depositAsset.mint(address(this), amount);
depositAsset.approve(address(pool), amount);

// Deposit in pool
depositAsset.approve(address(pool), amount);
pool.requestDeposit(amount, address(this), address(this), "");
}

Expand All @@ -210,7 +210,6 @@ contract Conduit {
uint256 amount = depositAsset.balanceOf(address(this));
depositAsset.burn(address(this), amount);

claimDeposit();
gem.transferFrom(address(this), withdrawal, amount);
}

Expand All @@ -223,17 +222,19 @@ contract Conduit {

/// @notice Lock deposit tokens in pool
function depositIntoPool() public onlyMate {
require(depositRecipient != "", "AndromedaPaymentConduit/deposit-recipient-is-zero");

uint256 amount = gem.balanceOf(address(this));
depositAsset.mint(address(this), amount);
poolManager.transfer(address(depositAsset), claimRecipient, _toUint128(amount));
poolManager.transfer(address(depositAsset), depositRecipient, _toUint128(amount));
}

/// @notice Claim and burn redeemed deposit tokens
function claimRedeem() public onlyMate {
uint256 claimable = pool.maxRedeem(address(this));
pool.redeem(claimable, address(this), address(this));
uint256 claimableShares = pool.maxRedeem(address(this));
uint256 redeemedAssets = pool.redeem(claimableShares, address(this), address(this));

depositAsset.burn(address(this), claimable);
depositAsset.burn(address(this), redeemedAssets);
}

/// @notice Send gem as interest to jar
Expand All @@ -260,7 +261,7 @@ contract Conduit {
/// -- Helpers --
function _toUint128(uint256 _value) internal pure returns (uint128 value) {
if (_value > type(uint128).max) {
revert("MathLib/uint128-overflow");
revert("AndromedaPaymentConduit/uint128-overflow");
} else {
value = uint128(_value);
}
Expand Down
Loading

0 comments on commit 3ff8715

Please sign in to comment.