pragma cashscript >= 0.7.1; // v20220522 // This is an experimental perpetuity contract // Beta stage contract Perpetuity( // interval for payouts, in blocks int period, // lockingBytecode of the beneficiary, // the address receiving payments bytes recipientLockingBytecode, // extra allowance for administration of contract // fees are paid from executors' allowance. int executorAllowance, // divisor for the payout, // each payout must be greater than // the input amount held on the contract // divided by this number int decay ) { function execute() { // Check that the first output sends to the recipient require(tx.outputs[0].lockingBytecode == recipientLockingBytecode); // Check that time has passed and that time locks are enabled require(tx.age >= period); // require the second output to match the active bytecode require(tx.outputs[1].lockingBytecode == new LockingBytecodeP2SH(hash160(this.activeBytecode))); // Get the input value on the contract int currentValue = tx.inputs[this.activeInputIndex].value; // The payout is the current value divided by the decay int installment = currentValue/decay; // Calculate value returned to the contract int returnedValue = currentValue - installment - executorAllowance; // Check that the outputs send the correct amounts require(tx.outputs[0].value >= installment); require(tx.outputs[1].value >= returnedValue); } }