Skip to content

Commit

Permalink
(fix) reorganise source code to be more similar to the way the XBridg…
Browse files Browse the repository at this point in the history
…e repo is laid out
  • Loading branch information
rrw-zilliqa committed Jul 29, 2024
1 parent 512a64d commit bf2067e
Show file tree
Hide file tree
Showing 36 changed files with 1,686 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {TokenManagerUpgradeable, ITokenManager} from "contracts/periphery/TokenManagerUpgradeable.sol";
import { ILockProxyTokenManagerStorage, LockProxyTokenManagerStorage } from "contracts/zilbridge/2/LockProxyTokenManagerStorage.sol";
import { ILockProxyTokenManagerStorage, LockProxyTokenManagerStorage } from "contracts/periphery/LockProxyTokenManagerStorage.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ILockProxyTokenManager is ITokenManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@ pragma solidity ^0.8.20;

import {TokenManagerUpgradeableV3, ITokenManager} from "contracts/periphery/TokenManagerV3/TokenManagerUpgradeableV3.sol";
import {BridgedToken} from "contracts/periphery/BridgedToken.sol";
import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol";
import {IERC20} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol";
import { ILockProxyTokenManagerStorage, LockProxyTokenManagerStorage } from "contracts/zilbridge/2/LockProxyTokenManagerStorage.sol";
import { ILockProxyTokenManagerStorage, LockProxyTokenManagerStorage } from "contracts/periphery/LockProxyTokenManagerStorage.sol";

interface ILockProxyTokenManager is ILockProxyTokenManagerStorage {
// Args in this order to match other token managers.
event SentToLockProxy(address indexed token, address indexed sender, uint amount);
event WithdrawnFromLockProxy(address indexed token, address indexed receipient, uint amount);
}

// Exists purely so that we can call the extensionTransfer() endpoint on the lock proxy without having
// to include its code here.
interface ILockProxyExtensionTransfer {
function extensionTransfer(
address _receivingAddress,
address _assetHash,
uint256 _amount
)
external
returns (bool);
}

