Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/multiply/DummyExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ contract DummyExchange {
uint256 amountOut = (mul(amount, 10**18) / prices[asset]) / (10**(18 - precision));
_transferIn(msg.sender, DAI_ADDRESS, amount);
emit AssetSwap(DAI_ADDRESS, asset, amount, amountOut);
console.log("DEBUG AMOUNT OUT", amountOut);
console.log("DEBUG msg.sender", msg.sender);
_transferOut(asset, msg.sender, amountOut);
}

Expand Down
9 changes: 8 additions & 1 deletion contracts/multiply/Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,18 @@ contract Exchange {
) internal returns (uint256) {
IERC20(fromAsset).safeApprove(callee, amount);
(bool success, ) = callee.call(withData);
console.log("DEBUG: swap status", success ? "succes" : "failure");
require(success, "Exchange / Could not swap");
uint256 balance = IERC20(toAsset).balanceOf(address(this));
console.log("DEBUG: SWAPPED BALANCE", balance);
emit SlippageSaved(receiveAtLeast, balance);
require(balance >= receiveAtLeast, "Exchange / Received less");
emit AssetSwap(fromAsset, toAsset, amount, balance);
return balance;
}

function _collectFee(address asset, uint256 fromAmount) internal returns (uint256) {
uint256 feeToTransfer = (fromAmount.mul(fee)).div(feeBase);
uint256 feeToTransfer = fromAmount.sub((fromAmount.mul(feeBase)).div(feeBase.add(fee)));
IERC20(asset).safeTransfer(feeBeneficiaryAddress, feeToTransfer);
emit FeePaid(feeBeneficiaryAddress, feeToTransfer);
return fromAmount.sub(feeToTransfer);
Expand All @@ -115,8 +117,13 @@ contract Exchange {
bytes calldata withData
) public {
_transferIn(msg.sender, DAI_ADDRESS, amount);
console.log("DEBUG: AMOUNT", amount);
console.log("DEBUG: ASSET", asset);
console.log("DEBUG: receiveAtLEast", receiveAtLeast);
console.logBytes(withData);

uint256 _amount = _collectFee(DAI_ADDRESS, amount);
console.log("DEBUG: AFTER FEE", _amount);
uint256 balance = _swap(DAI_ADDRESS, asset, _amount, receiveAtLeast, callee, withData);

uint256 daiBalance = IERC20(DAI_ADDRESS).balanceOf(address(this));
Expand Down
30 changes: 27 additions & 3 deletions contracts/multiply/GuniMultiplyProxyActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import "../interfaces/misc/IGUNIToken.sol";
import "../interfaces/exchange/IExchange.sol";
import "./../flashMint/interface/IERC3156FlashBorrower.sol";
import "./../flashMint/interface/IERC3156FlashLender.sol";
import "hardhat/console.sol";

struct CdpData {
address gemJoin;
Expand Down Expand Up @@ -75,7 +76,11 @@ contract GuniMultiplyProxyActions is IERC3156FlashBorrower {
CdpData memory cdpData,
GuniAddressRegistry calldata guniAddressRegistry
) public logMethodName("increaseMultipleGuni", cdpData, guniAddressRegistry.guniProxyActions) {
daiContract.transferFrom(msg.sender, guniAddressRegistry.guniProxyActions, cdpData.token0Amount);
daiContract.transferFrom(
msg.sender,
guniAddressRegistry.guniProxyActions,
cdpData.token0Amount
);
takeAFlashLoan(exchangeData, cdpData, guniAddressRegistry, 1);
}

Expand All @@ -102,7 +107,11 @@ contract GuniMultiplyProxyActions is IERC3156FlashBorrower {
uint256 action
) internal {
bytes memory paramsData = abi.encode(action, exchangeData, cdpData, guniAddressRegistry);

console.log(
"DEBUG DAI BALANCE before FL GUNIPA",
IERC20(DAI).balanceOf(guniAddressRegistry.guniProxyActions)
);
console.log("DEBUG DAI BALANCE before FL - DSPROXY", IERC20(DAI).balanceOf(address(this)));
IManager(guniAddressRegistry.manager).cdpAllow(
cdpData.cdpId,
guniAddressRegistry.guniProxyActions,
Expand Down Expand Up @@ -152,6 +161,9 @@ contract GuniMultiplyProxyActions is IERC3156FlashBorrower {
uint256 bal1 = otherToken.balanceOf(address(this)); //120k
bal0 = daiContract.balanceOf(address(this)); //80 k

console.log("DEBUG BAL0", bal0);
console.log("DEBUG BAL1", bal1);

{
IGUNIRouter router = IGUNIRouter(guniAddressRegistry.router);
daiContract.approve(address(router), bal0);
Expand All @@ -160,12 +172,22 @@ contract GuniMultiplyProxyActions is IERC3156FlashBorrower {
(, , guniBalance) = router.addLiquidity(address(guni), bal0, bal1, 0, 0, address(this));
}

console.log("DEBUG: GUNI BALANCE", guniBalance);
console.log("DEBUG: DAI BALANCE OF ", IERC20(DAI).balanceOf(address(this)));
guni.approve(guniAddressRegistry.guniProxyActions, guniBalance);
joinDrawDebt(cdpData, borrowedDaiAmount, guniAddressRegistry.manager, guniAddressRegistry.jug);
joinDrawDebt(
cdpData,
borrowedDaiAmount.sub(IERC20(DAI).balanceOf(address(this))),
guniAddressRegistry.manager,
guniAddressRegistry.jug
);

uint256 daiLeft = IERC20(DAI).balanceOf(address(this)).sub(borrowedDaiAmount);
uint256 otherTokenLeft = otherToken.balanceOf(address(this));

console.log("DEBUG: DAI LEFTOVER", daiLeft);
console.log("DEBUG: USDC LEFTOVER", otherTokenLeft);

if (daiLeft > 0) {
IERC20(DAI).transfer(cdpData.fundsReceiver, daiLeft);
}
Expand Down Expand Up @@ -236,6 +258,8 @@ contract GuniMultiplyProxyActions is IERC3156FlashBorrower {
GuniAddressRegistry memory guniAddressRegistry
) = abi.decode(params, (uint256, ExchangeData, CdpData, GuniAddressRegistry));

console.log("DEBUG: ON FLASH LOAN DAI BALANCE", IERC20(DAI).balanceOf(address(this)));

require(msg.sender == address(guniAddressRegistry.lender), "mpa-untrusted-lender");
uint256 borrowedDaiAmount;
{
Expand Down
2 changes: 1 addition & 1 deletion contracts/multiply/MultiplyProxyActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ contract MultiplyProxyActions is IERC3156FlashBorrower {
uint256 daiLeft = IERC20(DAI).balanceOf(address(this));

require(cdpData.requiredDebt <= daiLeft, "cannot repay all debt");

wipeAndFreeGem(
addressRegistry.manager,
cdpData.gemJoin,
Expand Down
3 changes: 2 additions & 1 deletion tenderly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ exports:
istanbul_block: 0
petersburg_block: 0
berlin_block: 0
london_block: 0
forked_network: mainnet
project_slug: jinx/project
project_slug: georgi2/project
protocol: ""
rpc_address: 127.0.0.1:8545
10 changes: 5 additions & 5 deletions test/common/mcd-deployment-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { getVaultInfo } = require('../utils-mcd.js')
const { curry } = require('ramda')
const { getMarketPrice } = require('./http_apis')

const FEE = 2
const FEE = 20
const FEE_BASE = 10000

const init = async function (blockNumber, provider, signer) {
Expand Down Expand Up @@ -330,11 +330,11 @@ const deploySystem = async function (provider, signer, isExchangeDummy = false,
deployedContracts.userProxyAddress = userProxyAddress
deployedContracts.dsProxyInstance = dsProxy

// GUNI DEPLOYMENT
// GUNI DEPLOYMENT

const GUni = await ethers.getContractFactory('GuniMultiplyProxyActions', signer)
const guni = await GUni.deploy()
deployedContracts.guni = await guni.deployed()
const GUni = await ethers.getContractFactory('GuniMultiplyProxyActions', signer)
const guni = await GUni.deploy()
deployedContracts.guni = await guni.deployed()

// const multiplyProxyActions = await deploy("MultiplyProxyActions");
const MPActions = await ethers.getContractFactory('MultiplyProxyActions', signer)
Expand Down
45 changes: 9 additions & 36 deletions test/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ describe('Exchange', async function () {
await expect(tx).to.revertedWith('Exchange / Unauthorized Caller')
})

it.only('should allow beneficiary to update the fee', async function () {
const toTransferAmount = "0x"+amountToWei(1,18).toString(16);
let tx0 = await signer.populateTransaction({to:feeBeneficiary,value:toTransferAmount});
await signer.sendTransaction(tx0);
await provider.send("hardhat_impersonateAccount", [feeBeneficiary]);
it('should allow beneficiary to update the fee', async function () {
const toTransferAmount = '0x' + amountToWei(1, 18).toString(16)
let tx0 = await signer.populateTransaction({ to: feeBeneficiary, value: toTransferAmount })
await signer.sendTransaction(tx0)
await provider.send('hardhat_impersonateAccount', [feeBeneficiary])
const benef = await ethers.provider.getSigner(feeBeneficiary)
let tx = await exchange.connect(benef).setFee('3')
})
Expand All @@ -118,7 +118,7 @@ describe('Exchange', async function () {
amountInWei,
exchange.address,
slippage.value.toString(),
ALLOWED_PROTOCOLS
ALLOWED_PROTOCOLS,
)
initialDaiWalletBalance = convertToBigNumber(await balanceOf(MAINNET_ADRESSES.ETH, address))

Expand All @@ -139,19 +139,6 @@ describe('Exchange', async function () {
await provider.send('evm_revert', [snapshotId])
})

it('should not happen if it is triggered from unauthorized caller', async () => {
let tx = exchange
.connect(provider.getSigner(1))
.swapTokenForDai(
MAINNET_ADRESSES.ETH,
amountToWei(1).toFixed(0),
amountFromWei(1).toFixed(0),
AGGREGATOR_V3_ADDRESS,
0,
)
await expect(tx).to.revertedWith('Exchange / Unauthorized Caller')
})

describe('when transferring an exact amount to the exchange', async function () {
let localSnapshotId, initialWethWalletBalance

Expand Down Expand Up @@ -479,7 +466,7 @@ describe('Exchange', async function () {
amountInWei.toFixed(0),
slippage.value.toString(),
exchange.address,
ALLOWED_PROTOCOLS
ALLOWED_PROTOCOLS,
)

const {
Expand All @@ -495,20 +482,6 @@ describe('Exchange', async function () {
receiveAtLeastInWei = amountToWei(receiveAtLeast).toFixed(0)
})

it('should not happen if it is triggered from unauthorized caller', async () => {
let tx = exchange
.connect(provider.getSigner(1))
.swapDaiForToken(
MAINNET_ADRESSES.ETH,
amountToWei(1).toFixed(0),
amountFromWei(1).toFixed(0),
AGGREGATOR_V3_ADDRESS,
0,
)

await expect(tx).to.revertedWith('Exchange / Unauthorized Caller')
})

describe('when transferring an exact amount to the exchange', async function () {
let localSnapshotId

Expand Down Expand Up @@ -956,7 +929,7 @@ describe('Exchange', async function () {
amountInWei,
exchange.address,
slippage.value.toString(),
ALLOWED_PROTOCOLS
ALLOWED_PROTOCOLS,
)

const {
Expand Down Expand Up @@ -1070,7 +1043,7 @@ describe('Exchange', async function () {
amountInWei.toFixed(0),
slippage.value.toString(),
exchange.address,
ALLOWED_PROTOCOLS
ALLOWED_PROTOCOLS,
)

const {
Expand Down
Loading