BCSkill (Block chain skill )
区块链中文技术社区
社区QQ群:791420381

了解如何在 MetaMask 中设置交易 gas 费用

常见问题

EIP-1559 是什么?

EIP-1559 将改变以太坊的市场机制来支付交易费用。从根本上讲,EIP-1559 摆脱了首价拍卖,取而代之的是固定价格拍卖。这一变化的意义在于,提交交易的人不必猜测需要多少 gas,因为下一个区块中将包含明确的“基本费用”。对于想要优先处理交易的用户或应用程序,他们可以添加“小费”以支付矿工费用。您可以在此处更详细地了解 EIP-1559 以及它将如何改变以太坊。

EIP-1559 会使 ETH 通货紧缩吗?

EIP-1559
烧伤花掉的交易费基本费用的ETH。该 ETH 从供应中移除。在 EIP-1559 下,ETH 变得更加稀缺,因为以太坊上的所有交易都会消耗一定数量的 ETH。

对 EIP-1559 的通货紧缩程度进行准确建模是很困难的,因为您必须预测诸如预期交易之类的变量,甚至更难预测的是预期网络拥堵。从理论上讲,发生的交易越多,基本费用的燃烧对整个以太坊供应的通货紧缩压力就越大。根据网络上发生的交易数量,ETH 供应可能会在不同时间减少或膨胀更多

在与 Proof of Stake 合并后,Justin Drake 的模型估计每天将发行 1,000 ETH,并将燃烧 6,000 ETH 作为“最佳猜测”。假设有更多验证者加入,Staking APR 为 6.7%,那么年供应变化将为 -160 万 ETH,年供应率降低 1.4%。

尽管人们越来越意识到 MEV 和潜在的 EIP 会带来更高的透明度,但我们可以预期,随着机构金融交易者使用 DeFi 协议,套利机会只会变得更加复杂。这可能意味着每个区块的小费最终可能会比基本费用多得多。朱苏和Hasu实际预测,不到一半的今天的费用可以通过EIP
1559年

已经烧掉了多少 ETH?

你可以在这里跟踪。

作为 EIP-1559 的用户,我有什么变化?

这个想法是使用户的gas费用或多或少透明。因此,钱包将能够有更好的估计并使交易费用更可预测。他们不必过多依赖外部预言机,因为基本费用由协议本身管理。将有额外的用户体验优势,例如自动化费用竞标机制,从而减少交易确认的延迟。

此更改何时推出?

EIP-1559 将于 8 月 5 日在以太坊主网上上线,届时我们将开始推出此更改。目前,它在 Ropsten、Rinkeby、Goerli 网络中可用。

费用

EIP-1559 会使汽油更便宜吗?

不,这不是 EIP 的意图。作为更可预测的基本费用的副作用,如果我们假设费用的可预测性意味着用户不会频繁地为 Gas 多付钱,那么 EIP-1559 可能会导致 Gas 价格有所下降。使用 EIP-1559,在区块填充超过 50% 后,基础费用将增加和减少 12.5%。例如,如果一个区块 100% 满,基础费用增加 12.5%;如果是 50%,基本费用将相同;如果是 0%,基本费用将减少 12.5%。

应用程序向汇总和第 2 层的持续移动将大大降低费用。

如何设置正确的gas费用?

MetaMask 在设置 gas 费用时会为您提供三个选项:

  • 高:这是掉期或其他时间敏感交易的最佳选择。如果掉期处理时间过长,它通常会失败,您可能会损失资金。
  • 中:这有利于发送资产、提取资产或其他非时间敏感但重要的交易。
  • 低:仅应为处理时间不太重要的交易选择较低的 gas 费用。由于费用较低,很难预测您的交易何时(或是否)会成功。

我应该编辑gas费用吗?

您可以在高、中或低汽油费之间进行选择。请参阅上面的问题以了解这些含义。此外,您可以在“高级选项”设置中编辑您的 gas 限额、优先费用和最高费用。这将覆盖 MetaMask 为您“推荐”的低、中或高设置。

我的交易在 EIP-1559 上的速度有多快?

这暂时还不得而知。预测是由于 gas 费的可预测性,交易将进行得更快。

汽油费是如何计算的?

