-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathsetupBatchPayments.ts
More file actions
47 lines (45 loc) · 1.75 KB
/
setupBatchPayments.ts
File metadata and controls
47 lines (45 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { batchPaymentsArtifact } from '../../src/lib';
import { HardhatRuntimeEnvironmentExtended } from '../types';
import utils from '@requestnetwork/utils';
import {
updateBatchPaymentFees,
updatePaymentErc20FeeProxy,
updatePaymentEthFeeProxy,
} 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 setupBatchPayments = async (
contractAddress: string,
hre: HardhatRuntimeEnvironmentExtended,
): Promise<void> => {
// Setup contract parameters
const batchPaymentContract = 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 batchPaymentConnected = await batchPaymentContract.connect(signer);
const adminNonce = await signer.getTransactionCount();
const gasPrice = await provider.getGasPrice();
// start from the adminNonce, increase gasPrice if needed
await Promise.all([
updateBatchPaymentFees(batchPaymentConnected, adminNonce, gasPrice.mul(2)),
updatePaymentErc20FeeProxy(batchPaymentConnected, network, adminNonce + 1, gasPrice.mul(2)),
updatePaymentEthFeeProxy(batchPaymentConnected, network, adminNonce + 2, gasPrice.mul(2)),
]);
}),
);
console.log('Setup for setupBatchPayment successfull');
};