Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions packages/currency/src/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export const nativeCurrencies: Record<NativeCurrencyType, (NativeCurrency & { na
name: 'Rinkeby Ether',
network: 'rinkeby',
},
{
symbol: 'ETH-goerli',
decimals: 18,
name: 'Goerli Ether',
network: 'goerli',
},
{
symbol: 'MATIC',
decimals: 18,
Expand Down
86 changes: 45 additions & 41 deletions packages/smart-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ The package stores the following smart contracts:
- `ERC20SwapToPay` same as `ERC20FeeProxy` but allowing the payer to swap another token before paying
- `ERC20SwapToConversion` same as `ERC20ConversionProxy` but allowing the payer to swap another token before paying

## Smart contracts deployment

### Local deployment
## Local deployment

The smart contracts can be deployed locally with the following commands:

Expand All @@ -102,29 +100,7 @@ And in another terminal, deploy the smart contracts locally with:
yarn run deploy
```

### Live deployment (Payment only)

The goal of this script is to let all our payment contracts be deployed with the same sequence on every chain.

The script also verify deployed contracts.

**Be sure that artifacts are up-to-date with most recent deployments**

Environment variables needed: `ETHERSCAN_API_KEY`, `ADMIN_WALLET_ADDRESS`, `DEPLOYMENT_PRIVATE_KEY`

```bash
# First check what will be done
yarn hardhat deploy-live-payments --network matic --dry-run

# Run
yarn hardhat deploy-live-payments --network matic

# To test locally
yarn hardhat deploy-live-payments --network private --force
yarn hardhat deploy-live-payments --network private --force --dry-run
```

### Deployment through request deployer
## Live deployment

The request deployer enables multichain deployment of several smart contracts at predefined address. It is based on https://github.com/pcaversaccio/xdeployer

Expand All @@ -134,15 +110,15 @@ 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).

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

Environment variables needed: `DEPLOYER_MASTER_KEY`

```bash
yarn hardhat deploy-deployer-contract --network <NETWORK>
```

#### Compute the contract addresses
### Compute the contract addresses

Run:

Expand All @@ -152,13 +128,21 @@ yarn hardhat compute-contract-addresses

It will compute the addresses of the contracts to be deployed via the request deployer.

#### Deploy the contracts
### Deploy the contracts

Depending on the xdeployer config, this script will deploy the smart contracts on several chain simultaneously
Environment variables needed: `ADMIN_PRIVATE_KEY`
You will need the request deployer to be deployed.
Then run:

To deploy all contracts to one network, use:

```bash
NETWORK=<NETWORK> yarn hardhat deploy-contracts-through-deployer
```

If you want to deploy all contracts on all networks:

```bash
yarn hardhat deploy-contracts-through-deployer
```
Expand All @@ -171,17 +155,45 @@ This command will output details about each contract deployment on each chain:
- If already deployed: the network, and the contract address
- If an error occured: the said error

#### Verify the contracts
### Verify the contracts

For each network the contract were deployed to run:
Verify and publish the contract code automatically to blockchain explorers, right after smart contracts compilation. You should first set the `ETHERSCAN_API_KEY` environment variable.

```bash
yarn hardhat verify-contract-from-deployer --network <NETWORK>
```

The associated `EXPLORER_API_KEY` is mandatory.
#### Verify the contracts manually With Hardhat (legacy)

### Tests
A more generic way to verify any contract by setting constructor argments manually:

```bash
yarn hardhat verify --network NETWORK_NAME DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
```

### Deprecated payment deployment scripts (legacy)

The goal of this script is to let all our payment contracts be deployed with the same sequence on every chain.

The script also verify deployed contracts.

**Be sure that artifacts are up-to-date with most recent deployments**

Environment variables needed: `ETHERSCAN_API_KEY`, `ADMIN_WALLET_ADDRESS`, `DEPLOYMENT_PRIVATE_KEY`

```bash
# First check what will be done
yarn hardhat deploy-live-payments --network matic --dry-run

# Run
yarn hardhat deploy-live-payments --network matic

# To test locally
yarn hardhat deploy-live-payments --network private --force
yarn hardhat deploy-live-payments --network private --force --dry-run
```

## Tests

After a local deployment:

Expand All @@ -195,14 +207,6 @@ Networks and providers are configured in [hardhat.config.ts](hardhat.config.ts).

Have a look at the [Hardhat documentation](https://hardhat.org/config/).

## Contract verification with Hardhat

Verify and publish the contract code automatically to blockchain explorers, right after smart contracts compilation. You should first set the `ETHERSCAN_API_KEY` environment variable.

```bash
yarn hardhat verify --network NETWORK_NAME DEPLOYED_CONTRACT_ADDRESS "Constructor argument 1"
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
10 changes: 8 additions & 2 deletions packages/smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { checkCreate2Deployer } from './scripts-create2/check-deployer';
import { deployDeployer } from './scripts-create2/deploy-request-deployer';
import { HardhatRuntimeEnvironmentExtended } from './scripts-create2/types';
import { computeCreate2DeploymentAddressesFromList } from './scripts-create2/compute-one-address';
import { VerifyCreate2FromList } from './scripts-create2/verify-one';
import { deployWithCreate2FromList } from './scripts-create2/deploy-one';
import { VerifyCreate2FromList } from './scripts-create2/verify';
import { deployWithCreate2FromList } from './scripts-create2/deploy';
import utils from '@requestnetwork/utils';

config();
Expand Down Expand Up @@ -69,6 +69,11 @@ export default {
chainId: 4,
accounts,
},
goerli: {
url: process.env.WEB3_PROVIDER_URL || 'https://goerli.infura.io/v3/YOUR_API_KEY',
chainId: 5,
accounts,
},
matic: {
url: url('matic'),
chainId: 137,
Expand Down Expand Up @@ -124,6 +129,7 @@ export default {
apiKey: {
mainnet: process.env.ETHERSCAN_API_KEY,
rinkeby: process.env.ETHERSCAN_API_KEY,
goerli: process.env.ETHERSCAN_API_KEY,
// binance smart chain
bsc: process.env.BSCSCAN_API_KEY,
bscTestnet: process.env.BSCSCAN_API_KEY,
Expand Down
14 changes: 11 additions & 3 deletions packages/smart-contracts/scripts-create2/compute-one-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ export const computeCreate2DeploymentAddressesFromList = async (
switch (contract) {
case 'EthereumProxy':
case 'EthereumFeeProxy':
case 'ETHConversionProxy':
case 'ERC20FeeProxy':
case 'Erc20ConversionProxy':
case 'ERC20EscrowToPay':
case 'BatchPayments':
case 'ERC20SwapToConversion': {
const constructorArgs = getConstructorArgs(contract);
address = await computeCreate2DeploymentAddress({ contract, constructorArgs }, hre);
console.log(`${contract.padEnd(36, ' ')}${address}`);
try {
const constructorArgs = getConstructorArgs(contract, hre.network.name);
address = await computeCreate2DeploymentAddress({ contract, constructorArgs }, hre);
console.log(`${contract.padEnd(36, ' ')}${address}`);
} catch (e) {
console.warn(`ERROR computing address of ${contract}: ${e}`);
}
break;
}
// Other cases to add when necessary
Expand Down
35 changes: 19 additions & 16 deletions packages/smart-contracts/scripts-create2/constructor-args.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
import * as artifacts from '../src/lib';

const getAdminWalletAddress = (contract: string): string => {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(`ADMIN_WALLET_ADDRESS missing to get constructor args for: ${contract}`);
}
return process.env.ADMIN_WALLET_ADDRESS;
};

export const getConstructorArgs = (contract: string, network?: string): string[] => {
switch (contract) {
case 'Erc20ConversionProxy': {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(`ADMIN_WALLET_ADDRESS missing to get constructor args for: ${contract}`);
}
return [
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
process.env.ADMIN_WALLET_ADDRESS,
getAdminWalletAddress(contract),
];
}
case 'ETHConversionProxy': {
return [
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x39e19aa5b69466dfdc313c7cda37cb2a599015cd',
];
// TODO setupETHConversionProxy
}
case 'ERC20SwapToConversion': {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(`ADMIN_WALLET_ADDRESS missing to get constructor args for: ${contract}`);
}
return [process.env.ADMIN_WALLET_ADDRESS];
return [getAdminWalletAddress(contract)];
}
case 'ERC20EscrowToPay': {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(`ADMIN_WALLET_ADDRESS missing to get constructor args for: ${contract}`);
}
if (!network) {
throw new Error(
'Escrow contract requires network parameter to get correct address of erc20FeeProxy',
);
}
const erc20FeeProxy = artifacts.erc20FeeProxyArtifact;
const erc20FeeProxyAddress = erc20FeeProxy.getAddress(network);
return [erc20FeeProxyAddress, process.env.ADMIN_WALLET_ADDRESS];
return [erc20FeeProxyAddress, getAdminWalletAddress(contract)];
}
case 'BatchPayments': {
if (!process.env.ADMIN_WALLET_ADDRESS) {
throw new Error(`ADMIN_WALLET_ADDRESS missing to get constructor args for: ${contract}`);
}
if (!network) {
throw new Error(
'Batch contract requires network parameter to get correct address of erc20FeeProxy and ethereumFeeProxy',
Expand All @@ -43,7 +46,7 @@ export const getConstructorArgs = (contract: string, network?: string): string[]
return [
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
process.env.ADMIN_WALLET_ADDRESS,
getAdminWalletAddress(contract),
];
}
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { batchPaymentsArtifact } from '../../src/lib';
import { HardhatRuntimeEnvironmentExtended } from '../types';
import utils from '@requestnetwork/utils';
import { updateChainlinkConversionPath, updatePaymentErc20FeeProxy } from './adminTasks';

/**
* Updates the values of the batch fees of the BatchPayments contract, if needed
* @param contractAddress address of the BatchPayments Proxy
* @param hre Hardhat runtime environment
*/
export const setupEthConversionProxy = async (
contractAddress: string,
hre: HardhatRuntimeEnvironmentExtended,
): Promise<void> => {
// Setup contract parameters
const EthConversionProxyContract = new hre.ethers.Contract(
contractAddress,
batchPaymentsArtifact.getContractAbi(),
);
await Promise.all(
hre.config.xdeploy.networks.map(async (network) => {
let provider;
if (network === 'celo') {
provider = utils.getCeloProvider();
} else {
provider = utils.getDefaultProvider(network);
}
const wallet = new hre.ethers.Wallet(hre.config.xdeploy.signer, provider);
const signer = wallet.connect(provider);
const EthConversionProxyConnected = await EthConversionProxyContract.connect(signer);
const adminNonce = await signer.getTransactionCount();
const gasPrice = await provider.getGasPrice();

// start from the adminNonce, increase gasPrice if needed
await Promise.all([
updatePaymentErc20FeeProxy(EthConversionProxyConnected, network, adminNonce, gasPrice),
updateChainlinkConversionPath(
EthConversionProxyConnected,
network,
adminNonce + 1,
gasPrice,
),
]);
}),
);
console.log('Setup for EthConversionProxy successful');
};
Loading