Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c108ad2
chore(smart-contracts): publish to tenderly
alexandre-abrioux Jan 16, 2023
89bb0ba
WIP
alexandre-abrioux Jan 31, 2023
53501d1
Merge branch 'master' into tenderly-contracts
alexandre-abrioux Jan 31, 2023
bd35879
yarn lockfile
alexandre-abrioux Jan 31, 2023
0d35b33
fix axios version
alexandre-abrioux Jan 31, 2023
b06bd1e
finish & test
alexandre-abrioux Jan 31, 2023
9fcffbc
wording
alexandre-abrioux Jan 31, 2023
222c30f
undo
alexandre-abrioux Jan 31, 2023
5fa415e
rename file
alexandre-abrioux Jan 31, 2023
dc410f6
WIP
alexandre-abrioux Jan 31, 2023
ed3b672
WIP
alexandre-abrioux Feb 3, 2023
924a70e
fixes
alexandre-abrioux Feb 3, 2023
4aee325
Merge branch 'master' into networks
alexandre-abrioux Feb 3, 2023
bae4830
fix ERC20 order
alexandre-abrioux Feb 3, 2023
e7ecfb9
fix indentation
alexandre-abrioux Feb 3, 2023
8771389
fix tests
alexandre-abrioux Feb 3, 2023
d48802d
rollback changes
alexandre-abrioux Feb 3, 2023
753fe99
fix tests
alexandre-abrioux Feb 3, 2023
5bc4f96
fix tests
alexandre-abrioux Feb 3, 2023
5363d3c
fix tests
alexandre-abrioux Feb 3, 2023
256b6df
fix tests
alexandre-abrioux Feb 3, 2023
21b92fc
rollback test
alexandre-abrioux Feb 3, 2023
7bd75c7
fix tests
alexandre-abrioux Feb 3, 2023
b2ed93b
Merge branch 'master' into networks
alexandre-abrioux Feb 7, 2023
d6ae451
remove aurora from evm
alexandre-abrioux Feb 7, 2023
c7b3112
remove unused export
alexandre-abrioux Feb 7, 2023
e52eb10
fix missing export
alexandre-abrioux Feb 7, 2023
a446daf
change chaindefinition type name
alexandre-abrioux Feb 7, 2023
f454936
edit README
alexandre-abrioux Feb 7, 2023
05ab7d5
refactor chain types to classes
alexandre-abrioux Feb 7, 2023
ddf73ac
fix test
alexandre-abrioux Feb 7, 2023
94cf0e8
remove unusued utils
alexandre-abrioux Feb 7, 2023
c3d01ad
fix some more types
alexandre-abrioux Feb 7, 2023
ead5d9b
fix some more types
alexandre-abrioux Feb 7, 2023
a9a3029
fix test types
alexandre-abrioux Feb 7, 2023
737aee6
fix test
alexandre-abrioux Feb 7, 2023
f44f683
fix near typing
alexandre-abrioux Feb 7, 2023
87c5cd0
fix currencyManager
alexandre-abrioux Feb 7, 2023
3d7c730
fix aggregators type
alexandre-abrioux Feb 7, 2023
2b1fd4f
fix aggregators type
alexandre-abrioux Feb 8, 2023
9baa2f8
fix chainlink test
alexandre-abrioux Feb 8, 2023
100f709
rollback currency manager change
alexandre-abrioux Feb 8, 2023
1c240b7
rollback addagregator change
alexandre-abrioux Feb 8, 2023
b5957a1
Merge branch 'networks' into tenderly-contracts
alexandre-abrioux Feb 8, 2023
8e4d4cd
use chain configuration
alexandre-abrioux Feb 8, 2023
729096e
fix ArtifactDeploymentInfo
alexandre-abrioux Feb 8, 2023
ad88345
Merge branch 'networks' into tenderly-contracts
alexandre-abrioux Feb 8, 2023
9e98eb8
rollback import line change
alexandre-abrioux Feb 8, 2023
cc4aa87
add testnet chain configuration
alexandre-abrioux Feb 8, 2023
ec78933
remove comment
alexandre-abrioux Feb 8, 2023
97b3438
fix type for ERC20Currency
alexandre-abrioux Feb 16, 2023
8f56b91
Merge branch 'master' into networks
alexandre-abrioux Feb 16, 2023
3452fd1
add README
alexandre-abrioux Feb 16, 2023
71f0809
Merge branch 'master' into networks
alexandre-abrioux Feb 22, 2023
9c014a9
Merge remote-tracking branch 'origin/master' into networks
alexandre-abrioux Mar 7, 2023
8d815f0
fix build
alexandre-abrioux Mar 7, 2023
51030c1
fix missing type
alexandre-abrioux Mar 7, 2023
0190ec2
Merge branch 'master' into networks
alexandre-abrioux Mar 7, 2023
0b99099
fix type errors
alexandre-abrioux Mar 7, 2023
66c75b8
Merge branch 'networks' into tenderly-contracts
alexandre-abrioux Mar 7, 2023
a551b40
Merge remote-tracking branch 'origin/master' into tenderly-contracts
alexandre-abrioux Mar 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/smart-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ The deployer contract should be deployed at `0xE99Ab70a5FAE59551544FA326fA048f7B

Be sure to run `yarn build:sol` before deploying the deployer or a contract.

The contracts implemented are listed in the array `create2ContractDeploymentList` in [Utils](./scripts-create2/utils.ts).
The contracts implemented are listed in the array `create2ContractDeploymentList` in [Utils](scripts-create2/utils/index.ts).

### Deploy the request deployer (once per chain)

Expand Down Expand Up @@ -166,6 +166,16 @@ See `hardhat.config.ts`.
yarn hardhat verify-contract-from-deployer --network <NETWORK>
```

