-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathsetupBatchConversionPayments.ts
95 lines (94 loc) · 3.34 KB
/
setupBatchConversionPayments.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { batchConversionPaymentsArtifact } from '../../src/lib';
import { HardhatRuntimeEnvironmentExtended } from '../types';
import utils from '@requestnetwork/utils';
import {
updateBatchPaymentFees,
updateBatchConversionProxy,
updateBatchPaymentFeeAmountUSDLimit,
updateNativeAndUSDAddress,
} from './adminTasks';
import { CurrencyManager } from '@requestnetwork/currency';
import { RequestLogicTypes } from '@requestnetwork/types';
/**
* Updates the values of the batch fees of the BatchConversionPayments contract, if needed
* @param contractAddress address of the BatchConversionPayments Proxy
* @param hre Hardhat runtime environment
*/
export const setupBatchConversionPayments = async (
contractAddress: string,
hre: HardhatRuntimeEnvironmentExtended,
): Promise<void> => {
// Setup contract parameters
const batchConversionPaymentContract = new hre.ethers.Contract(
contractAddress,
batchConversionPaymentsArtifact.getContractAbi(),
);
// constants related to chainlink and conversion rate
const currencyManager = CurrencyManager.getDefault();
for (const network of hre.config.xdeploy.networks) {
await Promise.all(
[network].map(async (network) => {
const NativeAddress = currencyManager.getNativeCurrency(
RequestLogicTypes.CURRENCY.ETH,
network,
)!.hash;
const USDAddress = currencyManager.fromSymbol('USD')!.hash;
console.log(`Setup BatchConversionPayments on ${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 batchConversionPaymentConnected = batchConversionPaymentContract.connect(signer);
const gasPrice = await provider.getGasPrice();
// start from the adminNonce, increase gasPrice if needed
const gasCoef = 3;
await updateBatchPaymentFees(batchConversionPaymentConnected, gasPrice.mul(gasCoef));
await updateBatchPaymentFeeAmountUSDLimit(
batchConversionPaymentConnected,
gasPrice.mul(gasCoef),
);
await updateBatchConversionProxy(
batchConversionPaymentConnected,
network,
gasPrice.mul(gasCoef),
'erc20',
);
await updateBatchConversionProxy(
batchConversionPaymentConnected,
network,
gasPrice.mul(gasCoef),
'native',
);
await updateBatchConversionProxy(
batchConversionPaymentConnected,
network,
gasPrice.mul(gasCoef),
'erc20Conversion',
);
await updateBatchConversionProxy(
batchConversionPaymentConnected,
network,
gasPrice.mul(gasCoef),
'nativeConversion',
);
await updateBatchConversionProxy(
batchConversionPaymentConnected,
network,
gasPrice.mul(gasCoef),
'chainlinkConversionPath',
);
await updateNativeAndUSDAddress(
batchConversionPaymentConnected,
NativeAddress,
USDAddress,
gasPrice.mul(gasCoef),
);
}),
);
}
console.log('Setup for setupBatchConversionPayment successfull');
};