Add polygon deposit and exit manager

This commit is contained in:
Mubaris NK 2021-04-12 16:18:42 +05:30
parent ad10944b63
commit e93efb9226
No known key found for this signature in database
GPG Key ID: 9AC09AD0F8D68561
108 changed files with 93 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,53 @@
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 {
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);
}
/**
* @dev Withdraw assets from Polygon.
* @notice Complete withdraw by submitting burn tx hash.
* @param proof The proof generated from burn tx.
*/
function withdraw(
bytes calldata proof
) external payable returns (string memory _eventName, bytes memory _eventParam) {
require(proof.length > 0, "invalid-proof");
migrator.exit(proof);
_eventName = "LogWithdraw(bytes)";
_eventParam = abi.encode(proof);
}
}
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