Skip to content

Commit

Permalink
feat: adapted to viem
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMartinezRodriguez committed Mar 18, 2024
1 parent 7468416 commit bf66c6e
Show file tree
Hide file tree
Showing 7 changed files with 3,556 additions and 53 deletions.
13 changes: 9 additions & 4 deletions packages/config/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Config

A TypeScript library designed to provide straightforward access to the Stability Testnet and Global Trust Network configurations. This package simplifies the process of integrating blockchain network configurations into your projects, offering details like network IDs, names, native currencies, RPC URLs, and smart contract addresses.
A TypeScript library designed to provide straightforward access to the Stability Testnet and Global Trust Network configurations. This package simplifies the process of integrating blockchain network configurations into your projects, offering details like network IDs, names, native currencies, RPC URLs, and smart contract addresses. Additionally, the configuration is structured to be directly usable as a network config in viem, enhancing its compatibility and ease of use.

## EXAMPLE

```ts
import { publicProvider } from "wagmi/providers/public";
import { configureChains, createConfig } from "wagmi";
import { Blockchains, networks } from "@stabilityprotocol/config";

console.log(
"Global Trust Network Chain Id:",
networks[Blockchains.STABILITY_GTN].id
const { chains, publicClient } = configureChains(
[
networks[Blockchains.STABILITY_TESTNET],
networks[Blockchains.STABILITY_GTN],
],
[publicProvider()]
);
```

Expand Down
17 changes: 11 additions & 6 deletions packages/config/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,42 @@ describe("Blockchain Enums and Objects", () => {
const testnetConfig = networks[Blockchains.STABILITY_TESTNET];
expect(testnetConfig.id).toEqual(20180427);
expect(testnetConfig.name).toEqual("Stability Testnet");
expect(testnetConfig.network).toEqual(Blockchains.STABILITY_TESTNET);
expect(testnetConfig.network).toEqual("stability-testnet");
expect(testnetConfig.nativeCurrency.decimals).toEqual(18);
expect(testnetConfig.nativeCurrency.name).toEqual(
"Decentralized Native Token"
);
expect(testnetConfig.nativeCurrency.symbol).toEqual("DNT");
expect(testnetConfig.rpcUrl).toEqual(
expect(testnetConfig.rpcUrls.default.http[0]).toEqual(
"https://free.testnet.stabilityprotocol.com"
);
expect(testnetConfig.blockExplorer).toEqual(
expect(testnetConfig.blockExplorers.default.url).toEqual(
"https://stability-testnet.blockscout.com/"
);
expect(testnetConfig.contracts.multicall3.address).toEqual(
"0x3ed62137c5DB927cb137c26455969116BF0c23Cb"
);
expect(testnetConfig.contracts.multicall3.blockCreated).toEqual(2318);
});

it("should have correct network configurations for STABILITY_GTN", () => {
const gtnConfig = networks[Blockchains.STABILITY_GTN];
expect(gtnConfig.id).toEqual(101010);
expect(gtnConfig.name).toEqual("Global Trust Network");
expect(gtnConfig.network).toEqual(Blockchains.STABILITY_GTN);
expect(gtnConfig.network).toEqual("stability-gtn");
expect(gtnConfig.nativeCurrency.decimals).toEqual(18);
expect(gtnConfig.nativeCurrency.name).toEqual("Decentralized Native Token");
expect(gtnConfig.nativeCurrency.symbol).toEqual("DNT");
expect(gtnConfig.rpcUrl).toEqual("https://gtn.stabilityprotocol.com");
expect(gtnConfig.blockExplorer).toEqual(
expect(gtnConfig.rpcUrls.default.http[0]).toEqual(
"https://gtn.stabilityprotocol.com"
);
expect(gtnConfig.blockExplorers.default.url).toEqual(
"https://stability-testnet.blockscout.com/"
);
expect(gtnConfig.contracts.multicall3.address).toEqual(
"0xBA2923DAe45aD6b8B77bff4733c75b0C13F0ce2d"
);
expect(gtnConfig.contracts.multicall3.blockCreated).toEqual(453);
expect(gtnConfig.logoUri).toEqual("/img/chain-icons/stability-logo.png");
});
});
6 changes: 6 additions & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@
"publishConfig": {
"access": "public",
"registry": "https://npm.pkg.github.com"
},
"dependencies": {
"@wagmi/connectors": "^4.1.18",
"@wagmi/core": "^2.6.9",
"viem": "^2.8.11",
"wagmi": "1.4.4"
}
}
53 changes: 42 additions & 11 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
import { defineChain, Address } from "viem";

