Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(smart-contracts):batch conversion xdeployer #912

Draft
wants to merge 172 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
71d0605
batch erc20 conversion contract and local deployment
olivier7delf Jun 1, 2022
5f7fc4f
tests batchPayments functions
olivier7delf Jul 13, 2022
eb1c4d8
clear batch contract
olivier7delf Jul 15, 2022
db22abc
add comments in smart contract
olivier7delf Jul 25, 2022
1a3e6b8
add batchEthConversionPaymentsWithReference
olivier7delf Jul 25, 2022
0ebe8b0
refacto batch contracts approval functions
olivier7delf Jul 29, 2022
1818239
PR - update batch contact - function visibility and comments
olivier7delf Aug 3, 2022
72c2a73
keep prefix underscore usage for function args
olivier7delf Aug 3, 2022
3ed489c
convention naming in batch contract and more comments
olivier7delf Aug 3, 2022
1800632
batchConv - delete chainlink implementation
olivier7delf Aug 4, 2022
1eb224d
batchConv erc20 - delete a require - add error tests
olivier7delf Aug 4, 2022
f8c2745
prettier contract
olivier7delf Aug 4, 2022
84216f7
doc: modify command to create request (#880)
rom1trt Jul 28, 2022
73cb822
chore: update escrow addresses (#886)
KolevDarko Jul 29, 2022
3e8763d
feat: goerli payment (#892)
rom1trt Aug 1, 2022
8b51b33
refactor: factorize goerli tests (#893)
rom1trt Aug 3, 2022
0f20179
feat: add goerli support (advanced-logic) (#895)
rom1trt Aug 3, 2022
3c1db98
tmp
olivier7delf Aug 2, 2022
31cf53f
any-to-erc20-proxy payment - correct documention on proxy used
olivier7delf Aug 4, 2022
f3ff088
wip
olivier7delf Aug 4, 2022
ebd3ff4
refacto receive function - add comments to test functions
olivier7delf Aug 4, 2022
1c07569
comments about unique token in smart contract
olivier7delf Aug 4, 2022
2357f60
prettier
olivier7delf Aug 4, 2022
b721ef4
Update packages/smart-contracts/src/contracts/BatchPaymentsPublic.sol
olivier7delf Aug 4, 2022
83398ea
Update packages/smart-contracts/src/contracts/BatchPaymentsPublic.sol
olivier7delf Aug 4, 2022
d5c11ec
Update packages/smart-contracts/src/contracts/BatchPaymentsPublic.sol
olivier7delf Aug 4, 2022
e704f4e
Update packages/smart-contracts/src/contracts/BatchPaymentsPublic.sol
olivier7delf Aug 4, 2022
978b701
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
ef4b86f
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
23b2980
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
abc5471
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
4367d97
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
4f683a3
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
dde44db
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
f20d802
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
a047149
Update packages/smart-contracts/src/contracts/BatchConversionPayments…
olivier7delf Aug 4, 2022
014c430
receive comment
olivier7delf Aug 4, 2022
f63d653
tmp tests fail
olivier7delf Aug 5, 2022
0c8f375
batch calcul updated and tested - it includes fees now
olivier7delf Aug 5, 2022
7cde97d
delete basicFee inside the contract - update test - refacto script to…
olivier7delf Aug 5, 2022
69b10dc
check the addresses of the contracts deployed and raise an error if n…
olivier7delf Aug 8, 2022
aa08563
smart contract add variable tenThousand
olivier7delf Aug 8, 2022
570de98
contract require message - wording
olivier7delf Aug 8, 2022
b3787cb
smart contract delete chainlink
olivier7delf Aug 8, 2022
101d9cd
revert batchPayments modif
olivier7delf Aug 8, 2022
f4c4452
merge with detached branch
olivier7delf Aug 8, 2022
2f79b95
Merge branch 'master' into feat/batch-conversion
olivier7delf Aug 8, 2022
70f9fe9
contract - remove irrelevant variable - wording uTokens
olivier7delf Aug 8, 2022
4b9f0af
renaming requestInfo into conversionDetail and requestsInfoParent int…
olivier7delf Aug 8, 2022
c2d842e
contract - clean constructor
olivier7delf Aug 9, 2022
73fa7a7
wording receive comments
olivier7delf Aug 9, 2022
04a2d92
clean packages
olivier7delf Aug 9, 2022
93fb63c
Merge branch 'master' into feat/batch-conversion
olivier7delf Aug 9, 2022
d49d1ad
Merge branch 'master' into feat/batch-conversion-payment
olivier7delf Aug 9, 2022
24c9ef4
Merge branch 'feat/batch-conversion' into feat/batch-conversion-payment
olivier7delf Aug 9, 2022
5e86486
wip
olivier7delf Aug 10, 2022
1a55c1e
refacto batch conversion ERC20 tests
olivier7delf Aug 10, 2022
8e3485d
eth batch functions tested
olivier7delf Aug 10, 2022
a5dcb32
rewording and cleaning
olivier7delf Aug 10, 2022
39199c8
refacto tests batch conversion ERC20
olivier7delf Aug 16, 2022
30e61e9
refacto tests: batch conversion Eth
olivier7delf Aug 17, 2022
c17d2ba
Merge branch 'master' into feat/batch-conversion
olivier7delf Aug 17, 2022
9285407
Merge branch 'feat/batch-conversion' into feat/batch-conversion-payment
olivier7delf Aug 17, 2022
d7e0b25
test erc20 can be run multiple time - revoke these approvals
olivier7delf Aug 17, 2022
bff175f
test swap-erc-20-fee-proxy revoke approval
olivier7delf Aug 17, 2022
b6b854c
refacto any-to-erc20-proxy to create the function checkRequestAndGetP…
olivier7delf Aug 18, 2022
8876f91
prettier
olivier7delf Aug 18, 2022
503e6ea
prettier test swap
olivier7delf Aug 18, 2022
24862d1
batch conversion proxy functions and approvals
olivier7delf Aug 18, 2022
d305475
test batch erc20
olivier7delf Aug 18, 2022
239c216
tests batch conversion payment done
olivier7delf Aug 25, 2022
0d44f52
prettier
olivier7delf Aug 25, 2022
ed525a4
clean tests and restore previous batchFee values
olivier7delf Aug 25, 2022
09f3fca
merge with master
olivier7delf Aug 25, 2022
69cb5ab
test refacto to simplify batchConvFunction
olivier7delf Aug 25, 2022
2736a8e
Merge branch 'master' into feat/batch-conversion
olivier7delf Aug 25, 2022
6bbccca
update batch conversion contract
olivier7delf Aug 26, 2022
b961daf
clean escrow
olivier7delf Aug 26, 2022
367fee4
Merge branch 'feat/batch-conversion' into feat/batch-conversion-payment
olivier7delf Aug 26, 2022
714590f
version with errors on 2 proxies
olivier7delf Aug 26, 2022
2bf4116
make proxies public
olivier7delf Aug 26, 2022
f0437d5
batch conversion deploy on rinkeby
olivier7delf Aug 26, 2022
978cd11
batch conversion deployed on goerli
olivier7delf Aug 26, 2022
d09aa03
update contract to make proxies public
olivier7delf Aug 26, 2022
75c7a3c
Merge branch 'feat/batch-conversion' into feat/deploy-batch-conversio…
olivier7delf Aug 26, 2022
9f746bc
test refacto: delete emitOneTx - path and add before - adminSigner
olivier7delf Aug 31, 2022
2a683ee
deploy instead of connect to batchProxy
olivier7delf Aug 31, 2022
65c9f94
end cleaning old test version
olivier7delf Aug 31, 2022
c6dc943
refacto new test structure
olivier7delf Aug 31, 2022
44d6372
refacto test add eth beginning
olivier7delf Aug 31, 2022
7cd6854
tests batchRouter erros
olivier7delf Sep 1, 2022
9439c7d
abi update
olivier7delf Sep 2, 2022
fc1c6d2
Merge branch 'master' into feat/batch-conversion
olivier7delf Sep 2, 2022
bc407d0
batch conv tests delete proxy global variables
olivier7delf Sep 2, 2022
3459966
test refactored
olivier7delf Sep 6, 2022
4dbf265
tests: cleaning
olivier7delf Sep 7, 2022
34e77e1
Merge branch 'feat/batch-conversion' into feat/deploy-batch-conversio…
olivier7delf Sep 7, 2022
d385a31
update batchConversionPayments proxies on rinkeby, goerli, and matic
olivier7delf Sep 7, 2022
21a4871
add type for batch payment inputs
olivier7delf Sep 7, 2022
d52958f
Merge branch 'feat/batch-conversion' into feat/deploy-batch-conversio…
olivier7delf Sep 7, 2022
68bdf3e
delete payment-processor batch
olivier7delf Sep 8, 2022
05fb4e3
Merge branch 'feat/batch-conversion' into feat/deploy-batch-conversio…
olivier7delf Sep 8, 2022
8bb8435
clean payment processor
olivier7delf Sep 9, 2022
d19a3bd
merge with master
olivier7delf Sep 14, 2022
aa18bef
add logs
olivier7delf Sep 15, 2022
0cad7b8
add batch conversion proxy address
olivier7delf Sep 15, 2022
103d432
remove batch payment deprecated - should not be deployed anymore
olivier7delf Sep 15, 2022
d92341c
add comments to batch fees
olivier7delf Sep 15, 2022
9738e7d
erase xdeployer batchpayments legacy
olivier7delf Sep 15, 2022
fa280d0
master merged
olivier7delf Sep 21, 2022
fb168a1
proxy addresses updated
olivier7delf Sep 22, 2022
256f5d6
add fee batch amount limit to batchMultiERC20ConversionPayments
olivier7delf Oct 7, 2022
1510142
batchFees amount limited for batchNoConversion erc20 functions
olivier7delf Oct 9, 2022
59a1485
batch erc20 functions tested
olivier7delf Oct 10, 2022
53e75c8
functions and test working
olivier7delf Oct 11, 2022
69d76a7
refacto smart contract and optimize gas
olivier7delf Oct 12, 2022
552ebbb
rename ConversionDetail into RequestDetail
olivier7delf Oct 12, 2022
aec302c
rename batchRouter function into batchPayment
olivier7delf Oct 12, 2022
ce934f2
typo corrections
olivier7delf Oct 12, 2022
385c36f
fix erc20 tests with batchFee value limited to 200
olivier7delf Oct 12, 2022
ccbc6d6
add the gas optimization for batch eth functions and clean tests
olivier7delf Oct 12, 2022
878c84e
test ready
olivier7delf Oct 12, 2022
1d2855d
legacy - delete BatchPayment modification
olivier7delf Oct 13, 2022
d2f0cfe
add privates functions - rename enable by skip fee USD limit - change…
olivier7delf Oct 13, 2022
05cd466
rename ETH functions into Native functions
olivier7delf Oct 13, 2022
aaf052b
abi code
olivier7delf Oct 13, 2022
6b853c2
pretty batch contract
olivier7delf Oct 13, 2022
61b2899
Merge branch 'master' into fix/btach-conversion-capped
olivier7delf Oct 13, 2022
f428ea4
update batch conversion processor
olivier7delf Oct 13, 2022
b3b5f72
update contract comment and receiver function
olivier7delf Oct 13, 2022
7a7d8b7
Merge branch 'fix/btach-conversion-capped' into chore/payment-process…
olivier7delf Oct 13, 2022
ac9b2a3
rename batchPayment into batchPayments
olivier7delf Oct 13, 2022
57d4e5f
Merge branch 'fix/btach-conversion-capped' into chore/payment-process…
olivier7delf Oct 13, 2022
93b8bb6
clean batch abi files
olivier7delf Oct 14, 2022
63ae2a1
Merge branch 'fix/btach-conversion-capped' into chore/payment-process…
olivier7delf Oct 14, 2022
42913a7
update payment processor batchPayments and fix one test
olivier7delf Oct 14, 2022
43baa37
add batch fee amount USD to batch payment processor and its tests
olivier7delf Oct 14, 2022
fc6887f
batch conversion payment processor functions and tests
olivier7delf Oct 17, 2022
ae46de2
increase DAI funds to tests batch payments with big amounts and be ab…
olivier7delf Oct 17, 2022
85f330e
Merge branch 'master' into fix/btach-conversion-capped
olivier7delf Oct 17, 2022
70d3fe9
Merge branch 'fix/btach-conversion-capped' into chore/payment-process…
olivier7delf Oct 17, 2022
1d28a64
update merge master
olivier7delf Oct 17, 2022
e7a6bff
Merge branch 'fix/btach-conversion-capped' into feat/deploy-batch-con…
olivier7delf Oct 18, 2022
fb8d60c
naming convention and update with master
olivier7delf Oct 18, 2022
da33fa4
Merge branch 'fix/btach-conversion-capped' into feat/deploy-batch-con…
olivier7delf Oct 18, 2022
fc92e94
update with batch fee amount in USD limit
olivier7delf Oct 18, 2022
1a4efd1
deployment batch conversion with fee amount USD limit
olivier7delf Oct 18, 2022
d215a6a
batch contract deployed for tests
olivier7delf Oct 18, 2022
9436290
Merge branch 'master' into fix/btach-conversion-capped
olivier7delf Oct 19, 2022
6de03f6
Merge branch 'fix/btach-conversion-capped' into chore/payment-process…
olivier7delf Oct 19, 2022
d98ec6b
Merge branch 'chore/payment-processor-batch-fee-usd-limited' into fea…
olivier7delf Oct 19, 2022
cf50687
contract deployed WIP verify failing
olivier7delf Oct 19, 2022
d3ba003
add Yo PR - function s comments on batch contracts
olivier7delf Oct 19, 2022
d176d6f
Merge branch 'master' into fix/btach-conversion-capped
olivier7delf Oct 19, 2022
a154712
files cleaned
olivier7delf Oct 20, 2022
502741d
contract deployed
olivier7delf Oct 20, 2022
2670ef6
naming convention and update with master
olivier7delf Oct 18, 2022
ee220e2
fix(graph retriever): null values (#961)
benjlevesque Oct 17, 2022
84431e3
fix: NEAR native timestamp precision (#963)
yomarion Oct 18, 2022
17608de
add batch proxy addresses and clean tests
olivier7delf Oct 20, 2022
478f60b
Merge branch 'fix/btach-conversion-capped' into chore/payment-process…
olivier7delf Oct 20, 2022
58b4aec
Merge branch 'chore/payment-processor-batch-fee-usd-limited' into fea…
olivier7delf Oct 20, 2022
0f56100
set not to skipFeeUSDLimit by default and fix tests with currencyMana…
olivier7delf Oct 21, 2022
1db3616
modify FAKE token and add DAI token within private currencyManager
olivier7delf Oct 24, 2022
a30f233
Revert "modify FAKE token and add DAI token within private currencyMa…
olivier7delf Oct 24, 2022
1530231
update batch payment - currencyManager and version and the associated…
olivier7delf Oct 25, 2022
ecb2c58
convention and typo corrections
olivier7delf Oct 25, 2022
6a432a8
refacto batch pay inputs - no more batch type and an options with cur…
olivier7delf Oct 26, 2022
f185d8e
Merge branch 'chore/payment-processor-batch-fee-usd-limited' into fea…
olivier7delf Oct 26, 2022
5b826c5
can deploy and setup batch contract in one cmd line
olivier7delf Oct 26, 2022
c37424f
update batch and re order hardhat order as mainnet is the slower
olivier7delf Nov 3, 2022
17a8eb8
merge with master
olivier7delf Nov 3, 2022
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
3 changes: 2 additions & 1 deletion packages/smart-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ This command will output details about each contract deployment on each chain:

### Verify the contracts

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.
Verify and publish the contract code automatically to blockchain explorers, right after smart contracts compilation.
Environment variables needed: `ADMIN_...` key and wallet, `ETHERSCAN_API_KEY`, and `REQUEST_DEPLOYER_LIVE`. If you deploy on mainnet, add `WEB3_PROVIDER_URL`.

```bash
yarn hardhat verify-contract-from-deployer --network <NETWORK>
Expand Down
2 changes: 1 addition & 1 deletion packages/smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default {
signer: process.env.ADMIN_PRIVATE_KEY,
networks: process.env.NETWORK
? [process.env.NETWORK]
: ['mainnet', 'matic', 'bsc', 'celo', 'xdai', 'fuse', 'arbitrum-one', 'fantom', 'avalanche'],
: ['matic', 'bsc', 'celo', 'xdai', 'fuse', 'arbitrum-one', 'fantom', 'avalanche', 'mainnet'],
gasLimit: undefined,
deployerAddress: requestDeployer,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const computeCreate2DeploymentAddressesFromList = async (
case 'ERC20FeeProxy':
case 'Erc20ConversionProxy':
case 'ERC20EscrowToPay':
case 'BatchPayments':
case 'BatchConversionPayments':
case 'ERC20SwapToConversion': {
try {
const constructorArgs = getConstructorArgs(contract, hre.network.name);
Expand Down
7 changes: 5 additions & 2 deletions packages/smart-contracts/scripts-create2/constructor-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ export const getConstructorArgs = (contract: string, network?: string): string[]
const erc20FeeProxyAddress = erc20FeeProxy.getAddress(network);
return [erc20FeeProxyAddress, getAdminWalletAddress(contract)];
}
case 'BatchPayments': {
case 'BatchConversionPayments': {
if (!network) {
throw new Error(
'Batch contract requires network parameter to get correct address of erc20FeeProxy and ethereumFeeProxy',
'Batch conversion contract requires network parameter to get correct address of erc20FeeProxy, erc20ConversionFeeProxy, ethereumFeeProxy, ethereumConversionFeeProxy, and chainlinkConversionPath',
);
}
return [
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
getAdminWalletAddress(contract),
Expand Down
123 changes: 104 additions & 19 deletions packages/smart-contracts/scripts-create2/contract-setup/adminTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { BigNumber } from 'ethers';

// Fees: 0.5%
export const REQUEST_SWAP_FEES = 5;
// Batch Fees: .3%
export const BATCH_FEE = 3;

// Batch fee: temporarily at 0%
const BATCH_FEE = 30;

// Batch fee amount in USD Limit: 150 * 1e8 ($150)
const BATCH_FEE_AMOUNT_USD_LIMIT = 150 * 1e8;

export const updateChainlinkConversionPath = async (
contract: any,
Expand All @@ -17,10 +21,11 @@ export const updateChainlinkConversionPath = async (
const currentChainlinkAddress = await contract.chainlinkConversionPath();
const chainlinkConversionPathAddress = chainlinkConversionPath.getAddress(network, '0.1.0');
if (currentChainlinkAddress !== chainlinkConversionPathAddress) {
await contract.updateConversionPathAddress(chainlinkConversionPathAddress, {
const tx = await contract.updateConversionPathAddress(chainlinkConversionPathAddress, {
nonce: nonce,
gasPrice: gasPrice,
});
await tx.wait();
}
};

Expand Down Expand Up @@ -50,16 +55,32 @@ export const updateRequestSwapFees = async (
}
};

export const updateBatchPaymentFees = async (
export const updateBatchPaymentFees = async (contract: any, gasPrice: BigNumber): Promise<void> => {
const currentFees = (await contract.batchFee()) as number;
if (currentFees - BATCH_FEE !== 0) {
const tx = await contract.setBatchFee(BATCH_FEE, { gasPrice: gasPrice });
await tx.wait();
// Log is useful to have a direct view on was is being updated
console.log(
`Batch: the current fees: ${currentFees.toString()}, have been replaced by: ${BATCH_FEE}`,
);
}
};

export const updateBatchPaymentFeeAmountUSDLimit = async (
contract: any,
nonce: number,
gasPrice: BigNumber,
): Promise<void> => {
const currentFees = await contract.batchFee();
if (currentFees !== BATCH_FEE) {
const currentFeeAmountUSDLimit = (await contract.batchFeeAmountUSDLimit()) as number;
if (currentFeeAmountUSDLimit - BATCH_FEE_AMOUNT_USD_LIMIT !== 0) {
const tx = await contract.setBatchFeeAmountUSDLimit(BATCH_FEE_AMOUNT_USD_LIMIT, {
gasPrice: gasPrice,
});
await tx.wait();
// Log is useful to have a direct view on was is being updated
console.log(`currentFees: ${currentFees.toString()}, new fees: ${BATCH_FEE}`);
await contract.setBatchFee(BATCH_FEE, { nonce: nonce, gasPrice: gasPrice });
console.log(
`Batch: the current fee amount in USD limit: ${currentFeeAmountUSDLimit.toString()}, have been replaced by: ${BATCH_FEE_AMOUNT_USD_LIMIT}. ($1 = 1e8)`,
);
}
};

Expand All @@ -71,28 +92,92 @@ export const updatePaymentErc20FeeProxy = async (
): Promise<void> => {
const erc20FeeProxy = artifacts.erc20FeeProxyArtifact;
const erc20FeeProxyAddress = erc20FeeProxy.getAddress(network);
const currentAddress = await contract.paymentErc20FeeProxy();
if (currentAddress !== erc20FeeProxyAddress) {
const currentAddress = (await contract.paymentErc20FeeProxy()) as string;
if (currentAddress.toLocaleLowerCase() !== erc20FeeProxyAddress.toLocaleLowerCase()) {
await contract.setPaymentErc20FeeProxy(erc20FeeProxyAddress, {
nonce: nonce,
gasPrice: gasPrice,
});
}
};

export const updatePaymentEthFeeProxy = async (
/**
* Update the address of a proxy used by batch conversion contract
*/
export const updateBatchConversionProxy = async (
contract: any,
network: string,
nonce: number,
gasPrice: BigNumber,
proxyName:
| 'native'
| 'nativeConversion'
| 'erc20'
| 'erc20Conversion'
| 'chainlinkConversionPath',
): Promise<void> => {
const ethereumFeeProxy = artifacts.ethereumFeeProxyArtifact;
const ethereumFeeProxyAddress = ethereumFeeProxy.getAddress(network);
const currentAddress = await contract.paymentEthFeeProxy();
if (currentAddress !== ethereumFeeProxyAddress) {
await contract.setPaymentEthFeeProxy(ethereumFeeProxyAddress, {
nonce: nonce,
try {
let proxyAddress: string;
let batchSetProxy: any;
let currentAddress: string;
if (proxyName === 'native') {
proxyAddress = artifacts.ethereumFeeProxyArtifact.getAddress(network);
batchSetProxy = await contract.setPaymentNativeProxy;
currentAddress = await contract.paymentNativeProxy();
} else if (proxyName === 'nativeConversion') {
proxyAddress = artifacts.ethConversionArtifact.getAddress(network);
batchSetProxy = await contract.setPaymentNativeConversionProxy;
currentAddress = await contract.paymentNativeConversionProxy();
} else if (proxyName === 'erc20') {
proxyAddress = artifacts.erc20FeeProxyArtifact.getAddress(network);
batchSetProxy = await contract.setPaymentErc20Proxy;
currentAddress = await contract.paymentErc20Proxy();
} else if (proxyName === 'erc20Conversion') {
proxyAddress = artifacts.erc20ConversionProxy.getAddress(network);
batchSetProxy = await contract.setPaymentErc20ConversionProxy;
currentAddress = await contract.paymentErc20ConversionProxy();
} else {
// (proxyName === 'chainlinkConversionPath')
proxyAddress = artifacts.chainlinkConversionPath.getAddress(network);
batchSetProxy = await contract.setChainlinkConversionPath;
currentAddress = await contract.chainlinkConversionPath();
}

if (currentAddress.toLocaleLowerCase() !== proxyAddress.toLocaleLowerCase()) {
const tx = await batchSetProxy(proxyAddress, {
gasPrice: gasPrice,
});
await tx.wait();
console.log(
`${proxyName}: the current address ${currentAddress} has been replaced by: ${proxyAddress}`,
);
}
} catch (e) {
console.log(`Cannot update ${proxyName} proxy, it might not exist on this network`);
console.log(e);
}
};

export const updateNativeAndUSDAddress = async (
contract: any,
NativeAddress: string,
USDAddress: string,
gasPrice: BigNumber,
): Promise<void> => {
const currentUSDAddress = (await contract.USDAddress()).toLocaleLowerCase();
const currentNativeAddress = (await contract.NativeAddress()).toLocaleLowerCase();
if (
currentNativeAddress !== NativeAddress.toLocaleLowerCase() ||
currentUSDAddress !== USDAddress.toLocaleLowerCase()
) {
console.log(
`Batch: the current NativeAddress: ${currentNativeAddress}, have been replaced by: ${NativeAddress}`,
);
console.log(
`Batch: the current USDAddress: ${currentUSDAddress}, have been replaced by: ${USDAddress}`,
);
const tx = await contract.setNativeAndUSDAddress(NativeAddress, USDAddress, {
gasPrice: gasPrice,
});
await tx.wait();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,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');
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HardhatRuntimeEnvironmentExtended } from '../types';
import { setupETHConversionProxy } from './setupETHConversionProxy';
import { setupBatchPayments } from './setupBatchPayments';
import { setupBatchConversionPayments } from './setupBatchConversionPayments';
import { setupERC20SwapToConversion } from './setupERC20SwapToConversion';

/**
* Updates the values of either BatchPayments, ETHConversionProxy, or ERC20SwapToConversion contract, if needed
* Updates the values of either BatchConversionPayments, ETHConversionProxy, or ERC20SwapToConversion contract, if needed
* @param contractAddress address of the proxy
* @param hre Hardhat runtime environment
* @param contractName name of the contract
Expand All @@ -23,8 +23,8 @@ export const setupContract = async (
await setupERC20SwapToConversion(contractAddress, hre);
break;
}
case 'BatchPayments': {
await setupBatchPayments(contractAddress, hre);
case 'BatchConversionPayments': {
await setupBatchConversionPayments(contractAddress, hre);
break;
}
default: {
Expand Down
Loading