您正在查看: Cross chain-新手教程 分类下的文章

bsc-eth-swap 编译及部署测试

背景

项目后期需要准备一个ETH体系的资产IBC服务,设计要求轻量稳定安全。
前面对poly做过技术调研,相对去中心化,但导致运行和运维成本过高,以及近期出现的安全性问题,所以暂时搁置。
本片文章将针对BSC提供的Swap服务做技术调研,由于没有找到官方的部署文档,只有技术实现讲解,所以本篇文章将从合约代码,以及Swap程序代码阅读方向进行部署文档的反推整理。

合约实现包含了可升级合约的实现架构,相关技术细节可参考《使用OpenZeppelin编写可升级合约

本篇文章先做bsc-eth-swap项目的部署和测试整理,后面将针对服务做二次开发或者模式技术参考,目标是开发出一个ETH体系多链资产和NFT轻量的IBC服务,后期再迭代成多节点去中心化模式。

项目组成

项目合约:https://github.com/binance-chain/eth-bsc-swap-contracts.git
项目程序:https://github.com/binance-chain/bsc-eth-swap.git

官方文档

https://github.com/binance-chain/bsc-eth-swap/blob/main/docs/spec.md

编译合约

git clone https://github.com/binance-chain/eth-bsc-swap-contracts.git
cd eth-bsc-swap-contracts/
sudo npm i -g truffle
npm i
npm run truffle:compile

部署合约

为了方便测试,以及etherscan区块浏览器对于数据的展示较完整,所以我们选择的测试网络为

  • Goerli Test Network
  • Ropsten Test Network

ETH合约部署在Goerli(主),BSC合约部署在Ropsten(侧)

ETH链合约部署

部署网络

Goerli Test Network

部署ETHSwapAgentImpl合约

使用编译后的build\contracts\ETHSwapAgentImpl.json中的abibytecode部署合约。

ETHSwapAgentImpl ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"erc20Addr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"bscTxHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"toAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"SwapFilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sponsor","type":"address"},{"indexed":true,"internalType":"address","name":"erc20Addr","type":"address"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"string","name":"symbol","type":"string"},{"indexed":false,"internalType":"uint8","name":"decimals","type":"uint8"}],"name":"SwapPairRegister","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"erc20Addr","type":"address"},{"indexed":true,"internalType":"address","name":"fromAddr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"SwapStarted","type":"event"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"filledBSCTx","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"registeredERC20","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address payable","name":"ownerAddr","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"setSwapFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"erc20Addr","type":"address"}],"name":"registerSwapPairToBSC","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"bscTxHash","type":"bytes32"},{"internalType":"address","name":"erc20Addr","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"fillBSC2ETHSwap","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"erc20Addr","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"swapETH2BSC","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"}]
ETHSwapAgentImpl bytecode
0x608060405234801561001057600080fd5b506112d7806100206000396000f3fe60806040526004361061009c5760003560e01c806389b156041161006457806389b156041461017a5780638da5cb5b146101ad5780639867df11146101de578063b9927a9c14610227578063da35a26f14610253578063f2fde38b1461028c5761009c565b806334e19907146100a157806350877c77146100cd57806354cf2aeb1461010b5780635c13c15114610132578063715018a614610165575b600080fd5b3480156100ad57600080fd5b506100cb600480360360208110156100c457600080fd5b50356102bf565b005b3480156100d957600080fd5b506100f7600480360360208110156100f057600080fd5b503561031c565b604080519115158252519081900360200190f35b34801561011757600080fd5b50610120610331565b60408051918252519081900360200190f35b34801561013e57600080fd5b506100f76004803603602081101561015557600080fd5b50356001600160a01b0316610337565b34801561017157600080fd5b506100cb61081e565b34801561018657600080fd5b506100f76004803603602081101561019d57600080fd5b50356001600160a01b03166108c0565b3480156101b957600080fd5b506101c26108d5565b604080516001600160a01b039092168252519081900360200190f35b3480156101ea57600080fd5b506100f76004803603608081101561020157600080fd5b508035906001600160a01b036020820135811691604081013590911690606001356108e4565b6100f76004803603604081101561023d57600080fd5b506001600160a01b038135169060200135610a88565b34801561025f57600080fd5b506100cb6004803603604081101561027657600080fd5b50803590602001356001600160a01b0316610c94565b34801561029857600080fd5b506100cb600480360360208110156102af57600080fd5b50356001600160a01b0316610d58565b6102c7610e51565b6003546001600160a01b03908116911614610317576040805162461bcd60e51b81526020600482018190526024820152600080516020611258833981519152604482015290519081900360640190fd5b600455565b60026020526000908152604090205460ff1681565b60045481565b6001600160a01b03811660009081526001602052604081205460ff161561039a576040805162461bcd60e51b8152602060048201526012602482015271185b1c9958591e481c9959da5cdd195c995960721b604482015290519081900360640190fd5b6060826001600160a01b03166306fdde036040518163ffffffff1660e01b815260040160006040518083038186803b1580156103d557600080fd5b505afa1580156103e9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052602081101561041257600080fd5b810190808051604051939291908464010000000082111561043257600080fd5b90830190602082018581111561044757600080fd5b825164010000000081118282018810171561046157600080fd5b82525081516020918201929091019080838360005b8381101561048e578181015183820152602001610476565b50505050905090810190601f1680156104bb5780820380516001836020036101000a031916815260200191505b5060405250505090506060836001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b1580156104ff57600080fd5b505afa158015610513573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052602081101561053c57600080fd5b810190808051604051939291908464010000000082111561055c57600080fd5b90830190602082018581111561057157600080fd5b825164010000000081118282018810171561058b57600080fd5b82525081516020918201929091019080838360005b838110156105b85781810151838201526020016105a0565b50505050905090810190601f1680156105e55780820380516001836020036101000a031916815260200191505b5060405250505090506000846001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561062957600080fd5b505afa15801561063d573d6000803e3d6000fd5b505050506040513d602081101561065357600080fd5b50518351909150610698576040805162461bcd60e51b815260206004820152600a602482015269656d707479206e616d6560b01b604482015290519081900360640190fd5b60008251116106dd576040805162461bcd60e51b815260206004820152600c60248201526b195b5c1d1e481cde5b589bdb60a21b604482015290519081900360640190fd5b6001600160a01b0385166000818152600160208181526040808420805460ff1916909317909255815160ff8616928101929092526060808352875190830152865133937ffe3bd005e346323fa452df8cafc28c55b99e3766ba8750571d139c6cf5bc08a0938993899389938392838101926080850192918901918190849084905b8381101561077657818101518382015260200161075e565b50505050905090810190601f1680156107a35780820380516001836020036101000a031916815260200191505b50838103825285518152855160209182019187019080838360005b838110156107d65781810151838201526020016107be565b50505050905090810190601f1680156108035780820380516001836020036101000a031916815260200191505b509550505050505060405180910390a3506001949350505050565b610826610e51565b6003546001600160a01b03908116911614610876576040805162461bcd60e51b81526020600482018190526024820152600080516020611258833981519152604482015290519081900360640190fd5b6003546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600380546001600160a01b0319169055565b60016020526000908152604090205460ff1681565b6003546001600160a01b031681565b60006108ee610e51565b6003546001600160a01b0390811691161461093e576040805162461bcd60e51b81526020600482018190526024820152600080516020611258833981519152604482015290519081900360640190fd5b60008581526002602052604090205460ff161561099a576040805162461bcd60e51b81526020600482015260156024820152746273632074782066696c6c656420616c726561647960581b604482015290519081900360640190fd5b6001600160a01b03841660009081526001602052604090205460ff166109fe576040805162461bcd60e51b81526020600482015260146024820152733737ba103932b3b4b9ba32b932b2103a37b5b2b760611b604482015290519081900360640190fd5b6000858152600260205260409020805460ff19166001179055610a316001600160a01b038516848463ffffffff610e5516565b826001600160a01b031685856001600160a01b03167f3bebd9a738291e69898b5dbfadb6329b4b09fc648bdef68762928e521463abd9856040518082815260200191505060405180910390a4506001949350505050565b6000610a9333610ea7565b15610ae5576040805162461bcd60e51b815260206004820152601f60248201527f636f6e7472616374206973206e6f7420616c6c6f77656420746f207377617000604482015290519081900360640190fd5b333214610b39576040805162461bcd60e51b815260206004820152601c60248201527f6e6f2070726f787920636f6e747261637420697320616c6c6f77656400000000604482015290519081900360640190fd5b6001600160a01b03831660009081526001602052604090205460ff16610b9d576040805162461bcd60e51b81526020600482015260146024820152733737ba103932b3b4b9ba32b932b2103a37b5b2b760611b604482015290519081900360640190fd5b6004543414610be8576040805162461bcd60e51b81526020600482015260126024820152711cddd85c08199959481b9bdd08195c5d585b60721b604482015290519081900360640190fd5b610c036001600160a01b03841633308563ffffffff610ead16565b3415610c44576003546040516001600160a01b03909116903480156108fc02916000818181858888f19350505050158015610c42573d6000803e3d6000fd5b505b60408051838152346020820152815133926001600160a01b038716927ff60309f865a6aa297da5fac6188136a02e5acfdf6e8f6d35257a9f4e9653170f929081900390910190a350600192915050565b600054610100900460ff1680610cad5750610cad610f0d565b80610cbb575060005460ff16155b610cf65760405162461bcd60e51b815260040180806020018281038252602e81526020018061122a602e913960400191505060405180910390fd5b600054610100900460ff16158015610d21576000805460ff1961ff0019909116610100171660011790555b6004839055600380546001600160a01b0319166001600160a01b0384161790558015610d53576000805461ff00191690555b505050565b610d60610e51565b6003546001600160a01b03908116911614610db0576040805162461bcd60e51b81526020600482018190526024820152600080516020611258833981519152604482015290519081900360640190fd5b6001600160a01b038116610df55760405162461bcd60e51b81526004018080602001828103825260268152602001806111de6026913960400191505060405180910390fd5b6003546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600380546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610d53908490610f13565b3b151590565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610f07908590610f13565b50505050565b303b1590565b6060610f68826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610fc49092919063ffffffff16565b805190915015610d5357808060200190516020811015610f8757600080fd5b5051610d535760405162461bcd60e51b815260040180806020018281038252602a815260200180611278602a913960400191505060405180910390fd5b6060610fd38484600085610fdd565b90505b9392505050565b60608247101561101e5760405162461bcd60e51b81526004018080602001828103825260268152602001806112046026913960400191505060405180910390fd5b61102785610ea7565b611078576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b602083106110b75780518252601f199092019160209182019101611098565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611119576040519150601f19603f3d011682016040523d82523d6000602084013e61111e565b606091505b509150915061112e828286611139565b979650505050505050565b60608315611148575081610fd6565b8251156111585782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156111a257818101518382015260200161118a565b50505050905090810190601f1680156111cf5780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a65644f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a26469706673582212207d800cfe9cc73238c171437c8cfab5dbce431b61738d8c89459b39acb1d5769064736f6c63430006040033

