-
Notifications
You must be signed in to change notification settings - Fork 51
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
add PolyERC20Factory contract #19
Open
Nemeswat
wants to merge
7
commits into
defi-wonderland:main
Choose a base branch
from
Nemeswat:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor(string memory name, string memory symbol) ERC20(name, symbol) UniversalChanIbcApp() {} function mint(address account, uint256 amount) public onlyOwner { function mint(address account, uint256 amount) public virtual onlyOwner { _mint(account, amount); } function burn(address account, uint256 amount) public onlyOwner { function burn(address account, uint256 amount) public virtual onlyOwner { _burn(account, amount); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import './UniversalChanIbcApp.sol'; import {PolyERC20} from './PolyERC20.sol'; import {receiverNotOriginPacketSender} from '@open-ibc/vibc-core-smart-contracts/contracts/libs/Ibc.sol'; contract PolyERC20FixedSupply is PolyERC20 { constructor(string memory _name, string memory _symbol, uint256 tokenSupply) PolyERC20(_name, _symbol) { _mint(msg.sender, tokenSupply); } function mint(address account, uint256 amount) public virtual override onlyOwner { revert('minting disabled'); } function burn(address account, uint256 amount) public virtual override onlyOwner { revert('burning disabled'); } } contract PolyERC20Factory is UniversalChanIbcApp { event TokenMint(address indexed token, address indexed receiver, uint256 amount); event BridgeSuccess(bytes32 indexed channelId); event BridgeFailure(bytes32 indexed channelId); constructor() UniversalChanIbcApp() {} function deployXPolyERC20( string[] memory channels, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply ) external returns (PolyERC20FixedSupply token) { return this.deployXPolyERC20(channels, _name, _symbol, _salt, _tokenSupply, 60); } function deployXPolyERC20( string[] memory channels, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply, uint64 timeoutSeconds ) external returns (PolyERC20FixedSupply token) { // deploy on the current chain token = this.deployPolyERC20(_name, _symbol, _salt, _tokenSupply); // deploy to other chains for (uint256 i = 0; i < channels.length; i++) { bytes memory payload = abi.encode(msg.sender, _name, _symbol, _salt, _tokenSupply); uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * 1_000_000_000); IbcUniversalPacketSender(mw).sendUniversalPacket( IbcUtils.toBytes32(channels[i]), IbcUtils.toBytes32(address(this)), payload, timeoutTimestamp ); } return token; } function deployPolyERC20( string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply ) external returns (PolyERC20FixedSupply token) { token = new PolyERC20FixedSupply{salt: _salt}(_name, _symbol, _tokenSupply); return token; } function onRecvUniversalPacket( bytes32 channelId, UniversalPacket calldata packet ) external override onlyIbcMw returns (AckPacket memory ackPacket) { if (packet.srcPortAddr != packet.destPortAddr) { revert receiverNotOriginPacketSender(); } (address sender, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply) = abi.decode(packet.appData, (address, string, string, bytes32, uint256)); PolyERC20FixedSupply token = this.deployPolyERC20(_name, _symbol, _salt, _tokenSupply); emit TokenMint(address(token), sender, _tokenSupply); return AckPacket(true, abi.encode(address(this))); } function onUniversalAcknowledgement( bytes32 channelId, UniversalPacket memory packet, AckPacket calldata ack ) external override onlyIbcMw { if (packet.srcPortAddr != packet.destPortAddr) { revert receiverNotOriginPacketSender(); } (address sender, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply) = abi.decode(packet.appData, (address, string, string, bytes32, uint256)); if (ack.success) { emit BridgeSuccess(channelId); (address receiver) = abi.decode(ack.data, (address)); } else { emit BridgeFailure(channelId); } } function onTimeoutUniversalPacket(bytes32 channelId, UniversalPacket calldata packet) external override onlyIbcMw { if (packet.srcPortAddr != packet.destPortAddr) { revert receiverNotOriginPacketSender(); } (address sender, string memory _name, string memory _symbol, string memory _salt, uint256 _tokenSupply) = abi.decode(packet.appData, (address, string, string, string, uint256)); emit BridgeFailure(channelId); } }
@@ -5,6 +5,7 @@ import 'forge-std/Script.sol'; import {IbcMwUser} from '@open-ibc/vibc-core-smart-contracts/contracts/interfaces/IbcMiddleware.sol'; import '../contracts/PolyERC20.sol'; import './XERC20Deploy.sol'; import '../contracts/PolyERC20Factory.sol'; contract PolyERC20Deploy is Script { using stdJson for string; @@ -15,7 +16,7 @@ contract PolyERC20Deploy is Script { return keccak256(bytes(vm.envString('SALT'))); } function run() external { function deployPolyERC20() public { string memory _json = vm.readFile('./solidity/scripts/xerc20-deployment-config.json'); DeploymentConfig memory _data = abi.decode(_json.parseRaw('.'), (DeploymentConfig)); @@ -47,4 +48,51 @@ contract PolyERC20Deploy is Script { vm.stopBroadcast(); } function deployPolyERC20WithFactory() public { string memory _json = vm.readFile('./solidity/scripts/xerc20-deployment-config.json'); DeploymentConfig memory _data = abi.decode(_json.parseRaw('.'), (DeploymentConfig)); uint256 baseFork = vm.createFork(vm.rpcUrl(vm.envString('BASE_SEPOLIA_RPC'))); uint256 opFork = vm.createFork(vm.rpcUrl(vm.envString('OPTIMISM_SEPOLIA_RPC'))); uint256 chainId = vm.envUint('CHAIN_ID'); if (chainId == 84_532) { string[] memory channels = new string[](1); channels[0] = 'channel-11'; vm.selectFork(baseFork); vm.startBroadcast(deployer); IbcMwUser baseMW = IbcMwUser(payable(vm.envAddress('BASE_UC_MW_SIM'))); PolyERC20Factory factory = new PolyERC20Factory{salt: salt()}(); factory.setDefaultMw(address(baseMW)); PolyERC20FixedSupply basePolyToken = factory.deployXPolyERC20(channels, _data.name, _data.symbol, salt(), 1_000_000_000); // solhint-disable-next-line no-console console.log('factory deployed on Base chain at:', address(factory)); // solhint-disable-next-line no-console console.log('PolyERC20 token deployed on Base chain at:', address(basePolyToken)); } if (chainId == 11_155_420) { string[] memory channels = new string[](1); channels[0] = 'channel-10'; vm.selectFork(opFork); vm.startBroadcast(deployer); IbcMwUser opMW = IbcMwUser(payable(vm.envAddress('OP_UC_MW_SIM'))); PolyERC20Factory factory = new PolyERC20Factory{salt: salt()}(); factory.setDefaultMw(address(opMW)); // solhint-disable-next-line no-console console.log('factory deployed on Optimism chain at:', address(factory)); } vm.stopBroadcast(); } function run() external { deployPolyERC20(); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; import './UniversalChanIbcApp.sol'; import {PolyERC20} from './PolyERC20.sol'; import {receiverNotOriginPacketSender} from '@open-ibc/vibc-core-smart-contracts/contracts/libs/Ibc.sol'; contract PolyERC20FixedSupply is PolyERC20 { constructor(string memory _name, string memory _symbol, uint256 tokenSupply) PolyERC20(_name, _symbol) { _mint(msg.sender, tokenSupply); } function mint(address account, uint256 amount) public virtual override onlyOwner { revert('minting disabled'); } function burn(address account, uint256 amount) public virtual override onlyOwner { revert('burning disabled'); } } contract PolyERC20Factory is UniversalChanIbcApp { event TokenMint(address indexed token, address indexed receiver, uint256 amount); event BridgeSuccess(bytes32 indexed channelId); event BridgeFailure(bytes32 indexed channelId); constructor() UniversalChanIbcApp() {} function deployXPolyERC20( string[] memory channels, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply ) external returns (PolyERC20FixedSupply token) { return this.deployXPolyERC20(channels, _name, _symbol, _salt, _tokenSupply, 60); } function deployXPolyERC20( string[] memory channels, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply, uint64 timeoutSeconds ) external returns (PolyERC20FixedSupply token) { // deploy on the current chain token = this.deployPolyERC20(_name, _symbol, _salt, _tokenSupply); // deploy to other chains for (uint256 i = 0; i < channels.length; i++) { bytes memory payload = abi.encode(msg.sender, _name, _symbol, _salt, _tokenSupply); uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * 1_000_000_000); IbcUniversalPacketSender(mw).sendUniversalPacket( IbcUtils.toBytes32(channels[i]), IbcUtils.toBytes32(address(this)), payload, timeoutTimestamp ); } return token; } function deployPolyERC20( string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply ) external returns (PolyERC20FixedSupply token) { token = new PolyERC20FixedSupply{salt: _salt}(_name, _symbol, _tokenSupply); return token; } function onRecvUniversalPacket( bytes32 channelId, UniversalPacket calldata packet ) external override onlyIbcMw returns (AckPacket memory ackPacket) { if (packet.srcPortAddr != packet.destPortAddr) { revert receiverNotOriginPacketSender(); } (address sender, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply) = abi.decode(packet.appData, (address, string, string, bytes32, uint256)); PolyERC20FixedSupply token = this.deployPolyERC20(_name, _symbol, _salt, _tokenSupply); emit TokenMint(address(token), sender, _tokenSupply); return AckPacket(true, abi.encode(address(this))); } function onUniversalAcknowledgement( bytes32 channelId, UniversalPacket memory packet, AckPacket calldata ack ) external override onlyIbcMw { if (packet.srcPortAddr != packet.destPortAddr) { revert receiverNotOriginPacketSender(); } (address sender, string memory _name, string memory _symbol, bytes32 _salt, uint256 _tokenSupply) = abi.decode(packet.appData, (address, string, string, bytes32, uint256)); if (ack.success) { emit BridgeSuccess(channelId); (address receiver) = abi.decode(ack.data, (address)); } else { emit BridgeFailure(channelId); } } function onTimeoutUniversalPacket(bytes32 channelId, UniversalPacket calldata packet) external override onlyIbcMw { if (packet.srcPortAddr != packet.destPortAddr) { revert receiverNotOriginPacketSender(); } (address sender, string memory _name, string memory _symbol, string memory _salt, uint256 _tokenSupply) = abi.decode(packet.appData, (address, string, string, string, uint256)); emit BridgeFailure(channelId); } }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.