-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK: Support for L2 direct bridging #798
Conversation
This is needed to fetch latest L2 contracts.
Here we enhance the SDK to support cross-chain contracts. We are achieving this by introducing a new `crossChainContracts` method exposed by the main `TBTC` component. This method allows to obtain cross-chain contracts handles for a specific supported L2 chain. This feature will serve as a base to write a cross-chain Bitcoin depositor component that will be used for direct bridging of deposits initiated on supported L2 chains. By the way, we are taking an opportunity and refactor the chain representation used across the SDK. Namely, we are getting rid of the `EthereumNetwork` type, and we are replacing it with a global `Chains` namespace that aggregates all chains supported by the tBTC v2 SDK.
Here we expose a possibility to initiate cross-chain deposit that targets an L2 chain other than the L1 chain the tBTC system is deployed on. This is achieved by exposing the `initiateCrossChainDeposit` method on the `DepositsService` component.
256ac99
to
119335b
Compare
The previous `@keep-network/tbtc-v2` upgrade bumped up a lot of dependencies. Some changes around Ethers turned out to be breaking for unit tests. Here we revert the unnecessary upgrades.
404b721
to
86bded9
Compare
86bded9
to
5b365f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🔥
const artifactLoader = { | ||
getMainnet: (l2ChainName: L2Chain) => { | ||
switch (l2ChainName) { | ||
// TODO: Uncomment once BaseL1BitcoinDepositor is available on Ethereum mainnet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not forget about those TODOs, when the mainnet contracts will be available on Ethereum mainnet. I assume it's a non-blocking issue and we can merge anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. We will open another PR just before the release.
Closes: #750
This pull request enhances the tBTC Typescript SDK with support of the L2 direct bridging mechanism introduced by #792. Moreover, we are adding Base as the first L2 chain with direct bridging enabled.
Initialization of the cross-chain contracts
To enable the SDK to work with a supported L2 chain, we introduce a new
initializeCrossChain
method that is exposed from the mainTBTC
component. This function sets up the SDK to work with the given L2 chain and attaches the provided signer to the tBTC cross-chain contracts deployed there. It's worth noting that the signer can be read-only (e.g. Ethers provider) but in that case, only read functions of the L2 contracts will be available.After initialization, the cross-chain contracts for the given chain can be directly accessed using the new
TBTC.crossChainContracts
method. This low-level access method is especially useful for reading data, e.g. get canonical L2 TBTC balance for the given address.Cross-chain deposits
To leverage the new L2 direct bridging mechanism, the SDK adds the concept of a cross-chain deposit. A cross-chain deposit is a deposit that targets an L2 chain other than the L1 chain the tBTC system is deployed on. Such a deposit is currently initiated using a transaction on the L2 chain (plans for the future include gas-less initiation). On the technical level, this is handled by the new
initiateCrossChainDeposit
method exposed by theDepositsService
component.Usage