Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
---
id: frontend-integration
title: Frontend Integration
sidebar_label: Frontend Integration
id: aggregator-integration
title: Aggregator Integration
sidebar_label: Aggregator Integration
sidebar_position: 2
---

# Frontend Integration for ERC 7683 Intent Bridging
# Aggregator Integration for t1 Intent Bridging

This guide explains how to integrate the 7683 intent bridging mechanism into your frontend application. It covers encoding the order data, estimating gas, and executing the bridge transaction.
This guide explains how to integrate the t1 intent bridging mechanism into your frontend application. It covers encoding the order data, estimating gas, and executing the bridge transaction.

## Overview

The 7683 Intent Bridge enables cross-chain token transfers through an intent-based system. Users express their intent to bridge tokens, and fillers compete to fulfill these intents, providing better execution and potentially better rates.
The t1 Intent Bridge facilitates cross-chain token transfers using a Trusted Execution Environment (TEE) based proving system. Users express their intent to bridge tokens, and fillers compete to fulfill these intents. TEE-based xChainRead enables solvers to get repaid in less than 10 seconds, improving capital efficiency for solvers and providing better execution and rates for users.

## How it works

The 7683 Intent Bridge operates through a standardized intent protocol:
The t1 Intent Bridge operates through a standardized intent protocol that is based on ERC-7683 standard:

1. **Intent Creation**: Users create an intent specifying source and destination tokens, amounts, and execution parameters
2. **Order Encoding**: The intent is encoded according to ERC-7683 standards with proper ABI encoding
Expand All @@ -25,35 +25,74 @@ The 7683 Intent Bridge operates through a standardized intent protocol:

## Integration Overview

The main components of frontend integration are:
The main components of aggregator integration are:

- Querying `minAmountOut` from API
- Encoding intent order data in a Solidity-compatible format.
- Executing the bridge intent with custom parameters.

## Encoding Order Data
### 1. Querying minAmountOut via API

To obtain a pre-auction bid, query the POST `${baseUrl}/preauction` API:

```bash
curl --location 'https://{baseUrl}/preauction' \
--header 'Content-Type: application/json' \
--data '{
"id": "uuid",
"srcTokenAddress": "string",
"dstTokenAddress": "string",
"srcChainId": 1,
"dstChainId": 137,
"amountIn": "1000000000000000000"
}'
```

Your response should look like this:

```typescript
interface Quote {
id: string
request: {
srcChainId: number
dstChainId: number
srcTokenAddress: string
dstTokenAddress: string
amountIn: number
}
amountOut: string
solverAddress: string
timestamp: number
}
```

We can obtain the `amountOut` and use it as `minAmountOut` in our intent.

### 2. Encoding Order Data

To prepare the order data for execution, use the `encodeIntentOrderData` function. This ensures the `bytes` format is correctly aligned for the 7683 contract.

### IntentOrderData Type Definition
#### IntentOrderData Type Definition

```ts
```typescript
export type IntentOrderData = {
sender: string // padded address
recipient: string // padded address
inputToken: string // padded address
outputToken: string // padded address
amountIn: string
amountOut: string
minAmountOut: string
senderNonce: number
originDomain: number
destinationDomain: number
destinationSettler: string // padded address
fillDeadline: number
closedAuction: boolean
data: string // hex string like "0x"
}
```

```ts
```typescript
export function encodeIntentOrderData(orderData: IntentOrderData): string {
const abiCoder = ethers.utils.defaultAbiCoder
const toBytes32 = (addr: string) => ethers.utils.hexZeroPad(addr, 32)
Expand All @@ -71,6 +110,7 @@ export function encodeIntentOrderData(orderData: IntentOrderData): string {
'uint32',
'bytes32',
'uint32',
'boolean',
'bytes',
],
[
Expand All @@ -79,22 +119,23 @@ export function encodeIntentOrderData(orderData: IntentOrderData): string {
toBytes32(orderData.inputToken),
toBytes32(orderData.outputToken),
orderData.amountIn,
orderData.amountOut,
orderData.minAmountOut,
orderData.senderNonce,
orderData.originDomain,
orderData.destinationDomain,
toBytes32(orderData.destinationSettler),
orderData.fillDeadline,
orderData.closedAuction,
orderData.data,
]
],
)

const dynamicOffsetPrefix = '0x0000000000000000000000000000000000000000000000000000000000000020'
return dynamicOffsetPrefix + orderDataEncoded.slice(2)
}
```

