Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WrappedToken.sol #1095

Draft
wants to merge 67 commits into
base: feature/1.5.0.0-interflux
Choose a base branch
from
Draft
Changes from 21 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
2d3e00a
Merge remote-tracking branch 'origin/release/1.3.0.0' into release/1.…
fassadlr Oct 11, 2022
96da7d1
Merge remote-tracking branch 'origin/release/1.3.2.1' into release/1.…
fassadlr Oct 11, 2022
729e92c
Merge remote-tracking branch 'origin/release/1.3.2.2' into release/1.…
fassadlr Oct 11, 2022
248646d
Merge remote-tracking branch 'origin/release/1.3.3.0' into release/1.…
fassadlr Oct 11, 2022
a12874d
Bump all versions to 1.3.4.0
fassadlr Oct 11, 2022
6f65bf6
Merge remote-tracking branch 'origin/release/1.3.3.0' into release/1.…
fassadlr Oct 21, 2022
9968ba1
Merge remote-tracking branch 'origin/release/1.3.4.0' into release/1.…
fassadlr Oct 21, 2022
309391d
Bump all versions to 1.4.0.0
fassadlr Oct 21, 2022
0c93dd2
Merge branch 'feature/dotnet6' into release/1.4.0.0
fassadlr Nov 9, 2022
be5ccd6
Set version to RC
fassadlr Nov 9, 2022
8fcacb6
Always publish mining statistics
fassadlr Nov 10, 2022
c14acd9
Add activation height for multisig fee sorting
fassadlr Nov 10, 2022
24ab542
Fix GateWayPairStarts pair
fassadlr Nov 11, 2022
58fc318
Merge pull request #1092 from stratisproject/interflux-ms-fees-ort
fassadlr Nov 14, 2022
341746c
Update release 1.4 activation height
fassadlr Nov 14, 2022
0606287
Bump build version to 1.4.0.1
fassadlr Nov 14, 2022
2958d64
Fix multisig fee sort
fassadlr Nov 14, 2022
d62930c
Bump build revision to 1.4.0.2
fassadlr Nov 14, 2022
fa722c2
Set release 1.4 activation height
fassadlr Nov 16, 2022
1b6c10a
Add WrappedToken.sol
quantumagi Nov 17, 2022
d4a265e
Add WrappedToken.cs
quantumagi Nov 17, 2022
470db60
Changes based on feedback
quantumagi Nov 18, 2022
0032aa6
Rename
quantumagi Nov 18, 2022
333a033
Add burnId
quantumagi Nov 18, 2022
6afb5fe
Add blacklisting
quantumagi Jan 20, 2023
814a3ac
Fix names
quantumagi Jan 20, 2023
2027682
Use external
quantumagi Jan 20, 2023
75a0487
Fix compilation issues
quantumagi Jan 20, 2023
0113b7e
Update ABI
quantumagi Jan 20, 2023
991cd53
Update bytecode
quantumagi Jan 20, 2023
19abd6c
Update WrappedTokenDeployment
quantumagi Jan 20, 2023
721fd34
Fix
quantumagi Jan 20, 2023
344638f
Add helper classes
quantumagi Jan 20, 2023
e7d3278
Bump all versions to 1.3.4.0
fassadlr Oct 11, 2022
577aa63
Bump all versions to 1.4.0.0
fassadlr Oct 21, 2022
f9dfd51
Set version to RC
fassadlr Nov 9, 2022
84d7f40
Bump build version to 1.4.0.1
fassadlr Nov 14, 2022
149a154
Bump build revision to 1.4.0.2
fassadlr Nov 14, 2022
309aed9
Add WrappedToken.sol
quantumagi Nov 17, 2022
efb0ebb
Add WrappedToken.cs
quantumagi Nov 17, 2022
fb747f5
Changes based on feedback
quantumagi Nov 18, 2022
b2f731b
Rename
quantumagi Nov 18, 2022
485edaa
Add burnId
quantumagi Nov 18, 2022
c7c4232
Add blacklisting
quantumagi Jan 20, 2023
6887246
Fix names
quantumagi Jan 20, 2023
9ee754c
Use external
quantumagi Jan 20, 2023
9c8529e
Fix compilation issues
quantumagi Jan 20, 2023
61fe516
Update ABI
quantumagi Jan 20, 2023
407bed3
Update bytecode
quantumagi Jan 20, 2023
320e1c8
Update WrappedTokenDeployment
quantumagi Jan 20, 2023
1c39f6f
Fix
quantumagi Jan 20, 2023
938cdb0
Add helper classes
quantumagi Jan 20, 2023
aa8ed8d
Merge branch 'wrappedcoin' of https://github.com/quantumagi/StratisFu…
quantumagi Sep 4, 2023
2a69ad0
Move contract to correct folder
quantumagi Sep 4, 2023
cff1217
Fix rebase
quantumagi Sep 4, 2023
2521d06
Add require and comments
quantumagi Sep 4, 2023
6314e73
Add TODO
quantumagi Sep 4, 2023
b86f39d
The user signature is not required in the contract
quantumagi Sep 4, 2023
0f6355a
Implement replay check
quantumagi Sep 5, 2023
c649116
Add fee log
quantumagi Sep 6, 2023
7032879
Calculate decimalsFactor
quantumagi Sep 6, 2023
70dd28b
Cast amounts
quantumagi Sep 6, 2023
e58bb5e
Refactor decimalsFactor
quantumagi Sep 7, 2023
dcc237d
Remove fee and toaddr
quantumagi Sep 13, 2023
f97e1ae
Add transferForNetwork method
quantumagi Sep 14, 2023
49b02dc
Fix compile errors and add constants and private methods
quantumagi Sep 14, 2023
feb9812
Refactor
quantumagi Sep 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// contracts/WrappedToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC20/ERC20.sol";

