Skip to content

Commit

Permalink
fix: revert changes of mock minting
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf committed Mar 5, 2024
1 parent fef7dc4 commit 959a0c0
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 103 deletions.
10 changes: 4 additions & 6 deletions contracts/mocks/swap/MockParaSwapAugustus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
pragma solidity ^0.8.10;

import {IParaSwapAugustus} from '../../adapters/paraswap/interfaces/IParaSwapAugustus.sol';
import {IFaucet} from '../testnet-helpers/IFaucet.sol';
import {MockParaSwapTokenTransferProxy} from './MockParaSwapTokenTransferProxy.sol';
import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol';
import {MintableERC20} from '@aave/core-v3/contracts/mocks/tokens/MintableERC20.sol';

contract MockParaSwapAugustus is IParaSwapAugustus {
MockParaSwapTokenTransferProxy immutable TOKEN_TRANSFER_PROXY;
IFaucet immutable FAUCET;
bool _expectingSwap;
address _expectedFromToken;
address _expectedToToken;
Expand All @@ -21,9 +20,8 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
uint256 _expectedToAmountMax;
uint256 _expectedToAmountMin;

constructor(address faucetMintable) {
constructor() {
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
FAUCET = IFaucet(faucetMintable);
}

function getTokenTransferProxy() external view override returns (address) {
Expand Down Expand Up @@ -75,7 +73,7 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
);
require(_receivedAmount >= toAmount, 'Received amount of tokens are less than expected');
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), fromAmount);
FAUCET.mint(toToken, address(this), _receivedAmount);
MintableERC20(toToken).mint(_receivedAmount);
IERC20(toToken).transfer(msg.sender, _receivedAmount);
_expectingSwap = false;
return _receivedAmount;
Expand All @@ -96,7 +94,7 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
);
require(_fromAmount <= fromAmount, 'From amount of tokens are higher than expected');
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), _fromAmount);
FAUCET.mint(toToken, address(this), toAmount);
MintableERC20(toToken).mint(toAmount);
IERC20(toToken).transfer(msg.sender, toAmount);
_expectingSwap = false;
return fromAmount;
Expand Down
41 changes: 26 additions & 15 deletions test/helpers/make-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
impersonateAddress,
getEmissionManager,
getFaucet,
MAX_UINT_AMOUNT,
} from '@aave/deploy-v3';
import { deployATokenMock } from '../rewards/helpers/deploy';
import { parseEther } from 'ethers/lib/utils';
Expand Down Expand Up @@ -282,22 +281,34 @@ export async function initializeMakeSuite() {
).address
);

