Skip to content

Commit

Permalink
Develop -> Main (#264)
Browse files Browse the repository at this point in the history
* feat(feat): develop/main

* fix(fix): fix

* fix(test): fix

* fix(nibijs): examples up-to-date + more docs + test examples in CI (#254)

* fix(fix): markdown (#256)

* fix(nibijs): NibiruQueryClient must expose methods from the Tendermint client (#257)

* refactor: custom chain for mainnet (#262)

* refactor: custom chain for mainnet

* test: increase open handle timeout

* test: adding --watchAll --no-cache

* ci: removing --watchall and --no-cache

* feat(nibijs): functions for humans + getTxByHash (exchange integration) (#260)

* fix(nibijs): NibiruQueryClient must expose methods from the Tendermint client

* feat(nibijs): functions for humans + getTxByHash

* chore(nibijs): build docs

* test(nibijs): fix import

* refactor(nibijs): remove unused fn, 'go', and use Result instead

* docs(nibijs-result): function docs

* test: fix by removing usage of go in test

* test: fix inactive chaint est

* test: fix inactive chaint est

* test: address PR comments

* chore(nibijs): rebuild docs

* Update packages/nibijs/src/result.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix: initChainId couldn't handle number == 0 case

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix: yarn merge

* fix: align chain id (#263)

* fix: align chain id

* fix: merge

* fix: merge

* fix: test

* fix: fix

* fix: fix

* fix: rem readme

* fix: point tests at devnet

* refactor(nibijs)!: NibiruSigningClient -> NibiruTxClient, NibiruQueryClient -> NibiruQuerier (#265)

* refactor(nibijs)!: NibiruSigningClient -> NibiruTxClient, NibiruQueryClient -> NibiruQuerier

* chore: rebuild docs + txClient file name

---------

Co-authored-by: Unique Divine <[email protected]>
Co-authored-by: Karim El Shenawy <[email protected]>
Co-authored-by: elshenak <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored Dec 13, 2023
1 parent ef01afa commit 5a548d1
Show file tree
Hide file tree
Showing 84 changed files with 2,593 additions and 63,461 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/test-ts-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ jobs:
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Install nibid
run: curl -s https://get.nibiru.fi/@v0.21.9! | bash
# Use https://get.nibiru.fi/ to get the most recent release.

- name: Check nibid version
run: nibid version

- name: Run localnet.sh in the background
- name: Run Nibiru network in the background (scripts/localnet.sh)
run: |
sh scripts/localnet.sh &
# Install nibid CLI
# Use https://get.nibiru.fi/ to get the most recent release.
curl -s https://get.nibiru.fi/@v0.21.9! | bash
# Sanity check nibid CLI
nibid version
# Start local network
bash scripts/localnet.sh &
- name: Setup NodeJS with yarn caching
uses: actions/setup-node@v3
Expand All @@ -56,6 +55,12 @@ jobs:
- name: Run tests
run: yarn test

- name: "Run examples (packages/examples)"
run: |
yarn run tsx packages/examples/examples.test.ts
# tsx is a TS script executor similar to ts-node, except it runs more
# consistently and has a more lightweight implementation.
- name: Jest Coverage Comment
uses: MishaKav/jest-coverage-comment@main

Expand All @@ -65,7 +70,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- name: SonarQube Quality Gate
- name: "SonarQube Quality Gate"
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
Expand Down
125 changes: 78 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
<p align="center">
<img src="https://raw.githubusercontent.com/NibiruChain/ts-sdk/main/img/nibijs.png" width="100%">
<img src="https://raw.githubusercontent.com/NibiruChain/ts-sdk/develop/img/nibijs.png" width="100%">
</p>

<!-- NOTE: Use direct links for external sites that copy these files. -->

<p align="center">
The official TypeScript SDK for the Nibiru blockchain
</p>

<div style="display: flex; flex-direction: row; gap: 4px;">

<!-- Badge | NPM version -->
<a target="_blank" href="https://www.npmjs.com/package/@nibiruchain/nibijs">
<img src="https://img.shields.io/npm/v/@nibiruchain/nibijs.svg?color=AE8CCD" style="height: 20px">
</a>

[![⛓️ Tests @nibiruchain/nibijs](https://github.com/NibiruChain/ts-sdk/actions/workflows/test-nibijs.yaml/badge.svg?branch=main)](https://github.com/NibiruChain/ts-sdk/actions/workflows/test-nibijs.yaml)
[![⛓️ Tests @nibiruchain/indexer-nibi](https://github.com/NibiruChain/ts-sdk/actions/workflows/test-indexer-nibi.yaml/badge.svg?branch=main)](https://github.com/NibiruChain/ts-sdk/actions/workflows/test-indexer-nibi.yaml)
<!-- Badge | Test workflows -->
<a target="_blank" href="https://github.com/NibiruChain/ts-sdk/actions/workflows/test-ts-sdk.yaml" alt="⛓️ Tests @nibiruchain/nibijs">
<img src="https://github.com/NibiruChain/ts-sdk/actions/workflows/test-ts-sdk.yaml/badge.svg?branch=main" style="height: 20px">
</a>

<!-- Badge | NPM downloads -->
<a target="_blank" href="https://www.npmjs.com/package/@nibiruchain/nibijs">
<img src="https://img.shields.io/npm/dm/@nibiruchain/nibijs.svg?color=FFF3CD" style="height: 20px">
</a>

<!-- Badge | NPM license -->
<a target="_blank" href="https://github.com/NibiruChain/ts-sdk/blob/main/LICENSE">
<img src="https://img.shields.io/npm/l/express.svg?color=050505" style="height: 20px">
</a>

<!-- Badge | Discord members -->
<a target="_blank" href="https://discord.gg/nibirufi">
<img src="https://dcbadge.vercel.app/api/server/nibirufi?style=flat" style="height: 20px">
</a>
Expand All @@ -40,9 +49,9 @@ The `nibijs` source code can be found in the ["packages" directory](https://gith
- [Example: Transaction with arbitrary messages](#example-transaction-with-arbitrary-messages)
- [Codebase structure](#codebase-structure)
- [Development Quick Start](#development-quick-start)
- [🔓 License](#-license)
- [🔓 License](#%F0%9F%94%93-license)

To learn more about Nibiru, see [docs.nibiru.fi](https://docs.nibiru.fi)
To learn more about Nibiru, see [nibiru.fi/docs](https://nibiru.fi/docs)

---

Expand All @@ -60,11 +69,12 @@ npm install @nibiruchain/nibijs # or yarn add

The entrypoint for `nibijs` is the `Sdk` object, which is meant to mimic the root of a command line interface. It can be used for both queries and transactions.

#### Example: Creating a wallet
### Example: Creating a wallet

```js
import { newRandomWallet, WalletHD } from "@nibiruchain/nibijs"
import { newRandomWallet } from "@nibiruchain/nibijs"

// Create a new Nibiru wallet
const wallet = await newRandomWallet()
const [{ address }] = await wallet.getAccounts()

Expand All @@ -73,88 +83,106 @@ console.log("mnemonic: ", wallet.mnemonic)
console.log("address: ", address)
```

#### Example: Querying
### Example: Querying

```js
import {
IncentivizedTestnet,
NibiruQueryClient,
NibiruSigningClient,
} from "@nibiruchain/nibijs"
import { NibiruQuerier, NibiruTxClient, Localnet } from "@nibiruchain/nibijs"

const TEST_CHAIN = IncentivizedTestnet(2)
const queryClient = await NibiruQueryClient.connect(TEST_CHAIN.endptTm)
export const CHAIN: Chain = Localnet
const querier = await NibiruQuerier.connect(CHAIN.endptTm)

const perpParamsResp = await queryClient.nibiruExtensions.perp.params()
const perpParamsResp = await querier.nibiruExtensions.perp.params()
console.log("perpParams: %o", perpParamsResp)

const allMarkets = await queryClient.nibiruExtensions.perp.markets({
const allMarkets = await querier.nibiruExtensions.perp.markets({
pair: "ueth:unusd",
})
console.log("allMarkets: %o", allMarkets)

const blockHeight = 1
const block = await queryClient.getBlock(blockHeight)
const block = await querier.getBlock(blockHeight)
```

#### Example: Sending funds
### Example: Sending funds

```js
import {
Coin,
NibiruSigningClient,
newCoins,
NibiruTxClient,
newSignerFromMnemonic,
Localnet
} from "@nibiruchain/nibijs"
import { coins } from "@cosmjs/proto-signing"

export const CHAIN: Chain = Localnet
const signer = await newSignerFromMnemonic(mnemonic!)
const signingClient = await NibiruSigningClient.connectWithSigner(
TEST_CHAIN.endptTm,
const txClient = await NibiruTxClient.connectWithSigner(
CHAIN.endptTm,
signer,
)
const [{ address: fromAddr }] = await signer.getAccounts()

const tokens: Coin[] = newCoins(5, "unibi")
const tokens: Coin[] = coins(5, "unibi")
const toAddr: string = "..." // bech32 address of the receiving party
const txResp = await signingClient.sendTokens(fromAddr, toAddr, tokens, "auto")
const txResp = await txClient.sendTokens(fromAddr, toAddr, tokens, "auto")
```

#### Example: Transaction with arbitrary messages
### Example: Transaction with arbitrary messages

```js
import { IncentivizedTestnet, NibiruSigningClient, newCoin } from "@nibiruchain/nibijs"
import {
NibiruTxClient,
newSignerFromMnemonic,
Msg,
TxMessage,
StdFee,
toSdkInt,
parseEventLogs,
Localnet
} from "@nibiruchain/nibijs"
import { Msg, TxMessage } from "@nibiruchain/nibijs/dist/msg"
import { coin } from "@cosmjs/proto-signing"

// const mnemonic = "..." <--
export const CHAIN: Chain = Localnet
const signer = await newSignerFromMnemonic(mnemonic!)
signer.getAccounts()
const signingClient = await NibiruSigningClient.connectWithSigner(
TEST_CHAIN.endptTm,
const txClient = await NibiruTxClient.connectWithSigner(
CHAIN.endptTm,
signer,
)
const [{ address: fromAddr }] = await signer.getAccounts()
const pair = "ubtc:unusd"

// ------------------------------------
// Construct tx msgs
// ------------------------------------
const msgs: TxMessage[] = [
Msg.perp.openPosition({
tokenPair: pair,
baseAssetAmountLimit: 0,
leverage: 1,
quoteAssetAmount: 10,
sender: fromAddr,
pair: pair,
quoteAssetAmount: 10,
leverage: 1,
goLong: true,
baseAssetAmountLimit: 0,
}),
Msg.perp.addMargin({
sender: fromAddr,
tokenPair: pair,
margin: newCoin("20", "unusd"),
pair: pair,
margin: coin("20", "unusd"),
}),
Msg.perp.removeMargin({
tokenPair: pair,
sender: fromAddr,
margin: newCoin("5", "unusd"),
pair: pair,
margin: coin("5", "unusd"),
}),
// final margin value of 10 (open) + 20 (add) - 5 (remove) = 25
]
const txResp = await signingClient.signAndBroadcast(fromAddr, msgs, "auto")

// ------------------------------------
// Broadcast tx
// ------------------------------------
const txResp = await txClient.signAndBroadcast(fromAddr, msgs, "auto")
```

## Codebase structure
Expand All @@ -171,27 +199,30 @@ const txResp = await signingClient.signAndBroadcast(fromAddr, msgs, "auto")

---

<!--
## 📜 Contribution Guidelines
TODO
-->
<!-- TODO: ## 📜 Contribution Guidelines -->

## Development Quick Start

1. First install yarn.
1. Install and use `nvm`.

```bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.6/install.sh | bash
nvm use
```

2. Install yarn.

```sh
npm install -g yarn
```

2. Then, install package dependencies. At the root of the repository, run
3. Then, install package dependencies. At the root of the repository, run

```sh
yarn
```

3. Lastly, compile the code in each package.
4. Lastly, compile the code in each package.

```sh
yarn build
Expand Down
26 changes: 0 additions & 26 deletions examples/01_new-wallet-and-faucet.ts

This file was deleted.

31 changes: 0 additions & 31 deletions examples/02_queries.ts

This file was deleted.

48 changes: 0 additions & 48 deletions examples/03_messages.ts

This file was deleted.

Loading

1 comment on commit 5a548d1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 95%
95.45% (1365/1430) 97.95% (576/588) 88.18% (321/364)

Please sign in to comment.