contract WrappedToken is ERC20, Ownable {
mapping (address => string) public withdrawalAddresses;

constructor(string tokenName, string tokenSymbol, uint256 initialSupply) public ERC20(tokenName, tokenSymbol) {
_mint(msg.sender, initialSupply);
}

/**
* @dev Creates `amount` new tokens and assigns them to `account`.
*
* See {ERC20-_mint}.
*/
function mint(address account, uint256 amount) public onlyOwner {
_mint(account, amount);
}

/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount, string memory address) public {
_burn(_msgSender(), amount);

// When the tokens are burnt we need to know where to credit the equivalent value on the Stratis chain.
// Currently it is only possible to assign a single address here, so if multiple recipients are required
// the burner will have to wait until each burn is processed before proceeding with the next.
withdrawalAddresses[msg.sender] = address;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add additional method with onlyOwner modifier that removes value withdrawalAddresses[address].
And in burn method if address is set- revert.
That will prevent users sending requests with multiple recepients in a row before prev requests are processed and subsequently loosing money

Copy link
Contributor Author

@quantumagi quantumagi Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@noescape00 , I've made the following change:

        string memory key = string(abi.encodePacked(msg.sender, " ", burnId));
        withdrawalAddresses[key] = tokenAddress;

Trying to clean-up the dictionary may not be worth the additional costs for each multisig node.

}

/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount, string memory address) public {
uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance");

_approve(account, _msgSender(), decreasedAllowance);
_burn(account, amount);

// When the tokens are burnt we need to know where to credit the equivalent value on the Stratis chain.
// Currently it is only possible to assign a single address here, so if multiple recipients are required
// the burner will have to wait until each burn is processed before proceeding with the next.
withdrawalAddresses[msg.sender] = address;
}
}
656 changes: 656 additions & 0 deletions src/Stratis.Bitcoin.Features.Interop/ETHClient/WrappedToken.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Stratis.Bitcoin.EventBus;
using Stratis.Bitcoin.EventBus;

namespace Stratis.Bitcoin.Features.PoA.Events
{
8 changes: 8 additions & 0 deletions src/Stratis.Bitcoin.Features.PoA/PoAConsensusOptions.cs
Original file line number Diff line number Diff line change
@@ -58,6 +58,14 @@ public class PoAConsensusOptions : ConsensusOptions
/// </summary>
public int Release1300ActivationHeight { get; set; }

/// <summary>
/// The height at which Release 1.4.0.0 became active.
/// <para>
/// This was primarily used for activating ScriptPubkey sorting for paying multisig recipients.
/// </para>
/// </summary>
public int Release1400ActivationHeight { get; set; }

/// <summary>
/// The height at which inituitive mining slots become active.
/// Legacy mining slots are determined by mining_slot = block_height % number_of_federation_members.
15 changes: 8 additions & 7 deletions src/Stratis.Bitcoin.Features.PoA/PoAMiner.cs
Original file line number Diff line number Diff line change
@@ -222,6 +222,8 @@ private void GatherMiningStatistics()

this.miningStatisticsLog = log.ToString();

this.signals?.Publish(new MiningStatisticsEvent(this.miningStatistics, 0));

return;
}

