Add GST support to DFB

This commit is contained in:
Jacob Evans 2020-04-06 13:55:05 +10:00 committed by Lawrence Forman
parent b09c751942
commit 282930cb9b
6 changed files with 41 additions and 10 deletions

View File

@ -21,6 +21,9 @@
{ {
"note": "Add `DexForwaderBridge` bridge contract.", "note": "Add `DexForwaderBridge` bridge contract.",
"pr": 2525 "pr": 2525
},
{
"note": "Add Gas Token freeing to `DexForwaderBridge` contract."
} }
] ]
}, },

View File

@ -23,15 +23,19 @@ import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol"; import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
import "@0x/contracts-exchange-libs/contracts/src/IWallet.sol"; import "@0x/contracts-exchange-libs/contracts/src/IWallet.sol";
import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol"; import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../interfaces/IERC20Bridge.sol"; import "../interfaces/IERC20Bridge.sol";
import "./MixinGasToken.sol";
// solhint-disable space-after-comma, indent // solhint-disable space-after-comma, indent
contract DexForwarderBridge is contract DexForwarderBridge is
IERC20Bridge, IERC20Bridge,
IWallet IWallet,
DeploymentConstants,
MixinGasToken
{ {
using LibSafeMath for uint256; using LibSafeMath for uint256;
@ -68,6 +72,7 @@ contract DexForwarderBridge is
bytes calldata bridgeData bytes calldata bridgeData
) )
external external
freesGasTokensFromCollector
returns (bytes4 success) returns (bytes4 success)
{ {
TransferFromState memory state; TransferFromState memory state;
@ -84,16 +89,15 @@ contract DexForwarderBridge is
break; break;
} }
BridgeCall memory call = state.calls[i];
// Compute token amounts. // Compute token amounts.
state.callInputTokenAmount = LibSafeMath.min256( state.callInputTokenAmount = LibSafeMath.min256(
call.inputTokenAmount, state.calls[i].inputTokenAmount,
state.initialInputTokenBalance.safeSub(state.totalInputTokenSold) state.initialInputTokenBalance.safeSub(state.totalInputTokenSold)
); );
state.callOutputTokenAmount = LibMath.getPartialAmountFloor( state.callOutputTokenAmount = LibMath.getPartialAmountFloor(
state.callInputTokenAmount, state.callInputTokenAmount,
call.inputTokenAmount, state.calls[i].inputTokenAmount,
call.outputTokenAmount state.calls[i].outputTokenAmount
); );
// Execute the call in a new context so we can recoup transferred // Execute the call in a new context so we can recoup transferred
@ -101,13 +105,13 @@ contract DexForwarderBridge is
(bool didSucceed, ) = address(this) (bool didSucceed, ) = address(this)
.call(abi.encodeWithSelector( .call(abi.encodeWithSelector(
this.executeBridgeCall.selector, this.executeBridgeCall.selector,
call.target, state.calls[i].target,
to, to,
state.inputToken, state.inputToken,
outputToken, outputToken,
state.callInputTokenAmount, state.callInputTokenAmount,
state.callOutputTokenAmount, state.callOutputTokenAmount,
call.bridgeData state.calls[i].bridgeData
)); ));
if (didSucceed) { if (didSucceed) {

View File

@ -156,6 +156,7 @@ contract TestDexForwarderBridge is
ITestDexForwarderBridge, ITestDexForwarderBridge,
DexForwarderBridge DexForwarderBridge
{ {
function createBridge( function createBridge(
bytes4 returnCode, bytes4 returnCode,
string memory revertError string memory revertError
@ -217,4 +218,12 @@ contract TestDexForwarderBridge is
function balanceOf(address token, address owner) public view returns (uint256) { function balanceOf(address token, address owner) public view returns (uint256) {
return TestDexForwarderBridgeTestToken(token).balanceOf(owner); return TestDexForwarderBridgeTestToken(token).balanceOf(owner);
} }
function _getGstAddress()
internal
view
returns (address gst)
{
return address(0);
}
} }

View File

@ -152,10 +152,19 @@ export function createOrdersFromPath(path: Fill[], opts: CreateOrderFromPathOpts
++i; ++i;
continue; continue;
} }
// Liquidity Provider must be called by ERC20BridgeProxy
if (collapsedPath[i].source === ERC20BridgeSource.LiquidityProvider) {
orders.push(createBridgeOrder(collapsedPath[i], opts));
++i;
continue;
}
// If there are contiguous bridge orders, we can batch them together. // If there are contiguous bridge orders, we can batch them together.
const contiguousBridgeFills = [collapsedPath[i]]; const contiguousBridgeFills = [collapsedPath[i]];
for (let j = i + 1; j < collapsedPath.length; ++j) { for (let j = i + 1; j < collapsedPath.length; ++j) {
if (collapsedPath[j].source === ERC20BridgeSource.Native) { if (
collapsedPath[j].source === ERC20BridgeSource.Native ||
collapsedPath[j].source === ERC20BridgeSource.LiquidityProvider
) {
break; break;
} }
contiguousBridgeFills.push(collapsedPath[j]); contiguousBridgeFills.push(collapsedPath[j]);

View File

@ -29,6 +29,12 @@
{ {
"note": "Redeploy `Forwarder` on all networks", "note": "Redeploy `Forwarder` on all networks",
"pr": 2521 "pr": 2521
},
{
"note": "Redeploy `DexForwarderBridge` on Mainnet with Gas Token freeing"
},
{
"note": "Revert to older Curve Bridge (without Gas Tokens)"
} }
] ]
}, },

View File

@ -28,9 +28,9 @@
"godsUnchainedValidator": "0x09a379ef7218bcfd8913faa8b281ebc5a2e0bc04", "godsUnchainedValidator": "0x09a379ef7218bcfd8913faa8b281ebc5a2e0bc04",
"broker": "0xd4690a51044db77d91d7aa8f7a3a5ad5da331af0", "broker": "0xd4690a51044db77d91d7aa8f7a3a5ad5da331af0",
"chainlinkStopLimit": "0xeb27220f95f364e1d9531992c48613f231839f53", "chainlinkStopLimit": "0xeb27220f95f364e1d9531992c48613f231839f53",
"curveBridge": "0x1cf6ccc7e15d0d99a9498f37e16ba65b5c54bdd0", "curveBridge": "0x6dc7950423ada9f56fb2c93a23edb787f1e29088",
"maximumGasPrice": "0xe2bfd35306495d11e3c9db0d8de390cda24563cf", "maximumGasPrice": "0xe2bfd35306495d11e3c9db0d8de390cda24563cf",
"dexForwarderBridge": "0xa96844087062acf8556ca06a27702c6d19f87e57" "dexForwarderBridge": "0x2b135c732110be20db72e44ab2a4b149fa213599"
}, },
"3": { "3": {
"erc20Proxy": "0xb1408f4c245a23c31b98d2c626777d4c0d766caa", "erc20Proxy": "0xb1408f4c245a23c31b98d2c626777d4c0d766caa",