mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #22 from Instadapp/polygon-connectors
Mainnet <> Polygon bridge connectors
This commit is contained in:
commit
aa645ac41d
12
contracts/mainnet/connectors/polygon-bridge/events.sol
Normal file
12
contracts/mainnet/connectors/polygon-bridge/events.sol
Normal 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);
|
||||
}
|
17
contracts/mainnet/connectors/polygon-bridge/helpers.sol
Normal file
17
contracts/mainnet/connectors/polygon-bridge/helpers.sol
Normal 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);
|
||||
}
|
11
contracts/mainnet/connectors/polygon-bridge/interface.sol
Normal file
11
contracts/mainnet/connectors/polygon-bridge/interface.sol
Normal 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;
|
||||
}
|
46
contracts/mainnet/connectors/polygon-bridge/main.sol
Normal file
46
contracts/mainnet/connectors/polygon-bridge/main.sol
Normal 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
Loading…
Reference in New Issue
Block a user