2

What I want to do: Send 25 ADA and lock it all at the script address until 1 of the 2 scenarios happen:

  1. 100 ADA is sent by Nov 25th (today is Nov 20th) and all ADA at the script address is sent out to some arbitrary address (total 125 ADA sent out)
  2. It is Nov 25th and 100 ADA has not been sent and locked at the script address by now, so all ADA at the script address is burned (25 ADA and whatever else that was sent below 100 ADA is burned)

Is this possible with Plutus smart contracts? Is there anyway at all a smart contract like this can be implemented on the Cardano blockchain?

1 Answer 1

3

Yes. Something like this is relatively trivial for a Plutus script (Essentially, locking funds and some data at an address is the only thing scripts do).

Here is one approach you could take. There are many other ways you could do this, but this is fairly reusable construction:

Your datum type could have the fields:

  1. Target Amount
  2. Deadline
  3. Recipient "Arbitrary" Address (if you want it to go to a specific party)

The script will ensure that the Datum UTxO can only be redeemed if:

  1. The OUTPUT of the spending Tx includes a UTxO paid to the Recipient of value >= Target Amount && the Tx was executed before the Deadline, OR
  2. The Datum is replaced with a new identical Datum and a UTxO of >= the value on the previous Datum.

You can see an example of scripts requiring the datum is replaced with a new one in the PPP Oracle example or the Uniswap example, with their corresponding off-chain code here and here.

The case where the deadline is passed and the ADA is burned is implicit in a Datum that can no longer be redeemed--if no-one can reach the funds, they are as good as burned (there is no actual way to burn ADA anyway).

To initialize the script, you will create the Datum with an attached 25 ADA. There would be nothing ensuring that the initial value is 25 ADA, but that doesn't seem like an issue. A script that makes that requirement would need to be more complex.

2
  • Thank you, Mitchell! Your level of detail is much appreciated. If we could get even deeper, I'm wondering about the 2nd option of redemption you mention. Do you have any references/examples for how to replace a Datum from within the smart contract? I'm assuming it's in Haskell, or could it be done another way?
    – Myles
    Nov 23, 2021 at 0:32
  • Added some examples to my answer. This will require you to write Plutus (on-chain script) and Haskell (off-chain code). If you aren't familiar with writing Plutus smart contracts, I'd highly encourage you to go through the Plutus Pioneer Program lectures. Unfortunately, Plutus is a young language and not trivially easy to pick up. Nov 23, 2021 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.