PIGY Token Smart Contract Testing

Your contract is close to what you’re attempting, but it needs some adjustments. Here are answers to your questions:

  1. The Marlowe language current doesn’t have constructs for delegation. A delegation transaction is mostly like a regular transaction, but it also has a delegation certificate attached to it. I think that Alice’s delegation transaction would have to occur outside of the contract.
  2. Yes, when you run the simulator in the Marlowe playground, you can enter 100,000 in the input field labeled Reward at the start of running the contract.
  3. Because of item #1, I think you’ll need an oracle (a trusted third party) to signal that Alice has indeed delegated to Bob’s pool.
  4. The contract that you posted has one dangerous aspect. When a deposit is made into an account, at the end of the contract anything left in that account is refunded to the account owner. Thus, the second and third close in that contract would refund the money to Alice the delegator, not to Bob’s pool. It’s important to test every eventuality in the simulator to make sure that funds aren’t refunded to the wrong role.

In the contract below, I corrected problem #4 and added Charlie the Oracle. The oracle doesn’t send funds to the contract, but instead it verifies that the delegation did indeed occur. Alice or Bob could serve as the oracle if they trusted each other.
image

Here is the transcript from running the contract when Charlie asserts that the delegation occurred:

Deposit 100,000 units of PIGY into account of BOBS POOL as BOBS POOL
Participant CHARLIE THE ORACLE chooses the value 1 for choice with id “ALICE DELEGATED FOR 2 EPOCHS”
The contract pays 100,000 units of PIGY to participant ALICE THE DELEGATOR

And here is the transcript from running the contract when Charlie asserts that the delegation did not occur:

Deposit 100,000 units of PIGY into account of BOBS POOL as BOBS POOL
Participant CHARLIE THE ORACLE chooses the value 0 for choice with id “ALICE DELEGATED FOR 2 EPOCHS”
The contract pays 100,000 units of PIGY to participant BOBS POOL

Here you can see that the second close caused the refund to Bob.

By the way, here is a discussion about using simple scripts to obtain a result similar to the Marlowe contract. It isn’t a practical solution yet because the commonly used wallets don’t support multiple wallets witnessing the same transaction, and it also requires a sophisticated delegator.

P.S. Maybe a fairer version of the contract would be for Alice to get 50,000 PIGY if Charlie doesn’t make any choice: to do this, the third close should be replaced by paying Alice half and letting the remainder be refunded to Bob.

3 Likes