Skip to content

Commit

Permalink
Merge 85cef3e into 1f830e3
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlilley committed Jan 10, 2022
2 parents 1f830e3 + 85cef3e commit 25eb480
Show file tree
Hide file tree
Showing 92 changed files with 4,367 additions and 232 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/certora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Certora

on:
# push:
# branches: [canary]
# pull_request:
# branches: [canary]
workflow_dispatch:

jobs:
verify_trident:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js 14 LTS
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarnv1-dist-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarnv1-dist-
- name: Installing dependencies
run: yarn install --frozen-lockfile

- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- uses: actions/setup-java@v1
with:
java-version: "11"
java-package: jre

- name: Install dependencies
run: |
wget https://github.com/ethereum/solidity/releases/download/v0.8.7/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc
wget https://github.com/ethereum/solidity/releases/download/v0.8.4/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc8.4
wget https://github.com/ethereum/solidity/releases/download/v0.8.2/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc8.2
wget https://github.com/ethereum/solidity/releases/download/v0.6.12/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc6.12
pip3 install certora-cli
- name: Prepare
run: |
chmod +x spec/scripts/*.sh
spec/scripts/applyHarnesses.sh
- name: Verify Trident Router with Certora
run: |
# spec/scripts/sanityConstantProductPool.sh
# spec/scripts/sanityHybridPool.sh
# spec/scripts/sanityMasterDeployer.sh
# spec/scripts/sanitySymbolicPool.sh
# spec/scripts/sanityTridentRouter.sh
spec/scripts/verifyConstantProductPool.sh
spec/scripts/verifyHybridPool.sh
spec/scripts/verifyTridentMath.sh
spec/scripts/verifyTridentRouter.sh
spec/scripts/verifyTridentRouterSimple.sh
env:
CERTORAKEY: ${{ secrets.CERTORAKEY }}
File renamed without changes.
9 changes: 7 additions & 2 deletions .github/workflows/gas.yaml → .github/workflows/gas.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Gas

# Controls when the action will run.
on: [push, pull_request]

on:
# push:
# branches: [canary]
# pull_request:
# branches: [canary]
workflow_dispatch:

jobs:
build:
name: Build
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/tests.yaml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: Test

# Controls when the action will run.
on: [push, pull_request]
on:
# push:
# branches: [canary]
# pull_request:
# branches: [canary]
workflow_dispatch:

jobs:
build:
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ coverage.json
local/

tenderly.yaml

# Certora
.certora_config
.last_confs
.certora_build.json
.certora_metadata.json
.certora_recent_jobs.json
.certora_verify.json
26 changes: 25 additions & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
module.exports = {
skipFiles: ["interfaces", "examples", "flat", "mocks"],
testCommand: "yarn test",
compileCommand: "yarn build",
skipFiles: [
"interfaces",
"examples",
"flat",
"libraries/DyDxMath",
"libraries/FullMath",
"libraries/MathUtils",
"libraries/SafeCast",
"libraries/SwapLib",
"libraries/TickMath",
"libraries/Ticks",
"libraries/UnsafeMath",
"migration",
"mocks",
"pool/concentrated",
"pool/franchised",
"pool/hybrid",
"pool/index",
"TridentERC721",
// Covered elsewhere
"TridentBatchable",
"TridentOwnable",
],
};
5 changes: 3 additions & 2 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export/
deployments/
artifacts/
cache/
coverage/
deployments/
export/
spec/
node_modules/
types/
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"esbenp.prettier-vscode",
"hbenl.vscode-mocha-test-adapter",
"juanblanco.solidity",
"tintinweb.solidity-visual-auditor"
"tintinweb.solidity-visual-auditor",
"certora.evmspec-lsp",
"certora.evmspecforvscode"
]
}
52 changes: 4 additions & 48 deletions contracts/utils/RouterHelper.sol → contracts/RouterHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

pragma solidity >=0.8.0;

import "../interfaces/IBentoBoxMinimal.sol";
import "../interfaces/IMasterDeployer.sol";
import "../TridentRouter.sol";
import "./interfaces/IBentoBoxMinimal.sol";
import "./interfaces/IMasterDeployer.sol";
import "./TridentPermit.sol";
import "./TridentBatchable.sol";

/// @notice Trident router helper contract.
contract RouterHelper is TridentPermit {
contract RouterHelper is TridentPermit, TridentBatchable {
/// @notice BentoBox token vault.
IBentoBoxMinimal public immutable bento;
/// @notice Trident AMM master deployer contract.
Expand All @@ -29,40 +29,6 @@ contract RouterHelper is TridentPermit {
_bento.registerProtocol();
}

/// @notice Provides batch function calls for this contract and returns the data from all of them if they all succeed.
/// Adapted from https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/base/Multicall.sol, License-Identifier: GPL-2.0-or-later.
/// @dev The `msg.value` should not be trusted for any method callable from this function.
/// @dev Uses a modified version of the batch function - preventing multiple calls of the single input swap functions
/// @param data ABI-encoded params for each of the calls to make to this contract.
/// @return results The results from each of the calls passed in via `data`.
function batch(bytes[] calldata data) external payable returns (bytes[] memory results) {
results = new bytes[](data.length);
// We only allow one exactInputSingle call to be made in a single batch call.
// This is not really needed but we want to save users from signing malicious payloads.
// We also don't want nested batch calls.
bool swapCalled;
for (uint256 i = 0; i < data.length; i++) {
bytes4 selector = getSelector(data[i]);
if (selector == TridentRouter.exactInputSingle.selector || selector == TridentRouter.exactInputSingleWithNativeToken.selector) {
require(!swapCalled, "Swap called twice");
swapCalled = true;
} else {
require(selector != this.batch.selector, "Nested Batch");
}

(bool success, bytes memory result) = address(this).delegatecall(data[i]);
if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577.
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
results[i] = result;
}
}

function deployPool(address factory, bytes calldata deployData) external payable returns (address) {
return masterDeployer.deployPool(factory, deployData);
}
Expand Down Expand Up @@ -127,14 +93,4 @@ contract RouterHelper is TridentPermit {
(bool success, ) = recipient.call{value: amount}("");
require(success, "ETH_TRANSFER_FAILED");
}

/**
* @notice function to extract the selector of a bytes calldata
* @param _data the calldata bytes
*/
function getSelector(bytes memory _data) internal pure returns (bytes4 sig) {
assembly {
sig := mload(add(_data, 32))
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

abstract contract TridentNFT is ERC721 {
abstract contract TridentERC721 is ERC721 {
bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)");

bytes32 public constant PERMIT_ALL_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 nonce,uint256 deadline)");
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion contracts/TridentRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

pragma solidity >=0.8.0;

import "./RouterHelper.sol";
import "./interfaces/IPool.sol";
import "./interfaces/ITridentRouter.sol";
import "./utils/RouterHelper.sol";

/// @notice Router contract that helps in swapping across Trident pools.
contract TridentRouter is ITridentRouter, RouterHelper {
Expand Down Expand Up @@ -244,6 +244,7 @@ contract TridentRouter is ITridentRouter, RouterHelper {
require(msg.sender == cachedPool, "UNAUTHORIZED_CALLBACK");
TokenInput memory tokenInput = abi.decode(data, (TokenInput));
// @dev Transfer the requested tokens to the pool.
// TODO: Refactor redudency
if (tokenInput.native) {
_depositFromUserToBentoBox(tokenInput.token, cachedMsgSender, msg.sender, tokenInput.amount);
} else {
Expand All @@ -259,6 +260,7 @@ contract TridentRouter is ITridentRouter, RouterHelper {
TokenInput[] memory tokenInput = abi.decode(data, (TokenInput[]));
// @dev Transfer the requested tokens to the pool.
for (uint256 i; i < tokenInput.length; i++) {
// TODO: Refactor redudency
if (tokenInput[i].native) {
_depositFromUserToBentoBox(tokenInput[i].token, cachedMsgSender, msg.sender, tokenInput[i].amount);
} else {
Expand Down Expand Up @@ -328,4 +330,7 @@ contract TridentRouter is ITridentRouter, RouterHelper {
whitelistedPools[pool] = true;
}
}

// LIBRARY FUNCTIONS
// https://github.com/Uniswap/v2-periphery/blob/master/contracts/UniswapV2Router02.sol#L402
}
2 changes: 1 addition & 1 deletion contracts/deployer/MasterDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity >=0.8.0;

import "../interfaces/IPoolFactory.sol";
import "../utils/TridentOwnable.sol";
import "../TridentOwnable.sol";

/// @notice Trident pool deployer contract with template factory whitelist.
/// @author Mudit Gupta.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/migration/IntermediaryToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity >=0.8.0;

import "../pool/TridentERC20.sol";
import "../TridentERC20.sol";
import "../interfaces/IERC20.sol";

/// @notice Intermediary token users who are staked in MasterChef will receive after migration.
Expand Down
4 changes: 2 additions & 2 deletions contracts/migration/TridentSushiRollCP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity >= 0.8.0;

import "../utils/TridentBatchable.sol";
import "../utils/TridentPermit.sol";
import "../TridentBatchable.sol";
import "../TridentPermit.sol";
import "../interfaces/IBentoBoxMinimal.sol";
import "../interfaces/ITridentRouter.sol";
import "../interfaces/IMasterDeployer.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/migration/TridentSushiRollReference.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
pragma solidity >=0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../utils/TridentBatchable.sol";
import "../utils/TridentPermit.sol";
import "../TridentBatchable.sol";
import "../TridentPermit.sol";

/// @notice Interface for handling Balancer V1 LP.
interface IBalancerV1 {
Expand Down
24 changes: 24 additions & 0 deletions contracts/mocks/PoolFactoryMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >= 0.8.0;

import "../interfaces/IPoolFactory.sol";
import "../deployer/PoolDeployer.sol";
import "./PoolTemplateMock.sol";

contract PoolFactoryMock is PoolDeployer {
constructor(address _masterDeployer) PoolDeployer(_masterDeployer) {}

function deployPool(bytes memory _deployData) external returns (address pool) {
(address tokenA, address tokenB) = abi.decode(_deployData, (address, address));

address[] memory tokens = new address[](2);
tokens[0] = tokenA;
tokens[1] = tokenB;

bytes32 salt = keccak256(_deployData);
pool = address(new PoolTemplateMock{salt: salt}(_deployData));

_registerPool(pool, tokens, salt);
}
}
16 changes: 16 additions & 0 deletions contracts/mocks/PoolTemplateMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >= 0.8.0;

contract PoolTemplateMock {
address public immutable token0;
address public immutable token1;
constructor(bytes memory _deployData) {
(address _token0, address _token1) = abi.decode(
_deployData,
(address, address)
);
token0 = _token0;
token1 = _token1;
}
}
Loading

0 comments on commit 25eb480

Please sign in to comment.