Skip to content
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

Audi Issue 12: Add foreignTokenIDOf to IGateway #1314

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
MultiAddress,
Ticket,
Costs,
TokenInfo,
AgentExecuteCommand
} from "./Types.sol";
import {Upgrade} from "./Upgrade.sol";
Expand Down Expand Up @@ -439,6 +438,10 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
return Assets.isTokenRegistered(token);
}

function queryForeignTokenID(address token) external view returns (bytes32) {
return AssetsStorage.layout().tokenRegistry[token].foreignID;
}

// Total fee for registering a token
function quoteRegisterTokenFee() external view returns (uint256) {
return _calculateFee(Assets.registerTokenCosts());
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/interfaces/IGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ interface IGateway {
/// @dev Check whether a token is registered
function isTokenRegistered(address token) external view returns (bool);

/// @dev Get token id of an ERC20 contract address.
function queryForeignTokenID(address token) external view returns (bytes32);

/// @dev Quote a fee in Ether for registering a token, covering
/// 1. Delivery costs to BridgeHub
/// 2. XCM Execution costs on AssetHub
Expand Down
6 changes: 0 additions & 6 deletions contracts/src/upgrades/polkadot/GatewayPNA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
pragma solidity 0.8.25;

import "../../Gateway.sol";
import {AssetsStorage} from "../../storage/AssetsStorage.sol";
import {TokenInfo} from "../../Types.sol";

contract GatewayPNA is Gateway {
constructor(
Expand All @@ -26,8 +24,4 @@ contract GatewayPNA is Gateway {
{}

function initialize(bytes memory) external override {}

function tokenInfo(address token) external view returns (TokenInfo memory) {
return AssetsStorage.layout().tokenRegistry[token];
}
}
15 changes: 6 additions & 9 deletions contracts/test/ForkUpgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ contract ForkUpgradeTest is Test {
}

function checkLegacyToken() public {
TokenInfo memory weth = GatewayPNA(GatewayProxy).tokenInfo(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
assertEq(weth.isRegistered, true);
assertEq(weth.foreignID, bytes32(""));
TokenInfo memory myth = GatewayPNA(GatewayProxy).tokenInfo(0xBA41Ddf06B7fFD89D1267b5A93BFeF2424eb2003);
assertEq(myth.isRegistered, true);
assertEq(myth.foreignID, bytes32(""));
assert(IGateway(GatewayProxy).isTokenRegistered(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));
assertEq(IGateway(GatewayProxy).queryForeignTokenID(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2), bytes32(""));
assert(IGateway(GatewayProxy).isTokenRegistered(0xBA41Ddf06B7fFD89D1267b5A93BFeF2424eb2003));
assertEq(IGateway(GatewayProxy).queryForeignTokenID(0xBA41Ddf06B7fFD89D1267b5A93BFeF2424eb2003), bytes32(""));
}

function registerForeignToken() public {
Expand All @@ -57,9 +55,8 @@ contract ForkUpgradeTest is Test {
emit IGateway.ForeignTokenRegistered(dotId, address(0x0));

GatewayPNA(GatewayProxy).registerForeignToken(abi.encode(params));
TokenInfo memory dot = GatewayPNA(GatewayProxy).tokenInfo(0x70D9d338A6b17957B16836a90192BD8CDAe0b53d);
assertEq(dot.isRegistered, true);
assertEq(dot.foreignID, dotId);
assert(IGateway(GatewayProxy).isTokenRegistered(0x70D9d338A6b17957B16836a90192BD8CDAe0b53d));
assertEq(IGateway(GatewayProxy).queryForeignTokenID(0x70D9d338A6b17957B16836a90192BD8CDAe0b53d), dotId);
}

function testSanityCheck() public {
Expand Down
Loading
Loading