mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #37 from Instadapp/polygon-connectors
Added polygon connectors
This commit is contained in:
commit
48ec4c7cb5
contracts
mainnet
connectors
1inch
1proto
COMP
aave
authority
basic
compound
cream
dydx
fee
gelato
instapool_v2
kyber
makerdao
oasis
polygon-bridge
reflexer
uniswap
deprecated
polygon/connectors
aave
authority
basic
paraswap
status-checks
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title 1Inch.
|
||||
* @dev On-chain DEX Aggregator.
|
||||
*/
|
||||
|
||||
// import files from common directory
|
||||
import { TokenInterface , MemoryInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title 1Proto.
|
||||
* @dev On-chain and off-chian DEX Aggregator.
|
||||
*/
|
||||
|
||||
import { TokenInterface , MemoryInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { OneProtoInterface, OneProtoData, OneProtoMultiData } from "./interface.sol";
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title COMP.
|
||||
* @dev Claim COMP.
|
||||
*/
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Aave Rewards.
|
||||
* @dev Claim Aave rewards.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
|
||||
/**
|
||||
* @title stkAave.
|
||||
* @dev Staked Aave.
|
||||
*/
|
||||
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
|
||||
/**
|
||||
* @title Aave v1.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Aave v2 AMM.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Aave v2.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Authority.
|
||||
* @dev Manage Authorities to DSA.
|
||||
*/
|
||||
|
||||
import { AccountInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Basic.
|
||||
* @dev Deposit & Withdraw from DSA.
|
||||
*/
|
||||
|
||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title Compound.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title CREAM.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title dYdX.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Fee.
|
||||
* @dev Calculate Fee.
|
||||
*/
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title Gelato.
|
||||
* @dev Automation.
|
||||
*/
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { IGelatoInterface, Task, Provider, TaskSpec, TaskReceipt } from "./interface.sol";
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
/**
|
||||
* @title Instapool.
|
||||
* @dev Flash Loan in DSA.
|
||||
*/
|
||||
|
||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
@ -15,8 +20,10 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
|
||||
/**
|
||||
* @dev Borrow Flashloan and Cast spells.
|
||||
* @notice Borrows flashloan and cast the spells.
|
||||
* @param token Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param route Route to borrow.
|
||||
* @param data targets & data for cast.
|
||||
*/
|
||||
function flashBorrowAndCast(
|
||||
|
@ -42,6 +49,7 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
|
||||
/**
|
||||
* @dev Return token to InstaPool.
|
||||
* @notice Payback borrowed flashloan.
|
||||
* @param token Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||
|
@ -67,6 +75,7 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
|
||||
/**
|
||||
* @dev Borrow Flashloan and Cast spells.
|
||||
* @notice Borrows multiple flashloan tokens and cast the spells.
|
||||
* @param tokens Array of token Addresses.
|
||||
* @param amts Array of token Amounts.
|
||||
* @param route Route to borrow.
|
||||
|
@ -90,6 +99,7 @@ contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
|||
|
||||
/**
|
||||
* @dev Return Multiple token liquidity to InstaPool.
|
||||
* @notice Payback borrowed multiple flashloan tokens.
|
||||
* @param tokens Array of token addresses.
|
||||
* @param amts Array of token amounts.
|
||||
* @param getId get token amounts at this IDs from `InstaMemory` Contract.
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Kyber.
|
||||
* @dev Decentralised Swapping.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title MakerDAO.
|
||||
* @dev Collateralized Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title OasisDEX.
|
||||
* @dev Decentralised Exchange.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Polygon Assets Bridge.
|
||||
* @dev Polygon assets bridge.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Reflexer.
|
||||
* @dev Collateralized Borrowing.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Uniswap v2.
|
||||
* @dev Decentralized Exchange.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Instapool.
|
||||
* @dev Flash Loan in DSA.
|
||||
*/
|
||||
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
|
@ -1,7 +1,7 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { DSMath } from "../../../common/math.sol";
|
||||
import { Basic } from "../../../common/basic.sol";
|
||||
import { AaveIncentivesInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
|
@ -1,7 +1,13 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
|
||||
/**
|
||||
* @title Aave Rewards.
|
||||
* @dev Claim Aave rewards.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
|
@ -34,6 +40,6 @@ abstract contract IncentivesResolver is Helpers, Events {
|
|||
}
|
||||
}
|
||||
|
||||
contract ConnectV2AaveIncentives is IncentivesResolver {
|
||||
contract ConnectV2AaveIncentivesPolygon is IncentivesResolver {
|
||||
string public constant name = "Aave-Incentives-v1";
|
||||
}
|
10
contracts/polygon/connectors/aave/v2/events.sol
Normal file
10
contracts/polygon/connectors/aave/v2/events.sol
Normal file
|
@ -0,0 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogWithdraw(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogBorrow(address indexed token, uint256 tokenAmt, uint256 indexed rateMode, uint256 getId, uint256 setId);
|
||||
event LogPayback(address indexed token, uint256 tokenAmt, uint256 indexed rateMode, uint256 getId, uint256 setId);
|
||||
event LogEnableCollateral(address[] tokens);
|
||||
event LogSwapRateMode(address indexed token, uint256 rateMode);
|
||||
}
|
49
contracts/polygon/connectors/aave/v2/helpers.sol
Normal file
49
contracts/polygon/connectors/aave/v2/helpers.sol
Normal file
|
@ -0,0 +1,49 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
import { DSMath } from "../../../common/math.sol";
|
||||
import { Basic } from "../../../common/basic.sol";
|
||||
import { AaveLendingPoolProviderInterface, AaveDataProviderInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
|
||||
/**
|
||||
* @dev Aave Lending Pool Provider
|
||||
*/
|
||||
AaveLendingPoolProviderInterface constant internal aaveProvider = AaveLendingPoolProviderInterface(0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5);
|
||||
|
||||
/**
|
||||
* @dev Aave Protocol Data Provider
|
||||
*/
|
||||
AaveDataProviderInterface constant internal aaveData = AaveDataProviderInterface(0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d);
|
||||
|
||||
/**
|
||||
* @dev Aave Referral Code
|
||||
*/
|
||||
uint16 constant internal referralCode = 3228;
|
||||
|
||||
/**
|
||||
* @dev Checks if collateral is enabled for an asset
|
||||
* @param token token address of the asset.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
*/
|
||||
function getIsColl(address token) internal view returns (bool isCol) {
|
||||
(, , , , , , , , isCol) = aaveData.getUserReserveData(token, address(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get total debt balance & fee for an asset
|
||||
* @param token token address of the debt.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param rateMode Borrow rate mode (Stable = 1, Variable = 2)
|
||||
*/
|
||||
function getPaybackBalance(address token, uint rateMode) internal view returns (uint) {
|
||||
(, uint stableDebt, uint variableDebt, , , , , , ) = aaveData.getUserReserveData(token, address(this));
|
||||
return rateMode == 1 ? stableDebt : variableDebt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Get total collateral balance for an asset
|
||||
* @param token token address of the collateral.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
*/
|
||||
function getCollateralBalance(address token) internal view returns (uint bal) {
|
||||
(bal, , , , , , , ,) = aaveData.getUserReserveData(token, address(this));
|
||||
}
|
||||
}
|
47
contracts/polygon/connectors/aave/v2/interface.sol
Normal file
47
contracts/polygon/connectors/aave/v2/interface.sol
Normal file
|
@ -0,0 +1,47 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
interface AaveInterface {
|
||||
function deposit(address _asset, uint256 _amount, address _onBehalfOf, uint16 _referralCode) external;
|
||||
function withdraw(address _asset, uint256 _amount, address _to) external;
|
||||
function borrow(
|
||||
address _asset,
|
||||
uint256 _amount,
|
||||
uint256 _interestRateMode,
|
||||
uint16 _referralCode,
|
||||
address _onBehalfOf
|
||||
) external;
|
||||
function repay(address _asset, uint256 _amount, uint256 _rateMode, address _onBehalfOf) external;
|
||||
function setUserUseReserveAsCollateral(address _asset, bool _useAsCollateral) external;
|
||||
function swapBorrowRateMode(address _asset, uint256 _rateMode) external;
|
||||
}
|
||||
|
||||
interface AaveLendingPoolProviderInterface {
|
||||
function getLendingPool() external view returns (address);
|
||||
}
|
||||
|
||||
interface AaveDataProviderInterface {
|
||||
function getReserveTokensAddresses(address _asset) external view returns (
|
||||
address aTokenAddress,
|
||||
address stableDebtTokenAddress,
|
||||
address variableDebtTokenAddress
|
||||
);
|
||||
function getUserReserveData(address _asset, address _user) external view returns (
|
||||
uint256 currentATokenBalance,
|
||||
uint256 currentStableDebt,
|
||||
uint256 currentVariableDebt,
|
||||
uint256 principalStableDebt,
|
||||
uint256 scaledVariableDebt,
|
||||
uint256 stableBorrowRate,
|
||||
uint256 liquidityRate,
|
||||
uint40 stableRateLastUpdated,
|
||||
bool usageAsCollateralEnabled
|
||||
);
|
||||
}
|
||||
|
||||
interface AaveAddressProviderRegistryInterface {
|
||||
function getAddressesProvidersList() external view returns (address[] memory);
|
||||
}
|
||||
|
||||
interface ATokenInterface {
|
||||
function balanceOf(address _user) external view returns(uint256);
|
||||
}
|
216
contracts/polygon/connectors/aave/v2/main.sol
Normal file
216
contracts/polygon/connectors/aave/v2/main.sol
Normal file
|
@ -0,0 +1,216 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Aave v2.
|
||||
* @dev Lending & Borrowing.
|
||||
*/
|
||||
|
||||
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import { Stores } from "../../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
import { AaveInterface } from "./interface.sol";
|
||||
|
||||
abstract contract AaveResolver is Events, Helpers {
|
||||
/**
|
||||
* @dev Deposit ETH/ERC20_Token.
|
||||
* @notice Deposit a token to Aave v2 for lending / collaterization.
|
||||
* @param token The address of the token to deposit.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function deposit(
|
||||
address token,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
bool isEth = token == maticAddr;
|
||||
address _token = isEth ? wmaticAddr : token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
if (isEth) {
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
convertMaticToWmatic(isEth, tokenContract, _amt);
|
||||
} else {
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
}
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
|
||||
aave.deposit(_token, _amt, address(this), referralCode);
|
||||
|
||||
if (!getIsColl(_token)) {
|
||||
aave.setUserUseReserveAsCollateral(_token, true);
|
||||
}
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw ETH/ERC20_Token.
|
||||
* @notice Withdraw deposited token from Aave v2
|
||||
* @param token The address of the token to withdraw.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of tokens withdrawn.
|
||||
*/
|
||||
function withdraw(
|
||||
address token,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
bool isEth = token == maticAddr;
|
||||
address _token = isEth ? wmaticAddr : token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
uint initialBal = tokenContract.balanceOf(address(this));
|
||||
aave.withdraw(_token, _amt, address(this));
|
||||
uint finalBal = tokenContract.balanceOf(address(this));
|
||||
|
||||
_amt = sub(finalBal, initialBal);
|
||||
|
||||
convertWmaticToMatic(isEth, tokenContract, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Borrow ETH/ERC20_Token.
|
||||
* @notice Borrow a token using Aave v2
|
||||
* @param token The address of the token to borrow.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt The amount of the token to borrow.
|
||||
* @param rateMode The type of borrow debt. (For Stable: 1, Variable: 2)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of tokens borrowed.
|
||||
*/
|
||||
function borrow(
|
||||
address token,
|
||||
uint256 amt,
|
||||
uint256 rateMode,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
bool isEth = token == maticAddr;
|
||||
address _token = isEth ? wmaticAddr : token;
|
||||
|
||||
aave.borrow(_token, _amt, rateMode, referralCode, address(this));
|
||||
convertWmaticToMatic(isEth, TokenInterface(_token), _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogBorrow(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, rateMode, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Payback borrowed ETH/ERC20_Token.
|
||||
* @notice Payback debt owed.
|
||||
* @param token The address of the token to payback.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt The amount of the token to payback. (For max: `uint256(-1)`)
|
||||
* @param rateMode The type of debt paying back. (For Stable: 1, Variable: 2)
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of tokens paid back.
|
||||
*/
|
||||
function payback(
|
||||
address token,
|
||||
uint256 amt,
|
||||
uint256 rateMode,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
bool isEth = token == maticAddr;
|
||||
address _token = isEth ? wmaticAddr : token;
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
_amt = _amt == uint(-1) ? getPaybackBalance(_token, rateMode) : _amt;
|
||||
|
||||
if (isEth) convertMaticToWmatic(isEth, tokenContract, _amt);
|
||||
|
||||
tokenContract.approve(address(aave), _amt);
|
||||
|
||||
aave.repay(_token, _amt, rateMode, address(this));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogPayback(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, rateMode, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Enable collateral
|
||||
* @notice Enable an array of tokens as collateral
|
||||
* @param tokens Array of tokens to enable collateral
|
||||
*/
|
||||
function enableCollateral(
|
||||
address[] calldata tokens
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _length = tokens.length;
|
||||
require(_length > 0, "0-tokens-not-allowed");
|
||||
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
for (uint i = 0; i < _length; i++) {
|
||||
address token = tokens[i];
|
||||
if (getCollateralBalance(token) > 0 && !getIsColl(token)) {
|
||||
aave.setUserUseReserveAsCollateral(token, true);
|
||||
}
|
||||
}
|
||||
|
||||
_eventName = "LogEnableCollateral(address[])";
|
||||
_eventParam = abi.encode(tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Swap borrow rate mode
|
||||
* @notice Swaps user borrow rate mode between variable and stable
|
||||
* @param token The address of the token to swap borrow rate.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param rateMode Desired borrow rate mode. (Stable = 1, Variable = 2)
|
||||
*/
|
||||
function swapBorrowRateMode(
|
||||
address token,
|
||||
uint rateMode
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
|
||||
|
||||
uint currentRateMode = rateMode == 1 ? 2 : 1;
|
||||
|
||||
if (getPaybackBalance(token, currentRateMode) > 0) {
|
||||
aave.swapBorrowRateMode(token, rateMode);
|
||||
}
|
||||
|
||||
_eventName = "LogSwapRateMode(address,uint256)";
|
||||
_eventParam = abi.encode(token, rateMode);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2AaveV2 is AaveResolver {
|
||||
string constant public name = "AaveV2-v1";
|
||||
}
|
6
contracts/polygon/connectors/authority/events.sol
Normal file
6
contracts/polygon/connectors/authority/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogAddAuth(address indexed _msgSender, address indexed _authority);
|
||||
event LogRemoveAuth(address indexed _msgSender, address indexed _authority);
|
||||
}
|
15
contracts/polygon/connectors/authority/helpers.sol
Normal file
15
contracts/polygon/connectors/authority/helpers.sol
Normal file
|
@ -0,0 +1,15 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { ListInterface } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
ListInterface internal constant listContract = ListInterface(0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556);
|
||||
|
||||
function checkAuthCount() internal view returns (uint count) {
|
||||
uint64 accountId = listContract.accountID(address(this));
|
||||
count = listContract.accountLink(accountId).count;
|
||||
}
|
||||
}
|
13
contracts/polygon/connectors/authority/interface.sol
Normal file
13
contracts/polygon/connectors/authority/interface.sol
Normal file
|
@ -0,0 +1,13 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface ListInterface {
|
||||
struct AccountLink {
|
||||
address first;
|
||||
address last;
|
||||
uint64 count;
|
||||
}
|
||||
|
||||
function accountID(address) external view returns (uint64);
|
||||
function accountLink(uint64) external view returns (AccountLink memory);
|
||||
}
|
45
contracts/polygon/connectors/authority/main.sol
Normal file
45
contracts/polygon/connectors/authority/main.sol
Normal file
|
@ -0,0 +1,45 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Authority.
|
||||
* @dev Manage Authorities to DSA.
|
||||
*/
|
||||
|
||||
import { AccountInterface } from "../../common/interfaces.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract AuthorityResolver is Events, Helpers {
|
||||
/**
|
||||
* @dev Add New authority
|
||||
* @notice Add an address as account authority
|
||||
* @param authority The authority Address.
|
||||
*/
|
||||
function add(
|
||||
address authority
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
AccountInterface(address(this)).enable(authority);
|
||||
|
||||
_eventName = "LogAddAuth(address,address)";
|
||||
_eventParam = abi.encode(msg.sender, authority);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Remove authority
|
||||
* @notice Remove an address as account authority
|
||||
* @param authority The authority Address.
|
||||
*/
|
||||
function remove(
|
||||
address authority
|
||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(checkAuthCount() > 1, "Removing-all-authorities");
|
||||
AccountInterface(address(this)).disable(authority);
|
||||
|
||||
_eventName = "LogRemoveAuth(address,address)";
|
||||
_eventParam = abi.encode(msg.sender, authority);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2Auth is AuthorityResolver {
|
||||
string public constant name = "Auth-v1";
|
||||
}
|
6
contracts/polygon/connectors/basic/events.sol
Normal file
6
contracts/polygon/connectors/basic/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||
event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId);
|
||||
}
|
82
contracts/polygon/connectors/basic/main.sol
Normal file
82
contracts/polygon/connectors/basic/main.sol
Normal file
|
@ -0,0 +1,82 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
|
||||
/**
|
||||
* @title Basic.
|
||||
* @dev Deposit & Withdraw from DSA.
|
||||
*/
|
||||
|
||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract BasicResolver is Events, DSMath, Basic {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
/**
|
||||
* @dev Deposit Assets To Smart Account.
|
||||
* @notice Deposit a token to DSA
|
||||
* @param token The address of the token to deposit. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt The amount of tokens to deposit. (For max: `uint256(-1)` (Not valid for MATIC))
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of tokens deposited.
|
||||
*/
|
||||
function deposit(
|
||||
address token,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
if (token != maticAddr) {
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(msg.sender) : _amt;
|
||||
tokenContract.safeTransferFrom(msg.sender, address(this), _amt);
|
||||
} else {
|
||||
require(msg.value == _amt || _amt == uint(-1), "invalid-ether-amount");
|
||||
_amt = msg.value;
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Withdraw Assets from Smart Account
|
||||
* @notice Withdraw a token from DSA
|
||||
* @param token The address of the token to withdraw. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param amt The amount of tokens to withdraw. (For max: `uint256(-1)`)
|
||||
* @param to The address to receive the token upon withdrawal
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of tokens withdrawn.
|
||||
*/
|
||||
function withdraw(
|
||||
address token,
|
||||
uint amt,
|
||||
address payable to,
|
||||
uint getId,
|
||||
uint setId
|
||||
) public payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint _amt = getUint(getId, amt);
|
||||
if (token == maticAddr) {
|
||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||
to.call{value: _amt}("");
|
||||
} else {
|
||||
IERC20 tokenContract = IERC20(token);
|
||||
_amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt;
|
||||
tokenContract.safeTransfer(to, _amt);
|
||||
}
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint256,address,uint256,uint256)";
|
||||
_eventParam = abi.encode(token, _amt, to, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2Basic is BasicResolver {
|
||||
string constant public name = "Basic-v1";
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
pragma solidity ^0.7.0;
|
||||
|
||||
/**
|
||||
* @title Paraswap.
|
||||
* @dev DEX Aggregator.
|
||||
*/
|
||||
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { Stores } from "../../common/stores.sol";
|
||||
import { Helpers } from "./helpers.sol";
|
||||
|
@ -8,11 +13,11 @@ abstract contract ParaswapResolver is Helpers {
|
|||
/**
|
||||
* @dev Sell ETH/ERC20_Token using ParaSwap.
|
||||
* @notice Swap tokens from exchanges like kyber, 0x etc, with calculation done off-chain.
|
||||
* @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param buyAddr The address of the token to buy.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAddr The address of the token to sell.(For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||
* @param sellAmt The amount of the token to sell.
|
||||
* @param unitAmt The amount of buyAmt/sellAmt with slippage.
|
||||
* @param callData Data from 1inch API.
|
||||
* @param callData Data from paraswap API.
|
||||
* @param setId ID stores the amount of token brought.
|
||||
*/
|
||||
function swap(
|
||||
|
|
|
@ -278,9 +278,31 @@ const checkName = async (connector) => {
|
|||
}
|
||||
}
|
||||
|
||||
async function checkMain () {
|
||||
const errors = []
|
||||
const checkHeadComments = async (connector) => {
|
||||
try {
|
||||
const errors = []
|
||||
const strs = connector.code.split('\n')
|
||||
let haveTitle = false
|
||||
let haveDev = false
|
||||
for (let index = 0; index < strs.length; index++) {
|
||||
if (!strs[index].includes('{')) {
|
||||
if (strs[index].includes('@title')) haveTitle = true
|
||||
if (strs[index].includes('@dev')) haveDev = true
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!haveTitle) errors.push(`@title missing in ${connector.path}/main.sol`)
|
||||
if (!haveDev) errors.push(`@dev missing in ${connector.path}/main.sol`)
|
||||
return errors
|
||||
} catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
async function checkMain () {
|
||||
try {
|
||||
const errors = []
|
||||
const warnings = []
|
||||
const connectors = await getConnectorsList()
|
||||
for (let index = 0; index < connectors.length; index++) {
|
||||
|
@ -290,28 +312,30 @@ async function checkMain () {
|
|||
const { eventsErrors, eventsWarnings } = await checkEvents(connectors[index])
|
||||
const commentsErrors = await checkComments(connectors[index])
|
||||
const nameErrors = await checkName(connectors[index])
|
||||
const headCommentsErrors = await checkHeadComments(connectors[index])
|
||||
|
||||
errors.push(...forbiddenErrors)
|
||||
errors.push(...eventsErrors)
|
||||
errors.push(...commentsErrors)
|
||||
errors.push(...nameErrors)
|
||||
errors.push(...headCommentsErrors)
|
||||
warnings.push(...eventsWarnings)
|
||||
}
|
||||
if (errors.length) {
|
||||
console.log('\x1b[31m%s\x1b[0m', `Total errors: ${errors.length}`)
|
||||
console.log('\x1b[31m%s\x1b[0m', errors.join('\n'))
|
||||
errors.forEach(error => console.log('\x1b[31m%s\x1b[0m', error))
|
||||
} else {
|
||||
console.log('\x1b[32m%s\x1b[0m', 'No Errors Found')
|
||||
}
|
||||
if (warnings.length) {
|
||||
console.log('\x1b[33m%s\x1b[0m', `Total warnings: ${warnings.length}`)
|
||||
console.log('\x1b[33m%s\x1b[0m', warnings.join('\n'))
|
||||
warnings.forEach(warning => console.log('\x1b[33m%s\x1b[0m', warning))
|
||||
} else {
|
||||
console.log('\x1b[32m%s\x1b[0m', 'No Warnings Found')
|
||||
}
|
||||
if (errors.length) return Promise.reject(errors.join('\n'))
|
||||
} catch (error) {
|
||||
console.error('check execution error:', error)
|
||||
}
|
||||
if (errors.length) throw new Error(errors.join('\n'))
|
||||
}
|
||||
module.exports = checkMain;
|
||||
module.exports = checkMain
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
const checkMain = require('./check');
|
||||
const checkMain = require('./check')
|
||||
|
||||
module.exports = [{
|
||||
name: 'Solidity check',
|
||||
callback: checkMain,
|
||||
}];
|
||||
callback: async () => {
|
||||
try {
|
||||
await checkMain()
|
||||
return 'Check passed!'
|
||||
} catch (error) {
|
||||
throw new Error('Check failed!')
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
|
|
@ -6,4 +6,4 @@ const checkMain = require('./check');
|
|||
} catch (error) {
|
||||
process.exit(1)
|
||||
}
|
||||
})()
|
||||
})()
|
||||
|
|
|
@ -1,54 +1,54 @@
|
|||
const cp = require('child_process');
|
||||
const fetch = require('node-fetch');
|
||||
const cp = require('child_process')
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
const checks = require('./checks');
|
||||
const checks = require('./checks')
|
||||
|
||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
|
||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
|
||||
|
||||
function getCurrentCommitSha() {
|
||||
function getCurrentCommitSha () {
|
||||
return cp
|
||||
.execSync(`git rev-parse HEAD`)
|
||||
.execSync('git rev-parse HEAD')
|
||||
.toString()
|
||||
.trim();
|
||||
.trim()
|
||||
}
|
||||
// The SHA provied by GITHUB_SHA is the merge (PR) commit.
|
||||
// We need to get the current commit sha ourself.
|
||||
const sha = getCurrentCommitSha();
|
||||
const sha = getCurrentCommitSha()
|
||||
|
||||
async function setStatus(context, state, description) {
|
||||
async function setStatus (context, state, description) {
|
||||
return fetch(`https://api.github.com/repos/${owner}/${repo}/statuses/${sha}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
state,
|
||||
description,
|
||||
context,
|
||||
context
|
||||
}),
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
(async () => {
|
||||
console.log(`Starting status checks for commit ${sha}`);
|
||||
console.log(`Starting status checks for commit ${sha}`)
|
||||
|
||||
// Run in parallel
|
||||
await Promise.all(
|
||||
checks.map(async check => {
|
||||
const { name, callback } = check;
|
||||
const { name, callback } = check
|
||||
|
||||
await setStatus(name, 'pending', 'Running check..');
|
||||
await setStatus(name, 'pending', 'Running check..')
|
||||
|
||||
try {
|
||||
const response = await callback();
|
||||
await setStatus(name, 'success', response);
|
||||
const response = await callback()
|
||||
await setStatus(name, 'success', response)
|
||||
} catch (err) {
|
||||
const message = err ? err.message : 'Something went wrong';
|
||||
await setStatus(name, 'failure', message);
|
||||
const message = err ? err.message : 'Something went wrong'
|
||||
await setStatus(name, 'failure', message)
|
||||
}
|
||||
}),
|
||||
);
|
||||
})
|
||||
)
|
||||
|
||||
console.log('Finished status checks');
|
||||
})();
|
||||
console.log('Finished status checks')
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue
Block a user