Skip to content

Commit

Permalink
Merge pull request #254 from InjectiveLabs/dev
Browse files Browse the repository at this point in the history
#PRMaster
  • Loading branch information
bangjelkoski authored Oct 27, 2023
2 parents 862e7c3 + f6793b6 commit 0acb98b
Show file tree
Hide file tree
Showing 154 changed files with 4,607 additions and 2,063 deletions.
1 change: 1 addition & 0 deletions .gitbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ _Note: Reading the Technical Concepts section after reading the overview below i
* [Core Modules](core-modules/) - In this section we are going to have a quick summary of the core modules on Injective and show examples of how to create some Messages (+ pack them into a transaction, sign them using a private key, and broadcast them on Injective) within these core modules.
* [Bridge](bridge/) - In this section, we are going to have a look at Injective's interoperability and explain how developers can utilize the Peggy bridge and the IBC bridge to bridge assets over to Injective.
* [Networks](readme/networks.md) - In this section, we will look at different (pre-defined) available Networks for developers to utilize while building dApps on top of Injective, allowing them to start building without the need to make their own infrastructure.
* [Calculations](calculations/) - In this section, we will look at different calculations formula converting values between UI human-readable and chain format.
9 changes: 6 additions & 3 deletions .gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* [Getting Started](README.md)
* [Technical Concepts](readme/technical-concepts.md)
* [Application Concepts](readme/application-concepts.md)
* [Token Metadata](readme/token-metadata/README.md)
* [Assets (Token Metadata)](readme/token-metadata/README.md)
* [Creating Tokens](readme/token-metadata/creating-tokens.md)
* [Denom Client](readme/token-metadata/denom-client.md)
* [Networks](readme/networks.md)
* [CosmJs Support](readme/getting-started-cosmjs.md)
* [Wallet](wallet/README.md)
* [Accounts](wallet/wallet-accounts.md)
* [Wallet Strategy](wallet/wallet-wallet-strategy.md)
* [Wallet Connections](wallet/wallet-connections.md)
* [Wallet Strategy](wallet/wallet-wallet-strategy.md)
* [Querying](querying/README.md)
* [Indexer](querying/querying-api/README.md)
* [Account](querying/querying-api/querying-indexer-account.md)
Expand Down Expand Up @@ -61,6 +61,7 @@
* [Core Modules](core-modules/README.md)
* [Auction](core-modules/auction.md)
* [AuthZ](core-modules/authz.md)
* [Feegrant](core-modules/feegrant.md)
* [Bank](core-modules/bank.md)
* [Distribution](core-modules/distribution.md)
* [Exchange](core-modules/exchange.md)
Expand All @@ -75,11 +76,13 @@
* [Ethereum](bridge/ethereum.md)
* [IBC](bridge/ibc.md)
* [Wormhole](bridge/wormhole.md)
* [Contracts](contracts.md)
* [Contracts](contracts/README.md)
* [Injective Name Service](contracts/injective-name-service.md)
* [Building dApps](building-dapps/README.md)
* [Configuring Nuxt](building-dapps/configuring-nuxt.md)
* [Configuring React](building-dapps/configuring-react.md)
* [dApps Examples](building-dapps/dapps-examples/README.md)
* [Smart Contract](building-dapps/smart-contract.md)
* [DEX](building-dapps/dex.md)
* [Bridge](building-dapps/bridge.md)
* [Calculations](calculations/README.md)
10 changes: 9 additions & 1 deletion .gitbook/building-dapps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ Injective is natively interoperable with several well-known blockchain networks,

Within this section we are going to explore configuring different UI frameworks to work with the `@injectivelabs` packages so you can start building decentralized applications on top of Injective. We are also going to showcase example (simple) dApps built on top of Injective.

***

### Create Injective dApp CLI tool

The simplest way to start your journey on Injective is using our CLI tool. To do this, simply write this command and follow the instructions in your terminal! 

```bash
$ npx @injectivelabs/create-injective-app
```

### Configuration

Expand All @@ -15,7 +23,7 @@ Within this section we are going to explore configuring different UI frameworks
| [Configuring Nuxt](configuring-nuxt.md) | Configuring Nuxt 3.x + Vite |
| [Configuring React](configuring-react.md) | Configuring React 18 + Vite |


***

### Dapps

Expand Down
10 changes: 10 additions & 0 deletions .gitbook/calculations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Calculations

Here are some formula formatting values between the chain and UI human-readable.

### Bridges Supported

| Topic | Description |
| ------------------------------------------------------- | --------------------------------------- |
| [Market min price tick size](minPriceTickSize.md) | Minimum market order price tick size |
| [Market min quantity tick size](minQuantityTickSzie.md) | Minimum market order quantity tick size |
47 changes: 47 additions & 0 deletions .gitbook/calculations/minPriceTickSize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Market min price tick size

