-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathsetupBatchConversionPayments.ts
More file actions
116 lines (110 loc) · 3.56 KB
/
Copy pathsetupBatchConversionPayments.ts
File metadata and controls
116 lines (110 loc) · 3.56 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { batchConversionPaymentsArtifact } from '../../src/lib';
import { HardhatRuntimeEnvironmentExtended } from '../types';
import {
getSignerAndGasFees,
updateBatchConversionProxy,
updateBatchPaymentFeeAmountUSDLimit,
updateBatchPaymentFees,
updateNativeAndUSDAddress,
} from './adminTasks';
import { CurrencyManager, EvmChains } from '@requestnetwork/currency';
import { CurrencyTypes, RequestLogicTypes } from '@requestnetwork/types';
/**
* Updates the values of the batch fees of the BatchConversionPayments contract, if needed.
* @param contractAddress address of the BatchConversionPayments contract.
* If not provided fallback to the latest deployment address
* @param hre Hardhat runtime environment.
* @param signWithEoa Are transactions to be signed by an EAO
*/
export const setupBatchConversionPayments = async ({
contractAddress,
hre,
signWithEoa,
}: {
contractAddress?: string;
hre: HardhatRuntimeEnvironmentExtended;
signWithEoa: boolean;
}): Promise<void> => {
// Setup contract parameters
// constants related to chainlink and conversion rate
const currencyManager = CurrencyManager.getDefault();
const setUpActions = async (network: CurrencyTypes.EvmChainName) => {
console.log(`Setup BatchConversionPayments on ${network}`);
if (!contractAddress) {
contractAddress = batchConversionPaymentsArtifact.getAddress(network);
}
const batchConversionPaymentContract = new hre.ethers.Contract(
contractAddress,
batchConversionPaymentsArtifact.getContractAbi(),
);
const NativeAddress = currencyManager.getNativeCurrency(
RequestLogicTypes.CURRENCY.ETH,
network,
)!.hash;
const USDAddress = currencyManager.fromSymbol('USD')!.hash;
const { signer, txOverrides } = await getSignerAndGasFees(network, hre);
const batchConversionPaymentConnected = batchConversionPaymentContract.connect(signer);
await updateBatchPaymentFees(
batchConversionPaymentConnected,
network,
txOverrides,
signer,
signWithEoa,
);
await updateBatchPaymentFeeAmountUSDLimit(
batchConversionPaymentConnected,
network,
txOverrides,
signer,
signWithEoa,
);
const proxies = [
'erc20',
'native',
'erc20Conversion',
'nativeConversion',
'chainlinkConversionPath',
];
for (const proxy of proxies) {
try {
await updateBatchConversionProxy(
batchConversionPaymentConnected,
network,
txOverrides,
proxy,
signer,
signWithEoa,
);
} catch (err) {
if (err.message.includes('No deployment for network')) {
console.warn(`No deployment for proxy ${proxy} on ${network}`);
console.warn(`Skipping Batch contract setup for ${proxy} on ${network}`);
console.warn(
`If ${proxy} was deployed on ${network} update the artifacts and run the contract setup script`,
);
} else {
throw err;
}
}
}
await updateNativeAndUSDAddress(
batchConversionPaymentConnected,
network,
NativeAddress,
USDAddress,
txOverrides,
signer,
signWithEoa,
);
};
for (const network of hre.config.xdeploy.networks) {
try {
EvmChains.assertChainSupported(network);
await setUpActions(network);
} catch (err) {
console.warn(`An error occurred during the setup of BatchConversion on ${network}`);
console.warn(err);
}
}
console.log('Setup for setupBatchConversionPayment successful');
};