diff --git a/packages/nibijs/docs/classes/StableSwap.md b/packages/nibijs/docs/classes/StableSwap.md index 6b526a38..a8ae01e9 100644 --- a/packages/nibijs/docs/classes/StableSwap.md +++ b/packages/nibijs/docs/classes/StableSwap.md @@ -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) diff --git a/packages/nibijs/src/chain/chain.ts b/packages/nibijs/src/chain/chain.ts index bed27c2d..6e063ecf 100644 --- a/packages/nibijs/src/chain/chain.ts +++ b/packages/nibijs/src/chain/chain.ts @@ -71,6 +71,16 @@ export class CustomChain implements Chain { this.endptGrpc = `grpc.${chainIdParts.shortName}-${chainIdParts.number}.nibiru.fi` } + public static fromChainId(chainId: string): Chain { + const parts = chainId.split("-") + const chainIdParts = { + prefix: parts[0], + shortName: parts[1], + number: Number(parts[2]), + } as ChainIdParts + return new CustomChain(chainIdParts) + } + private initChainId = () => { const { prefix, shortName, number } = this.chainIdParts return [prefix, shortName, number].join("-") diff --git a/packages/nibijs/src/test/chain.test.ts b/packages/nibijs/src/test/chain.test.ts index 7257a14b..400019e5 100644 --- a/packages/nibijs/src/test/chain.test.ts +++ b/packages/nibijs/src/test/chain.test.ts @@ -4,6 +4,7 @@ import { Chain, Coin, CoinMap, + CustomChain, isRestEndptLive, newCoin, newCoinMapFromCoins, @@ -18,6 +19,12 @@ describe("chain connections", () => { expect(blockHeight).toBeDefined() expect(blockHeight).toBeGreaterThanOrEqual(0) }) + + test("chain from chain-id", async () => { + const chain = CustomChain.fromChainId(TEST_CHAIN.chainId) + expect(chain.chainId).toEqual(TEST_CHAIN.chainId) + }) + test("inactive chain validation cases", async () => { const inactiveChain: Chain = { endptTm: "",