mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #128 from Instadapp/wmatic-connector
Added WMATIC-A connector
This commit is contained in:
commit
34ff908331
|
@ -1,18 +1,24 @@
|
|||
pragma solidity ^0.7.6;
|
||||
pragma abicoder v2;
|
||||
|
||||
/**
|
||||
* @title Universe finance
|
||||
* @dev Maximising uniswap v3 returns
|
||||
*/
|
||||
|
||||
import {TokenInterface} from "../../common/interfaces.sol";
|
||||
import {Helpers} from "./helpers.sol";
|
||||
import {Events} from "./events.sol";
|
||||
|
||||
abstract contract UniverseFinanceConnect is Helpers, Events {
|
||||
|
||||
/**
|
||||
* @notice Deposit in Universe Vault by Adapter
|
||||
* @dev Deposit in universe vault
|
||||
* @param universeVault Universe Official Vault Address
|
||||
* @param amountA Amount of tokenA
|
||||
* @param amountB Amount of tokenB
|
||||
* @param getIds ID to retrieve amountA and amountB
|
||||
* @param setIds ID to store amountA and amountB
|
||||
*/
|
||||
function deposit(
|
||||
address universeVault,
|
||||
|
@ -20,23 +26,39 @@ abstract contract UniverseFinanceConnect is Helpers, Events {
|
|||
uint256 amountB,
|
||||
uint256[] calldata getIds,
|
||||
uint256[] calldata setIds
|
||||
) external returns (string memory _eventName, bytes memory _eventParam){
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
amountA = getUint(getIds[0], amountA);
|
||||
amountB = getUint(getIds[1], amountB);
|
||||
_approve(universeVault, amountA, amountB);
|
||||
(uint256 share0, uint256 share1) = _deposit(universeVault, amountA, amountB);
|
||||
(uint256 share0, uint256 share1) = _deposit(
|
||||
universeVault,
|
||||
amountA,
|
||||
amountB
|
||||
);
|
||||
setUint(setIds[0], share0);
|
||||
setUint(setIds[1], share1);
|
||||
// EVENT
|
||||
_eventName = "LogDeposit(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(universeVault, amountA, amountB, share0, share1);
|
||||
_eventParam = abi.encode(
|
||||
universeVault,
|
||||
amountA,
|
||||
amountB,
|
||||
share0,
|
||||
share1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Withdraw Token0 & Token1 From Universe Vault
|
||||
* @dev Withdraw supplied token0 and token1 from universe vault
|
||||
* @param universeVault Universe Official Vault Address
|
||||
* @param share0 Amount of uToken0.
|
||||
* @param share1 Amount of uToken1.
|
||||
* @param getIds ID to retrieve amount of output token
|
||||
* @param setIds stores the amount of output tokens
|
||||
*/
|
||||
function withdraw(
|
||||
|
@ -45,17 +67,24 @@ abstract contract UniverseFinanceConnect is Helpers, Events {
|
|||
uint256 share1,
|
||||
uint256[] calldata getIds,
|
||||
uint256[] calldata setIds
|
||||
) external returns (string memory _eventName, bytes memory _eventParam){
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
share0 = getUint(getIds[0], share0);
|
||||
share1 = getUint(getIds[1], share1);
|
||||
(uint256 _amtA, uint256 _amtB) = _withdraw(universeVault, share0, share1);
|
||||
(uint256 _amtA, uint256 _amtB) = _withdraw(
|
||||
universeVault,
|
||||
share0,
|
||||
share1
|
||||
);
|
||||
setUint(setIds[0], _amtA);
|
||||
setUint(setIds[1], _amtB);
|
||||
// EVENT
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(universeVault, _amtA, _amtB, share0, share1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract ConnectV2UniverseFinance is UniverseFinanceConnect {
|
||||
|
|
6
contracts/polygon/connectors/wmatic/events.sol
Normal file
6
contracts/polygon/connectors/wmatic/events.sol
Normal file
|
@ -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);
|
||||
}
|
8
contracts/polygon/connectors/wmatic/helpers.sol
Normal file
8
contracts/polygon/connectors/wmatic/helpers.sol
Normal file
|
@ -0,0 +1,8 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
||||
|
||||
abstract contract Helpers {
|
||||
TokenInterface constant internal wmaticContract = TokenInterface(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270);
|
||||
}
|
65
contracts/polygon/connectors/wmatic/main.sol
Normal file
65
contracts/polygon/connectors/wmatic/main.sol
Normal file
|
@ -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";
|
||||
}
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user