Skip to content

Commit

Permalink
refactor: custom chain for mainnet (#262)
Browse files Browse the repository at this point in the history
* refactor: custom chain for mainnet

* test: increase open handle timeout

* test: adding --watchAll --no-cache
  • Loading branch information
CalicoNino authored Dec 12, 2023
1 parent 4c38b2d commit ffc2060
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"clean": "lerna run --parallel clean",
"commit": "cz",
"publish:all": "lerna publish from-package",
"test": "jest --verbose --detectOpenHandles",
"test": "jest --verbose --detectOpenHandles --watchAll --no-cache",
"lint": "eslint -c './.eslintrc.js' './packages/**/*.{ts,js}'",
"lint:ci": "yarn lint . --format junit",
"lint:md": "markdownlint --ignore node_modules --ignore .git",
Expand Down
4 changes: 2 additions & 2 deletions packages/nibijs/docs/classes/StableSwap.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ 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 + b\*x_1 = c
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)

Expand Down
16 changes: 11 additions & 5 deletions packages/nibijs/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export interface Chain {
}

export interface ChainIdParts {
prefix: string // e.g. `nibiru`
prefix?: string // e.g. `nibiru`
shortName: string // e.g. `itn`
number: number // e.g. `1`
mainnet?: boolean
}

/** CustomChain is a convenience class for intializing the endpoints of a chain
Expand Down Expand Up @@ -57,9 +58,14 @@ export class CustomChain implements Chain {
this.chainIdParts = chainIdParts
this.chainId = this.initChainId()
this.chainName = this.chainId
this.endptTm = `https://rpc.${chainIdParts.shortName}-${chainIdParts.number}.nibiru.fi`
this.endptRest = `https://lcd.${chainIdParts.shortName}-${chainIdParts.number}.nibiru.fi`
this.endptGrpc = `grpc.${chainIdParts.shortName}-${chainIdParts.number}.nibiru.fi`

const chainEndpt = chainIdParts.mainnet
? ""
: `.${chainIdParts.shortName}-${chainIdParts.number}`

this.endptTm = `https://rpc${chainEndpt}.nibiru.fi`
this.endptRest = `https://lcd${chainEndpt}.nibiru.fi`
this.endptGrpc = `grpc${chainEndpt}.nibiru.fi`
}

public static fromChainId(chainId: string): Chain {
Expand All @@ -74,7 +80,7 @@ export class CustomChain implements Chain {

private initChainId = () => {
const { prefix, shortName, number } = this.chainIdParts
return [prefix, shortName, number].join("-")
return [prefix, shortName, number].filter(Boolean).join("-")
}
}

Expand Down
16 changes: 16 additions & 0 deletions packages/nibijs/src/test/chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe("chain/chain", () => {
expectCreatedChain(result, "devnet")
})

test("Mainnet", () => {
const shortName = "cataclysm"
const number = 1
const result = new CustomChain({
shortName,
number,
mainnet: true,
})
expect(result.chainId).toEqual(`${shortName}-${number}`)
expect(result.chainName).toEqual(`${shortName}-${number}`)
expect(result.endptGrpc).toEqual(`grpc.nibiru.fi`)
expect(result.endptRest).toEqual(`https://lcd.nibiru.fi`)
expect(result.endptTm).toEqual(`https://rpc.nibiru.fi`)
expect(result.feeDenom).toEqual(`unibi`)
})

test("queryChainIdWithRest", async () => {
const chain = Devnet(2)
const result = await queryChainIdWithRest(chain)
Expand Down

0 comments on commit ffc2060

Please sign in to comment.