bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 13쪽 중 7쪽
will affect blockchain state
* **Gas Optimization**: Fine-tune gas limits and pricing strategies
* **Risk Management**: Prevent failed transactions and unexpected behaviors
### Providers
#### Tenderly
{% embed url="<https://docs.tenderly.co/node/rpc-reference/zircuit#integrations>" %}
# GUD Trading Engine (Beta)
### What's the Trading Engine?
The Trading Engine is a cross-chain trading infrastructure that aggregates liquidity across multiple blockchain networks and bridge protocols to provide users with the best possible rates for their trades.
#### Key Features
* **Multi-Protocol Integration**: Connects to leading cross-chain protocols like Across, deBridge, and more to ensure competitive pricing
* **Best Quote Aggregation**: Automatically compares quotes across all integrated protocols and returns the most favorable rate
* **Direct Wallet Execution**: Users maintain full custody - trades are executed directly from their wallets without intermediaries
* **Gasless Options**: Integrators can provide users with a gasless trading experience using off-chain EIP712 signatures
* **Universal Token Support**: Trade any token across supported chains with automatic routing and bridging
* **Fee Transparency**: Clear fee structure with customizable integrator fees
# API Endpoint
## Core Endpoints
### Base URL
```
https://trading.ai.zircuit.com/api/engine/v1
```
### Authentication
All API requests require authentication using a Bearer token.
```bash
Authorization: Bearer API_KEY
```
> <mark style="color:blue;">**ⓘ Info**</mark>
>
> Contact the team to get the API\_KEY, these are also shared in hackathons!
### Methods
#### 1. Get Trade Estimate
Get a quote and all necessary data to execute a trade directly from a user's wallet, or make your user sign it and use your own relayer to provide gasless experience.
```http
POST /order/estimate
```
**Request Body**
For example, a trade of 1 USDC from Base to USDT in Optimism:
```json
{
"srcChainId": 8453,
"srcToken": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"srcAmountWei": "1000000",
"destChainId": 10,
"destToken": "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58",
"slippageBps": "100",
"userAccount": "0x...",
"destReceiver": "0x...",
"feeRecipient": "0x...",
"feeBps": "100"
}
```
> <mark style="color:blue;">**ⓘ Info**</mark>
>
> Use this special addresses for native tokens: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`
**Parameters**
| Parameter | Type | Required | Description |
| -------------- | ------ | -------- | --------------------------------------------------------- |
| `srcChainId` | number | Yes | Source chain ID |
| `srcToken` | string | Yes | Source token contract address |
| `srcAmountWei` | string | Yes | Amount in wei (string to handle large numbers) |
| `destChainId` | number | Yes | Destination chain ID |
| `destToken` | string | Yes | Destination token contract address |
| `slippageBps` | number | Yes | Slippage tolerance over the estimated output token amount |
| `userAccount` | string | Yes | User's wallet address |
| `destReceiver` | string | Yes | Recipient address on destination chain |
| `feeRecipient` | string | No | Fee recipient address on SOURCE chain |
| `feeBps` | string | No | Fee percentage over the input token amount |
**Example response**
```json
{
"message": "Trade estimate determined",
"data": {
"trade": {
"tradeId": "0x1234...abcd",
"nonce": "1",
"userAccount": "0x1234567890123456789012345678901234567890",
"destReceiver": "0x1234567890123456789012345678901234567890",
"srcToken": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"srcTokenAmount": "1000000000",
"srcChainId": 8453,
"destToken": "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
"destTokenAmount": "995000000",
"destTokenMinAmount": "993000000",
"destChainId": 10,
"adapter": "0xAdapterAddress",
"protocolNativeFee": "0",
"data": "0x...",
"deadline": 1699127056,
"fees": [
{
"bps": 100,
"recipient": "0x1234567890123456789012345678901234567890"
},
{
"bps": 25,
"recipient": "0xprotocol_fee_recipient"
}
],
"guardianSignature": "0xabcde...",
"eip712": {
"types": {
"EIP712Domain": [...],
"Fee": [...],
"Trade": [...]
},
"domain": {
"name": "GudEngine",
"version": "1.0.0",
"chainId": 8453,
"verifyingContract": "0xGudEngineAddress"
},
"message": {
"tradeId": "0x1234...abcd",
"nonce": 1,
"userAccount": "0x1234567890123456789012345678901234567890",
"destReceiver": "0x0x0000000000000000000000001234567890123456789012345678901234567890",
"srcToken": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"srcTokenAmount": "1000000000",
"srcChainId": 8453,
"destToken": "0x0x0000000000000000000000007F5c764cBc14f9669B88837ca1490cCa17c31607",
"destTokenMinAmount": "993000000",
"destChainId": 10,
"adapter": "0xAdapterAddress",
"protocolNativeFee": "0",
"data": "0x...",
"deadline": 1699127056,
"fees": [...],
"guardianSignature": "0xabcde..."
},
"primaryType": "Trade"
}
},
"tx": {
"chainId": 8453,
"data": "0x1234abcd...", // Encoded calldata for GudEngine.execute()
"from": "0x1234567890123456789012345678901234567890",
"to": "0xGudEngineContractAddress",
"value": "0" // ETH value to send (usually 0 for ERC20)
}
}
}
```
### Fee Structure
#### Integrator Fees
You can specify optional custom fees for your integration. The user will be charged a percentage of input tokens:
* `feeRecipient`: Your fee recipient address in **source** chain
* `feeBps`: Fee percentage in basis points (1 BPS = 0.01%, 10000 BPS = 100%)
`feeRecipient` will receive the fees in the same transaction.
#### Protocol Fees
The protocol supports adding a fee to support the infrastructure. It is not enabled at the moment.
# Supported Chains & Contract Addresses
## Mainnets
<table><thead><tr><th width="172.12890625">Chain</th><th width="98.0703125">ID</th><th>GudEngine Address</th></tr></thead><tbody><tr><td>Ethereum Mainnet</td><td>1</td><td>0x0792C46723d479D4C29De5D78D93C0146EdF3f5B</td></tr><tr><td>Base</td><td>8453</td><td>0x0792C46723d479D4C29De5D78D93C0146EdF3f5B</td></tr><tr><td>Zircuit</td><td>48900</td><td>0x0792C46723d479D4C29De5D78D93C0146EdF3f5B</td></tr><tr><td>OP Mainnet</td><td>10</td><td>0x0792C46723d479D4C29De5D78D93C0146EdF3f5B</td></tr><tr><td>Arbitrum One</td><td>42161</td><td>0x0792C46723d479D4C29De5D78D93C0146EdF3f5B</td></tr></tbody></table>
## Testnets
<table><thead><tr><th width="171.63671875">Chain</th><th width="97.390625">ID</th><th>GudEngine Address</th></tr></thead><tbody><tr><td>Sepolia</td><td>11155111</td><td>0x7Fd9F1BBFF0f12822Dce087D4020310b06a01F70</td></tr><tr><td>Base Sepolia</td><td>84532</td><td>0x7Fd9F1BBFF0f12822Dce087D4020310b06a01F70</td></tr><tr><td>OP Sepolia</td><td>11155420</td><td>0x7Fd9F1BBFF0f12822Dce087D4020310b06a01F70</td></tr><tr><td>Arbitrum Sepolia</td><td>421614</td><td>0x7Fd9F1BBFF0f12822Dce087D4020310b06a01F70</td></tr></tbody></table>
> <mark style="color:blue;">**ⓘ Info**</mark>
>
> In Testnets the liquidity is limited, and the majority of the tokens will not be available. Slippage/fees can be high in some providers to avoid abuse. Consider using just native ETH as source and destination in small amounts for cross chain testing.
# Development Guide
This page describes how to execute GUD Engine trade in a few steps.
## Step 1: Get Trade Estimate
Call the `/order/estimate` endpoint to get a quote and transaction data.
## Step 2: Handle ERC20 Approvals
For ERC20 tokens, remember to check if the user has sufficient allowance for the GudEngine contract:
```javascript
// Check current allowance
const allowance = await erc20Contract.allowance(userAddress, gudEngineAddress);
if (allowance < srcAmountWei) {
// Request approval
await erc20Contract.approve(gudEngineAddress, srcAmountWei);
}
```
## Step 3: Transaction Execution
Gud Engine allows your users to execute trade - either directly by themselves or in a gasless fashion. We will explain both cases below.
### Case 1: User executing the transaction
Signatures are not needed if the address calling the engine is the trader. The backend provide calldata ready to be executed:
```javascript
const txHash = await userWallet.sendTransaction({
to: tx.to,
data: tx.data,
value: tx.value
});
```
### Case 2: Gasless Execution For Your Users
Protocol allow relayers to execute ERC-20 trades on behalf of traders by using off-chain signatures. User trading must sign the data contained in `trade.eip712` object using user's wallet. `trade.eip712` object is formatted to be compatible with main blockchain libraries like viem or ethers.
> <mark style="color:blue;">**ⓘ Info**</mark>\
> This flow is only available for trades with ERC-20 tokens as source token. For trades with native ETH as source token, `trade.eip712` object will be `undefined` in the estimated quote.
```javascript
const userSignature = await userWallet.signTypedData({
types: eip712.types,
domain: eip712.domain,
message: eip712.message,
primaryType: eip712.primaryType
});
```
Update the calldata with the user's signature and send the transaction:
```javascript
const tradeStruct = {
...estimate.data.trade.eip712.message, // This contains all the trade data
signature: userSignature, // User's signature of the trade
};
// Encode the final calldata
const calldata = encodeFunctionData({
abi: gudEngineAbi, // Find it at the end of this document
functionName: 'execute',
args: [tradeStruct]
});
// Send the transaction from any account
const txHash = await relayerWallet.sendTransaction({
to: estimate.data.tx.to,
data: calldata,
value: 0
// WARNING: Your relayer should not send native ETH in behalf of users. Otherwise, your relayer account will be paying the trade instead of the user!
// A trade with native ETH as input token could drain your relayer account!
});
```
> **⚠ Warning**\
> Your relayer should not send native ETH in behalf of users. Otherwise, your relayer account will be paying the trade instead of the user!
### Error Handling
#### Common Error Codes
<table><thead><tr><th width="143.02734375">Status Code</th><th>Error</th><th>Description</th></tr></thead><tbody><tr><td>400</td><td>Bad Request</td><td>Invalid request parameters</td></tr><tr><td>401</td><td>Unauthorized</td><td>Missing or invalid API key</td></tr><tr><td>404</td><td>Not Found</td><td>No quotes found for the requested trade</td></tr><tr><td>429</td><td>Too Many Requests</td><td>Rate Limit Exceeded</td></tr><tr><td>500</td><td>Internal Server Error</td><td>Server error during processing</td></tr></tbody></table>
#### Error Response Format
```json
{
"error": "Error description",
"message": "Detailed error message"
}
```
> <mark style="color:blue;">**ⓘ Info**</mark>\
> As the Trading Engine API is in beta, our API could limit or ban you if the number of requests is excessive. If you think you are being rate limited or have specific needs, please contact us.
# L1 Bridge
Contracts involved in canonical messaging between Ethereum and Zircuit
Contracts involved in canonical messaging between Ethereum and Zircuit
## Ethereum
| Contract Name | Contract Address |
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `L1CrossDomainMessengerProxy` | [0x2a721cBE81a128be0F01040e3353c3805A5EA091](https://etherscan.io/address/0x2a721cBE81a128be0F01040e3353c3805A5EA091) |
| `L1StandardBridgeProxy` | [0x386B76D9cA5F5Fb150B6BFB35CF5379B22B26dd8](https://etherscan.io/address/0x386B76D9cA5F5Fb150B6BFB35CF5379B22B26dd8) |
| `ProxyAdmin` | [0x5B1Ef673d9c316b3eE9Ed3B4E3cC84952bfC5257](https://etherscan.io/address/0x5B1Ef673d9c316b3eE9Ed3B4E3cC84952bfC5257) |
| `SystemConfigProxy` | [0x30F82a1Ca89226E8b8815d6EbB728e3b18a428ff](https://etherscan.io/address/0x30F82a1Ca89226E8b8815d6EbB728e3b18a428ff) |
| `SP1VerifierGateway` | [0xf35A4088eA0231C44B9DB52D25c0E9E2fEe31f67](https://etherscan.io/address/0xf35A4088eA0231C44B9DB52D25c0E9E2fEe31f67) |
| `OptimismPortalProxy` | [0x17bfAfA932d2e23Bd9B909Fd5B4D2e2a27043fb1](https://etherscan.io/address/0x17bfAfA932d2e23Bd9B909Fd5B4D2e2a27043fb1) |
| `OptimismMintableERC20FactoryProxy` | [0xc77ece87C91C44AFb5f19638f9a0F75b5d90E932](https://etherscan.io/address/0xc77ece87C91C44AFb5f19638f9a0F75b5d90E932) |
| `L2OutputOracleProxy` | [0x92Ef6Af472b39F1b363da45E35530c24619245A4](https://etherscan.io/address/0x92Ef6Af472b39F1b363da45E35530c24619245A4) |
| `L1ERC721BridgeProxy` | [0x994eEb321F9cD79B077a5455fC248c77f30Dd244](https://etherscan.io/address/0x994eEb321F9cD79B077a5455fC248c77f30Dd244) |
| `SuperchainConfigProxy` | [0x745393Cc03b5fE668ECd52c0E625f59aAD6D3Da0](https://etherscan.io/address/0x745393Cc03b5fE668ECd52c0E625f59aAD6D3Da0) |
| `ResolverRegistryProxy` | [0x6c89104690452AD7e209f0ab72287C2561d5cF0E](https://etherscan.io/address/0x6c89104690452AD7e209f0ab72287C2561d5cF0E) |
| `CrisisControlRegistryProxy` | [0x7d43EB137185aEa81A020563099e940Bb380F35e](https://etherscan.io/address/0x7d43EB137185aEa81A020563099e940Bb380F35e) |
## Sepolia
| Contract Name | Contract Address |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `L1CrossDomainMessengerProxy` | [0x6aC894b2a32fED0DC09c2c617277c2F2BF1cf130](https://sepolia.etherscan.io/address/0x6aC894b2a32fED0DC09c2c617277c2F2BF1cf130) |
| `L1StandardBridgeProxy` | [0x87a7E2bCA9E35BA49282E832a28A6023904460D8](https://sepolia.etherscan.io/address/0x87a7E2bCA9E35BA49282E832a28A6023904460D8) |
| `ProxyAdmin` | [0x540fF7ab7bb9894E408bb650ed4f060c390c9B6d](https://sepolia.etherscan.io/address/0x540fF7ab7bb9894E408bb650ed4f060c390c9B6d) |
| `SystemConfigProxy` | [0x3D3fC87Ec70705Ba6FDDAcc72D5C71440F64463F](https://sepolia.etherscan.io/address/0x3D3fC87Ec70705Ba6FDDAcc72D5C71440F64463F) |
| `SP1VerifierGateway` | [0xb9985758eed32892441fAF6FE852B8c6d6847205](https://sepolia.etherscan.io/address/0xb9985758eed32892441fAF6FE852B8c6d6847205) |
| `OptimismPortalProxy` | [0x4E21A71Ac3F7607Da5c06153A17B1DD20E702c21](https://sepolia.etherscan.io/address/0x4E21A71Ac3F7607Da5c06153A17B1DD20E702c21) |
| `OptimismMintableERC20FactoryProxy` | [0x9641B86870bbe53264492854Ad7af32E39079dfe](https://sepolia.etherscan.io/address/0x9641B86870bbe53264492854Ad7af32E39079dfe) |
| `L2OutputOracleProxy` | [0xd69D3AC5CA686cCF94b258291772bc520FEAf211](https://sepolia.etherscan.io/address/0xd69D3AC5CA686cCF94b258291772bc520FEAf211) |
| `L1ERC721BridgeProxy` | [0x987d6008BB5C1e94a72b60a4bbFaAF67Ef09746E](https://sepolia.etherscan.io/address/0x987d6008BB5C1e94a72b60a4bbFaAF67Ef09746E) |
| `SuperchainConfigProxy` | [0x9da6c219742518AE98E364184cE32fe81c08Ba2A](https://sepolia.etherscan.io/address/0x9da6c219742518AE98E364184cE32fe81c08Ba2A) |
| `ResolverRegistryProxy` | [0x2B49136665Dc78347893BFaCf3F9e2af546A1069](https://sepolia.etherscan.io/address/0x2B49136665Dc78347893BFaCf3F9e2af546A1069) |
| `CrisisControlRegistryProxy` | [0xBEa946FF59F97Eec54e4B32a01e68d67fb4Df5A6](https://sepolia.etherscan.io/address/0xBEa946FF59F97Eec54e4B32a01e68d67fb4Df5A6) |
## Definitions
### L1Standard Bridge
The `L1StandardBridge` handles ETH and ERC20 transfers between L1 and L2. For L1-native ERC20 tokens, they're escrowed in this contract, while L2-native ones are burnt. ETH is stored in the OptimismPortal contract.
*NOTE: The contract doesn't support all ERC20 variations, e.g., those with transfer fees, rebasing tokens, or blocklists.*
#### Functions:
`bridgeETH`: Sends ETH the sender's address on L2.
`bridgeETHTo`: Sends ETH to a receiver's address on L2.
`bridgeERC20`: Sends ERC20 tokens to the sender's address onon L2.
`depositERC20To`: Deposit an ERC20 for a target on L2.
`receive`: Bridge ETH via direct send to the bridge.
`finalizeBridgeETH`: Finalizes an ETH bridge.
`finalizeBridgeERC20`: Finalizes an ERC20 bridge.
### L1CrossDomainMessenger
The contract serves as an interface for managing cross-layer communication between L1 and L2. It provides functionalities to send and receive messages, potentially facilitating interactions like token transfers or contract calls between different layers of the network.
### L1ERC721Bridge
The `L1ERC721Bridge` contract facilitates ERC721 token transfers between Ethereum and Zircuit by escrowing tokens on L1, liaising with the L2 bridge, and ensuring secure, transparent transfers. It's vital for scaling NFTs and ERC721 assets across blockchain layers.
### L2OutputOracle
The contract holds an array of L2 state outputs, each representing the L2 chain state at specific block numbers. It permits adding new outputs and removing existing ones based on conditions.
#### Events:
`OutputProposed`: Announces a new output with its details.
#### Functions:
`proposeL2Output`: Submits a new L2 output, ensuring block number and timestamp accuracy.
`getL2Output`: Retrieves an output by index.
`getL2OutputIndexAfter` & `getL2OutputAfter`: Uses binary search to find and return outputs based on block numbers.
`finalizationPeriodSeconds`: The minimum time (in seconds) that must elapse before a withdrawal can be finalized.
### OptimismPortal
The OptimismPortal is responsible for managing cross-chain communication between L1 and Zircuit L2. It handles depositing messages from L1 to L2 and proving and finalizing withdrawal messages from L2 to L1.
#### Functions
`minimumGasLimit`: Computes the minimum gas limit for a deposit.
`receive()`: Allows users to send ETH directly to the contract and have the funds deposited to their address on L2.
`donateETH`: Accepts ETH without triggering a deposit to L2.
`proveWithdrawalTransaction`: Allows a user to prove a withdrawal transaction by providing necessary proofs, upon which the withdrawn funds are released and forwarded to the targeted receiver.
`depositTransaction`: Accepts deposits of ETH and data, and triggers a TransactionDeposited event.
`isOutputFinalized`: Checks if a given L2 output is finalized.
### Verifier
The `Verifier` is responsible for checking Zircuit validity and template proofs.
# L2 Predeploys
A contract placed in the L2 genesis state. They operate natively within the EVM instead of executing as external native code outside the EVM environment
A contract placed in the L2 genesis state. They operate natively within the EVM instead of executing as external native code outside the EVM environment
## Zircuit Mainnet & Garfield Testnet
| Contract Name | Contract Address |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `BaseFeeVault` | [0x4200000000000000000000000000000000000019](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000019) |
| `GasPriceOracle` | [0x420000000000000000000000000000000000000F](https://explorer.zircuit.com/address/0x420000000000000000000000000000000000000F) |
| `L1Block` | [0x4200000000000000000000000000000000000015](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000015) |
| `L1FeeVault` | [0x420000000000000000000000000000000000001A](https://explorer.zircuit.com/address/0x420000000000000000000000000000000000001A) |
| `L2CrossDomainMessenger` | [0x4200000000000000000000000000000000000007](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000007) |
| `L2ERC721Bridge` | [0x4200000000000000000000000000000000000014](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000014) |
| `L2StandardBridge` | [0x4200000000000000000000000000000000000010](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000010) |
| `L2ToL1MessagePasser` | [0x4200000000000000000000000000000000000016](https://explorer.zircuit.com/address/0x4200000000000000000000000000000000000016) |
| `OptimismMintableERC20Factory` | [0x4200000000000000000000000000000000000012](https://explorer.zircuit.com/address/0x4200000000000000프로젝트로 돌아가기