Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 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)
romtref Jul 28, 2022
73cb822
chore: update escrow addresses (#886)
KolevDarko Jul 29, 2022
3e8763d
feat: goerli payment (#892)
romtref Aug 1, 2022
8b51b33
refactor: factorize goerli tests (#893)
romtref Aug 3, 2022
0f20179
feat: add goerli support (advanced-logic) (#895)
romtref 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
a6bc406
clean test
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
d45751e
Merge branch 'feat/batch-conversion' into feat/batch-conversion-payment
olivier7delf Aug 26, 2022
a1cbbe8
Merge branch 'feat/deploy-batch-conversion-contracts' into feat/batch…
olivier7delf Aug 26, 2022
ab9f4b7
fix import getPaymentNetworkExtension and its paymentReference undefi…
olivier7delf Aug 26, 2022
b35d5d1
fix error message
olivier7delf Aug 26, 2022
16b2b94
rename batch conversion file
olivier7delf Aug 30, 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
cb4b33f
Merge branch 'feat/deploy-batch-conversion-contracts' into feat/batch…
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
2b63a45
Merge branch 'feat/deploy-batch-conversion-contracts' into feat/batch…
olivier7delf Sep 7, 2022
7a98313
update processor with type
olivier7delf Sep 8, 2022
8fd262f
refacto feeAddress
olivier7delf Sep 9, 2022
ea5bc98
refacto batch payment
olivier7delf Sep 13, 2022
ecb74dd
merge with master
olivier7delf Sep 14, 2022
f31725d
clean history
olivier7delf Sep 14, 2022
34d3d72
refacto batch-conversion-proxy
olivier7delf Sep 14, 2022
4fca56c
refacto tests
olivier7delf Sep 14, 2022
487473d
cleaning
olivier7delf Sep 14, 2022
40974f9
tests cleaning
olivier7delf Sep 14, 2022
5cc5755
refacto from PR comments
olivier7delf Sep 14, 2022
78d8c3b
use type guards for ERC20 and ISO4217 currencies
olivier7delf Sep 14, 2022
20a8424
PR comments B
olivier7delf Sep 15, 2022
dba87f8
add comments
olivier7delf Sep 15, 2022
7a9ecf3
convention if
olivier7delf Sep 15, 2022
5beb6ca
Add every params description to functions
olivier7delf Sep 16, 2022
26407ea
add batch proxy addresses
olivier7delf Sep 16, 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
1 change: 1 addition & 0 deletions packages/payment-processor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './payment/near-input-data';
export * from './payment/eth-proxy';
export * from './payment/eth-fee-proxy';
export * from './payment/batch-proxy';
export * from './payment/batch-conversion-proxy';
export * from './payment/swap-conversion-erc20';
export * from './payment/swap-any-to-erc20';
export * from './payment/swap-erc20';
Expand Down
116 changes: 92 additions & 24 deletions packages/payment-processor/src/payment/any-to-erc20-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { constants, ContractTransaction, Signer, providers, BigNumberish, BigNumber } from 'ethers';

import { CurrencyManager, UnsupportedCurrencyError } from '@requestnetwork/currency';
import {
CurrencyDefinition,
CurrencyManager,
UnsupportedCurrencyError,
} from '@requestnetwork/currency';
import { AnyToERC20PaymentDetector } from '@requestnetwork/payment-detection';
import { Erc20ConversionProxy__factory } from '@requestnetwork/smart-contracts/types';
import { ClientTypes, RequestLogicTypes } from '@requestnetwork/types';
Expand All @@ -20,13 +24,13 @@ import { IConversionPaymentSettings } from './index';

/**
* Processes a transaction to pay a request with an ERC20 currency that is different from the request currency (eg. fiat).
* The payment is made by the ERC20 fee proxy contract.
* @param request the request to pay
* @param signerOrProvider the Web3 provider, or signer. Defaults to window.ethereum.
* @param paymentSettings payment settings
* @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
* @param feeAmount optionally, the fee amount to pay. Defaults to the fee amount.
* @param overrides optionally, override default transaction values, like gas.
* The payment is made by the ERC20 Conversion fee proxy contract.
* @param request The request to pay
* @param signerOrProvider The Web3 provider, or signer. Defaults to window.ethereum.
* @param paymentSettings The payment settings
* @param amount Optionally, the amount to pay. Defaults to remaining amount of the request.
* @param feeAmount Optionally, the fee amount to pay. Defaults to the fee amount.
* @param overrides Optionally, override default transaction values, like gas.
*/
export async function payAnyToErc20ProxyRequest(
request: ClientTypes.IRequestData,
Expand All @@ -47,19 +51,54 @@ export async function payAnyToErc20ProxyRequest(
}

/**
* Encodes the call to pay a request with an ERC20 currency that is different from the request currency (eg. fiat). The payment is made by the ERC20 fee proxy contract.
* @param request request to pay
* @param signerOrProvider the Web3 provider, or signer. Defaults to window.ethereum.
* @param paymentSettings payment settings
* @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
* @param feeAmountOverride optionally, the fee amount to pay. Defaults to the fee amount of the request.
* Encodes the call to pay a request with an ERC20 currency that is different from the request currency (eg. fiat).
* The payment is made by the ERC20 Conversion fee proxy contract.
* @param request The request to pay
* @param paymentSettings The payment settings
* @param amount Optionally, the amount to pay. Defaults to remaining amount of the request.
* @param feeAmountOverride Optionally, the fee amount to pay. Defaults to the fee amount of the request.
*/
export function encodePayAnyToErc20ProxyRequest(
request: ClientTypes.IRequestData,
paymentSettings: IConversionPaymentSettings,
amount?: BigNumberish,
feeAmountOverride?: BigNumberish,
): string {
const {
path,
paymentReference,
paymentAddress,
feeAddress,
maxRateTimespan,
amountToPay,
feeToPay,
} = prepareAnyToErc20Arguments(request, paymentSettings, amount, feeAmountOverride);
const proxyContract = Erc20ConversionProxy__factory.createInterface();
return proxyContract.encodeFunctionData('transferFromWithReferenceAndFee', [
paymentAddress,
amountToPay,
path,
`0x${paymentReference}`,
feeToPay,
feeAddress || constants.AddressZero,
BigNumber.from(paymentSettings.maxToSpend),
maxRateTimespan || 0,
]);
}

/**
* It checks paymentSettings values, it get request's path and requestCurrency
* @param request The request to pay
* @param paymentSettings The payment settings
* @param amount Optionally, the amount to pay. Defaults to remaining amount of the request.
* @param feeAmountOverride Optionally, the fee amount to pay. Defaults to the fee amount of the request.
*/
export function checkRequestAndGetPathAndCurrency(
request: ClientTypes.IRequestData,
paymentSettings: IConversionPaymentSettings,
amount?: BigNumberish,
feeAmountOverride?: BigNumberish,
): { path: string[]; requestCurrency: CurrencyDefinition<unknown> } {
if (!paymentSettings.currency) {
throw new Error('currency must be provided in the paymentSettings');
}
Expand Down Expand Up @@ -94,24 +133,53 @@ export function encodePayAnyToErc20ProxyRequest(

// Check request
validateConversionFeeProxyRequest(request, path, amount, feeAmountOverride);
return { path, requestCurrency };
}

/**
* Prepares all necessaries arguments required to encode an any-to-erc20 request
* @param request The request to pay
* @param paymentSettings The payment settings
* @param amount Optionally, the amount to pay. Defaults to remaining amount of the request.
* @param feeAmountOverride Optionally, the fee amount to pay. Defaults to the fee amount of the request.
*/
function prepareAnyToErc20Arguments(
request: ClientTypes.IRequestData,
paymentSettings: IConversionPaymentSettings,
amount?: BigNumberish,
feeAmountOverride?: BigNumberish,
): {
path: string[];
paymentReference: string;
paymentAddress: string;
feeAddress: string | undefined;
maxRateTimespan: string | undefined;
amountToPay: BigNumber;
feeToPay: BigNumber;
} {
const { path, requestCurrency } = checkRequestAndGetPathAndCurrency(
request,
paymentSettings,
amount,
feeAmountOverride,
);

const { paymentReference, paymentAddress, feeAddress, feeAmount, maxRateTimespan } =
getRequestPaymentValues(request);

if (!paymentReference) {
throw new Error('paymentReference is missing');
}
const amountToPay = padAmountForChainlink(getAmountToPay(request, amount), requestCurrency);
const feeToPay = padAmountForChainlink(feeAmountOverride || feeAmount || 0, requestCurrency);

const proxyContract = Erc20ConversionProxy__factory.createInterface();
return proxyContract.encodeFunctionData('transferFromWithReferenceAndFee', [
return {
path,
paymentReference,
paymentAddress,
feeAddress,
maxRateTimespan,
amountToPay,
path,
`0x${paymentReference}`,
feeToPay,
feeAddress || constants.AddressZero,
BigNumber.from(paymentSettings.maxToSpend),
maxRateTimespan || 0,
]);
};
}

export function prepareAnyToErc20ProxyPaymentTransaction(
Expand Down
Loading