Merge pull request #22 from Instadapp/polygon-connectors

Mainnet <> Polygon bridge connectors
This commit is contained in:
Samyak Jain 2021-04-13 06:19:59 +10:00 committed by GitHub
commit aa645ac41d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
112 changed files with 245 additions and 0 deletions

View File

@ -0,0 +1,12 @@
pragma solidity ^0.7.0;
contract Events {
event LogDeposit(
address targetDsa,
address token,
uint256 amt,
uint256 getId,
uint256 setId
);
event LogWithdraw(bytes proof);
}

View File

@ -0,0 +1,17 @@
pragma solidity ^0.7.0;
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { RootChainManagerInterface } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
* Polygon POS Bridge ERC20 Predicate
*/
address internal constant erc20Predicate = 0x40ec5B33f54e0E8A33A975908C5BA1c14e5BbbDf;
/**
* Polygon POS Bridge Manager
*/
RootChainManagerInterface internal constant migrator = RootChainManagerInterface(0xA0c68C638235ee32657e8f720a23ceC1bFc77C77);
}

View File

@ -0,0 +1,11 @@
pragma solidity ^0.7.0;
interface RootChainManagerInterface {
function depositEtherFor(address user) external payable;
function depositFor(
address user,
address rootToken,
bytes calldata depositData
) external;
function exit(bytes calldata inputData) external;
}

View File

@ -0,0 +1,46 @@
pragma solidity ^0.7.0;
import { TokenInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
abstract contract PolygonBridgeResolver is Events, Helpers {
/**
* @dev Deposit assets to the bridge.
* @notice Deposit assets to the bridge.
* @param targetDsa The address to receive the token on Polygon
* @param token The address of the token to deposit. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of tokens to deposit. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens deposit.
*/
function deposit(
address targetDsa,
address token,
uint256 amt,
uint256 getId,
uint256 setId
) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint _amt = getUint(getId, amt);
if (token == ethAddr) {
_amt = _amt == uint(-1) ? address(this).balance : _amt;
migrator.depositEtherFor{value: _amt}(targetDsa);
} else {
TokenInterface _token = TokenInterface(token);
_amt = _amt == uint(-1) ? _token.balanceOf(address(this)) : _amt;
_token.approve(erc20Predicate, _amt);
migrator.depositFor(targetDsa, token, abi.encode(_amt));
}
setUint(setId, _amt);
_eventName = "LogDeposit(address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(targetDsa, token, _amt, getId, setId);
}
}
contract ConnectPolygonBridge is PolygonBridgeResolver {
string public constant name = "COMP-v1";
}

Some files were not shown because too many files have changed in this diff Show More