-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: kudos * build: update deps * feat: add logic comparison * revert: reintroduce example * fix: naming * docs: improve comment * feat: update kudos * refactor: formatting and naming * feat: improve kudos error handling * feat: imporved kudo check * build: update deps * feat: implement getBalance * fix: wrong import * refactor: update deps and label * build: use nightly tag * build: update deps * build: update deps * feat: improve error handling * build: update deps * build: update deps * fix: example * chore: update deps * chore: update deps and adapt * refactor: imports * refactor: adapt Kudos * chore: update deps * chore: bump deps and cleaning * chore: bump deps * chore: update deps * feat: adapted apps * chore: use refactored applib * chore: update deps * chore: bump dep
- Loading branch information
1 parent
a4f04aa
commit 10113e3
Showing
19 changed files
with
365 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
name: Test anoma-apps | ||
|
||
on: | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
}; |
Oops, something went wrong.