Skip to content

Commit

Permalink
fix the build (#28)
Browse files Browse the repository at this point in the history
* fix the build

* fix tests

* fix tests

* fix client tests
  • Loading branch information
Joe Andrews committed Mar 16, 2022
1 parent 120ec68 commit 757f231
Show file tree
Hide file tree
Showing 24 changed files with 4,605 additions and 1,568 deletions.
2 changes: 2 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ remappings = ['ds-test/=lib/ds-test/src/', '@openzeppelin/=node_modules/@openzep
fuzz_runs = 256
gas_reports = ["*"]
ETH_RPC_URL = 'https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c'
solc_version = '0.8.10'

# See more config options https://github.com/gakonst/foundry/tree/master/config
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"install:foundry": "curl -L https://foundry.paradigm.xyz | bash",
"compile:contracts": "forge build",
"compile:typechain": "forge build && hardhat compile ",
"compile:client-dest": "tsc --project tsconfig.client-dest.json && node package-client-dest.js",
"compile:client-dest": "yarn compile:typechain && tsc --project tsconfig.client-dest.json && node package-client-dest.js",
"clean": "rm -rf ./cache ./dest ./out ./artifacts ./typechain-types",
"test": "yarn test:contracts && yarn test:clients",
"test:client": "jest test",
"test:element": "forge test --fork-block-number 14000000 --match-contract Element -vvv",
"test:contracts:block": "forge test --fork-block-number",
"cast": "cast",
"test:contracts": "forge test --fork-block-number 14000000 -vvv",
"test:contracts": "forge test --no-match-contract Element -vvv && yarn test:element",
"build": "yarn clean && yarn compile:typechain && yarn compile:client-dest"
},
"dependencies": {
Expand All @@ -24,7 +25,8 @@
"ethers": "^5.5.4",
"hardhat": "^2.8.3",
"jest": "^27.5.0",
"typescript": "^4.5.5"
"typescript": "^4.5.5",
"typechain": "^7.0.1"
},
"jest": {
"transform": {
Expand All @@ -43,7 +45,6 @@
"@typechain/hardhat": "^4.0.0",
"@types/jest": "^27.4.0",
"ts-jest": "^27.1.3",
"ts-node": "^10.4.0",
"typechain": "^7.0.0"
"ts-node": "^10.4.0"
}
}
7 changes: 3 additions & 4 deletions src/aztec/RollupProcessor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ contract RollupProcessor is DSTest {
convertArgs.interactionNonce,
convertArgs.auxInputData
);
uint256 gas = bridgeGasLimits[convertArgs.bridgeAddress] > 0 ? bridgeGasLimits[convertArgs.bridgeAddress]: uint256(150000000);


(bool success, bytes memory result) = address(bridgeProxy).delegatecall{gas: bridgeGasLimits[convertArgs.bridgeAddress]}(
(bool success, bytes memory result) = address(bridgeProxy).delegatecall{gas: gas}(
abi.encodeWithSelector(
DEFI_BRIDGE_PROXY_CONVERT_SELECTOR,
convertArgs.bridgeAddress,
Expand All @@ -229,8 +229,7 @@ contract RollupProcessor is DSTest {
convertArgs.ethPaymentsSlot
)
);

results = ConvertReturnValues(0, 0, false);
results = ConvertReturnValues(0, 0, false);

if (success) {
(uint256 outputValueA, uint256 outputValueB, bool isAsync) = abi.decode(
Expand Down
6 changes: 3 additions & 3 deletions src/bridges/lido/LidoBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ contract LidoBridge is IDefiBridge {
AztecTypes.AztecAsset calldata,
uint256 inputValue,
uint256 interactionNonce,
uint64
uint64,
address
)
external
payable
override
returns (
uint256 outputValueA,
uint256,
Expand Down Expand Up @@ -146,7 +146,7 @@ contract LidoBridge is IDefiBridge {
AztecTypes.AztecAsset calldata,
uint256,
uint64
) external payable override returns (uint256, uint256, bool) {
) external payable returns (uint256, uint256, bool) {
require(false);
}
}
3 changes: 2 additions & 1 deletion src/bridges/liquity/StabilityPoolBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ contract StabilityPoolBridge is IDefiBridge, ERC20("StabilityPoolBridge", "SPB")
AztecTypes.AztecAsset calldata,
uint256 inputValue,
uint256,
uint64
uint64,
address
)
external
payable
Expand Down
5 changes: 2 additions & 3 deletions src/bridges/liquity/StakingBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
AztecTypes.AztecAsset calldata,
uint256 inputValue,
uint256,
uint64
uint64,
address
)
external
payable
override
returns (
uint256 outputValueA,
uint256,
Expand Down Expand Up @@ -180,7 +180,6 @@ contract StakingBridge is IDefiBridge, ERC20("StakingBridge", "SB") {
)
external
payable
override
returns (
uint256,
uint256,
Expand Down
8 changes: 4 additions & 4 deletions src/bridges/liquity/TroveBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import "./interfaces/ISortedTroves.sol";
*
* If the trove is closed by redemption, users can withdraw their remaining collateral by supplying their TB.
*/
contract TroveBridge is IDefiBridge, ERC20, Ownable {
contract TroveBridge is ERC20, Ownable, IDefiBridge {
using Strings for uint256;

address public constant LUSD = 0x5f98805A4E8be255a32880FDeC7F6728C6568bA0;
Expand Down Expand Up @@ -118,11 +118,12 @@ contract TroveBridge is IDefiBridge, ERC20, Ownable {
AztecTypes.AztecAsset calldata outputAssetB,
uint256 inputValue,
uint256 interactionNonce,
uint64
uint64,
address

)
external
payable
override
returns (
uint256 outputValueA,
uint256 outputValueB,
Expand Down Expand Up @@ -266,7 +267,6 @@ contract TroveBridge is IDefiBridge, ERC20, Ownable {
)
external
payable
override
returns (
uint256,
uint256,
Expand Down
26 changes: 13 additions & 13 deletions src/bridges/rai/RaiBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {ICoinJoin} from "./interfaces/ICoinJoin.sol";
import {IEthJoin} from "./interfaces/IEthJoin.sol";
import {ISafeEngine} from "./interfaces/ISafeEngine.sol";
import {ISafeManager} from "./interfaces/ISafeManager.sol";
import {IWeth} from "./interfaces/IWeth.sol";
import {IWETH} from "../../interfaces/IWETH.sol";
import {AggregatorV3Interface} from "./interfaces/AggregatorV3Interface.sol";
import {IRollupProcessor} from "../../interfaces/IRollupProcessor.sol";

Expand All @@ -24,7 +24,7 @@ import {IRollupProcessor} from "../../interfaces/IRollupProcessor.sol";
// 1. Theres a minimum amount of RAI to be borrowed in the first call, which is currently 1469 RAI
// 2. You can find the readme for the contract here: https://gist.github.com/realdiganta/2c73f86820bf7310bd934184fa960e3d

contract RaiBridge is IDefiBridge, ERC20 {
contract RaiBridge is ERC20, IDefiBridge {
using SafeMath for uint256;

address public immutable rollupProcessor;
Expand All @@ -49,8 +49,8 @@ contract RaiBridge is IDefiBridge, ERC20 {
SAFE_HANDLER = ISafeManager(SAFE_MANAGER).safes(safeId);

// do all one off approvals
require(IWeth(WETH).approve(ETH_JOIN, type(uint).max), "Weth approve failed");
require(IWeth(WETH).approve(rollupProcessor, type(uint).max), "Weth approve failed");
require(IWETH(WETH).approve(ETH_JOIN, type(uint).max), "Weth approve failed");
require(IWETH(WETH).approve(rollupProcessor, type(uint).max), "Weth approve failed");
require(IERC20(RAI).approve(COIN_JOIN, type(uint).max), "Rai approve failed");
require(IERC20(RAI).approve(rollupProcessor, type(uint).max), "Rai approve failed");
ISafeEngine(SAFE_ENGINE).approveSAFEModification(COIN_JOIN);
Expand Down Expand Up @@ -79,11 +79,11 @@ contract RaiBridge is IDefiBridge, ERC20 {
AztecTypes.AztecAsset memory outputAssetB,
uint256 totalInputValue,
uint256 interactionNonce,
uint64 auxData
uint64 auxData,
address
)
external
payable
override
returns (
uint256 outputValueA,
uint256 outputValueB,
Expand All @@ -95,7 +95,7 @@ contract RaiBridge is IDefiBridge, ERC20 {

if (inputAssetA.assetType == AztecTypes.AztecAssetType.ETH) {
// transfer to weth
IWeth(WETH).deposit{value: msg.value}();
IWETH(WETH).deposit{value: msg.value}();
}


Expand All @@ -113,12 +113,12 @@ contract RaiBridge is IDefiBridge, ERC20 {
outputValueA = _removeCollateral(totalInputValue, safe);
if (outputAssetA.assetType == AztecTypes.AztecAssetType.ETH) {
// change weth to eth
IWeth(WETH).withdraw(outputValueA);
IWETH(WETH).withdraw(outputValueA);
IRollupProcessor(rollupProcessor).receiveEthFromBridge{value: outputValueA}(interactionNonce);
}
}
} else {
// CONTRACT INITIALIZATION
} else {
// CONTRACT INITIALIZATION
require(auxData > 0, "no collateral ratio provided");
require(outputAssetB.assetType == AztecTypes.AztecAssetType.ERC20 && outputAssetB.erc20Address == address(this));
isInitialized = true;
Expand All @@ -133,7 +133,7 @@ contract RaiBridge is IDefiBridge, ERC20 {
outputValueB = outputValueA;
_mint(address(this), outputValueB);
}
}
}

function finalise(
AztecTypes.AztecAsset calldata inputAssetA,
Expand All @@ -142,12 +142,12 @@ contract RaiBridge is IDefiBridge, ERC20 {
AztecTypes.AztecAsset calldata outputAssetB,
uint256 interactionNonce,
uint64 auxData
) external payable override returns (uint256, uint256, bool) {
) external payable returns (uint256, uint256, bool) {
require(false);
}


// ------------------------------- INTERNAL FUNCTIONS -------------------------------------------------
// ------------------------------- INTERNAL FUNCTIONS -------------------------------------------------

function _addCollateral(uint _wethAmount, uint _collateralRatio, uint _raiToEth) internal returns (uint outputRai) {
IEthJoin(ETH_JOIN).join(SAFE_HANDLER, _wethAmount);
Expand Down
10 changes: 0 additions & 10 deletions src/bridges/rai/interfaces/IWeth.sol

This file was deleted.

3 changes: 2 additions & 1 deletion src/interfaces/IDefiBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface IDefiBridge {
)
external
payable
virtual
returns (
uint256 outputValueA,
uint256 outputValueB,
Expand All @@ -79,7 +80,7 @@ interface IDefiBridge {
AztecTypes.AztecAsset calldata outputAssetB,
uint256 interactionNonce,
uint64 auxData
) external payable returns (uint256 outputValueA, uint256 outputValueB, bool interactionComplete);
) external payable virtual returns (uint256 outputValueA, uint256 outputValueB, bool interactionComplete);


}
2 changes: 2 additions & 0 deletions src/interfaces/IWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface IWETH {
function transfer(address to, uint256 amount) external returns (bool);

function balanceOf(address user) external view returns (uint256);

function withdraw(uint256 amount) external;
}
2 changes: 1 addition & 1 deletion src/test/liquity/StabilityPoolBridgeInternal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma abicoder v2;
import "./utils/TestUtil.sol";
import "../../bridges/liquity/StabilityPoolBridge.sol";

contract StabilityPoolBridgeTestInternal is TestUtil, StabilityPoolBridge(address(0), address(0)) {
abstract contract StabilityPoolBridgeTestInternal is TestUtil, StabilityPoolBridge(address(0), address(0)) {
function setUp() public {
_aztecPreSetup();
setUpTokens();
Expand Down
4 changes: 2 additions & 2 deletions src/test/liquity/StakingBridgeInternal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ pragma abicoder v2;
import "./utils/TestUtil.sol";
import "../../bridges/liquity/StakingBridge.sol";

contract StakingBridgeTestInternal is TestUtil, StakingBridge(address(0)) {
abstract contract StakingBridgeTestInternal is TestUtil, StakingBridge(address(0)) {

function setUp() public {
_aztecPreSetup();
setUpTokens();

require(IERC20(WETH).approve(address(UNI_ROUTER), type(uint256).max), "StakingBridge: WETH_APPROVE_FAILED");
require(IERC20(LUSD).approve(address(UNI_ROUTER), type(uint256).max), "StakingBridge: LUSD_APPROVE_FAILED");
require(IERC20(USDC).approve(address(UNI_ROUTER), type(uint256).max), "StakingBridge: USDC_APPROVE_FAILED");
Expand Down
6 changes: 4 additions & 2 deletions src/test/liquity/TroveBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ contract TroveBridgeTest is TestUtil {
AztecTypes.AztecAsset(1, tokens["LUSD"].addr, AztecTypes.AztecAssetType.ERC20),
ROLLUP_PROCESSOR_WEI_BALANCE,
0,
0
0,
address(0)
)
{
assertTrue(false, "convert(...) has to revert when trove is in an incorrect state.");
Expand All @@ -81,7 +82,8 @@ contract TroveBridgeTest is TestUtil {
AztecTypes.AztecAsset(0, address(0), AztecTypes.AztecAssetType.NOT_USED),
0,
0,
0
0,
address(0)
)
{
assertTrue(false, "convert(...) has to revert on incorrect input.");
Expand Down
Loading

0 comments on commit 757f231

Please sign in to comment.