mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
commit
b6e873f006
94
contracts/mainnet/connectors/euler/events.sol
Normal file
94
contracts/mainnet/connectors/euler/events.sol
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogDeposit(
|
||||||
|
uint256 subaccount,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
bool enableCollateral,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdraw(
|
||||||
|
uint256 subaccount,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogBorrow(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogRepay(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogMint(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogBurn(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogETransfer(
|
||||||
|
uint256 subAccount1,
|
||||||
|
uint256 subAccount2,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogDTransfer(
|
||||||
|
uint256 subAccount1,
|
||||||
|
uint256 subAccount2,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogApproveDebt(
|
||||||
|
uint256 subAccountId,
|
||||||
|
address debtReceiver,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogSwap(
|
||||||
|
uint256 subAccountFrom,
|
||||||
|
uint256 subAccountTo,
|
||||||
|
address buyAddr,
|
||||||
|
address sellAddr,
|
||||||
|
uint256 sellAmt,
|
||||||
|
uint256 unitAmt,
|
||||||
|
bytes callData
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogEnterMarket(uint256 subAccountId, address[] newMarkets);
|
||||||
|
|
||||||
|
event LogExitMarket(uint256 subAccountId, address oldMarket);
|
||||||
|
}
|
75
contracts/mainnet/connectors/euler/helpers.sol
Normal file
75
contracts/mainnet/connectors/euler/helpers.sol
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
import "./interface.sol";
|
||||||
|
import "./events.sol";
|
||||||
|
import { Basic } from "../../common/basic.sol";
|
||||||
|
|
||||||
|
contract Helpers is Basic, Events {
|
||||||
|
|
||||||
|
address internal constant EULER_MAINNET =
|
||||||
|
0x27182842E098f60e3D576794A5bFFb0777E025d3;
|
||||||
|
IEulerMarkets internal constant markets =
|
||||||
|
IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3);
|
||||||
|
IEulerSwap internal constant swapExec =
|
||||||
|
IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341);
|
||||||
|
|
||||||
|
struct swapHelper {
|
||||||
|
address _sellAddr;
|
||||||
|
address _buyAddr;
|
||||||
|
uint256 _buyDec;
|
||||||
|
uint256 _sellDec;
|
||||||
|
uint256 _sellAmt18;
|
||||||
|
uint256 _slippageAmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct swapParams {
|
||||||
|
uint256 subAccountFrom;
|
||||||
|
uint256 subAccountTo;
|
||||||
|
address buyAddr;
|
||||||
|
address sellAddr;
|
||||||
|
uint256 sellAmt;
|
||||||
|
uint256 unitAmt;
|
||||||
|
bytes callData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Get Enetered markets for a user
|
||||||
|
*/
|
||||||
|
function getEnteredMarkets()
|
||||||
|
internal
|
||||||
|
view
|
||||||
|
returns (address[] memory enteredMarkets)
|
||||||
|
{
|
||||||
|
enteredMarkets = markets.getEnteredMarkets(address(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Get sub account address
|
||||||
|
* @param primary address of user
|
||||||
|
* @param subAccountId subAccount ID
|
||||||
|
*/
|
||||||
|
function getSubAccount(address primary, uint256 subAccountId)
|
||||||
|
public
|
||||||
|
pure
|
||||||
|
returns (address)
|
||||||
|
{
|
||||||
|
require(subAccountId < 256, "sub-account-id-too-big");
|
||||||
|
return address(uint160(primary) ^ uint160(subAccountId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Check if the market is entered
|
||||||
|
* @param token token address
|
||||||
|
*/
|
||||||
|
function checkIfEnteredMarket(address token) public view returns (bool) {
|
||||||
|
address[] memory enteredMarkets = getEnteredMarkets();
|
||||||
|
uint256 length = enteredMarkets.length;
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < length; i++) {
|
||||||
|
if (enteredMarkets[i] == token) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
79
contracts/mainnet/connectors/euler/interface.sol
Normal file
79
contracts/mainnet/connectors/euler/interface.sol
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
interface IEulerMarkets {
|
||||||
|
function enterMarket(uint256 subAccountId, address newMarket) external;
|
||||||
|
|
||||||
|
function getEnteredMarkets(address account)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (address[] memory);
|
||||||
|
|
||||||
|
function exitMarket(uint256 subAccountId, address oldMarket) external;
|
||||||
|
|
||||||
|
function underlyingToEToken(address underlying)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (address);
|
||||||
|
|
||||||
|
function underlyingToDToken(address underlying)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (address);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IEulerEToken {
|
||||||
|
function deposit(uint256 subAccountId, uint256 amount) external;
|
||||||
|
|
||||||
|
function withdraw(uint256 subAccountId, uint256 amount) external;
|
||||||
|
|
||||||
|
function decimals() external view returns (uint8);
|
||||||
|
|
||||||
|
function mint(uint256 subAccountId, uint256 amount) external;
|
||||||
|
|
||||||
|
function burn(uint256 subAccountId, uint256 amount) external;
|
||||||
|
|
||||||
|
function balanceOf(address account) external view returns (uint256);
|
||||||
|
|
||||||
|
function transfer(address to, uint256 amount) external returns (bool);
|
||||||
|
|
||||||
|
function approve(address spender, uint256 amount) external returns (bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IEulerDToken {
|
||||||
|
function underlyingToDToken(address underlying)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (address);
|
||||||
|
|
||||||
|
function decimals() external view returns (uint8);
|
||||||
|
|
||||||
|
function borrow(uint256 subAccountId, uint256 amount) external;
|
||||||
|
|
||||||
|
function repay(uint256 subAccountId, uint256 amount) external;
|
||||||
|
|
||||||
|
function balanceOf(address account) external view returns (uint256);
|
||||||
|
|
||||||
|
function transfer(address to, uint256 amount) external returns (bool);
|
||||||
|
|
||||||
|
function approveDebt(
|
||||||
|
uint256 subAccountId,
|
||||||
|
address spender,
|
||||||
|
uint256 amount
|
||||||
|
) external returns (bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Swap1InchParams {
|
||||||
|
uint256 subAccountIdIn;
|
||||||
|
uint256 subAccountIdOut;
|
||||||
|
address underlyingIn;
|
||||||
|
address underlyingOut;
|
||||||
|
uint256 amount;
|
||||||
|
uint256 amountOutMinimum;
|
||||||
|
bytes payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IEulerSwap {
|
||||||
|
function swap1Inch(Swap1InchParams memory) external;
|
||||||
|
}
|
522
contracts/mainnet/connectors/euler/main.sol
Normal file
522
contracts/mainnet/connectors/euler/main.sol
Normal file
|
@ -0,0 +1,522 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
import "./helpers.sol";
|
||||||
|
import { Stores } from "../../common/stores.sol";
|
||||||
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
|
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
|
||||||
|
abstract contract Euler is Helpers {
|
||||||
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit ETH/ERC20_Token.
|
||||||
|
* @notice Deposit a token to Euler for lending / collaterization.
|
||||||
|
* @param subAccount Sub-account Id (0 for primary and 1 - 255 for sub-account)
|
||||||
|
* @param token The address of the token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
|
||||||
|
* @param enableCollateral True for entering the market
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function deposit(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
bool enableCollateral,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
|
if (isEth) {
|
||||||
|
_amt = _amt == uint256(-1) ? address(this).balance : _amt;
|
||||||
|
convertEthToWeth(isEth, tokenContract, _amt);
|
||||||
|
} else {
|
||||||
|
_amt = _amt == uint256(-1)
|
||||||
|
? tokenContract.balanceOf(address(this))
|
||||||
|
: _amt;
|
||||||
|
}
|
||||||
|
|
||||||
|
approve(tokenContract, EULER_MAINNET, _amt);
|
||||||
|
|
||||||
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
eToken.deposit(subAccount, _amt);
|
||||||
|
|
||||||
|
if (enableCollateral) {
|
||||||
|
markets.enterMarket(subAccount, _token);
|
||||||
|
}
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogDeposit(uint256,address,uint256,bool,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
subAccount,
|
||||||
|
token,
|
||||||
|
_amt,
|
||||||
|
enableCollateral,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw ETH/ERC20_Token.
|
||||||
|
* @notice Withdraw deposited token and earned interest from Euler
|
||||||
|
* @param subAccount Subaccount number
|
||||||
|
* @param token The address of the token to withdraw.(For ETH: 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(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
_amt = _amt == uint256(-1) ? eToken.balanceOf(address(this)) : _amt;
|
||||||
|
uint256 initialBal = tokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
|
eToken.withdraw(subAccount, _amt);
|
||||||
|
|
||||||
|
uint256 finalBal = tokenContract.balanceOf(address(this));
|
||||||
|
_amt = finalBal - initialBal;
|
||||||
|
|
||||||
|
convertWethToEth(isEth, tokenContract, _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogWithdraw(uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(subAccount, token, _amt, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Borrow ETH/ERC20_Token.
|
||||||
|
* @notice Borrow a token from Euler
|
||||||
|
* @param subAccount Subaccount number
|
||||||
|
* @param token The address of the token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to borrow.
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function borrow(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr ? true : false;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
IEulerDToken borrowedDToken = IEulerDToken(
|
||||||
|
markets.underlyingToDToken(_token)
|
||||||
|
);
|
||||||
|
borrowedDToken.borrow(subAccount, _amt);
|
||||||
|
|
||||||
|
convertWethToEth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogBorrow(uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(subAccount, token, _amt, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Repay ETH/ERC20_Token.
|
||||||
|
* @notice Repay a token from Euler
|
||||||
|
* @param subAccount Subaccount number
|
||||||
|
* @param token The address of the token to repay.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to repay. (For max: `uint256(-1)`)
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function repay(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
IEulerDToken borrowedDToken = IEulerDToken(
|
||||||
|
markets.underlyingToDToken(_token)
|
||||||
|
);
|
||||||
|
|
||||||
|
_amt = _amt == uint256(-1) ? borrowedDToken.balanceOf(address(this)) : _amt;
|
||||||
|
if (isEth) {
|
||||||
|
convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
}
|
||||||
|
|
||||||
|
approve(TokenInterface(_token), EULER_MAINNET, _amt);
|
||||||
|
borrowedDToken.repay(subAccount, _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogRepay(uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(subAccount, token, _amt, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Mint ETH/ERC20_Token.
|
||||||
|
* @notice Mint a token from Euler. Mint creates an equal amount of deposits and debts. (self-borrow)
|
||||||
|
* @param subAccount Subaccount number
|
||||||
|
* @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to mint.
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function mint(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr ? true : false;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
|
||||||
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
|
eToken.mint(subAccount, _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogMint(uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(subAccount, token, _amt, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Burn ETH/ERC20_Token.
|
||||||
|
* @notice Burn a token from Euler. Burn removes equal amount of deposits and debts.
|
||||||
|
* @param subAccount Subaccount number
|
||||||
|
* @param token The address of the token to burn.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to burn.
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function burn(
|
||||||
|
uint256 subAccount,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr ? true : false;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
||||||
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
|
||||||
|
_amt = _amt == type(uint256).max
|
||||||
|
? dToken.balanceOf(address(this))
|
||||||
|
: _amt;
|
||||||
|
|
||||||
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
|
eToken.burn(subAccount, _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogBurn(uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(subAccount, token, _amt, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev ETransfer ETH/ERC20_Token.
|
||||||
|
* @notice ETransfer deposits from one sub-account to another.
|
||||||
|
* @param subAccountFrom subAccount from which deposit is transferred
|
||||||
|
* @param subAccountTo subAccount to which deposit is transferred
|
||||||
|
* @param token The address of the token to etransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to etransfer. (For max: `uint256(-1)`)
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function eTransfer(
|
||||||
|
uint256 subAccountFrom,
|
||||||
|
uint256 subAccountTo,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr ? true : false;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
|
||||||
|
_amt = _amt == uint256(-1)
|
||||||
|
? eToken.balanceOf(address(this))
|
||||||
|
: _amt;
|
||||||
|
|
||||||
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
|
address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
|
||||||
|
|
||||||
|
eToken.transfer(_subAccountToAddr, _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogETransfer(uint256,uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
subAccountFrom,
|
||||||
|
subAccountTo,
|
||||||
|
token,
|
||||||
|
_amt,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev DTransfer ETH/ERC20_Token.
|
||||||
|
* @notice DTransfer deposits from one sub-account to another.
|
||||||
|
* @param subAccountFrom subAccount from which debt is transferred
|
||||||
|
* @param subAccountTo subAccount to which debt is transferred
|
||||||
|
* @param token The address of the token to dtransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to dtransfer. (For max: `uint256(-1)`)
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function dTransfer(
|
||||||
|
uint256 subAccountFrom,
|
||||||
|
uint256 subAccountTo,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr ? true : false;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
||||||
|
|
||||||
|
_amt = _amt == uint256(-1)
|
||||||
|
? dToken.balanceOf(address(this))
|
||||||
|
: _amt;
|
||||||
|
|
||||||
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
|
address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
|
||||||
|
dToken.transfer(_subAccountToAddr, amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogDTransfer(uint256,uint256,address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
subAccountFrom,
|
||||||
|
subAccountTo,
|
||||||
|
token,
|
||||||
|
_amt,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Approve debt.
|
||||||
|
* @notice Approves receiver to take debt.
|
||||||
|
* @param subAccountId Subaccount number
|
||||||
|
* @param debtReceiver Address of receiver
|
||||||
|
* @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
|
* @param amt The amount of the token to mint.
|
||||||
|
* @param getId ID to retrieve amt.
|
||||||
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
*/
|
||||||
|
function approveDebt(
|
||||||
|
uint256 subAccountId,
|
||||||
|
address debtReceiver,
|
||||||
|
address token,
|
||||||
|
uint256 amt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
bool isEth = token == ethAddr;
|
||||||
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
||||||
|
|
||||||
|
dToken.approveDebt(subAccountId, debtReceiver, _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogApproveDebt(uint256,address,address,uint256)";
|
||||||
|
_eventParam = abi.encode(subAccountId, debtReceiver, token, _amt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Swap.
|
||||||
|
* @notice Executes swap.
|
||||||
|
* @param params swapParams struct
|
||||||
|
*/
|
||||||
|
function swap(swapParams memory params)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
swapHelper memory helperParams;
|
||||||
|
|
||||||
|
helperParams._sellAddr = params.sellAddr == ethAddr
|
||||||
|
? wethAddr
|
||||||
|
: params.sellAddr;
|
||||||
|
helperParams._buyAddr = params.sellAddr == ethAddr
|
||||||
|
? wethAddr
|
||||||
|
: params.buyAddr;
|
||||||
|
|
||||||
|
TokenInterface sellToken = TokenInterface(helperParams._sellAddr);
|
||||||
|
TokenInterface buyToken = TokenInterface(helperParams._buyAddr);
|
||||||
|
|
||||||
|
approve(sellToken, address(swapExec), params.sellAmt);
|
||||||
|
|
||||||
|
(helperParams._buyDec, helperParams._sellDec) = getTokensDec(
|
||||||
|
buyToken,
|
||||||
|
sellToken
|
||||||
|
);
|
||||||
|
helperParams._sellAmt18 = convertTo18(
|
||||||
|
helperParams._sellDec,
|
||||||
|
params.sellAmt
|
||||||
|
);
|
||||||
|
helperParams._slippageAmt = convert18ToDec(
|
||||||
|
helperParams._buyDec,
|
||||||
|
wmul(params.unitAmt, helperParams._sellAmt18)
|
||||||
|
);
|
||||||
|
|
||||||
|
Swap1InchParams memory oneInchParams = Swap1InchParams({
|
||||||
|
subAccountIdIn: params.subAccountFrom,
|
||||||
|
subAccountIdOut: params.subAccountTo,
|
||||||
|
underlyingIn: helperParams._sellAddr,
|
||||||
|
underlyingOut: helperParams._buyAddr,
|
||||||
|
amount: params.sellAmt,
|
||||||
|
amountOutMinimum: helperParams._slippageAmt,
|
||||||
|
payload: params.callData
|
||||||
|
});
|
||||||
|
|
||||||
|
swapExec.swap1Inch(oneInchParams);
|
||||||
|
|
||||||
|
if (!checkIfEnteredMarket(helperParams._buyAddr)) {
|
||||||
|
markets.enterMarket(params.subAccountTo, helperParams._buyAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
_eventName = "LogSwap(uint256,uint256,address,address,uint256,uint256,bytes)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
params.subAccountFrom,
|
||||||
|
params.subAccountTo,
|
||||||
|
params.buyAddr,
|
||||||
|
params.sellAddr,
|
||||||
|
params.sellAmt,
|
||||||
|
params.unitAmt,
|
||||||
|
params.callData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Enter Market.
|
||||||
|
* @notice Enter Market.
|
||||||
|
* @param subAccountId Subaccount number
|
||||||
|
* @param tokens Array of new token markets to be entered
|
||||||
|
*/
|
||||||
|
function enterMarket(uint256 subAccountId, address[] memory tokens)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _length = tokens.length;
|
||||||
|
require(_length > 0, "0-markets-not-allowed");
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < _length; i++) {
|
||||||
|
address _token = tokens[i] == ethAddr ? wethAddr : tokens[i];
|
||||||
|
markets.enterMarket(subAccountId, _token);
|
||||||
|
}
|
||||||
|
|
||||||
|
_eventName = "LogEnterMarket(uint256,address[])";
|
||||||
|
_eventParam = abi.encode(subAccountId, tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Exit Market.
|
||||||
|
* @notice Exit Market.
|
||||||
|
* @param subAccountId Subaccount number
|
||||||
|
* @param token token address
|
||||||
|
*/
|
||||||
|
function exitMarket(uint256 subAccountId, address token)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
address _token = token == ethAddr ? wethAddr : token;
|
||||||
|
markets.exitMarket(subAccountId, _token);
|
||||||
|
|
||||||
|
_eventName = "LogExitMarket(uint256,address)";
|
||||||
|
_eventParam = abi.encode(subAccountId, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectV2Euler is Euler {
|
||||||
|
string public constant name = "Euler-v1.0";
|
||||||
|
}
|
|
@ -27,6 +27,13 @@ export const tokens = {
|
||||||
name: "USD Coin",
|
name: "USD Coin",
|
||||||
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
||||||
decimals: 6
|
decimals: 6
|
||||||
|
},
|
||||||
|
weth: {
|
||||||
|
type: "token",
|
||||||
|
symbol: "WETH",
|
||||||
|
name: "Wrapped Ether",
|
||||||
|
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
|
decimals: 18
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
378
test/mainnet/euler/euler.test.ts
Normal file
378
test/mainnet/euler/euler.test.ts
Normal file
|
@ -0,0 +1,378 @@
|
||||||
|
import { expect } from "chai";
|
||||||
|
import hre from "hardhat";
|
||||||
|
import { abis } from "../../../scripts/constant/abis";
|
||||||
|
import { addresses } from "../../../scripts/tests/mainnet/addresses";
|
||||||
|
import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector";
|
||||||
|
import { getMasterSigner } from "../../../scripts/tests/getMasterSigner";
|
||||||
|
import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2";
|
||||||
|
import { ConnectV2Euler__factory, IERC20__factory } from "../../../typechain";
|
||||||
|
import { parseEther, parseUnits } from "@ethersproject/units";
|
||||||
|
import { encodeSpells } from "../../../scripts/tests/encodeSpells";
|
||||||
|
import { tokens } from "../../../scripts/tests/mainnet/tokens";
|
||||||
|
const { ethers } = hre;
|
||||||
|
import type { Signer, Contract } from "ethers";
|
||||||
|
|
||||||
|
describe("Euler", function () {
|
||||||
|
const connectorName = "EULER-TEST-A";
|
||||||
|
let connector: any;
|
||||||
|
|
||||||
|
let wallet0: Signer, wallet1:Signer;
|
||||||
|
let dsaWallet0: any;
|
||||||
|
let instaConnectorsV2: Contract;
|
||||||
|
let masterSigner: Signer;
|
||||||
|
|
||||||
|
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
|
||||||
|
const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0'
|
||||||
|
const Usdc = parseUnits('5000', 6)
|
||||||
|
|
||||||
|
const DAI = '0x6b175474e89094c44da98b954eedeac495271d0f'
|
||||||
|
const ACC_DAI = '0xcd6Eb888e76450eF584E8B51bB73c76ffBa21FF2'
|
||||||
|
const Dai = parseUnits('5000', 18)
|
||||||
|
|
||||||
|
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
|
||||||
|
const ACC_WETH = '0x05547D4e1A2191B91510Ea7fA8555a2788C70030'
|
||||||
|
const Weth = parseUnits('50', 18)
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: "hardhat_reset",
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
forking: {
|
||||||
|
// @ts-ignore
|
||||||
|
jsonRpcUrl: hre.config.networks.hardhat.forking.url,
|
||||||
|
blockNumber: 15078000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
[wallet0, wallet1] = await ethers.getSigners();
|
||||||
|
masterSigner = await getMasterSigner();
|
||||||
|
instaConnectorsV2 = await ethers.getContractAt(
|
||||||
|
abis.core.connectorsV2,
|
||||||
|
addresses.core.connectorsV2
|
||||||
|
);
|
||||||
|
connector = await deployAndEnableConnector({
|
||||||
|
connectorName,
|
||||||
|
contractArtifact: ConnectV2Euler__factory,
|
||||||
|
signer: masterSigner,
|
||||||
|
connectors: instaConnectorsV2,
|
||||||
|
});
|
||||||
|
console.log("Connector address", connector.address);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have contracts deployed", async () => {
|
||||||
|
expect(!!instaConnectorsV2.address).to.be.true;
|
||||||
|
expect(!!connector.address).to.be.true;
|
||||||
|
expect(!!(await masterSigner.getAddress())).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DSA wallet setup", function () {
|
||||||
|
it("Should build DSA v2", async function () {
|
||||||
|
dsaWallet0 = await buildDSAv2(wallet0.getAddress());
|
||||||
|
expect(!!dsaWallet0.address).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Deposit ETH into DSA wallet", async function () {
|
||||||
|
await wallet0.sendTransaction({
|
||||||
|
to: dsaWallet0.address,
|
||||||
|
value: parseEther("10"),
|
||||||
|
});
|
||||||
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
|
||||||
|
parseEther("10")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Deposit USDC into DSA wallet", async function () {
|
||||||
|
const token_usdc = new ethers.Contract(
|
||||||
|
USDC,
|
||||||
|
IERC20__factory.abi,
|
||||||
|
ethers.provider,
|
||||||
|
)
|
||||||
|
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: 'hardhat_impersonateAccount',
|
||||||
|
params: [ACC_USDC],
|
||||||
|
})
|
||||||
|
|
||||||
|
const signer_usdc = await ethers.getSigner(ACC_USDC)
|
||||||
|
await token_usdc.connect(signer_usdc).transfer(wallet0.getAddress(), Usdc)
|
||||||
|
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: 'hardhat_stopImpersonatingAccount',
|
||||||
|
params: [ACC_USDC],
|
||||||
|
})
|
||||||
|
|
||||||
|
await token_usdc.connect(wallet0).transfer(dsaWallet0.address, Usdc);
|
||||||
|
|
||||||
|
expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(
|
||||||
|
parseUnits('5000', 6)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Deposit DAI into DSA wallet", async function () {
|
||||||
|
const token_dai = new ethers.Contract(
|
||||||
|
DAI,
|
||||||
|
IERC20__factory.abi,
|
||||||
|
ethers.provider,
|
||||||
|
)
|
||||||
|
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: 'hardhat_impersonateAccount',
|
||||||
|
params: [ACC_DAI],
|
||||||
|
})
|
||||||
|
|
||||||
|
const signer_dai = await ethers.getSigner(ACC_DAI)
|
||||||
|
await token_dai.connect(signer_dai).transfer(wallet0.getAddress(), Dai)
|
||||||
|
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: 'hardhat_stopImpersonatingAccount',
|
||||||
|
params: [ACC_DAI],
|
||||||
|
})
|
||||||
|
|
||||||
|
await token_dai.connect(wallet0).transfer(dsaWallet0.address, Dai);
|
||||||
|
|
||||||
|
expect(await token_dai.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(
|
||||||
|
parseUnits('5000', 18)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Deposit WETH into DSA wallet", async function () {
|
||||||
|
const token_weth = new ethers.Contract(
|
||||||
|
WETH,
|
||||||
|
IERC20__factory.abi,
|
||||||
|
ethers.provider,
|
||||||
|
)
|
||||||
|
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: 'hardhat_impersonateAccount',
|
||||||
|
params: [ACC_WETH],
|
||||||
|
})
|
||||||
|
|
||||||
|
const signer_weth = await ethers.getSigner(ACC_WETH)
|
||||||
|
await token_weth.connect(signer_weth).transfer(wallet0.getAddress(), Weth)
|
||||||
|
|
||||||
|
await hre.network.provider.request({
|
||||||
|
method: 'hardhat_stopImpersonatingAccount',
|
||||||
|
params: [ACC_WETH],
|
||||||
|
})
|
||||||
|
|
||||||
|
await token_weth.connect(wallet0).transfer(dsaWallet0.address, Weth);
|
||||||
|
|
||||||
|
expect(await token_weth.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(
|
||||||
|
parseUnits('50', 18)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Main", function () {
|
||||||
|
beforeEach(async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "deposit",
|
||||||
|
args: ["0", tokens.usdc.address, "10000000", "true", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
});
|
||||||
|
it("Should borrow DAI into DSA wallet", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "borrow",
|
||||||
|
args: ["0", tokens.dai.address, "1000000000000000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(
|
||||||
|
parseUnits('1', 18)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
it("Should repay DAI", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "repay",
|
||||||
|
args: ["0", tokens.dai.address, "1000000000000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(
|
||||||
|
parseUnits('5000', 18)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should withdraw USDC into DSA wallet", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "withdraw",
|
||||||
|
args: ["0", tokens.usdc.address, "2000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should eTransfer to subAccount 2", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "eTransfer",
|
||||||
|
args: ["0", "1", tokens.usdc.address, "1000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should dTransfer to subAccount 2", async function () {
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "deposit",
|
||||||
|
args: ["1", tokens.usdc.address, "10000000", "true", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "dTransfer",
|
||||||
|
args: ["0", "1", tokens.dai.address, "100000000000000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should give debt transfer allowance", async function () {
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "approveDebt",
|
||||||
|
args: ["0", "0x9F60699cE23f1Ab86Ec3e095b477Ff79d4f409AD", tokens.dai.address, "10000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should enter the market", async function () {
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "enterMarket",
|
||||||
|
args: ["0", [tokens.weth.address]],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should exit the market", async function () {
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "exitMarket",
|
||||||
|
args: ["0", tokens.weth.address],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should mint", async function () {
|
||||||
|
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "deposit",
|
||||||
|
args: ["2", tokens.weth.address, "1000000000000000000", "true", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "mint",
|
||||||
|
args: ["2", tokens.weth.address, "100000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should burn", async function () {
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "burn",
|
||||||
|
args: ["2", tokens.weth.address, "10000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user