// This is the lock proxy token manager that runs on EVM chains. It talks to an EVM LockProxy.
contract LockProxyTokenManagerUpgradeableV3 is TokenManagerUpgradeableV3, ILockProxyTokenManager, LockProxyTokenManagerStorage {
address public constant NATIVE_ASSET_HASH = address(0);
Expand Down Expand Up @@ -43,7 +54,7 @@ contract LockProxyTokenManagerUpgradeableV3 is TokenManagerUpgradeableV3, ILockP

function _handleAccept(address token, address recipient, uint amount) internal override {
address lockProxyAddress = getLockProxy();
LockProxy lp = LockProxy(payable(lockProxyAddress));
ILockProxyExtensionTransfer lp = ILockProxyExtensionTransfer(payable(lockProxyAddress));
// Sadly, extensionTransfer() takes the same arguments as the withdrawn event but in a
// different order. This will automagically transfer native token if token==0.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.20;

import { Utils, ZeroCopySink, IEthCrossChainManager, IUpgradableECCM,
UpgradableECCM, IEthCrossChainData, EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol";
UpgradableECCM, IEthCrossChainData, EthCrossChainManager } from "contracts/periphery/ZilBridge/ccmCrossChainManager.sol";
import { Ownable } from "lib/openzeppelin-contracts/contracts/access/Ownable.sol";


Expand Down

This file was deleted.

12 changes: 6 additions & 6 deletions smart-contracts/script/bsc-testnet/deployMockZilBridge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {Script} from "forge-std/Script.sol";
import "forge-std/console.sol";
import {Tester} from "test/Tester.sol";
import {TestToken} from "test/Helpers.sol";
import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol";
import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol";
import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol";
import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxy } from "test/zilbridge/infrastructure/lockProxy.sol";
import { EthCrossChainManagerProxy } from "test/zilbridge/infrastructure/ccmProxy.sol";
import { EthCrossChainManager } from "test/zilbridge/infrastructure/ccmCrossChainManager.sol";
import { EthCrossChainData } from "test/zilbridge/infrastructure/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/periphery/ZilBridge/ccmExtendCrossChainManager.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {Script} from "forge-std/Script.sol";
import "forge-std/console.sol";
import {Tester} from "test/Tester.sol";
import {TestToken} from "test/Helpers.sol";
import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol";
import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol";
import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol";
import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxy } from "test/zilbridge/infrastructure/lockProxy.sol";
import { EthCrossChainManagerProxy } from "test/zilbridge/infrastructure/ccmProxy.sol";
import { EthCrossChainManager } from "test/zilbridge/infrastructure/ccmCrossChainManager.sol";
import { EthCrossChainData } from "test/zilbridge/infrastructure/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/periphery/ZilBridge/ccmExtendCrossChainManager.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import {Script} from "forge-std/Script.sol";
import "forge-std/console.sol";
import {Tester} from "test/Tester.sol";
import {TestToken} from "test/Helpers.sol";
import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol";
import { LockProxy } from "test/zilbridge/infrastructure/lockProxy.sol";
import { TestingLockProxy } from "test/zilbridge/TestingLockProxy.sol";
import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol";
import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol";
import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol";
import { EthCrossChainManagerProxy } from "test/zilbridge/infrastructure/ccmProxy.sol";
import { EthCrossChainManager } from "test/zilbridge/infrastructure/ccmCrossChainManager.sol";
import { EthCrossChainData } from "test/zilbridge/infrastructure/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/periphery/ZilBridge/ccmExtendCrossChainManager.sol";
import { ChainGateway } from "contracts/core/ChainGateway.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerDeployer} from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol";
import {MintAndBurnTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/MintAndBurnTokenManagerDeployer.sol";
import {LockAndReleaseTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/LockAndReleaseTokenManagerDeployer.sol";
import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol";
import { SwitcheoToken } from "test/zilbridge/tokens/switcheo/tokens/SwitcheoTokenETH.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";

/*** @notice Deploy token managers over the extension manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {MintAndBurnTokenManagerUpgradeable} from "contracts/periphery/MintAndBur
import {ITokenManagerStructs} from "contracts/periphery/TokenManagerUpgradeable.sol";
import {BridgedToken} from "contracts/periphery/BridgedToken.sol";
import { ERC20 } from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol";
import { SwitcheoToken } from "test/zilbridge/tokens/switcheo/tokens/SwitcheoTokenETH.sol";
import "forge-std/console.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";

Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/script/bsc-testnet/pauseBridge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {MintAndBurnTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/MintAndBurnTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";
import "forge-std/console.sol";

Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/script/bsc-testnet/setZilBridgeRouting.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {MintAndBurnTokenManagerUpgradeable} from "contracts/periphery/MintAndBur
import {ITokenManagerStructs} from "contracts/periphery/TokenManagerUpgradeable.sol";
import {BridgedToken} from "contracts/periphery/BridgedToken.sol";
import { ERC20 } from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol";
import { SwitcheoToken } from "test/zilbridge/tokens/switcheo/tokens/SwitcheoTokenETH.sol";
import "forge-std/console.sol";
import {LockProxyTokenManagerUpgradeable} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeable.sol";
import {LockProxyTokenManagerUpgradeable} from "contracts/periphery/LockProxyTokenManagerUpgradeable.sol";
import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";

Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/script/bsc-testnet/unpauseBridge.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {MintAndBurnTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/MintAndBurnTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";
import "forge-std/console.sol";

Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/script/zq-testnet/deployZRC2ERC20.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
import {Script} from "forge-std/Script.sol";
import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import { ZRC2ProxyForZRC2 } from "test/zilbridge/zrc2erc20/ZRC2ProxyForZRC2.sol";
import { ZRC2ProxyForZRC2 } from "test/zilbridge/tokens/zrc2erc20/ZRC2ProxyForZRC2.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";
import "forge-std/console.sol";

Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/script/zq-testnet/setZilBridgeRouting.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {MintAndBurnTokenManagerUpgradeable} from "contracts/periphery/MintAndBur
import {ITokenManagerStructs} from "contracts/periphery/TokenManagerUpgradeable.sol";
import {BridgedToken} from "contracts/periphery/BridgedToken.sol";
import { ERC20 } from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol";
import { SwitcheoToken } from "test/zilbridge/tokens/switcheo/tokens/SwitcheoTokenETH.sol";
import "forge-std/console.sol";
import {LockProxyTokenManagerUpgradeable} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeable.sol";
import {LockProxyTokenManagerUpgradeable} from "contracts/periphery/LockProxyTokenManagerUpgradeable.sol";
import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";

Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/script/zq-testnet/zilBridgeDebug.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAnd
import {LockAndReleaseOrNativeTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol";
import {ITokenManagerStructs, ITokenManager} from "contracts/periphery/TokenManagerUpgradeable.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ZRC2ProxyForZRC2} from "test/zilbridge/zrc2erc20/ZRC2ProxyForZRC2.sol";
import {ZRC2ProxyForZRC2} from "test/zilbridge/tokens/zrc2erc20/ZRC2ProxyForZRC2.sol";
import "forge-std/console.sol";
import { TestnetConfig } from "script/testnetConfig.s.sol";
import {IERC20} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol";
Expand Down
12 changes: 6 additions & 6 deletions smart-contracts/test/zilbridge/DeployZilBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pragma solidity 0.8.20;
import "forge-std/console.sol";
import {Tester} from "test/Tester.sol";
import {TestToken} from "test/Helpers.sol";
import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol";
import { LockProxy } from "test/zilbridge/infrastructure/lockProxy.sol";
import { TestingLockProxy } from "./TestingLockProxy.sol";
import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol";
import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol";
import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import { EthCrossChainManagerProxy } from "test/zilbridge/infrastructure/ccmProxy.sol";
import { EthCrossChainManager } from "test/zilbridge/infrastructure/ccmCrossChainManager.sol";
import { EthCrossChainData } from "test/zilbridge/infrastructure/ethCrossChainData.sol";
import { EthExtendCrossChainManager } from "contracts/periphery/ZilBridge/ccmExtendCrossChainManager.sol";
import { LockProxyTokenManagerUpgradeableV3 } from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol";

abstract contract ZilBridgeFixture is Tester, LockProxyTokenManagerDeployer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
pragma solidity 0.8.20;

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeable} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeable.sol";
import { ZilliqaLockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/ZilliqaLockProxyManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeable} from "contracts/periphery/LockProxyTokenManagerUpgradeable.sol";

abstract contract LockProxyTokenManagerDeployer {

Expand All @@ -29,24 +28,7 @@ abstract contract LockProxyTokenManagerDeployer {
return LockProxyTokenManagerUpgradeableV3(address(proxy));
}

function deployZilliqaLockProxyTokenManagerV3(
address chainGateway,
address lockProxyAddress,
uint fees) public returns (ZilliqaLockProxyTokenManagerUpgradeableV3) {
LockProxyTokenManagerUpgradeable proxy = deployLockProxyTokenManagerUpgradeable(chainGateway, lockProxyAddress);
address newImplementation = address(new ZilliqaLockProxyTokenManagerUpgradeableV3());
bytes memory encodedInitializerCall = abi.encodeCall(
ZilliqaLockProxyTokenManagerUpgradeableV3.reinitialize, fees);
proxy.upgradeToAndCall(newImplementation, encodedInitializerCall);
return ZilliqaLockProxyTokenManagerUpgradeableV3(address(proxy));
}

function deployLatestLockProxyTokenManager(address chainGateway, address lockProxy, uint fees) public returns (LockProxyTokenManagerUpgradeableV3) {
return deployLockProxyTokenManagerV3(chainGateway, lockProxy, fees);
}

function deployLatestZilliqaLockProxyTokenManager(address chainGateway, address lockProxy, uint fees) public returns (ZilliqaLockProxyTokenManagerUpgradeableV3) {
return deployZilliqaLockProxyTokenManagerV3(chainGateway, lockProxy, fees);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {ValidatorManager} from "contracts/core/ValidatorManager.sol";
import {ChainGateway} from "contracts/core/ChainGateway.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {TestToken} from "test/Helpers.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import {LockProxyTokenManagerDeployer} from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol";
import {MintAndBurnTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/MintAndBurnTokenManagerDeployer.sol";
import {LockAndReleaseTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/LockAndReleaseTokenManagerDeployer.sol";
import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol";
import { SwitcheoToken } from "test/zilbridge/tokens/switcheo/tokens/SwitcheoTokenETH.sol";
import { ZilBridgeFixture } from "test/zilbridge/DeployZilBridge.t.sol";
import { MockLockProxy } from "./MockLockProxy.sol";
import { ZilBridgeTokenBridgeIntegrationFixture } from "./ZilBridgeTokenIntegrationFixture.t.sol";
Expand Down
Loading

0 comments on commit bf2067e

Please sign in to comment.