dsa-connectors/contracts/mainnet/connectors/polygon-bridge/main.sol

56 lines
2.0 KiB
Solidity
Raw Normal View History

2021-04-12 10:48:42 +00:00
pragma solidity ^0.7.0;
/**
* @title Polygon Assets Bridge.
* @dev Polygon assets bridge.
*/
2021-04-12 10:48:42 +00:00
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.
*/
2021-04-12 10:48:42 +00:00
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;
2021-06-02 00:11:02 +00:00
if (migrator.rootToChildToken(token) != address(0)) {
_token.approve(erc20Predicate, _amt);
migrator.depositFor(targetDsa, token, abi.encode(_amt));
} else {
_token.approve(address(migratorPlasma), _amt);
migratorPlasma.depositERC20ForUser(token, targetDsa, _amt);
}
2021-04-12 10:48:42 +00:00
}
setUint(setId, _amt);
_eventName = "LogDeposit(address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(targetDsa, token, _amt, getId, setId);
}
}
2021-04-12 21:50:10 +00:00
contract ConnectV2PolygonBridge is PolygonBridgeResolver {
2021-06-02 00:11:02 +00:00
string public constant name = "Polygon-Bridge-v1.1";
2021-04-12 10:48:42 +00:00
}