-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(synapse-interface): refund RFQ transaction [SLT-272] (#3197)
* Txn transaction refund tracking * Update store to support tracking * Query FastBridge contract for `bridgeStatuses` to find refund status * Track bridge transaction `bridgeQuote.routerAddress` in store * Fetch FastBridge contract address when only provided router address * add translations
- Loading branch information
1 parent
d8338fe
commit f0b13bc
Showing
21 changed files
with
1,430 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
packages/synapse-interface/components/_Transaction/components/TransactionSupport.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/synapse-interface/components/_Transaction/helpers/useTxRefundStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { type Address } from 'viem' | ||
import { isNumber, isString } from 'lodash' | ||
import { useEffect, useState } from 'react' | ||
import { readContract } from '@wagmi/core' | ||
|
||
import { type Chain } from '@/utils/types' | ||
import { useIntervalTimer } from '@/utils/hooks/useIntervalTimer' | ||
import { wagmiConfig } from '@/wagmiConfig' | ||
import fastBridgeAbi from '@/constants/abis/fastBridge.json' | ||
import fastBridgeRouterAbi from '@/constants/abis/fastBridgeRouter.json' | ||
|
||
enum BridgeStatus { | ||
NULL, | ||
REQUESTED, | ||
RELAYER_PROVED, | ||
RELAYER_CLAIMED, | ||
REFUNDED, | ||
} | ||
|
||
export const useTxRefundStatus = ( | ||
txId: string | undefined, | ||
routerAddress: Address, | ||
chain: Chain, | ||
checkForRefund: boolean | ||
) => { | ||
const [isRefunded, setIsRefunded] = useState<boolean>(false) | ||
const currentTime = useIntervalTimer(600000) | ||
|
||
const getTxRefundStatus = async () => { | ||
try { | ||
const bridgeContract = await getRFQBridgeContract( | ||
routerAddress, | ||
chain?.id | ||
) | ||
|
||
const status = await checkRFQTxBridgeStatus( | ||
txId, | ||
bridgeContract as Address, | ||
chain?.id | ||
) | ||
|
||
if (status === BridgeStatus.REFUNDED) { | ||
setIsRefunded(true) | ||
} | ||
} catch (error) { | ||
console.error('Failed to get transaction refund status:', error) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
if (checkForRefund) { | ||
getTxRefundStatus() | ||
} | ||
}, [checkForRefund, txId, chain, currentTime]) | ||
|
||
return isRefunded | ||
} | ||
|
||
const getRFQBridgeContract = async ( | ||
routerAddress: Address, | ||
chainId: number | ||
): Promise<string | undefined> => { | ||
try { | ||
const fastBridgeAddress = await readContract(wagmiConfig, { | ||
abi: fastBridgeRouterAbi, | ||
address: routerAddress, | ||
functionName: 'fastBridge', | ||
chainId, | ||
}) | ||
|
||
if (!isString(fastBridgeAddress)) { | ||
throw new Error('Invalid address') | ||
} | ||
|
||
return fastBridgeAddress | ||
} catch (error) { | ||
throw new Error(error) | ||
} | ||
} | ||
|
||
const checkRFQTxBridgeStatus = async ( | ||
txId: string, | ||
bridgeContract: Address, | ||
chainId: number | ||
): Promise<number | undefined> => { | ||
try { | ||
const status = await readContract(wagmiConfig, { | ||
abi: fastBridgeAbi, | ||
address: bridgeContract, | ||
functionName: 'bridgeStatuses', | ||
args: [txId], | ||
chainId, | ||
}) | ||
|
||
if (!isNumber(status)) { | ||
throw new Error('Invalid status code') | ||
} | ||
|
||
return status | ||
} catch (error) { | ||
throw new Error(error) | ||
} | ||
} |
Oops, something went wrong.