Skip to content

Commit

Permalink
fix approval
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkx committed Sep 11, 2024
1 parent f3f646a commit c511d18
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,20 @@ export function TransferPanel() {
return
}

const isCustomNativeTokenAmount2 =
nativeCurrency.isCustom &&
isBatchTransferSupported &&
Number(amount2) > 0

const isNativeCurrencyApprovalRequired =
await bridgeTransferStarter.requiresNativeCurrencyApproval({
signer,
amount: amountBigNumber
amount: amountBigNumber,
options: {
approvalAmountIncrease: isCustomNativeTokenAmount2
? utils.parseUnits(amount2, nativeCurrency.decimals)
: undefined
}
})

if (isNativeCurrencyApprovalRequired) {
Expand All @@ -770,7 +780,12 @@ export function TransferPanel() {

const approvalTx = await bridgeTransferStarter.approveNativeCurrency({
signer,
amount: amountBigNumber
amount: amountBigNumber,
options: {
approvalAmountIncrease: isCustomNativeTokenAmount2
? utils.parseUnits(amount2, nativeCurrency.decimals)
: undefined
}
})

if (approvalTx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export type TransferProps = {
export type RequiresNativeCurrencyApprovalProps = {
amount: BigNumber
signer: Signer
options?: {
approvalAmountIncrease?: BigNumber
}
}

export type ApproveNativeCurrencyEstimateGasProps = {
Expand All @@ -73,6 +76,9 @@ export type ApproveNativeCurrencyEstimateGasProps = {
export type ApproveNativeCurrencyProps = {
signer: Signer
amount: BigNumber
options?: {
approvalAmountIncrease?: BigNumber
}
}

export type RequiresTokenApprovalProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class Erc20DepositStarter extends BridgeTransferStarter {

public async requiresNativeCurrencyApproval({
amount,
signer
signer,
options
}: RequiresNativeCurrencyApprovalProps) {
if (!this.sourceChainErc20Address) {
throw Error('Erc20 token address not found')
Expand Down Expand Up @@ -128,7 +129,9 @@ export class Erc20DepositStarter extends BridgeTransferStarter {
// We want to bridge a certain amount of an ERC-20 token, but the Retryable fees on the destination chain will be paid in the custom fee token
// We have to check if the native-token spending allowance is enough to cover the fees
return customFeeTokenAllowanceForSourceChainGateway.lt(
estimatedDestinationChainGasFee
estimatedDestinationChainGasFee.add(
options?.approvalAmountIncrease ?? BigNumber.from(0)
)
)
}

Expand All @@ -153,7 +156,8 @@ export class Erc20DepositStarter extends BridgeTransferStarter {

public async approveNativeCurrency({
signer,
amount
amount,
options
}: ApproveNativeCurrencyProps) {
if (!this.sourceChainErc20Address) {
throw Error('Erc20 token address not found')
Expand Down Expand Up @@ -198,7 +202,9 @@ export class Erc20DepositStarter extends BridgeTransferStarter {
return erc20Bridger.approveGasToken({
erc20ParentAddress: this.sourceChainErc20Address,
parentSigner: signer,
amount: estimatedDestinationChainGasFee
amount: estimatedDestinationChainGasFee.add(
options?.approvalAmountIncrease ?? BigNumber.from(0)
)
})
}

Expand Down

0 comments on commit c511d18

Please sign in to comment.