1
- import { Contract , ContractTransaction , Signer , BigNumberish , providers , BigNumber } from 'ethers' ;
1
+ import { BigNumber , BigNumberish , Contract , ContractTransaction , providers , Signer } from 'ethers' ;
2
2
import { erc20FeeProxyArtifact } from '@requestnetwork/smart-contracts' ;
3
3
import {
4
+ ERC20__factory ,
4
5
ERC20FeeProxy__factory ,
5
6
ERC20Proxy__factory ,
6
- ERC20__factory ,
7
7
} from '@requestnetwork/smart-contracts/types' ;
8
8
import { ClientTypes , ExtensionTypes } from '@requestnetwork/types' ;
9
9
import { Erc20PaymentNetwork , getPaymentNetworkExtension } from '@requestnetwork/payment-detection' ;
10
10
import { EvmChains } from '@requestnetwork/currency' ;
11
11
import {
12
12
getAmountToPay ,
13
13
getProvider ,
14
+ getProxyAddress ,
14
15
getRequestPaymentValues ,
15
16
getSigner ,
16
- validateRequest ,
17
17
validateErc20FeeProxyRequest ,
18
- getProxyAddress ,
18
+ validateRequest ,
19
19
} from './utils' ;
20
20
import { IPreparedPrivateTransaction } from './prepared-transaction' ;
21
21
22
- import { emporiumOp , IHinkal , RelayerTransaction } from '@hinkal/common' ;
22
+ import type { IHinkal , RelayerTransaction } from '@hinkal/common' ;
23
23
import { prepareEthersHinkal } from '@hinkal/common/providers/prepareEthersHinkal' ;
24
24
25
25
/**
@@ -85,10 +85,8 @@ export async function payErc20ProxyRequestFromHinkalShieldedAddress(
85
85
const signer = getSigner ( signerOrProvider ) ;
86
86
const hinkalObject = await addToHinkalStore ( signer ) ;
87
87
88
- const { amountToPay, tokenAddress, ops } = prepareErc20ProxyPaymentFromHinkalShieldedAddress (
89
- request ,
90
- amount ,
91
- ) ;
88
+ const { amountToPay, tokenAddress, ops } =
89
+ await prepareErc20ProxyPaymentFromHinkalShieldedAddress ( request , amount ) ;
92
90
93
91
return hinkalObject . actionPrivateWallet (
94
92
[ tokenAddress ] ,
@@ -114,11 +112,8 @@ export async function payErc20FeeProxyRequestFromHinkalShieldedAddress(
114
112
const signer = getSigner ( signerOrProvider ) ;
115
113
const hinkalObject = await addToHinkalStore ( signer ) ;
116
114
117
- const { amountToPay, tokenAddress, ops } = prepareErc20FeeProxyPaymentFromHinkalShieldedAddress (
118
- request ,
119
- amount ,
120
- feeAmount ,
121
- ) ;
115
+ const { amountToPay, tokenAddress, ops } =
116
+ await prepareErc20FeeProxyPaymentFromHinkalShieldedAddress ( request , amount , feeAmount ) ;
122
117
123
118
return hinkalObject . actionPrivateWallet (
124
119
[ tokenAddress ] ,
@@ -133,10 +128,10 @@ export async function payErc20FeeProxyRequestFromHinkalShieldedAddress(
133
128
* @param request request to pay
134
129
* @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
135
130
*/
136
- export function prepareErc20ProxyPaymentFromHinkalShieldedAddress (
131
+ export async function prepareErc20ProxyPaymentFromHinkalShieldedAddress (
137
132
request : ClientTypes . IRequestData ,
138
133
amount ?: BigNumberish ,
139
- ) : IPreparedPrivateTransaction {
134
+ ) : Promise < IPreparedPrivateTransaction > {
140
135
validateRequest ( request , ExtensionTypes . PAYMENT_NETWORK_ID . ERC20_PROXY_CONTRACT ) ;
141
136
142
137
const { value : tokenAddress } = request . currencyInfo ;
@@ -150,6 +145,7 @@ export function prepareErc20ProxyPaymentFromHinkalShieldedAddress(
150
145
151
146
const { paymentReference, paymentAddress } = getRequestPaymentValues ( request ) ;
152
147
const amountToPay = getAmountToPay ( request , amount ) ;
148
+ const { emporiumOp } = await import ( '@hinkal/common' ) ;
153
149
154
150
const ops = [
155
151
emporiumOp ( tokenContract , 'approve' , [ proxyContract . address , amountToPay ] ) ,
@@ -174,11 +170,11 @@ export function prepareErc20ProxyPaymentFromHinkalShieldedAddress(
174
170
* @param amount optionally, the amount to pay. Defaults to remaining amount of the request.
175
171
* @param feeAmountOverride optionally, the fee amount to pay. Defaults to the fee amount of the request.
176
172
*/
177
- export function prepareErc20FeeProxyPaymentFromHinkalShieldedAddress (
173
+ export async function prepareErc20FeeProxyPaymentFromHinkalShieldedAddress (
178
174
request : ClientTypes . IRequestData ,
179
175
amount ?: BigNumberish ,
180
176
feeAmountOverride ?: BigNumberish ,
181
- ) : IPreparedPrivateTransaction {
177
+ ) : Promise < IPreparedPrivateTransaction > {
182
178
validateErc20FeeProxyRequest ( request , amount , feeAmountOverride ) ;
183
179
184
180
const { value : tokenAddress , network } = request . currencyInfo ;
@@ -194,6 +190,7 @@ export function prepareErc20FeeProxyPaymentFromHinkalShieldedAddress(
194
190
const amountToPay = getAmountToPay ( request , amount ) ;
195
191
const feeToPay = String ( feeAmountOverride || feeAmount || 0 ) ;
196
192
const totalAmount = amountToPay . add ( BigNumber . from ( feeToPay ) ) ;
193
+ const { emporiumOp } = await import ( '@hinkal/common' ) ;
197
194
198
195
const ops = [
199
196
emporiumOp ( tokenContract , 'approve' , [ proxyContract . address , totalAmount ] ) ,
0 commit comments