### 2. Order Data Type Hash
### 3. Order Data Type Hash

Define the EIP-712 type string and hash for the order data:

Expand All @@ -106,36 +147,39 @@ export const ORDER_DATA_TYPE_STRING =
'bytes32 inputToken,' +
'bytes32 outputToken,' +
'uint256 amountIn,' +
'uint256 amountOut,' +
'uint256 minAmountOut,' +
'uint256 senderNonce,' +
'uint32 originDomain,' +
'uint32 destinationDomain,' +
'bytes32 destinationSettler,' +
'uint32 fillDeadline,' +
'bool closedAuction,' +
'bytes data)'

export const ORDER_DATA_TYPE_HASH = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(ORDER_DATA_TYPE_STRING))
```

### 3. Executing Intent Bridge
### 4. Executing Intent Bridge

Here's the complete implementation for executing an intent bridge:

```typescript
export const executeIntentBridge = async (
walletProvider: providers.ExternalProvider,
walletAddress: string,
tokenInAddress: string,
tokenOutAddress: string,
fromChainId: number,
toChainId: number,
amount: string
amount: string,
) => {
const provider = new ethers.providers.Web3Provider(walletProvider, 'any')
const signer = provider.getSigner()

const originChainContract = new ethers.Contract(
process.env.ORIGIN_CHAIN_7683_CONTRACT_ADDRESS,
process.env.ORIGIN_CHAIN_7683_CONTRACT_ADDRESS!,
ORIGIN_CHAIN_7683_ABI,
signer
signer,
)

try {
Expand All @@ -145,15 +189,16 @@ export const executeIntentBridge = async (
const orderData: IntentOrderData = {
sender: walletAddress,
recipient: walletAddress,
inputToken: '0x0000000000000000000000000000000000000000', // Native ETH
outputToken: '0x0000000000000000000000000000000000000000', // Native ETH
inputToken: tokenInAddress,
outputToken: tokenOutAddress,
amountIn: Number(amountAfterConversion).toString(),
amountOut: Number(amountAfterConversion).toString(), // Adjust amountOut based on the filler's fee
minAmountOut: Number(amountAfterConversion).toString(), // Get minAmountOut from our /preauction API
senderNonce: Math.floor(Math.random() * 1e15),
originDomain: fromChainId,
destinationDomain: toChainId,
destinationSettler: process.env.DESTINATION_CHAIN_7683_CONTRACT_ADDRESS,
destinationSettler: process.env.DESTINATION_CHAIN_7683_CONTRACT_ADDRESS!,
fillDeadline: Math.floor(Date.now() / 1000) + 24 * 60 * 60, // 24 hour deadline
closedAuction: true,
data: '0x',
}

Expand All @@ -169,7 +214,7 @@ export const executeIntentBridge = async (
},
{
value: amountAfterConversion.toBigInt(),
}
},
)
await executeIntentBridgeResult.wait()
} catch (e) {
Expand All @@ -178,7 +223,7 @@ export const executeIntentBridge = async (
}
```

### Security Considerations
## Security Considerations

- **Nonce Management**: Each intent uses a unique random nonce to prevent replay attacks
- **Deadline Protection**: 24-hour deadline prevents indefinite pending states
Expand Down
2 changes: 1 addition & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const sidebars = {
{
type: 'category',
label: '7683',
items: ['integration/7683/solver-integration', 'integration/7683/frontend-integration'],
items: ['integration/7683/solver-integration', 'integration/7683/aggregator-integration'],
},
],
}
Expand Down