-
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.
Merge pull request #21 from anoma/feature/refactoring
feature: add swap and refactor file structure
- Loading branch information
Showing
27 changed files
with
464 additions
and
291 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
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,29 @@ | ||
module Intent.Asset; | ||
|
||
import Stdlib.Prelude open; | ||
import Anoma open; | ||
|
||
type Asset := | ||
mkAsset { | ||
quantity : Nat; | ||
kind : Kind | ||
}; | ||
|
||
type Quantifier := | ||
| Any | ||
| All; | ||
|
||
type QuantifiedAssets := | ||
mkQuantifiedAssets { | ||
quantifier : Quantifier; | ||
assets : List Asset | ||
}; | ||
|
||
--- Checks if an ;Asset; is included in a list of resources. | ||
--- The resource ;Kind; must match, the quantity must be | ||
--- greater or equal, and the `npk` must be the ;PublicKey; of the receiver. | ||
includesAsset (asset : Asset) (receiver : PublicKey) (resources : List Resource) : Bool := | ||
any (r in resources) | ||
Asset.quantity asset <= Resource.quantity r | ||
&& Asset.kind asset == anomaKind r | ||
&& receiver == Resource.npk r; |
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
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
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,24 +1,3 @@ | ||
module Token.Projection; | ||
|
||
import Stdlib.Prelude open; | ||
import Data.Set as Set open using {Set}; | ||
import Data.Map as Map open using {Map}; | ||
|
||
import Anoma open; | ||
|
||
--- Returns the total quantity of all resources ;Kind; by looking up | ||
--- a ;Set; of ;Commitment;s associated with an account's ;PublicKey; | ||
--- from the key-value storage. | ||
--- This assume that the set is is up-to-date an no ;Commitment;s of | ||
--- consumed ;Resource;s are present. | ||
getBalance (kind : Kind) (account : PublicKey) : Nat := | ||
let | ||
ledger : Map PublicKey (Set Commitment) := anomaGet (anomaEncode (kind)); | ||
result := Map.lookup account ledger; | ||
in case result of | ||
| nothing := 0 | ||
| just ledger := | ||
for (sum := 0) (cm in Set.toList ledger) | ||
{let | ||
q := Resource.quantity (commitmentResource cm); | ||
in q + sum}; | ||
import Token.Projection.Balance 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Token.Projection.Balance; | ||
|
||
import Stdlib.Prelude open; | ||
import Data.Set as Set open using {Set}; | ||
import Anoma open; | ||
|
||
--- Returns the total quantity of all resources ;Kind; by looking up | ||
--- a ;Set; of ;Commitment;s associated with an account's ;PublicKey; | ||
--- from the key-value storage. | ||
--- This assume that the set is is up-to-date an no ;Commitment;s of | ||
--- consumed ;Resource;s are present. | ||
balance (kind : Kind) (account : PublicKey) : Nat := | ||
let | ||
ownedResources : Set Commitment := anomaGet (kind, account); | ||
in for (sum := 0) (cm in Set.toList ownedResources) | ||
{let | ||
q := Resource.quantity (commitmentResource cm); | ||
in q + sum}; |
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.