github.com/ethereum-optimism/optimism@v1.7.2/packages/sdk/src/interfaces/bridge-adapter.ts (about) 1 import { 2 Contract, 3 Overrides, 4 Signer, 5 BigNumber, 6 CallOverrides, 7 PayableOverrides, 8 } from 'ethers' 9 import { 10 TransactionRequest, 11 TransactionResponse, 12 BlockTag, 13 } from '@ethersproject/abstract-provider' 14 15 import { NumberLike, AddressLike, TokenBridgeMessage } from './types' 16 import { CrossChainMessenger } from '../cross-chain-messenger' 17 18 /** 19 * Represents an adapter for an L1<>L2 token bridge. Each custom bridge currently needs its own 20 * adapter because the bridge interface is not standardized. This may change in the future. 21 */ 22 export interface IBridgeAdapter { 23 /** 24 * Provider used to make queries related to cross-chain interactions. 25 */ 26 messenger: CrossChainMessenger 27 28 /** 29 * L1 bridge contract. 30 */ 31 l1Bridge: Contract 32 33 /** 34 * L2 bridge contract. 35 */ 36 l2Bridge: Contract 37 38 /** 39 * Gets all deposits for a given address. 40 * 41 * @param address Address to search for messages from. 42 * @param opts Options object. 43 * @param opts.fromBlock Block to start searching for messages from. If not provided, will start 44 * from the first block (block #0). 45 * @param opts.toBlock Block to stop searching for messages at. If not provided, will stop at the 46 * latest known block ("latest"). 47 * @returns All deposit token bridge messages sent by the given address. 48 */ 49 getDepositsByAddress( 50 address: AddressLike, 51 opts?: { 52 fromBlock?: BlockTag 53 toBlock?: BlockTag 54 } 55 ): Promise<TokenBridgeMessage[]> 56 57 /** 58 * Gets all withdrawals for a given address. 59 * 60 * @param address Address to search for messages from. 61 * @param opts Options object. 62 * @param opts.fromBlock Block to start searching for messages from. If not provided, will start 63 * from the first block (block #0). 64 * @param opts.toBlock Block to stop searching for messages at. If not provided, will stop at the 65 * latest known block ("latest"). 66 * @returns All withdrawal token bridge messages sent by the given address. 67 */ 68 getWithdrawalsByAddress( 69 address: AddressLike, 70 opts?: { 71 fromBlock?: BlockTag 72 toBlock?: BlockTag 73 } 74 ): Promise<TokenBridgeMessage[]> 75 76 /** 77 * Checks whether the given token pair is supported by the bridge. 78 * 79 * @param l1Token The L1 token address. 80 * @param l2Token The L2 token address. 81 * @returns Whether the given token pair is supported by the bridge. 82 */ 83 supportsTokenPair( 84 l1Token: AddressLike, 85 l2Token: AddressLike 86 ): Promise<boolean> 87 88 /** 89 * Queries the account's approval amount for a given L1 token. 90 * 91 * @param l1Token The L1 token address. 92 * @param l2Token The L2 token address. 93 * @param signer Signer to query the approval for. 94 * @returns Amount of tokens approved for deposits from the account. 95 */ 96 approval( 97 l1Token: AddressLike, 98 l2Token: AddressLike, 99 signer: Signer 100 ): Promise<BigNumber> 101 102 /** 103 * Approves a deposit into the L2 chain. 104 * 105 * @param l1Token The L1 token address. 106 * @param l2Token The L2 token address. 107 * @param amount Amount of the token to approve. 108 * @param signer Signer used to sign and send the transaction. 109 * @param opts Additional options. 110 * @param opts.overrides Optional transaction overrides. 111 * @returns Transaction response for the approval transaction. 112 */ 113 approve( 114 l1Token: AddressLike, 115 l2Token: AddressLike, 116 amount: NumberLike, 117 signer: Signer, 118 opts?: { 119 overrides?: Overrides 120 } 121 ): Promise<TransactionResponse> 122 123 /** 124 * Deposits some tokens into the L2 chain. 125 * 126 * @param l1Token The L1 token address. 127 * @param l2Token The L2 token address. 128 * @param amount Amount of the token to deposit. 129 * @param signer Signer used to sign and send the transaction. 130 * @param opts Additional options. 131 * @param opts.recipient Optional address to receive the funds on L2. Defaults to sender. 132 * @param opts.l2GasLimit Optional gas limit to use for the transaction on L2. 133 * @param opts.overrides Optional transaction overrides. 134 * @returns Transaction response for the deposit transaction. 135 */ 136 deposit( 137 l1Token: AddressLike, 138 l2Token: AddressLike, 139 amount: NumberLike, 140 signer: Signer, 141 opts?: { 142 recipient?: AddressLike 143 l2GasLimit?: NumberLike 144 overrides?: Overrides 145 } 146 ): Promise<TransactionResponse> 147 148 /** 149 * Withdraws some tokens back to the L1 chain. 150 * 151 * @param l1Token The L1 token address. 152 * @param l2Token The L2 token address. 153 * @param amount Amount of the token to withdraw. 154 * @param signer Signer used to sign and send the transaction. 155 * @param opts Additional options. 156 * @param opts.recipient Optional address to receive the funds on L1. Defaults to sender. 157 * @param opts.overrides Optional transaction overrides. 158 * @returns Transaction response for the withdraw transaction. 159 */ 160 withdraw( 161 l1Token: AddressLike, 162 l2Token: AddressLike, 163 amount: NumberLike, 164 signer: Signer, 165 opts?: { 166 recipient?: AddressLike 167 overrides?: Overrides 168 } 169 ): Promise<TransactionResponse> 170 171 /** 172 * Object that holds the functions that generate transactions to be signed by the user. 173 * Follows the pattern used by ethers.js. 174 */ 175 populateTransaction: { 176 /** 177 * Generates a transaction for approving some tokens to deposit into the L2 chain. 178 * 179 * @param l1Token The L1 token address. 180 * @param l2Token The L2 token address. 181 * @param amount Amount of the token to approve. 182 * @param opts Additional options. 183 * @param opts.overrides Optional transaction overrides. 184 * @returns Transaction that can be signed and executed to deposit the tokens. 185 */ 186 approve( 187 l1Token: AddressLike, 188 l2Token: AddressLike, 189 amount: NumberLike, 190 opts?: { 191 overrides?: Overrides 192 } 193 ): Promise<TransactionRequest> 194 195 /** 196 * Generates a transaction for depositing some tokens into the L2 chain. 197 * 198 * @param l1Token The L1 token address. 199 * @param l2Token The L2 token address. 200 * @param amount Amount of the token to deposit. 201 * @param opts Additional options. 202 * @param opts.recipient Optional address to receive the funds on L2. Defaults to sender. 203 * @param opts.l2GasLimit Optional gas limit to use for the transaction on L2. 204 * @param opts.overrides Optional transaction overrides. 205 * @returns Transaction that can be signed and executed to deposit the tokens. 206 */ 207 deposit( 208 l1Token: AddressLike, 209 l2Token: AddressLike, 210 amount: NumberLike, 211 opts?: { 212 recipient?: AddressLike 213 l2GasLimit?: NumberLike 214 overrides?: PayableOverrides 215 } 216 ): Promise<TransactionRequest> 217 218 /** 219 * Generates a transaction for withdrawing some tokens back to the L1 chain. 220 * 221 * @param l1Token The L1 token address. 222 * @param l2Token The L2 token address. 223 * @param amount Amount of the token to withdraw. 224 * @param opts Additional options. 225 * @param opts.recipient Optional address to receive the funds on L1. Defaults to sender. 226 * @param opts.overrides Optional transaction overrides. 227 * @returns Transaction that can be signed and executed to withdraw the tokens. 228 */ 229 withdraw( 230 l1Token: AddressLike, 231 l2Token: AddressLike, 232 amount: NumberLike, 233 opts?: { 234 recipient?: AddressLike 235 overrides?: Overrides 236 } 237 ): Promise<TransactionRequest> 238 } 239 240 /** 241 * Object that holds the functions that estimates the gas required for a given transaction. 242 * Follows the pattern used by ethers.js. 243 */ 244 estimateGas: { 245 /** 246 * Estimates gas required to approve some tokens to deposit into the L2 chain. 247 * 248 * @param l1Token The L1 token address. 249 * @param l2Token The L2 token address. 250 * @param amount Amount of the token to approve. 251 * @param opts Additional options. 252 * @param opts.overrides Optional transaction overrides. 253 * @returns Gas estimate for the transaction. 254 */ 255 approve( 256 l1Token: AddressLike, 257 l2Token: AddressLike, 258 amount: NumberLike, 259 opts?: { 260 overrides?: CallOverrides 261 } 262 ): Promise<BigNumber> 263 264 /** 265 * Estimates gas required to deposit some tokens into the L2 chain. 266 * 267 * @param l1Token The L1 token address. 268 * @param l2Token The L2 token address. 269 * @param amount Amount of the token to deposit. 270 * @param opts Additional options. 271 * @param opts.recipient Optional address to receive the funds on L2. Defaults to sender. 272 * @param opts.l2GasLimit Optional gas limit to use for the transaction on L2. 273 * @param opts.overrides Optional transaction overrides. 274 * @returns Gas estimate for the transaction. 275 */ 276 deposit( 277 l1Token: AddressLike, 278 l2Token: AddressLike, 279 amount: NumberLike, 280 opts?: { 281 recipient?: AddressLike 282 l2GasLimit?: NumberLike 283 overrides?: CallOverrides 284 } 285 ): Promise<BigNumber> 286 287 /** 288 * Estimates gas required to withdraw some tokens back to the L1 chain. 289 * 290 * @param l1Token The L1 token address. 291 * @param l2Token The L2 token address. 292 * @param amount Amount of the token to withdraw. 293 * @param opts Additional options. 294 * @param opts.recipient Optional address to receive the funds on L1. Defaults to sender. 295 * @param opts.overrides Optional transaction overrides. 296 * @returns Gas estimate for the transaction. 297 */ 298 withdraw( 299 l1Token: AddressLike, 300 l2Token: AddressLike, 301 amount: NumberLike, 302 opts?: { 303 recipient?: AddressLike 304 overrides?: CallOverrides 305 } 306 ): Promise<BigNumber> 307 } 308 }