Skip to content

Commit

Permalink
Merge branch 'vincent/v2' into ron/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Dec 11, 2024
2 parents d162fd3 + 005da17 commit 8ec8306
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 44 deletions.
1 change: 1 addition & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ignored_error_codes = [
# tstore
2394,
]

evm_version = 'Cancun'

[profile.production]
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/AgentExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ contract AgentExecutor {
_transferToken(token, recipient, amount);
}

/// @dev Transfer WETH to `recipient`. Only callable via `execute`.
function transferWeth(address weth, address recipient, uint128 amount) external {
WETH9(payable(weth)).withdraw(amount);
payable(recipient).safeNativeTransfer(amount);
}

/// @dev Call contract with Ether value. Only callable via `execute`.
function callContract(address target, bytes memory data, uint256 value) external {
bool success = Call.safeCall(target, data, value);
Expand All @@ -43,6 +37,12 @@ contract AgentExecutor {
}
}

/// @dev Transfer WETH to `recipient`. Only callable via `execute`.
function transferWeth(address weth, address recipient, uint128 amount) external {
WETH9(payable(weth)).withdraw(amount);
payable(recipient).safeNativeTransfer(amount);
}

function deposit() external payable {}

function _transferToken(address token, address recipient, uint128 amount) internal {
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/Initializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ library Initializer {
UD60x18 multiplier;
/// @dev Optional rescueOperator
address rescueOperator;
/// @dev The WETH address used for wrapping ETH
address weth;
uint8 foreignTokenDecimals;
uint128 maxDestinationFee;
address weth;
}

function initialize(bytes calldata data) external {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/storage/AssetsStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ library AssetsStorage {
uint256 registerTokenFee;
// Foreign token registry by token ID
mapping(bytes32 foreignID => address) tokenAddressOf;
address weth;
uint8 foreignTokenDecimals;
// The maximum fee that can be sent to a destination parachain to pay for execution (DOT).
// Has two functions:
// * Reduces the ability of users to perform arbitrage using a favourable exchange rate
// * Prevents users from mistakenly providing too much fees, which would drain AssetHub's
// sovereign account here on Ethereum.
uint128 maxDestinationFee;
address weth;
}

bytes32 internal constant SLOT = keccak256("org.snowbridge.storage.assets");
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v1/Calls.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ library CallsV1 {
* Internal functions
*/

// Convert foreign currency to native currency (ROC/KSM/DOT -> ETH)
// Convert foreign currency to native currency (WND/PAS/KSM/DOT -> ETH)
function _convertToNative(UD60x18 exchangeRate, UD60x18 multiplier, UD60x18 amount)
internal
view
Expand Down
67 changes: 32 additions & 35 deletions contracts/test/GatewayV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,32 +174,29 @@ contract GatewayV2Test is Test {
return commands;
}

function makeCallContractCommand(uint256 value) public view returns (CommandV2[] memory) {
bytes memory data = abi.encodeWithSignature("sayHello(string)", "World");
CallContractParams memory params = CallContractParams({
target: address(helloWorld),
data: data,
value: value
});
function makeUnlockWethCommand(uint128 value) public view returns (CommandV2[] memory) {
UnlockNativeTokenParams memory params =
UnlockNativeTokenParams({token: address(weth), recipient: relayer, amount: value});
bytes memory payload = abi.encode(params);

CommandV2[] memory commands = new CommandV2[](1);
commands[0] =
CommandV2({kind: CommandKind.CallContract, gas: 500_000, payload: payload});
CommandV2({kind: CommandKind.UnlockNativeToken, gas: 500_000, payload: payload});
return commands;
}

function makeUnlockWethCommand(uint128 value) public view returns (CommandV2[] memory) {
UnlockNativeTokenParams memory params = UnlockNativeTokenParams({
token: address(weth),
recipient: relayer,
amount: value
function makeCallContractCommand(uint256 value) public view returns (CommandV2[] memory) {
bytes memory data = abi.encodeWithSignature("sayHello(string)", "World");
CallContractParams memory params = CallContractParams({
target: address(helloWorld),
data: data,
value: value
});
bytes memory payload = abi.encode(params);

CommandV2[] memory commands = new CommandV2[](1);
commands[0] =
CommandV2({kind: CommandKind.UnlockNativeToken, gas: 500_000, payload: payload});
CommandV2({kind: CommandKind.CallContract, gas: 500_000, payload: payload});
return commands;
}

Expand Down Expand Up @@ -345,6 +342,27 @@ contract GatewayV2Test is Test {
);
}

function testUnlockWethSuccess() public {
hoax(assetHubAgent);
weth.deposit{value: 1 ether}();

vm.expectEmit(true, false, false, true);
emit IGatewayV2.InboundMessageDispatched(1, true, relayerRewardAddress);

vm.deal(assetHubAgent, 1 ether);
hoax(relayer, 1 ether);
IGatewayV2(address(gateway)).v2_submit(
InboundMessageV2({
origin: Constants.ASSET_HUB_AGENT_ID,
nonce: 1,
commands: makeUnlockWethCommand(0.1 ether)
}),
proof,
makeMockProof(),
relayerRewardAddress
);
}

function testEncodeDecodeMessageV2() public {
UnlockNativeTokenParams memory params = UnlockNativeTokenParams({
token: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,
Expand Down Expand Up @@ -411,25 +429,4 @@ contract GatewayV2Test is Test {
relayerRewardAddress
);
}

function testUnlockWethSuccess() public {
hoax(assetHubAgent);
weth.deposit{value: 1 ether}();

vm.expectEmit(true, false, false, true);
emit IGatewayV2.InboundMessageDispatched(1, true, relayerRewardAddress);

vm.deal(assetHubAgent, 1 ether);
hoax(relayer, 1 ether);
IGatewayV2(address(gateway)).v2_submit(
InboundMessageV2({
origin: Constants.ASSET_HUB_AGENT_ID,
nonce: 1,
commands: makeUnlockWethCommand(0.1 ether)
}),
proof,
makeMockProof(),
relayerRewardAddress
);
}
}

0 comments on commit 8ec8306

Please sign in to comment.