Skip to content

Commit

Permalink
feat(abiFetcher): add support for bsc and gnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
KABBOUCHI committed Feb 18, 2023
1 parent 2e5dad3 commit 45a9be5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@instadapp/utils",
"version": "0.4.5",
"version": "0.4.6",
"description": "",
"repository": "instadapp/utils",
"license": "MIT",
Expand Down
16 changes: 10 additions & 6 deletions src/abi/fetcher/AbiFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ const DEFAULTS: IAbiFetcherOptions = {
avalanche: 'https://rpc.ankr.com/avalanche',
optimism: 'https://rpc.ankr.com/optimism',
arbitrum: 'https://rpc.ankr.com/arbitrum',
fantom: 'https://rpc.ankr.com/fantom'
fantom: 'https://rpc.ankr.com/fantom',
bsc: 'https://rpc.ankr.com/bsc',
gnosis: 'https://rpc.ankr.com/gnosis'
},
networkToEtherscanAPI: {
polygon: 'https://api.polygonscan.com/api',
mainnet: 'https://api.etherscan.io/api',
avalanche: 'https://api.snowtrace.io/api',
optimism: 'https://api-optimistic.etherscan.io/api',
arbitrum: 'https://api.arbiscan.io/api',
fantom: 'https://api.ftmscan.com/api'
fantom: 'https://api.ftmscan.com/api',
bsc: 'https://api.bscscan.com/api',
gnosis: 'https://api.gnosisscan.io/api'
}
}

Expand Down Expand Up @@ -107,7 +111,7 @@ export class AbiFetcher {
if (originalAbi.some(item => item.type === 'function' && item.name === 'implementation')) {
// EIP-897 DelegateProxy
if (originalAbi.some(item => item.type === 'function' && item.name === 'proxyType')) {
const contract = new Contract(contractAddress, originalAbi, provider)
const contract = new Contract(contractAddress, originalAbi, provider as any)
implementationAddress = await contract.implementation()
} else { // EIP-1967: Standard Proxy Storage Slots
for (const implementationStorageLocation of implementationStorageLocations) {
Expand Down Expand Up @@ -135,19 +139,19 @@ export class AbiFetcher {
return originalAbi
}
} else if (originalAbi.some(item => item.type === 'function' && item.name === 'getDummyImplementation')) {
const contract = new Contract(contractAddress, originalAbi, provider)
const contract = new Contract(contractAddress, originalAbi, provider as any)

implementationAddress = await contract.getDummyImplementation()
implementationAbi = await this._get(implementationAddress, network, metadata)
return proxyFetchMode === 'implementationOnly' ? implementationAbi : [...originalAbi, ...implementationAbi]
} else if (originalAbi.some(item => item.type === 'function' && item.name === 'implementations')) {
const contract = new Contract(contractAddress, originalAbi, provider)
const contract = new Contract(contractAddress, originalAbi, provider as any)

implementationAddress = await contract.implementations()
implementationAbi = await this._get(implementationAddress, network, metadata)
return proxyFetchMode === 'implementationOnly' ? implementationAbi : [...originalAbi, ...implementationAbi]
} else if (originalAbi.some(item => item.type === 'function' && item.name === 'comptrollerImplementation')) {
const contract = new Contract(contractAddress, originalAbi, provider)
const contract = new Contract(contractAddress, originalAbi, provider as any)

implementationAddress = await contract.comptrollerImplementation()
implementationAbi = await this._get(implementationAddress, network, metadata)
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type Network = 'polygon' | 'mainnet' | 'fantom' | 'arbitrum' | 'avalanche' | 'optimism';
export type Network = 'polygon' | 'mainnet' | 'fantom' | 'arbitrum' | 'avalanche' | 'optimism' | 'bsc' | 'gnosis' | string;

0 comments on commit 45a9be5

Please sign in to comment.