Gas 费用由区块的满量决定。EIP-1559 建立了交易包含的市场费率,并允许以太坊拥有双倍的区块空间(通过将每个区块的最大 gas 限制从 12.5M 增加到 25M)。然后它将块定位为只有 50% 满。

当网络利用率 > 50% 时,基础费用增加
当网络利用率 < 50% 时,基础费用减少

随着时间的推移,以太坊的区块大小将平均为相同的大小,但这种额外的容量允许具有交易包容性的灵活性。从本质上讲,它将消除设置天然气价格以进行交易的额外步骤。

MetaMask 的汽油费是否比其他任何地方都高?

不,MetaMask 使用与其他钱包如何估算 gas 价格类似的 gas 估算预言机的汇编。我们相信我们可以提供有竞争力的气体估算。

估计的gas费用与我实际支付的费用有多少不同?

估计的gas费用是一个范围。此范围的上限是用户将为交易支付的最高金额。在 EIP-1559 推出后,我们应该能够从我们的 gas 估计范围分析我们的交易包含率。

我应该考虑采用不同的方法来为掉期交易和其他交易设置 gas 费用吗?

MetaMask 将提供三个选项来设置 gas 费用:高、中和低(更多详细信息在“我如何设置正确的 gas 费用?”上方的常见问题解答中),并且会预先选择我们认为与您的交易类型相关的费用。如果您愿意,可以更改此设置,但我们会提供最佳建议。对于掉期等时间敏感的交易,我们建议并会预先选择“高”的gas费用。

什么是基本费用/最高费用/优先费用/等。是什么意思?

有关(新)术语的详细定义,请参阅我们的词汇表

由于我设置了“最高优先费用”,我如何才能看到我实际为交易支付的金额?

您可以查看已支付的估计 gas 费用的交易活动,或在区块浏览器(如 Etherscan)上查看交易收据中的“有效GasPrice”。

我可以在没有优先费(“矿工小费”)的情况下进行交易吗?

是的,你可以,但有可能其他交易(确实包括优先费)将被优先考虑,因为矿工被激励包含优先费的交易。

典型用户会选择“小费”金额还是为用户预选的总费用的一部分?

“小费”将作为用户在提交交易时看到的总体“汽油费”中包含在内。您还可以“编辑汽油费”以增加或减少称为“优先费”的“小费”。

在哪里可以看到他们为小费支付的费用?像 Etherscan 这样的区块浏览器现在会显示这些信息吗?

大多数工具将相应更新以显示与 EIP 相关的新信息。交易收据中现在将有一个“effectiveGasPrice”,它返回交易执行后支付的价格(即基本费用+优先费用)。

集成

EIP-1559 如何与 MetaMask 上的 Trezor/Ledger 集成一起工作?

Trezor 和 Ledger 尚不支持 EIP-1559,因此 MetaMask 将回退到 EIP-1559 之前的气体控制。

是在钱包还是 dapp 级别上实现?换句话说,我所有的 dapp 连接都会显示钱包中的新界面,还是只显示采用 EIP-1559 的 dapp?

如果 dapp 尚未切换到新的 EIP-1559 字段,MetaMask 将检测到这一点并使用 gasPrice 作为 maxFeePerGas。这意味着用户可能会为他们的交易多付钱。

用户体验

EIP-1559 还能如何改变钱包用户体验?

这将因钱包而异。这个想法是让基于区块需求的费用对用户更加透明。像 MetaMask 这样的钱包将能够有更好的估计,并且不必过多依赖外部预言机,因为基本费用由协议本身管理。此外,在使用 MetaMask 时,您可以决定高、中或低 gas 费。虽然会预先选择推荐类型,但用户可以在确认交易之前进行更改。此外,用户可以在“高级”设置中更改最高费用、最高优先费用和 Gwei。这样做将覆盖初始的高、中或低设置。

在网络拥塞期间,用户体验是否会有所不同?

在网络严重拥堵期间,基本费用将根据每个区块超过理想气体限制的需求量调整 12.5%,直到需求减弱。与首价拍卖不同,用户将更好地了解网络的拥堵程度,因为基本费用有多高。如果它太拥挤,用户可以支付或不支付该价格,就像他们在商店购买商品一样。或者,他们提交较低的费用并等待未来价格下跌。

开发者常见问题

作为 EIP-1559 的开发人员,我有什么变化?

