mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #251 from Instadapp/Euler-connector-updates
Euler connector updates
This commit is contained in:
commit
687f49d65b
|
@ -52,8 +52,8 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogETransfer(
|
event LogETransfer(
|
||||||
uint256 subAccount1,
|
uint256 subAccountFrom,
|
||||||
uint256 subAccount2,
|
uint256 subAccountTo,
|
||||||
address token,
|
address token,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
|
@ -61,31 +61,20 @@ contract Events {
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogDTransfer(
|
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 subAccountFrom,
|
||||||
uint256 subAccountTo,
|
uint256 subAccountTo,
|
||||||
address buyAddr,
|
address token,
|
||||||
address sellAddr,
|
uint256 amount,
|
||||||
uint256 sellAmt,
|
uint256 getId,
|
||||||
uint256 unitAmt,
|
uint256 setId
|
||||||
bytes callData
|
);
|
||||||
|
|
||||||
|
event LogApproveSpenderDebt(
|
||||||
|
uint256 subAccountId,
|
||||||
|
address debtSender,
|
||||||
|
address token,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogEnterMarket(uint256 subAccountId, address[] newMarkets);
|
event LogEnterMarket(uint256 subAccountId, address[] newMarkets);
|
||||||
|
|
|
@ -10,43 +10,11 @@ contract Helpers is Basic, Events {
|
||||||
0x27182842E098f60e3D576794A5bFFb0777E025d3;
|
0x27182842E098f60e3D576794A5bFFb0777E025d3;
|
||||||
IEulerMarkets internal constant markets =
|
IEulerMarkets internal constant markets =
|
||||||
IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3);
|
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
|
* @dev Get sub account address
|
||||||
* @param primary address of user
|
* @param primary address of user
|
||||||
* @param subAccountId subAccount ID
|
* @param subAccountId sub-account id
|
||||||
*/
|
*/
|
||||||
function getSubAccount(address primary, uint256 subAccountId)
|
function getSubAccount(address primary, uint256 subAccountId)
|
||||||
public
|
public
|
||||||
|
@ -57,12 +25,26 @@ contract Helpers is Basic, Events {
|
||||||
return address(uint160(primary) ^ uint160(subAccountId));
|
return address(uint160(primary) ^ uint160(subAccountId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Get Enetered markets for a user
|
||||||
|
* @param subAccountId sub-account id
|
||||||
|
*/
|
||||||
|
function getEnteredMarkets(uint256 subAccountId)
|
||||||
|
internal
|
||||||
|
view
|
||||||
|
returns (address[] memory enteredMarkets)
|
||||||
|
{
|
||||||
|
address _subAccountAddress = getSubAccount(address(this), subAccountId);
|
||||||
|
enteredMarkets = markets.getEnteredMarkets(_subAccountAddress);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Check if the market is entered
|
* @dev Check if the market is entered
|
||||||
|
* @param subAccountId sub-account id
|
||||||
* @param token token address
|
* @param token token address
|
||||||
*/
|
*/
|
||||||
function checkIfEnteredMarket(address token) public view returns (bool) {
|
function checkIfEnteredMarket(uint256 subAccountId, address token) public view returns (bool) {
|
||||||
address[] memory enteredMarkets = getEnteredMarkets();
|
address[] memory enteredMarkets = getEnteredMarkets(subAccountId);
|
||||||
uint256 length = enteredMarkets.length;
|
uint256 length = enteredMarkets.length;
|
||||||
|
|
||||||
for (uint256 i = 0; i < length; i++) {
|
for (uint256 i = 0; i < length; i++) {
|
||||||
|
|
|
@ -36,7 +36,9 @@ interface IEulerEToken {
|
||||||
|
|
||||||
function balanceOf(address account) external view returns (uint256);
|
function balanceOf(address account) external view returns (uint256);
|
||||||
|
|
||||||
function transfer(address to, uint256 amount) external returns (bool);
|
function balanceOfUnderlying(address account) external view returns (uint);
|
||||||
|
|
||||||
|
function transferFrom(address from, address to, uint amount) external returns (bool);
|
||||||
|
|
||||||
function approve(address spender, uint256 amount) external returns (bool);
|
function approve(address spender, uint256 amount) external returns (bool);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ interface IEulerDToken {
|
||||||
|
|
||||||
function balanceOf(address account) external view returns (uint256);
|
function balanceOf(address account) external view returns (uint256);
|
||||||
|
|
||||||
function transfer(address to, uint256 amount) external returns (bool);
|
function transferFrom(address from, address to, uint amount) external returns (bool);
|
||||||
|
|
||||||
function approveDebt(
|
function approveDebt(
|
||||||
uint256 subAccountId,
|
uint256 subAccountId,
|
||||||
|
@ -63,17 +65,3 @@ interface IEulerDToken {
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) external returns (bool);
|
) 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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -95,7 +95,9 @@ abstract contract Euler is Helpers {
|
||||||
|
|
||||||
TokenInterface tokenContract = TokenInterface(_token);
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
_amt = _amt == uint256(-1) ? eToken.balanceOf(address(this)) : _amt;
|
|
||||||
|
address _subAccount = getSubAccount(address(this), subAccount);
|
||||||
|
_amt = _amt == uint256(-1) ? eToken.balanceOfUnderlying(_subAccount) : _amt;
|
||||||
uint256 initialBal = tokenContract.balanceOf(address(this));
|
uint256 initialBal = tokenContract.balanceOf(address(this));
|
||||||
|
|
||||||
eToken.withdraw(subAccount, _amt);
|
eToken.withdraw(subAccount, _amt);
|
||||||
|
@ -178,7 +180,8 @@ abstract contract Euler is Helpers {
|
||||||
markets.underlyingToDToken(_token)
|
markets.underlyingToDToken(_token)
|
||||||
);
|
);
|
||||||
|
|
||||||
_amt = _amt == uint256(-1) ? borrowedDToken.balanceOf(address(this)) : _amt;
|
address _subAccount = getSubAccount(address(this), subAccount);
|
||||||
|
_amt = _amt == uint256(-1) ? borrowedDToken.balanceOf(_subAccount) : _amt;
|
||||||
if (isEth) {
|
if (isEth) {
|
||||||
convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
}
|
}
|
||||||
|
@ -256,9 +259,15 @@ abstract contract Euler is Helpers {
|
||||||
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
||||||
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
|
||||||
_amt = _amt == type(uint256).max
|
address _subAccount = getSubAccount(address(this), subAccount);
|
||||||
? dToken.balanceOf(address(this))
|
|
||||||
: _amt;
|
if(_amt == uint256(-1)) {
|
||||||
|
|
||||||
|
uint256 _eTokenBalance = eToken.balanceOfUnderlying(_subAccount);
|
||||||
|
uint256 _dTokenBalance = dToken.balanceOf(_subAccount);
|
||||||
|
|
||||||
|
_amt = _eTokenBalance <= _dTokenBalance ? _eTokenBalance : _dTokenBalance;
|
||||||
|
}
|
||||||
|
|
||||||
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
|
@ -299,15 +308,16 @@ abstract contract Euler is Helpers {
|
||||||
|
|
||||||
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
|
||||||
|
|
||||||
|
address _subAccountFromAddr = getSubAccount(address(this), subAccountFrom);
|
||||||
|
address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
|
||||||
|
|
||||||
_amt = _amt == uint256(-1)
|
_amt = _amt == uint256(-1)
|
||||||
? eToken.balanceOf(address(this))
|
? eToken.balanceOf(_subAccountFromAddr)
|
||||||
: _amt;
|
: _amt;
|
||||||
|
|
||||||
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
|
eToken.transferFrom(_subAccountFromAddr, _subAccountToAddr, _amt);
|
||||||
|
|
||||||
eToken.transfer(_subAccountToAddr, _amt);
|
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
@ -351,14 +361,16 @@ abstract contract Euler is Helpers {
|
||||||
|
|
||||||
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
||||||
|
|
||||||
|
address _subAccountFromAddr = getSubAccount(address(this), subAccountFrom);
|
||||||
|
address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
|
||||||
|
|
||||||
_amt = _amt == uint256(-1)
|
_amt = _amt == uint256(-1)
|
||||||
? dToken.balanceOf(address(this))
|
? dToken.balanceOf(_subAccountFromAddr)
|
||||||
: _amt;
|
: _amt;
|
||||||
|
|
||||||
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
|
||||||
|
|
||||||
address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
|
dToken.transferFrom(_subAccountFromAddr, _subAccountToAddr, _amt);
|
||||||
dToken.transfer(_subAccountToAddr, amt);
|
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
@ -374,105 +386,37 @@ abstract contract Euler is Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Approve debt.
|
* @dev Approve Spender's debt.
|
||||||
* @notice Approves receiver to take debt.
|
* @notice Approve sender to send debt.
|
||||||
* @param subAccountId Subaccount number
|
* @param subAccountId Subaccount id of receiver
|
||||||
* @param debtReceiver Address of receiver
|
* @param debtSender Address of sender
|
||||||
* @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param token The address of the token.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param amt The amount of the token to mint.
|
* @param amt The amount of the token.
|
||||||
* @param getId ID to retrieve amt.
|
|
||||||
* @param setId ID stores the amount of tokens deposited.
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
*/
|
*/
|
||||||
function approveDebt(
|
function approveSpenderDebt(
|
||||||
uint256 subAccountId,
|
uint256 subAccountId,
|
||||||
address debtReceiver,
|
address debtSender,
|
||||||
address token,
|
address token,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
uint256 setId
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
payable
|
payable
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
uint256 _amt = getUint(getId, amt);
|
|
||||||
|
|
||||||
bool isEth = token == ethAddr;
|
bool isEth = token == ethAddr;
|
||||||
address _token = isEth ? wethAddr : token;
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
|
||||||
|
|
||||||
dToken.approveDebt(subAccountId, debtReceiver, _amt);
|
dToken.approveDebt(subAccountId, debtSender, amt);
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, amt);
|
||||||
|
|
||||||
_eventName = "LogApproveDebt(uint256,address,address,uint256)";
|
_eventName = "LogApproveSpenderDebt(uint256,address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(subAccountId, debtReceiver, token, _amt);
|
_eventParam = abi.encode(subAccountId, debtSender, token, amt, setId);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,6 +34,13 @@ export const tokens = {
|
||||||
name: "Wrapped Ether",
|
name: "Wrapped Ether",
|
||||||
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
decimals: 18
|
decimals: 18
|
||||||
|
},
|
||||||
|
ens: {
|
||||||
|
type: "token",
|
||||||
|
symbol: "ENS",
|
||||||
|
name: "Etherem Name Services",
|
||||||
|
address: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72",
|
||||||
|
decimals: 18
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,6 @@ import { tokens } from "../../../scripts/tests/mainnet/tokens";
|
||||||
const { ethers } = hre;
|
const { ethers } = hre;
|
||||||
import type { Signer, Contract } from "ethers";
|
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 USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
|
||||||
const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0'
|
const ACC_USDC = '0xe78388b4ce79068e89bf8aa7f218ef6b9ab0e9d0'
|
||||||
const Usdc = parseUnits('5000', 6)
|
const Usdc = parseUnits('5000', 6)
|
||||||
|
@ -33,6 +24,21 @@ describe("Euler", function () {
|
||||||
const ACC_WETH = '0x05547D4e1A2191B91510Ea7fA8555a2788C70030'
|
const ACC_WETH = '0x05547D4e1A2191B91510Ea7fA8555a2788C70030'
|
||||||
const Weth = parseUnits('50', 18)
|
const Weth = parseUnits('50', 18)
|
||||||
|
|
||||||
|
const token_usdc = new ethers.Contract(
|
||||||
|
USDC,
|
||||||
|
IERC20__factory.abi,
|
||||||
|
ethers.provider,
|
||||||
|
)
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await hre.network.provider.request({
|
await hre.network.provider.request({
|
||||||
method: "hardhat_reset",
|
method: "hardhat_reset",
|
||||||
|
@ -84,11 +90,6 @@ describe("Euler", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Deposit USDC into DSA wallet", async function () {
|
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({
|
await hre.network.provider.request({
|
||||||
method: 'hardhat_impersonateAccount',
|
method: 'hardhat_impersonateAccount',
|
||||||
|
@ -171,7 +172,7 @@ describe("Euler", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "deposit",
|
method: "deposit",
|
||||||
args: ["0", tokens.usdc.address, "10000000", "true", "0", "0"],
|
args: ["0", tokens.usdc.address, "10000000", "true", "0", "0"], // 10 USDC
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -181,12 +182,13 @@ describe("Euler", function () {
|
||||||
|
|
||||||
await tx.wait();
|
await tx.wait();
|
||||||
});
|
});
|
||||||
it("Should borrow DAI into DSA wallet", async function () {
|
|
||||||
|
it("Should deposit in sub-account 1", async function () {
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "borrow",
|
method: "deposit",
|
||||||
args: ["0", tokens.dai.address, "1000000000000000000", "0", "0"],
|
args: ["1", tokens.usdc.address, "10000000", "true", "0", "0"], // 10 USDC
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -199,12 +201,30 @@ describe("Euler", function () {
|
||||||
parseUnits('1', 18)
|
parseUnits('1', 18)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
it("Should repay DAI", async function () {
|
it("Should borrow DAI into DSA wallet sub-account 0", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "borrow",
|
||||||
|
args: ["0", tokens.dai.address, "1000000000000000000", "0", "0"], // 1 DAI
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
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 sub-account 0", async function () {
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "repay",
|
method: "repay",
|
||||||
args: ["0", tokens.dai.address, "1000000000000000", "0", "0"],
|
args: ["0", tokens.dai.address, "500000000000000000", "0", "0"], // 0.5 DAI
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -218,12 +238,49 @@ describe("Euler", function () {
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should withdraw USDC into DSA wallet", async function () {
|
it("Should withdraw USDC into DSA wallet from sub-account 0", async function () {
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "withdraw",
|
method: "withdraw",
|
||||||
args: ["0", tokens.usdc.address, "2000000", "0", "0"],
|
args: ["0", tokens.usdc.address, "2000000", "0", "0"], // 2 USDC
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
expect(await token_usdc.connect(masterSigner).balanceOf(dsaWallet0.address)).to.be.gte(
|
||||||
|
parseUnits('2', 6)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should borrow ENS into DSA wallet sub-account 1", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "borrow",
|
||||||
|
args: ["1", tokens.ens.address, "100000000000000", "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 withdraw USDC from sub-account 1", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "withdraw",
|
||||||
|
args: ["1", tokens.usdc.address, "20000", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -234,12 +291,12 @@ describe("Euler", function () {
|
||||||
await tx.wait();
|
await tx.wait();
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should eTransfer to subAccount 2", async function () {
|
it("Should eTransfer from subAccount 0 to sub account 2", async function () {
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "eTransfer",
|
method: "eTransfer",
|
||||||
args: ["0", "1", tokens.usdc.address, "1000000", "0", "0"],
|
args: ["0", "2", tokens.usdc.address, "2000000", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -250,26 +307,97 @@ describe("Euler", function () {
|
||||||
await tx.wait();
|
await tx.wait();
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should dTransfer to subAccount 2", async function () {
|
it("Should eTransfer from subAccount 1 to sub account 2", async function () {
|
||||||
const spell = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "deposit",
|
method: "eTransfer",
|
||||||
args: ["1", tokens.usdc.address, "10000000", "true", "0", "0"],
|
args: ["1", "2", tokens.usdc.address, "10000", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const txn = await dsaWallet0
|
const tx = await dsaWallet0
|
||||||
.connect(wallet0)
|
.connect(wallet0)
|
||||||
.cast(...encodeSpells(spell), wallet1.getAddress());
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
await txn.wait();
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should eTransfer from subAccount 2 to sub account 0", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "eTransfer",
|
||||||
|
args: ["2", "0", tokens.usdc.address, "10000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should deposit in sub-account 2", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "deposit",
|
||||||
|
args: ["2", tokens.usdc.address, "10000000", "true", "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 dTransfer from subAccount 0 to sub account 2", async function () {
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "dTransfer",
|
||||||
|
args: ["0", "2", tokens.dai.address, "50000000000000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should dTransfer from subAccount 1 to sub account 2", async function () {
|
||||||
|
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "dTransfer",
|
method: "dTransfer",
|
||||||
args: ["0", "1", tokens.dai.address, "100000000000000000", "0", "0"],
|
args: ["1", "2", tokens.ens.address, "100000", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should dTransfer from sub account 2 to subAccount 0", async function () {
|
||||||
|
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "dTransfer",
|
||||||
|
args: ["2", "0", tokens.dai.address, "5000000000000", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -284,8 +412,8 @@ describe("Euler", function () {
|
||||||
const spell = [
|
const spell = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "approveDebt",
|
method: "approveSpenderDebt",
|
||||||
args: ["0", "0x9F60699cE23f1Ab86Ec3e095b477Ff79d4f409AD", tokens.dai.address, "10000000", "0", "0"],
|
args: ["0", "0x85c2ac24a8BD9Ff6E2Ef6cf76C198E36550f41D7", tokens.dai.address, "10000000", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -328,13 +456,13 @@ describe("Euler", function () {
|
||||||
await txn.wait();
|
await txn.wait();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should mint", async function () {
|
it("Should mint in sub-account 3", async function () {
|
||||||
|
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "deposit",
|
method: "deposit",
|
||||||
args: ["2", tokens.weth.address, "1000000000000000000", "true", "0", "0"],
|
args: ["3", tokens.dai.address, "1000000000000000000", "true", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -348,7 +476,7 @@ describe("Euler", function () {
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "mint",
|
method: "mint",
|
||||||
args: ["2", tokens.weth.address, "100000000", "0", "0"],
|
args: ["3", tokens.weth.address, "100000000", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -359,12 +487,44 @@ describe("Euler", function () {
|
||||||
await txn.wait();
|
await txn.wait();
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Should burn", async function () {
|
it("Should burn in sub account 3", async function () {
|
||||||
const spell = [
|
const spell = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "burn",
|
method: "burn",
|
||||||
args: ["2", tokens.weth.address, "10000000", "0", "0"],
|
args: ["3", tokens.weth.address, "115792089237316195423570985008687907853269984665640564039457584007913129639935", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const txn = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spell), wallet1.getAddress());
|
||||||
|
|
||||||
|
await txn.wait();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should deposit in sub account 4", async function () {
|
||||||
|
|
||||||
|
const spells = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "deposit",
|
||||||
|
args: ["4", tokens.weth.address, "1000000000000000000", "true", "0", "0"],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const tx = await dsaWallet0
|
||||||
|
.connect(wallet0)
|
||||||
|
.cast(...encodeSpells(spells), wallet1.getAddress());
|
||||||
|
|
||||||
|
await tx.wait();
|
||||||
|
})
|
||||||
|
it("Should withdraw from sub account 4", async function () {
|
||||||
|
const spell = [
|
||||||
|
{
|
||||||
|
connector: connectorName,
|
||||||
|
method: "withdraw",
|
||||||
|
args: ["4", tokens.weth.address, "115792089237316195423570985008687907853269984665640564039457584007913129639935", "0", "0"],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user