// Increase maximum amount for mints on Faucet for tests
await testEnv.faucetMintable.setMaximumMintAmount(BigNumber.from(10).pow(40)); // 1e40
await testEnv.faucetMintable.mint(
testEnv.aave.address,
rewardsVault.address,
parseEther('60000000000')
// Support direct minting
await waitForTx(
await testEnv.faucetMintable.setProtectedOfChild(
[
testEnv.aave.address,
testEnv.dai.address,
testEnv.usdc.address,
testEnv.rewardToken.address,
],
false
)
);
await testEnv.faucetMintable.mint(
testEnv.rewardToken.address,
rewardsVault.address,
parseEther('200000000')

await waitForTx(
await testEnv.aaveToken
.connect(rewardsVault.signer)
['mint(address,uint256)'](rewardsVault.address, parseEther('60000000000'))
);
await waitForTx(
await testEnv.rewardToken
.connect(rewardsVault.signer)
['mint(address,uint256)'](rewardsVault.address, parseEther('200000000'))
);
await testEnv.faucetMintable.mint(
testEnv.aave.address,
testEnv.stakedTokenStrategy.address,
parseEther('30000000000')

await waitForTx(
await testEnv.aaveToken
.connect(rewardsVault.signer)
.transfer(testEnv.stakedTokenStrategy.address, parseEther('30000000000'))
);
}

Expand Down
66 changes: 32 additions & 34 deletions test/paraswap/paraswapAdapters.liquiditySwap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
let evmSnapshotId: string;

before(async () => {
const { addressesProvider, deployer, faucetMintable } = testEnv;
const { addressesProvider, deployer } = testEnv;

mockAugustus = await new MockParaSwapAugustus__factory(await getFirstSigner()).deploy(
faucetMintable.address
);
mockAugustus = await new MockParaSwapAugustus__factory(await getFirstSigner()).deploy();
mockAugustusRegistry = await new MockParaSwapAugustusRegistry__factory(
await getFirstSigner()
).deploy(mockAugustus.address);
Expand Down Expand Up @@ -95,20 +93,20 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {

describe('executeOperation', () => {
beforeEach(async () => {
const { users, weth, dai, pool, deployer, faucetMintable } = testEnv;
const { users, weth, dai, pool, deployer } = testEnv;
const userAddress = users[0].address;

// Provide liquidity
await faucetMintable.mint(dai.address, deployer.address, parseEther('20000'));
await dai['mint(uint256)'](parseEther('20000'));
await dai.approve(pool.address, parseEther('20000'));
await pool.deposit(dai.address, parseEther('20000'), deployer.address, 0);

await faucetMintable.mint(weth.address, deployer.address, parseEther('10000'));
await weth['mint(uint256)'](parseEther('10000'));
await weth.approve(pool.address, parseEther('10000'));
await pool.deposit(weth.address, parseEther('10000'), deployer.address, 0);

// Make a deposit for user
await faucetMintable.mint(weth.address, deployer.address, parseEther('100'));
await weth['mint(uint256)'](parseEther('100'));
await weth.approve(pool.address, parseEther('100'));
await pool.deposit(weth.address, parseEther('100'), userAddress, 0);
});
Expand Down Expand Up @@ -339,7 +337,7 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
});

it('should work correctly with tokens of different decimals', async () => {
const { users, usdc, oracle, dai, aDai, pool, deployer, faucetMintable } = testEnv;
const { users, usdc, oracle, dai, aDai, pool, deployer } = testEnv;
const user = users[0].signer;
const userAddress = users[0].address;

Expand All @@ -350,12 +348,12 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
const flashloanTotal = amountUSDCtoSwap.add(flashloanPremium);

// Provider liquidity
await faucetMintable.mint(usdc.address, deployer.address, liquidity);
await usdc['mint(uint256)'](liquidity);
await usdc.approve(pool.address, liquidity);
await pool.deposit(usdc.address, liquidity, deployer.address, 0);

// Make a deposit for user
await faucetMintable.mint(usdc.address, userAddress, flashloanTotal);
await usdc.connect(user)['mint(uint256)'](flashloanTotal);
await usdc.connect(user).approve(pool.address, flashloanTotal);
await pool.connect(user).deposit(usdc.address, flashloanTotal, userAddress, 0);

Expand Down Expand Up @@ -509,7 +507,7 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
});

it('should revert when min amount to receive exceeds the max slippage amount (with tokens of different decimals)', async () => {
const { users, usdc, oracle, dai, pool, deployer, faucetMintable } = testEnv;
const { users, usdc, oracle, dai, pool, deployer } = testEnv;
const user = users[0].signer;
const userAddress = users[0].address;

Expand All @@ -520,12 +518,12 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
const flashloanTotal = amountUSDCtoSwap.add(flashloanPremium);

// Provider liquidity
await faucetMintable.mint(usdc.address, deployer.address, liquidity);
await usdc['mint(uint256)'](liquidity);
await usdc.approve(pool.address, liquidity);
await pool.deposit(usdc.address, liquidity, deployer.address, 0);

// Make a deposit for user
await faucetMintable.mint(usdc.address, userAddress, flashloanTotal);
await usdc.connect(user)['mint(uint256)'](flashloanTotal);
await usdc.connect(user).approve(pool.address, flashloanTotal);
await pool.connect(user).deposit(usdc.address, flashloanTotal, userAddress, 0);

Expand Down Expand Up @@ -915,16 +913,16 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
});

it('should not touch any token balance already in the adapter', async () => {
const { users, weth, oracle, dai, aDai, aWETH, pool, faucetMintable, deployer } = testEnv;
const { users, weth, oracle, dai, aDai, aWETH, pool } = testEnv;
const user = users[0].signer;
const userAddress = users[0].address;

// Put token balances in the adapter
const adapterWethBalanceBefore = parseEther('123');
await faucetMintable.mint(weth.address, deployer.address, adapterWethBalanceBefore);
await weth['mint(uint256)'](adapterWethBalanceBefore);
await weth.transfer(paraswapLiquiditySwapAdapter.address, adapterWethBalanceBefore);
const adapterDaiBalanceBefore = parseEther('234');
await faucetMintable.mint(dai.address, deployer.address, adapterDaiBalanceBefore);
await dai['mint(uint256)'](adapterDaiBalanceBefore);
await dai.transfer(paraswapLiquiditySwapAdapter.address, adapterDaiBalanceBefore);

const amountWETHtoSwap = await parseUnitsFromToken(weth.address, '10');
Expand Down Expand Up @@ -1000,28 +998,28 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {

describe('executeOperation with borrowing', () => {
beforeEach(async () => {
const { users, weth, dai, pool, deployer, faucetMintable } = testEnv;
const { users, weth, dai, pool, deployer } = testEnv;
const userAddress = users[0].address;
const borrower = users[1].signer;
const borrowerAddress = users[1].address;

// Provide liquidity
await faucetMintable.mint(dai.address, deployer.address, parseEther('20000'));
await dai['mint(uint256)'](parseEther('20000'));
await dai.approve(pool.address, parseEther('20000'));
await pool.deposit(dai.address, parseEther('20000'), deployer.address, 0);

await faucetMintable.mint(weth.address, deployer.address, parseEther('10000'));
await weth['mint(uint256)'](parseEther('10000'));
await weth.approve(pool.address, parseEther('10000'));
await pool.deposit(weth.address, parseEther('10000'), deployer.address, 0);

// Make a deposit for user
await faucetMintable.mint(weth.address, deployer.address, parseEther('100'));
await weth['mint(uint256)'](parseEther('100'));
await weth.approve(pool.address, parseEther('100'));
await pool.deposit(weth.address, parseEther('100'), userAddress, 0);

// Add borrowing
const collateralAmount = parseEther('30000000');
await faucetMintable.mint(dai.address, deployer.address, collateralAmount);
await dai['mint(uint256)'](collateralAmount);
await dai.approve(pool.address, collateralAmount);
await pool.deposit(dai.address, collateralAmount, borrowerAddress, 0);
await pool
Expand Down Expand Up @@ -1382,20 +1380,20 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {

describe('swapAndDeposit', () => {
beforeEach(async () => {
const { users, weth, dai, pool, deployer, faucetMintable } = testEnv;
const { users, weth, dai, pool, deployer } = testEnv;
const userAddress = users[0].address;

// Provide liquidity
await faucetMintable.mint(dai.address, deployer.address, parseEther('20000'));
await dai['mint(uint256)'](parseEther('20000'));
await dai.approve(pool.address, parseEther('20000'));
await pool.deposit(dai.address, parseEther('20000'), deployer.address, 0);

await faucetMintable.mint(weth.address, deployer.address, parseEther('10000'));
await weth['mint(uint256)'](parseEther('10000'));
await weth.approve(pool.address, parseEther('10000'));
await pool.deposit(weth.address, parseEther('10000'), deployer.address, 0);

// Make a deposit for user
await faucetMintable.mint(weth.address, deployer.address, parseEther('100'));
await weth['mint(uint256)'](parseEther('100'));
await weth.approve(pool.address, parseEther('100'));
await pool.deposit(weth.address, parseEther('100'), userAddress, 0);
});
Expand Down Expand Up @@ -2202,16 +2200,16 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {
});

it('should not touch any token balance already in the adapter', async () => {
const { users, weth, oracle, dai, aDai, aWETH, deployer, faucetMintable } = testEnv;
const { users, weth, oracle, dai, aDai, aWETH } = testEnv;
const user = users[0].signer;
const userAddress = users[0].address;

// Put token balances in the adapter
const adapterWethBalanceBefore = parseEther('123');
await faucetMintable.mint(weth.address, deployer.address, adapterWethBalanceBefore);
await weth['mint(uint256)'](adapterWethBalanceBefore);
await weth.transfer(paraswapLiquiditySwapAdapter.address, adapterWethBalanceBefore);
const adapterDaiBalanceBefore = parseEther('234');
await faucetMintable.mint(dai.address, deployer.address, adapterDaiBalanceBefore);
await dai['mint(uint256)'](adapterDaiBalanceBefore);
await dai.transfer(paraswapLiquiditySwapAdapter.address, adapterDaiBalanceBefore);

const amountWETHtoSwap = await parseUnitsFromToken(weth.address, '10');
Expand Down Expand Up @@ -2282,28 +2280,28 @@ makeSuite('ParaSwap adapters', (testEnv: TestEnv) => {

describe('swapAndDeposit with borrowing', () => {
beforeEach(async () => {
const { users, weth, dai, pool, deployer, faucetMintable } = testEnv;
const { users, weth, dai, pool, deployer } = testEnv;
const userAddress = users[0].address;
const borrower = users[1].signer;
const borrowerAddress = users[1].address;

// Provide liquidity
await faucetMintable.mint(dai.address, deployer.address, parseEther('20000'));
await dai['mint(uint256)'](parseEther('20000'));
await dai.approve(pool.address, parseEther('20000'));
await pool.deposit(dai.address, parseEther('20000'), deployer.address, 0);

await faucetMintable.mint(weth.address, deployer.address, parseEther('10000'));
await weth['mint(uint256)'](parseEther('10000'));
await weth.approve(pool.address, parseEther('10000'));
await pool.deposit(weth.address, parseEther('10000'), deployer.address, 0);

// Make a deposit for user
await faucetMintable.mint(weth.address, deployer.address, parseEther('100'));
await weth['mint(uint256)'](parseEther('100'));
await weth.approve(pool.address, parseEther('100'));
await pool.deposit(weth.address, parseEther('100'), userAddress, 0);

// Add borrowing
const collateralAmount = parseEther('30000000');
await faucetMintable.mint(dai.address, deployer.address, collateralAmount);
await dai['mint(uint256)'](collateralAmount);
await dai.approve(pool.address, collateralAmount);
await pool.deposit(dai.address, collateralAmount, borrowerAddress, 0);
await pool
Expand Down
Loading

0 comments on commit 959a0c0

Please sign in to comment.