我们建议 dapp 开发者和网络在伦敦分叉发生后立即分别切换到 EIP-1559 字段和区块头。如果不是,传统的 gasPrice 将用作 maxFeePerGas,这意味着用户可能会为他们的交易支付过高的费用。

如何使用 MetaMask 为我的 dapp 实施 EIP-1559?

您可以通读EIP-1559 规范,也可以查看Ethereum 的 JSON-RPC 规范中的 EIP-1559 部分。

是在用户级别还是 dapp 级别上实现?换句话说,如果我实施 EIP-1559,我的所有 dapp 用户会看到新的 gas 费用设置,还是只有同意采用 EIP-1559 的用户?

两者都是。用户通过客户端(钱包)与以太坊网络交互。用户还可以通过 dapp 与网络交互。如果 dapp 没有切换到新的 EIP-1559 字段,MetaMask 将检测到这一点并显示 1559 之前的气体估计 UI。

谁估计 gas 估计值,dapp 还是 MetaMask?

MetaMask.

所有的客户团队都准备好迎接 EIP-1559 了吗?

是的,客户规格已被冻结。伦敦硬分叉发布时间表如下

是否有关于复仇dapps任何潜在的风险?

答:所有的改变都是有风险的,但以太坊社区在强大的软件开发和协调方面有着良好的记录。EIP-1559 给对时间敏感的网络参与者(例如预言机)带来了一些潜在风险。Oracle 通常提供支持 DeFi 生态系统中各种参与者所需的定价信息。例如,Compound 需要知道用户抵押品的估值(即价格 x 资产数量),以确定他们的头寸是否需要清算。这些资产的估值必须不断更新,Compound 依靠预言机来更新这些信息。可以在这篇文章中找到有关这方面的更多信息。

对于伦敦硬分叉,我的项目可能需要考虑哪些更改?

EIP-1559(和 EIP-3198)的技术变化可能会影响您的项目,包括新的区块格式、新的交易格式、用于选择 gas 价格的新值、新的 JSON RPC 调用和几个 JSON RPC 的行为改变调用。有关这些更改的详细信息,请参阅此Infura 博客文章

词汇表

EIP-1559(以太坊改进协议 1559)

该提案最初由 Vitalik Buterin 创建,目的是通过不向矿工支付以太坊用户通过竞标天然气费而支付的天然气费来降低每笔交易的成本。以太坊用户现在可以根据网络的内部平均值对交易的平均汽油价格进行更准确的估计。如果我们假设费用的可预测性意味着用户不会频繁地为 gas 支付过高的费用,那么更可预测的基本费用的副作用可能会导致 gas 价格有所下降。有关 EIP-1559 将如何改变以太坊的更多信息,请参见此处

Gas fee

Gas 是指以太坊区块链上的交易费用。这是用户为验证或完成交易而支付的费用。

Base fee(基本费用)

由协议产生。表示将交易包含在区块中(即完成交易)所需的最小 gasUsed 乘数。这是交易费用中被烧掉的部分。

Max Priority fee - 即优先费或矿工的小费

MetaMask 最初将根据前一个区块的历史记录设置此金额。但是,用户将被允许在高级设置中编辑此金额。它被添加到交易中并代表支付给矿工的交易费用的一部分。

Max fee

MetaMask 最初将根据前一个区块的历史记录设置此金额。但是,用户将被允许在高级设置中编辑此金额。它代表用户愿意为其交易支付的最大金额(包括基本费用和最高优先级费用)。每gas最高费用与基本费用+最高优先费用之间的差额将“退还”给用户。

Gas limit

交易可能消耗的最大gas单位数量。

Gwei

Gwei 是以太的单位,最小的面额,代表 gigawei(或 1,000,000,000)。¹ Gwei 用于支付 gas 费用,或者说是用户支付的费用,以补偿处理和验证交易所需的计算能量在复仇blockchain.²

Slippage (滑点)

滑点是报价和执行价格之间的预期百分比差异。

原文:https://metamask.io/1559

争议不断的EIP-1559即将到来,它会造成哪些影响?

伦敦升级来临

以太坊基金会于7月15日公布了伦敦升级最新进展,本次升级将在主网达到12965000区块高度时被激活,具体时间预计在8月3日至5日之间。