The min market price tick size for an order price - if a market has an minPriceTickSick of `0.001` and order submission with the price of `0.0011` will be rejected.

Note that calculating the formula for calculating a spot and quote market price tick size are different.

### Spot market

1. UI human readable to chain format:
Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the chain format:

```js
const chainFormat = new BigNumberInBase(10)
.pow(quoteDecimal - baseDecimal)
.times(value)
.toFixed()
```

1. Chain format to UI human readable format:
Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the UI human readable format:

```js
const humanReadableFormat = new BigNumber(value)
.shiftedBy(baseDecimals - quoteDecimals)
.toFixed()
```

### Derivative market

1. UI human readable to chain format:
Using INJ/USDT perp market which has 6 quote decimals as an example, here's how we convert the value to the chain format:

```js
const chainFormat = new BigNumberInBase(10)
.pow(-quoteDecimal)
.times(value)
.toFixed()
```

1. Chain format to UI human readable format:
Using INJ/USDT perp market which has 6 quote decimals as an example, here's how we convert the value to the UI human readable format:

```js
const humanReadableFormat = new BigNumber(value)
.shiftedBy(-quoteDecimals)
.toFixed()
```
23 changes: 23 additions & 0 deletions .gitbook/calculations/minQuantityTickSize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Market min quantity tick size

The min market quantity tick size for an order price - if a market has an minQuantityTickSize of `0.001` and order submission with the quantity of `0.0011` will be rejected.

Note that derivate markets shares the same format for minQuantityTickSize between UI and the chain, so no formatting is required.

### Spot market

1. UI human readable to chain format:
Using on a INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the chain format:

```js
const chainFormat = new BigNumberInWei(value).toBase(baseDecimals)
```

1. Chain format to UI human readable format:
Using INJ/USDT market which has 18 base decimals and 6 quote decimals as an example, here's how we convert the value to the UI human readable format:

```js
const humanReadableFormat = new BigNumber(minQuantityTickSize)
.shiftedBy(-baseDecimals)
.toFixed()
```
6 changes: 0 additions & 6 deletions .gitbook/contracts.md

This file was deleted.

4 changes: 2 additions & 2 deletions .gitbook/contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contracts

### What is CosmWasm?[](https://docs.injective.network/develop/guides/cosmwasm-dapps/#what-is-cosmwasm) <a href="#what-is-cosmwasm" id="what-is-cosmwasm"></a>
#### [What is CosmWasm?](./#what-is-cosmwasm-)[](https://docs.injective.network/develop/guides/cosmwasm-dapps/#what-is-cosmwasm) <a href="#user-content-what-is-cosmwasm" id="user-content-what-is-cosmwasm"></a>

CosmWasm is a novel smart contracting platform built for the Cosmos ecosystem. You can learn more about CosmWasm [here](https://docs.cosmwasm.com/docs/), or see the [CosmWasm Book](https://book.cosmwasm.com/index.html) for a guide on creating CosmWasm smart contracts.

### Specific Cosmwasm Contracts
#### Specific Cosmwasm Contracts

| Topic | Description |
| --------------------------------------------------- | ---------------------- |
Expand Down
27 changes: 22 additions & 5 deletions .gitbook/contracts/injective-name-service.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
# Injective Name Service

Within this section we are going to have a look how to query the Injective name service contracts.
Within this section, we will look at how to query the Injective name service contracts.

## Querying
## Abstraction Service

You can use our `InjNameService` [abstraction](../../packages/sdk-ui-ts/src/services/nameservice/InjNameService.ts) to query the smart contracts with a single method call. Below this example, you can also find the raw implementation on how to query the smart contracts in case you need more flexibility.&#x20;

<pre class="language-typescript"><code class="lang-typescript">import { getNetworkEndpoints, Network } from '@injectivelabs/network'
import { InjNameService } from '@injectivelabs/sdk-ui-ts'

const injNameService = new InjNameService(Network.Testnet)
<strong>const name = 'ninja.inj'
</strong>
// Fetch the address for the particular name
const addressForName = await injNameService.fetchInjAddress(name)

// Fetch the name for the particular address
const nameFromAddress = await injNameService.fetchInjName(addressForName)
</code></pre>

## Raw Smart Contract Querying

Example code snippets to resolve .inj domain name.

### Domain Resolution

- Get resolver address
* Get resolver address

```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
Expand Down Expand Up @@ -41,7 +58,7 @@ const resolverAddress = InjNameServiceQueryTransformer.resolverAddressResponseTo
console.log(resolverAddress)
```

- Get address for .inj domain name.
* Get address for .inj domain name.

```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
Expand Down Expand Up @@ -83,7 +100,7 @@ console.log(injectiveAddress)

### Reverse Resolution

- Get primary name for injective address.
* Get primary name for injective address.

```ts
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
Expand Down
1 change: 1 addition & 0 deletions .gitbook/core-modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Within this section, we are going to explore the core modules of the Injective c
| ------------------------------- | ------------------------------------------------ |
| [Auction](auction.md) | Use for the buy-back-and-burn on chain mechanism |
| [AuthZ](authz.md) | Used for granting account priveledges |
| [Feegrant](feegrant.md) | Used for granting fee allowance priveledges |
| [Bank](bank.md) | Used for managing users assets (funds) |
| [Exchange](exchange.md) | Used for the exchange primitives |
| [Distribution](distribution.md) | Used for on-chain distribution/minting |
Expand Down
79 changes: 71 additions & 8 deletions .gitbook/core-modules/auction.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const auctionApi = new ChainGrpcAuctionApi(endpointsForNetwork.grpc);
const injectiveAddress = "inj1...";
/* format amount for bid, note that bid amount has to be higher than the current highest bid */
const amount = {
denom: INJ,
denom: INJ_DENOM,
amount: new BigNumberInBase(1).toWei(),
};

Expand All @@ -38,20 +38,83 @@ const latestRound = uiLatestAuctionModuleState.auctionRound;
const msg = MsgBid.fromJSON({
amount,
injectiveAddress,
round: latestRound,
round: latestRound
});

const privateKey = "0x...";

/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
privateKey,
chainId: ChainId.Mainnet,
endpoints: endpointsForNetwork,
network: Network.Mainnet,
privateKey,
}).broadcast({
msgs: msg,
injectiveAddress,
});
msgs: msg
})