### Add the contracts to Tenderly

Once the contract has been added to the artifacts (`./src/lib/artifacts`), run the following command to synchronize
contracts with the Tenderly account.
Environment variables needed: `TENDERLY_...` (see `hardhat.config.ts`).

```bash
yarn hardhat tenderly-monitor-contracts
```

#### Verify the contracts manually With Hardhat (legacy)

A more generic way to verify any contract by setting constructor argments manually:
Expand Down
12 changes: 12 additions & 0 deletions packages/smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { VerifyCreate2FromList } from './scripts-create2/verify';
import { deployWithCreate2FromList } from './scripts-create2/deploy';
import { NUMBER_ERRORS } from './scripts/utils';
import { networkRpcs } from '@requestnetwork/utils';
import { tenderlyImportAll } from './scripts-create2/tenderly';

config();

Expand Down Expand Up @@ -180,6 +181,11 @@ export default {
},
],
},
tenderly: {
project: process.env.TENDERLY_PROJECT,
username: process.env.TENDERLY_USERNAME,
accessKey: process.env.TENDERLY_ACCESS_KEY,
},
typechain: {
outDir: 'src/types',
target: 'ethers-v5',
Expand Down Expand Up @@ -267,6 +273,12 @@ task(
await VerifyCreate2FromList(hre as HardhatRuntimeEnvironmentExtended);
});

task('tenderly-monitor-contracts', 'Import all contracts to a Tenderly account').setAction(
async (_args, hre) => {
await tenderlyImportAll(hre as HardhatRuntimeEnvironmentExtended);
},
);

