-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(smart-contracts): publish to tenderly (#1048)
- Loading branch information
1 parent
4d414a3
commit 27aaa1f
Showing
15 changed files
with
178 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const chainId = '000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943'; | ||
export const testnet = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const chainId = 421611; | ||
export const testnet = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const chainId = 80001; | ||
export const testnet = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const chainId = 'testnet'; | ||
export const testnet = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { HardhatRuntimeEnvironmentExtended } from './types'; | ||
import * as artifacts from '../src/lib/artifacts'; | ||
import { ContractArtifact } from '../src/lib'; | ||
import { Contract } from 'ethers'; | ||
import * as console from 'console'; | ||
import axios from 'axios'; | ||
import { EvmChains } from '@requestnetwork/currency'; | ||
import { CurrencyTypes } from '@requestnetwork/types'; | ||
|
||
const getTenderlyAxiosInstance = (hre: HardhatRuntimeEnvironmentExtended) => { | ||
return axios.create({ | ||
baseURL: 'https://api.tenderly.co', | ||
headers: { | ||
'X-Access-Key': hre.config.tenderly.accessKey, | ||
}, | ||
}); | ||
}; | ||
|
||
const capitalizeFirstLetter = (string: string) => string.charAt(0).toUpperCase() + string.slice(1); | ||
|
||
/** | ||
* Chains supported by Tenderly. | ||
* Supported testnet chains are commented out. | ||
*/ | ||
const supportedTenderlyChains: CurrencyTypes.EvmChainName[] = [ | ||
'arbitrum-one', | ||
'arbitrum-rinkeby', | ||
'avalanche', | ||
'bsc', | ||
'fantom', | ||
'goerli', | ||
'mainnet', | ||
'matic', | ||
'moonbeam', | ||
'mumbai', | ||
'optimism', | ||
'rinkeby', | ||
'xdai', | ||
]; | ||
|
||
type TenderlyContract = { address: string; chainId: number }; | ||
|
||
const getTenderlyContractId = (c: TenderlyContract) => | ||
`eth:${c.chainId}:${c.address.toLowerCase()}`; | ||
|
||
export const tenderlyImportAll = async (hre: HardhatRuntimeEnvironmentExtended): Promise<void> => { | ||
try { | ||
const { username, project } = hre.config.tenderly; | ||
const contracts: Record<string, { name: string } & TenderlyContract> = {}; | ||
const mainnetContracts: Set<string> = new Set(); | ||
const testnetContracts: Set<string> = new Set(); | ||
const versions: Record<string, Set<string>> = {}; | ||
for (const artifactName in artifacts) { | ||
const artifact = (artifacts as any)[artifactName] as ContractArtifact<Contract>; | ||
const deployments = artifact.getAllAddressesFromAllNetworks(); | ||
for (const deployment of deployments) { | ||
const { networkName, address, version } = deployment; | ||
if (!supportedTenderlyChains.includes(networkName)) continue; | ||
const chainId = EvmChains.getChainId(networkName); | ||
const contract: TenderlyContract = { | ||
address, | ||
chainId, | ||
}; | ||
const contractId = getTenderlyContractId(contract); | ||
contracts[contractId] = { | ||
name: capitalizeFirstLetter(artifactName.replace(/Artifact/i, '')), | ||
...contract, | ||
}; | ||
versions[version] ??= new Set(); | ||
versions[version].add(contractId); | ||
(EvmChains.isTestnet(networkName) ? testnetContracts : mainnetContracts).add(contractId); | ||
} | ||
} | ||
console.log(`> Retrieved ${Object.keys(contracts).length} contracts from protocol artifacts`); | ||
|
||
console.log(`> Syncing contracts with Tenderly...`); | ||
const axiosInstance = getTenderlyAxiosInstance(hre); | ||
await axiosInstance.post(`/api/v2/accounts/${username}/projects/${project}/contracts`, { | ||
contracts: Object.values(contracts).map((contract) => ({ | ||
address: contract.address, | ||
display_name: contract.name, | ||
network_id: contract.chainId.toString(), | ||
})), | ||
}); | ||
console.log(' ✔ done'); | ||
|
||
console.log(`> Adding version tags to contracts...`); | ||
for (const version in versions) { | ||
await axiosInstance.post(`/api/v1/account/${username}/project/${project}/tag`, { | ||
contract_ids: Array.from(versions[version]), | ||
tag: `v${version}`, | ||
}); | ||
} | ||
console.log(' ✔ done'); | ||
|
||
console.log(`> Adding mainnet/testnet tags to contracts...`); | ||
await axiosInstance.post(`/api/v1/account/${username}/project/${project}/tag`, { | ||
contract_ids: Array.from(mainnetContracts), | ||
tag: 'mainnet', | ||
}); | ||
await axiosInstance.post(`/api/v1/account/${username}/project/${project}/tag`, { | ||
contract_ids: Array.from(testnetContracts), | ||
tag: 'testnet', | ||
}); | ||
console.log(' ✔ done'); | ||
} catch (err) { | ||
console.error('Error while adding contract(s) to Tenderly', err.response?.data || err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters