Skip to content
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

WIP: feat: support dapp portal #6

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
}): Promise<PriorityOpResponse> {
const depositTx = await this.getDepositTx(transaction);

if (transaction.token == ETH_ADDRESS) {
const zksyncContract = await this.getMainContract();
const baseTokenAddress = await zksyncContract.baseTokenAddress();

if (transaction.token == baseTokenAddress) {
const baseGasLimit = await this.estimateGasRequestExecute(depositTx);
const gasLimit = scaleGasLimit(baseGasLimit);

Expand Down Expand Up @@ -278,7 +281,10 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
const depositTx = await this.getDepositTx(transaction);

let baseGasLimit: bigint;
if (transaction.token == ETH_ADDRESS) {

const zksyncContract = await this.getMainContract();
const baseTokenAddress = await zksyncContract.baseTokenAddress();
if (transaction.token == baseTokenAddress) {
baseGasLimit = await this.estimateGasRequestExecute(depositTx);
} else {
baseGasLimit = await this._providerL1().estimateGas(depositTx);
Expand Down Expand Up @@ -357,14 +363,24 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
tx.gasPerPubdataByte,
);

const baseTokenAddress = await zksyncContract.baseTokenAddress();

if (token == ETH_ADDRESS) {
checkBridgeWETHAllowed();
overrides.value ??= baseCost + BigInt(operatorTip) + BigInt(amount);

return {
contractAddress: to,
calldata: "0x",
l2Value: amount,
l2Value: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we don't need to update logic in the eth case because our chain doesn't use it. Keeps code less different with the upstream?

// For some reason typescript can not deduce that we've already set the tx.l2GasLimit
l2GasLimit: tx.l2GasLimit!,
...tx,
};
} else if (token == baseTokenAddress) {
return {
contractAddress: to,
calldata: "0x",
l2Value: 0,
// For some reason typescript can not deduce that we've already set the tx.l2GasLimit
l2GasLimit: tx.l2GasLimit!,
...tx,
Expand Down Expand Up @@ -702,6 +718,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
contractAddress: Address;
calldata: string;
l2GasLimit: BigNumberish;
amount: BigNumberish;
l2Value?: BigNumberish;
factoryDeps?: ethers.BytesLike[];
operatorTip?: BigNumberish;
Expand All @@ -718,6 +735,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
async estimateGasRequestExecute(transaction: {
contractAddress: Address;
calldata: string;
amount: BigNumberish;
l2GasLimit?: BigNumberish;
l2Value?: BigNumberish;
factoryDeps?: ethers.BytesLike[];
Expand All @@ -738,6 +756,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
async getRequestExecuteTx(transaction: {
contractAddress: Address;
calldata: string;
amount: BigNumberish;
l2GasLimit?: BigNumberish;
l2Value?: BigNumberish;
factoryDeps?: ethers.BytesLike[];
Expand Down Expand Up @@ -768,6 +787,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
overrides,
gasPerPubdataByte,
refundRecipient,
amount,
} = tx;

await insertGasPrice(this._providerL1(), overrides);
Expand All @@ -779,9 +799,9 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
gasLimit: l2GasLimit,
});

overrides.value ??= baseCost + BigInt(operatorTip) + BigInt(l2Value);

await checkBaseCost(baseCost, overrides.value);
// fee on L2 is subsctracted from the amount
// overrides.value ??= baseCost + BigInt(operatorTip) + BigInt(l2Value);
// await checkBaseCost(baseCost, overrides.value);

const l2Tx: L2TransactionStruct = {
l2Contract: contractAddress,
Expand All @@ -795,7 +815,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
calldata,
factoryDeps,
refundRecipient,
0,
amount,
overrides,
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ export function JsonRpcApiProvider<TBase extends Constructor<ethers.JsonRpcApiPr
tx.overrides.from ??= tx.from;

if (isETH(tx.token)) {
checkBridgeWETHAllowed();
if (!tx.overrides.value) {
tx.overrides.value = tx.amount;
}
Expand Down Expand Up @@ -384,7 +383,6 @@ export function JsonRpcApiProvider<TBase extends Constructor<ethers.JsonRpcApiPr
tx.overrides.from ??= tx.from;

if (tx.token == null || tx.token == ETH_ADDRESS) {
checkBridgeWETHAllowed();
return {
...tx.overrides,
to: tx.to,
Expand Down