Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Sep 10, 2024
2 parents e568aad + b557ef6 commit 7fc6a85
Show file tree
Hide file tree
Showing 28 changed files with 1,259 additions and 2,420 deletions.
31 changes: 31 additions & 0 deletions contracts/MockPolygonEvents.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file contains contracts that can be used to unit test the src/clients/bridges/ZkSyncAdapter.ts
// code which reads events from zkSync contracts facilitating cross chain transfers.

pragma solidity ^0.8.0;

contract Polygon_L1Bridge {
event LockedERC20(
address indexed depositor,
address indexed depositReceiver,
address indexed rootToken,
uint256 amount
);

event LockedEther(address indexed depositor, address indexed depositReceiver, uint256 amount);

function depositFor(address depositor, address depositReceiver, address rootToken, uint256 amount) external {
emit LockedERC20(depositor, depositReceiver, rootToken, amount);
}

function depositEtherFor(address depositor, address depositReceiver, uint256 amount) external {
emit LockedEther(depositor, depositReceiver, amount);
}
}

contract Polygon_L2Bridge {
event Transfer(address indexed from, address indexed to, uint256 value);

function transfer(address from, address to, uint256 value) external {
emit Transfer(from, to, value);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@across-protocol/constants": "^3.1.14",
"@across-protocol/contracts": "^3.0.10",
"@across-protocol/sdk": "^3.1.31",
"@across-protocol/sdk": "^3.1.33",
"@arbitrum/sdk": "^3.1.3",
"@aws-sdk/client-kms": "^3.592.0",
"@aws-sdk/client-s3": "^3.592.0",
Expand Down
10 changes: 6 additions & 4 deletions scripts/spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async function deposit(args: Record<string, number | string>, signer: Signer): P
}

async function fillDeposit(args: Record<string, number | string | boolean>, signer: Signer): Promise<boolean> {
const { txnHash, depositId: depositIdArg, execute } = args;
const { txnHash, depositId: depositIdArg, execute, slow } = args;
const originChainId = Number(args.chainId);

if (txnHash === undefined || typeof txnHash !== "string" || txnHash.length != 66 || !txnHash.startsWith("0x")) {
Expand Down Expand Up @@ -295,7 +295,9 @@ async function fillDeposit(args: Record<string, number | string | boolean>, sign
fromLiteChain: false, // Not relevant
toLiteChain: false, // Not relevant
};
const fill = await sdkUtils.populateV3Relay(destSpokePool, deposit, relayer);
const fill = isDefined(slow)
? await destSpokePool.populateTransaction.requestV3SlowFill(deposit)
: await sdkUtils.populateV3Relay(destSpokePool, deposit, relayer);

console.group("Fill Txn Info");
console.log(`to: ${fill.to}`);
Expand Down Expand Up @@ -459,7 +461,7 @@ function usage(badInput?: string): boolean {

const dumpConfigArgs = "--chainId";
const fetchArgs = "--chainId <chainId> [--depositId <depositId> | --txnHash <txnHash>]";
const fillArgs = "--chainId <originChainId> --txnHash <depositHash> [--depositId <depositId>] [--execute]";
const fillArgs = "--chainId <originChainId> --txnHash <depositHash> [--depositId <depositId>] [--slow] [--execute]";

const pad = "deposit".length;
usageStr += `
Expand Down Expand Up @@ -491,7 +493,7 @@ async function run(argv: string[]): Promise<number> {
const fetchDepositOpts = ["chainId", "depositId"];
const opts = {
string: ["wallet", ...configOpts, ...depositOpts, ...fetchOpts, ...fillOpts, ...fetchDepositOpts],
boolean: ["decimals", "execute"], // @dev tbd whether this is good UX or not...may need to change.
boolean: ["decimals", "execute", "slow"], // @dev tbd whether this is good UX or not...may need to change.
default: {
wallet: "secret",
decimals: false,
Expand Down
7 changes: 6 additions & 1 deletion src/adapter/BaseChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ export class BaseChainAdapter {
const augmentedTxn = { contract, chainId: this.chainId, method, args: [], value, mrkdwn, message };
if (simMode) {
const { succeed, reason } = (await this.transactionClient.simulate([augmentedTxn]))[0];
this.log("Simulation result", { succeed, reason, contract, value }, "debug", "wrapEthIfAboveThreshold");
this.log(
"Simulation result",
{ succeed, reason, contract: contract.address, value },
"debug",
"wrapEthIfAboveThreshold"
);
return { hash: ZERO_ADDRESS } as TransactionResponse;
} else {
(await this.transactionClient.submit(this.chainId, [augmentedTxn]))[0];
Expand Down
11 changes: 5 additions & 6 deletions src/adapter/bridges/PolygonERC20Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Provider,
bnToHex,
ZERO_ADDRESS,
getL2TokenAddresses,
} from "../../utils";
import { CONTRACT_ADDRESSES } from "../../common";
import { BridgeTransactionDetails, BaseBridgeAdapter, BridgeEvents } from "./BaseBridgeAdapter";
Expand All @@ -31,7 +30,6 @@ export class PolygonERC20Bridge extends BaseBridgeAdapter {
// TOKEN_SYMBOLS_MAP. This constructor will therefore break if
// either the SDK, or the constants dependency in the SDK, is not
// up-to-date.
const l2TokenAddresses = getL2TokenAddresses(l1Token);
const { address: l1Address, abi: l1Abi } = CONTRACT_ADDRESSES[hubChainId].polygonBridge;
const { address: l1GatewayAddress, abi: l1GatewayAbi } = CONTRACT_ADDRESSES[hubChainId].polygonRootChainManager;
super(l2chainId, hubChainId, l1Signer, l2SignerOrProvider, [l1Address]);
Expand All @@ -41,7 +39,8 @@ export class PolygonERC20Bridge extends BaseBridgeAdapter {

// For Polygon, we look for mint events triggered by the L2 token, not the L2 Bridge.
const l2Abi = CONTRACT_ADDRESSES[l2chainId].withdrawableErc20.abi;
this.l2Bridge = new Contract(l2TokenAddresses[l2chainId], l2Abi, l2SignerOrProvider);
const l2TokenAddress = this.resolveL2TokenAddress(l1Token);
this.l2Bridge = new Contract(l2TokenAddress, l2Abi, l2SignerOrProvider);
}

async constructL1ToL2Txn(
Expand All @@ -65,12 +64,12 @@ export class PolygonERC20Bridge extends BaseBridgeAdapter {
): Promise<BridgeEvents> {
const events = await paginatedEventQuery(
this.getL1Bridge(),
this.getL1Bridge().filters.LockedERC20(undefined, fromAddress, l1Token),
this.getL1Bridge().filters.LockedERC20(undefined, toAddress, l1Token),
eventConfig
);
return {
[this.resolveL2TokenAddress(l1Token)]: events.map((event) =>
processEvent(event, "amount", "depositorReceiver", "depositor")
processEvent(event, "amount", "depositReceiver", "depositor")
),
};
}
Expand All @@ -83,7 +82,7 @@ export class PolygonERC20Bridge extends BaseBridgeAdapter {
): Promise<BridgeEvents> {
const events = await paginatedEventQuery(
this.getL2Bridge(),
this.getL2Bridge().filters.Transfer(ZERO_ADDRESS, fromAddress),
this.getL2Bridge().filters.Transfer(ZERO_ADDRESS, toAddress),
eventConfig
);
return {
Expand Down
4 changes: 2 additions & 2 deletions src/adapter/bridges/PolygonWethBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class PolygonWethBridge extends BaseBridgeAdapter {
): Promise<BridgeEvents> {
const events = await paginatedEventQuery(
this.getL1Bridge(),
this.getL1Bridge().filters.LockedEther(undefined, fromAddress),
this.getL1Bridge().filters.LockedEther(undefined, toAddress),
eventConfig
);
return {
Expand All @@ -82,7 +82,7 @@ export class PolygonWethBridge extends BaseBridgeAdapter {
): Promise<BridgeEvents> {
const events = await paginatedEventQuery(
this.getL2Bridge(),
this.getL2Bridge().filters.Transfer(ZERO_ADDRESS, fromAddress),
this.getL2Bridge().filters.Transfer(ZERO_ADDRESS, toAddress),
eventConfig
);
return {
Expand Down
Loading

0 comments on commit 7fc6a85

Please sign in to comment.