V神在7月24号的世界区块链大会上演讲时说到:“当现在的PoW链完成了它的使命,PoW链上的一切都转移到PoS链上之后,就算是进入了以太坊2.0。但在两条链合并前期,将会执行一些较小的升级,引入分片,搭配Rollup,理想状态下可实现每秒10万笔交易。”而即将在PoW链上进行的伦敦分叉就是合并前期的一次重要升级。

从2015年开始,以太坊经历了数次升级,它们帮助以太坊不断完善并走向2.0时代。

什么是EIP-1559

以太坊的网络升级通过链下治理实施,社区成员提出以太坊改进提案(Ethereum Improvement Proposal,EIP)并对升级所要采用的EIP内容达成一致,由开发团队更新客户端,最后矿工使用最新版的以太坊客户端并通过硬分叉升级。

伦敦硬分叉升级中包含了五个以太坊改进提案,包括EIP-1559、EIP-3198、EIP-3529、EIP-3541和EIP-3554。伦敦升级因EIP-1559备受瞩目,其将改进现有的手续费机制,并将持续销毁ETH。

目前以太坊的交易手续费(Gas费)计算机制中一部分由创建者设置,创建者设置的交易费用多少会影响到矿工打包的先后顺序。矿工提供了在以太坊上运行交易和智能合约的计算能力,他们通常会优先处理设定高Gas费的用户的交易,以最大限度地获得区块奖励。

同样,为了能够更快完成交易,交易创建者也会设置更高的手续费来激励矿工。因此,在这种机制的刺激下,导致竞争巨大、Gas费不断上升、效率极低,并导致验证节点总价超付,增加了成本。

为了改善用户体验,V神和以太坊核心开发人员提出EIP-1559改进提案,在EIP-1559提案中,交易手续费将被拆分为两部分:基础费+矿工小费。其中基础费是交易所需的最少花费,由系统直接销毁,小费归矿工所有。

基础费用是用户在以太坊上发送交易或完成操作所需的最低Gas价格。它根据以太坊上每个区块使用的空间大小而波动。理想情况下,以太坊上的每个区块最多可容纳1500万Gas。然而在网络拥堵时,EIP-1559将允许块大小增加到这个数量的两倍。如果区块包含的Gas超过1500万,基础费将提高12.5%,反之如果低于1500万,将降低12.5%,直至趋于零。这种调整旨在确保以太坊的Gas费趋向于平均每区块约1500万Gas。

矿工小费指的是用户可以选择在最低基本费用的基础上再支付额外费用,该费用将直接支付给矿工,以激励矿工优先处理某些交易。EIP-1559中的小费是可选的,仅用于需要最快网络确认时间的用户。

EIP-1559对我们会产生哪些影响?

那么,EIP-1559设定的相对固定的Gas基础费的作用有哪些呢?

其一,可以降低ETH的通胀率。目前,ETH的供应量是无限的,每产生一个新的区块,就会有两枚新的ETH诞生,因此,它是有通胀的属性在的。但EIP-1559对于Gas基础费的销毁机制可能会带来一种局面,在交易活跃度较高时,用户支付基础费用销毁的ETH总量可能会抵消并大于通过区块奖励新发行的ETH总额,这将意味着ETH供应量出现负增长。如果交易不活跃,销毁的基础费少于出块奖励,那也可以促进ETH数量不会过分减少,使其达到一种平衡状态。

其二,降低以太坊交易费用波动性。根据EIP-1559,Gas基础费只能增减12.5%,这为以太坊的交易费用带来了稳定性。但是,降低波动性不代表降低交易费用,高费用问题主要是由于处理交易的网络容量有限造成的。以太坊费用机制的变化不能改变网络一次能够处理多少交易。这属于以太坊的可拓展性问题,需要交给Layer 2扩容方案和未来的分片技术。

基于EIP-1559的手续费机制和作用,我们可以看到它将主要影响三种不同类型的利益相关者:ETH投资者、矿工和用户。

(一)ETH投资者

基础费的销毁降低了ETH的通胀率。如果以太坊交易非常活跃时,甚至可能出现其销毁量高于新增量的情况,在这种情况下,ETH会变成通缩资产。

