Skip to content

Commit

Permalink
Merge pull request #9 from curvefi/feat/polygon-zkevm
Browse files Browse the repository at this point in the history
Polygon zkEVM bridger
  • Loading branch information
romanagureev authored Aug 22, 2024
2 parents 5c76df0 + d8a102d commit 2328fd6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
59 changes: 59 additions & 0 deletions contracts/bridgers/PolygonzkEVMBridger.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# @version 0.3.10
"""
@title Curve Polygon zkEVM Bridge Wrapper
"""
from vyper.interfaces import ERC20


interface PolygonZkEVMBridge:
def bridgeAsset(destination_network: uint32, destination_address: address, amount: uint256, token: address, force_update: bool, permit_data: Bytes[2]): nonpayable


CRV20: constant(address) = 0xD533a949740bb3306d119CC777fa900bA034cd52
L1_BRIDGE: immutable(PolygonZkEVMBridge)

DESTINATION_NETWORK: immutable(uint32)


@external
def __init__(_l1_bridge: PolygonZkEVMBridge, _network: uint32):
L1_BRIDGE = _l1_bridge
assert ERC20(CRV20).approve(_l1_bridge.address, max_value(uint256))

DESTINATION_NETWORK = _network


@external
def bridge(_token: ERC20, _to: address, _amount: uint256):
"""
@notice Bridge a token to Polygon zkEVM using built-in PolygonZkEVMBridge
@dev Might need `claimAsset` on destination chain, save `depositCount` from POLYGON_ZKEVM_BRIDGE.BridgeEvent
@param _token The token to bridge
@param _to The address to deposit the token to on L2
@param _amount The amount of the token to deposit
"""
assert _token.transferFrom(msg.sender, self, _amount)

if _token.allowance(self, L1_BRIDGE.address) < _amount:
_token.approve(L1_BRIDGE.address, max_value(uint256))

L1_BRIDGE.bridgeAsset(DESTINATION_NETWORK, _to, _amount, _token.address, True, b"")


@view
@external
def check(_account: address) -> bool:
"""
@notice Dummy method to check if caller is allowed to bridge
@param _account The account to check
"""
return True


@view
@external
def cost() -> uint256:
"""
@notice Cost in ETH to bridge
"""
return 0
17 changes: 17 additions & 0 deletions tests/forked/test_bridgers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,20 @@ def test_harmony_bridger(alice, crv_token, HarmonyBridger):
assert crv_token.balanceOf(harmony_bridge) == balance_before + 10**18
assert "Locked" in tx.events
assert tx.events["Locked"].values() == [crv_token, bridger, 10**18, alice]


def test_polygonzkevm_bridger(alice, crv_token, PolygonzkEVMBridger):
bridge = "0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe"
bridger = PolygonzkEVMBridger.deploy(bridge, 3, {"from": alice})

assert bridger.cost() == 0
assert bridger.check(alice) is True

crv_token.approve(bridger, 2**256 - 1, {"from": alice})

balance_before = crv_token.balanceOf(bridge)
tx = bridger.bridge(crv_token, alice, 10**18, {"from": alice})

assert crv_token.balanceOf(bridge) == balance_before + 10**18
assert "BridgeEvent" in tx.events
assert tx.events["BridgeEvent"].values()[2:5] == [crv_token, 3, bridger]

0 comments on commit 2328fd6

Please sign in to comment.