Skip to content

Commit

Permalink
test: Add changes of Mock Augustus
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf committed Sep 3, 2024
1 parent b7c586f commit cca2c04
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions contracts/mocks/swap/MockParaSwapAugustus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
uint256 _expectedToAmountMax;
uint256 _expectedToAmountMin;

uint256 _excessFromAmount;
uint256 _excessToAmount;

constructor() {
TOKEN_TRANSFER_PROXY = new MockParaSwapTokenTransferProxy();
}
Expand Down Expand Up @@ -58,6 +61,11 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
_expectedToAmountMax = toAmountMax;
}

function expectExcess(uint256 excessFrom, uint256 excessTo) external {
_excessFromAmount = excessFrom;
_excessToAmount = excessTo;
}

function swap(
address fromToken,
address toToken,
Expand All @@ -72,10 +80,17 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
'From amount out of range'
);
require(_receivedAmount >= toAmount, 'Received amount of tokens are less than expected');
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), fromAmount);
MintableERC20(toToken).mint(_receivedAmount);
IERC20(toToken).transfer(msg.sender, _receivedAmount);
TOKEN_TRANSFER_PROXY.transferFrom(
fromToken,
msg.sender,
address(this),
fromAmount - _excessFromAmount
);
MintableERC20(toToken).mint(_receivedAmount + _excessToAmount);
IERC20(toToken).transfer(msg.sender, _receivedAmount + _excessToAmount);
_expectingSwap = false;
_excessFromAmount = 0;
_excessToAmount = 0;
return _receivedAmount;
}

Expand All @@ -93,10 +108,17 @@ contract MockParaSwapAugustus is IParaSwapAugustus {
'To amount out of range'
);
require(_fromAmount <= fromAmount, 'From amount of tokens are higher than expected');
TOKEN_TRANSFER_PROXY.transferFrom(fromToken, msg.sender, address(this), _fromAmount);
MintableERC20(toToken).mint(toAmount);
IERC20(toToken).transfer(msg.sender, toAmount);
TOKEN_TRANSFER_PROXY.transferFrom(
fromToken,
msg.sender,
address(this),
_fromAmount - _excessFromAmount
);
MintableERC20(toToken).mint(toAmount + _excessToAmount);
IERC20(toToken).transfer(msg.sender, toAmount + _excessToAmount);
_expectingSwap = false;
_excessFromAmount = 0;
_excessToAmount = 0;
return fromAmount;
}
}

0 comments on commit cca2c04

Please sign in to comment.