From 824f64d5376dc101769059b15db179e8ed6e71ec Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Tue, 7 Dec 2021 19:37:41 +0530 Subject: [PATCH] Added wmatic --- .../polygon/connectors/wmatic/events.sol | 6 ++ .../polygon/connectors/wmatic/helpers.sol | 8 +++ contracts/polygon/connectors/wmatic/main.sol | 65 +++++++++++++++++++ hardhat.config.js | 4 +- 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 contracts/polygon/connectors/wmatic/events.sol create mode 100644 contracts/polygon/connectors/wmatic/helpers.sol create mode 100644 contracts/polygon/connectors/wmatic/main.sol diff --git a/contracts/polygon/connectors/wmatic/events.sol b/contracts/polygon/connectors/wmatic/events.sol new file mode 100644 index 00000000..f8ec366a --- /dev/null +++ b/contracts/polygon/connectors/wmatic/events.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.7.0; + +contract Events { + event LogDeposit(uint256 tokenAmt, uint256 getId, uint256 setId); + event LogWithdraw(uint256 tokenAmt, uint256 getId, uint256 setId); +} diff --git a/contracts/polygon/connectors/wmatic/helpers.sol b/contracts/polygon/connectors/wmatic/helpers.sol new file mode 100644 index 00000000..bfc084ae --- /dev/null +++ b/contracts/polygon/connectors/wmatic/helpers.sol @@ -0,0 +1,8 @@ +pragma solidity ^0.7.0; + +import { TokenInterface } from "../../common/interfaces.sol"; + + +abstract contract Helpers { + TokenInterface constant internal wmaticContract = TokenInterface(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270); +} diff --git a/contracts/polygon/connectors/wmatic/main.sol b/contracts/polygon/connectors/wmatic/main.sol new file mode 100644 index 00000000..1f15c12b --- /dev/null +++ b/contracts/polygon/connectors/wmatic/main.sol @@ -0,0 +1,65 @@ +pragma solidity ^0.7.0; + +/** + * @title WMATIC. + * @dev Wrap and Unwrap WMATIC. + */ + +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { Events } from "./events.sol"; +import { Helpers } from "./helpers.sol"; + +abstract contract Resolver is Events, DSMath, Basic, Helpers { + + /** + * @dev Deposit MATIC into WMATIC. + * @notice Wrap MATIC into WMATIC + * @param amt The amount of MATIC to deposit. (For max: `uint256(-1)`) + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of MATIC deposited. + */ + function deposit( + uint256 amt, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + + _amt = _amt == uint(-1) ? address(this).balance : _amt; + wmaticContract.deposit{value: _amt}(); + + setUint(setId, _amt); + + _eventName = "LogDeposit(uint256,uint256,uint256)"; + _eventParam = abi.encode(_amt, getId, setId); + } + + /** + * @dev Withdraw MATIC from WMATIC from Smart Account + * @notice Unwrap MATIC from WMATIC + * @param amt The amount of wmatic to withdraw. (For max: `uint256(-1)`) + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of MATIC withdrawn. + */ + function withdraw( + uint amt, + uint getId, + uint setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + + _amt = _amt == uint(-1) ? wmaticContract.balanceOf(address(this)) : _amt; + approve(wmaticContract, wmaticAddr, _amt); + wmaticContract.withdraw(_amt); + + setUint(setId, _amt); + + _eventName = "LogWithdraw(uint256,uint256,uint256)"; + _eventParam = abi.encode(_amt, getId, setId); + } +} + +contract ConnectV2WMATICPolygon is Resolver { + string constant public name = "WMATIC-v1.0"; +} diff --git a/hardhat.config.js b/hardhat.config.js index 31c7b9ed..7c82bc76 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -67,10 +67,10 @@ module.exports = { blockGasLimit: 12000000, }, matic: { - url: "https://rpc-mainnet.maticvigil.com/", + url: "https://polygon-rpc.com/", accounts: [`0x${PRIVATE_KEY}`], timeout: 150000, - gasPrice: parseInt(utils.parseUnits("1", "gwei")), + gasPrice: parseInt(utils.parseUnits("50", "gwei")), }, arbitrum: { chainId: 42161,