Skip to content

Commit

Permalink
Add fraxtal
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Mar 27, 2024
1 parent b24287a commit 21e2af7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@openzeppelin/contracts": "^4.9.3",
"async-lock": "^1.4.0",
"axios": "^1.5.0",
"blockchain-addressbook": "^0.46.7",
"blockchain-addressbook": "^0.46.56",
"dotenv": "^16.3.1",
"lodash": "^4.17.21",
"pg": "^8.11.3",
Expand Down
14 changes: 7 additions & 7 deletions src/lib/addressbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import { Chain } from './chain';
import { Hex } from 'viem';

export function getChainWNativeTokenDecimals(chain: Chain): number {
if (chain === 'linea') {
if (chain === 'fraxtal') {
return 18;
}
const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.decimals;
}

export function getChainWNativeTokenSymbol(chain: Chain): string {
if (chain === 'linea') {
return 'ETH';
if (chain === 'fraxtal') {
return 'frxETH';
}
const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.symbol;
}

export function getChainWNativeTokenAddress(chain: Chain): Hex {
if (chain === 'linea') {
return '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f';
if (chain === 'fraxtal') {
return '0xFC00000000000000000000000000000000000006';
}
const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.address as Hex;
}

export function getNetworkId(chain: Chain): number {
if (chain === 'linea') {
return 59144;
if (chain === 'fraxtal') {
return 252;
}
const tokens = addressbook.addressBook[chain].tokens;
return tokens.WNATIVE.chainId;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addressBook } from 'blockchain-addressbook';

export type Chain = keyof typeof addressBook | 'linea';
export type Chain = keyof typeof addressBook | 'fraxtal';

export const allChainIds: Chain[] = [...Object.keys(addressBook), 'linea'] as Chain[];
export const allChainIds: Chain[] = [...Object.keys(addressBook), 'fraxtal'] as Chain[];
26 changes: 26 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,25 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
},
},
},
fraxtal: {
...defaultConfig,
url: RPC_FORCE_URL || process.env.FRAXTAL_RPC_URL || 'https://rpc.frax.com',
transaction: {
...defaultTransactionConfig,
type: 'legacy',
maxNativePerTransactionWei: bigintMultiplyFloat(ONE_ETHER, 0.002),
maxGasPricePerTransactionWei: null,
receipt: {
...defaultTransactionConfig.receipt,
notFoundErrorRetryCount: 5, // more retries
},
},
unwrap: {
...defaultUnwrapConfig,
minAmountOfWNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.005),
maxAmountOfNativeWei: bigintMultiplyFloat(ONE_ETHER, 0.005),
},
},
fuse: {
...defaultConfig,
url: RPC_FORCE_URL || process.env.FUSE_RPC_URL || 'https://rpc.fuse.io',
Expand Down Expand Up @@ -767,6 +786,13 @@ export const EXPLORER_CONFIG: Record<Chain, ExplorerConfig> = {
apiKey: process.env.FANTOM_EXPLORER_API_KEY || '',
type: 'etherscan',
},
fraxtal: {
addressLinkTemplate: 'https://fraxscan.com/address/${address}',
transactionLinkTemplate: 'https://fraxscan.com/tx/${hash}',
apiUrl: process.env.FRAXTAL_EXPLORER_API_URL || 'https://fraxscan.com/api',
apiKey: process.env.FRAXTAL_EXPLORER_API_KEY || '',
type: 'etherscan',
},
fuse: {
addressLinkTemplate: 'https://explorer.fuse.io/address/${address}',
transactionLinkTemplate: 'https://explorer.fuse.io/tx/${hash}',
Expand Down
38 changes: 32 additions & 6 deletions src/lib/rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ import { createCustomHarvestWalletActions } from './harvest-actions';
import { cachedFactory } from '../util/cache';
import { createCustomRpcPublicActions, createCustomRpcWalletActions } from './rpc-actions';

const fraxtal = {
id: 252,
name: 'Fraxtal',
network: 'fraxtal',
nativeCurrency: {
decimals: 18,
name: 'frxETH',
symbol: 'frxETH',
},
rpcUrls: {
// we will use our own http transport anyway
public: { http: [] },
default: { http: [] },
},
blockExplorers: {
default: { name: 'Fraxtal Explorer', url: 'https://fraxscan.com/' },
},
contracts: {
multicall3: {
address: '0xcA11bde05977b3631167028862bE2a173976CA11',
blockCreated: 1,
},
},
} as const satisfies ViemChain;

const fuse = {
id: addressBook.fuse.tokens.FUSE.chainId,
name: 'Fuse',
Expand Down Expand Up @@ -104,21 +129,22 @@ const VIEM_CHAINS: Record<Chain, ViemChain | null> = {
canto: applyConfig('canto', canto),
celo: applyConfig('celo', celo),
cronos: applyConfig('cronos', cronos),
fantom: applyConfig('fantom', fantom),
ethereum: applyConfig('ethereum', mainnet),
emerald: null,
one: applyConfig('one', harmonyOne),
heco: null,
ethereum: applyConfig('ethereum', mainnet),
fantom: applyConfig('fantom', fantom),
fraxtal: applyConfig('fraxtal', fraxtal),
fuse: applyConfig('fuse', fuse),
gnosis: applyConfig('gnosis', gnosis),
heco: null,
kava: applyConfig('kava', kava),
linea: applyConfig('linea', linea),
polygon: applyConfig('polygon', polygon),
mantle: applyConfig('mantle', mantle),
metis: applyConfig('metis', metis),
moonbeam: applyConfig('moonbeam', moonbeam),
moonriver: applyConfig('moonriver', moonriver),
metis: applyConfig('metis', metis),
one: applyConfig('one', harmonyOne),
optimism: applyConfig('optimism', optimism),
polygon: applyConfig('polygon', polygon),
zkevm: applyConfig('zkevm', polygonZkEvm),
zksync: applyConfig('zksync', zkSync),
};
Expand Down

0 comments on commit 21e2af7

Please sign in to comment.