Skip to content

Commit

Permalink
feat: composable kudos (#2)
Browse files Browse the repository at this point in the history
* refactor: kudos

* build: update deps

* feat: add logic comparison

* revert: reintroduce example

* fix: naming

* docs: improve comment
  • Loading branch information
heueristik authored Jul 15, 2024
1 parent d82e7d8 commit e5807f4
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 288 deletions.
26 changes: 8 additions & 18 deletions Kudos/Example.juvix
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
module Example;

import Anoma open;
import Kudos open;
import Stdlib.Prelude open;

--- The originator's private key
privKey : Nat :=
0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac11662fc6e7829efcb0f4500827d49bb699af7b5475cef5220fd600ebbf9709a58;

--- The originator's public key
pubKey : PublicKey :=
0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac1;

-- TODO: These should use different keypairs
commitmentKeyPair : KeyPair := mkKeyPair pubKey privKey;
import Kudos open;

originatorKeyPair : KeyPair := commitmentKeyPair;
alice : KeyPair := mkKeyPair@{
pubKey := 0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac1;
privKey := 0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac11662fc6e7829efcb0f4500827d49bb699af7b5475cef5220fd600ebbf9709a58;
};

owner : Owner := mkOwner pubKey;
bob : PublicKey := 0x7d59c5623dd40a74aa4d5a32ac645d3b3f95daeae4c22be25476dd6a486f7382;

--- After this transaction is verified there is a resource in the commitment
--- tree that represents 10 Kudos of the originator's kind that are owned by the
--- specified owner.
main : Transaction :=
instantiate commitmentKeyPair owner originatorKeyPair 10;
--- Create 10 Kudo tokens as Alice (the originator) for Bob (the owner).
main : Transaction := create@{self := alice; amount := 10; receiver := bob};
39 changes: 36 additions & 3 deletions Kudos/Kudos.juvix
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
module Kudos;

import Kudos.Types open public;
import Kudos.Logic open public;
import Kudos.Instantiate open public;
import Stdlib.Prelude open;
import Anoma open;
import Token.Transaction open;
import Token.Logic open;

import Label open;

--- Creates an amount of Kudo tokens to a receiver.
create
(self : KeyPair)
(amount : Nat)
(receiver : PublicKey)
: Transaction :=
let
kudoLabel : Label := mkKudoLabel (KeyPair.pubKey self);
in Token.Transaction.mint self kudoLabel amount receiver;

--- Sends an amount of Kudo tokens to a receiver.
--- If the token ;Resource; has no Kudos ;Label; this function returns nothing.
--- If the token logic function differs from the current implementation, this function returns nothing,
--- If the calling ;KeyPair; is not the owner, this function returns nothing.
send
(self : KeyPair)
(token : Resource)
(amount : Nat)
(receiver : PublicKey)
: Maybe Transaction :=
let
isKudo (r : Resource) : Bool :=
getSymbol r == "Kudos"
&& getDecimals r == 18
&& anomaEncode(Resource.logic r) == anomaEncode(tokenLogic);
in if
| isKudo token :=
Token.Transaction.send self token amount receiver
| else := nothing;
34 changes: 0 additions & 34 deletions Kudos/Kudos/Extra.juvix

This file was deleted.

120 changes: 0 additions & 120 deletions Kudos/Kudos/Instantiate.juvix

This file was deleted.

44 changes: 0 additions & 44 deletions Kudos/Kudos/Logic.juvix

This file was deleted.

14 changes: 0 additions & 14 deletions Kudos/Kudos/Types.juvix

This file was deleted.

15 changes: 15 additions & 0 deletions Kudos/Label.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Label;

import Anoma open;

import Token.Label open public;

mkKudoLabel (originator : PublicKey) : Label :=
mkLabel@{
name := originator;
symbol := "Kudos";
decimals := 18
};

getOriginator (r : Resource) : PublicKey :=
Label.name (anomaDecode (Resource.label r));
9 changes: 4 additions & 5 deletions Kudos/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import PackageDescription.V2 open;
package : Package :=
defaultPackage
{name := "kudos";
dependencies := [ defaultStdlib
; github
"anoma"
"juvix-anoma-stdlib"
"b91e93a7582a7ac87e7756e39c28affc05926dca"
dependencies := [ github "anoma" "juvix-anoma-stdlib" "v0.1.0"
; github "anoma" "juvix-stdlib" "v0.4.0"
; github "anoma" "juvix-containers" "v0.12.1"
; github "anoma" "anoma-app-patterns" "v0.1.2"
]};
44 changes: 0 additions & 44 deletions Kudos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,6 @@

Status: DRAFT

## Paricipants

### Originator

A user that can create any quantity of a particular kind of Kudos.

### Owner

A user that owns some quantity of a particular kind of Kudos.

## Resource Structure

### Label

The value of the `label` field contains the _originator_'s public key.

### Data

The value of the `data` field contains the _owner_'s public key.

## Transaction Structure

### Extra

The value of the `extra` field is a signature generated from the transaction commitments and nullifiers using the _owner_'s private key.

## Interface

### Instantiate

Instantiate a quantity of a Kudos kind owned by a specified owner.

See [Example.juvix](Example.juvix) for an example of using this interface.

## Logic

### Instantiate

The consumed ephemeral resource of the _orignator_'s kind must be owned by the _originator_, i.e:
* The _originator public key_ must equal the _owner_'s public key on the resource.

All consumed resources must be authorized for by the _owner_ i.e:
* The _transaction signature_ must be valid for the transaction commitments and nullifiers using the _owner public key_.

## How to run it

You need:
Expand Down
Loading

0 comments on commit e5807f4

Please sign in to comment.