Skip to content

Repository files navigation

aleo-contracts

Leo programs for batching record consolidation on Aleo before executing a transfer, for both native credits.aleo and stablecoins (usad, usdcx).

Overview

Three contract families, differentiated by the underlying asset and the recipient semantics of the final call:

Family Directory Final call Recipient Backing asset(s)
Private transfer private_transfer/ transfer_private arbitrary address (parameter) credits.aleo, usad_stablecoin.aleo, usdcx_stablecoin.aleo
Self transfer to public self_transfer_private_to_public/ transfer_private_to_public self.signer (caller only) credits.aleo
Transfer to public transfer_private_to_public/ transfer_private_to_public arbitrary address (public parameter) usad_stablecoin.aleo, usdcx_stablecoin.aleo

Within each family, programs are further split by record-count range because Leo limits function size by constraint count. credits.aleo-backed programs cover 2–14 records (split 2–8 / 9–10 / 11–14); stablecoin-backed programs cover 2–13 records (split 2–8 / 9–10 / 11–13).

credits.aleo transitions

private_transfer transitions (transfer_private_N):

  • Take N credits.aleo::credits records
  • Join them into a single record via repeated credits.aleo::join calls
  • Call credits.aleo::transfer_private(joined_record, recipient, amount)
  • Return (change: credits, output: credits) - no Final block; the transition is fully private

self_transfer_private_to_public transitions (transfer_private_to_public_N):

  • Take N credits.aleo::credits records and a public amount: u64
  • Join them into a single record
  • Call credits.aleo::transfer_private_to_public(joined_record, self.signer, amount)
  • Return (change: credits, Final) - Final executes the on-chain balance update, always crediting the caller

Stablecoin transitions (usad_stablecoin.aleo / usdcx_stablecoin.aleo)

private_transfer transitions (transfer_private_N):

  • Take N <token>.aleo::Token records, a recipient: address, amount: u128, and a proofs: [<token>.aleo::MerkleProof; 2] compliance proof
  • Join the records, then call <token>.aleo::transfer_private(recipient, amount, joined_record, proofs)
  • Return (ComplianceRecord, change: Token, output: Token, Final) - Final runs compliance/finalize logic even though the transfer itself stays private

transfer_private_to_public transitions (transfer_private_to_public_N):

  • Take N <token>.aleo::Token records, a public recipient: address, public amount: u128, and proofs
  • Join the records, then call <token>.aleo::transfer_private_to_public(recipient, amount, joined_record, proofs)
  • Return (ComplianceRecord, change: Token, Final)
  • Unlike the credits.aleo self-transfer family, recipient is a free parameter, not self.signer - hence these programs live under transfer_private_to_public/ rather than self_transfer_private_to_public/

Repository layout

external/
  credits.aleo                           # credits.aleo program source (reference)
  token_registry.aleo                    # token_registry.aleo program source (reference)

private_transfer/                        # transfer_private, arbitrary recipient
  ldgbatcher_2_8_records/                 # ldg_p_28.aleo         credits.aleo            (transitions 2-8)
  ldgbatcher_9_10_records/                # ldg_p_910.aleo        credits.aleo            (transitions 9-10)
  ldgbatcher_11_14_records/               # ldg_p_1114.aleo       credits.aleo            (transitions 11-14)
  usad_ldgbatcher_28_records/             # ldg_usad_p_28.aleo    usad_stablecoin.aleo    (transitions 2-8)
  usad_ldgbatcher_910_records/            # ldg_usad_p_910.aleo   usad_stablecoin.aleo    (transitions 9-10)
  usad_ldgbatcher_1113_records/           # ldg_usad_p_1113.aleo  usad_stablecoin.aleo    (transitions 11-13)
  usdcx_ldgbatcher_28_records/            # ldg_usdcx_p_28.aleo   usdcx_stablecoin.aleo   (transitions 2-8)
  usdcx_ldgbatcher_910_records/           # ldg_usdcx_p_910.aleo  usdcx_stablecoin.aleo   (transitions 9-10)
  usdcx_ldgbatcher_1113_records/          # ldg_usdcx_p_1113.aleo usdcx_stablecoin.aleo   (transitions 11-13)