现在每天ETH的产出是13000枚左右,年通胀率约为4%。Dune Analytics的数据显示,如果按照EIP-1559的方式,一年内预计销毁2937123枚以太坊,占增发量的61.9%,可以把通胀率降低到1.5%,这个数值要比比特币1.8%的通胀率更低。通过销毁基础费,在一定程度上会提升ETH的价值,有利于长期持有ETH的投资者们。

(二)矿工

表面来看,EIP-1559中基础费的销毁会极大地削减矿工收入。但这是绝对的吗?

我们首先来看一下矿工的收入来源是什么。目前,矿工收入来源于交易手续费和区块奖励。当EIP-1559落实之后,交易手续费拆分为基础费和矿工小费,其中基础费被销毁。但随着以太坊上DEX的崛起,还有一种矿工收入出现,即矿工可提取价值(MEV)。MEV是一种可变的收入来源,DEX交易者可能比普通用户更看重链上交易执行的速度和顺序,矿工可利用这一点从DEX交易者那里获得更多的回报。

由于DEX越来越受欢迎,MEV变得越来越有利可图。研究和开发组织Flashbots估计,MEV的日收入已从2021年初的50万美元增长到2021年6月的600多万美元。

因此,在EIP-1559之后,矿工的MEV部分的收益比例有可能会越来越多。EIP-1559对矿工的收益肯定会有影响,但可能不一定有想象中的大。矿工依然有机会获得不错的收益。此外,EIP-1559本身会对ETH带来增值效应,这对所有人都是有利的。

(三)用户

对于以太坊的用户来说,高昂的费用是目前最紧迫的问题之一。EIP-1559并不会解决这个问题,并没有改变以太坊本身一次只能处理有限数量交易的事实。EIP-1559的主要作用是可以优化和提高以太坊手续费的使用效率。

EIP-1559提高了以太坊费用方式的透明度和可见性。过去用户在支付手续费时,需要根据网络拥堵情况和近期Gas费估算手续费多少。如果过少等待时间会变长,过多则造成浪费。从区块层面看,EIP-1559的方案每次区块之间的基础费变化幅度最多为12.5%,根据规则用户能预测并支付相对准确的手续费,以提高用户体验。

EIP-1559面临的风险

EIP-1559关于手续费的改变可以为以太坊带来好的一面,但技术是双刃剑,有好处但也同样伴随着风险。

对于矿工来说,随着EIP-1559的激活,他们的收入将减少。矿工将失去大额的交易手续费,而只能从寻求交易优先权的用户那里获得小费。改变奖励机制本身不会影响以太坊处理区块或计算的能力。然而,却存在着不满的矿工离开网络、破坏网络或启动竞争链的可能性。如果有很大一部分以太坊矿工退出或造反,区块时间和网络安全将受到负面影响。

对于用户和DAPP开发者,EIP-1559的激活可能不会表现得像理论上那样有效。如果不能实现承诺的费用市场效率,可能会导致用户和开发者的幻想破灭。如果发生这种情况,以太坊的竞争对手,如Binance Smart Chain和Cardano(按市值计算仅次于以太坊的两个最大的智能合约区块链平台),无疑将抓住机会抢占市场份额。

最后,EIP-1559的激活还带来了不可预见的错误或恶意的用户行为的风险。这在私人测试网络上测试EIP-1559的过程中,已经发现了一些。

以太坊的新时代

EIP-1559通过让手续费更有效率来提升用户体验,但不能从根本上解决网络拥堵和高手续费的问题,这需要通过Layer 2扩容或者以太坊2.0来实现。

EIP-1559将极大地增强以太坊上处理交易的用户体验。当然,矿工们会担心EIP-1559的费用销毁方面,但EIP-1559的总体好处远远超过费用销毁,将对终端用户产生积极的影响。

随着EIP-1559、Layer 2以及PoS的推进,以太坊及ETH会有向好的变化,其中也会潜藏一些危机。不过,如果一切都能顺利落地,这会开启以太坊的新时代,对整个加密领域的格局产生非常重大的影响。

转载自:https://zhuanlan.zhihu.com/p/395153612

其他

https://notes.ethereum.org/@vbuterin/eip-1559-faq
https://zhuanlan.zhihu.com/p/393196358
https://zhuanlan.zhihu.com/p/396948190
https://zhuanlan.zhihu.com/p/361104358

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