Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update kudos #7

Merged
merged 34 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c5d10cb
refactor: kudos
heueristik Jul 4, 2024
831d9dd
build: update deps
heueristik Jul 4, 2024
44d0f78
feat: add logic comparison
heueristik Jul 4, 2024
a694421
revert: reintroduce example
heueristik Jul 5, 2024
4823c00
fix: naming
heueristik Jul 5, 2024
3af7745
docs: improve comment
heueristik Jul 5, 2024
c812b07
feat: update kudos
heueristik Jul 18, 2024
300f1a6
refactor: formatting and naming
heueristik Jul 18, 2024
b86230e
feat: improve kudos error handling
heueristik Jul 18, 2024
0dbbe7a
feat: imporved kudo check
heueristik Jul 22, 2024
c17a844
build: update deps
heueristik Jul 22, 2024
64c58b4
feat: implement getBalance
heueristik Jul 22, 2024
edbeb45
fix: wrong import
heueristik Jul 22, 2024
69cb183
refactor: update deps and label
heueristik Jul 22, 2024
3a0004e
build: use nightly tag
heueristik Jul 22, 2024
05fbd5b
build: update deps
heueristik Jul 23, 2024
fa84f5c
build: update deps
heueristik Jul 23, 2024
ee4cbe6
feat: improve error handling
heueristik Jul 23, 2024
3512b77
build: update deps
heueristik Jul 23, 2024
5953793
build: update deps
heueristik Jul 23, 2024
622ae82
fix: example
heueristik Jul 25, 2024
f7b1e26
chore: update deps
heueristik Jul 25, 2024
818aeaf
chore: update deps and adapt
heueristik Jul 26, 2024
a97b5ae
refactor: imports
heueristik Jul 26, 2024
e293c83
refactor: adapt Kudos
heueristik Aug 9, 2024
1c3eef6
chore: update deps
heueristik Sep 4, 2024
4be0c56
chore: bump deps and cleaning
heueristik Sep 6, 2024
83dd479
chore: bump deps
heueristik Sep 6, 2024
3f481e5
chore: update deps
heueristik Sep 6, 2024
f405b64
Merge branch 'main' into feature/kudos
heueristik Sep 6, 2024
c751862
feat: adapted apps
heueristik Oct 21, 2024
fe4123f
chore: use refactored applib
heueristik Oct 22, 2024
7d9c930
chore: update deps
heueristik Oct 23, 2024
1d5aaca
chore: bump dep
heueristik Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/test.yaml → .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Test anoma-apps

on:
Expand All @@ -8,18 +7,25 @@ on:
workflow_dispatch:

jobs:
test:
tests:
name: Run test suite
runs-on: ubuntu-latest
defaults:
run:
working-directory: Kudos
steps:
- name: checkout code
uses: actions/checkout@v3

- name: Download latest nightly Juvix binary
uses: jaxxstorm/[email protected]
with:
repo: anoma/juvix-nightly-builds
cache: enable

- name: Run tests
run: juvix eval tests/Main.juvix
- name: Clean
run: juvix clean --global && juvix clean && juvix dependencies update
- name: Type Check
run: juvix typecheck
- name: Format Check
run: juvix format
- name: Run Example
run: juvix eval Example.juvix
35 changes: 28 additions & 7 deletions Kudos/Example.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,36 @@ module Example;

import Anoma open;
import Stdlib.Prelude open;
import Stdlib.Debug.Fail open using {failwith};

import Kudos open;
import Applib.Resource.Error open;
import Applib.Authorization.Identities open;
import Applib.Helpers open;

alice : KeyPair := mkKeyPair@{
pubKey := 0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac1;
privKey := 0xddd315c76991f8e058760cacdd19c21bf6a12c72bc229a60ad6aaa314fa07ac11662fc6e7829efcb0f4500827d49bb699af7b5475cef5220fd600ebbf9709a58;
};
import Anoma.Transaction open;
import Anoma.Identity open;
import Anoma.State.CommitmentTree open;

bob : PublicKey := 0x7d59c5623dd40a74aa4d5a32ac645d3b3f95daeae4c22be25476dd6a486f7382;
import Interface open;

alice : Identity := Universal.identity;

bob : ExternalIdentity := Zero.externalIdentity;

standardInputs : StandardInputs :=
mkStandardInputs@{
identity := alice;
currentRoot := mkRoot 0
};

--- Create 10 Kudo tokens as Alice (the originator) for Bob (the owner).
main : Transaction := create@{self := alice; amount := 10; receiver := bob};
main : Transaction :=
case
initialize@{
standardInputs;
quantity := 10;
receiver := bob
}
of
| error err := failwith (Show.show err)
| ok tx := tx;
150 changes: 150 additions & 0 deletions Kudos/Interface.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
module Interface;

import Stdlib.Prelude open;

import Anoma.Identity open;
import Anoma.Transaction open;
import Anoma.Resource open;

import Applib.Resource.Error open;
import Applib.Transaction as Transaction;

