Skip to content

Commit

Permalink
Send tokens via TokenManager
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Jan 8, 2025
1 parent acc6e19 commit 161bb62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
13 changes: 10 additions & 3 deletions contracts/schain/ExecutionLayer/ExecutionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IExecutionManager, SchainHash} from "@skalenetwork/ima-interfaces/schain/ExecutionLayer/IExecutionManager.sol";
import {ITokenManagerERC20} from "@skalenetwork/ima-interfaces/schain/TokenManagers/ITokenManagerERC20.sol";
import {ExecutorId} from "@skalenetwork/ima-interfaces/schain/ExecutionLayer/IExecutor.sol";
import {IMessageProxy} from "@skalenetwork/ima-interfaces/IMessageProxy.sol";
import {RoleRequired} from "../../CommonErrors.sol";
import {TokenManagerERC20} from "../TokenManagers/TokenManagerERC20.sol";
import {MetaActionId, Protocol, TokenInfo} from "./Protocol.sol";
Expand Down Expand Up @@ -236,7 +237,10 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
}

function _receiveMetaAction(Protocol.Message memory message, SchainHash sourceChain) private {
console.log("_receiveMetaAction");
(Protocol.MetaAction memory metaAction, TokenInfo[] memory tokens) = Protocol.decodeMetaActionMessage(message);
console.log("Number of tokens");
console.log(tokens.length);
metaActions[message.metaActionId] = MetaActionContainer({
version: Protocol.VERSION,
sender: address(0),
Expand Down Expand Up @@ -265,6 +269,7 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
}

function _processMetaAction(MetaActionContainer storage metaAction, TokenInfo[] memory tokens) private {
console.log("_processMetaAction");
TokenInfo[] memory tokensAfterActions = _executeActions(metaAction, tokens);
_sendNextMetaAction(metaAction, tokensAfterActions);
}
Expand All @@ -287,6 +292,7 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
private
returns (TokenInfo[] memory resultTokens)
{
console.log("_executeActions");
}

function _postExecuteMetaAction(MetaActionContainer storage metaAction) private {
Expand All @@ -302,14 +308,15 @@ contract ExecutionManager is AccessControlEnumerableUpgradeable, IExecutionManag
address remoteExecutionManagerAddress = address(_getRemoteExecutionManager(targetChainHash));

for (uint256 i = 0; i < tokens.length; ++i) {
erc20TokenManager.transferToSchainERC20Direct(
targetSchainName,
erc20TokenManager.transferToSchainHashERC20Direct(
targetChainHash,
tokens[i].token,
tokens[i].number,
remoteExecutionManagerAddress);
}

erc20TokenManager.messageProxy.postOutgoingMessage(
IMessageProxy messageProxy = IMessageProxy(erc20TokenManager.messageProxy.address);
messageProxy.postOutgoingMessage(
targetChainHash,
remoteExecutionManagerAddress,
Protocol.encodeMetaActionMessage(metaAction.id, nextMetaAction, tokens)
Expand Down
24 changes: 11 additions & 13 deletions test/ExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,19 @@ describe("ExecutionManager", () => {
[{token: clone, number: value}]
)).wait();
assert(executeReceipt);
// let metaActionId = "0x";
// for (const log of executeReceipt.logs) {
// const event = sourceExecutionManager.interface.parseLog(log);
// if (event && event.name == 'MetaActionCreated') {
// metaActionId = event.args.id;
// }
// }

// console.log("MetaActionId", metaActionId);

// await agent.deliverMessages();
let metaActionId = "0x";
for (const log of executeReceipt.logs) {
const event = sourceExecutionManager.interface.parseLog(log);
if (event && event.name == 'MetaActionCreated') {
metaActionId = event.args.id;
}
}

// expect(await sourceExecutionManager.getMetaActionStatus(metaActionId)).to.be.equal(MetaActionStatus.SUCCEED);
// expect(await targetExecutionManager.getMetaActionStatus(metaActionId)).to.be.equal(MetaActionStatus.SUCCEED);
console.log("MetaActionId", metaActionId);

await agent.deliverMessages();

expect(await sourceExecutionManager.getMetaActionStatus(metaActionId)).to.be.equal(MetaActionStatus.SUCCEED);
expect(await targetExecutionManager.getMetaActionStatus(metaActionId)).to.be.equal(MetaActionStatus.SUCCEED);
});
});

0 comments on commit 161bb62

Please sign in to comment.