-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement AstriaMintableERC20
, update deposit tx to support ERC20 mints
#20
Conversation
v1.8.2
grpc/execution/server.go
Outdated
// | ||
// the fees are spent from the "bridge account" which is not actually a real account, but is instead some | ||
// address defined by consensus, so the gas cost is not actually deducted from any account. | ||
Gas: 16000, |
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 not sure if this is a big enough number, the gas costs of a tx is normally gasUnits * gasPrice. I'd either make it so the DepositTxs pay no gas or set this to something crazy large to account for EIP1559 gas price swings
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 originally tried to just make the tx not use gas, but it got a bit janky when it came to the state transition gas accounting D:
the gas
parameter here is just for the gas units, not the gas price, and I don't think gas itself can vary that much? DepositTxs don't have a gas price since they're inherent to consensus
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.
Lol I got that wrong, you're right it's the gas unit and not gas cost. This should be fine then
contracts/src/Counter.sol
Outdated
@@ -0,0 +1,14 @@ | |||
// SPDX-License-Identifier: UNLICENSED |
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.
This file can be deleted
grpc/execution/server.go
Outdated
assetID := [32]byte{} | ||
copy(assetID[:], deposit.AssetId[:32]) | ||
|
||
if _, ok := s.bridgeAllowedAssetIDs[assetID]; !ok { |
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 don't check that the bridge account itself is tied to this asset or if the bridge's start height requirement has been met. Might be safer to make these checks
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 catch, added!
## Summary implement withdrawals of ERC20 tokens that are of type `AstriaBridgeableERC20` (see implemented contract). ## Background we want to be able to withdraw ERC20 tokens that are bridged to a rollup. ## Changes - implement `AstriaBridgeableERC20` which is a standard `ERC20` contract with additional functionality for minting (not used by the withdrawer, implemented/tested here astriaorg/astria-geth#20) as well as functionality for withdrawing - implement `IAstriaWithdrawer` which is implemented by both `AstriaWithdrawer` and `AstriaMintableERC20`. - the withdrawer now interacts with a `IAstriaWithdrawer`. both native assets and ERC20 withdrawals have the same event signatures, so no additional code was needed for the withdrawer itself. - to use the withdrawer with an `AstriaBridgeableERC20`, the `ASTRIA_BRIDGE_WITHDRAWER_ETHEREUM_CONTRACT_ADDRESS` is set to some `AstriaMintableERC20`, and `ASTRIA_BRIDGE_WITHDRAWER_ROLLUP_ASSET_DENOMINATION` is set to the rollup asset's denomination as represented on the sequencer. for example, if the asset is represented on the sequencer is `transfer/channel-1/usdc`, that is the rollup asset denomination. the `name/symbol` of the ERC20 contract are not relevant. - also update the build script to write the generated abigen contract bindings to files, this is easier for debugging and unit testing. ## Testing unit tests ## Related Issues closes #924
contracts/astria_bridgeable_erc20.go
Outdated
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.
can we add a .gitattributes
file and mark as generated?
func (tx *DepositTx) gas() uint64 { return tx.Gas } | ||
func (tx *DepositTx) gasFeeCap() *big.Int { return new(big.Int) } | ||
func (tx *DepositTx) gasTipCap() *big.Int { return new(big.Int) } | ||
func (tx *DepositTx) gasPrice() *big.Int { return new(big.Int) } | ||
func (tx *DepositTx) value() *big.Int { return tx.Value } | ||
func (tx *DepositTx) nonce() uint64 { return 0 } | ||
func (tx *DepositTx) to() *common.Address { return nil } | ||
func (tx *DepositTx) to() *common.Address { return tx.To } |
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.
how were we identifying the correct account to send funds to previously?
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.
using the From
field, but i felt that was confusing, and now we need to set the From
field to the bridge "account"
grpc/execution/server.go
Outdated
if cfg.Erc20Asset == nil && nativeBridgeSeen { | ||
return nil, errors.New("only one native bridge address is allowed") | ||
} | ||
if cfg.Erc20Asset != nil && !nativeBridgeSeen { | ||
if cfg.Erc20Asset == nil && !nativeBridgeSeen { | ||
nativeBridgeSeen = true | ||
} |
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 know I wrote this but maybe a slightly cleaner if we combine?
if cfg.Erc20Asset == nil {
if nativeBridgeSeen {
return nil, errors.New("only one native bridge address is allowed")
}
nativeBridgeSeen = true
}
nativeBridgeSeen = true | ||
} | ||
|
||
if cfg.Erc20Asset != nil && bc.Config().AstriaBridgeSenderAddress == (common.Address{}) { | ||
return nil, errors.New("astria bridge sender address must be set for bridged ERC20 assets") |
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.
Noted further down, but we should probably use string.
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.
AstriaBridgeSenderAddress
is an evm address address (the fake address mints are sent from) so can leave this
@@ -346,6 +346,7 @@ type ChainConfig struct { | |||
AstriaCelestiaInitialHeight uint64 `json:"astriaCelestiaInitialHeight"` | |||
AstriaCelestiaHeightVariance uint64 `json:"astriaCelestiaHeightVariance,omitempty"` | |||
AstriaBridgeAddressConfigs []AstriaBridgeAddressConfig `json:"astriaBridgeAddresses,omitempty"` | |||
AstriaBridgeSenderAddress common.Address `json:"astriaBridgeSenderAddress,omitempty"` |
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 use a bech32m encoded string here, given that we marked the bytes as deprecated.
Does this have any implications on the 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.
same as above, this is actually supposed to be an evm address, it's not an astria address
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 updated the contracts for bech32 also btw
AstriaMintableERC20.sol
, allows an immutable addressbridge
to mint or burnDepositTx
s is set to this addressDepositTx
was updated to includeto
anddata
which are set for erc20 mints (later on burns),to
is set to the erc20 address of theAstriaMintableERC20
anddata
is the calldata to call the mint functiontesting:
contracts/README.md
.closes #9