简体   繁体   English

抵押现有的 ERC20 代币

[英]staking existing ERC20 token

How do I make a existing running erc20 to prevent some holders from transacting?如何让现有的 erc20 运行以防止某些持有者进行交易?

I am trying to do a staking feature.我正在尝试做一个抵押功能。 Can I write a new contract to control the existing erc20 contract?我可以写一个新合约来控制现有的erc20合约吗?

Logic that would affect a token holder's ability to transfer (or have a party transferFrom on the holders behalf) must be written into the contract if you want token transfers to be halted within the contract itself.如果您希望在合约本身内暂停代币传输,则必须将影响代币持有者transfer (或代表持有者的一方transferFrom )能力的逻辑写入合约。 Therefore, if you already have a contract deployed you would have to deploy a new ERC20 contract that has the logic - if you want the staking mechanism to be within the same contract.因此,如果您已经部署了合约,则必须部署具有逻辑的新 ERC20 合约——如果您希望抵押机制在同一个合约中。 Then you would have to transfer balances from the previous version of the contract to the newly deployed contract.然后,您必须将余额从合同的先前版本转移到新部署的合同。 While possible, it would incur a gas expense to replicate the contract state.虽然可能,但复制合约状态会产生 gas 费用。 You could have your token holders pay this gas cost by having some sort of mint or recover function that would read the old contract balance for an address, create the balance on the new contract, and then mark the balance as transferred.您可以让您的代币持有者通过使用某种mintrecover功能来支付此 gas 成本,该功能会读取地址的旧合约余额,在新合约上创建余额,然后将余额标记为已转移。

Alternatively, to your second question, you could facilitate the staking with an additional contract that users would set an allowance to within the ERC20 contract.或者,对于您的第二个问题,您可以通过附加合同来促进抵押,用户可以在 ERC20 合同中设置配额。 Then, users could interact with something like a stake function on this new staking contract.然后,用户可以用像一个互动stake这一新的跑马圈地合同的功能。 The staking contract would use the transferFrom ERC20 function to transfer tokens from the owner to the staking contract's address after incrementing the user's staked token amount within the staking contract. Staking 合约将使用transferFrom ERC20 函数增加用户在 Staking 合约内的 Staking 代币数量后,将代币从所有者transferFrom Staking 合约的地址 This would record the holder's staking "credit" and tie the tokens up by transferring their ownership to the staking contract.这将记录持有者的抵押“信用”,并通过将其所有权转移到抵押合约来绑定代币。 Users could then unstake which would decrement the user's staked token amount and transfer the tokens back from the staking contract's address to the token holder's address.然后用户可以unstake ,这将减少用户unstake的代币数量,并将代币从抵押合约的地址转移回代币持有者的地址。 This type of approach has more moving pieces but could be a more flexible step while developing the mechanism as you can deploy new versions of the staking contract without having to redeploy the ERC20 contract or transfer balances.这种方法有更多的移动部分,但在开发机制时可能是一个更灵活的步骤,因为您可以部署新版本的 staking 合约,而无需重新部署 ERC20 合约或转移余额。 Users would be able to transfer like normal throughout multiple versions of the staking contract and extracting tokens from previous versions of the staking contracts would be gas-efficient.用户将能够像往常一样在多个版本的 staking 合约中进行转移,并且从之前版本的 staking 合约中提取代币将非常高效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM