Skip to content

Commit

Permalink
Coins Improvements (#140)
Browse files Browse the repository at this point in the history
* chore: improved README and export parseCoins and Coin type

* fix: README

* chore: increase version
  • Loading branch information
troykessler authored Jun 19, 2024
1 parent 2fef9d4 commit d7c1a80
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
48 changes: 40 additions & 8 deletions common/coins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,53 @@ npm i @kyvejs/coins

Here are some examples on how to use the coins sdk:

Arithmetic methods:

```ts
const coinsA = new Coins({"denom": "acoin", amount: "10"}, {"denom": "bcoin", amount: "20"})
const coinsB = new Coins("30ccoin")
new Coins("1acoin,2bcoin").add({denom: "ccoin", amount: "3"}).mul(2).toString()
-> "2acoin,4bcoin,6ccoin"

new Coins("1acoin,2bcoin,4ccoin").sub("1acoin").div(2).toArray()
-> [{denom: "bcoin", amount: "1"}, {denom: "ccoin", amount: "2"}]
```

Checks and info methods:

coinsA.add(coinsB).quo(10).toString()
-> "1acoin,2bcoin,3ccoin"
```ts
const myCoins = new Coins("1acoin,2bcoin")

coinsA.equal(coinsB)
myCoins.isZero()
-> false

coinsA.max(coinsB).toArray()
-> [{"denom": "acoin", amount: "10"}, {"denom": "bcoin", amount: "20"}, {"denom": "ccoin", amount: "30"}]
myCoins.len()
-> 2

myCoins.equal("1acoin,2bcoin")
-> true

myCoins.amountOf("bcoin")
-> "2"

myCoins.min("1bcoin,1ccoin").toString()
-> "1bcoin"

myCoins.max("1bcoin,1ccoin").toString()
-> "1acoin,2bcoin,1ccoin"
```

Comparison methods:

```ts
const myCoins = new Coins({denom: "bcoin", amount: "1"}, {denom: "ccoin", amount: "2"})

new Coins("1acoin,2bcoin,3ccoin").isAllGT(myCoins)
-> true

new Coins("2bcoin,1ccoin").isAnyLT(myCoins)
-> true
```

## Available methods
## All available methods

The following methods are available on the Coins class:

Expand Down
2 changes: 1 addition & 1 deletion common/coins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kyvejs/coins",
"version": "1.0.0",
"version": "1.0.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions common/coins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,5 @@ export class Coins {
.join(",");
}
}

export { parseCoins, Coin } from "@cosmjs/amino";

0 comments on commit d7c1a80

Please sign in to comment.