subtask(DEPLOYER_KEY_GUARD, 'prevent usage of the deployer master key').setAction(async () => {
if (accounts && accounts[0] === process.env.DEPLOYER_MASTER_KEY) {
throw new Error('The deployer master key should not be used for this action');
Expand Down
1 change: 1 addition & 0 deletions packages/smart-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@types/chai": "4.2.21",
"@types/mocha": "8.2.3",
"@types/node": "14.14.16",
"axios": "0.27.2",
"chai": "4.3.4",
"dotenv": "10.0.0",
"ethereum-waffle": "3.4.0",
Expand Down
51 changes: 51 additions & 0 deletions packages/smart-contracts/scripts-create2/tenderly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { HardhatRuntimeEnvironmentExtended } from './types';
import axios from 'axios';
import * as artifacts from '../src/lib/artifacts';
import { getChainConfig } from './utils/chains';
import { ContractArtifact } from '../src/lib';
import { Contract } from 'ethers';
import * as console from 'console';

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);

export const tenderlyImportAll = async (hre: HardhatRuntimeEnvironmentExtended): Promise<void> => {
const { username, project } = hre.config.tenderly;
try {
const contracts: Array<{ name: string; address: string; networkId: number }> = [];
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 } = deployment;
if (['private', 'rinkeby', 'bsctest', 'alfajores'].includes(networkName)) continue;
const chainConfig = await getChainConfig(networkName);
if (!chainConfig) continue;
const sanitizedArtifactName = artifactName.replace(/Artifact/i, '');
contracts.push({
name: `${capitalizeFirstLetter(sanitizedArtifactName)}-${deployment.version}`,
address: deployment.address,
networkId: chainConfig.chainId,
});
}
}
const axiosInstance = getTenderlyAxiosInstance(hre);
await axiosInstance.post(`/api/v2/accounts/${username}/projects/${project}/contracts`, {
contracts: contracts.map((contract) => ({
address: contract.address,
display_name: contract.name,
network_id: contract.networkId.toString(),
})),
});
} catch (err) {
console.error('Error while adding contract(s) to Tenderly', err.response?.data || err);
}
};
5 changes: 5 additions & 0 deletions packages/smart-contracts/scripts-create2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export type HardhatRuntimeEnvironmentExtended = HardhatRuntimeEnvironment & {
deployerAddress: string;
gasLimit?: number;
};
tenderly: {
project: string;
username: string;
accessKey: string;
};
};
};

Expand Down
23 changes: 23 additions & 0 deletions packages/smart-contracts/scripts-create2/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import axios from 'axios';

type ChainConfig = {
name: string;
chainId: number;
rpcUrls: string[];
};

const cachedChainConfigs: Record<string, ChainConfig> = {};

export const getChainConfig = async (chainName: string) => {
try {
if (cachedChainConfigs[chainName]) return cachedChainConfigs[chainName];
const { data } = await axios.get<ChainConfig>(
`https://api.request.network/currency/chains/${chainName}`,
);
cachedChainConfigs[chainName] = data;
return data;
} catch (e) {
console.warn(e.message);
return null;
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Contract } from 'ethers';
import * as artifacts from '../src/lib';
import * as artifacts from '../../src/lib';

/**
* List of smart contract that we deploy using the CREATE2 scheme through the Request Deployer contract
Expand Down
2 changes: 1 addition & 1 deletion packages/smart-contracts/scripts-create2/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function VerifyCreate2FromList(hre: HardhatRuntimeEnvironmentExtend
// Other cases to add when necessary
default:
throw new Error(
`The contrat ${contract} is not to be deployed using the CREATE2 scheme`,
`The contract ${contract} is not to be deployed using the CREATE2 scheme`,
);
}
} catch (err) {
Expand Down
18 changes: 18 additions & 0 deletions packages/smart-contracts/src/lib/ContractArtifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ export class ContractArtifact<TContract extends Contract> {
}));
}

/**
* Retrieve all addresses for all versions for all networks
* @returns the addresses of the deployed contract and the associated network and version.
*/
getAllAddressesFromAllNetworks(): { version: string; address: string; networkName: string }[] {
const deployments = [];
for (const version in this.info) {
for (const networkName in this.info[version].deployment) {
deployments.push({
version,
address: this.info[version].deployment[networkName].address,
networkName,
});
}
}
return deployments;
}

/**
* Retrieve the block creation number from the artifact of the used version
* deployed into the specified network
Expand Down
16 changes: 1 addition & 15 deletions packages/toolbox/src/commands/transaction/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getDefaultProvider } from '@requestnetwork/payment-detection';
import { providers, Wallet } from 'ethers';
import axios from 'axios';
import { getChainConfig } from '@requestnetwork/smart-contracts/scripts-create2/utils/chains';

export const getWallet = async ({
chainName,
Expand Down Expand Up @@ -31,17 +31,3 @@ export const getProvider = async (chainName: string) => {
}
return getDefaultProvider(chainName);
};

const getChainConfig = async (chainName: string) => {
try {
const { data } = await axios.get<{
name: string;
chainId: number;
rpcUrls: string[];
}>(`https://api.request.network/currency/chains/${chainName}`);
return data;
} catch (e) {
console.warn(e.message);
return null;
}
};
Loading