@@ -5,11 +5,13 @@ import { ClientTypes, PaymentTypes } from '@requestnetwork/types';
5
5
import { ITransactionOverrides } from './transaction-overrides' ;
6
6
import {
7
7
comparePnTypeAndVersion ,
8
+ getAmountToPay ,
8
9
getPnAndNetwork ,
9
10
getProvider ,
10
11
getProxyAddress ,
11
12
getRequestPaymentValues ,
12
13
getSigner ,
14
+ validateErc20FeeProxyRequest ,
13
15
} from './utils' ;
14
16
import {
15
17
padAmountForChainlink ,
@@ -18,7 +20,6 @@ import {
18
20
import { IPreparedTransaction } from './prepared-transaction' ;
19
21
import { EnrichedRequest , IConversionPaymentSettings } from './index' ;
20
22
import { checkRequestAndGetPathAndCurrency } from './any-to-erc20-proxy' ;
21
- import { getBatchArgs } from './batch-proxy' ;
22
23
import { checkErc20Allowance , encodeApproveAnyErc20 } from './erc20' ;
23
24
import { BATCH_PAYMENT_NETWORK_ID } from '@requestnetwork/types/dist/payment-types' ;
24
25
import { IState } from 'types/dist/extension-types' ;
@@ -33,7 +34,7 @@ import { CurrencyInput, isERC20Currency, isISO4217Currency } from '@requestnetwo
33
34
* @param version The version of the batch conversion proxy
34
35
* @param signerOrProvider The Web3 provider, or signer. Defaults to window.ethereum.
35
36
* @param overrides Optionally, override default transaction values, like gas.
36
- * @dev We only implement batchRouter using two ERC20 functions:
37
+ * @dev We only implement batchPayments using two ERC20 functions:
37
38
* batchMultiERC20ConversionPayments, and batchMultiERC20Payments.
38
39
*/
39
40
export async function payBatchConversionProxyRequest (
@@ -79,10 +80,10 @@ export function encodePayBatchConversionRequest(enrichedRequests: EnrichedReques
79
80
const firstNetwork = getPnAndNetwork ( enrichedRequests [ 0 ] . request ) [ 1 ] ;
80
81
let firstConversionRequestExtension : IState < any > | undefined ;
81
82
let firstNoConversionRequestExtension : IState < any > | undefined ;
82
- const requestsWithoutConversion : ClientTypes . IRequestData [ ] = [ ] ;
83
- const conversionDetails : PaymentTypes . ConversionDetail [ ] = [ ] ;
83
+ const requestDetailsERC20NoConversion : PaymentTypes . RequestDetail [ ] = [ ] ;
84
+ const requestDetailsERC20Conversion : PaymentTypes . RequestDetail [ ] = [ ] ;
84
85
85
- // fill conversionDetails and requestsWithoutConversion lists
86
+ // fill requestDetailsERC20Conversion and requestDetailsERC20NoConversion lists
86
87
for ( const enrichedRequest of enrichedRequests ) {
87
88
if (
88
89
enrichedRequest . paymentNetworkId ===
@@ -100,7 +101,7 @@ export function encodePayBatchConversionRequest(enrichedRequests: EnrichedReques
100
101
) {
101
102
throw new Error ( `wrong request currencyInfo type` ) ;
102
103
}
103
- conversionDetails . push ( getInputConversionDetail ( enrichedRequest ) ) ;
104
+ requestDetailsERC20Conversion . push ( getInputConversionDetail ( enrichedRequest ) ) ;
104
105
} else if (
105
106
enrichedRequest . paymentNetworkId === BATCH_PAYMENT_NETWORK_ID . BATCH_MULTI_ERC20_PAYMENTS
106
107
) {
@@ -109,59 +110,63 @@ export function encodePayBatchConversionRequest(enrichedRequests: EnrichedReques
109
110
110
111
// isERC20Currency is checked within getBatchArgs function
111
112
comparePnTypeAndVersion ( firstNoConversionRequestExtension , enrichedRequest . request ) ;
112
- requestsWithoutConversion . push ( enrichedRequest . request ) ;
113
+ requestDetailsERC20NoConversion . push (
114
+ getInputRequestDetailERC20NoConversion ( enrichedRequest . request ) ,
115
+ ) ;
113
116
}
114
117
if ( firstNetwork !== getPnAndNetwork ( enrichedRequest . request ) [ 1 ] )
115
118
throw new Error ( 'All the requests must have the same network' ) ;
116
119
}
117
120
118
121
const metaDetails : PaymentTypes . MetaDetail [ ] = [ ] ;
119
- // Add conversionDetails to metaDetails
120
- if ( conversionDetails . length > 0 ) {
122
+ // Add requestDetailsERC20Conversion to metaDetails
123
+ if ( requestDetailsERC20Conversion . length > 0 ) {
121
124
metaDetails . push ( {
122
125
paymentNetworkId : BATCH_PAYMENT_NETWORK_ID . BATCH_MULTI_ERC20_CONVERSION_PAYMENTS ,
123
- conversionDetails : conversionDetails ,
124
- cryptoDetails : {
125
- tokenAddresses : [ ] ,
126
- recipients : [ ] ,
127
- amounts : [ ] ,
128
- paymentReferences : [ ] ,
129
- feeAmounts : [ ] ,
130
- } , // cryptoDetails is not used with paymentNetworkId 0
126
+ requestDetails : requestDetailsERC20Conversion ,
131
127
} ) ;
132
128
}
133
129
134
- // Get values and add cryptoDetails to metaDetails
135
- if ( requestsWithoutConversion . length > 0 ) {
136
- const { tokenAddresses, paymentAddresses, amountsToPay, paymentReferences, feesToPay } =
137
- getBatchArgs ( requestsWithoutConversion , 'ERC20' ) ;
138
-
130
+ // Add cryptoDetails to metaDetails
131
+ if ( requestDetailsERC20NoConversion . length > 0 ) {
139
132
// add ERC20 no-conversion payments
140
133
metaDetails . push ( {
141
134
paymentNetworkId : BATCH_PAYMENT_NETWORK_ID . BATCH_MULTI_ERC20_PAYMENTS ,
142
- conversionDetails : [ ] ,
143
- cryptoDetails : {
144
- tokenAddresses : tokenAddresses ,
145
- recipients : paymentAddresses ,
146
- amounts : amountsToPay . map ( ( x ) => x . toString ( ) ) ,
147
- paymentReferences : paymentReferences ,
148
- feeAmounts : feesToPay . map ( ( x ) => x . toString ( ) ) ,
149
- } ,
135
+ requestDetails : requestDetailsERC20NoConversion ,
150
136
} ) ;
151
137
}
152
138
153
139
const proxyContract = BatchConversionPayments__factory . createInterface ( ) ;
154
- return proxyContract . encodeFunctionData ( 'batchRouter ' , [
140
+ return proxyContract . encodeFunctionData ( 'batchPayments ' , [
155
141
metaDetails ,
156
142
feeAddress || constants . AddressZero ,
157
143
] ) ;
158
144
}
159
145
146
+ function getInputRequestDetailERC20NoConversion (
147
+ request : ClientTypes . IRequestData ,
148
+ ) : PaymentTypes . RequestDetail {
149
+ validateErc20FeeProxyRequest ( request ) ;
150
+
151
+ const tokenAddress = request . currencyInfo . value ;
152
+ const { paymentReference, paymentAddress, feeAmount } = getRequestPaymentValues ( request ) ;
153
+
154
+ return {
155
+ recipient : paymentAddress ,
156
+ requestAmount : getAmountToPay ( request ) . toString ( ) ,
157
+ path : [ tokenAddress ] ,
158
+ paymentReference : `0x${ paymentReference } ` ,
159
+ feeAmount : feeAmount || '0' ,
160
+ maxToSpend : '' ,
161
+ maxRateTimespan : '' ,
162
+ } ;
163
+ }
164
+
160
165
/**
161
166
* Get the conversion detail values from one enriched request
162
167
* @param enrichedRequest The enrichedRequest to pay
163
168
*/
164
- function getInputConversionDetail ( enrichedRequest : EnrichedRequest ) : PaymentTypes . ConversionDetail {
169
+ function getInputConversionDetail ( enrichedRequest : EnrichedRequest ) : PaymentTypes . RequestDetail {
165
170
const paymentSettings = enrichedRequest . paymentSettings ;
166
171
if ( ! paymentSettings ) throw Error ( 'the enrichedRequest has no paymentSettings' ) ;
167
172
0 commit comments