-
Notifications
You must be signed in to change notification settings - Fork 465
Eth2DaiBridge #2221
Eth2DaiBridge #2221
Conversation
b1098ca
to
6355a8a
Compare
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.
What are your thoughts on creating a new integrations
package and moving this there? This can be used for all external integrations, and also provides a place for us to write end-to-end integration tests for the Exchange/Staking/Forwarder/Coordinator. CC @jalextowle
ERC20Bridge, | ||
IWallet | ||
{ | ||
bytes4 private constant LEGACY_WALLET_MAGIC_VALUE = 0xb0671381; |
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 just include this in IWallet.sol
and inherit that?
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.
interfaces can't have/expose constants though, right?
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.
Abstract contracts can though , which is what we already use for most interfaces
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.
nvm, IWallet
is actually a contract.
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 ended up just making a copy in asset-proxy
since it would be a circular dep.
bytes4 private constant LEGACY_WALLET_MAGIC_VALUE = 0xb0671381; | ||
/* Mainnet addresses */ | ||
address constant public ETH2DAI_ADDRESS = 0x39755357759cE0d7f32dC8dC45414CCa409AE24e; | ||
address constant public WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; |
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.
Ideally we don't have to hard code any token addresses. It looks like Eth2Dai supports other token pairs in theory, and those should be able to be used as well. The fromToken
can probably be encoded in the bridgeData
.
amount | ||
); | ||
// Transfer the converted `toToken`s to `to`. | ||
toToken.transfer(to, boughtAmount); |
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.
We should probably check the return value here, just in case a token isn't 100% ERC20 compliant.
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.
LGTM
6355a8a
to
729a8b5
Compare
…n in `IEth2Dai`.
…y tokens. `@0x/contracts-asset-proxy`: Support non-conformant tokens in Eth2DaiBridge
729a8b5
to
8db3815
Compare
) | ||
private | ||
{ | ||
mapping (address => bool) storage spenderHasAllowance = _hasAllowance[spender]; |
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.
What happens when the allowance decreases to less than the required amount, but this is still set to true?
I think that this check actually just ends up being an extra expense most of the time. I'd prefer just calling IERC20Token(tokenAddress).approve(spender, uint256(-1))
every single time. If an allowance is already set, then this won't cost much extra gas at all. This also allows us to remove the _hasAllowance
mapping altogether.
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'm OK with this.
|
||
contract IWallet { | ||
|
||
bytes4 internal constant LEGACY_WALLET_MAGIC_VALUE = 0xb0671381; |
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 guess we can't import this due to circular dependencies?
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.
Yep. The alternative is to have exchange
import this file from the asset-proxy
package, but that just feels wrong.
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.
We should probably create a task for moving this to exchange-libs
, but doesn't have to be in this PR.
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.
One more small nit, then LGTM!
|
||
IEth2Dai exchange = _getEth2DaiContract(); | ||
// Grant an allowance to the exchange to spend `fromTokenAddress` token. | ||
_grantAllowanceForToken(address(exchange), fromTokenAddress); |
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.
Nit: we can probably just remove this function. It's pretty simple, and we also use IERC20Token(fromTokenAddress).balanceOf
below.
Description
Here's our first ever
ERC20BridgeProxy
(#2220) bridge:Eth2DaiBridge
!.Overview
This bridge contract is designed to be the
makerAddress
in all transactions, so:ERC20BridgeProxy
calls this contract, which:Because this contract should be the
makerAddress
of the order, it must sign for itself using theWallet
signature type. It implements theisValidSignature()
callback but always succeeds.Testing instructions
There are a whole 8 tests for this package. There really isn't much to unit test since the balance checks are enforced by the
ERC20BridgeProxy
and we just rely onEth2Dai
to do the actual conversion.Types of changes
Checklist:
[WIP]
if necessary.Relates to 0xProject/ZEIPs/issues/47