Support ICA/IQS functions without Call struct (#1307)

* Support ICA/IQS functions without Call struct

* Fix
pull/1328/head
Nam Chu Hoai 2 years ago committed by GitHub
parent 6ac9e9f1d4
commit 551af4c12e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      solidity/contracts/middleware/InterchainAccountRouter.sol
  2. 20
      solidity/contracts/middleware/InterchainQueryRouter.sol
  3. 18
      solidity/contracts/mock/MockInterchainAccountRouter.sol
  4. 6
      solidity/interfaces/IInterchainAccountRouter.sol
  5. 7
      solidity/interfaces/IInterchainQueryRouter.sol
  6. 4
      typescript/sdk/src/middleware/accounts.hardhat-test.ts

@ -44,6 +44,16 @@ contract InterchainAccountRouter is Router, IInterchainAccountRouter {
return _dispatch(_destinationDomain, abi.encode(msg.sender, calls));
}
function dispatch(
uint32 _destinationDomain,
address target,
bytes calldata data
) external returns (uint256) {
Call[] memory calls = new Call[](1);
calls[0] = Call({to: target, data: data});
return _dispatch(_destinationDomain, abi.encode(msg.sender, calls));
}
function getInterchainAccount(uint32 _origin, address _sender)
public
view

@ -43,6 +43,26 @@ contract InterchainQueryRouter is
_setInterchainGasPaymaster(_interchainGasPaymaster);
}
/**
* @param _destinationDomain Domain of destination chain
* @param target The address of the contract to query on destination chain.
* @param queryData The calldata of the view call to make on the destination chain.
* @param callback Callback function selector on `msg.sender` and optionally abi-encoded prefix arguments.
*/
function query(
uint32 _destinationDomain,
address target,
bytes calldata queryData,
bytes calldata callback
) external returns (uint256 leafIndex) {
// TODO: fix this ugly arrayification
Call[] memory calls = new Call[](1);
calls[0] = Call({to: target, data: queryData});
bytes[] memory callbacks = new bytes[](1);
callbacks[0] = callback;
leafIndex = query(_destinationDomain, calls, callbacks);
}
/**
* @param _destinationDomain Domain of destination chain
* @param call Call (to and data packed struct) to be made on destination chain.

@ -38,10 +38,24 @@ contract MockInterchainAccountRouter is IInterchainAccountRouter {
originDomain = _originDomain;
}
function dispatch(uint32, Call[] calldata calls)
external
function dispatch(uint32 _destinationDomain, Call[] calldata calls)
public
returns (uint256)
{
return _dispatch(_destinationDomain, calls);
}
function dispatch(
uint32 _destinationDomain,
address target,
bytes calldata data
) external returns (uint256) {
Call[] memory calls = new Call[](1);
calls[0] = Call({to: target, data: data});
return _dispatch(_destinationDomain, calls);
}
function _dispatch(uint32, Call[] memory calls) internal returns (uint256) {
pendingCalls[totalCalls] = PendingCall(
originDomain,
msg.sender,

@ -8,6 +8,12 @@ interface IInterchainAccountRouter {
external
returns (uint256);
function dispatch(
uint32 _destinationDomain,
address target,
bytes calldata data
) external returns (uint256);
function getInterchainAccount(uint32 _originDomain, address _sender)
external
view

@ -4,6 +4,13 @@ pragma solidity >=0.6.11;
import {Call} from "../contracts/Call.sol";
interface IInterchainQueryRouter {
function query(
uint32 _destinationDomain,
address target,
bytes calldata queryData,
bytes calldata callback
) external returns (uint256);
function query(
uint32 _destinationDomain,
Call calldata call,

@ -67,7 +67,9 @@ describe('InterchainAccountRouter', async () => {
localDomain,
signer.address,
);
await local.dispatch(remoteDomain, [{ to: recipient.address, data }]);
await local['dispatch(uint32,(address,bytes)[])'](remoteDomain, [
{ to: recipient.address, data },
]);
await coreApp.processMessages();
expect(await recipient.lastCallMessage()).to.eql(fooMessage);
expect(await recipient.lastCaller()).to.eql(icaAddress);

Loading…
Cancel
Save