diff --git a/package.json b/package.json index 3a58499d..5dc8e5d7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "lint": "eslint -c './.eslintrc.js' './packages/**/*.{ts,js}'", "lint:ci": "yarn lint . --format junit", "lint:md": "markdownlint --ignore node_modules --ignore .git", - "localnet": "sh scripts/localnet.sh", + "localnet": "bash scripts/localnet.sh", "format": "yarn lint --fix", "format:md": "yarn lint:md --fix", "proto-gen": "yarn exec ./scripts/protocgen.sh", diff --git a/packages/nibijs/docs/classes/CustomChain.md b/packages/nibijs/docs/classes/CustomChain.md index e76edb5b..8ca60757 100644 --- a/packages/nibijs/docs/classes/CustomChain.md +++ b/packages/nibijs/docs/classes/CustomChain.md @@ -54,7 +54,7 @@ export const TEST_CHAIN = new CustomChain({ #### Defined in -[chain/chain.ts:56](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L56) +[chain/chain.ts:57](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L57) ## Properties @@ -70,7 +70,7 @@ chainId: identifier for the chain #### Defined in -[chain/chain.ts:47](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L47) +[chain/chain.ts:48](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L48) --- @@ -80,7 +80,7 @@ chainId: identifier for the chain #### Defined in -[chain/chain.ts:54](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L54) +[chain/chain.ts:55](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L55) --- @@ -96,7 +96,7 @@ chainName: the name of the chain to display to the user #### Defined in -[chain/chain.ts:48](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L48) +[chain/chain.ts:49](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L49) --- @@ -112,7 +112,7 @@ endptGrpc: endpoint for the gRPC gateway. Usually on port 9090. #### Defined in -[chain/chain.ts:51](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L51) +[chain/chain.ts:52](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L52) --- @@ -128,7 +128,7 @@ endptRest: endpoint for the REST server. Also, the LCD endpoint. #### Defined in -[chain/chain.ts:50](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L50) +[chain/chain.ts:51](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L51) --- @@ -144,7 +144,7 @@ endptTm: endpoint for the Tendermint RPC server. Usually on port 26657. #### Defined in -[chain/chain.ts:49](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L49) +[chain/chain.ts:50](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L50) --- @@ -160,7 +160,7 @@ feeDenom: the denomination of the fee to be paid for transactions. #### Defined in -[chain/chain.ts:52](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L52) +[chain/chain.ts:53](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L53) ## Methods @@ -174,7 +174,7 @@ feeDenom: the denomination of the fee to be paid for transactions. #### Defined in -[chain/chain.ts:75](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L75) +[chain/chain.ts:81](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L81) --- @@ -194,4 +194,4 @@ feeDenom: the denomination of the fee to be paid for transactions. #### Defined in -[chain/chain.ts:65](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L65) +[chain/chain.ts:71](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L71) diff --git a/packages/nibijs/docs/classes/MsgFactory.md b/packages/nibijs/docs/classes/MsgFactory.md index c607ac6b..0baba825 100644 --- a/packages/nibijs/docs/classes/MsgFactory.md +++ b/packages/nibijs/docs/classes/MsgFactory.md @@ -27,7 +27,7 @@ #### Defined in -[msg/index.ts:6](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/index.ts#L6) +[msg/index.ts:6](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/index.ts#L6) --- @@ -37,4 +37,4 @@ #### Defined in -[msg/index.ts:5](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/index.ts#L5) +[msg/index.ts:5](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/index.ts#L5) diff --git a/packages/nibijs/docs/classes/NibiruQueryClient.md b/packages/nibijs/docs/classes/NibiruQueryClient.md index 51de737b..4133b441 100644 --- a/packages/nibijs/docs/classes/NibiruQueryClient.md +++ b/packages/nibijs/docs/classes/NibiruQueryClient.md @@ -32,6 +32,8 @@ const querier = await NibiruQueryClient.connect(chain.endptTm) ### Methods +- [getTxByHash](NibiruQueryClient.md#gettxbyhash) +- [getTxByHashBytes](NibiruQueryClient.md#gettxbyhashbytes) - [waitForHeight](NibiruQueryClient.md#waitforheight) - [waitForNextBlock](NibiruQueryClient.md#waitfornextblock) - [connect](NibiruQueryClient.md#connect) @@ -56,7 +58,7 @@ StargateClient.constructor #### Defined in -[query/query.ts:63](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L63) +[query/query.ts:66](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L66) ## Properties @@ -66,7 +68,7 @@ StargateClient.constructor #### Defined in -[query/query.ts:50](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L50) +[query/query.ts:53](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L53) --- @@ -76,7 +78,7 @@ StargateClient.constructor #### Defined in -[query/query.ts:52](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L52) +[query/query.ts:55](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L55) --- @@ -86,10 +88,75 @@ StargateClient.constructor #### Defined in -[query/query.ts:51](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L51) +[query/query.ts:54](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L54) ## Methods +### getTxByHash + +▸ **getTxByHash**(`txHashHex`): `Promise`<[`Result`](Result.md)<`TxResponse`\>\> + +getTxByHash: Query a transaction (tx) using its hexadecial encoded tx hash. +A tx hash uniquely identifies a tx on the blockchain. + +The hex-encoded tx hash is: + +- An unambiguous representation of the SHA-256 cryptographic hash in the + consensus layer. +- Well-suited for human-facing applications, as it is easier to work with + than bytes. + +#### Parameters + +| Name | Type | +| :---------- | :------- | +| `txHashHex` | `string` | + +#### Returns + +`Promise`<[`Result`](Result.md)<`TxResponse`\>\> + +**`Example`** + +```ts +const txHash = + "7A919F2CC9A51B139444F7D8E84A46EEF307E839C6CA914C1A1C594FEF5C1562" +const txRespResult = await getTxByHash(txHash) +``` + +#### Defined in + +[query/query.ts:122](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L122) + +--- + +### getTxByHashBytes + +▸ **getTxByHashBytes**(`txHash`): `Promise`<[`Result`](Result.md)<`TxResponse`\>\> + +getTxByHashBytes: Query a transaction (tx) using its SHA-256 tx hash (bytes). +A tx hash uniquely identifies a tx on the blockchain. + +#### Parameters + +| Name | Type | +| :------- | :----------- | +| `txHash` | `Uint8Array` | + +#### Returns + +`Promise`<[`Result`](Result.md)<`TxResponse`\>\> + +**`See`** + +getTxByHash - Equivalent query using the hex-encoded tx hash string. + +#### Defined in + +[query/query.ts:136](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L136) + +--- + ### waitForHeight ▸ **waitForHeight**(`height`): `Promise`<`void`\> @@ -106,7 +173,7 @@ StargateClient.constructor #### Defined in -[query/query.ts:89](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L89) +[query/query.ts:92](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L92) --- @@ -120,7 +187,7 @@ StargateClient.constructor #### Defined in -[query/query.ts:97](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L97) +[query/query.ts:100](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L100) --- @@ -145,4 +212,4 @@ StargateClient.connect #### Defined in -[query/query.ts:54](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L54) +[query/query.ts:57](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L57) diff --git a/packages/nibijs/docs/classes/NibiruSigningClient.md b/packages/nibijs/docs/classes/NibiruSigningClient.md index 327a4192..ea9e3a26 100644 --- a/packages/nibijs/docs/classes/NibiruSigningClient.md +++ b/packages/nibijs/docs/classes/NibiruSigningClient.md @@ -46,7 +46,7 @@ SigningStargateClient.constructor #### Defined in -[tx/signingClient.ts:41](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L41) +[tx/signingClient.ts:41](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L41) ## Properties @@ -56,7 +56,7 @@ SigningStargateClient.constructor #### Defined in -[tx/signingClient.ts:38](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L38) +[tx/signingClient.ts:38](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L38) --- @@ -66,7 +66,7 @@ SigningStargateClient.constructor #### Defined in -[tx/signingClient.ts:39](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L39) +[tx/signingClient.ts:39](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L39) ## Methods @@ -86,7 +86,7 @@ SigningStargateClient.constructor #### Defined in -[tx/signingClient.ts:94](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L94) +[tx/signingClient.ts:94](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L94) --- @@ -100,7 +100,7 @@ SigningStargateClient.constructor #### Defined in -[tx/signingClient.ts:102](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L102) +[tx/signingClient.ts:102](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L102) --- @@ -127,4 +127,4 @@ SigningStargateClient.connectWithSigner #### Defined in -[tx/signingClient.ts:66](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L66) +[tx/signingClient.ts:66](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L66) diff --git a/packages/nibijs/docs/classes/PerpMsgFactory.md b/packages/nibijs/docs/classes/PerpMsgFactory.md index a9180fa4..525f5684 100644 --- a/packages/nibijs/docs/classes/PerpMsgFactory.md +++ b/packages/nibijs/docs/classes/PerpMsgFactory.md @@ -55,7 +55,7 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:124](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L124) +[msg/perp.ts:124](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L124) --- @@ -75,7 +75,7 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:161](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L161) +[msg/perp.ts:161](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L161) --- @@ -95,7 +95,7 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:175](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L175) +[msg/perp.ts:175](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L175) --- @@ -115,7 +115,7 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:131](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L131) +[msg/perp.ts:131](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L131) --- @@ -141,7 +141,7 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:138](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L138) +[msg/perp.ts:138](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L138) --- @@ -161,7 +161,7 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:168](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L168) +[msg/perp.ts:168](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L168) --- @@ -181,4 +181,4 @@ Returns a 'TxMessage' for adding margin to a position #### Defined in -[msg/perp.ts:110](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L110) +[msg/perp.ts:110](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L110) diff --git a/packages/nibijs/docs/classes/Result.md b/packages/nibijs/docs/classes/Result.md new file mode 100644 index 00000000..0c1c5553 --- /dev/null +++ b/packages/nibijs/docs/classes/Result.md @@ -0,0 +1,195 @@ +[NibiJS Documentation - v0.21.42](../intro.md) / [Exports](../modules.md) / Result + +# Class: Result + +Poor-man's Result type from Rust. + +The Result type forces you to explicitly handle errors in contrast to allowing +errors to propagate up the call stack implicitly. Handling potential errors +explicitly leads to more robust and reliable code. + +Ref: Propagating Errors - Rust Book. + +**`Example`** + +```ts +// --------------------------------------- +// Most common use-case: Result.ofSafeExec +// --------------------------------------- +res = Result.ofSafeExec(somethingDangerous) // without args + +// with args +res = Result.ofSafeExec(() => somethingDangerous(arg0, arg1)) +``` + +**`Example`** + +```ts +// --------------------------------------- +// Direct constructor +// --------------------------------------- +let res = new Result({ ok: "Operation successful!" }) +if (res.isOk()) { + happyPath(res.ok) +} else { + handleGracefully(res.err!) // throws impossible based on constructor args +} +``` + +## Type parameters + +| Name | +| :--- | +| `T` | + +## Table of contents + +### Constructors + +- [constructor](Result.md#constructor) + +### Properties + +- [err](Result.md#err) +- [ok](Result.md#ok) + +### Methods + +- [isErr](Result.md#iserr) +- [isOk](Result.md#isok) +- [ofSafeExec](Result.md#ofsafeexec) +- [ofSafeExecAsync](Result.md#ofsafeexecasync) + +## Constructors + +### constructor + +• **new Result**<`T`\>(`«destructured»`) + +#### Type parameters + +| Name | +| :--- | +| `T` | + +#### Parameters + +| Name | Type | +| :--------------- | :-------- | +| `«destructured»` | `Object` | +| › `err?` | `unknown` | +| › `ok?` | `T` | + +#### Defined in + +[result.ts:33](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L33) + +## Properties + +### err + +• **err**: `undefined` \| `Error` + +#### Defined in + +[result.ts:32](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L32) + +--- + +### ok + +• **ok**: `undefined` \| `T` + +#### Defined in + +[result.ts:31](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L31) + +## Methods + +### isErr + +▸ **isErr**(): `boolean` + +#### Returns + +`boolean` + +#### Defined in + +[result.ts:44](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L44) + +--- + +### isOk + +▸ **isOk**(): `boolean` + +#### Returns + +`boolean` + +#### Defined in + +[result.ts:45](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L45) + +--- + +### ofSafeExec + +▸ `Static` **ofSafeExec**<`Y`\>(`fn`): [`Result`](Result.md)<`Y`\> + +Constructor for "Result" using the return value of the input function. + +#### Type parameters + +| Name | +| :--- | +| `Y` | + +#### Parameters + +| Name | Type | +| :--- | :-------------------------- | +| `fn` | (...`args`: `any`[]) => `Y` | + +#### Returns + +[`Result`](Result.md)<`Y`\> + +#### Defined in + +[result.ts:48](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L48) + +--- + +### ofSafeExecAsync + +▸ `Static` **ofSafeExecAsync**<`Y`\>(`fn`): `Promise`<[`Result`](Result.md)<`Y`\>\> + +Constructor for "Result" using the return value of the input async function. + +#### Type parameters + +| Name | +| :--- | +| `Y` | + +#### Parameters + +| Name | Type | +| :--- | :-------------------- | +| `fn` | () => `Promise`<`Y`\> | + +#### Returns + +`Promise`<[`Result`](Result.md)<`Y`\>\> + +**`Example`** + +```ts +const result = Result.ofSafeExecAsync(async () => someAsyncFunc(args)) +``` + +#### Defined in + +[result.ts:60](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L60) diff --git a/packages/nibijs/docs/classes/SpotMsgFactory.md b/packages/nibijs/docs/classes/SpotMsgFactory.md index 8ed3d6ab..18e4d7b4 100644 --- a/packages/nibijs/docs/classes/SpotMsgFactory.md +++ b/packages/nibijs/docs/classes/SpotMsgFactory.md @@ -39,7 +39,7 @@ #### Defined in -[msg/spot.ts:61](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L61) +[msg/spot.ts:61](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L61) --- @@ -59,7 +59,7 @@ #### Defined in -[msg/spot.ts:91](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L91) +[msg/spot.ts:91](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L91) --- @@ -79,7 +79,7 @@ #### Defined in -[msg/spot.ts:74](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L74) +[msg/spot.ts:74](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L74) --- @@ -99,4 +99,4 @@ #### Defined in -[msg/spot.ts:102](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L102) +[msg/spot.ts:102](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L102) diff --git a/packages/nibijs/docs/classes/StableSwap.md b/packages/nibijs/docs/classes/StableSwap.md index 9c4067e5..5eb2e74f 100644 --- a/packages/nibijs/docs/classes/StableSwap.md +++ b/packages/nibijs/docs/classes/StableSwap.md @@ -54,7 +54,7 @@ Constructor: #### Defined in -[stableswap/stableswap.ts:25](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L25) +[stableswap/stableswap.ts:25](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L25) ## Properties @@ -64,7 +64,7 @@ Constructor: #### Defined in -[stableswap/stableswap.ts:20](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L20) +[stableswap/stableswap.ts:20](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L20) --- @@ -74,7 +74,7 @@ Constructor: #### Defined in -[stableswap/stableswap.ts:23](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L23) +[stableswap/stableswap.ts:23](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L23) --- @@ -84,7 +84,7 @@ Constructor: #### Defined in -[stableswap/stableswap.ts:21](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L21) +[stableswap/stableswap.ts:21](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L21) --- @@ -94,7 +94,7 @@ Constructor: #### Defined in -[stableswap/stableswap.ts:22](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L22) +[stableswap/stableswap.ts:22](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L22) ## Methods @@ -117,7 +117,7 @@ StableSwap #### Defined in -[stableswap/stableswap.ts:54](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L54) +[stableswap/stableswap.ts:54](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L54) --- @@ -145,7 +145,7 @@ StableSwap #### Defined in -[stableswap/stableswap.ts:143](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L143) +[stableswap/stableswap.ts:143](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L143) --- @@ -165,7 +165,7 @@ StableSwap #### Defined in -[stableswap/stableswap.ts:41](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L41) +[stableswap/stableswap.ts:41](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L41) --- @@ -178,7 +178,7 @@ y() Calculate x[j] if one makes x[i] = x Done by solving quadratic equation iteratively. -x*1\*\*2 + x1 * (sum' - (A*n\*\*n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A) +x*1**2 + x1 * (sum' - (A*n**n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A) x_1\*\*2 + b\*x_1 = c x_1 = (x_1\**2 + c) / (2*x_1 + b) @@ -201,4 +201,4 @@ StableSwap #### Defined in -[stableswap/stableswap.ts:104](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/stableswap/stableswap.ts#L104) +[stableswap/stableswap.ts:104](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/stableswap/stableswap.ts#L104) diff --git a/packages/nibijs/docs/enums/BECH32_PREFIX.md b/packages/nibijs/docs/enums/BECH32_PREFIX.md index 86cfeba7..d6ef5c82 100644 --- a/packages/nibijs/docs/enums/BECH32_PREFIX.md +++ b/packages/nibijs/docs/enums/BECH32_PREFIX.md @@ -23,7 +23,7 @@ ADDR defines the Bech32 prefix of an account address #### Defined in -[tx/signer.ts:6](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L6) +[tx/signer.ts:6](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L6) --- @@ -35,7 +35,7 @@ ADDR_VAL defines the Bech32 prefix of an validator's operator address #### Defined in -[tx/signer.ts:8](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L8) +[tx/signer.ts:8](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L8) --- @@ -47,7 +47,7 @@ ADDR_VALCONS defines the Bech32 prefix of a consensus node address #### Defined in -[tx/signer.ts:10](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L10) +[tx/signer.ts:10](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L10) --- @@ -59,7 +59,7 @@ PUB defines the Bech32 prefix of an account's public key #### Defined in -[tx/signer.ts:12](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L12) +[tx/signer.ts:12](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L12) --- @@ -71,7 +71,7 @@ PUB_VAL defines the Bech32 prefix of an validator's operator public key #### Defined in -[tx/signer.ts:14](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L14) +[tx/signer.ts:14](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L14) --- @@ -83,4 +83,4 @@ PUB_VALCONS defines the Bech32 prefix of a consensus node public key #### Defined in -[tx/signer.ts:16](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L16) +[tx/signer.ts:16](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L16) diff --git a/packages/nibijs/docs/enums/Signer.md b/packages/nibijs/docs/enums/Signer.md index cd433919..a9d98ca0 100644 --- a/packages/nibijs/docs/enums/Signer.md +++ b/packages/nibijs/docs/enums/Signer.md @@ -17,7 +17,7 @@ #### Defined in -[tx/signer.ts:53](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L53) +[tx/signer.ts:53](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L53) --- @@ -27,4 +27,4 @@ #### Defined in -[tx/signer.ts:52](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L52) +[tx/signer.ts:52](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L52) diff --git a/packages/nibijs/docs/interfaces/ABCIEvent.md b/packages/nibijs/docs/interfaces/ABCIEvent.md index 4801bd39..1c1c5910 100644 --- a/packages/nibijs/docs/interfaces/ABCIEvent.md +++ b/packages/nibijs/docs/interfaces/ABCIEvent.md @@ -23,7 +23,7 @@ key-value strings of arbitrary data. #### Defined in -[tx/event.ts:23](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L23) +[tx/event.ts:23](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L23) --- @@ -33,4 +33,4 @@ key-value strings of arbitrary data. #### Defined in -[tx/event.ts:22](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L22) +[tx/event.ts:22](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L22) diff --git a/packages/nibijs/docs/interfaces/Chain.md b/packages/nibijs/docs/interfaces/Chain.md index 9c4a0551..b2bfcd1b 100644 --- a/packages/nibijs/docs/interfaces/Chain.md +++ b/packages/nibijs/docs/interfaces/Chain.md @@ -38,7 +38,7 @@ chainId: identifier for the chain #### Defined in -[chain/chain.ts:21](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L21) +[chain/chain.ts:21](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L21) --- @@ -50,7 +50,7 @@ chainName: the name of the chain to display to the user #### Defined in -[chain/chain.ts:23](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L23) +[chain/chain.ts:23](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L23) --- @@ -62,7 +62,7 @@ endptGrpc: endpoint for the gRPC gateway. Usually on port 9090. #### Defined in -[chain/chain.ts:19](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L19) +[chain/chain.ts:19](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L19) --- @@ -74,7 +74,7 @@ endptRest: endpoint for the REST server. Also, the LCD endpoint. #### Defined in -[chain/chain.ts:17](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L17) +[chain/chain.ts:17](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L17) --- @@ -86,7 +86,7 @@ endptTm: endpoint for the Tendermint RPC server. Usually on port 26657. #### Defined in -[chain/chain.ts:15](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L15) +[chain/chain.ts:15](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L15) --- @@ -98,4 +98,4 @@ feeDenom: the denomination of the fee to be paid for transactions. #### Defined in -[chain/chain.ts:25](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L25) +[chain/chain.ts:25](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L25) diff --git a/packages/nibijs/docs/interfaces/ChainIdParts.md b/packages/nibijs/docs/interfaces/ChainIdParts.md index 48c42f3f..4288b87e 100644 --- a/packages/nibijs/docs/interfaces/ChainIdParts.md +++ b/packages/nibijs/docs/interfaces/ChainIdParts.md @@ -6,29 +6,40 @@ ### Properties +- [mainnet](ChainIdParts.md#mainnet) - [number](ChainIdParts.md#number) - [prefix](ChainIdParts.md#prefix) - [shortName](ChainIdParts.md#shortname) ## Properties +### mainnet + +• `Optional` **mainnet**: `boolean` + +#### Defined in + +[chain/chain.ts:32](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L32) + +--- + ### number • **number**: `number` #### Defined in -[chain/chain.ts:31](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L31) +[chain/chain.ts:31](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L31) --- ### prefix -• **prefix**: `string` +• `Optional` **prefix**: `string` #### Defined in -[chain/chain.ts:29](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L29) +[chain/chain.ts:29](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L29) --- @@ -38,4 +49,4 @@ #### Defined in -[chain/chain.ts:30](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L30) +[chain/chain.ts:30](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L30) diff --git a/packages/nibijs/docs/interfaces/EpochsExtension.md b/packages/nibijs/docs/interfaces/EpochsExtension.md index cb580984..528c1cef 100644 --- a/packages/nibijs/docs/interfaces/EpochsExtension.md +++ b/packages/nibijs/docs/interfaces/EpochsExtension.md @@ -16,4 +16,4 @@ #### Defined in -[query/epochs.ts:11](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/epochs.ts#L11) +[query/epochs.ts:11](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/epochs.ts#L11) diff --git a/packages/nibijs/docs/interfaces/EventAttribute.md b/packages/nibijs/docs/interfaces/EventAttribute.md index 3ccf56c1..eb057aab 100644 --- a/packages/nibijs/docs/interfaces/EventAttribute.md +++ b/packages/nibijs/docs/interfaces/EventAttribute.md @@ -19,7 +19,7 @@ EventAttribute: A single key-value pair of event data for an ABCI event. #### Defined in -[tx/event.ts:5](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L5) +[tx/event.ts:5](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L5) --- @@ -29,4 +29,4 @@ EventAttribute: A single key-value pair of event data for an ABCI event. #### Defined in -[tx/event.ts:6](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L6) +[tx/event.ts:6](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L6) diff --git a/packages/nibijs/docs/interfaces/EventMap.md b/packages/nibijs/docs/interfaces/EventMap.md index 33e348a8..faa2c21e 100644 --- a/packages/nibijs/docs/interfaces/EventMap.md +++ b/packages/nibijs/docs/interfaces/EventMap.md @@ -41,4 +41,4 @@ export interface EventTransfer extends EventMap { #### Defined in -[tx/event.ts:41](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L41) +[tx/event.ts:41](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L41) diff --git a/packages/nibijs/docs/interfaces/InflationExtension.md b/packages/nibijs/docs/interfaces/InflationExtension.md index 1889a391..2fd968dd 100644 --- a/packages/nibijs/docs/interfaces/InflationExtension.md +++ b/packages/nibijs/docs/interfaces/InflationExtension.md @@ -16,4 +16,4 @@ #### Defined in -[query/inflation.ts:19](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/inflation.ts#L19) +[query/inflation.ts:19](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/inflation.ts#L19) diff --git a/packages/nibijs/docs/interfaces/MsgAddMarginEncodeObject.md b/packages/nibijs/docs/interfaces/MsgAddMarginEncodeObject.md index ee814bcd..769cb41b 100644 --- a/packages/nibijs/docs/interfaces/MsgAddMarginEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgAddMarginEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:37](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L37) +[msg/perp.ts:37](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L37) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:38](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L38) +[msg/perp.ts:38](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L38) diff --git a/packages/nibijs/docs/interfaces/MsgClosePositionEncodeObject.md b/packages/nibijs/docs/interfaces/MsgClosePositionEncodeObject.md index 243839b6..6136cd35 100644 --- a/packages/nibijs/docs/interfaces/MsgClosePositionEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgClosePositionEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:73](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L73) +[msg/perp.ts:73](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L73) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:74](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L74) +[msg/perp.ts:74](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L74) diff --git a/packages/nibijs/docs/interfaces/MsgCreatePoolEncodeObject.md b/packages/nibijs/docs/interfaces/MsgCreatePoolEncodeObject.md index cd8140c0..f7ae264e 100644 --- a/packages/nibijs/docs/interfaces/MsgCreatePoolEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgCreatePoolEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/spot.ts:27](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L27) +[msg/spot.ts:27](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L27) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/spot.ts:28](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L28) +[msg/spot.ts:28](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L28) diff --git a/packages/nibijs/docs/interfaces/MsgDonateToEcosystemFundEncodeObject.md b/packages/nibijs/docs/interfaces/MsgDonateToEcosystemFundEncodeObject.md index ef505095..8af3260d 100644 --- a/packages/nibijs/docs/interfaces/MsgDonateToEcosystemFundEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgDonateToEcosystemFundEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:82](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L82) +[msg/perp.ts:82](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L82) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:83](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L83) +[msg/perp.ts:83](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L83) diff --git a/packages/nibijs/docs/interfaces/MsgExitPoolEncodeObject.md b/packages/nibijs/docs/interfaces/MsgExitPoolEncodeObject.md index 72964378..bc27353b 100644 --- a/packages/nibijs/docs/interfaces/MsgExitPoolEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgExitPoolEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/spot.ts:43](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L43) +[msg/spot.ts:43](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L43) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/spot.ts:44](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L44) +[msg/spot.ts:44](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L44) diff --git a/packages/nibijs/docs/interfaces/MsgJoinPoolEncodeObject.md b/packages/nibijs/docs/interfaces/MsgJoinPoolEncodeObject.md index 937a2de0..07149731 100644 --- a/packages/nibijs/docs/interfaces/MsgJoinPoolEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgJoinPoolEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/spot.ts:35](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L35) +[msg/spot.ts:35](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L35) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/spot.ts:36](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L36) +[msg/spot.ts:36](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L36) diff --git a/packages/nibijs/docs/interfaces/MsgMultiLiquidateEncodeObject.md b/packages/nibijs/docs/interfaces/MsgMultiLiquidateEncodeObject.md index 672c71ca..0542ea0d 100644 --- a/packages/nibijs/docs/interfaces/MsgMultiLiquidateEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgMultiLiquidateEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:55](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L55) +[msg/perp.ts:55](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L55) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:56](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L56) +[msg/perp.ts:56](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L56) diff --git a/packages/nibijs/docs/interfaces/MsgOpenPositionEncodeObject.md b/packages/nibijs/docs/interfaces/MsgOpenPositionEncodeObject.md index 5410ef2e..fb676be4 100644 --- a/packages/nibijs/docs/interfaces/MsgOpenPositionEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgOpenPositionEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:64](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L64) +[msg/perp.ts:64](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L64) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:65](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L65) +[msg/perp.ts:65](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L65) diff --git a/packages/nibijs/docs/interfaces/MsgPartialCloseEncodeObject.md b/packages/nibijs/docs/interfaces/MsgPartialCloseEncodeObject.md index 2a6e6db7..b0c8c877 100644 --- a/packages/nibijs/docs/interfaces/MsgPartialCloseEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgPartialCloseEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:93](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L93) +[msg/perp.ts:93](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L93) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:94](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L94) +[msg/perp.ts:94](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L94) diff --git a/packages/nibijs/docs/interfaces/MsgRemoveMarginEncodeObject.md b/packages/nibijs/docs/interfaces/MsgRemoveMarginEncodeObject.md index 417ab5dd..5a189f44 100644 --- a/packages/nibijs/docs/interfaces/MsgRemoveMarginEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgRemoveMarginEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/perp.ts:46](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L46) +[msg/perp.ts:46](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L46) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/perp.ts:47](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L47) +[msg/perp.ts:47](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L47) diff --git a/packages/nibijs/docs/interfaces/MsgSwapAssetsEncodeObject.md b/packages/nibijs/docs/interfaces/MsgSwapAssetsEncodeObject.md index 5d7e1940..60ca6faa 100644 --- a/packages/nibijs/docs/interfaces/MsgSwapAssetsEncodeObject.md +++ b/packages/nibijs/docs/interfaces/MsgSwapAssetsEncodeObject.md @@ -27,7 +27,7 @@ EncodeObject.typeUrl #### Defined in -[msg/spot.ts:51](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L51) +[msg/spot.ts:51](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L51) --- @@ -41,4 +41,4 @@ EncodeObject.value #### Defined in -[msg/spot.ts:52](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L52) +[msg/spot.ts:52](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L52) diff --git a/packages/nibijs/docs/interfaces/OracleExtension.md b/packages/nibijs/docs/interfaces/OracleExtension.md index 9de66f07..dbf28f3c 100644 --- a/packages/nibijs/docs/interfaces/OracleExtension.md +++ b/packages/nibijs/docs/interfaces/OracleExtension.md @@ -16,4 +16,4 @@ #### Defined in -[query/oracle.ts:37](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/oracle.ts#L37) +[query/oracle.ts:37](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/oracle.ts#L37) diff --git a/packages/nibijs/docs/interfaces/PageRequest.md b/packages/nibijs/docs/interfaces/PageRequest.md index cae43fe3..7e26ca39 100644 --- a/packages/nibijs/docs/interfaces/PageRequest.md +++ b/packages/nibijs/docs/interfaces/PageRequest.md @@ -34,7 +34,7 @@ is set. #### Defined in -[query/spot.ts:252](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L252) +[query/spot.ts:252](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L252) --- @@ -48,7 +48,7 @@ should be set. #### Defined in -[query/spot.ts:234](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L234) +[query/spot.ts:234](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L234) --- @@ -61,7 +61,7 @@ If left empty it will default to a value to be set by each app. #### Defined in -[query/spot.ts:245](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L245) +[query/spot.ts:245](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L245) --- @@ -75,7 +75,7 @@ be set. #### Defined in -[query/spot.ts:240](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L240) +[query/spot.ts:240](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L240) --- @@ -89,4 +89,4 @@ Since: cosmos-sdk 0.43 #### Defined in -[query/spot.ts:258](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L258) +[query/spot.ts:258](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L258) diff --git a/packages/nibijs/docs/interfaces/PerpExtension.md b/packages/nibijs/docs/interfaces/PerpExtension.md index 9273ae70..8573b7a8 100644 --- a/packages/nibijs/docs/interfaces/PerpExtension.md +++ b/packages/nibijs/docs/interfaces/PerpExtension.md @@ -16,4 +16,4 @@ #### Defined in -[query/perp.ts:24](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/perp.ts#L24) +[query/perp.ts:24](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/perp.ts#L24) diff --git a/packages/nibijs/docs/interfaces/SpotExtension.md b/packages/nibijs/docs/interfaces/SpotExtension.md index e29cbcba..b0511570 100644 --- a/packages/nibijs/docs/interfaces/SpotExtension.md +++ b/packages/nibijs/docs/interfaces/SpotExtension.md @@ -16,4 +16,4 @@ #### Defined in -[query/spot.ts:58](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L58) +[query/spot.ts:58](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L58) diff --git a/packages/nibijs/docs/interfaces/SudoExtension.md b/packages/nibijs/docs/interfaces/SudoExtension.md index 510750e3..d93ce458 100644 --- a/packages/nibijs/docs/interfaces/SudoExtension.md +++ b/packages/nibijs/docs/interfaces/SudoExtension.md @@ -16,4 +16,4 @@ #### Defined in -[query/sudo.ts:9](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/sudo.ts#L9) +[query/sudo.ts:9](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/sudo.ts#L9) diff --git a/packages/nibijs/docs/interfaces/TxLog.md b/packages/nibijs/docs/interfaces/TxLog.md index 3c1e907d..8c3ade93 100644 --- a/packages/nibijs/docs/interfaces/TxLog.md +++ b/packages/nibijs/docs/interfaces/TxLog.md @@ -16,4 +16,4 @@ #### Defined in -[chain/types.ts:53](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/types.ts#L53) +[chain/types.ts:41](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/types.ts#L41) diff --git a/packages/nibijs/docs/modules.md b/packages/nibijs/docs/modules.md index 8d5b2abf..c6c2217f 100644 --- a/packages/nibijs/docs/modules.md +++ b/packages/nibijs/docs/modules.md @@ -16,6 +16,7 @@ - [NibiruQueryClient](classes/NibiruQueryClient.md) - [NibiruSigningClient](classes/NibiruSigningClient.md) - [PerpMsgFactory](classes/PerpMsgFactory.md) +- [Result](classes/Result.md) - [SpotMsgFactory](classes/SpotMsgFactory.md) - [StableSwap](classes/StableSwap.md) @@ -56,11 +57,15 @@ ### Variables +- [ERR](modules.md#err) - [INT_MULT](modules.md#int_mult) - [Localnet](modules.md#localnet) - [Msg](modules.md#msg) - [PERP_MSG_TYPE_URLS](modules.md#perp_msg_type_urls) - [SPOT_MSG_TYPE_URLS](modules.md#spot_msg_type_urls) +- [TEST_ADDRESS](modules.md#test_address) +- [TEST_CHAIN](modules.md#test_chain) +- [TEST_MNEMONIC](modules.md#test_mnemonic) - [nibiruRegistryTypes](modules.md#nibiruregistrytypes) - [perpTypes](modules.md#perptypes) - [spotTypes](modules.md#spottypes) @@ -71,6 +76,12 @@ - [IncentivizedTestnet](modules.md#incentivizedtestnet) - [Testnet](modules.md#testnet) - [assert](modules.md#assert) +- [assertExpectedError](modules.md#assertexpectederror) +- [assertHasEventType](modules.md#asserthaseventtype) +- [assertHasMsgType](modules.md#asserthasmsgtype) +- [assertValidBlock](modules.md#assertvalidblock) +- [assertValidBlockFromJsonRpc](modules.md#assertvalidblockfromjsonrpc) +- [bytesToHex](modules.md#bytestohex) - [chainToParts](modules.md#chaintoparts) - [eventToMap](modules.md#eventtomap) - [faucetUrlFromChain](modules.md#fauceturlfromchain) @@ -78,7 +89,7 @@ - [fromSdkDec](modules.md#fromsdkdec) - [fromSdkInt](modules.md#fromsdkint) - [getRegistry](modules.md#getregistry) -- [go](modules.md#go) +- [hexToBytes](modules.md#hextobytes) - [isMsgAddMarginEncodeObject](modules.md#ismsgaddmarginencodeobject) - [isMsgClosePositionEncodeObject](modules.md#ismsgclosepositionencodeobject) - [isMsgCreatePoolEncodeObject](modules.md#ismsgcreatepoolencodeobject) @@ -94,6 +105,7 @@ - [newCoinMapFromCoins](modules.md#newcoinmapfromcoins) - [newRandomWallet](modules.md#newrandomwallet) - [newSignerFromMnemonic](modules.md#newsignerfrommnemonic) +- [parseError](modules.md#parseerror) - [parseEventLogs](modules.md#parseeventlogs) - [queryChainIdWithRest](modules.md#querychainidwithrest) - [setupEpochsExtension](modules.md#setupepochsextension) @@ -116,17 +128,35 @@ #### Defined in -[query/query.ts:29](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/query.ts#L29) +[query/query.ts:32](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/query.ts#L32) ## Variables +### ERR + +• `Const` **ERR**: `Object` + +#### Type declaration + +| Name | Type | +| :------------ | :------- | +| `collections` | `string` | +| `noPrices` | `string` | +| `sequence` | `string` | + +#### Defined in + +[testutil.ts:19](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L19) + +--- + ### INT_MULT • `Const` **INT_MULT**: `1000000` #### Defined in -[chain/parse.ts:2](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/parse.ts#L2) +[chain/parse.ts:2](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/parse.ts#L2) --- @@ -141,7 +171,7 @@ controllable, isolated development environment for testing purposes. #### Defined in -[chain/chain.ts:85](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L85) +[chain/chain.ts:91](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L91) --- @@ -151,7 +181,7 @@ controllable, isolated development environment for testing purposes. #### Defined in -[msg/index.ts:9](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/index.ts#L9) +[msg/index.ts:9](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/index.ts#L9) --- @@ -173,7 +203,7 @@ controllable, isolated development environment for testing purposes. #### Defined in -[msg/perp.ts:16](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L16) +[msg/perp.ts:16](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L16) --- @@ -192,7 +222,47 @@ controllable, isolated development environment for testing purposes. #### Defined in -[msg/spot.ts:12](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L12) +[msg/spot.ts:12](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L12) + +--- + +### TEST_ADDRESS + +• `Const` **TEST_ADDRESS**: `string` + +Address for the wallet of the default validator on localnet" + +#### Defined in + +[testutil.ts:16](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L16) + +--- + +### TEST_CHAIN + +• `Const` **TEST_CHAIN**: [`Chain`](interfaces/Chain.md) = `Localnet` + +TEST_CHAIN: Alias for Localnet. + +**`See`** + +Localnet + +#### Defined in + +[testutil.ts:8](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L8) + +--- + +### TEST_MNEMONIC + +• `Const` **TEST_MNEMONIC**: `string` + +Mnemonic for the wallet of the default validator on localnet" + +#### Defined in + +[testutil.ts:11](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L11) --- @@ -202,7 +272,7 @@ controllable, isolated development environment for testing purposes. #### Defined in -[tx/signingClient.ts:31](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signingClient.ts#L31) +[tx/signingClient.ts:31](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signingClient.ts#L31) --- @@ -212,7 +282,7 @@ controllable, isolated development environment for testing purposes. #### Defined in -[msg/perp.ts:26](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L26) +[msg/perp.ts:26](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L26) --- @@ -222,7 +292,7 @@ controllable, isolated development environment for testing purposes. #### Defined in -[msg/spot.ts:19](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L19) +[msg/spot.ts:19](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L19) ## Functions @@ -246,7 +316,7 @@ dev team to live-test new features before official public release. #### Defined in -[chain/chain.ts:124](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L124) +[chain/chain.ts:130](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L130) --- @@ -275,7 +345,7 @@ Testnet - Permanent Nibiru public test network. #### Defined in -[chain/chain.ts:106](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L106) +[chain/chain.ts:112](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L112) --- @@ -308,28 +378,184 @@ arguments are passed. #### Defined in -[chain/chain.ts:106](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L106) +[chain/chain.ts:112](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L112) --- ### assert -▸ **assert**(`condition`, `message?`): `string` \| `true` +▸ **assert**(`condition`, `message?`): `string` \| `boolean` + +Asserts that a given condition is true. If the condition evaluates to false, +an "AssertionError" is thrown with an optional custom message. #### Parameters -| Name | Type | -| :---------- | :-------- | -| `condition` | `boolean` | -| `message?` | `string` | +| Name | Type | Description | +| :---------- | :-------- | :------------------------------------------------------------------ | +| `condition` | `boolean` | The condition to test. | +| `message?` | `string` | Optional. A custom error message to display if the assertion fails. | #### Returns -`string` \| `true` +`string` \| `boolean` + +- Returns true if the assertion is successful. + +#### Defined in + +[chain/types.ts:14](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/types.ts#L14) + +--- + +### assertExpectedError + +▸ **assertExpectedError**(`err`, `okErrors`): `void` + +Asserts that the given error matches one of the expected error messages. + +This function parses the error object to extract its message and checks if +it includes any of the specified acceptable error messages. It sets a test +expectation that the error message is contained within the list of acceptable errors. + +#### Parameters + +| Name | Type | Description | +| :--------- | :--------- | :-------------------------------------------- | +| `err` | `unknown` | The error object to be tested. | +| `okErrors` | `string`[] | An array of acceptable error message strings. | + +#### Returns + +`void` + +#### Defined in + +[testutil.ts:100](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L100) + +--- + +### assertHasEventType + +▸ **assertHasEventType**(`eventType`, `events`): `void` + +Asserts that an array of ABCIEvent objects contains an event with a specified +type. This runs a test expectation that the specified `eventType` is +contained in `events`. + +#### Parameters + +| Name | Type | Description | +| :---------- | :--------------------------------------- | :------------------------------------------------- | +| `eventType` | `string` | The event type to look for in the array of events. | +| `events` | [`ABCIEvent`](interfaces/ABCIEvent.md)[] | An array of ABCIEvent objects to be tested. | + +#### Returns + +`void` #### Defined in -[chain/types.ts:29](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/types.ts#L29) +[testutil.ts:82](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L82) + +--- + +### assertHasMsgType + +▸ **assertHasMsgType**(`msgType`, `events`): `void` + +Asserts that a list of ABCIEvents contains a specific type of `TxMsg`. This +`TxMsg` type is read from a "message" event's "action" attribute. + +#### Parameters + +| Name | Type | Description | +| :-------- | :--------------------------------------- | :-------------------------------------------------- | +| `msgType` | `string` | TxMsg type to look for within the event attributes. | +| `events` | [`ABCIEvent`](interfaces/ABCIEvent.md)[] | set of events over which we're searching. | + +#### Returns + +`void` + +#### Defined in + +[testutil.ts:63](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L63) + +--- + +### assertValidBlock + +▸ **assertValidBlock**(`block`, `chain`): `void` + +assertValidBlock: Performs runtime type validation on a CometBFT "Block". + +#### Parameters + +| Name | Type | +| :------ | :----------------------------- | +| `block` | `Block` | +| `chain` | [`Chain`](interfaces/Chain.md) | + +#### Returns + +`void` + +#### Defined in + +[testutil.ts:49](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L49) + +--- + +### assertValidBlockFromJsonRpc + +▸ **assertValidBlockFromJsonRpc**(`blockJson`): `void` + +Validates that block queried via the JSON RPC client has the expected fields. + +#### Parameters + +| Name | Type | +| :---------- | :---- | +| `blockJson` | `any` | + +#### Returns + +`void` + +#### Defined in + +[testutil.ts:26](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/testutil.ts#L26) + +--- + +### bytesToHex + +▸ **bytesToHex**(`bz`): `string` + +Converts an 8-bit byte array (Uint8Array) into a hexadecimal (hex) string. + +Each 8-bit byte ranges from 0 to 255 and is represented by a 2-tuple of +hex digits (0-9, A-F). Values from 0-15 (0x0 to 0xF) +are indeed single-digit in hex, but in the context of hex strings, these +values are padded with a leading zero to maintain a consistent two-character +representation for each byte. + +Thus, a byte value of 9 is represented as "09". + +#### Parameters + +| Name | Type | +| :--- | :----------- | +| `bz` | `Uint8Array` | + +#### Returns + +`string` + +#### Defined in + +[hash.ts:14](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/hash.ts#L14) --- @@ -353,7 +579,7 @@ a ChainIdParts object #### Defined in -[chain/chain.ts:157](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L157) +[chain/chain.ts:164](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L164) --- @@ -375,7 +601,7 @@ eventToMap: Converts an ABCIEvent into an EventMap. #### Defined in -[tx/event.ts:44](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L44) +[tx/event.ts:44](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L44) --- @@ -397,7 +623,7 @@ Constructs a faucet URL from a Chain object. #### Defined in -[chain/useFaucet.ts:59](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/useFaucet.ts#L59) +[chain/useFaucet.ts:59](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/useFaucet.ts#L59) --- @@ -421,7 +647,7 @@ events of known type are present. #### Defined in -[tx/event.ts:54](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L54) +[tx/event.ts:54](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L54) --- @@ -461,7 +687,7 @@ the human-readbale Dec. #### Defined in -[chain/parse.ts:113](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/parse.ts#L113) +[chain/parse.ts:113](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/parse.ts#L113) --- @@ -481,7 +707,7 @@ the human-readbale Dec. #### Defined in -[chain/parse.ts:164](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/parse.ts#L164) +[chain/parse.ts:166](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/parse.ts#L166) --- @@ -495,42 +721,61 @@ the human-readbale Dec. #### Defined in -[tx/signer.ts:19](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L19) +[tx/signer.ts:19](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L19) --- -### go - -▸ **go**<`T`\>(`promise`): `Promise`<`GoSuccess`<`T`\> \| `GoError`\> +### hexToBytes -go: Generic function for executing asynchronous code safely inside a -try-catch by default. If the promise succeeds, it's result is returned and the -error is undefined. If it fails, the result is undefined and the error message -is present. The function's called "go" because it mimics the error handling -behavior from Golang. +▸ **hexToBytes**(`hex`): [`Result`](classes/Result.md)<`Uint8Array`\> -GoSuccess: A successful promise result that doesn't "throw". -GoError: A wrapped error type resulting from a "throw" inside a Promise. +Converts a hexadecimal-encoded string into a Uint8Array. -#### Type parameters - -| Name | -| :--- | -| `T` | +The hexadecimal string must have an even length, as each byte is represented +by two hex digits. Each of hex digit 2-tuples (ranging from 00 to FF) is +converted to a single byte ranging from 0 to 255. #### Parameters -| Name | Type | -| :-------- | :-------------- | -| `promise` | `Promise`<`T`\> | +| Name | Type | Description | +| :---- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `hex` | `string` | The hexadecimal string to be decoded. If the string has an odd length or contains non-hexadecimal characters, the function returns an error wrapped in a Result object rather than throwing. | #### Returns -`Promise`<`GoSuccess`<`T`\> \| `GoError`\> +[`Result`](classes/Result.md)<`Uint8Array`\> + +The decoded Uint8Array if successful or an +error result if the input is invalid. + +**`Example`** + +```ts +// Successful decoding +const result = hexToBytes("7A919F2CC9A51B139444F7D8E84A46EE") +if (result.isOk()) { + console.log(result.ok) // Uint8Array of bytes +} else { + console.error(result.err) // Error +} +``` + +**`Example`** + +```ts +// Error handling for invalid hex string +const result = hexToBytes("7G919F") +if (result.isOk()) { + console.log(result.ok) +} else { + console.error(result.err.message) + // "HexError: non-hex characters detected in hex: 7G919F" +} +``` #### Defined in -[chain/types.ts:14](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/types.ts#L14) +[hash.ts:51](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/hash.ts#L51) --- @@ -550,7 +795,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:41](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L41) +[msg/perp.ts:41](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L41) --- @@ -570,7 +815,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:77](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L77) +[msg/perp.ts:77](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L77) --- @@ -590,7 +835,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/spot.ts:31](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L31) +[msg/spot.ts:31](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L31) --- @@ -610,7 +855,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:86](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L86) +[msg/perp.ts:86](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L86) --- @@ -630,7 +875,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/spot.ts:47](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L47) +[msg/spot.ts:47](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L47) --- @@ -650,7 +895,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/spot.ts:39](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L39) +[msg/spot.ts:39](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L39) --- @@ -670,7 +915,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:59](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L59) +[msg/perp.ts:59](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L59) --- @@ -690,7 +935,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:68](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L68) +[msg/perp.ts:68](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L68) --- @@ -710,7 +955,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:97](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L97) +[msg/perp.ts:97](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L97) --- @@ -730,7 +975,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/perp.ts:50](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/perp.ts#L50) +[msg/perp.ts:50](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/perp.ts#L50) --- @@ -750,7 +995,7 @@ GoError: A wrapped error type resulting from a "throw" inside a Promise. #### Defined in -[msg/spot.ts:55](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/msg/spot.ts#L55) +[msg/spot.ts:55](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/msg/spot.ts#L55) --- @@ -773,7 +1018,7 @@ the network and endpoint are active. #### Defined in -[chain/chain.ts:147](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L147) +[chain/chain.ts:154](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L154) --- @@ -793,7 +1038,7 @@ the network and endpoint are active. #### Defined in -[chain/types.ts:44](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/types.ts#L44) +[chain/types.ts:32](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/types.ts#L32) --- @@ -820,7 +1065,7 @@ A wallet for protobuf based signing using SIGN_MODE_DIRECT. #### Defined in -[tx/signer.ts:45](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L45) +[tx/signer.ts:45](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L45) --- @@ -847,7 +1092,31 @@ A wallet for protobuf based signing using SIGN_MODE_DIRECT #### Defined in -[tx/signer.ts:29](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/signer.ts#L29) +[tx/signer.ts:29](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/signer.ts#L29) + +--- + +### parseError + +▸ **parseError**(`err`): `Error` + +parseError: Guarantees runtime strong error typing since this isn't +guaranteed in JS by default. The error that comes out of a try-catch may not +have type "Error" since it's perfectly valid to throw strings or `undefined`. + +#### Parameters + +| Name | Type | +| :---- | :---- | +| `err` | `any` | + +#### Returns + +`Error` + +#### Defined in + +[result.ts:75](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/result.ts#L75) --- @@ -877,13 +1146,13 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[tx/event.ts:67](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/tx/event.ts#L67) +[tx/event.ts:67](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/tx/event.ts#L67) --- ### queryChainIdWithRest -▸ **queryChainIdWithRest**(`chain`): `Promise`<(`undefined` \| `string`)[]\> +▸ **queryChainIdWithRest**(`chain`): `Promise`<[`Result`](classes/Result.md)<`string`\>\> #### Parameters @@ -893,11 +1162,11 @@ const eventLogs = parseEventLogs(txResp) #### Returns -`Promise`<(`undefined` \| `string`)[]\> +`Promise`<[`Result`](classes/Result.md)<`string`\>\> #### Defined in -[chain/chain.ts:131](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/chain.ts#L131) +[chain/chain.ts:137](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/chain.ts#L137) --- @@ -917,7 +1186,7 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[query/epochs.ts:19](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/epochs.ts#L19) +[query/epochs.ts:19](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/epochs.ts#L19) --- @@ -937,7 +1206,7 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[query/inflation.ts:29](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/inflation.ts#L29) +[query/inflation.ts:29](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/inflation.ts#L29) --- @@ -957,7 +1226,7 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[query/oracle.ts:91](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/oracle.ts#L91) +[query/oracle.ts:91](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/oracle.ts#L91) --- @@ -977,7 +1246,7 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[query/perp.ts:45](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/perp.ts#L45) +[query/perp.ts:45](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/perp.ts#L45) --- @@ -997,7 +1266,7 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[query/spot.ts:102](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L102) +[query/spot.ts:102](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L102) --- @@ -1017,7 +1286,7 @@ const eventLogs = parseEventLogs(txResp) #### Defined in -[query/sudo.ts:14](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/sudo.ts#L14) +[query/sudo.ts:14](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/sudo.ts#L14) --- @@ -1064,7 +1333,7 @@ sdk.Dec protobuf string into a number. #### Defined in -[chain/parse.ts:30](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/parse.ts#L30) +[chain/parse.ts:30](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/parse.ts#L30) --- @@ -1084,7 +1353,7 @@ sdk.Dec protobuf string into a number. #### Defined in -[chain/parse.ts:162](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/parse.ts#L162) +[chain/parse.ts:164](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/parse.ts#L164) --- @@ -1104,7 +1373,7 @@ sdk.Dec protobuf string into a number. #### Defined in -[query/spot.ts:49](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L49) +[query/spot.ts:49](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L49) --- @@ -1124,7 +1393,7 @@ sdk.Dec protobuf string into a number. #### Defined in -[query/spot.ts:41](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/query/spot.ts#L41) +[query/spot.ts:41](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/query/spot.ts#L41) --- @@ -1153,4 +1422,4 @@ Sends 11 NIBI, 100 NUSD, and 100 USDT to the given address from the testnet fauc #### Defined in -[chain/useFaucet.ts:7](https://github.com/NibiruChain/ts-sdk/blob/d2a4311/packages/nibijs/src/chain/useFaucet.ts#L7) +[chain/useFaucet.ts:7](https://github.com/NibiruChain/ts-sdk/blob/f607ea4/packages/nibijs/src/chain/useFaucet.ts#L7) diff --git a/packages/nibijs/src/chain/chain.ts b/packages/nibijs/src/chain/chain.ts index bb574f35..268d82e4 100644 --- a/packages/nibijs/src/chain/chain.ts +++ b/packages/nibijs/src/chain/chain.ts @@ -1,5 +1,5 @@ import { fetch } from "cross-fetch" -import { go } from "./types" +import { Result } from "../result" /** * Specifies chain information for all endpoints a Nibiru node exposes such as the @@ -70,17 +70,19 @@ export class CustomChain implements Chain { public static fromChainId(chainId: string): Chain { const parts = chainId.split("-") - const chainIdParts = { + const chainIdParts: ChainIdParts = { prefix: parts[0], shortName: parts[1], - number: Number(parts[2]), - } as ChainIdParts + number: parseInt(parts[2]), + } return new CustomChain(chainIdParts) } private initChainId = () => { const { prefix, shortName, number } = this.chainIdParts - return [prefix, shortName, number].filter(Boolean).join("-") + return [prefix, shortName, number] + .filter((v) => Boolean(v) || Number(v) === 0) + .join("-") } } @@ -134,7 +136,9 @@ export const Devnet = (chainNumber: number) => number: chainNumber, }) -export const queryChainIdWithRest = async (chain: Chain) => { +export const queryChainIdWithRest = async ( + chain: Chain +): Promise> => { const queryChainId = async (chain: Chain): Promise => { const response = await fetch( `${chain.endptRest}/cosmos/base/tendermint/v1beta1/node_info` @@ -144,15 +148,14 @@ export const queryChainIdWithRest = async (chain: Chain) => { return nodeInfo.default_node_info.network } - const { res: chainId, err } = await go(queryChainId(chain)) - return [chainId ?? "", err] + return Result.ofSafeExecAsync(async () => queryChainId(chain)) } /** isRestEndptLive: Makes a request using the chain's REST endpoint to see if * the network and endpoint are active. */ export const isRestEndptLive = async (chain: Chain): Promise => { - const [_chainId, err] = await queryChainIdWithRest(chain) - return err === undefined + const res = await queryChainIdWithRest(chain) + return res.isOk() } /** diff --git a/packages/nibijs/src/chain/parse.ts b/packages/nibijs/src/chain/parse.ts index 0c21c6a9..74608091 100644 --- a/packages/nibijs/src/chain/parse.ts +++ b/packages/nibijs/src/chain/parse.ts @@ -69,9 +69,9 @@ export const toSdkDec = (dec: string): string => { if (lenDigitBlock > PRECISION) { console.error( - `value \${decStr}' exceeds max precision by ${ + `value "${decStr}" exceeds max precision by ${ PRECISION - lenDigitBlock - } decimal places: max precision ${PRECISION}` + } decimal places: max precision is ${PRECISION}` ) return "0" } @@ -116,12 +116,14 @@ export const fromSdkDec = (sdkDec: string): number => { } if (sdkDec.indexOf(".") !== -1) { - console.error(`expected a decimal string but got ${sdkDec} containing '.'`) + console.error( + `expected a decimal string but got "${sdkDec}" containing '.'` + ) return 0 } if (Number.isNaN(parseInt(sdkDec, 10))) { - console.error(`failed to convert ${sdkDec} to a number`) + console.error(`failed to convert "${sdkDec}" to a number`) return 0 } diff --git a/packages/nibijs/src/chain/types.ts b/packages/nibijs/src/chain/types.ts index e62415d6..435b634b 100644 --- a/packages/nibijs/src/chain/types.ts +++ b/packages/nibijs/src/chain/types.ts @@ -1,32 +1,20 @@ import { Coin } from "@cosmjs/proto-signing" -import { ABCIEvent } from "../tx/event" import BigNumber from "bignumber.js" +import { ABCIEvent } from "../tx/event" -/** go: Generic function for executing asynchronous code safely inside a - * try-catch by default. If the promise succeeds, it's result is returned and the - * error is undefined. If it fails, the result is undefined and the error message - * is present. The function's called "go" because it mimics the error handling - * behavior from Golang. +/** + * Asserts that a given condition is true. If the condition evaluates to false, + * an "AssertionError" is thrown with an optional custom message. * - * GoSuccess: A successful promise result that doesn't "throw". - * GoError: A wrapped error type resulting from a "throw" inside a Promise. - * */ -export const go = async ( - promise: Promise -): Promise | GoError> => { - try { - return { res: await promise, err: undefined } - } catch (err) { - return { res: undefined, err: (err as Error).message } - } -} - -/** GoSuccess: A successful promise result that doesn't "throw". */ -type GoSuccess = { res: T; err: undefined } -/** GoError: A wrapped error type resulting from a "throw" inside a Promise. */ -type GoError = { res: undefined; err: string } - -export const assert = (condition: boolean, message?: string) => { + * @param {boolean} condition - The condition to test. + * @param {string} message - Optional. A custom error message to display if the + * assertion fails. + * @returns {boolean} - Returns true if the assertion is successful. + */ +export const assert = ( + condition: boolean, + message?: string +): boolean | string => { if (!condition) { const errMsg = message ? `AssertionError: ${message}` : "AssertionError" console.error(Error(errMsg)) diff --git a/packages/nibijs/src/hash.test.ts b/packages/nibijs/src/hash.test.ts new file mode 100644 index 00000000..d1ba301b --- /dev/null +++ b/packages/nibijs/src/hash.test.ts @@ -0,0 +1,57 @@ +import { bytesToHex, hexToBytes } from "./hash" + +const TEST_CASES: { hex: string; bz: Uint8Array }[] = [ + { + hex: "7A919F2CC9A51B139444F7D8E84A46EEF307E839C6CA914C1A1C594FEF5C1562", + bz: Uint8Array.from([ + 122, 145, 159, 44, 201, 165, 27, 19, 148, 68, 247, 216, 232, 74, 70, 238, + 243, 7, 232, 57, 198, 202, 145, 76, 26, 28, 89, 79, 239, 92, 21, 98, + ]), + }, + { + hex: "C171E757AA0EEDB45703DC733A92162A2413CA1ACFCE8FBBA912A0B9F01122C1", + bz: Uint8Array.from([ + 193, 113, 231, 87, 170, 14, 237, 180, 87, 3, 220, 115, 58, 146, 22, 42, + 36, 19, 202, 26, 207, 206, 143, 187, 169, 18, 160, 185, 240, 17, 34, 193, + ]), + }, + { + hex: "792C9F0D5052BD722BBD2DC332F24944143436AA1E1FA30E9A5E5B45C73831D0", + bz: Uint8Array.from([ + 121, 44, 159, 13, 80, 82, 189, 114, 43, 189, 45, 195, 50, 242, 73, 68, 20, + 52, 54, 170, 30, 31, 163, 14, 154, 94, 91, 69, 199, 56, 49, 208, + ]), + }, + { + hex: "D3EB2222E9A46BF3A0D6C70544E8916EFE016DD42820F27CDA382991FC336274", + bz: Uint8Array.from([ + 211, 235, 34, 34, 233, 164, 107, 243, 160, 214, 199, 5, 68, 232, 145, 110, + 254, 1, 109, 212, 40, 32, 242, 124, 218, 56, 41, 145, 252, 51, 98, 116, + ]), + }, + { + hex: "E56701BF3110CCD73AFA94C149024BC2A64C1DDD75A74F3DB397677EC6C47D52", + bz: Uint8Array.from([ + 229, 103, 1, 191, 49, 16, 204, 215, 58, 250, 148, 193, 73, 2, 75, 194, + 166, 76, 29, 221, 117, 167, 79, 61, 179, 151, 103, 126, 198, 196, 125, 82, + ]), + }, +] + +test("encode to hex, decode to bytes", () => { + TEST_CASES.forEach((tc) => { + const resBz = hexToBytes(tc.hex) + expect(resBz.isOk()).toBeTruthy() + expect(resBz.ok).toEqual(tc.bz) + + const gotHex = bytesToHex(resBz.ok!) + expect(gotHex).toEqual(tc.hex) + }) +}) + +test("hex encode: sad path", () => { + const hex = "ABC12" + const resBz = hexToBytes(hex) + expect(resBz.isErr()).toBeTruthy() + expect(resBz.err!.message).toContain("even length") +}) diff --git a/packages/nibijs/src/hash.ts b/packages/nibijs/src/hash.ts new file mode 100644 index 00000000..b0288370 --- /dev/null +++ b/packages/nibijs/src/hash.ts @@ -0,0 +1,73 @@ +import { Result } from "./result" + +/** + * Converts an 8-bit byte array (Uint8Array) into a hexadecimal (hex) string. + * + * Each 8-bit byte ranges from 0 to 255 and is represented by a 2-tuple of + * hex digits (0-9, A-F). Values from 0-15 (0x0 to 0xF) + * are indeed single-digit in hex, but in the context of hex strings, these + * values are padded with a leading zero to maintain a consistent two-character + * representation for each byte. + * + * Thus, a byte value of 9 is represented as "09". + * */ +export const bytesToHex = (bz: Uint8Array): string => + Array.from(bz) + .map((b) => b.toString(16).toUpperCase().padStart(2, "0")) + .join("") + +/** + * Converts a hexadecimal-encoded string into a Uint8Array. + * + * The hexadecimal string must have an even length, as each byte is represented + * by two hex digits. Each of hex digit 2-tuples (ranging from 00 to FF) is + * converted to a single byte ranging from 0 to 255. + * + * @param {string} hex - The hexadecimal string to be decoded. If the string + * has an odd length or contains non-hexadecimal characters, the function + * returns an error wrapped in a Result object rather than throwing. + * @returns {Result} The decoded Uint8Array if successful or an + * error result if the input is invalid. + * + * @example + * // Successful decoding + * const result = hexToBytes("7A919F2CC9A51B139444F7D8E84A46EE"); + * if (result.isOk()) { + * console.log(result.ok); // Uint8Array of bytes + * } else { + * console.error(result.err); // Error + * } + * + * @example + * // Error handling for invalid hex string + * const result = hexToBytes("7G919F"); + * if (result.isOk()) { + * console.log(result.ok); + * } else { + * console.error(result.err.message); + * // "HexError: non-hex characters detected in hex: 7G919F" + * } + */ +export const hexToBytes = (hex: string): Result => { + if (hex.length % 2 !== 0) { + return new Result({ + err: new Error( + `HexError: hex string must have even length to decode into bytes: hex ${hex}` + ), + }) + } + + return Result.ofSafeExec(() => + Uint8Array.from( + hex.match(/.{1,2}/g)!.map((hexTuple: string) => { + const byte = parseInt(hexTuple, 16) + if (Number.isNaN(byte)) { + throw new Error( + `HexError: non-hex characters detected in hex: ${hex}` + ) + } + return byte + }) + ) + ) +} diff --git a/packages/nibijs/src/index.ts b/packages/nibijs/src/index.ts index 269512de..a97246ab 100644 --- a/packages/nibijs/src/index.ts +++ b/packages/nibijs/src/index.ts @@ -3,3 +3,6 @@ export * from "./msg" export * from "./query" export * from "./stableswap" export * from "./tx" +export * from "./hash" +export * from "./result" +export * from "./testutil" diff --git a/packages/nibijs/src/query/query.ts b/packages/nibijs/src/query/query.ts index 3a4ec6d3..ee8aba87 100644 --- a/packages/nibijs/src/query/query.ts +++ b/packages/nibijs/src/query/query.ts @@ -19,12 +19,15 @@ import { setupWasmExtension, WasmExtension, } from "@cosmjs/cosmwasm-stargate" +import { TxResponse } from "@cosmjs/tendermint-rpc/build/tendermint37" import { EpochsExtension, setupEpochsExtension } from "./epochs" import { OracleExtension, setupOracleExtension } from "./oracle" import { PerpExtension, setupPerpExtension } from "./perp" import { setupSpotExtension, SpotExtension } from "./spot" import { setupSudoExtension, SudoExtension } from "./sudo" import { InflationExtension, setupInflationExtension } from "./inflation" +import { Result } from "../result" +import { bytesToHex, hexToBytes } from "../hash" export type NibiruExtensions = StargateQueryClient & SpotExtension & @@ -102,4 +105,38 @@ export class NibiruQueryClient extends StargateClient { }) } } + + /** getTxByHash: Query a transaction (tx) using its hexadecial encoded tx hash. + * A tx hash uniquely identifies a tx on the blockchain. + * + * The hex-encoded tx hash is: + * - An unambiguous representation of the SHA-256 cryptographic hash in the + * consensus layer. + * - Well-suited for human-facing applications, as it is easier to work with + * than bytes. + * + * @example + * const txHash = "7A919F2CC9A51B139444F7D8E84A46EEF307E839C6CA914C1A1C594FEF5C1562" + * const txRespResult = await getTxByHash(txHash) + * */ + public getTxByHash = (txHashHex: string): Promise> => + Result.ofSafeExecAsync(async () => { + const resBz = hexToBytes(txHashHex) + if (resBz.ok) { + return this.tm.tx({ hash: resBz.ok }) + } + throw resBz.err + }) + + /** getTxByHashBytes: Query a transaction (tx) using its SHA-256 tx hash (bytes). + * A tx hash uniquely identifies a tx on the blockchain. + * + * @see getTxByHash - Equivalent query using the hex-encoded tx hash string. + * */ + public getTxByHashBytes = (txHash: Uint8Array): Promise> => + Result.ofSafeExecAsync(async () => { + bytesToHex(txHash) // To validate the format up-front before making an + // unnecessary request + return this.tm.tx({ hash: txHash }) + }) } diff --git a/packages/nibijs/src/result.ts b/packages/nibijs/src/result.ts new file mode 100644 index 00000000..7f3f00b3 --- /dev/null +++ b/packages/nibijs/src/result.ts @@ -0,0 +1,76 @@ +/** Poor-man's Result type from Rust. + * + * The Result type forces you to explicitly handle errors in contrast to allowing + * errors to propagate up the call stack implicitly. Handling potential errors + * explicitly leads to more robust and reliable code. + * + * Ref: Propagating Errors - Rust Book. + * + * @example + * // --------------------------------------- + * // Most common use-case: Result.ofSafeExec + * // --------------------------------------- + * res = Result.ofSafeExec(somethingDangerous) // without args + * + * // with args + * res = Result.ofSafeExec(() => somethingDangerous(arg0, arg1)) + * + * @example + * // --------------------------------------- + * // Direct constructor + * // --------------------------------------- + * let res = new Result({ ok: "Operation successful!" }) + * if (res.isOk()) { + * happyPath(res.ok) + * } else { + * handleGracefully(res.err!) // throws impossible based on constructor args + * } + * + * */ +export class Result { + ok: T | undefined + err: Error | undefined + constructor({ ok, err }: { ok?: T; err?: unknown }) { + this.ok = ok + this.err = err ? parseError(err) : undefined + + if (Boolean(this.ok) && Boolean(this.err)) { + throw new Error( + "ResultError: ok and error states must not be defined simultaneously" + ) + } + } + + isErr = (): boolean => this.err !== undefined + isOk = (): boolean => !this.isErr() + + /** Constructor for "Result" using the return value of the input function. */ + static ofSafeExec = (fn: (...args: any[]) => Y): Result => { + try { + return new Result({ ok: fn() }) + } catch (err) { + return new Result({ err }) + } + } + + /** Constructor for "Result" using the return value of the input async function. + * @example + * const result = Result.ofSafeExecAsync(async () => someAsyncFunc(args)) + * */ + static ofSafeExecAsync = async ( + fn: () => Promise + ): Promise> => { + try { + return new Result({ ok: await fn() }) + } catch (err) { + return new Result({ err }) + } + } +} + +/** parseError: Guarantees runtime strong error typing since this isn't + * guaranteed in JS by default. The error that comes out of a try-catch may not + * have type "Error" since it's perfectly valid to throw strings or `undefined`. + * */ +export const parseError = (err: any): Error => + err instanceof Error ? err : new Error(`${err}`) diff --git a/packages/nibijs/src/test/chain.test.ts b/packages/nibijs/src/test/chain.test.ts index a1eb8adc..8633078c 100644 --- a/packages/nibijs/src/test/chain.test.ts +++ b/packages/nibijs/src/test/chain.test.ts @@ -1,4 +1,3 @@ -import { SigningStargateClient } from "@cosmjs/stargate" import { Coin, coin } from "@cosmjs/proto-signing" import { assert, @@ -9,7 +8,6 @@ import { Devnet, fromSdkDec, fromSdkInt, - go, Testnet, isRestEndptLive, newCoinMapFromCoins, @@ -17,10 +15,11 @@ import { toSdkDec, } from "../chain" import { TEST_CHAIN } from "../testutil" +import { NibiruSigningClient } from "../tx/signingClient" describe("chain/chain", () => { test("testnet rpc", async () => { - const sgClient = await SigningStargateClient.connect(TEST_CHAIN.endptTm) + const sgClient = await NibiruSigningClient.connect(TEST_CHAIN.endptTm) const blockHeight = await sgClient.getHeight() expect(blockHeight).toBeDefined() expect(blockHeight).toBeGreaterThanOrEqual(0) @@ -69,7 +68,7 @@ describe("chain/chain", () => { test("queryChainIdWithRest", async () => { const chain = Devnet(2) const result = await queryChainIdWithRest(chain) - expect(result).toEqual(["nibiru-devnet-2", undefined]) + expect(result.ok).toEqual("nibiru-devnet-2") }) test("inactive chain validation cases", async () => { @@ -81,9 +80,8 @@ describe("chain/chain", () => { chainName: "inactive-chain", feeDenom: "unibi", } - const [chainId, err] = await queryChainIdWithRest(inactiveChain) - expect(err).toBeDefined() - expect(chainId).toEqual("") + const res = await queryChainIdWithRest(inactiveChain) + expect(res.isErr()).toBeDefined() await expect(isRestEndptLive(inactiveChain)).resolves.toBeFalsy() }) @@ -196,13 +194,6 @@ describe("chain/types", () => { expect(coins.unibi2.toString()).toBe("21519262") expect(coins["nibiru/pool/2"].toString()).toBe("16800456610195729831") }) - - test("go", async () => { - const error = Error("Failure") - const result = await go(Promise.reject(error)) - expect(result.err).toEqual(error.message) - expect(result.res).toBeUndefined() - }) }) test("custom assert fn", () => { diff --git a/packages/nibijs/src/test/query.test.ts b/packages/nibijs/src/test/query.test.ts index 13427ccc..1b05b364 100644 --- a/packages/nibijs/src/test/query.test.ts +++ b/packages/nibijs/src/test/query.test.ts @@ -6,8 +6,8 @@ import { NibiruQueryClient } from "../query" import { TEST_CHAIN, TEST_ADDRESS, - validateBlock, - validateBlockFromJsonRpc, + assertValidBlock, + assertValidBlockFromJsonRpc, TEST_MNEMONIC, assertExpectedError, } from "../testutil" @@ -22,7 +22,7 @@ describe("connections", () => { test("query command is able to fetch latest block", async () => { const queryClient = await NibiruQueryClient.connect(TEST_CHAIN.endptTm) const blockResp: Block = await queryClient.getBlock() - validateBlock(blockResp, TEST_CHAIN) + assertValidBlock(blockResp, TEST_CHAIN) }) test("tendermint rpc url returns block with GET", async () => { @@ -30,7 +30,7 @@ describe("connections", () => { const respJson = (await resp.json()) as BlockResp expect(respJson.result, `respJson: ${respJson}`).toHaveProperty("block") const blockJson = respJson.result.block - validateBlockFromJsonRpc(blockJson) + assertValidBlockFromJsonRpc(blockJson) }) }) diff --git a/packages/nibijs/src/testutil.ts b/packages/nibijs/src/testutil.ts index 642a519e..c6266b5f 100644 --- a/packages/nibijs/src/testutil.ts +++ b/packages/nibijs/src/testutil.ts @@ -1,5 +1,6 @@ import { Block } from "@cosmjs/stargate" import { Chain, Localnet } from "./chain" +import { parseError } from "./result" import { ABCIEvent } from "./tx" /** TEST_CHAIN: Alias for Localnet. @@ -22,7 +23,7 @@ export const ERR = { } /** Validates that block queried via the JSON RPC client has the expected fields. */ -export function validateBlockFromJsonRpc(blockJson: any) { +export function assertValidBlockFromJsonRpc(blockJson: any) { const blockSchema = { header: ["version", "chain_id", "height", "last_block_id"].concat( ["last_commit_hash", "data_hash", "validators_hash"], @@ -44,14 +45,21 @@ export function validateBlockFromJsonRpc(blockJson: any) { } } -/** valideBlock: Performs runtime type validation on a CometBFT "Block". */ -export function validateBlock(block: Block, chain: Chain) { +/** assertValidBlock: Performs runtime type validation on a CometBFT "Block". */ +export function assertValidBlock(block: Block, chain: Chain) { expect(block.header.chainId).toEqual(chain.chainId) expect(block.header.time).toBeDefined() expect(block.header.height).toBeGreaterThanOrEqual(1) expect(block).toHaveProperty("txs") } +/** + * Asserts that a list of ABCIEvents contains a specific type of `TxMsg`. This + * `TxMsg` type is read from a "message" event's "action" attribute. + * + * @param {string} msgType - TxMsg type to look for within the event attributes. + * @param {ABCIEvent[]} events - set of events over which we're searching. + */ export function assertHasMsgType(msgType: string, events: ABCIEvent[]): void { events.forEach((event) => { if (event.type === "message") { @@ -63,6 +71,14 @@ export function assertHasMsgType(msgType: string, events: ABCIEvent[]): void { }) } +/** + * Asserts that an array of ABCIEvent objects contains an event with a specified + * type. This runs a test expectation that the specified `eventType` is + * contained in `events`. + * + * @param {string} eventType - The event type to look for in the array of events. + * @param {ABCIEvent[]} events - An array of ABCIEvent objects to be tested. + */ export function assertHasEventType( eventType: string, events: ABCIEvent[] @@ -71,15 +87,19 @@ export function assertHasEventType( expect(eventTypes).toContain(eventType) } +/** + * Asserts that the given error matches one of the expected error messages. + * + * This function parses the error object to extract its message and checks if + * it includes any of the specified acceptable error messages. It sets a test + * expectation that the error message is contained within the list of acceptable errors. + * + * @param {unknown} err - The error object to be tested. + * @param {string[]} okErrors - An array of acceptable error message strings. + */ export const assertExpectedError = (err: unknown, okErrors: string[]) => { - let errMsg: string - if (err instanceof Error) { - errMsg = err.message - } else { - errMsg = `${err}` - } - console.log(errMsg) let isContained = false + const errMsg = parseError(err).message okErrors.forEach((e) => { if (errMsg.includes(e)) { isContained = true diff --git a/packages/nibijs/src/tx/signingClient.test.ts b/packages/nibijs/src/tx/signingClient.test.ts index ccdbeb28..eace2333 100644 --- a/packages/nibijs/src/tx/signingClient.test.ts +++ b/packages/nibijs/src/tx/signingClient.test.ts @@ -52,6 +52,10 @@ describe("nibid tx bank send", () => { 400000 ) assertIsDeliverTxSuccess(resp) + + const querier = await NibiruQueryClient.connect(TEST_CHAIN.endptTm) + const txQuery = await querier.getTxByHash(resp.transactionHash) + expect(txQuery.isOk()).toBeTruthy() }) })