chore: consolidate functions to deposit and swap

This commit is contained in:
Dimitri 2022-01-02 15:28:40 +07:00
parent b8fc97f6c0
commit 531ac64ba5
9 changed files with 111 additions and 254 deletions

View File

@ -1,7 +1,7 @@
pragma solidity ^0.7.6; pragma solidity ^0.7.6;
import { DSMath } from "../common/math.sol"; import { DSMath } from "../../common/math.sol";
import { Basic } from "../common/basic.sol"; import { Basic } from "../../common/basic.sol";
abstract contract Helpers is DSMath, Basic { abstract contract Helpers is DSMath, Basic {
address internal constant mUsdToken = address internal constant mUsdToken =

View File

@ -8,7 +8,7 @@ pragma solidity ^0.7.6;
import { Helpers } from "./helpers.sol"; import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
import { IMasset, ISavingsContractV2, IBoostedSavingsVault, IFeederPool } from "./interface.sol"; import { IMasset, ISavingsContractV2, IBoostedSavingsVault, IFeederPool } from "./interface.sol";
import { TokenInterface } from "../common/interfaces.sol"; import { TokenInterface } from "../../common/interfaces.sol";
abstract contract mStableResolver is Events, Helpers { abstract contract mStableResolver is Events, Helpers {
// //
@ -17,51 +17,38 @@ abstract contract mStableResolver is Events, Helpers {
****************************************/ ****************************************/
/** /**
* @dev Deposit to Save via mUSD * @dev Deposit to Save via mUSD or bAsset
* @notice Deposits token supported by mStable to Save * @notice Deposits token supported by mStable to Save
* @param _token Address of token to deposit * @param _token Address of token to deposit
* @param _amount Amount of token to deposit * @param _amount Amount of token to deposit
* @param _minOut Minimum amount of token to mint/deposit, equal to _amount if mUSD
* @return _eventName Event name * @return _eventName Event name
* @return _eventParam Event parameters * @return _eventParam Event parameters
*/ */
function deposit(address _token, uint256 _amount) function deposit(
external
returns (string memory _eventName, bytes memory _eventParam)
{
return _deposit(_token, _amount, imUsdToken);
}
/**
* @dev Deposit to Save via bAsset
* @notice Deposits token, requires _minOut for minting
* @param _token Address of token to deposit
* @param _amount Amount of token to deposit
* @param _minOut Minimum amount of token to mint
* @return _eventName Event name
* @return _eventParam Event parameters
*/
function depositViaMint(
address _token, address _token,
uint256 _amount, uint256 _amount,
uint256 _minOut uint256 _minOut
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
// //
require( uint256 mintedAmount = _amount;
IMasset(mUsdToken).bAssetIndexes(_token) != 0,
"Token not a bAsset"
);
// Check if needs to be minted first
if (IMasset(mUsdToken).bAssetIndexes(_token) != 0) {
// mint first
approve(TokenInterface(_token), mUsdToken, _amount); approve(TokenInterface(_token), mUsdToken, _amount);
uint256 mintedAmount = IMasset(mUsdToken).mint( mintedAmount = IMasset(mUsdToken).mint(
_token, _token,
_amount, _amount,
_minOut, _minOut,
address(this) address(this)
); );
} else {
require(mintedAmount >= _minOut, "mintedAmount < _minOut");
}
return _deposit(_token, mintedAmount, mUsdToken); return _deposit(_token, mintedAmount, imUsdToken);
} }
/** /**
@ -100,54 +87,36 @@ abstract contract mStableResolver is Events, Helpers {
} }
/** /**
* @dev Withdraw from Save to mUSD * @dev Withdraw from Save to mUSD or bAsset
* @notice Withdraws from Save Vault to mUSD * @notice Withdraws from Save Vault to mUSD
* @param _token Address of token to withdraw
* @param _credits Credits to withdraw * @param _credits Credits to withdraw
* @param _minOut Minimum amount of token to withdraw
* @return _eventName Event name * @return _eventName Event name
* @return _eventParam Event parameters * @return _eventParam Event parameters
*/ */
function withdraw(uint256 _credits) function withdraw(
external
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 amountWithdrawn = _withdraw(_credits);
_eventName = "LogWithdraw()";
_eventParam = abi.encode(mUsdToken, amountWithdrawn, imUsdToken);
}
/**
* @dev Withdraw from Save to bAsset
* @notice Withdraws from Save Vault to bAsset
* @param _token bAsset to withdraw to
* @param _credits Credits to withdraw
* @param _minOut Minimum amount of token to mint
* @return _eventName Event name
* @return _eventParam Event parameters
*/
function withdrawViaRedeem(
address _token, address _token,
uint256 _credits, uint256 _credits,
uint256 _minOut uint256 _minOut
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
//
require(
IMasset(mUsdToken).bAssetIndexes(_token) != 0,
"Token not a bAsset"
);
uint256 amountWithdrawn = _withdraw(_credits); uint256 amountWithdrawn = _withdraw(_credits);
uint256 amountRedeemed = IMasset(mUsdToken).redeem(
// Check if needs to be redeemed
if (IMasset(mUsdToken).bAssetIndexes(_token) != 0) {
amountWithdrawn = IMasset(mUsdToken).redeem(
_token, _token,
amountWithdrawn, amountWithdrawn,
_minOut, _minOut,
address(this) address(this)
); );
} else {
require(amountWithdrawn >= _minOut, "amountWithdrawn < _minOut");
}
_eventName = "LogRedeem()"; _eventName = "LogWithdraw()";
_eventParam = abi.encode(mUsdToken, amountRedeemed, _token); _eventParam = abi.encode(mUsdToken, amountWithdrawn, imUsdToken);
} }
/** /**

View File

@ -17,51 +17,38 @@ abstract contract PmStableResolver is Events, Helpers {
****************************************/ ****************************************/
/** /**
* @dev Deposit to Save via mUSD * @dev Deposit to Save via mUSD or bAsset
* @notice Deposits token supported by mStable to Save * @notice Deposits token supported by mStable to Save
* @param _token Address of token to deposit * @param _token Address of token to deposit
* @param _amount Amount of token to deposit * @param _amount Amount of token to deposit
* @param _minOut Minimum amount of token to mint/deposit, equal to _amount if mUSD
* @return _eventName Event name * @return _eventName Event name
* @return _eventParam Event parameters * @return _eventParam Event parameters
*/ */
function deposit(address _token, uint256 _amount) function deposit(
external
returns (string memory _eventName, bytes memory _eventParam)
{
return _deposit(_token, _amount, imUsdToken);
}
/**
* @dev Deposit to Save via bAsset
* @notice Deposits token, requires _minOut for minting
* @param _token Address of token to deposit
* @param _amount Amount of token to deposit
* @param _minOut Minimum amount of token to mint
* @return _eventName Event name
* @return _eventParam Event parameters
*/
function depositViaMint(
address _token, address _token,
uint256 _amount, uint256 _amount,
uint256 _minOut uint256 _minOut
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
// //
require( uint256 mintedAmount = _amount;
IMasset(mUsdToken).bAssetIndexes(_token) != 0,
"Token not a bAsset"
);
// Check if needs to be minted first
if (IMasset(mUsdToken).bAssetIndexes(_token) != 0) {
// mint first
approve(TokenInterface(_token), mUsdToken, _amount); approve(TokenInterface(_token), mUsdToken, _amount);
uint256 mintedAmount = IMasset(mUsdToken).mint( mintedAmount = IMasset(mUsdToken).mint(
_token, _token,
_amount, _amount,
_minOut, _minOut,
address(this) address(this)
); );
} else {
require(mintedAmount >= _minOut, "mintedAmount < _minOut");
}
return _deposit(_token, mintedAmount, mUsdToken); return _deposit(_token, mintedAmount, imUsdToken);
} }
/** /**
@ -100,54 +87,36 @@ abstract contract PmStableResolver is Events, Helpers {
} }
/** /**
* @dev Withdraw from Save to mUSD * @dev Withdraw from Save to mUSD or bAsset
* @notice Withdraws from Save Vault to mUSD * @notice Withdraws from Save Vault to mUSD
* @param _token Address of token to withdraw
* @param _credits Credits to withdraw * @param _credits Credits to withdraw
* @param _minOut Minimum amount of token to withdraw
* @return _eventName Event name * @return _eventName Event name
* @return _eventParam Event parameters * @return _eventParam Event parameters
*/ */
function withdraw(uint256 _credits) function withdraw(
external
returns (string memory _eventName, bytes memory _eventParam)
{
uint256 amountWithdrawn = _withdraw(_credits);
_eventName = "LogWithdraw()";
_eventParam = abi.encode(mUsdToken, amountWithdrawn, imUsdToken);
}
/**
* @dev Withdraw from Save to bAsset
* @notice Withdraws from Save Vault to bAsset
* @param _token bAsset to withdraw to
* @param _credits Credits to withdraw
* @param _minOut Minimum amount of token to mint
* @return _eventName Event name
* @return _eventParam Event parameters
*/
function withdrawViaRedeem(
address _token, address _token,
uint256 _credits, uint256 _credits,
uint256 _minOut uint256 _minOut
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
//
require(
IMasset(mUsdToken).bAssetIndexes(_token) != 0,
"Token not a bAsset"
);
uint256 amountWithdrawn = _withdraw(_credits); uint256 amountWithdrawn = _withdraw(_credits);
uint256 amountRedeemed = IMasset(mUsdToken).redeem(
// Check if needs to be redeemed
if (IMasset(mUsdToken).bAssetIndexes(_token) != 0) {
amountWithdrawn = IMasset(mUsdToken).redeem(
_token, _token,
amountWithdrawn, amountWithdrawn,
_minOut, _minOut,
address(this) address(this)
); );
} else {
require(amountWithdrawn >= _minOut, "amountWithdrawn < _minOut");
}
_eventName = "LogRedeem()"; _eventName = "LogWithdraw()";
_eventParam = abi.encode(mUsdToken, amountRedeemed, _token); _eventParam = abi.encode(mUsdToken, amountWithdrawn, imUsdToken);
} }
/** /**
@ -367,7 +336,6 @@ abstract contract PmStableResolver is Events, Helpers {
returns (uint256 amountWithdrawn) returns (uint256 amountWithdrawn)
{ {
// 1. Withdraw from Vault // 1. Withdraw from Vault
// approve(TokenInterface(imUsdVault), imUsdToken, _credits);
IStakingRewardsWithPlatformToken(imUsdVault).withdraw(_credits); IStakingRewardsWithPlatformToken(imUsdVault).withdraw(_credits);
// 2. Withdraw from Save // 2. Withdraw from Save

View File

@ -118,14 +118,15 @@ describe("MStable", async () => {
}); });
it("Should deposit mUSD to Vault successfully", async () => { it("Should deposit mUSD to Vault successfully", async () => {
const depositAmount = simpleToExactAmount(100); const depositAmount = simpleToExactAmount(100);
const minOut = depositAmount;
await executeAndAssertDeposit("deposit", mUsdToken, depositAmount, dsaWallet0, wallet0); await executeAndAssertDeposit("deposit", mUsdToken, depositAmount, dsaWallet0, wallet0, [minOut]);
}); });
it("Should deposit DAI to Vault successfully (mUSD bAsset)", async () => { it("Should deposit DAI to Vault successfully (mUSD bAsset)", async () => {
const depositAmount = simpleToExactAmount(100); const depositAmount = simpleToExactAmount(100);
const minOut = calcMinOut(depositAmount, 0.02); const minOut = calcMinOut(depositAmount, 0.02);
await executeAndAssertDeposit("depositViaMint", daiToken, depositAmount, dsaWallet0, wallet0, [minOut]); await executeAndAssertDeposit("deposit", daiToken, depositAmount, dsaWallet0, wallet0, [minOut]);
}); });
it("Should deposit alUSD to Vault successfully (via Feeder Pool)", async () => { it("Should deposit alUSD to Vault successfully (via Feeder Pool)", async () => {
const depositAmount = simpleToExactAmount(100); const depositAmount = simpleToExactAmount(100);
@ -136,66 +137,25 @@ describe("MStable", async () => {
}); });
it("Should withdraw from Vault to mUSD", async () => { it("Should withdraw from Vault to mUSD", async () => {
const withdrawAmount = simpleToExactAmount(100); const withdrawAmount = simpleToExactAmount(100);
const minOut = simpleToExactAmount(1);
await executeAndAssertWithdraw("withdraw", mUsdToken, withdrawAmount, dsaWallet0, wallet0, [withdrawAmount]); await executeAndAssertWithdraw("withdraw", mUsdToken, withdrawAmount, dsaWallet0, wallet0, [minOut]);
}); });
it("Should withdraw from Vault to DAI (mUSD bAsset)", async () => { it("Should withdraw from Vault to DAI (mUSD bAsset)", async () => {
const withdrawAmount = simpleToExactAmount(100); const withdrawAmount = simpleToExactAmount(100);
const minOut = simpleToExactAmount(1); const minOut = simpleToExactAmount(1);
const daiBalanceBefore = await daiToken.balanceOf(dsaWallet0.address); await executeAndAssertWithdraw("withdraw", mUsdToken, withdrawAmount, dsaWallet0, wallet0, [minOut]);
console.log("DAI balance before: ", toEther(daiBalanceBefore));
const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore));
const spells = [
{
connector: connectorName,
method: "withdrawViaRedeem",
args: [daiToken.address, withdrawAmount, minOut]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), DEAD_ADDRESS);
const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter));
const daiBalanceAfter = await daiToken.balanceOf(dsaWallet0.address);
console.log("DAI balance after: ", toEther(daiBalanceAfter));
expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount));
expect(daiBalanceAfter).to.gt(daiBalanceBefore);
}); });
it("Should withdraw from Vault to alUSD (via Feeder Pool)", async () => { it("Should withdraw from Vault to alUSD (via Feeder Pool)", async () => {
const withdrawAmount = simpleToExactAmount(100); const withdrawAmount = simpleToExactAmount(100);
const minOut = simpleToExactAmount(1); const minOut = simpleToExactAmount(1);
const path = getToken("alUSD").feederPool;
const alusdBalanceBefore = await alusdToken.balanceOf(dsaWallet0.address); await executeAndAssertWithdraw("withdrawViaSwap", alusdToken, withdrawAmount, dsaWallet0, wallet0, [
console.log("Balance before: ", toEther(alusdBalanceBefore)); minOut,
path
const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address); ]);
console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore));
const spells = [
{
connector: connectorName,
method: "withdrawViaSwap",
args: [alusdToken.address, withdrawAmount, minOut, getToken("alUSD").feederPool]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), DEAD_ADDRESS);
const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter));
const alusdBalanceAfter = await alusdToken.balanceOf(dsaWallet0.address);
console.log("alUSD balance after: ", toEther(alusdBalanceAfter));
expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount));
expect(alusdBalanceAfter).to.gt(alusdBalanceBefore);
}); });
it("Should claim Rewards", async () => { it("Should claim Rewards", async () => {
const mtaBalanceBefore = await mtaToken.balanceOf(dsaWallet0.address); const mtaBalanceBefore = await mtaToken.balanceOf(dsaWallet0.address);

View File

@ -104,14 +104,14 @@ export const executeAndAssertDeposit = async (
export const executeAndAssertWithdraw = async ( export const executeAndAssertWithdraw = async (
method: string, method: string,
tokenFrom: IERC20Minimal, tokenTo: IERC20Minimal,
withdrawAmount: BigNumber, withdrawAmount: BigNumber,
dsaWallet0: Contract, dsaWallet0: Contract,
wallet0: Wallet, wallet0: Wallet,
args: any[] args: any[]
) => { ) => {
const mUsdBalanceBefore = await tokenFrom.balanceOf(dsaWallet0.address); const tokenToBalanceBefore = await tokenTo.balanceOf(dsaWallet0.address);
console.log("Balance before: ", toEther(mUsdBalanceBefore)); console.log("Balance before: ", toEther(tokenToBalanceBefore));
const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address); const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore)); console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore));
@ -120,7 +120,7 @@ export const executeAndAssertWithdraw = async (
{ {
connector: connectorName, connector: connectorName,
method, method,
args args: [tokenTo.address, withdrawAmount, ...(args ? args : [])]
} }
]; ];
@ -129,9 +129,9 @@ export const executeAndAssertWithdraw = async (
const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address); const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter)); console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter));
const mUsdBalanceAfter = await tokenFrom.balanceOf(dsaWallet0.address); const tokenToBalanceAfter = await tokenTo.balanceOf(dsaWallet0.address);
console.log("Balance after: ", toEther(mUsdBalanceAfter)); console.log("Balance after: ", toEther(tokenToBalanceAfter));
expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount)); expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount));
expect(mUsdBalanceAfter).to.gt(mUsdBalanceBefore); expect(tokenToBalanceAfter).to.gt(tokenToBalanceBefore);
}; };

View File

@ -118,14 +118,15 @@ describe("MStable", async () => {
}); });
it("Should deposit mUSD to Vault successfully", async () => { it("Should deposit mUSD to Vault successfully", async () => {
const depositAmount = simpleToExactAmount(100); const depositAmount = simpleToExactAmount(100);
const minOut = depositAmount;
await executeAndAssertDeposit("deposit", mUsdToken, depositAmount, dsaWallet0, wallet0); await executeAndAssertDeposit("deposit", mUsdToken, depositAmount, dsaWallet0, wallet0, [minOut]);
}); });
it("Should deposit DAI to Vault successfully (mUSD bAsset)", async () => { it("Should deposit DAI to Vault successfully (mUSD bAsset)", async () => {
const depositAmount = simpleToExactAmount(100); const depositAmount = simpleToExactAmount(100);
const minOut = calcMinOut(depositAmount, 0.02); const minOut = calcMinOut(depositAmount, 0.02);
await executeAndAssertDeposit("depositViaMint", daiToken, depositAmount, dsaWallet0, wallet0, [minOut]); await executeAndAssertDeposit("deposit", daiToken, depositAmount, dsaWallet0, wallet0, [minOut]);
}); });
it("Should deposit FRAX to Vault successfully (via Feeder Pool)", async () => { it("Should deposit FRAX to Vault successfully (via Feeder Pool)", async () => {
const depositAmount = simpleToExactAmount(100); const depositAmount = simpleToExactAmount(100);
@ -136,66 +137,25 @@ describe("MStable", async () => {
}); });
it("Should withdraw from Vault to mUSD", async () => { it("Should withdraw from Vault to mUSD", async () => {
const withdrawAmount = simpleToExactAmount(100); const withdrawAmount = simpleToExactAmount(100);
const minOut = simpleToExactAmount(1);
await executeAndAssertWithdraw("withdraw", mUsdToken, withdrawAmount, dsaWallet0, wallet0, [withdrawAmount]); await executeAndAssertWithdraw("withdraw", mUsdToken, withdrawAmount, dsaWallet0, wallet0, [minOut]);
}); });
it("Should withdraw from Vault to DAI (mUSD bAsset)", async () => { it("Should withdraw from Vault to DAI (mUSD bAsset)", async () => {
const withdrawAmount = simpleToExactAmount(100); const withdrawAmount = simpleToExactAmount(100);
const minOut = simpleToExactAmount(1); const minOut = simpleToExactAmount(1);
const daiBalanceBefore = await daiToken.balanceOf(dsaWallet0.address); await executeAndAssertWithdraw("withdraw", mUsdToken, withdrawAmount, dsaWallet0, wallet0, [minOut]);
console.log("DAI balance before: ", toEther(daiBalanceBefore));
const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore));
const spells = [
{
connector: connectorName,
method: "withdrawViaRedeem",
args: [daiToken.address, withdrawAmount, minOut]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), DEAD_ADDRESS);
const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter));
const daiBalanceAfter = await daiToken.balanceOf(dsaWallet0.address);
console.log("DAI balance after: ", toEther(daiBalanceAfter));
expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount));
expect(daiBalanceAfter).to.gt(daiBalanceBefore);
}); });
it("Should withdraw from Vault to FRAX (via Feeder Pool)", async () => { it("Should withdraw from Vault to FRAX (via Feeder Pool)", async () => {
const withdrawAmount = simpleToExactAmount(100); const withdrawAmount = simpleToExactAmount(100);
const minOut = simpleToExactAmount(1); const minOut = simpleToExactAmount(1);
const path = getToken("FRAX").feederPool;
const fraxBalanceBefore = await fraxToken.balanceOf(dsaWallet0.address); await executeAndAssertWithdraw("withdrawViaSwap", fraxToken, withdrawAmount, dsaWallet0, wallet0, [
console.log("FRAX balance before: ", toEther(fraxBalanceBefore)); minOut,
path
const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address); ]);
console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore));
const spells = [
{
connector: connectorName,
method: "withdrawViaSwap",
args: [fraxToken.address, withdrawAmount, minOut, getToken("FRAX").feederPool]
}
];
const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), DEAD_ADDRESS);
const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter));
const fraxBalanceAfter = await fraxToken.balanceOf(dsaWallet0.address);
console.log("FRAX balance after: ", toEther(fraxBalanceAfter));
expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount));
expect(fraxBalanceAfter).to.gt(fraxBalanceBefore);
}); });
it("Should claim Rewards", async () => { it("Should claim Rewards", async () => {
const mtaBalanceBefore = await mtaToken.balanceOf(dsaWallet0.address); const mtaBalanceBefore = await mtaToken.balanceOf(dsaWallet0.address);

View File

@ -104,14 +104,14 @@ export const executeAndAssertDeposit = async (
export const executeAndAssertWithdraw = async ( export const executeAndAssertWithdraw = async (
method: string, method: string,
tokenFrom: IERC20Minimal, tokenTo: IERC20Minimal,
withdrawAmount: BigNumber, withdrawAmount: BigNumber,
dsaWallet0: Contract, dsaWallet0: Contract,
wallet0: Wallet, wallet0: Wallet,
args: any[] args: any[]
) => { ) => {
const mUsdBalanceBefore = await tokenFrom.balanceOf(dsaWallet0.address); const tokenToBalanceBefore = await tokenTo.balanceOf(dsaWallet0.address);
console.log("Balance before: ", toEther(mUsdBalanceBefore)); console.log("Balance before: ", toEther(tokenToBalanceBefore));
const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address); const imUsdVaultBalanceBefore = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore)); console.log("imUSD Vault balance before: ", toEther(imUsdVaultBalanceBefore));
@ -120,7 +120,7 @@ export const executeAndAssertWithdraw = async (
{ {
connector: connectorName, connector: connectorName,
method, method,
args args: [tokenTo.address, withdrawAmount, ...(args ? args : [])]
} }
]; ];
@ -129,9 +129,9 @@ export const executeAndAssertWithdraw = async (
const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address); const imUsdVaultBalanceAfter = await imUsdVault.balanceOf(dsaWallet0.address);
console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter)); console.log("imUSD Vault balance after: ", toEther(imUsdVaultBalanceAfter));
const mUsdBalanceAfter = await tokenFrom.balanceOf(dsaWallet0.address); const tokenToBalanceAfter = await tokenTo.balanceOf(dsaWallet0.address);
console.log("Balance after: ", toEther(mUsdBalanceAfter)); console.log("Balance after: ", toEther(tokenToBalanceAfter));
expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount)); expect(imUsdVaultBalanceAfter).to.be.eq(imUsdVaultBalanceBefore.sub(withdrawAmount));
expect(mUsdBalanceAfter).to.gt(mUsdBalanceBefore); expect(tokenToBalanceAfter).to.gt(tokenToBalanceBefore);
}; };