Skip to content

Commit

Permalink
chore: update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
romanagureev committed May 6, 2024
1 parent ad662b0 commit d792e27
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 7 deletions.
29 changes: 29 additions & 0 deletions scripts/polygon_zkevm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Deploy
1. Deploy `Agent` blueprint

```bash
ape run deploy_agent --network <destination network>
```

2. Deploy `Relayer` and `Vault`

```bash
ape run polygon_zkevm deploy --blueprint <AGENT_BLUEPRINT_ADDRESS> --network <destination network>
```

3. Deploy `Broadcaster`

```bash
ape run polygon_zkevm deploy --network <origin network> --destination_chain_id <destination network chain ID>
```

## Claim message on destination chain
Save `depositCount` from PolygonZkEVMBridge.BridgeEvent to claim message on destination chain:
```bash
ape run polygon_zkevm claim_message --deposit_cnt <depositCount> --network <network>
```

Example:
```bash
ape run polygon_zkevm claim_message --deposit_cnt 189238 --network https://rpc.xlayer.tech
```
31 changes: 31 additions & 0 deletions scripts/polygon_zkevm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ape.api import ProviderAPI

POLYGON_ZKEVM_BRIDGE = "0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe"
BRIDGE_ABI = [
{"constant": False, "inputs": [
{"indexed": False, "internalType": "bytes32[32]", "name": "smtProofLocalExitRoot", "type": "bytes32[32]"},
{"indexed": False, "internalType": "bytes32[32]", "name": "smtProofRollupExitRoot", "type": "bytes32[32]"},
{"indexed": False, "internalType": "uint256", "name": "globalIndex", "type": "uint256"},
{"indexed": False, "internalType": "bytes32", "name": "mainnetExitRoot", "type": "bytes32"},
{"indexed": False, "internalType": "bytes32", "name": "rollupExitRoot", "type": "bytes32"},
{"indexed": False, "internalType": "uint32", "name": "originNetwork", "type": "uint32"},
{"indexed": False, "internalType": "address", "name": "originAddress", "type": "address"},
{"indexed": False, "internalType": "uint32", "name": "destinationNetwork", "type": "uint32"},
{"indexed": False, "internalType": "address", "name": "destinationAddress", "type": "address"},
{"indexed": False, "internalType": "uint256", "name": "amount", "type": "uint256"},
{"indexed": False, "internalType": "bytes", "name": "metadata", "type": "bytes"}], "name": "claimMessage",
"outputs": [], "payable": False, "stateMutability": "nonpayable", "type": "function"},
]


def get_destination_network(destination_chain_id: int | str):
if int(destination_chain_id) == 196: # xlayer
return 3
raise "Unknown destination chain id"


def get_bridge_url(provider: ProviderAPI):
rpc = provider.http_uri # try
if provider.chain_id == 196: # xlayer
rpc = "https://rpc.xlayer.tech"
return rpc + "/priapi/v1/ob/bridge"
47 changes: 47 additions & 0 deletions scripts/polygon_zkevm/claim_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import click
import requests

from ape import project, Contract
from ape.cli import ConnectedProviderCommand, account_option, network_option

from . import BRIDGE_ABI, POLYGON_ZKEVM_BRIDGE, get_bridge_url


@click.command(cls=ConnectedProviderCommand)
@account_option()
@network_option()
@click.option("--deposit_cnt")
def cli(account, network, deposit_cnt):
chain_id = project.provider.chain_id

if chain_id not in (1,):
bridge = Contract(POLYGON_ZKEVM_BRIDGE, abi=BRIDGE_ABI)
url = get_bridge_url(project.provider)

status = requests.get(
url=f"{url}/bridge",
params={"net_id": 0, "deposit_cnt": int(deposit_cnt)},
).json()["deposit"]
if not status["ready_for_claim"]:
raise "Not ready yet"

proof = requests.get(
url=f"{url}/merkle-proof",
params={"net_id": 0, "deposit_cnt": int(deposit_cnt)},
).json()

bridge.claimMessage(
proof["proof"]["merkle_proof"],
proof["proof"]["rollup_merkle_proof"],
status["global_index"],
proof["proof"]["main_exit_root"],
proof["proof"]["rollup_exit_root"],
status["orig_net"],
status["orig_addr"],
status["dest_net"],
status["dest_addr"],
status["amount"],
status["metadata"],
gas_price=project.provider.gas_price,
sender=account,
)
11 changes: 4 additions & 7 deletions scripts/polygon_zkevm.py → scripts/polygon_zkevm/deploy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import click
from ape import project
from ape.cli import NetworkBoundCommand, account_option, network_option
from ape.cli import ConnectedProviderCommand, account_option, network_option

from . import POLYGON_ZKEVM_BRIDGE, get_destination_network

POLYGON_ZKEVM_BRIDGE = "0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe"


@click.command(cls=NetworkBoundCommand)
@click.command(cls=ConnectedProviderCommand)
@account_option()
@network_option()
@click.option("--blueprint")
Expand Down Expand Up @@ -35,10 +34,8 @@ def cli(account, network, blueprint, destination_chain_id):
"0x467947EE34aF926cF1DCac093870f613C96B1E0c",
)

if int(destination_chain_id) == 196: # xlayer
destination_network = 3
return project.PolygonzkEVMBroadcaster.deploy(
admins, POLYGON_ZKEVM_BRIDGE, destination_network,
admins, POLYGON_ZKEVM_BRIDGE, get_destination_network(destination_chain_id),
sender=account,
max_priority_fee="1 gwei",
max_fee="20 gwei",
Expand Down

0 comments on commit d792e27

Please sign in to comment.