@@ -18,6 +18,12 @@ import * as OFT from "../../utils/OFTUtils";
1818import { OFT_DEFAULT_FEE_CAP , OFT_FEE_CAP_OVERRIDES } from "../../common/Constants" ;
1919import { IOFT_ABI_FULL } from "../../common/ContractAddresses" ;
2020
21+ type OFTBridgeArguments = {
22+ sendParamStruct : OFT . SendParamStruct ;
23+ feeStruct : OFT . MessagingFeeStruct ;
24+ refundAddress : string ;
25+ } ;
26+
2127export class OFTBridge extends BaseBridgeAdapter {
2228 public readonly l2TokenAddress : string ;
2329 private readonly l1ChainEid : number ;
@@ -62,6 +68,36 @@ export class OFTBridge extends BaseBridgeAdapter {
6268 _l2Token : Address ,
6369 amount : BigNumber
6470 ) : Promise < BridgeTransactionDetails > {
71+ const { sendParamStruct, feeStruct, refundAddress } = await this . buildOftTransactionArgs (
72+ toAddress ,
73+ l1Token ,
74+ amount
75+ ) ;
76+ return {
77+ contract : this . l1Bridge ,
78+ method : "send" ,
79+ args : [ sendParamStruct , feeStruct , refundAddress ] ,
80+ value : BigNumber . from ( feeStruct . nativeFee ) ,
81+ } ;
82+ }
83+
84+ /**
85+ * Rounds send amount so that dust doesn't get subtracted from it in the OFT contract.
86+ * @param amount amount to round
87+ * @returns amount rounded down
88+ */
89+ async roundAmountToSend ( amount : BigNumber ) : Promise < BigNumber > {
90+ // Fetch `sharedDecimals` if not already fetched
91+ this . sharedDecimals ??= await this . l1Bridge . sharedDecimals ( ) ;
92+
93+ return OFT . roundAmountToSend ( amount , this . l1TokenInfo . decimals , this . sharedDecimals ) ;
94+ }
95+
96+ async buildOftTransactionArgs (
97+ toAddress : Address ,
98+ l1Token : EvmAddress ,
99+ amount : BigNumber
100+ ) : Promise < OFTBridgeArguments > {
65101 // Verify the token matches the one this bridge was constructed for
66102 assert (
67103 l1Token . eq ( this . l1TokenAddress ) ,
@@ -96,24 +132,12 @@ export class OFTBridge extends BaseBridgeAdapter {
96132 // Set refund address to signer's address. This should technically never be required as all of our calcs
97133 // are precise, set it just in case
98134 const refundAddress = await this . l1Bridge . signer . getAddress ( ) ;
99- return {
100- contract : this . l1Bridge ,
101- method : "send" ,
102- args : [ sendParamStruct , feeStruct , refundAddress ] ,
103- value : BigNumber . from ( feeStruct . nativeFee ) ,
104- } ;
105- }
106135
107- /**
108- * Rounds send amount so that dust doesn't get subtracted from it in the OFT contract.
109- * @param amount amount to round
110- * @returns amount rounded down
111- */
112- private async roundAmountToSend ( amount : BigNumber ) : Promise < BigNumber > {
113- // Fetch `sharedDecimals` if not already fetched
114- this . sharedDecimals ??= await this . l1Bridge . sharedDecimals ( ) ;
115-
116- return OFT . roundAmountToSend ( amount , this . l1TokenInfo . decimals , this . sharedDecimals ) ;
136+ return {
137+ sendParamStruct,
138+ feeStruct,
139+ refundAddress,
140+ } satisfies OFTBridgeArguments ;
117141 }
118142
119143 async queryL1BridgeInitiationEvents (
0 commit comments