Skip to content

Commit

Permalink
updated hardhat version and test-suite to support new interface/balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Apr 2, 2024
1 parent 012f38e commit bbf41e6
Show file tree
Hide file tree
Showing 28 changed files with 4,729 additions and 9,365 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x]
node-version: [20.x]
os: [ubuntu-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
os: [ubuntu-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20
2 changes: 1 addition & 1 deletion spot-contracts/contracts/_interfaces/IBalancer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface IBalancer {
/// @notice Emits the component and the token denomination and amount of fees collected.
/// @param collector Address of fee recipient.
/// @param token Address of fee token.
/// @param balance The amount tokens paid as fees.
/// @param amount The amount tokens paid as fees.
event Fee(address collector, IERC20Upgradeable token, uint256 amount);

//--------------------------------------------------------------------------
Expand Down
52 changes: 52 additions & 0 deletions spot-contracts/contracts/_test/DMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract DMock {
struct MockCall {
bytes data;
bytes returnValue;
}

// Maps a method signature to its mock call definition
mapping(bytes32 => MockCall) public mockCalls;

// Fallback function to handle all calls
// solhint-disable-next-line
fallback(bytes calldata) external returns (bytes memory) {
// Check if mock has been defined based on {sig,param} pair
MockCall storage mockCall_ = mockCalls[keccak256(msg.data)];

// else check if generic mock has been defined based on sig
if (mockCall_.data.length <= 0) {
mockCall_ = mockCalls[keccak256(abi.encodePacked(bytes4(msg.data)))];
}

// solhint-disable-next-line custom-errors
require(mockCall_.data.length > 0, "DMock: method not mocked");

// Return the mocked return value
return mockCall_.returnValue;
}

// Function to set up a mock call, given method sig and parameters
function mockCall(bytes memory data, bytes memory returnValue) public {
mockCalls[keccak256(data)] = MockCall(data, returnValue);
}

// Function to set up a mock call, given just method sig
function mockMethod(bytes4 sig, bytes memory returnValue) public {
bytes memory data = abi.encodePacked(sig);
mockCalls[keccak256(data)] = MockCall(data, returnValue);
}

// Function to clear mocked call
function clearMockCall(bytes memory data) public {
delete mockCalls[keccak256(data)];
}

// Function to clear mocked method call
function clearMockMethodSig(bytes4 sig) public {
bytes memory data = abi.encodePacked(sig);
delete mockCalls[keccak256(data)];
}
}
16 changes: 8 additions & 8 deletions spot-contracts/contracts/_test/HelpersTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ contract HelpersTester {
return b.trancheAt(index);
}

function getSeniorTranche(IBondController b) public view returns (ITranche) {
return b.getSeniorTranche();
function seniorTranche(IBondController b) public view returns (ITranche) {
return b.seniorTranche();
}

function getSeniorTrancheRatio(IBondController b) public view returns (uint256) {
return b.getSeniorTrancheRatio();
function seniorTrancheRatio(IBondController b) public view returns (uint256) {
return b.seniorTrancheRatio();
}

function previewDeposit(IBondController b, uint256 collateralAmount) public view returns (TokenAmount[] memory) {
Expand Down Expand Up @@ -66,8 +66,8 @@ contract HelpersTester {
IPerpetualTranche perp,
uint256 perpTVL,
uint256 perpAmtToMint
) public returns (uint256, uint256) {
IBondController depositBond = perp.getDepositBond();
) public view returns (uint256, uint256) {
IBondController depositBond = perp.depositBond();
return
PerpHelpers.estimateUnderlyingAmtToTranche(
PerpHelpers.MintEstimationParams({
Expand All @@ -77,8 +77,8 @@ contract HelpersTester {
address(depositBond)
),
depositBondTotalDebt: depositBond.totalDebt(),
depositTrancheSupply: (depositBond.getSeniorTranche()).totalSupply(),
depositTrancheTR: depositBond.getSeniorTrancheRatio()
depositTrancheSupply: (depositBond.seniorTranche()).totalSupply(),
depositTrancheTR: depositBond.seniorTrancheRatio()
}),
perpAmtToMint
);
Expand Down
32 changes: 1 addition & 31 deletions spot-contracts/contracts/_test/mocks/MockVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,13 @@
pragma solidity ^0.8.20;

import { IPerpetualTranche, IERC20Upgradeable, ITranche } from "../../_interfaces/IPerpetualTranche.sol";
import { TokenAmount, RolloverData } from "../../_interfaces/CommonTypes.sol";
import { RolloverData } from "../../_interfaces/CommonTypes.sol";

contract MockVault {
function getTVL() public pure returns (uint256) {
return 0;
}

function mintPerps(IPerpetualTranche perp, ITranche trancheIn, uint256 trancheInAmt) public {
trancheIn.transferFrom(msg.sender, address(this), trancheInAmt);

trancheIn.approve(address(perp), trancheInAmt);
perp.deposit(trancheIn, trancheInAmt);

perp.transfer(msg.sender, perp.balanceOf(address(this)));
}

function computePerpMintAmt(
IPerpetualTranche perp,
ITranche trancheIn,
uint256 trancheInAmt
) public returns (uint256) {
return perp.computeMintAmt(trancheIn, trancheInAmt);
}

function redeemPerps(IPerpetualTranche perp, uint256 perpAmt) public {
perp.transferFrom(msg.sender, address(this), perpAmt);
TokenAmount[] memory tokensOut = perp.redeem(perpAmt);
for (uint256 i = 0; i < tokensOut.length; ++i) {
IERC20Upgradeable tokenOut = tokensOut[i].token;
tokenOut.transfer(msg.sender, tokenOut.balanceOf(address(this)));
}
}

function computePerpRedemptionAmts(IPerpetualTranche perp, uint256 perpAmt) public returns (TokenAmount[] memory) {
return perp.computeRedemptionAmts(perpAmt);
}

function rollover(
IPerpetualTranche perp,
ITranche trancheIn,
Expand Down
10 changes: 5 additions & 5 deletions spot-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { HardhatUserConfig } from "hardhat/config";
import { Wallet } from "ethers";

import "@nomiclabs/hardhat-ethers";
import "@nomicfoundation/hardhat-ethers";
import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-verify";
import "@openzeppelin/hardhat-upgrades";
import "solidity-coverage";
import "hardhat-gas-reporter";

// Loads custom tasks
import "./tasks/tools";
import "./tasks/deploy";
import "./tasks/upgrade";
import "./tasks/ops";
// import "./tasks/tools";
// import "./tasks/deploy";
// import "./tasks/upgrade";
// import "./tasks/ops";

// Loads env variables from .env file
import * as dotenv from "dotenv";
Expand Down
26 changes: 13 additions & 13 deletions spot-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
"test": "yarn hardhat test test/*.ts test/**/*.ts"
},
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^4.7.3"
"@openzeppelin/contracts-upgradeable": "4.7.3"
},
"devDependencies": {
"@defi-wonderland/smock": "^2.3.4",
"@ethersproject/abi": "^5.6.4",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bytes": "^5.6.1",
"@ethersproject/providers": "^5.6.8",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomicfoundation/hardhat-verify": "^1.1.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@openzeppelin/hardhat-upgrades": "^1.19.0",
"@nomicfoundation/hardhat-chai-matchers": "latest",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-verify": "latest",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@openzeppelin/hardhat-upgrades": "^3.0.4",
"@openzeppelin/upgrades-core": "latest",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
Expand All @@ -51,11 +50,12 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.6.9",
"ganache-cli": "^6.12.2",
"hardhat": "^2.19.4",
"hardhat-gas-reporter": "^1.0.9",
"ethereum-waffle": "latest",
"ethers": "^6.6.0",
"ethers-v5": "npm:ethers@^5.7.0",
"ganache-cli": "latest",
"hardhat": "^2.22.1",
"hardhat-gas-reporter": "latest",
"lodash": "^4.17.21",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-dev.23",
Expand Down
Loading

0 comments on commit bbf41e6

Please sign in to comment.