-
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.
- Loading branch information
1 parent
f405b64
commit c751862
Showing
15 changed files
with
266 additions
and
465 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
name: Test anoma-app-patterns | ||
name: Test anoma-apps | ||
|
||
on: | ||
push: | ||
|
@@ -7,21 +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: Clean | ||
run: juvix clean --global && juvix clean && juvix dependencies update | ||
|
||
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 |
---|---|---|
@@ -1,121 +1,150 @@ | ||
module Interface; | ||
|
||
import Stdlib.Prelude open; | ||
import Anoma open; | ||
import Data.Set as Set open using {Set}; | ||
|
||
import Anoma.Identity open; | ||
import Anoma.Transaction open; | ||
import Anoma.Resource open; | ||
|
||
import Resource.Error open; | ||
import Resource.Traits open; | ||
import Transaction as Transaction open; | ||
import Projection.Balance as Projection open; | ||
import Transaction as Transaction; | ||
|
||
import Token.Resource open; | ||
import Token.Label open; | ||
import Token.Logic open; | ||
import Intent.Asset open; | ||
import Intent.Swap.Resource open; | ||
import Intent.Swap.Solution open; | ||
|
||
import AnomaHelpers open; | ||
|
||
import Label open; | ||
|
||
initialize | ||
(self : KeyPair) (quantity : Nat) (receiver : PublicKey) : Result StandardError Transaction := | ||
Transaction.initialize@{ | ||
self; | ||
toInitialize := | ||
(standardInputs : StandardInputs) | ||
(quantity : Quantity) | ||
(receiver : ExternalIdentity) | ||
: Result StandardError Transaction := | ||
let | ||
self := standardInputs |> StandardInputs.identity |> Identity.external; | ||
token := | ||
Token.create@{ | ||
quantity; | ||
tokenLabel := mkKudoLabel (KeyPair.pubKey self); | ||
npk := receiver | ||
tokenLabel := mkKudoLabel self; | ||
owner := receiver | ||
}; | ||
in Transaction.initialize@{ | ||
standardInputs; | ||
toInitialize := token; | ||
maybeDummy := nothing | ||
}; | ||
|
||
finalize (self : KeyPair) (token : Token) : Result StandardError Transaction := | ||
case isKudo (KeyPair.pubKey self) token of | ||
| false := throw notKudoError | ||
| true := | ||
Transaction.finalize@{ | ||
self; | ||
toFinalize := token | ||
}; | ||
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 | ||
(self : KeyPair) | ||
(standardInputs : StandardInputs) | ||
(token : Token) | ||
(quantity : Nat) | ||
(receiver : PublicKey) | ||
(quantity : Quantity) | ||
(receiver : ExternalIdentity) | ||
: Result StandardError Transaction := | ||
case isKudo (KeyPair.pubKey self) token of | ||
| false := throw notKudoError | ||
| true := | ||
Transaction.send@{ | ||
self; | ||
toSend := token; | ||
quantity; | ||
receiver | ||
}; | ||
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 | ||
(self : KeyPair) (token : Token) (receiver : PublicKey) : Result StandardError Transaction := | ||
case isKudo (KeyPair.pubKey self) token of | ||
| false := throw notKudoError | ||
| true := | ||
Transaction.transfer@{ | ||
self; | ||
toTransfer := token; | ||
receiver | ||
}; | ||
(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 | ||
(self : KeyPair) | ||
(standardInputs : StandardInputs) | ||
(token : Token) | ||
(quantitiesAndReceivers : List (Pair Nat PublicKey)) | ||
-- TODO refactor type | ||
(quantitiesAndReceivers : List (Pair Quantity ExternalIdentity)) | ||
: Result StandardError Transaction := | ||
case isKudo (KeyPair.pubKey self) token of | ||
| false := throw notKudoError | ||
| true := | ||
Transaction.split@{ | ||
self; | ||
toSplit := token; | ||
quantitiesAndReceivers | ||
}; | ||
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 | ||
(self : KeyPair) | ||
(standardInputs : StandardInputs) | ||
(tokens : List Token) | ||
(receiver : PublicKey) | ||
(receiver : ExternalIdentity) | ||
: Result StandardError Transaction := | ||
case all (t in tokens) {isKudo (KeyPair.pubKey self) t} of | ||
| false := throw notKudoError | ||
| true := | ||
Transaction.merge@{ | ||
self; | ||
toMerge := tokens; | ||
receiver | ||
}; | ||
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 | ||
(self : KeyPair) | ||
(tokens : List Token) | ||
(standardInputs : StandardInputs) | ||
(toSwap : List Token) | ||
(want : QuantifiedAssets) | ||
(solver : PublicKey) | ||
(solver : ExternalIdentity) | ||
: Result StandardError Transaction := | ||
Transaction.swap@{ | ||
self; | ||
toSwap := tokens; | ||
intent := | ||
SwapIntent.create@{ | ||
want; | ||
receiver := KeyPair.pubKey self; | ||
solver | ||
} | ||
}; | ||
|
||
--- Returns the total quantity of all Kudo ;Kind; resources from an orignator ;PublicKey; for an account ;PublicKey; | ||
balance (originator : PublicKey) (account : PublicKey) : Nat := | ||
let | ||
label : Label := mkKudoLabel originator; | ||
logic : Resource -> Transaction -> Bool := tokenLogic (Label.supply label) originator; | ||
kind : Kind := anomaDecode (anomaEncode (tokenLogic, label)); | ||
ownedKudos : Set Resource := fetchOwnedResources kind account; | ||
in Projection.balance ownedKudos; | ||
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,4 +1,4 @@ | ||
module Kudos; | ||
|
||
import Label open public; | ||
import Interface 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
Oops, something went wrong.