Skip to content

Commit 8753b17

Browse files
bardboudra
andauthored
feat: add avalanche support (#303)
* feat: partial avalanche support * chore: upgrade chainsauce for improved RPC fetching * fix: change Avalanche RPC to one with more relaxed limits * feat: add avalanche fuji * chore: revert chainsauce upgrade --------- Co-authored-by: Mohamed Boudra <[email protected]>
1 parent ddee1b6 commit 8753b17

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PGN_TESTNET_RPC_URL=https://sepolia.publicgoods.network
77
PGN_RPC_URL=https://rpc.publicgoods.network
88
ARBITRUM_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/
99
ARBITRUM_GOERLI_RPC_URL=https://arb-goerli.g.alchemy.com/v2/
10+
AVALANCHE_RPC_URL=https://avalanche-c-chain.publicnode.com
11+
AVALANCHE_FUJI_RPC_URL=https://avalanche-fuji-c-chain.publicnode.com
1012
PASSPORT_SCORER_ID=
1113
COINGECKO_API_KEY=
1214
IPFS_GATEWAY=

src/config.ts

+87-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { z } from "zod";
66
import * as abis from "./indexer/abis/index.js";
77

88
type ChainId = number;
9-
type CoingeckoSupportedChainId = 1 | 10 | 250 | 42161;
9+
type CoingeckoSupportedChainId = 1 | 10 | 250 | 42161 | 43114;
1010

1111
export type Token = {
1212
code: string;
@@ -470,7 +470,7 @@ const CHAINS: Chain[] = [
470470
rpc: rpcUrl
471471
.default("https://rpc-mumbai.maticvigil.com/")
472472
.parse(process.env.POLYGON_MUMBAI_RPC_URL),
473-
pricesFromTimestamp: Date.UTC(2023, 9, 19, 0, 0, 0),
473+
pricesFromTimestamp: Date.UTC(2023, 8, 19, 0, 0, 0),
474474
tokens: [
475475
{
476476
code: "MATIC",
@@ -512,7 +512,7 @@ const CHAINS: Chain[] = [
512512
rpc: rpcUrl
513513
.default("https://polygon-rpc.com")
514514
.parse(process.env.POLYGON_RPC_URL),
515-
pricesFromTimestamp: Date.UTC(2023, 9, 19, 0, 0, 0),
515+
pricesFromTimestamp: Date.UTC(2023, 8, 19, 0, 0, 0),
516516
tokens: [
517517
{
518518
code: "MATIC",
@@ -548,6 +548,90 @@ const CHAINS: Chain[] = [
548548
},
549549
],
550550
},
551+
{
552+
id: 43114,
553+
name: "avalanche",
554+
rpc: rpcUrl
555+
.default("https://avalanche-c-chain.publicnode.com")
556+
.parse(process.env.AVALANCHE_RPC_URL),
557+
pricesFromTimestamp: Date.UTC(2023, 8, 19, 0, 0, 0),
558+
tokens: [
559+
{
560+
code: "AVAX",
561+
address: "0x0000000000000000000000000000000000000000",
562+
decimals: 18,
563+
priceSource: {
564+
chainId: 43114,
565+
address: "0x0000000000000000000000000000000000000000",
566+
},
567+
},
568+
{
569+
code: "USDC",
570+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
571+
decimals: 6,
572+
priceSource: {
573+
chainId: 1,
574+
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
575+
},
576+
},
577+
],
578+
subscriptions: [
579+
{
580+
address: "0xDF9BF58Aa1A1B73F0e214d79C652a7dd37a6074e",
581+
abi: abis.v2.ProjectRegistry,
582+
},
583+
{
584+
address: "0x8eC471f30cA797FD52F9D37A47Be2517a7BD6912",
585+
abi: abis.v2.RoundFactory,
586+
},
587+
{
588+
address: "0x2AFA4bE0f2468347A2F086c2167630fb1E58b725",
589+
abi: abis.v2.QuadraticFundingVotingStrategyFactory,
590+
},
591+
],
592+
},
593+
{
594+
id: 43113,
595+
name: "avalanche-fuji",
596+
rpc: rpcUrl
597+
.default("https://avalanche-fuji-c-chain.publicnode.com")
598+
.parse(process.env.AVALANCHE_FUJI_RPC_URL),
599+
pricesFromTimestamp: Date.UTC(2023, 8, 19, 0, 0, 0),
600+
tokens: [
601+
{
602+
code: "AVAX",
603+
address: "0x0000000000000000000000000000000000000000",
604+
decimals: 18,
605+
priceSource: {
606+
chainId: 43114,
607+
address: "0x0000000000000000000000000000000000000000",
608+
},
609+
},
610+
{
611+
code: "USDC",
612+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
613+
decimals: 6,
614+
priceSource: {
615+
chainId: 1,
616+
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
617+
},
618+
},
619+
],
620+
subscriptions: [
621+
{
622+
address: "0xDF9BF58Aa1A1B73F0e214d79C652a7dd37a6074e",
623+
abi: abis.v2.ProjectRegistry,
624+
},
625+
{
626+
address: "0x8eC471f30cA797FD52F9D37A47Be2517a7BD6912",
627+
abi: abis.v2.RoundFactory,
628+
},
629+
{
630+
address: "0x2AFA4bE0f2468347A2F086c2167630fb1E58b725",
631+
abi: abis.v2.QuadraticFundingVotingStrategyFactory,
632+
},
633+
],
634+
},
551635
];
552636

553637
export const getDecimalsForToken = (

src/prices/coinGecko.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const platforms: { [key: number]: string } = {
77
250: "fantom",
88
10: "optimistic-ethereum",
99
42161: "arbitrum-one",
10+
43114: "avalanche",
1011
};
1112

1213
const nativeTokens: { [key: number]: string } = {
1314
1: "ethereum",
1415
250: "fantom",
1516
10: "ethereum",
1617
42161: "ethereum",
18+
43114: "avalanche-2",
1719
};
1820

1921
type Timestamp = number;

0 commit comments

Comments
 (0)