Skip to content

Commit

Permalink
delete xtoken register
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Mar 27, 2024
1 parent fcb3987 commit b690c62
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 41 deletions.
41 changes: 6 additions & 35 deletions helix-contract/contracts/xtoken/v3/base/XTokenIssuing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "@zeppelin-solidity/contracts/utils/introspection/ERC165Checker.sol";
import "./XTokenBridgeBase.sol";
import "./XTokenErc20.sol";
import "../interfaces/IXToken.sol";
import "../interfaces/IXTokenBacking.sol";
import "../interfaces/IXTokenCallback.sol";
import "../../../utils/TokenTransferHelper.sol";
Expand Down Expand Up @@ -37,35 +37,6 @@ contract XTokenIssuing is XTokenBridgeBase {
);
event TokenRemintForFailed(bytes32 transferId, uint256 originalChainId, address originalToken, address xToken, address originalSender, uint256 amount);

function registerXToken(
uint256 _originalChainId,
address _originalToken,
string memory _originalChainName,
string memory _name,
string memory _symbol,
uint8 _decimals,
uint256 _dailyLimit
) external onlyDao returns (address xToken) {
bytes32 salt = xTokenSalt(_originalChainId, _originalToken);
require(xTokens[salt] == address(0), "contract has been deployed");
bytes memory bytecode = type(XTokenErc20).creationCode;
bytes memory bytecodeWithInitdata = abi.encodePacked(
bytecode,
abi.encode(
string(abi.encodePacked(_name, "[", _originalChainName, ">")),
string(abi.encodePacked("x", _symbol)),
_decimals
));
assembly {
xToken := create2(0, add(bytecodeWithInitdata, 0x20), mload(bytecodeWithInitdata), salt)
if iszero(extcodesize(xToken)) { revert(0, 0) }
}
xTokens[salt] = xToken;
originalTokens[xToken] = OriginalTokenInfo(_originalChainId, _originalToken);
_setDailyLimit(xToken, _dailyLimit);
emit IssuingERC20Created(_originalChainId, _originalToken, xToken);
}

// using this interface, the Issuing contract must be must be granted mint and burn authorities.
// warning: if the _xToken contract has no transferOwnership/acceptOwnership interface, then the authority cannot be transfered.
function updateXToken(
Expand All @@ -85,11 +56,11 @@ contract XTokenIssuing is XTokenBridgeBase {

// transfer xToken ownership
function transferXTokenOwnership(address _xToken, address _newOwner) external onlyDao {
XTokenErc20(_xToken).transferOwnership(_newOwner);
IXToken(_xToken).transferOwnership(_newOwner);
}

function acceptXTokenOwnership(address _xToken) external onlyDao {
XTokenErc20(_xToken).acceptOwnership();
IXToken(_xToken).acceptOwnership();
}

// receive issuing xToken message from remote backing contract
Expand Down Expand Up @@ -119,7 +90,7 @@ contract XTokenIssuing is XTokenBridgeBase {
require(_recipient == _guard, "must issue token from guard");
}
}
XTokenErc20(xToken).mint(_recipient, _amount);
IXToken(xToken).mint(_recipient, _amount);

if (ERC165Checker.supportsInterface(_recipient, type(IXTokenCallback).interfaceId)) {
IXTokenCallback(_recipient).xTokenCallback(uint256(transferId), xToken, _amount, _extData);
Expand All @@ -143,7 +114,7 @@ contract XTokenIssuing is XTokenBridgeBase {
_requestTransfer(transferId);
// transfer to this and then burn
TokenTransferHelper.safeTransferFrom(_xToken, msg.sender, address(this), _amount);
XTokenErc20(_xToken).burn(address(this), _amount);
IXToken(_xToken).burn(address(this), _amount);

bytes memory remoteUnlockCall = encodeXUnlock(
originalInfo.token,
Expand Down Expand Up @@ -250,7 +221,7 @@ contract XTokenIssuing is XTokenBridgeBase {
address xToken = xTokens[salt];
require(xToken != address(0), "xToken not exist");

XTokenErc20(xToken).mint(_originalSender, _amount);
IXToken(xToken).mint(_originalSender, _amount);
if (ERC165Checker.supportsInterface(_originalSender, type(IXTokenRollbackCallback).interfaceId)) {
IXTokenRollbackCallback(_originalSender).xTokenRollbackCallback(uint256(transferId), xToken, _amount);
}
Expand Down
9 changes: 9 additions & 0 deletions helix-contract/contracts/xtoken/v3/interfaces/IXToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.17;

interface IXToken {
function transferOwnership(address newOwner) external;
function acceptOwnership() external;
function mint(address account, uint256 amount) external;
function burn(address account, uint256 amount) external;
}
21 changes: 15 additions & 6 deletions helix-contract/test/6_test_xtoken_v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,25 @@ describe("xtoken tests", () => {
originalTokenDecimals,
dailyLimit
) {
// register xtoken
await issuing.registerXToken(
const erc20Contract = await ethers.getContractFactory("Erc20");
const erc20 = await erc20Contract.deploy(
`[${originalTokenName}[${originalChainName}>`,
`x${originalTokenSymbol}`,
originalTokenDecimals
);
await erc20.deployed();

await issuing.updateXToken(
backingChainId,
originalTokenAddress,
originalChainName,
originalTokenName,
originalTokenSymbol,
originalTokenDecimals,
erc20.address
);
await issuing.setDailyLimit(
erc20.address,
dailyLimit
);
await erc20.transferOwnership(issuing.address);

console.log("register xtoken finished");

const xTokenSalt = await issuing.xTokenSalt(backingChainId, originalTokenAddress);
Expand Down

0 comments on commit b690c62

Please sign in to comment.