self_transfer_private_to_public/         # transfer_private_to_public, recipient = self.signer
  ldgbatcher_2_8_records/                  # ldg_p2p_28.aleo       credits.aleo            (transitions 2-8)
  ldgbatcher_9_10_records/                 # ldg_p2p_910.aleo      credits.aleo            (transitions 9-10)
  ldgbatcher_11_14_records/                # ldg_p2p_1114.aleo     credits.aleo            (transitions 11-14)

transfer_private_to_public/              # transfer_private_to_public, arbitrary recipient
  usad_ldgbatcher_ppub_28_records/          # ldg_usad_p2p_28.aleo     usad_stablecoin.aleo   (transitions 2-8)
  usad_ldgbatcher_ppub_910_records/         # ldg_usad_p2p_910.aleo    usad_stablecoin.aleo   (transitions 9-10)
  usad_ldgbatcher_ppub_1113_records/        # ldg_usad_p2p_1113.aleo   usad_stablecoin.aleo   (transitions 11-13)
  usdcx_ldgbatcher_ppub_28_records/         # ldg_usdcx_p2p_28.aleo    usdcx_stablecoin.aleo  (transitions 2-8)
  usdcx_ldgbatcher_ppub_910_records/        # ldg_usdcx_p2p_910.aleo   usdcx_stablecoin.aleo  (transitions 9-10)
  usdcx_ldgbatcher_ppub_1113_records/       # ldg_usdcx_p2p_1113.aleo  usdcx_stablecoin.aleo  (transitions 11-13)

Each program directory contains:

  • src/main.leo - program source
  • program.json - Leo project manifest (name, version, dependencies)
  • .env.example - environment variable template (see Deploy)
  • build/, outputs/ - generated build/execution artifacts once you run leo build / leo execute (git-ignored)

Prerequisites

  • Leo ≥ 4.0 (leo --version)

Build

From any program directory (e.g. to build the 2–8 private-transfer program):

cd private_transfer/ldgbatcher_2_8_records
leo build

Repeat for each program you intend to deploy, e.g.:

cd private_transfer/ldgbatcher_9_10_records && leo build
cd private_transfer/ldgbatcher_11_14_records && leo build
cd private_transfer/usad_ldgbatcher_28_records && leo build
cd private_transfer/usad_ldgbatcher_910_records && leo build
cd private_transfer/usad_ldgbatcher_1113_records && leo build
cd private_transfer/usdcx_ldgbatcher_28_records && leo build
cd private_transfer/usdcx_ldgbatcher_910_records && leo build
cd private_transfer/usdcx_ldgbatcher_1113_records && leo build
cd self_transfer_private_to_public/ldgbatcher_2_8_records && leo build
cd self_transfer_private_to_public/ldgbatcher_9_10_records && leo build
cd self_transfer_private_to_public/ldgbatcher_11_14_records && leo build
cd transfer_private_to_public/usad_ldgbatcher_ppub_28_records && leo build
cd transfer_private_to_public/usad_ldgbatcher_ppub_910_records && leo build
cd transfer_private_to_public/usad_ldgbatcher_ppub_1113_records && leo build
cd transfer_private_to_public/usdcx_ldgbatcher_ppub_28_records && leo build
cd transfer_private_to_public/usdcx_ldgbatcher_ppub_910_records && leo build
cd transfer_private_to_public/usdcx_ldgbatcher_ppub_1113_records && leo build

Deploy

  1. Create a .env inside the program directory (copy .env.example where one exists, otherwise create it directly) and fill in your credentials:

    cp .env.example .env
    NETWORK=testnet
    PRIVATE_KEY=APrivateKey1...
    ENDPOINT=https://api.explorer.provable.com/v1
  2. Deploy from the program directory (to testnet):

    leo deploy --print --network testnet --broadcast

Leo reads NETWORK, PRIVATE_KEY, and ENDPOINT from .env and submits the deployment transaction.

Dependencies

All programs resolve their dependency directly from the network (declared in program.json) - no local path overrides are needed:

  • credits.aleo-backed programs (private_transfer/ldgbatcher_*, self_transfer_private_to_public/ldgbatcher_*) depend on credits.aleo.
  • Stablecoin-backed programs (*_ldgbatcher(_ppub)_* under private_transfer/ and transfer_private_to_public/) depend on usad_stablecoin.aleo or usdcx_stablecoin.aleo

Reference copies of the credits.aleo and token_registry.aleo program source live under external/ for lookup; they are not built or deployed from this repo.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages