-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad662b0
commit d792e27
Showing
4 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters