YetAnotherBridge
  • 🌉Yet Another Bridge
  • About YAB
    • ⭐️ Features
    • 💻How does it work
    • ❓FAQ
  • Contracts
    • 💻Introduction
    • 🏦Escrow
      • 🏦Starknet
      • 🏦Zksync
    • 📜Payment Registry
    • 🔨Deploy
    • 📈Upgrade
    • ⛔️ Pause
  • Market Maker Bot
    • 🤖Introduction
    • 🤖Architecture
    • 🚀Deploy
  • Links
    • Telegram Group
    • Twitter/X
Powered by GitBook
On this page
  • Project Layout
  • How to Use
  • How does a User set a new order?
  • How does a MM detect a User's new order?
  • How does a MM claim his payment?
  1. Contracts
  2. Escrow

Starknet

PreviousEscrowNextZksync

Last updated 1 year ago

is a Smart Contract written in Cairo that resides in Ethereum's L2 , and is our implementation of our bridge's entity for this L2.

Project Layout

  • /src: Contains source files, Cairo smart contracts.

    • /src/test & /src/mocks: Test files.

  • /target: Autogenerated output files.

  • /scripts: Scripts for contract deployment and interaction.

  • /: Config files

How to Use

  • make deps: Installs dependencies

  • make starknet-build: Compiles contracts.

  • make starknet-deploy: Deploys using script /deploy/deploy.ts.

  • make starknet-connect: Connects itself to saved PaymentRegistry address.

  • make starknet-deploy-and-connect: Deploys and connects itself to saved PaymentRegistry address.

  • make ethereum-and-starknet-deploy: Deploys both smart contracts and connects them to each other.

  • make starknet-test: Runs local tests

How does a User set a new order?

This contract recieves User's new orders with the function:

fn set_order(ref self: ContractState, order: Order) -> u256

Which recieves an Order structure:

struct Order {
    recipient_address: EthAddress,
    amount: u256,
    fee: u256
}

And returns the new order's ID.

How does a MM detect a User's new order?

When a new order is set, the following SetOrder Event is emitted, detectable by MM's:

struct SetOrder {
    order_id: u256,
    recipient_address: EthAddress,
    amount: u256,
    fee: u256
}

How does a MM claim his payment?

#[l1_handler]
fn claim_payment(
    ref self: ContractState,
    from_address: felt252,
    order_id: u256,
    recipient_address: EthAddress,
    amount: u256
)
#[l1_handler]
fn claim_payment_batch(
    ref self: ContractState,
    from_address: felt252,
    orders: Array<(u256, EthAddress, u256)>
)

The claim_payment function is called, only by our , in order for the MM to retrieve its payment from the Escrow:

Alternatevly, the claim_payment_batch function is called, only by our , in order for the MM to retrieve many payments from the Escrow at once:

🏦
🏦
Escrow.cairo
Starknet
Escrow
Payment Registry
Payment Registry