Skip to content

Commit

Permalink
Add x-chain gauge factory contracts w/ basic tests and deploy scripts (
Browse files Browse the repository at this point in the history
…#684)

* adding files is state where tests work

* root gauge factory tests, child gauge factory initialize

* child gauge initial tests

* added oracles and arbitrum bridger

* fixed oracles and added test for oracle

* updated todo comments

* updated Anycall translator and anycall mock contracts

* added rootgaugeFactory tests

* updated mock anycall contract

* updated translator / mock anycall contracts

* finalized AnycallTranslator contract

* updated translator contract with all accepted function calls

* finalized oracle contracts

* finalized gauge implementations

* added Optimism bridger, cleaned up comments

* removed delegatecall from translator

* naming changes

* Script for enabling on chain gauge voting (#691)

* updated logic of RootGauge

* added logic for having a RootGauge name

* fixed typing of name(), added to factory tests

* updated tests to successfully deploy root gauge

* Added to RootGauge Factory tests

* added deposit and rescue functios to translator

* added fixture to RootGauge Factory Test

* added todo comments

* Add deploy script and deployment data for non-flashloan swaps (#690)

* Updates pool reg for FraxBP USDs pool (#686)

* updates pool reg for FraxBP USDs pool

* ran lint fix

* fixed typo in pool registry update

* Skip script from running

Co-authored-by: Jongseung Lim <penandlim@gmail.com>

* Add separate tests for permissionless contracts (#681)

* Add separate tests for permissionless contracts

* Change test name to be accurate

* added deploys for non-flashload permissionless swaps

Co-authored-by: Michael Daly <dalymike102@gmail.com>

* Fix root gauge factory test.
- fix capitalization

* Fix capitalization in file names

* Fix test imports and types
- import from typechain

* Lint x chain gauges contracts

* Deploy root gauge factory on hardhat

* Deploy script for fake USDC (#693)

* Run prepare scripts by default on hardhat (#694)

* Run prepare scripts by default on hardhat

* Specify tags for swapMigrator tests

* Fix saving Multicall3 with abi

* Ensure no other deploy scripts are ran except the specified

* Add the deployed gauge to gauge controller

* Updates hardhat and migrate from waffle to hardhat chai matchers (#696)

* Migrate from waffle to hardhat chai matchers

* Linting fix

* Fix function name to include parameters for overloading

* Adds 2 new node dependencies (#699)

- hardhat-tracer
- openzepplin 4.4.0 upgradable

* Update AnyCallTranslator to be a proxy. Updates the test.

* Change signatures to match up between contracts

* Add test for sidechain -> root chain deploy_gauge()

* Fix encoding type

* Use proxy in deploy script

* ChildOracle emits an event when recieving

* Cleans up hardhat config file and moves tasks into tasks folder (#698)

* Cleans up hardhat config file and moves tasks into tasks folder

* Remove unnecessary dependency

* Add comments to tasks

* Fix param casing

* Add deploy scripts for optimism mainnet

* Improve fork settings (#700)

* Add deploy scripts

* Deploy a child gauge for SaddleFRAXBPPoolLPToken

* Adds `patch-package` to apply fix for Arbitrum Nitro (#701)

* Update USDS pool in pool registry (#702)

* Fix duplicate contract names

* Add deploy scripts for mainnet. Only run when forking for now

* Update RootOracle contract and test

* Uses immutables
* Removes unnecessary storage var

* USDT pool deploy (#703)

* Added USDT pool deploy, fixed typo in verify script

* deployed to kava_mainnet

* fixed registering of pools

* registered USDT pool

* verified new USDT Pool deployment

* Update hardhat to 2.11.1 and associated dependencies (#704)

* Update hardhat to 2.11.1 and associated dependencies

* Update solidity-coverage package version

* Update tests to use the ignore tx type flag

* Test for each storage variable separately

* Change file name cases to be in consistent style

* Update RootGaugeFactory tests

* Include prefix and suffix on Gauge names

* Update ChildGaugeFactory test

* Specify deploy tags for each test (#705)

* Use chai's closeTo comparison to approximate

* Add appropriate fixture deploy tags to all tests

* Increase line coverage

* Add tests for collecting fees on PermissionlessMetaSwapFlashLoan
instance

Co-authored-by: Jongseung (John) Lim <penandlim@gmail.com>
  • Loading branch information
lilPlumberBoy and penandlim committed Sep 14, 2022
1 parent 77b182b commit 241e2fc
Show file tree
Hide file tree
Showing 30 changed files with 4,724 additions and 0 deletions.
689 changes: 689 additions & 0 deletions contracts/tokenomics/gauges/CurveLiquidityGauge.vy

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions contracts/xchainGauges/AnycallTranslator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.6;
pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts-4.4.0/proxy/transparent/TransparentUpgradeableProxy.sol";
import "@openzeppelin/contracts-4.4.0/proxy/transparent/ProxyAdmin.sol";

import "@openzeppelin/contracts-upgradeable-4.4.0/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable-4.4.0/access/OwnableUpgradeable.sol";

interface ICallProxy {
function anyCall(
address _to,
bytes calldata _data,
address _fallback,
uint256 _toChainId,
uint256 _flags
) external payable; // nonpayable

function deposit(address _account) external payable;

function withdraw(uint256 amount) external;

function executor() external view returns (address executor);
}

interface IAnycallExecutor {
function context()
external
view
returns (
address from,
uint256 fromChainID,
uint256 nonce
);
}

// Empty contract to ensure import of TransparentUpgradeableProxy contract
contract EmptyProxy is TransparentUpgradeableProxy {
constructor(
address _logic,
address admin_,
bytes memory _data
) payable TransparentUpgradeableProxy(_logic, admin_, _data) {}
}

// Empty contract to ensure import of ProxyAdmin contract
contract EmptyProxyAdmin is ProxyAdmin {

}

// Logic contract that will be used by the proxy
contract AnyCallTranslator is OwnableUpgradeable {
using SafeERC20Upgradeable for IERC20Upgradeable;
// consts
address public anycallContract;
address public anyCallExecutor;
mapping(address => bool) public isKnownCaller;

constructor() initializer {
// logic contract
}

receive() external payable {
// fallback payable function
}

function initialize(address _owner, address _anycallContract)
public
initializer
{
_transferOwnership(_owner);
anycallContract = _anycallContract;
anyCallExecutor = ICallProxy(_anycallContract).executor();
}

function addKnownCallers(address[] calldata _callers) external onlyOwner {
for (uint256 i = 0; i < _callers.length; i++) {
isKnownCaller[_callers[i]] = true;
}
}

function removeKnownCallers(address[] calldata _callers)
external
onlyOwner
{
for (uint256 i = 0; i < _callers.length; i++) {
isKnownCaller[_callers[i]] = false;
}
}

function setAnycall(address _anycallContract) external onlyOwner {
anycallContract = _anycallContract;
anyCallExecutor = ICallProxy(_anycallContract).executor();
}

function withdraw(uint256 _amount) external onlyOwner {
ICallProxy(anycallContract).withdraw(_amount);
}

function rescue(IERC20Upgradeable token, address to) external onlyOwner {
token.safeTransfer(to, token.balanceOf(address(this)));
}

function anyCall(
address _to,
bytes calldata _data,
address _fallback,
uint256 _toChainId,
// Use 0 flag to pay fee on destination chain, 1 to pay on source
uint256 _flags
) external payable {
require(isKnownCaller[msg.sender], "Unknown caller");
ICallProxy(anycallContract).anyCall{value: msg.value}(
address(this),
abi.encode(_to, _data),
_fallback,
_toChainId,
_flags
);
}

function anyExecute(bytes calldata toAndData)
external
returns (bool, bytes memory)
{
// Check that caller is anycall executor
require(
msg.sender == anyCallExecutor,
"Caller is not anycall executor"
);
// Get address of anycallExecutor
(address _from, , ) = IAnycallExecutor(msg.sender).context();
// Check that caller is verified
require(_from == address(this), "Wrong context");

// Decode to and data
(address to, bytes memory data) = abi.decode(
toAndData,
(address, bytes)
);
(bool success, bytes memory returnData) = to.call(data);
require(success, "Proxy call failed");
return (success, returnData);
}
}

0 comments on commit 241e2fc

Please sign in to comment.