Skip to content

Commit

Permalink
add src chainid to transferId
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Dec 25, 2023
1 parent 67961ed commit acc39a8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions helix-contract/address/xtoken-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
}
},
"backingProxy": {
"crab": "0x27F58339CbB8c5A6f58d5D05Bfc1B3fd121F489C"
"crab": "0xbdC7bbF408931C5d666b4F0520E0D9E9A0B04e99"
},
"backingLogic": {
"crab": "0xF2274a80e93075ccD5E2Af8F07beF370Bb6dfac7"
"crab": "0x01F53415adC20a2D058DfF14e295Ab955CafD6d6"
},
"issuingProxy": {
"sepolia": "0xFF3bc7372A8011CFaD43D240464ef2fe74C59b86"
"sepolia": "0xf22D0bb66b39745Ae6e3fEa3E5859d7f0b367Fd1"
},
"issuingLogic": {
"sepolia": "0x1c955644c527BAA5a28255bCf9F7D3635B7ad99b"
"sepolia": "0xCD1c1C799f3914ECFC5e3653D3Cc846355d3dFC9"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract xTokenBacking is xTokenBridgeBase {
bytes32 key = keccak256(abi.encodePacked(_remoteChainId, _originalToken));
require(originalToken2xTokens[key] != address(0), "token not registered");

bytes32 transferId = getTransferId(_nonce, _remoteChainId, _originalToken, msg.sender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, block.chainid, _remoteChainId, _originalToken, msg.sender, _recipient, _amount);
_requestTransfer(transferId);

uint256 prepaid = msg.value;
Expand Down Expand Up @@ -124,7 +124,7 @@ contract xTokenBacking is xTokenBridgeBase {
) external calledByMessager(_remoteChainId) whenNotPaused {
expendDailyLimit(_originalToken, _amount);

bytes32 transferId = getTransferId(_nonce, block.chainid, _originalToken, _originSender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, block.chainid, _remoteChainId, _originalToken, _originSender, _recipient, _amount);
_handleTransfer(transferId);

// native token do not use guard
Expand Down Expand Up @@ -181,7 +181,7 @@ contract xTokenBacking is xTokenBridgeBase {
bytes memory _extParams
) external payable {
require(_originalSender == msg.sender || _recipient == msg.sender || dao == msg.sender, "invalid msgSender");
bytes32 transferId = getTransferId(_nonce, _remoteChainId, _originalToken, _originalSender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, block.chainid, _remoteChainId, _originalToken, _originalSender, _recipient, _amount);
_requestRefund(transferId);
bytes memory unlockForFailed = encodeIssuingForUnlockFailureFromRemote(
_originalToken,
Expand Down Expand Up @@ -225,7 +225,7 @@ contract xTokenBacking is xTokenBridgeBase {
uint256 _amount,
uint256 _nonce
) external calledByMessager(_remoteChainId) whenNotPaused {
bytes32 transferId = keccak256(abi.encodePacked(_nonce, _remoteChainId, _originalToken, _originalSender, _recipient, _amount));
bytes32 transferId = getTransferId(_nonce, block.chainid, _remoteChainId, _originalToken, _originalSender, _recipient, _amount);
_handleRefund(transferId);
if (_originalToken == address(0)) {
TokenTransferHelper.safeTransferNative(_originalSender, _amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,14 @@ contract xTokenBridgeBase is Initializable, Pausable, AccessController, DailyLim

function getTransferId(
uint256 _nonce,
uint256 _sourceChainId,
uint256 _targetChainId,
address _originalToken,
address _originalSender,
address _recipient,
uint256 _amount
) public pure returns(bytes32) {
return keccak256(abi.encodePacked(_nonce, _targetChainId, _originalToken, _originalSender, _recipient, _amount));
return keccak256(abi.encodePacked(_nonce, _sourceChainId, _targetChainId, _originalToken, _originalSender, _recipient, _amount));
}

// settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ contract xTokenIssuing is xTokenBridgeBase {
uint256 _amount,
uint256 _nonce
) external calledByMessager(_remoteChainId) whenNotPaused {
bytes32 transferId = getTransferId(_nonce, block.chainid, _originalToken, _originalSender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, _remoteChainId, block.chainid, _originalToken, _originalSender, _recipient, _amount);
bytes32 salt = xTokenSalt(_remoteChainId, _originalToken);
address xToken = xTokens[salt];
require(xToken != address(0), "xToken not exist");
Expand Down Expand Up @@ -129,7 +129,7 @@ contract xTokenIssuing is xTokenBridgeBase {
) external payable {
require(_amount > 0, "can not transfer amount zero");
OriginalTokenInfo memory originalInfo = originalTokens[_xToken];
bytes32 transferId = getTransferId(_nonce, originalInfo.chainId, originalInfo.token, msg.sender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, originalInfo.chainId, block.chainid, originalInfo.token, msg.sender, _recipient, _amount);
_requestTransfer(transferId);
// transfer to this and then burn
TokenTransferHelper.safeTransferFrom(_xToken, msg.sender, address(this), _amount);
Expand Down Expand Up @@ -178,7 +178,7 @@ contract xTokenIssuing is xTokenBridgeBase {
bytes memory _extParams
) external payable {
require(_originalSender == msg.sender || _recipient == msg.sender || dao == msg.sender, "invalid msgSender");
bytes32 transferId = getTransferId(_nonce, _originalChainId, _originalToken, _originalSender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, _originalChainId, block.chainid, _originalToken, _originalSender, _recipient, _amount);
_requestRefund(transferId);
bytes memory handleUnlockForFailed = encodeUnlockForIssuingFailureFromRemote(
_originalToken,
Expand Down Expand Up @@ -222,7 +222,7 @@ contract xTokenIssuing is xTokenBridgeBase {
uint256 _amount,
uint256 _nonce
) external calledByMessager(_originalChainId) whenNotPaused {
bytes32 transferId = getTransferId(_nonce, _originalChainId, _originalToken, _originalSender, _recipient, _amount);
bytes32 transferId = getTransferId(_nonce, _originalChainId, block.chainid, _originalToken, _originalSender, _recipient, _amount);
_handleRefund(transferId);

bytes32 salt = xTokenSalt(_originalChainId, _originalToken);
Expand Down
4 changes: 2 additions & 2 deletions helix-contract/deploy/deploy_xtoken_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const crabNetwork = {
url: "https://crab-rpc.darwinia.network",
dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
messager: "0xf85638B61E0425D6BB91981190B73246e3AF3CA9",
backing: "0x27F58339CbB8c5A6f58d5D05Bfc1B3fd121F489C",
backing: "0xbdC7bbF408931C5d666b4F0520E0D9E9A0B04e99",
chainid: 44
};

Expand All @@ -21,7 +21,7 @@ const sepoliaNetwork = {
url: "https://rpc-sepolia.rockx.com",
dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
messager: "0xc876D0873e4060472334E297b2db200Ca10cc806",
issuing: "0xFF3bc7372A8011CFaD43D240464ef2fe74C59b86",
issuing: "0xf22D0bb66b39745Ae6e3fEa3E5859d7f0b367Fd1",
chainid: 11155111
};

Expand Down
4 changes: 2 additions & 2 deletions helix-contract/deploy/deploy_xtoken_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ async function deployxTokenIssuing(wallet, deployerAddress, salt) {
async function main() {
// deploy backing on crab
const walletCrab = wallet(crabNetwork.url);
const backingLogic = await deployxTokenBacking(walletCrab, crabNetwork.deployer, "xTokenBacking-logic-v1.0.1");
const backingLogic = await deployxTokenBacking(walletCrab, crabNetwork.deployer, "xTokenBacking-logic-v1.0.3");

// deploy issuing on sepolia
const walletSpeolia = wallet(sepoliaNetwork.url);
const issuingLogic = await deployxTokenIssuing(walletSpeolia, sepoliaNetwork.deployer, "xTokenIssuing-logic-v1.0.0");
const issuingLogic = await deployxTokenIssuing(walletSpeolia, sepoliaNetwork.deployer, "xTokenIssuing-logic-v1.0.3");
}

main()
Expand Down
8 changes: 4 additions & 4 deletions helix-contract/deploy/deploy_xtoken_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ async function deployxTokenProxy(wallet, salt, dao, proxyAdminAddress, logicAddr

async function deploy() {
const walletCrab = wallet(crabNetwork.url);
const backingLogic = "0xF2274a80e93075ccD5E2Af8F07beF370Bb6dfac7";
await deployxTokenProxy(walletCrab, "xtoken-backing-1.0.1", crabNetwork.dao, crabNetwork.proxyAdmin, backingLogic, crabNetwork.deployer);
const backingLogic = "0x22E50D0511538B78D4E3b94d4D51AFDa924286D0";
await deployxTokenProxy(walletCrab, "xtoken-backing-1.0.4", crabNetwork.dao, crabNetwork.proxyAdmin, backingLogic, crabNetwork.deployer);

const walletSepolia = wallet(sepoliaNetwork.url);
const issuingLogic = "0x1c955644c527BAA5a28255bCf9F7D3635B7ad99b";
await deployxTokenProxy(walletSepolia, "xtoken-issuing-1.0.1", sepoliaNetwork.dao, sepoliaNetwork.proxyAdmin, issuingLogic, sepoliaNetwork.deployer);
const issuingLogic = "0xCD1c1C799f3914ECFC5e3653D3Cc846355d3dFC9";
await deployxTokenProxy(walletSepolia, "xtoken-issuing-1.0.4", sepoliaNetwork.dao, sepoliaNetwork.proxyAdmin, issuingLogic, sepoliaNetwork.deployer);
}

async function main() {
Expand Down

0 comments on commit acc39a8

Please sign in to comment.