@@ -233,6 +235,8 @@ private void GatherMiningStatistics()

this.miningStatisticsLog = log.ToString();

this.signals?.Publish(new MiningStatisticsEvent(this.miningStatistics, 0));

return;
}

@@ -249,7 +253,7 @@ private void GatherMiningStatistics()
// TODO: Make this a command line option.
bool includeHeight = false;

log.AppendLine($"Mining information for the last { maxDepth } blocks.");
log.AppendLine($"Mining information for the last {maxDepth} blocks.");
if (includeHeight)
log.AppendLine("Note 'MISS' indicates a slot where a miner didn't produce a block.");
else
@@ -288,7 +292,7 @@ private void GatherMiningStatistics()
if (includeHeight)
{
string strHeight = minedInThisSlot ? currentHeader.Height.ToString().PadLeft(7) : "---MISS";
log.Append($"{strHeight}:{ pubKeyRepresentation } ");
log.Append($"{strHeight}:{pubKeyRepresentation} ");
}
else
{
@@ -304,15 +308,12 @@ private void GatherMiningStatistics()

this.miningStatistics.MinerHits = hitCount;

if (this.signals != null)
{
this.signals.Publish(new MiningStatisticsEvent(this.miningStatistics, maxDepth));
}
this.signals?.Publish(new MiningStatisticsEvent(this.miningStatistics, maxDepth));

log.Append("...");
log.AppendLine();
log.AppendLine($"Miner hits".PadRight(LoggingConfiguration.ColumnLength) + $": {hitCount} of {maxDepth}({(((float)hitCount / (float)maxDepth)).ToString("P2")})");
log.AppendLine($"Miner idle time".PadRight(LoggingConfiguration.ColumnLength) + $": { TimeSpan.FromSeconds(this.network.ConsensusOptions.TargetSpacingSeconds * (maxDepth - hitCount)).ToString(@"hh\:mm\:ss")}");
log.AppendLine($"Miner idle time".PadRight(LoggingConfiguration.ColumnLength) + $": {TimeSpan.FromSeconds(this.network.ConsensusOptions.TargetSpacingSeconds * (maxDepth - hitCount)).ToString(@"hh\:mm\:ss")}");
log.AppendLine();

this.miningStatisticsLog = log.ToString();
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Stratis.Bitcoin.EventBus;
using Stratis.Bitcoin.Features.PoA.Events;

@@ -16,7 +14,7 @@ public class MiningStatisticsClientEvent : IClientEvent
public void BuildFrom(EventBase @event)
{
if (@event is MiningStatisticsEvent miningStatisticsEvent)
{
{
this.IsMining = miningStatisticsEvent.MiningStatistics.ProducedBlockInLastRound;
this.BlockProducerHit = miningStatisticsEvent.MiningStatistics.MinerHits;
this.FederationMemberSize = miningStatisticsEvent.FederationMemberSize;
4 changes: 2 additions & 2 deletions src/Stratis.Bitcoin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.0.7")]
[assembly: AssemblyFileVersion("1.4.0.7")]
[assembly: AssemblyVersion("1.4.0.2")]
[assembly: AssemblyFileVersion("1.4.0.2")]
[assembly: InternalsVisibleTo("Stratis.Bitcoin.Tests")]
2 changes: 1 addition & 1 deletion src/Stratis.Bitcoin/Stratis.Bitcoin.csproj
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.4.0.7</Version>
<Version>1.4.0.2-rc</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<CodeAnalysisRuleSet>..\Stratis.ruleset</CodeAnalysisRuleSet>
<Authors>Stratis Group Ltd.</Authors>
Original file line number Diff line number Diff line change
@@ -167,17 +167,20 @@ public void GatewayPairStarts()
{
using (var nodeBuilder = SidechainNodeBuilder.CreateSidechainNodeBuilder(this))
{
CoreNode side = nodeBuilder.CreateSidechainFederationNode(this.sidechainNetwork, this.mainNetwork, this.sidechainNetwork.FederationKeys[0]);
CirrusRegTest collateralSidechainNetwork = new CirrusSingleCollateralRegTest();

CoreNode side = nodeBuilder.CreateSidechainFederationNode(collateralSidechainNetwork, this.mainNetwork, collateralSidechainNetwork.FederationKeys[0]);
side.AppendToConfig("sidechain=1");
side.AppendToConfig($"redeemscript={this.scriptAndAddresses.payToMultiSig}");
side.AppendToConfig($"publickey={this.sidechainNetwork.FederationMnemonics[0].DeriveExtKey().PrivateKey.PubKey}");
side.AppendToConfig($"publickey={collateralSidechainNetwork.FederationMnemonics[0].DeriveExtKey().PrivateKey.PubKey}");
side.AppendToConfig("federationips=0.0.0.0,0.0.0.1"); // Placeholders
side.AppendToConfig($"mindepositconfirmations={DepositConfirmations}");

CoreNode main = nodeBuilder.CreateMainChainFederationNode(this.mainNetwork, this.sidechainNetwork).WithWallet();
CoreNode main = nodeBuilder.CreateMainChainFederationNode(this.mainNetwork, collateralSidechainNetwork).WithWallet();
main.AppendToConfig("addressindex=1");
main.AppendToConfig("mainchain=1");
main.AppendToConfig($"redeemscript={this.scriptAndAddresses.payToMultiSig}");
main.AppendToConfig($"publickey={this.sidechainNetwork.FederationMnemonics[0].DeriveExtKey().PrivateKey.PubKey}");
main.AppendToConfig($"publickey={collateralSidechainNetwork.FederationMnemonics[0].DeriveExtKey().PrivateKey.PubKey}");
main.AppendToConfig("federationips=0.0.0.0,0.0.0.1"); // Placeholders
main.AppendToConfig($"mindepositconfirmations={DepositConfirmations}");

Original file line number Diff line number Diff line change
@@ -142,9 +142,11 @@ public List<Recipient> DistributeToMultisigNodes(uint256 depositId, Money fee)
multiSigRecipients.Add(new Recipient() { Amount = feeReward, ScriptPubKey = multiSigMinerScript });
this.logger.LogDebug($"Paying multisig member '{multiSigMinerScript.ToHex()}' (hex) {feeReward} STRAX.");
}

}

if (this.chainIndexer.Tip.Height >= (this.network.Consensus.Options as PoAConsensusOptions).Release1400ActivationHeight)
return multiSigRecipients.OrderBy(m => m.ScriptPubKey.ToHex()).ToList();

return multiSigRecipients;
}

3 changes: 2 additions & 1 deletion src/Stratis.Sidechains.Networks/CirrusMain.cs
Original file line number Diff line number Diff line change
@@ -185,7 +185,8 @@ public CirrusMain()
GetMiningTimestampV2ActivationHeight = 3_709_000, // Monday 14 February 00:00:00 (Estimated)
GetMiningTimestampV2ActivationStrictHeight = 3_783_000, // Monday 28 February 07:00:00 (London Time) (Estimated)
ContractSerializerV2ActivationHeight = 3_386_335, // Monday 13 December 16:00:00 (Estimated)
Release1300ActivationHeight = 4_334_400
Release1300ActivationHeight = 4_334_400,
Release1400ActivationHeight = 5_345_325, // 7 December 2022 (Estimated)
};

var buriedDeployments = new BuriedDeploymentsArray
3 changes: 2 additions & 1 deletion src/Stratis.Sidechains.Networks/CirrusTest.cs
Original file line number Diff line number Diff line change
@@ -136,7 +136,8 @@ public CirrusTest()
GetMiningTimestampV2ActivationHeight = 3_000_000, // 15 January 2022
GetMiningTimestampV2ActivationStrictHeight = 3_121_500, // 17 January 2022
ContractSerializerV2ActivationHeight = 2_842_681,
Release1300ActivationHeight = 3_280_032
Release1300ActivationHeight = 3_280_032,
Release1400ActivationHeight = 4_074_250,
};

var buriedDeployments = new BuriedDeploymentsArray