console.log(txHash);
```

### Burn Auction Deposit via MsgExternalTransfer

If you would like to grow the burn auction's pool size, you can directly send funds to the Auction subaccount.

Notes:
- You will need to send funds to the pool's subaccount `0x1111111111111111111111111111111111111111111111111111111111111111`.
- Be aware that any funds you send will be reflected in the next auction, not the current one.
- You cannot transfer from your default subaccountId since that balance is now associated with your Injective address in the bank module. Therefore, in order for `MsgExternalTransfer` to work, you will need to transfer from a non-default subaccountId.

How to find the subaccountId that you will be transferring from:
- you can query your existing subaccountIds via the [account portfolio api](../querying/querying-api/querying-indexer-portfolio.md).

How to use funds that are currently associated with your Injective Address in bank module:
- If you have existing non-default subaccounts, you'll want to do a [MsgDeposit](./exchange.md#MsgDeposit) to one of your existing non-default subaccountIds and use that subaccountId as the `srcSubaccountId` below.
- If you don't have existing non-default subaccounts, you can do a [MsgDeposit](./exchange.md#MsgDeposit) to a new default subaccountId, which would be done via importing `getSubaccountId` from `sdk-ts` and setting the `subaccountId` field in [MsgDeposit](./exchange.md#MsgDeposit) to `getSubaccountId(injectiveAddress, 1)`.

For more info, check out the [burn auction pool docs](https://docs.injective.network/develop/tech-concepts/auction_pool/).

```ts
import {
DenomClient,
MsgExternalTransfer,
MsgBroadcasterWithPk,
} from '@injectivelabs/sdk-ts'
import { BigNumberInBase } from '@injectivelabs/utils'
import { Network } from '@injectivelabs/networks'

const denomClient = new DenomClient(Network.Mainnet);

const injectiveAddress = 'inj1...'
const srcSubaccountId = '0x...'
const POOL_SUBACCOUNT_ID = `0x1111111111111111111111111111111111111111111111111111111111111111`
const USDT_TOKEN_SYMBOL='USDT'
const tokenMeta = denomClient.getTokenMetaDataBySymbol(USDT_TOKEN_SYMBOL);
const tokenDenom = `peggy${tokenMeta.erc20.address}`;

/* format amount to add to the burn auction pool */
const amount = {
denom: tokenDenom,
amount: new BigNumberInBase(1).toWei(tokenMeta.decimals).toFixed()
}

/* create message in proto format */
const msg = MsgExternalTransfer.fromJSON({
amount,
srcSubaccountId,
injectiveAddress,
dstSubaccountId: POOL_SUBACCOUNT_ID
})

const privateKey = '0x...'

/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
network: Network.Mainnet,
privateKey
}).broadcast({
msgs: msg
})


console.log(txHash)
```
Loading

0 comments on commit 0acb98b

Please sign in to comment.