Skip to content

Commit

Permalink
Support celo testnet (#868)
Browse files Browse the repository at this point in the history
* Support celo testnet

* Update chain name
  • Loading branch information
JayJay1024 authored Nov 6, 2024
1 parent e3e807f commit b870e3e
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/helixbox-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@apollo/client": "^3.10.3",
"@floating-ui/react": "^0.26.14",
"@helixbridge/helixconf": "1.1.18",
"@helixbridge/helixconf": "v1.2.0-beta",
"@reown/appkit": "^1.0.7",
"@reown/appkit-adapter-wagmi": "^1.0.7",
"@sentry/react": "^8.30.0",
Expand Down
Binary file added apps/helixbox-app/public/images/network/celo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions apps/helixbox-app/src/config/chains/celo-testnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { HelixChain } from "@helixbridge/helixconf";
import { BridgeV2Type, ChainConfig, Network } from "../../types";
import { Address } from "viem";
import { celoAlfajores } from "viem/chains";

const chain = HelixChain.celoTestnet;
const tokens = chain.tokens.map((token) => {
const couples = chain.filterCouples({ symbolFrom: token.symbol });
const category = couples.at(0)?.category ?? "Others";

const routes = new Set<string>();
for (const couple of couples) {
routes.add(`${couple.chain.code}:${couple.symbol.from}:${couple.symbol.to}`);
}

const cross = [...routes].map((route) => {
const [toChain, fromToken, toToken] = route.split(":");
const lnv2 = couples.find(
(c) =>
c.chain.code === toChain &&
c.symbol.from === fromToken &&
c.symbol.to === toToken &&
(c.protocol.name === "lnv2-default" || c.protocol.name === "lnv2-opposite"),
);
return {
target: { network: toChain as Network, symbol: toToken },
bridge: {
category: "lnbridge" as const,
lnv2Type: (lnv2?.protocol.name === "lnv2-opposite" ? "opposite" : "default") as BridgeV2Type,
disableV2: !lnv2,
},
};
});
return { ...token, name: token.symbol, address: token.address as Address, category, cross };
});

if (chain.couples.length && !chain.tokens.some((t) => t.type === "native")) {
tokens.push({
...celoAlfajores.nativeCurrency,
logo: "https://raw.githubusercontent.com/helix-bridge/helix-ui/main/packages/assets/images/tokens/eth.png",
address: "0x0000000000000000000000000000000000000000",
category: "ETH",
type: "native",
cross: [],
alias: [],
});
}

export const celoTestChain: ChainConfig = {
/**
* Chain
*/
...celoAlfajores,
network: "celo-testnet",
name: "Celo Alfajores",

/**
* Custom
*/
logo: "celo.png",
tokens,
};
1 change: 1 addition & 0 deletions apps/helixbox-app/src/config/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export * from "./zircuit";
export * from "./zircuit-sepolia";
export * from "./morph-testnet";
export * from "./morph";
export * from "./celo-testnet";
4 changes: 3 additions & 1 deletion apps/helixbox-app/src/types/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum ChainID {
AVALANCHE = 43_114,
ZIRCUIT = 48900,
ZIRCUIT_SEPOLIA = 48899,
CELO_TESTNET = 44787,
}

// According to graphql indexer
Expand Down Expand Up @@ -65,7 +66,8 @@ export type Network =
| "avalanche"
| "zircuit"
| "zircuit-sepolia"
| "bsc";
| "bsc"
| "celo-testnet";

export interface ChainConfig extends Chain {
/**
Expand Down
5 changes: 5 additions & 0 deletions apps/helixbox-app/src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
zircuitSepoliaChain,
zksyncChain,
zksyncSepoliaChain,
celoTestChain,
} from "../config/chains";
import { ChainConfig, ChainID, Network } from "../types";
import { isMainnet } from "./env";
Expand Down Expand Up @@ -113,6 +114,9 @@ export function getChainConfig(chainIdOrNetwork?: ChainID | Network | null): Cha
case ChainID.ZIRCUIT_SEPOLIA:
case "zircuit-sepolia":
return zircuitSepoliaChain;
case ChainID.CELO_TESTNET:
case "celo-testnet":
return celoTestChain;
default:
return;
}
Expand Down Expand Up @@ -147,6 +151,7 @@ export function getChainConfigs(askAll?: boolean) {
avalancheChain,
zircuitChain,
zircuitSepoliaChain,
celoTestChain,
].sort((a, b) => a.name.localeCompare(b.name));

if (askAll) {
Expand Down
Binary file added packages/assets/images/chains/celo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 21 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b870e3e

Please sign in to comment.