import Applib.Token.Resource open;
import Applib.Token.Label open;
import Applib.Intent.Asset open;
import Applib.Intent.Swap.Resource open;
import Applib.Intent.Swap.Solution open;

import Applib.Helpers open;

import Label open;

initialize
(standardInputs : StandardInputs)
(quantity : Quantity)
(receiver : ExternalIdentity)
: Result StandardError Transaction :=
let
self := standardInputs |> StandardInputs.identity |> Identity.external;
token :=
Token.create@{
quantity;
tokenLabel := mkKudoLabel self;
owner := receiver
};
in Transaction.initialize@{
standardInputs;
toInitialize := token;
maybeDummy := nothing
};

finalize (standardInputs : StandardInputs) (token : Token) : Result StandardError Transaction :=
let
self : ExternalIdentity := standardInputs |> StandardInputs.identity |> Identity.external;
in case isKudo (self) token of
| false := throw notKudoError
| true :=
Transaction.finalize@{
standardInputs;
toFinalize := token
};

send
(standardInputs : StandardInputs)
(token : Token)
(quantity : Quantity)
(receiver : ExternalIdentity)
: Result StandardError Transaction :=
let
self : ExternalIdentity := standardInputs |> StandardInputs.identity |> Identity.external;
in case isKudo self token of
| false := throw notKudoError
| true :=
Transaction.send@{
standardInputs;
toSend := token;
quantity;
receiver
};

transfer
(standardInputs : StandardInputs)
(token : Token)
(receiver : ExternalIdentity)
: Result StandardError Transaction :=
let
self : ExternalIdentity := standardInputs |> StandardInputs.identity |> Identity.external;
in case isKudo (self) token of
| false := throw notKudoError
| true :=
Transaction.transfer@{
standardInputs;
toTransfer := token;
receiver
};

split
(standardInputs : StandardInputs)
(token : Token)
-- TODO refactor type
(quantitiesAndReceivers : List (Pair Quantity ExternalIdentity))
: Result StandardError Transaction :=
let
self : ExternalIdentity := standardInputs |> StandardInputs.identity |> Identity.external;
in case isKudo self token of
| false := throw notKudoError
| true :=
Transaction.split@{
standardInputs;
toSplit := token;
quantitiesAndReceivers
};

merge
(standardInputs : StandardInputs)
(tokens : List Token)
(receiver : ExternalIdentity)
: Result StandardError Transaction :=
let
self := standardInputs |> StandardInputs.identity |> Identity.external;
in case all (t in tokens) {isKudo self t} of
| false := throw notKudoError
| true :=
Transaction.merge@{
standardInputs;
toMerge := tokens;
receiver
};

swap
(standardInputs : StandardInputs)
(toSwap : List Token)
(want : QuantifiedAssets)
(solver : ExternalIdentity)
: Result StandardError Transaction :=
let
self := standardInputs |> StandardInputs.identity |> Identity.external;
in case all (t in toSwap) {isKudo self t} of
| false := throw notKudoError
| true :=
Transaction.swap@{
standardInputs;
toSwap;
intent :=
SwapIntent.create@{
want;
receiver := self;
solver
}
};

settle
(standardInputs : StandardInputs)
(transactions : List Transaction)
(solutions : List Solution)
: Result StandardError Transaction :=
Transaction.settle@{
standardInputs;
transactions;
solutions
};
38 changes: 2 additions & 36 deletions Kudos/Kudos.juvix
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
module Kudos;

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;
import Label open public;
import Interface open public;
44 changes: 35 additions & 9 deletions Kudos/Label.juvix
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
module Label;

import Anoma open;
import Stdlib.Prelude open;
import Applib.Helpers open;

import Token.Label open public;
import Applib.Token.Resource open;
import Applib.Token.Label open;
import Applib.Token.Logic open;

mkKudoLabel (originator : PublicKey) : Label :=
mkLabel@{
name := originator;
symbol := "Kudos";
decimals := 18
import Applib.Resource.Error open;
import Applib.Resource.Traits open;

import Anoma.Identity open;
import Anoma.Builtin.System open;

mkKudoLabel (originator : ExternalIdentity) : TokenLabel :=
mkTokenLabel@{
name := "Kudos";
symbol := "KDS";
decimals := 18;
supply := Unbound;
transferability := Transferability.Transferable;
originator
};

getOriginator (r : Resource) : PublicKey :=
Label.name (anomaDecode (Resource.label r));
isKudo (originator : ExternalIdentity) (token : Token) : Bool :=
let
expectedLabel : TokenLabel := mkKudoLabel originator;
label : TokenLabel := HasLabel.get token;
expectedLogicEncoded : Nat :=
tokenLogic (TokenLabel.supply expectedLabel) originator |> anomaEncode;
logicEncoded : Nat := HasLogic.get token |> anomaEncode;
in if
| label /= expectedLabel := false
| logicEncoded /= expectedLogicEncoded := false
| else := true;

notKudoError : DefaultError :=
mkDefaultError@{
msg := "The input resource is not a Kudo token."
};
Loading
Loading