-
-
Save A60AB5450353F40E/c2140423440c2c5e8ef6c856e6819473 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract SecurityBudgetFund() { | |
function DonateOrPayout() { | |
require(tx.inputs[this.activeInputIndex].lockingBytecode == | |
tx.outputs[this.activeInputIndex].lockingBytecode); | |
int amountDiff = | |
tx.outputs[this.activeInputIndex].value - | |
tx.inputs[this.activeInputIndex].value; | |
// Donate | |
if (amountDiff > 0) { | |
// a day's worth of min. payouts is the minimum donation | |
require(amountDiff >= 14400); | |
// Payout | |
} else { | |
// Payout claimed as TX fee | |
require(tx.inputs.length == 1); | |
require(tx.outputs.length == 1); | |
// Payout once per block | |
require(tx.age >= 1); | |
// Decay half-life of 4 years | |
int maxPayout = (tx.inputs[this.activeInputIndex].value * 4392) / 1333036486; | |
// If payout would be too low, switch to flat payout | |
if (maxPayout < 100) { | |
maxPayout = 100; | |
} | |
// Enforce maxPayout amount | |
require(abs(amountDiff) <= maxPayout); | |
} | |
} | |
function TerminateOrMerge() { | |
// Only 1 output in any case | |
require(tx.outputs.length == 1); | |
// Terminate | |
if (tx.inputs.length == 1) { | |
// allow termination only if this contract UTXO has a day or less worth of | |
// min. payouts remaining | |
require(tx.inputs[0].value <= 14400); | |
require(tx.outputs[0].lockingBytecode == 0x6a); | |
require(tx.outputs[0].value == 0); | |
// Merge | |
} else { | |
// allow only the case of 2-in-1-out merge | |
require(tx.inputs.length == 2); | |
// the 2 inputs and the 1 output must all have same contract | |
require(tx.inputs[0].lockingBytecode == tx.inputs[1].lockingBytecode); | |
require(tx.inputs[0].lockingBytecode == tx.outputs[0].lockingBytecode); | |
// and they can be merged only if they're each not below min. already | |
// (in which case Terminate should be used individually) | |
int mergeMin = 14400; | |
require(tx.inputs[0].value > mergeMin); | |
require(tx.inputs[1].value > mergeMin); | |
// and we allow the mergeMin amount to be extracted as bonus, | |
// so there's incentive to merge rather than drip 2 UTXOs independently | |
require(tx.outputs[0].value >= tx.inputs[0].value + tx.inputs[1].value - mergeMin); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment