Skip to content

Commit

Permalink
feat(sdk): update SDK based on the new specs
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6e616d committed Aug 16, 2024
1 parent d99d0fc commit c4a3c87
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 399 deletions.
6 changes: 4 additions & 2 deletions packages/tokamak/sdk/src/adapters/eth-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export class ETHBridgeAdapter extends StandardBridgeAdapter {
}

if (opts?.recipient === undefined) {
return this.l1Bridge.populateTransaction.depositETH(
return this.l1Bridge.populateTransaction.bridgeETH(
amount,
opts?.l2GasLimit || 200_000, // Default to 200k gas limit.
'0x', // No data.
{
Expand All @@ -144,8 +145,9 @@ export class ETHBridgeAdapter extends StandardBridgeAdapter {
}
)
} else {
return this.l1Bridge.populateTransaction.depositETHTo(
return this.l1Bridge.populateTransaction.bridgeETHTo(
toAddress(opts.recipient),
amount,
opts?.l2GasLimit || 200_000, // Default to 200k gas limit.
'0x', // No data.
{
Expand Down
4 changes: 2 additions & 2 deletions packages/tokamak/sdk/src/adapters/native-token-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ export class NativeTokenBridgeAdapter extends StandardBridgeAdapter {

// NOTE: don't set the "value" because on ETH is native token in L1
if (opts?.recipient === undefined) {
return this.l1Bridge.populateTransaction.depositNativeToken(
return this.l1Bridge.populateTransaction.bridgeNativeToken(
amount,
opts?.l2GasLimit || 200_000, // Default to 200k gas limit.
'0x', // No data.
opts?.overrides || {}
)
} else {
return this.l1Bridge.populateTransaction.depositNativeTokenTo(
return this.l1Bridge.populateTransaction.bridgeNativeTokenTo(
toAddress(opts.recipient),
amount,
opts?.l2GasLimit || 200_000, // Default to 200k gas limit.
Expand Down
4 changes: 2 additions & 2 deletions packages/tokamak/sdk/src/adapters/standard-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class StandardBridgeAdapter implements IBridgeAdapter {
}

if (opts?.recipient === undefined) {
return this.l1Bridge.populateTransaction.depositERC20(
return this.l1Bridge.populateTransaction.bridgeERC20(
toAddress(l1Token),
toAddress(l2Token),
amount,
Expand All @@ -327,7 +327,7 @@ export class StandardBridgeAdapter implements IBridgeAdapter {
opts?.overrides || {}
)
} else {
return this.l1Bridge.populateTransaction.depositERC20To(
return this.l1Bridge.populateTransaction.bridgeERC20To(
toAddress(l1Token),
toAddress(l2Token),
toAddress(opts.recipient),
Expand Down
57 changes: 25 additions & 32 deletions packages/tokamak/sdk/src/cross-chain-messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ export class CrossChainMessenger {
* @param opts.overrides Optional transaction overrides.
* @returns Transaction response for the deposit transaction.
*/
public async depositETH(
public async bridgeETH(
amount: NumberLike,
opts?: {
recipient?: AddressLike
Expand All @@ -2000,7 +2000,7 @@ export class CrossChainMessenger {
}
): Promise<TransactionResponse> {
return (opts?.signer || this.l1Signer).sendTransaction(
await this.populateTransaction.depositETH(amount, opts)
await this.populateTransaction.bridgeETH(amount, opts)
)
}

Expand Down Expand Up @@ -2038,7 +2038,7 @@ export class CrossChainMessenger {
* @param opts.overrides Optional transaction overrides.
* @returns Transaction response for the deposit transaction.
*/
public async depositNativeToken(
public async bridgeNativeToken(
amount: NumberLike,
opts?: {
recipient?: AddressLike
Expand All @@ -2048,7 +2048,7 @@ export class CrossChainMessenger {
}
): Promise<TransactionResponse> {
return (opts?.signer || this.l1Signer).sendTransaction(
await this.populateTransaction.depositNativeToken(amount, opts)
await this.populateTransaction.bridgeNativeToken(amount, opts)
)
}

Expand Down Expand Up @@ -2159,7 +2159,7 @@ export class CrossChainMessenger {
* @param opts.overrides Optional transaction overrides.
* @returns Transaction response for the deposit transaction.
*/
public async depositERC20(
public async bridgeERC20(
l1Token: AddressLike,
l2Token: AddressLike,
amount: NumberLike,
Expand All @@ -2171,12 +2171,7 @@ export class CrossChainMessenger {
}
): Promise<TransactionResponse> {
return (opts?.signer || this.l1Signer).sendTransaction(
await this.populateTransaction.depositERC20(
l1Token,
l2Token,
amount,
opts
)
await this.populateTransaction.bridgeERC20(l1Token, l2Token, amount, opts)
)
}

Expand Down Expand Up @@ -2480,7 +2475,7 @@ export class CrossChainMessenger {
* @param isEstimatingGas Enable estimation gas
* @returns Transaction that can be signed and executed to deposit the ETH.
*/
depositETH: async (
bridgeETH: async (
amount: NumberLike,
opts?: {
recipient?: AddressLike
Expand All @@ -2493,7 +2488,7 @@ export class CrossChainMessenger {
if (isEstimatingGas) {
return opts
}
const gasEstimation = await this.estimateGas.depositETH(amount, opts)
const gasEstimation = await this.estimateGas.bridgeETH(amount, opts)
return {
...opts,
overrides: {
Expand Down Expand Up @@ -2545,7 +2540,7 @@ export class CrossChainMessenger {
* @param isEstimatingGas Enable estimation gas
* @returns Transaction that can be signed and executed to deposit the L2 Native Token.
*/
depositNativeToken: async (
bridgeNativeToken: async (
amount: NumberLike,
opts?: {
recipient?: AddressLike
Expand All @@ -2565,16 +2560,13 @@ export class CrossChainMessenger {

const from = (this.l1SignerOrProvider as Signer).getAddress()

const gasEstimation = await this.estimateGas.depositNativeToken(
amount,
{
...opts,
overrides: {
...opts?.overrides,
from: opts?.overrides?.from ?? from,
},
}
)
const gasEstimation = await this.estimateGas.bridgeNativeToken(amount, {
...opts,
overrides: {
...opts?.overrides,
from: opts?.overrides?.from ?? from,
},
})
return {
...opts,
overrides: {
Expand Down Expand Up @@ -2670,9 +2662,10 @@ export class CrossChainMessenger {
* @param opts.recipient Optional address to receive the funds on L2. Defaults to sender.
* @param opts.l2GasLimit Optional gas limit to use for the transaction on L2.
* @param opts.overrides Optional transaction overrides.
* @param isEstimatingGas determine to estimate gas.
* @returns Transaction that can be signed and executed to deposit the tokens.
*/
depositERC20: async (
bridgeERC20: async (
l1Token: AddressLike,
l2Token: AddressLike,
amount: NumberLike,
Expand All @@ -2694,7 +2687,7 @@ export class CrossChainMessenger {
throw new Error('unable to deposit without an l1 signer')
}
const from = (this.l1SignerOrProvider as Signer).getAddress()
const gasEstimation = await this.estimateGas.depositERC20(
const gasEstimation = await this.estimateGas.bridgeERC20(
l1Token,
l2Token,
amount,
Expand Down Expand Up @@ -2858,7 +2851,7 @@ export class CrossChainMessenger {
* @param opts.overrides Optional transaction overrides.
* @returns Gas estimate for the transaction.
*/
depositETH: async (
bridgeETH: async (
amount: NumberLike,
opts?: {
recipient?: AddressLike
Expand All @@ -2867,7 +2860,7 @@ export class CrossChainMessenger {
}
): Promise<BigNumber> => {
return this.l1Provider.estimateGas(
await this.populateTransaction.depositETH(amount, opts, true)
await this.populateTransaction.bridgeETH(amount, opts, true)
)
},

Expand Down Expand Up @@ -2902,7 +2895,7 @@ export class CrossChainMessenger {
* @param opts.overrides Optional transaction overrides.
* @returns Gas estimate for the transaction.
*/
depositNativeToken: async (
bridgeNativeToken: async (
amount: NumberLike,
opts?: {
recipient?: AddressLike
Expand All @@ -2911,7 +2904,7 @@ export class CrossChainMessenger {
}
): Promise<BigNumber> => {
return this.l1Provider.estimateGas(
await this.populateTransaction.depositNativeToken(amount, opts, true)
await this.populateTransaction.bridgeNativeToken(amount, opts, true)
)
},

Expand Down Expand Up @@ -2994,7 +2987,7 @@ export class CrossChainMessenger {
* @param opts.overrides Optional transaction overrides.
* @returns Gas estimate for the transaction.
*/
depositERC20: async (
bridgeERC20: async (
l1Token: AddressLike,
l2Token: AddressLike,
amount: NumberLike,
Expand All @@ -3005,7 +2998,7 @@ export class CrossChainMessenger {
}
): Promise<BigNumber> => {
return this.l1Provider.estimateGas(
await this.populateTransaction.depositERC20(
await this.populateTransaction.bridgeERC20(
l1Token,
l2Token,
amount,
Expand Down
Loading

0 comments on commit c4a3c87

Please sign in to comment.