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

Implement Stake Pre-Splitting #444

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 4 additions & 2 deletions chain_params.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"proposalFeeConfirmRequirement": 6,
"maxPaymentCycles": 6,
"maxPayment": 43200000000000,
"defaultColdStakingAddress": "SdgQDpS8jDRJDX8yK8m9KnTMarsE84zdsy"
"defaultColdStakingAddress": "SdgQDpS8jDRJDX8yK8m9KnTMarsE84zdsy",
"stakeSplitTarget": 50000000000
},
"testnet": {
"name": "testnet",
Expand Down Expand Up @@ -64,6 +65,7 @@
"proposalFeeConfirmRequirement": 3,
"maxPaymentCycles": 20,
"maxPayment": 144000000000,
"defaultColdStakingAddress": "WmNziUEPyhnUkiVdfsiNX93H6rSJnios44"
"defaultColdStakingAddress": "WmNziUEPyhnUkiVdfsiNX93H6rSJnios44",
"stakeSplitTarget": 50000000000
}
}
6 changes: 4 additions & 2 deletions chain_params.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"proposalFeeConfirmRequirement": 3,
"maxPaymentCycles": 20,
"maxPayment": 144000000000,
"defaultColdStakingAddress": "WmNziUEPyhnUkiVdfsiNX93H6rSJnios44"
"defaultColdStakingAddress": "WmNziUEPyhnUkiVdfsiNX93H6rSJnios44",
"stakeSplitTarget": 50000000000
},
"testnet": {
"name": "testnet",
Expand Down Expand Up @@ -54,6 +55,7 @@
"proposalFeeConfirmRequirement": 3,
"maxPaymentCycles": 20,
"maxPayment": 144000000000,
"defaultColdStakingAddress": "WmNziUEPyhnUkiVdfsiNX93H6rSJnios44"
"defaultColdStakingAddress": "WmNziUEPyhnUkiVdfsiNX93H6rSJnios44",
"stakeSplitTarget": 50000000000
}
}
26 changes: 21 additions & 5 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,27 @@ export class Wallet {
// Add primary output
if (isDelegation) {
if (!returnAddress) [returnAddress] = this.getNewAddress(1);
transactionBuilder.addColdStakeOutput({
address: returnAddress,
addressColdStake: address,
value,
});
// The per-output target for maximum staking efficiency
const nTarget = cChainParams.current.stakeSplitTarget;
// Keep track of the remainder, which is the 'unoptimal' output (or change/non-output, if too small)
let nRemainder = value;
// Generate optimal staking outputs
while (nRemainder > nTarget) {
JSKitty marked this conversation as resolved.
Show resolved Hide resolved
transactionBuilder.addColdStakeOutput({
address: returnAddress,
addressColdStake: address,
value: nTarget,
});
nRemainder -= nTarget;
}
// If the remainder is larger than one coin, we create the 'unoptimal' output
if (nRemainder >= COIN) {
transactionBuilder.addColdStakeOutput({
address: returnAddress,
addressColdStake: address,
value: nRemainder,
});
}
} else if (isProposal) {
transactionBuilder.addProposalOutput({
hash: address,
Expand Down