export enum Blockchains {
STABILITY_TESTNET = "stabilitytestnet",
STABILITY_GTN = "stabilitygtn",
}

export const networks = {
[Blockchains.STABILITY_TESTNET]: {
[Blockchains.STABILITY_TESTNET]: defineChain({
id: 20180427,
name: "Stability Testnet",
network: Blockchains.STABILITY_TESTNET,
network: "stability-testnet",
key: "stabilityTestnet",
nativeCurrency: {
decimals: 18,
name: "Decentralized Native Token",
symbol: "DNT",
},
rpcUrl: "https://free.testnet.stabilityprotocol.com",
blockExplorer: "https://stability-testnet.blockscout.com/",
rpcUrls: {
default: {
http: ["https://free.testnet.stabilityprotocol.com"],
},
public: {
http: ["https://free.testnet.stabilityprotocol.com"],
},
},
blockExplorers: {
default: {
name: "Stability Testnet",
url: "https://stability-testnet.blockscout.com/",
},
},
contracts: {
multicall3: {
address: "0x3ed62137c5DB927cb137c26455969116BF0c23Cb",
address: "0x3ed62137c5DB927cb137c26455969116BF0c23Cb" as Address,
blockCreated: 2318,
},
},
},
[Blockchains.STABILITY_GTN]: {
}),
[Blockchains.STABILITY_GTN]: defineChain({
id: 101010,
name: "Global Trust Network",
network: Blockchains.STABILITY_GTN,
network: "stability-gtn",
key: "stabilityGtn",
nativeCurrency: {
decimals: 18,
name: "Decentralized Native Token",
symbol: "DNT",
},
rpcUrl: "https://gtn.stabilityprotocol.com",
blockExplorer: "https://stability-testnet.blockscout.com/",
rpcUrls: {
default: {
http: ["https://gtn.stabilityprotocol.com"],
},
public: {
http: ["https://gtn.stabilityprotocol.com"],
},
},
blockExplorers: {
default: {
name: "Stability GTN",
url: "https://stability-testnet.blockscout.com/",
},
},
contracts: {
multicall3: {
address: "0xBA2923DAe45aD6b8B77bff4733c75b0C13F0ce2d",
blockCreated: 453,
},
},
},
logoUri: "/img/chain-icons/stability-logo.png",
}),
};
6 changes: 4 additions & 2 deletions packages/provider/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("StabilityGtnRpcProvider", () => {
const provider = new StabilityGtnRpcProvider(apiKey);

expect(provider.connection.url).toBe(
`${networks.stabilitygtn.rpcUrl}/${apiKey}`
`${networks.stabilitygtn.rpcUrls.default.http[0]}/${apiKey}`
);
});

Expand All @@ -27,7 +27,9 @@ describe("StabilityTestnetRpcProvider", () => {
it("correctly configures the provider instance for the Stability Testnet (STABILITY_TESTNET) with the correct RPC URL", () => {
const provider = new StabilityTestnetRpcProvider();

expect(provider.connection.url).toBe(networks.stabilitytestnet.rpcUrl);
expect(provider.connection.url).toBe(
networks.stabilitytestnet.rpcUrls.default.http[0]
);
});

it("correctly configures the provider instance for the Stability Testnet (STABILITY_TESTNET) with the correct CHAIN ID", () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Blockchains, networks } from "@stabilityprotocol/config";

export class StabilityGtnRpcProvider extends ethers.providers.JsonRpcProvider {
constructor(apiKey: string) {
const url = `${networks[Blockchains.STABILITY_GTN].rpcUrl}/${apiKey}`;
const url = `${
networks[Blockchains.STABILITY_GTN].rpcUrls.default.http[0]
}/${apiKey}`;
super(url, networks[Blockchains.STABILITY_GTN].id);
}
}
Expand All @@ -12,7 +14,7 @@ export class StabilityTestnetRpcProvider extends ethers.providers
.JsonRpcProvider {
constructor() {
super(
networks[Blockchains.STABILITY_TESTNET].rpcUrl,
networks[Blockchains.STABILITY_TESTNET].rpcUrls.default.http[0],
networks[Blockchains.STABILITY_TESTNET].id
);
}
Expand Down
Loading

0 comments on commit bf66c6e

Please sign in to comment.