callback-style funding option
This commit is contained in:
@@ -248,6 +248,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
|
||||
/// @inheritdoc IPartyPool
|
||||
function swap(
|
||||
address payer,
|
||||
bytes4 selector,
|
||||
address receiver,
|
||||
uint256 inputTokenIndex,
|
||||
uint256 outputTokenIndex,
|
||||
@@ -266,8 +267,18 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
|
||||
IERC20 tokenIn = _tokens[inputTokenIndex];
|
||||
IERC20 tokenOut = _tokens[outputTokenIndex];
|
||||
|
||||
// Transfer _tokens in via centralized helper
|
||||
_receiveTokenFrom(payer, tokenIn, totalTransferAmount);
|
||||
if ( selector == bytes4(0) )
|
||||
// Regular ERC20 permit of the pool to move the tokens
|
||||
_receiveTokenFrom(payer, tokenIn, totalTransferAmount);
|
||||
else {
|
||||
// Callback-style funding mechanism
|
||||
uint256 startingBalance = tokenIn.balanceOf(address(this));
|
||||
bytes memory data = abi.encodeWithSelector(selector, tokenIn, totalTransferAmount);
|
||||
// Invoke the payer callback; no return value expected (reverts on failure)
|
||||
Address.functionCall(payer, data);
|
||||
uint256 endingBalance = tokenIn.balanceOf(address(this));
|
||||
require(endingBalance-startingBalance == totalTransferAmount, 'Insufficient funds');
|
||||
}
|
||||
|
||||
// Compute on-chain balances as: onchain = cached + owed (+/- transfer)
|
||||
uint256 balIAfter = _cachedUintBalances[inputTokenIndex] + _protocolFeesOwed[inputTokenIndex] + totalTransferAmount;
|
||||
|
||||
Reference in New Issue
Block a user