-
Notifications
You must be signed in to change notification settings - Fork 107
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
Improve solidity code for PNA #1275
Improve solidity code for PNA #1275
Conversation
What about already registered foreign assets? Are they still using the agent as admin account? Or do you plan to switch the registered admin on AH for them (need to check if that is possible)? |
Cool, much simple! Btw: It seems we want to support multi-hop for Ethereum->AH->Para direction. So is the fee token on Para still be relay token? If so will destination chain accept that? Can we always assume it's reserve-backed transfers beween AH and Para(more discussion in https://snowfork.slack.com/archives/G01BGMGLAC9/p1724456977726639thread_ts=1724432403.659139&cid=G01BGMGLAC9)? My concern here is seems not easy to find a common pattern to support multi-hop which applies to all parachains. |
contracts/src/Token.sol
Outdated
address public immutable OWNER; | ||
|
||
uint8 public immutable decimals; | ||
TokenLib.Token token; |
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.
Would suggest to move the token slots to the very end after decimals
.
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.
Moved fields around a bit
contracts/src/Assets.sol
Outdated
|
||
Token(token).burn(sender, amount); | ||
|
||
ticket.dest = destinationChain; |
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 the dest here supposed to be assetHubParaID
?
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 good catch. I've reimplemented _sendForeignToken
to mirror _sendNativeToken
. So that PNA assets can be sent to assethub or a further hop from assethub.
contracts/src/Assets.sol
Outdated
if (destinationAddress.isAddress32()) { | ||
// The receiver has a 32-byte account ID | ||
ticket.payload = SubstrateTypes.SendForeignTokenToAddress32( | ||
foreignID, destinationChain, destinationAddress.asAddress32(), destinationChainFee, amount | ||
); | ||
} else if (destinationAddress.isAddress20()) { | ||
// The receiver has a 20-byte account ID | ||
ticket.payload = SubstrateTypes.SendForeignTokenToAddress20( | ||
foreignID, destinationChain, destinationAddress.asAddress20(), destinationChainFee, amount | ||
); | ||
} else { | ||
revert Unsupported(); | ||
} |
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.
Need to double check the execution cost on AH(i.e. assetHubReserveTransferFee
) is included.
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.
For now I'm assuming assetHubReserveTransferFee
(which is configured to have considerable buffer) will cover costs for xcm execution on AH for both ENA and PNA flows.
We should probably rename the field to something like assetHubXcmFee
This is an Ethereum-specific addition that does not involve AH. Currently there are only native tokens (aka Ethereum-native ERC20s) registered in the Gateway contract, and on AH too. This change gives our gateway contract the ability to be aware of foreign assets on AH for example the Hydra or Kilt token in the ForeignAssets pallets. So it does affect the code paths that involve ethereum-native assets such as WETH or WBTC. |
I see. Sounds good! Thanks for the explanation 👍🏻 |
One idea I had for the Ethereum->AH->Parachain flow regarding fees on the final destination parachain. We already take DOT from AH's SA on BH to pay for XCM execution on AH. So we could go on step further and on AH we swap some of that DOT for the native token of the destination parachain. |
Sounds good. Can we make the fee asset of destination Para configurable when register token here? So for chains does allow AH-DOT as fee asset, swap is not required. Updates: Seems swap heavily depends on these PRs which are not ready yet, also not exist in our forked repo.
So I would prefer to make things easy just use AH-DOT as fee for PNA and move the swap improvement to a seperate PR in future when it's included in https://github.com/polkadot-fellows/runtimes, I would assume it applies also to the legacy Ethereum native asset like WETH. |
contracts/src/Assets.sol
Outdated
ticket.payload = SubstrateTypes.SendTokenToAssetHubAddress32( | ||
token, destinationAddress.asAddress32(), $.assetHubReserveTransferFee, amount | ||
); |
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.
On substrate side we always expect foreignID
for PNA, not the token 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.
Fixed in 57fa08c
* Asset from polkadot * Remove params unnecessary * Experiment: return calldata from Agent instead of call Gateway directly * To store registries also on agent * Send polkadot tokens back * Cleanup for not exceed the size limit * Add smoke test for register polkadot token * Transfer relay token to Ethereum * Reuse IGateway.sendToken for polkadot native asset * More cleanup * Fix encode substrate types * Add smoke test send relay token back * Rename to sendForeignToken * Improve ERC20.sol * Revert the change double register the token * Migration for AssetsStorage * Rename to _sendForeignTokenCosts * Use storage for less gas * Rename to tokenAddressOf * Rename as _burnToken * _ensureAgent in Gateway * Remove unused * Clean up smoke test * Terminate register foreign token in Gateway * Mint foreign token without the callback * Burn token without the callback * constructor ERC20 with the agent as owner * Move handler to Assets.sol reduce contract size * Refactoring to move transferToken to Assets * Remove TokenMinted&TokenBurned event * Move Command.RegisterToken to top level * Fix smoke tests * Move the check before interactions * Polish * Introduce ERC20Lib.sol * Remove unused * More test * Remove AgentExecuteCommand * More contract tests * Update contract address * Add AgentExecuteCommand back for compatibility * Cleanup * Add rfc * Update polkadot-native-assets.md * Update rfc * Update rfc with fee section * Fix _calculateFee for polkadot native token * Improve solidity code for PNA (#1275) * Improve PNA implementation * More improvents to ERC20 token * Fix implementation of Assets._sendForeignToken * Fix build payload for foreign token --------- Co-authored-by: ron <yrong1997@gmail.com> * Remove storage migration * Smoke test for register relay token * Fix fee estimation * Fix binding * Remove outdated doc * Fork upgrade test with sanity checks * Fix test --------- Co-authored-by: Vincent Geddes <117534+vgeddes@users.noreply.github.com>
Various improvements and cleanups
Changes:
execute
methodFIXES: SNO-1133