-
Notifications
You must be signed in to change notification settings - Fork 465
Conversation
75b8bf7
to
ade380d
Compare
5bf0ead
to
ab409f4
Compare
|
||
for (uint256 i = 0; i < state.calls.length; ++i) { | ||
// Stop if the we've sold all our input tokens. | ||
if (state.totalInputTokenSold >= state.initialInputTokenBalance) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a version where we also could stop based on output tokens bought (market buy), but ran into some issues:
- we can't use
amount
because we underestimate this value in AS w/bridgeSlippage
- this contract can end up with a balance of input tokens, so would we refund those to
to
? - I'm not sure this is the same behavior you would get if not using the DFB (individual bridge orders)
- Not sure any of this is even worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think this is probably cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good stuff, just some typos/nits
state.calls | ||
) = abi.decode(bridgeData, (address, BridgeCall[])); | ||
|
||
state.initialInputTokenBalance = IERC20Token(state.inputToken).balanceOf(address(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well use LibERC20Token for balances
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LibERC20Token.balanceOf()
swallows reverts. Not my jam.
contracts/asset-proxy/contracts/src/bridges/DexForwarderBridge.sol
Outdated
Show resolved
Hide resolved
contracts/asset-proxy/contracts/src/bridges/DexForwarderBridge.sol
Outdated
Show resolved
Hide resolved
contracts/asset-proxy/contracts/src/bridges/DexForwarderBridge.sol
Outdated
Show resolved
Hide resolved
call.outputTokenAmount | ||
); | ||
|
||
(bool didSucceed, ) = address(this) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should decode the return data here and check that it equals BRIDGE_SUCCESS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
executeBridgeCall()
doesn't return anything. It just succeeds or reverts.
|
||
for (uint256 i = 0; i < state.calls.length; ++i) { | ||
// Stop if the we've sold all our input tokens. | ||
if (state.totalInputTokenSold >= state.initialInputTokenBalance) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think this is probably cleaner
export interface DexForwaderBridgeCall { | ||
target: string; | ||
inputTokenAmount: BigNumber; | ||
outputTokenAmount: BigNumber; | ||
bridgeData: string; | ||
} | ||
|
||
export interface DexForwaderBridgeData { | ||
inputToken: string; | ||
calls: DexForwaderBridgeCall[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export interface DexForwaderBridgeCall { | |
target: string; | |
inputTokenAmount: BigNumber; | |
outputTokenAmount: BigNumber; | |
bridgeData: string; | |
} | |
export interface DexForwaderBridgeData { | |
inputToken: string; | |
calls: DexForwaderBridgeCall[]; | |
export interface DexForwarderBridgeCall { | |
target: string; | |
inputTokenAmount: BigNumber; | |
outputTokenAmount: BigNumber; | |
bridgeData: string; | |
} | |
export interface DexForwarderBridgeData { | |
inputToken: string; | |
calls: DexForwarderBridgeCall[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
help me jesus
// Revert if we were not able to sell our entire input token balance. | ||
require( | ||
state.totalInputTokenSold >= state.initialInputTokenBalance, | ||
"DexForwaderBridge/INCOMPLETE_FILL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"DexForwaderBridge/INCOMPLETE_FILL" | |
"DexForwarderBridge/INCOMPLETE_FILL" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and a few more 😆
|
||
if (!didSucceed) { | ||
// Log errors. | ||
emit DexForwarderBridgeCallFailed( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just for internal data gathering/insights?
AS makes heavy use of FillOrKill so the only case where it'd reasonably be emitted is when succeed with enough slippage/backup path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I'm thinking. These won't be going through fillOrder()
or the ERC20BridgeProxy so it's a less obvious path to detecting them. Maybe it's not worth it, though, since the bridge itself can revert if not enough input tokens are sold. We'd have to rely on traces for those situations (and the market fn failing).
Now I'm leaning towards nixing this event.
2e5bf37
to
02e47c7
Compare
…CallFailed` event from `DexForwarderBridge`.
`@0x/migrations`: Add `dexForwarderBridge` address field.
02e47c7
to
a509af2
Compare
Description
We can reduce swap protocol fees by unifying bridge orders under a single fill. We can take advantage of the fact that DEX bridges are permissionless. This PR introduces the
DexForwarderBridge
bridge, which essentially performs market fills over a sequence of bridge calls.Testing instructions
Types of changes
Checklist:
[WIP]
if necessary.