部署后的地址是0x4e99e2A70664f30d14b1f703b8bbe077872F5Fb7

部署ETHSwapAgentUpgradeableProxy合约

使用编译后的build\contracts\ETHSwapAgentUpgradeableProxy.json中的abibytecode部署合约。

ETHSwapAgentUpgradeableProxy abi
[{"inputs":[{"internalType":"address","name":"logic","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"admin_","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"changeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"implementation_","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
ETHSwapAgentUpgradeableProxy bytecode
0x608060405234801561001057600080fd5b506040516109b33803806109b38339818101604052606081101561003357600080fd5b8151602083015160408085018051915193959294830192918464010000000082111561005e57600080fd5b90830190602082018581111561007357600080fd5b825164010000000081118282018810171561008d57600080fd5b82525081516020918201929091019080838360005b838110156100ba5781810151838201526020016100a2565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b5060408181527f656970313936372e70726f78792e696d706c656d656e746174696f6e0000000082525190819003601c0190208693508592508491508390829060008051602061095d8339815191526000199091011461014357fe5b610155826001600160e01b0361027a16565b80511561020d576000826001600160a01b0316826040518082805190602001908083835b602083106101985780518252601f199092019160209182019101610179565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d80600081146101f8576040519150601f19603f3d011682016040523d82523d6000602084013e6101fd565b606091505b505090508061020b57600080fd5b505b5050604080517f656970313936372e70726f78792e61646d696e000000000000000000000000008152905190819003601301902060008051602061093d8339815191526000199091011461025d57fe5b61026f826001600160e01b036102da16565b5050505050506102f2565b61028d816102ec60201b61054e1760201c565b6102c85760405162461bcd60e51b815260040180806020018281038252603681526020018061097d6036913960400191505060405180910390fd5b60008051602061095d83398151915255565b60008051602061093d83398151915255565b3b151590565b61063c806103016000396000f3fe60806040526004361061004e5760003560e01c80633659cfe6146100655780634f1ef286146100985780635c60da1b146101185780638f28397014610149578063f851a4401461017c5761005d565b3661005d5761005b610191565b005b61005b610191565b34801561007157600080fd5b5061005b6004803603602081101561008857600080fd5b50356001600160a01b03166101ab565b61005b600480360360408110156100ae57600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156100d957600080fd5b8201836020820111156100eb57600080fd5b8035906020019184600183028401116401000000008311171561010d57600080fd5b5090925090506101e5565b34801561012457600080fd5b5061012d610292565b604080516001600160a01b039092168252519081900360200190f35b34801561015557600080fd5b5061005b6004803603602081101561016c57600080fd5b50356001600160a01b03166102cf565b34801561018857600080fd5b5061012d610389565b6101996103b4565b6101a96101a4610414565b610439565b565b6101b361045d565b6001600160a01b0316336001600160a01b031614156101da576101d581610482565b6101e2565b6101e2610191565b50565b6101ed61045d565b6001600160a01b0316336001600160a01b031614156102855761020f83610482565b6000836001600160a01b031683836040518083838082843760405192019450600093509091505080830381855af49150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b606091505b505090508061027f57600080fd5b5061028d565b61028d610191565b505050565b600061029c61045d565b6001600160a01b0316336001600160a01b031614156102c4576102bd610414565b90506102cc565b6102cc610191565b90565b6102d761045d565b6001600160a01b0316336001600160a01b031614156101da576001600160a01b0381166103355760405162461bcd60e51b815260040180806020018281038252603a815260200180610555603a913960400191505060405180910390fd5b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61035e61045d565b604080516001600160a01b03928316815291841660208301528051918290030190a16101d5816104c2565b600061039361045d565b6001600160a01b0316336001600160a01b031614156102c4576102bd61045d565b6103bc61045d565b6001600160a01b0316336001600160a01b0316141561040c5760405162461bcd60e51b81526004018080602001828103825260428152602001806105c56042913960600191505060405180910390fd5b6101a96101a9565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b3660008037600080366000845af43d6000803e808015610458573d6000f35b3d6000fd5b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b61048b816104e6565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610355565b6104ef8161054e565b61052a5760405162461bcd60e51b815260040180806020018281038252603681526020018061058f6036913960400191505060405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55565b3b15159056fe5472616e73706172656e745570677261646561626c6550726f78793a206e65772061646d696e20697320746865207a65726f20616464726573735570677261646561626c6550726f78793a206e657720696d706c656d656e746174696f6e206973206e6f74206120636f6e74726163745472616e73706172656e745570677261646561626c6550726f78793a2061646d696e2063616e6e6f742066616c6c6261636b20746f2070726f787920746172676574a2646970667358221220b76161e075f62521c54fef8e9af35ad8ae87258a9bd53744da1e6ed02b2aa47d64736f6c63430006040033b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5570677261646561626c6550726f78793a206e657720696d706c656d656e746174696f6e206973206e6f74206120636f6e7472616374
部署参数
  • _logic (逻辑合约,也就是上面部署的ETHSwapAgentImpl合约地址)0x4e99e2A70664f30d14b1f703b8bbe077872F5Fb7
  • Admin_ (升级管理权限地址,需要一个单独的地址,只用于升级合约,不能与当前部署ETHSwapAgentImpl合约的ownerAddr地址相同)0x48F155527f25EB1d4cb2aa32b7e84692AA0025C0
  • _data (ETHSwapAgentImpl合约中的initialize初始化bytes数据)
    ETHSwapAgentImpl中的initialize实现如下
    function initialize(uint256 fee, address payable ownerAddr) public initializer {
      swapFee = fee;
      owner = ownerAddr;
    }

    其中的ownerAddr为逻辑合约管理权限地址,切记不能与升级管理权限地址相同,否则无法执行。fee为跨链需要缴纳的手续费。
    简单说就是部署ETHSwapAgentUpgradeableProxy合约时,会把ETHSwapAgentImpl合约一同初始化{_logic.delegatecall(_data)},此时测试时预定的参数如下

    • fee = 100000000
    • ownerAddr = 0xbb93FcC2bB90D46255c43DD398A1A372E12bE6Aa
      此时计算_data如下
      web3js.eth.abi.encodeFunctionCall({
      name: 'initialize',
      type: 'function',
      inputs: [{
        type: 'uint256',
        name: 'fee'
      },{
        type: 'address',
        name: 'ownerAddr'
      }]
      }, [100000000, '0xbb93FcC2bB90D46255c43DD398A1A372E12bE6Aa']);

      得到

      0xda35a26f0000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000bb93fcc2bb90d46255c43dd398a1a372e12be6aa

最终三个参数为

  • _logic0x4e99e2A70664f30d14b1f703b8bbe077872F5Fb7
  • Admin_0x48F155527f25EB1d4cb2aa32b7e84692AA0025C0
  • _data0xda35a26f0000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000bb93fcc2bb90d46255c43dd398a1a372e12be6aa

部署后的地址是0x31366023017888A1ef48ca60cbB5de26aCBe6b02

测试ETHSwapAgentImpl合约

通过逻辑合约管理权限地址0xbb93FcC2bB90D46255c43DD398A1A372E12bE6Aa使用ETHSwapAgentImpl ABI访问ETHSwapAgentUpgradeableProxy部署地址0x31366023017888A1ef48ca60cbB5de26aCBe6b02

  1. 查询swapFee等于100000000,然后使用setSwapFee修改值为100000000000000,再次查询确认值与修改值相同
  2. 使用registerSwapPairToBSC注册已发行ERC20代币,代币地址0x8ee79e91b1f7b882941f0c11bb91a760134bc644,并通过registeredERC20确认注册成功

测试ETHSwapAgentUpgradeableProxy合约

通过升级合约管理权限地址0x48F155527f25EB1d4cb2aa32b7e84692AA0025C0使用ETHSwapAgentUpgradeableProxy ABI访问ETHSwapAgentUpgradeableProxy部署地址0x31366023017888A1ef48ca60cbB5de26aCBe6b02

  1. 使用changeAdmin修改当前升级合约管理权限地址0x10210572d6b4924Af7Ef946136295e9b209E1FA0,然后验证权限生效,再修改回0x48F155527f25EB1d4cb2aa32b7e84692AA0025C0
    一定确认好执行的权限地址是对应的,否则只报执行合约出错
  2. ETHSwapAgentImp合约中增加一个方法,
    function hellowWord() public view returns (string memory) {
     return "https://www.bcskill.com";
    }

    并重新编译和部署,新部署的地址为0x63F27AEE1A7C228D05f67C43F6C5ED82d726b104
    使用upgradeTo修改新逻辑合约地址NewImplementation0x63F27AEE1A7C228D05f67C43F6C5ED82d726b104
    然后通过逻辑合约管理权限地址,使用修改后ETHSwapAgentImpl合约编译得到的ABI,访问ETHSwapAgentUpgradeableProxy部署地址0x31366023017888A1ef48ca60cbB5de26aCBe6b02,执行hellowWord
    正确返回https://www.bcskill.com
    并再次验证测试ETHSwapAgentImpl合约中的流程,保证结果都正确

此时ETHSwapAgent合约相关部署已完成,

BSC侧链合约部署

对于BSCSwapAgent相关侧链部署同理,再此不做详细讲解,只做数据的记录

部署网络

Ropsten Test Network

1. BEP20Token合约部署

BEP20TokenImplementation ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint8","name":"decimals","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"mintable","type":"bool"},{"internalType":"address","name":"owner","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mintable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"mintTo","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

BEP20TokenImplementation bytecode

0x608060405234801561001057600080fd5b506114b2806100206000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c8063715018a6116100ad578063a9059cbb11610071578063a9059cbb14610347578063b723b34e14610373578063dd62ed3e1461039f578063ef3ebcb8146103cd578063f2fde38b1461051957610121565b8063715018a6146102c8578063893d20e8146102d257806395d89b41146102f6578063a0712d68146102fe578063a457c2d71461031b57610121565b8063313ce567116100f4578063313ce56714610233578063395093511461025157806342966c681461027d5780634bf365df1461029a57806370a08231146102a257610121565b806306fdde0314610126578063095ea7b3146101a357806318160ddd146101e357806323b872dd146101fd575b600080fd5b61012e61053f565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610168578181015183820152602001610150565b50505050905090810190601f1680156101955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101cf600480360360408110156101b957600080fd5b506001600160a01b0381351690602001356105d6565b604080519115158252519081900360200190f35b6101eb6105f3565b60408051918252519081900360200190f35b6101cf6004803603606081101561021357600080fd5b506001600160a01b038135811691602081013590911690604001356105f9565b61023b610686565b6040805160ff9092168252519081900360200190f35b6101cf6004803603604081101561026757600080fd5b506001600160a01b03813516906020013561068f565b6101cf6004803603602081101561029357600080fd5b50356106e3565b6101cf6106fe565b6101eb600480360360208110156102b857600080fd5b50356001600160a01b031661070e565b6102d0610729565b005b6102da6107d6565b604080516001600160a01b039092168252519081900360200190f35b61012e6107ea565b6101cf6004803603602081101561031457600080fd5b503561084b565b6101cf6004803603604081101561033157600080fd5b506001600160a01b038135169060200135610919565b6101cf6004803603604081101561035d57600080fd5b506001600160a01b038135169060200135610987565b6101cf6004803603604081101561038957600080fd5b50803590602001356001600160a01b031661099b565b6101eb600480360360408110156103b557600080fd5b506001600160a01b0381358116916020013516610a62565b6102d0600480360360c08110156103e357600080fd5b8101906020810181356401000000008111156103fe57600080fd5b82018360208201111561041057600080fd5b8035906020019184600183028401116401000000008311171561043257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929594936020810193503591505064010000000081111561048557600080fd5b82018360208201111561049757600080fd5b803590602001918460018302840111640100000000831117156104b957600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295505050813560ff169250506020810135906040810135151590606001356001600160a01b0316610a8d565b6102d06004803603602081101561052f57600080fd5b50356001600160a01b0316610ba7565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105cb5780601f106105a0576101008083540402835291602001916105cb565b820191906000526020600020905b8154815290600101906020018083116105ae57829003601f168201915b505050505090505b90565b60006105ea6105e3610cb0565b8484610cb4565b50600192915050565b60035490565b6000610606848484610da0565b61067c84610612610cb0565b61067785604051806060016040528060288152602001611334602891396001600160a01b038a16600090815260026020526040812090610650610cb0565b6001600160a01b03168152602081019190915260400160002054919063ffffffff610efe16565b610cb4565b5060019392505050565b60065460ff1690565b60006105ea61069c610cb0565b8461067785600260006106ad610cb0565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff610f9516565b60006106f66106f0610cb0565b83610ff6565b506001919050565b600654600160a81b900460ff1690565b6001600160a01b031660009081526001602052604090205490565b610731610cb0565b60065461010090046001600160a01b03908116911614610786576040805162461bcd60e51b8152602060048201819052602482015260008051602061138a833981519152604482015290519081900360640190fd5b60065460405160009161010090046001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a360068054610100600160a81b0319169055565b60065461010090046001600160a01b031690565b60058054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156105cb5780601f106105a0576101008083540402835291602001916105cb565b6000610855610cb0565b60065461010090046001600160a01b039081169116146108aa576040805162461bcd60e51b8152602060048201819052602482015260008051602061138a833981519152604482015290519081900360640190fd5b600654600160a81b900460ff16610908576040805162461bcd60e51b815260206004820152601a60248201527f7468697320746f6b656e206973206e6f74206d696e7461626c65000000000000604482015290519081900360640190fd5b6106f6610913610cb0565b836110f2565b60006105ea610926610cb0565b84610677856040518060600160405280602581526020016113f36025913960026000610950610cb0565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff610efe16565b60006105ea610994610cb0565b8484610da0565b60006109a5610cb0565b60065461010090046001600160a01b039081169116146109fa576040805162461bcd60e51b8152602060048201819052602482015260008051602061138a833981519152604482015290519081900360640190fd5b600654600160a81b900460ff16610a58576040805162461bcd60e51b815260206004820152601a60248201527f7468697320746f6b656e206973206e6f74206d696e7461626c65000000000000604482015290519081900360640190fd5b6105ea82846110f2565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b600054610100900460ff1680610aa65750610aa66111e4565b80610ab4575060005460ff16155b610aef5760405162461bcd60e51b815260040180806020018281038252602e81526020018061135c602e913960400191505060405180910390fd5b600054610100900460ff16158015610b1a576000805460ff1961ff0019909116610100171660011790555b60068054610100600160a81b0319166101006001600160a01b038516021790558651610b4d9060049060208a019061122c565b508551610b6190600590602089019061122c565b506006805460ff191660ff87161760ff60a81b1916600160a81b85151502179055610b8c82856110f2565b8015610b9e576000805461ff00191690555b50505050505050565b610baf610cb0565b60065461010090046001600160a01b03908116911614610c04576040805162461bcd60e51b8152602060048201819052602482015260008051602061138a833981519152604482015290519081900360640190fd5b6001600160a01b038116610c495760405162461bcd60e51b815260040180806020018281038252602681526020018061130e6026913960400191505060405180910390fd5b6006546040516001600160a01b0380841692610100900416907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600680546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b3390565b6001600160a01b038316610cf95760405162461bcd60e51b81526004018080602001828103825260248152602001806112ea6024913960400191505060405180910390fd5b6001600160a01b038216610d3e5760405162461bcd60e51b815260040180806020018281038252602281526020018061145b6022913960400191505060405180910390fd5b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316610de55760405162461bcd60e51b81526004018080602001828103825260258152602001806112c56025913960400191505060405180910390fd5b6001600160a01b038216610e2a5760405162461bcd60e51b81526004018080602001828103825260238152602001806113d06023913960400191505060405180910390fd5b610e6d816040518060600160405280602681526020016113aa602691396001600160a01b038616600090815260016020526040902054919063ffffffff610efe16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054610ea2908263ffffffff610f9516565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b60008184841115610f8d5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610f52578181015183820152602001610f3a565b50505050905090810190601f168015610f7f5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b600082820183811015610fef576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b6001600160a01b03821661103b5760405162461bcd60e51b81526004018080602001828103825260218152602001806114186021913960400191505060405180910390fd5b61107e81604051806060016040528060228152602001611439602291396001600160a01b038516600090815260016020526040902054919063ffffffff610efe16565b6001600160a01b0383166000908152600160205260409020556003546110aa908263ffffffff6111ea16565b6003556040805182815290516000916001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9181900360200190a35050565b6001600160a01b03821661114d576040805162461bcd60e51b815260206004820152601f60248201527f42455032303a206d696e7420746f20746865207a65726f206164647265737300604482015290519081900360640190fd5b600354611160908263ffffffff610f9516565b6003556001600160a01b03821660009081526001602052604090205461118c908263ffffffff610f9516565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b303b1590565b6000610fef83836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250610efe565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061126d57805160ff191683800117855561129a565b8280016001018555821561129a579182015b8281111561129a57825182559160200191906001019061127f565b506112a69291506112aa565b5090565b6105d391905b808211156112a657600081556001016112b056fe42455032303a207472616e736665722066726f6d20746865207a65726f206164647265737342455032303a20617070726f76652066726f6d20746865207a65726f20616464726573734f776e61626c653a206e6577206f776e657220697320746865207a65726f206164647265737342455032303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a65644f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657242455032303a207472616e7366657220616d6f756e7420657863656564732062616c616e636542455032303a207472616e7366657220746f20746865207a65726f206164647265737342455032303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726f42455032303a206275726e2066726f6d20746865207a65726f206164647265737342455032303a206275726e20616d6f756e7420657863656564732062616c616e636542455032303a20617070726f766520746f20746865207a65726f2061646472657373a2646970667358221220d28ad019253e134d8321300a2878b923db889aa49087e15f1ec77fc72393491a64736f6c63430006040033

部署地址:0x41941cC749d561A13A3a8295f355033D23fDc060

2. BSCSwapAgent合约部署

BSCSwapAgentImpl合约ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"bep20Addr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"ethTxHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"toAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"SwapFilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"ethRegisterTxHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"bep20Addr","type":"address"},{"indexed":true,"internalType":"address","name":"erc20Addr","type":"address"},{"indexed":false,"internalType":"string","name":"symbol","type":"string"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"uint8","name":"decimals","type":"uint8"}],"name":"SwapPairCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"bep20Addr","type":"address"},{"indexed":true,"internalType":"address","name":"erc20Addr","type":"address"},{"indexed":true,"internalType":"address","name":"fromAddr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"}],"name":"SwapStarted","type":"event"},{"inputs":[],"name":"bep20Implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bep20ProxyAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"filledETHTx","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"swapMappingBSC2ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"swapMappingETH2BSC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"bep20Impl","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"address payable","name":"ownerAddr","type":"address"},{"internalType":"address","name":"bep20ProxyAdminAddr","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"name":"setSwapFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"ethTxHash","type":"bytes32"},{"internalType":"address","name":"erc20Addr","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"name":"createSwapPair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"ethTxHash","type":"bytes32"},{"internalType":"address","name":"erc20Addr","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"fillETH2BSCSwap","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bep20Addr","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"swapBSC2ETH","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"}]
BSCSwapAgentImpl合约bytecode
0x608060405234801561001057600080fd5b50611db3806100206000396000f3fe608060405260043610620000f25760003560e01c806360b810f1116200008b5780638da5cb5b11620000615780638da5cb5b146200039b578063be0ace6914620003b3578063e307b93114620003ea578063f2fde38b146200043757620000f2565b806360b810f1146200033457806366fec65c146200036b578063715018a6146200038357620000f2565b806334e1990711620000cd57806334e19907146200025f578063358394d8146200028f5780634e2dc7f114620002dc57806354cf2aeb146200030a57620000f2565b80630344165a14620000f75780631ba3b150146200012b57806332bd6e31146200016e575b600080fd5b3480156200010457600080fd5b506200010f6200046e565b604080516001600160a01b039092168252519081900360200190f35b6200015a600480360360408110156200014357600080fd5b506001600160a01b0381351690602001356200047d565b604080519115158252519081900360200190f35b3480156200017b57600080fd5b506200010f600480360360a08110156200019457600080fd5b8135916001600160a01b0360208201351691810190606081016040820135640100000000811115620001c557600080fd5b820183602082011115620001d857600080fd5b80359060200191846001830284011164010000000083111715620001fb57600080fd5b9193909290916020810190356401000000008111156200021a57600080fd5b8201836020820111156200022d57600080fd5b803590602001918460018302840111640100000000831117156200025057600080fd5b91935091503560ff1662000717565b3480156200026c57600080fd5b506200028d600480360360208110156200028557600080fd5b503562000a24565b005b3480156200029c57600080fd5b506200028d60048036036080811015620002b557600080fd5b506001600160a01b0381358116916020810135916040820135811691606001351662000a85565b348015620002e957600080fd5b506200015a600480360360208110156200030257600080fd5b503562000b75565b3480156200031757600080fd5b506200032262000b8a565b60408051918252519081900360200190f35b3480156200034157600080fd5b506200010f600480360360208110156200035a57600080fd5b50356001600160a01b031662000b90565b3480156200037857600080fd5b506200010f62000bab565b3480156200039057600080fd5b506200028d62000bba565b348015620003a857600080fd5b506200010f62000c60565b348015620003c057600080fd5b506200010f60048036036020811015620003d957600080fd5b50356001600160a01b031662000c6f565b348015620003f757600080fd5b506200015a600480360360808110156200041057600080fd5b508035906001600160a01b0360208201358116916040810135909116906060013562000c8a565b3480156200044457600080fd5b506200028d600480360360208110156200045d57600080fd5b50356001600160a01b031662000e9f565b6005546001600160a01b031681565b60006200048a3362000f9e565b15620004dd576040805162461bcd60e51b815260206004820152601f60248201527f636f6e7472616374206973206e6f7420616c6c6f77656420746f207377617000604482015290519081900360640190fd5b33321462000532576040805162461bcd60e51b815260206004820152601c60248201527f6e6f2070726f787920636f6e747261637420697320616c6c6f77656400000000604482015290519081900360640190fd5b6001600160a01b038084166000908152600260205260409020541680620005a0576040805162461bcd60e51b815260206004820152601b60248201527f6e6f2073776170207061697220666f72207468697320746f6b656e0000000000604482015290519081900360640190fd5b6007543414620005ec576040805162461bcd60e51b81526020600482015260126024820152711cddd85c08199959481b9bdd08195c5d585b60721b604482015290519081900360640190fd5b620006096001600160a01b03851633308663ffffffff62000fa416565b836001600160a01b03166342966c68846040518263ffffffff1660e01b815260040180828152602001915050602060405180830381600087803b1580156200065057600080fd5b505af115801562000665573d6000803e3d6000fd5b505050506040513d60208110156200067c57600080fd5b50503415620006c1576004546040516001600160a01b03909116903480156108fc02916000818181858888f19350505050158015620006bf573d6000803e3d6000fd5b505b60408051848152346020820152815133926001600160a01b0385811693908916927f49c08ff11118922c1e8298915531eff9ef6f8b39b44b3e9952b75d47e1d0cdd0929181900390910190a45060019392505050565b60006200072362001006565b6004546001600160a01b0390811691161462000775576040805162461bcd60e51b8152602060048201819052602482015260008051602062001d34833981519152604482015290519081900360640190fd5b6001600160a01b038781166000908152600160205260409020541615620007da576040805162461bcd60e51b8152602060048201526014602482015273323ab83634b1b0ba32b21039bbb0b8103830b4b960611b604482015290519081900360640190fd5b6006546005546040516000926001600160a01b03908116921690620007ff90620012f8565b6001600160a01b03928316815291166020820152606060408083018290526000918301829052519182900360a0019190f08015801562000843573d6000803e3d6000fd5b50604051631de7d79760e31b815260ff851660448201526000606482018190526001608483018190523060a4840181905260c06004850190815260c485018c905294955085946001600160a01b0386169463ef3ebcb8948e948e948e948e948e94939291908190602481019060e4018b8b80828437600083820152601f01601f191690910184810383528981526020019050898980828437600081840152601f19601f8201169050808301925050509a5050505050505050505050600060405180830381600087803b1580156200091957600080fd5b505af11580156200092e573d6000803e3d6000fd5b5050506001600160a01b03808b16600081815260016020908152604080832080549588166001600160a01b03199687168117909155808452600283529281902080549095168417909455835160ff8a1694810194909452606080855284018a9052919350918d917fcc0314763eabceb74cd3d30ae785c09bfe4e204af2088b3bfcdbbe5082133db5918b918b918f918f918d918190810160808201888880828437600083820152601f01601f191690910184810383528681526020019050868680828437600083820152604051601f909101601f1916909201829003995090975050505050505050a49998505050505050505050565b62000a2e62001006565b6004546001600160a01b0390811691161462000a80576040805162461bcd60e51b8152602060048201819052602482015260008051602062001d34833981519152604482015290519081900360640190fd5b600755565b600054610100900460ff168062000aa1575062000aa16200100a565b8062000ab0575060005460ff16155b62000aed5760405162461bcd60e51b815260040180806020018281038252602e81526020018062001d06602e913960400191505060405180910390fd5b600054610100900460ff1615801562000b19576000805460ff1961ff0019909116610100171660011790555b600680546001600160a01b038088166001600160a01b0319928316179092556007869055600480548684169083161790556005805492851692909116919091179055801562000b6e576000805461ff00191690555b5050505050565b60036020526000908152604090205460ff1681565b60075481565b6001602052600090815260409020546001600160a01b031681565b6006546001600160a01b031681565b62000bc462001006565b6004546001600160a01b0390811691161462000c16576040805162461bcd60e51b8152602060048201819052602482015260008051602062001d34833981519152604482015290519081900360640190fd5b6004546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600480546001600160a01b0319169055565b6004546001600160a01b031681565b6002602052600090815260409020546001600160a01b031681565b600062000c9662001006565b6004546001600160a01b0390811691161462000ce8576040805162461bcd60e51b8152602060048201819052602482015260008051602062001d34833981519152604482015290519081900360640190fd5b60008581526003602052604090205460ff161562000d45576040805162461bcd60e51b81526020600482015260156024820152746574682074782066696c6c656420616c726561647960581b604482015290519081900360640190fd5b6001600160a01b03808516600090815260016020526040902054168062000db3576040805162461bcd60e51b815260206004820152601b60248201527f6e6f2073776170207061697220666f72207468697320746f6b656e0000000000604482015290519081900360640190fd5b6000868152600360209081526040808320805460ff191660011790558051635b91d9a760e11b8152600481018790526001600160a01b03888116602483015291519185169363b723b34e9360448084019491939192918390030190829087803b15801562000e2057600080fd5b505af115801562000e35573d6000803e3d6000fd5b505050506040513d602081101562000e4c57600080fd5b50506040805184815290516001600160a01b03808716928992918516917f3bebd9a738291e69898b5dbfadb6329b4b09fc648bdef68762928e521463abd99181900360200190a450600195945050505050565b62000ea962001006565b6004546001600160a01b0390811691161462000efb576040805162461bcd60e51b8152602060048201819052602482015260008051602062001d34833981519152604482015290519081900360640190fd5b6001600160a01b03811662000f425760405162461bcd60e51b815260040180806020018281038252602681526020018062001cba6026913960400191505060405180910390fd5b6004546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600480546001600160a01b0319166001600160a01b0392909216919091179055565b3b151590565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526200100090859062001010565b50505050565b3390565b303b1590565b606062001067826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316620010cc9092919063ffffffff16565b805190915015620010c7578080602001905160208110156200108857600080fd5b5051620010c75760405162461bcd60e51b815260040180806020018281038252602a81526020018062001d54602a913960400191505060405180910390fd5b505050565b6060620010dd8484600085620010e7565b90505b9392505050565b6060824710156200112a5760405162461bcd60e51b815260040180806020018281038252602681526020018062001ce06026913960400191505060405180910390fd5b620011358562000f9e565b62001187576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b60208310620011c85780518252601f199092019160209182019101620011a7565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146200122c576040519150601f19603f3d011682016040523d82523d6000602084013e62001231565b606091505b5091509150620012438282866200124e565b979650505050505050565b606083156200125f575081620010e0565b825115620012705782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015620012bc578181015183820152602001620012a2565b50505050905090810190601f168015620012ea5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6109b380620013078339019056fe608060405234801561001057600080fd5b506040516109b33803806109b38339818101604052606081101561003357600080fd5b8151602083015160408085018051915193959294830192918464010000000082111561005e57600080fd5b90830190602082018581111561007357600080fd5b825164010000000081118282018810171561008d57600080fd5b82525081516020918201929091019080838360005b838110156100ba5781810151838201526020016100a2565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b5060408181527f656970313936372e70726f78792e696d706c656d656e746174696f6e0000000082525190819003601c0190208693508592508491508390829060008051602061095d8339815191526000199091011461014357fe5b610155826001600160e01b0361027a16565b80511561020d576000826001600160a01b0316826040518082805190602001908083835b602083106101985780518252601f199092019160209182019101610179565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d80600081146101f8576040519150601f19603f3d011682016040523d82523d6000602084013e6101fd565b606091505b505090508061020b57600080fd5b505b5050604080517f656970313936372e70726f78792e61646d696e000000000000000000000000008152905190819003601301902060008051602061093d8339815191526000199091011461025d57fe5b61026f826001600160e01b036102da16565b5050505050506102f2565b61028d816102ec60201b61054e1760201c565b6102c85760405162461bcd60e51b815260040180806020018281038252603681526020018061097d6036913960400191505060405180910390fd5b60008051602061095d83398151915255565b60008051602061093d83398151915255565b3b151590565b61063c806103016000396000f3fe60806040526004361061004e5760003560e01c80633659cfe6146100655780634f1ef286146100985780635c60da1b146101185780638f28397014610149578063f851a4401461017c5761005d565b3661005d5761005b610191565b005b61005b610191565b34801561007157600080fd5b5061005b6004803603602081101561008857600080fd5b50356001600160a01b03166101ab565b61005b600480360360408110156100ae57600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156100d957600080fd5b8201836020820111156100eb57600080fd5b8035906020019184600183028401116401000000008311171561010d57600080fd5b5090925090506101e5565b34801561012457600080fd5b5061012d610292565b604080516001600160a01b039092168252519081900360200190f35b34801561015557600080fd5b5061005b6004803603602081101561016c57600080fd5b50356001600160a01b03166102cf565b34801561018857600080fd5b5061012d610389565b6101996103b4565b6101a96101a4610414565b610439565b565b6101b361045d565b6001600160a01b0316336001600160a01b031614156101da576101d581610482565b6101e2565b6101e2610191565b50565b6101ed61045d565b6001600160a01b0316336001600160a01b031614156102855761020f83610482565b6000836001600160a01b031683836040518083838082843760405192019450600093509091505080830381855af49150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b606091505b505090508061027f57600080fd5b5061028d565b61028d610191565b505050565b600061029c61045d565b6001600160a01b0316336001600160a01b031614156102c4576102bd610414565b90506102cc565b6102cc610191565b90565b6102d761045d565b6001600160a01b0316336001600160a01b031614156101da576001600160a01b0381166103355760405162461bcd60e51b815260040180806020018281038252603a815260200180610555603a913960400191505060405180910390fd5b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61035e61045d565b604080516001600160a01b03928316815291841660208301528051918290030190a16101d5816104c2565b600061039361045d565b6001600160a01b0316336001600160a01b031614156102c4576102bd61045d565b6103bc61045d565b6001600160a01b0316336001600160a01b0316141561040c5760405162461bcd60e51b81526004018080602001828103825260428152602001806105c56042913960600191505060405180910390fd5b6101a96101a9565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b3660008037600080366000845af43d6000803e808015610458573d6000f35b3d6000fd5b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b61048b816104e6565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610355565b6104ef8161054e565b61052a5760405162461bcd60e51b815260040180806020018281038252603681526020018061058f6036913960400191505060405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55565b3b15159056fe5472616e73706172656e745570677261646561626c6550726f78793a206e65772061646d696e20697320746865207a65726f20616464726573735570677261646561626c6550726f78793a206e657720696d706c656d656e746174696f6e206973206e6f74206120636f6e74726163745472616e73706172656e745570677261646561626c6550726f78793a2061646d696e2063616e6e6f742066616c6c6261636b20746f2070726f787920746172676574a2646970667358221220d51b9a3c2a10700d22ce61992f1afda59614179c27719ea9d498bfc20e22c93d64736f6c63430006040033b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5570677261646561626c6550726f78793a206e657720696d706c656d656e746174696f6e206973206e6f74206120636f6e74726163744f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a65644f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65725361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a2646970667358221220c84fdff4cabd7d2277fe8f8ac5de02e6b150109b949e9a549407a80a0a4b3db664736f6c63430006040033

部署后地址:0xc5612639db6250a9e44A7d846fe60adCE1f65E53

BSCSwapAgentUpgradeableProxy 合约abi

[{"inputs":[{"internalType":"address","name":"logic","type":"address"},{"internalType":"address","name":"admin","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"admin_","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"changeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"implementation_","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]

BSCSwapAgentUpgradeableProxy 合约bytecode

0x608060405234801561001057600080fd5b506040516109b33803806109b38339818101604052606081101561003357600080fd5b8151602083015160408085018051915193959294830192918464010000000082111561005e57600080fd5b90830190602082018581111561007357600080fd5b825164010000000081118282018810171561008d57600080fd5b82525081516020918201929091019080838360005b838110156100ba5781810151838201526020016100a2565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b5060408181527f656970313936372e70726f78792e696d706c656d656e746174696f6e0000000082525190819003601c0190208693508592508491508390829060008051602061095d8339815191526000199091011461014357fe5b610155826001600160e01b0361027a16565b80511561020d576000826001600160a01b0316826040518082805190602001908083835b602083106101985780518252601f199092019160209182019101610179565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d80600081146101f8576040519150601f19603f3d011682016040523d82523d6000602084013e6101fd565b606091505b505090508061020b57600080fd5b505b5050604080517f656970313936372e70726f78792e61646d696e000000000000000000000000008152905190819003601301902060008051602061093d8339815191526000199091011461025d57fe5b61026f826001600160e01b036102da16565b5050505050506102f2565b61028d816102ec60201b61054e1760201c565b6102c85760405162461bcd60e51b815260040180806020018281038252603681526020018061097d6036913960400191505060405180910390fd5b60008051602061095d83398151915255565b60008051602061093d83398151915255565b3b151590565b61063c806103016000396000f3fe60806040526004361061004e5760003560e01c80633659cfe6146100655780634f1ef286146100985780635c60da1b146101185780638f28397014610149578063f851a4401461017c5761005d565b3661005d5761005b610191565b005b61005b610191565b34801561007157600080fd5b5061005b6004803603602081101561008857600080fd5b50356001600160a01b03166101ab565b61005b600480360360408110156100ae57600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156100d957600080fd5b8201836020820111156100eb57600080fd5b8035906020019184600183028401116401000000008311171561010d57600080fd5b5090925090506101e5565b34801561012457600080fd5b5061012d610292565b604080516001600160a01b039092168252519081900360200190f35b34801561015557600080fd5b5061005b6004803603602081101561016c57600080fd5b50356001600160a01b03166102cf565b34801561018857600080fd5b5061012d610389565b6101996103b4565b6101a96101a4610414565b610439565b565b6101b361045d565b6001600160a01b0316336001600160a01b031614156101da576101d581610482565b6101e2565b6101e2610191565b50565b6101ed61045d565b6001600160a01b0316336001600160a01b031614156102855761020f83610482565b6000836001600160a01b031683836040518083838082843760405192019450600093509091505080830381855af49150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b606091505b505090508061027f57600080fd5b5061028d565b61028d610191565b505050565b600061029c61045d565b6001600160a01b0316336001600160a01b031614156102c4576102bd610414565b90506102cc565b6102cc610191565b90565b6102d761045d565b6001600160a01b0316336001600160a01b031614156101da576001600160a01b0381166103355760405162461bcd60e51b815260040180806020018281038252603a815260200180610555603a913960400191505060405180910390fd5b7f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f61035e61045d565b604080516001600160a01b03928316815291841660208301528051918290030190a16101d5816104c2565b600061039361045d565b6001600160a01b0316336001600160a01b031614156102c4576102bd61045d565b6103bc61045d565b6001600160a01b0316336001600160a01b0316141561040c5760405162461bcd60e51b81526004018080602001828103825260428152602001806105c56042913960600191505060405180910390fd5b6101a96101a9565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b3660008037600080366000845af43d6000803e808015610458573d6000f35b3d6000fd5b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b61048b816104e6565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610355565b6104ef8161054e565b61052a5760405162461bcd60e51b815260040180806020018281038252603681526020018061058f6036913960400191505060405180910390fd5b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55565b3b15159056fe5472616e73706172656e745570677261646561626c6550726f78793a206e65772061646d696e20697320746865207a65726f20616464726573735570677261646561626c6550726f78793a206e657720696d706c656d656e746174696f6e206973206e6f74206120636f6e74726163745472616e73706172656e745570677261646561626c6550726f78793a2061646d696e2063616e6e6f742066616c6c6261636b20746f2070726f787920746172676574a264697066735822122090c377aaf4226453bc11a4d3569b56498c596cfd128747512a8e6687b2339d8d64736f6c63430006040033b53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5570677261646561626c6550726f78793a206e657720696d706c656d656e746174696f6e206973206e6f74206120636f6e7472616374

此时计算_data如下

web3js.eth.abi.encodeFunctionCall({
    name: 'initialize',
    type: 'function',
    inputs: [{
        type: 'address',
        name: 'bep20Impl'
    },{
        type: 'uint256',
        name: 'fee'
    },{
        type: 'address',
        name: 'ownerAddr'
    },{
        type: 'address',
        name: 'bep20ProxyAdminAddr'
    }]
}, ['0x41941cC749d561A13A3a8295f355033D23fDc060',100000000, '0xbb93FcC2bB90D46255c43DD398A1A372E12bE6Aa','0x48F155527f25EB1d4cb2aa32b7e84692AA0025C0']);

得到

0x358394d800000000000000000000000041941cc749d561a13a3a8295f355033d23fdc0600000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000bb93fcc2bb90d46255c43dd398a1a372e12be6aa00000000000000000000000048f155527f25eb1d4cb2aa32b7e84692aa0025c0

最终三个参数为

  • _logic0xc5612639db6250a9e44A7d846fe60adCE1f65E53
  • Admin_0xF8329Ea42489C2164F44A81DEb3bE22c2C456109
  • _data0x358394d800000000000000000000000041941cc749d561a13a3a8295f355033d23fdc0600000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000bb93fcc2bb90d46255c43dd398a1a372e12be6aa00000000000000000000000048f155527f25eb1d4cb2aa32b7e84692aa0025c0

部署后的地址:0x2dd3DC6ec3ddC15d05C3719EB329a7E64e00Aad5

BSC合约管理地址

升级管理地址:0xF8329Ea42489C2164F44A81DEb3bE22c2C456109
逻辑合约管理地址:0xbb93FcC2bB90D46255c43DD398A1A372E12bE6Aa
Bep20合约管理地址:0x48F155527f25EB1d4cb2aa32b7e84692AA0025C0

Swap程序部署

编译程序

git clone https://github.com/binance-chain/bsc-eth-swap.git
make build

编译完,服务程序会生成在bsc-eth-swap\build\swap-backend

config配置

由于没有文档,还是看代码吧,先查看demo config config\config.json,以及config解析的代码
从代码角度完善配置参数以及参数作用。

{
  "key_manager_config": {
    "key_type": "local_private_key",
    "aws_region": "",
    "aws_secret_name": "",

    "local_hmac_key": "",
    "local_bsc_private_key": "",
    "local_eth_private_key": "",
    "local_admin_api_key":"",
    "local_admin_secret_key":""
  },
  "db_config": {
    "dialect": "sqlite3",
    "db_path": "./build/test.db"
  },
  "chain_config": {
    "balance_monitor_interval": 60,

    "bsc_observer_fetch_interval": 1,
    "bsc_start_height": 6010146,
    "bsc_provider": "https://ropsten.infura.io/v3/c4f8f662c565463e8e3285708cb41823",
    "bsc_confirm_num": 2,
    "bsc_swap_agent_addr":"0x2dd3DC6ec3ddC15d05C3719EB329a7E64e00Aad5",
    "bsc_explorer_url": "https://ropsten.etherscan.io/tx",
    "bsc_max_track_retry": 60,
    "bsc_alert_threshold": "1000000000000000000",
    "bsc_wait_milli_sec_between_swaps": 100,

    "eth_observer_fetch_interval": 10,
    "eth_start_height": 8018001,
    "eth_provider": "https://goerli.infura.io/v3/87aba2e668f9410498cdf74bc7a35467",
    "eth_confirm_num": 1,
    "eth_swap_agent_addr": "0x31366023017888A1ef48ca60cbB5de26aCBe6b02",
    "eth_explorer_url": "https://goerli.etherscan.io/tx",
    "eth_max_track_retry": 600,
    "eth_alert_threshold": "1000000000000000000",
    "eth_wait_milli_sec_between_swaps": 200
  },
  "log_config": {
    "level": "INFO",
    "filename": "build/test.log",
    "max_file_size_in_mb": 100,
    "max_backups_of_log_files": 1,
    "max_age_to_retain_log_files_in_days": 30,
    "use_console_logger": false,
    "use_file_logger": true,
    "compress": false
  },
  "alert_config": {
    "telegram_bot_id": "",
    "telegram_chat_id": "",
    "block_update_timeout": 10
  },
  "admin_config": {
    "listen_addr": ":8000"
  }
}

启动程序

./build/swap-backend --config-type local --config-path config/config.json

unknown block

由于现有项目不支持 EIP-1559,导致解析 block head错误,block hash无效,报 unknown block

支持EIP-1559

更新 go-ethereum模块
go get github.com/ethereum/go-ethereum@v1.10.8

需要重新生成\bsc-eth-swap\abi\*.goabi.go文件
需要准备合约编译工具环境

首次需要安装solc
sudo pip3 install solc-select
sudo solc-select install 0.6.4 //安装指定版本solc
solc-select use 0.6.4

查看solc安装位置

whereis solc
/usr/local/bin/solc /home/surou/.local/bin/solc

添加到环境变量,或者移动到默认/usr/bin

sudo cp /usr/local/bin/solc  /usr/bin

查看版本solc版本

solc --version
solc, the solidity compiler commandline interface
Version: 0.6.4+commit.1dca32f3.Linux.g++
首次需要安装protobuf
sudo apt install protobuf-compiler

编译go-ethereum

git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum/
make all

最终生成在go-ethereum\build\bin\abigen
复制到全局

sudo cp ./build/bin/abigen /usr/bin/

重新生成abi和bin

git clone https://github.com/binance-chain/eth-bsc-swap-contracts.git
cd eth-bsc-swap-contracts/
npm run flatten //合并依赖为单文件
cd eth-bsc-swap-contracts/contracts/flattened
BSCSwapAgentImpl
solc --bin ./BSCSwapAgentImpl.sol > BSCSwapAgent.bin //生成文件中只保留BSCSwapAgentImpl独立内容
solc --abi ./BSCSwapAgentImpl.sol > BSCSwapAgent.abi //生成文件中只保留BSCSwapAgentImpl独立内容
abigen --bin=BSCSwapAgent.bin --abi=BSCSwapAgent.abi --pkg=BSCSwapAgent --out=BSCSwapAgent.go
ETHSwapAgentImpl
solc --bin ./ETHSwapAgentImpl.sol > ETHSwapAgent.bin //生成文件中只保留ETHSwapAgentImpl独立内容
solc --abi ./ETHSwapAgentImpl.sol > ETHSwapAgent.abi //生成文件中只保留ETHSwapAgentImpl独立内容
abigen --bin=ETHSwapAgent.bin --abi=ETHSwapAgent.abi --pkg=ETHSwapAgent --out=ETHSwapAgent.go

回到 \bsc-eth-swap\abi目录,将上面生成的BSCSwapAgent.go,BSCSwapAgent.abi,ETHSwapAgent.abi,ETHSwapAgent.go 文件覆盖过来
然后把 BSCSwapAgent.goETHSwapAgent.go中的package改为abi

ERC20
cd eth-bsc-swap-contracts/
sudo npm install -g truffle-flattener
truffle-flattener node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol > contracts/flattened/ERC20.sol

同上将contracts/flattened/ERC20.sol 复制到 \bsc-eth-swap\abi目录中

cd `bsc-eth-swap/abi`
solc --bin ./ERC20.sol > ERC20.bin // 删除多余注释
solc --abi ./ERC20.sol > ERC20.abi // 删除多余注释
abigen --bin=ERC20.bin --abi=ERC20.abi --pkg=ERC20 --out=ERC20.go

修改后的代码已提交

git clone https://github.com/bcskill/bsc-eth-swap.git

常见问题

  • Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given: 0x0NaN
    把逻辑合约重新部署下,用新地址再试下,或者确认下逻辑合约初始化函数参数,是否与encodeFunctionCall参数一致
  • admin cannot fallback to proxy target
    不能拿升级管理权限地址操作逻辑合约,逻辑合约管理权限地址不能与升级管理权限地址相同

注意

  1. encodeFunctionCall执行时,参数要与函数方法参数顺序一致

在线工具

https://www.sojson.com/yasuoyihang.html

测试如何用Cosmos创建并交易通证

安装go环境

下载并安装go

https://golang.org/dl/

wget https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz // 下载
tar -C $HOME -xzf go$VERSION.$OS-$ARCH.tar.gz // 解压到home/go

配置环境变量

mkdir -p $HOME/go/bin
echo "export GOPATH=$HOME/go" >> ~/.bash_profile
echo "export GOBIN=$GOPATH/bin" >> ~/.bash_profile
echo "export PATH=$PATH:$GOBIN" >> ~/.bash_profile
source ~/.bash_profile

安装cosmos

先解决墙内问题

一键解决 go get golang.org/x 包失败

https://shockerli.net/post/go-get-golang-org-x-solution/

export GO111MODULE=on
export GOPROXY=https://goproxy.io
// Go version >= 1.11

下载代码并编译

mkdir -p $GOPATH/src/github.com/cosmos
cd $GOPATH/src/github.com/cosmos
git clone https://github.com/cosmos/cosmos-sdk
cd cosmos-sdk && git checkout v0.35.0
make tools install

那将安装gaiad和gaiacli二进制文件。验证一切正常:

gaiad version --long
gaiacli version --long

安装jq

sudo apt-get install jq

开始配置

设置新节点

gaiad init <your_custom_moniker> // 注意Monikers只能包含ASCII字符。使用Unicode字符将使您的节点无法访问。

您可以moniker稍后在~/.gaiad/config/config.toml文件中进行编辑:

# A custom human readable name for this node
moniker = "<your_custom_moniker>"

您可以编辑该~/.gaiad/config/gaiad.toml文件以启用反垃圾邮件机制并拒绝低于最低汽油价格的传入交易:

# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml

##### main base config options #####

# The minimum gas prices a validator is willing to accept for processing a
# transaction. A transaction's fees must meet the minimum of any denomination
# specified in this config (e.g. 10uatom).

minimum-gas-prices = ""

您的完整节点已初始化!

创建Genesis文件并启动网络

# You can run all of these commands from your home directory
cd $HOME

# Initialize the genesis.json file that will help you to bootstrap the network
gaiad init --chain-id=testing testing

# Create a key to hold your validator account
gaiacli keys add validator

# Add that key into the genesis.app_state.accounts array in the genesis file
# NOTE: this command lets you set the number of coins. Make sure this account has some coins
# with the genesis.app_state.staking.params.bond_denom denom, the default is staking
gaiad add-genesis-account $(gaiacli keys show validator -a) 1000000000stake,1000000000validatortoken

# Generate the transaction that creates your validator
gaiad gentx --name validator

# Add the generated bonding transaction to the genesis file
gaiad collect-gentxs

# Now its safe to start `gaiad`
gaiad start

此设置将所有数据gaiad放入~/.gaiad。您可以检查您创建的创世纪文件~/.gaiad/config/genesis.json。使用此配置gaiacli也可以使用并且具有令牌帐户(包括放样和自定义)。

参考

https://www.jianshu.com/p/38736bdc08d8
https://cosmos.network/docs/cosmos-hub/installation.html#install-gaia
https://github.com/cosmos/cosmos-sdk/issues/4634

Wrapper for node-ipfs-api

IPFS 介绍及Windows系统下环境搭建使用

IPFS(InterPlanetary File System)是一个点对点的分布式超媒体分发协议,它整合了过去几年最好的分布式系统思路,为所有人提供全球统一的可寻址空间,包括Git、自证明文件系统SFS、BitTorrent和DHT,同时也被认为是最有可能取代HTTP的新一代互联网协议。

IPFS用基于内容的寻址替代传统的基于域名的寻址,用户不需要关心服务器的位置,不用考虑文件存储的名字和路径。我们将一个文件放到IPFS节点中,将会得到基于其内容计算出的唯一加密哈希值。哈希值直接反映文件的内容,哪怕只修改1比特,哈希值也会完全不同。当IPFS被请求一个文件哈希时,它会使用一个分布式哈希表找到文件所在的节点,取回文件并验证文件数据。

IPFS是通用目的的基础架构,基本没有存储上的限制。大文件会被切分成小的分块,下载的时候可以从多个服务器同时获取。IPFS的网络是不固定的、细粒度的、分布式的网络,可以很好的适应内容分发网络的要求。这样的设计可以很好的共享各类数据,包括图像、视频流、分布式数据库、整个操作系统、模块链、8英寸软盘的备份,还有静态网站。

1、下载IPFS
  • 打开官网https://ipfs.io/ ,点击Try it
  • 点击 Install IPFS now
  • 开始下载
  • 下载对应版本的IPFS安装文件
  • 下载完之后,将文件解压
    2.安装IPFS
  • 打开CMD,进入IPFS解压目录
  • 初始化 ipfs网络环境
    ipfs init


    并且系统会分配一个属于你自己的IPFS网络哈希值(类似你在IPFS网络中的一张身份证ID)。有了这个ID,别人就可以访问到你的节点。
    输入

    ipfs cat /ipfs/QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv/readme

    出现Hello and Welcome to IPFS! 那恭喜你!说明你的电脑已经成功安装IPFS并已经加入到IPFS网络了。

    3.IPFS系统配置
  • 查找配置
    IPFS的初始化配置在当前系统的用户目录
  • 打开config配置文件

    具体的配置参数以及如何修改,此处不做具体说明,请参考官网
    4.服务运行

    输入ipfs daemon启动IPFS服务监听,用于监听IPFS网络通信数据,默认使用的监听端口是5001,请确保此端口不被占用。也可自行修改config配置

    "API": "/ip4/127.0.0.1/tcp/5001",
    "Gateway": "/ip4/127.0.0.1/tcp/8080"

    5.IPFS使用测试

    重新打开另一CMD,并进入IPFS文件目录
    使用ipfs help获取常用命令参数

C:\Users\Surou\Desktop\Ipfs>ipfs help
USAGE
  ipfs - Global p2p merkle-dag filesystem.

  ipfs [--config=<config> | -c] [--debug=<debug> | -D] [--help=<help>] [-h=<h>] [--local=<local> | -L] [--api=<api>] <command> ...

SUBCOMMANDS
  BASIC COMMANDS
    init          Initialize ipfs local configuration
    add <path>    Add a file to IPFS
    cat <ref>     Show IPFS object data
    get <ref>     Download IPFS objects
    ls <ref>      List links from an object
    refs <ref>    List hashes of links from an object

  DATA STRUCTURE COMMANDS
    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
    files         Interact with objects as if they were a unix filesystem
    dag           Interact with IPLD documents (experimental)

  ADVANCED COMMANDS
    daemon        Start a long-running daemon process
    mount         Mount an IPFS read-only mountpoint
    resolve       Resolve any type of name
    name          Publish and resolve IPNS names
    key           Create and list IPNS name keypairs
    dns           Resolve DNS links
    pin           Pin objects to local storage
    repo          Manipulate the IPFS repository
    stats         Various operational stats
    p2p           Libp2p stream mounting
    filestore     Manage the filestore (experimental)

  NETWORK COMMANDS
    id            Show info about IPFS peers
    bootstrap     Add or remove bootstrap peers
    swarm         Manage connections to the p2p network
    dht           Query the DHT for values or peers
    ping          Measure the latency of a connection
    diag          Print diagnostics

  TOOL COMMANDS
    config        Manage configuration
    version       Show ipfs version information
    update        Download and apply go-ipfs updates
    commands      List all available commands

  Use 'ipfs <command> --help' to learn more about each command.

  ipfs uses a repository in the local file system. By default, the repo is
  located at ~/.ipfs. To change the repo location, set the $IPFS_PATH
  environment variable:

    export IPFS_PATH=/path/to/ipfsrepo

  EXIT STATUS

  The CLI will exit with one of the following values:

  0     Successful execution.
  1     Failed executions.

ipfs id,可以查看你的通信ID信息

使用ipfs swarm peers 可以查看附近也在使用IPFS网络节点伙伴,可以发现不是你一个人在战斗

6.访问IPFS网络中的某一文件