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

Feature/add receiver field for chain to chain transfers #1744

Merged
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.3.0
28 changes: 23 additions & 5 deletions contracts/schain/TokenManagers/TokenManagerERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,8 @@ contract TokenManagerERC20 is TokenManager, ITokenManagerERC20 {
)
external
override
rightTransaction(targetSchainName, msg.sender)
{
SchainHash targetSchainHash = SchainHash.wrap(keccak256(abi.encodePacked(targetSchainName)));
communityLocker.checkAllowedToSendMessage(targetSchainHash, msg.sender);
_exit(targetSchainHash, tokenManagers[targetSchainHash], contractOnMainnet, msg.sender, amount);
transferToSchainERC20Direct(targetSchainName, contractOnMainnet, amount, msg.sender);
}

/**
Expand Down Expand Up @@ -212,6 +209,27 @@ contract TokenManagerERC20 is TokenManager, ITokenManagerERC20 {
);
}

/**
* @dev Move tokens from schain to schain to specified receiver.
*
* {contractOnMainnet} tokens are burned on origin schain
* and are minted on {targetSchainName} schain for {receiver} address.
*/
function transferToSchainERC20Direct(
string calldata targetSchainName,
address contractOnMainnet,
uint256 amount,
address receiver
)
public
override
rightTransaction(targetSchainName, receiver)
{
SchainHash targetSchainHash = SchainHash.wrap(keccak256(abi.encodePacked(targetSchainName)));
communityLocker.checkAllowedToSendMessage(targetSchainHash, msg.sender);
_exit(targetSchainHash, tokenManagers[targetSchainHash], contractOnMainnet, receiver, amount);
}

// private

/**
Expand Down Expand Up @@ -304,7 +322,7 @@ contract TokenManagerERC20 is TokenManager, ITokenManagerERC20 {
data = _receiveERC20(
chainHash,
address(contractOnSchain),
msg.sender,
to,
amount
);
_saveTransferredAmount(chainHash, address(contractOnSchain), amount);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@openzeppelin/hardhat-upgrades": "^3.1.1",
"@safe-global/api-kit": "2.5.4",
"@skalenetwork/etherbase-interfaces": "^0.0.1-develop.20",
"@skalenetwork/ima-interfaces": "^2.0.0-execution-layer.13",
"@skalenetwork/ima-interfaces": "2.0.0-add-receiver-field-for-chain-to-chain-transfers.1",
"@skalenetwork/skale-manager-interfaces": "2.0.0",
"@skalenetwork/upgrade-tools": "3.0.0-develop.34",
"axios": "^0.21.4",
Expand Down
37 changes: 37 additions & 0 deletions test/TokenManagerERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,43 @@ describe("TokenManagerERC20", () => {
outgoingMessagesCounter.should.be.equal(1);
});

it("should invoke `transferToSchainERC20Direct` without mistakes", async () => {
const amount = "20000000000000000";
await messageProxyForSchain.registerExtraContract(newSchainName, tokenManagerErc20);

// add connected chain:
await messageProxyForSchain.connect(deployer).grantRole(await messageProxyForSchain.CHAIN_CONNECTOR_ROLE(), deployer.address);
await messageProxyForSchain.connect(deployer).addConnectedChain(newSchainName);

await erc20OnOriginChain.connect(deployer).mint(user.address, amount);
await erc20OnOriginChain.connect(user).approve(tokenManagerErc20, amount);

await tokenManagerErc20
.connect(user)
.transferToSchainERC20Direct(newSchainName, erc20OnOriginChain, amount, deployer.address)
.should.be.eventually.rejectedWith("Incorrect Token Manager address");

await tokenManagerErc20
.connect(user)
.transferToSchainERC20Direct("Mainnet", erc20OnOriginChain, amount, deployer.address)
.should.be.eventually.rejectedWith("This function is not for transferring to Mainnet");

await tokenManagerErc20.addTokenManager(newSchainName, tokenManagerErc202);

const data = await messages.encodeTransferErc20AndTokenInfoMessage(erc20OnOriginChain, deployer.address, amount, amount, { name: "NewToken", symbol: "NTN", decimals: 18 });

// execution:
await tokenManagerErc20
.connect(user)
.transferToSchainERC20Direct(newSchainName, erc20OnOriginChain, amount, deployer.address)
.should.emit(messageProxyForSchain, "OutgoingMessage")
.withArgs(newSchainId, 0, tokenManagerErc20, tokenManagerErc202, data);

// expectation:
const outgoingMessagesCounter = await messageProxyForSchain.getOutgoingMessagesCounter(newSchainName);
outgoingMessagesCounter.should.be.deep.equal(1n);
});

it("should reject `transferToSchainERC20` when executing earlier than allowed", async () => {
const amount = "20000000000000000";
await messageProxyForSchain.registerExtraContract(newSchainName, tokenManagerErc20);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,10 @@
resolved "https://registry.yarnpkg.com/@skalenetwork/etherbase-interfaces/-/etherbase-interfaces-0.0.1.tgz#97ed2069256a835efa1b088a58de17e2783a9e71"
integrity sha512-CgAo41sSL1KT9e1d3sUTxW5WPbEvHQwoqo3hLt+VW/6kGYukCuW4AHWMyDr5Jjw9KtjDKSOySDcoukhaeKxToQ==

"@skalenetwork/ima-interfaces@^2.0.0-execution-layer.13":
version "2.0.0-execution-layer.13"
resolved "https://registry.yarnpkg.com/@skalenetwork/ima-interfaces/-/ima-interfaces-2.0.0-execution-layer.13.tgz#5ed8e488f6cec755b15aefcbff2a4333596e51b8"
integrity sha512-SyrKE8qGtXq9QVcn5Z4yT5CgLpG79yLxcs8KuygiFEXopdYbM2tuQHIspVBSL+6UtIUYRz40g7IZN1vdVY+RcQ==
"@skalenetwork/[email protected]add-receiver-field-for-chain-to-chain-transfers.1":
version "2.0.0-add-receiver-field-for-chain-to-chain-transfers.1"
resolved "https://registry.yarnpkg.com/@skalenetwork/ima-interfaces/-/ima-interfaces-2.0.0-add-receiver-field-for-chain-to-chain-transfers.1.tgz#24621a1510e3df52506bb16884a58f54f8af1e34"
integrity sha512-NLGuHXAWS5t6QoaxZNShG92VhmBsbV4MCbmWiaDQbrjUDyyi2LzzCEuzDjvlLqMRUpE/2ztPRBOjqMg7dzeLGg==
dependencies:
"@skalenetwork/skale-manager-interfaces" "^3.2.0-develop.0"

Expand Down
Loading