Skip to content

Commit

Permalink
Audi Issue 12: Add foreignTokenIDOf to IGateway (#1314)
Browse files Browse the repository at this point in the history
* Add tokenInfo to IGateway

* fix imports

* convert to address lookup

* remove unused Token.sol

* PR feedback

* rename to queryForeignTokenID
  • Loading branch information
alistair-singh authored Oct 24, 2024
1 parent ac4ccd0 commit 0c0e046
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
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 @@ -428,6 +427,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

0 comments on commit 0c0e046

Please sign in to comment.