Skip to content

Commit

Permalink
finalized almost everything
Browse files Browse the repository at this point in the history
  • Loading branch information
ijonele committed Dec 26, 2024
1 parent 157a857 commit a6b3ef7
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,9 @@ sidebar_position: 6

## Overview

The **`OrderFactory` contract** securely manages the creation and tracking of orders.
The `OrderFactory` contract securely manages the creation and tracking of orders – instances of the [`BasicOrder`](main_contract) contract that monitor price feeds and perform swaps when price conditions are met.

**Key features:**

1. Factory pattern:

- Creates new order instances
- Tracks order creators
- Supports multiple order types

2. Management:

- Ownable for admin control
- Scheduler management
- Registry integration

3. Order creation:

- Basic orders supported
- Advanced orders placeholder
- Order registration in Registry
When triggered by a user, `OrderFactory` deploys a new [`BasicOrder`](main_contract) contract and registers it in the [registry](structure#3-implement-the-registry).

## Create the `OrderFactory` contract

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
sidebar_position: 7
---

# Implement the deployment scripts
# Implement deployment scripts

## Overview

Let's implement the deployment scripts. We'll need two scripts: one for deployment and one for creating orders.
This tutorial explains how to implement the main deployment script and the script for creating orders.

## 1. Implement a script for deployment

## 1. Implement the main deployment script

The main deployment script handles the following tasks:

- Deploying [`Registry`](structure#3-implement-the-registry)
- Deploying [`OrderFactory`](agent_factory)
- Environment configuration

To implement this script, use the following code:

:::note GitHub
You can find the full code on GitHub: [`/script/Deploy.s.sol`](https://github.com/warden-protocol/wardenprotocol/blob/main/solidity/orders/script/Deploy.s.sol)
Expand All @@ -35,13 +44,16 @@ contract Deploy is Script {
}
```

This script handles the following tasks:
## 2. Implement the script for creating orders

1. Registry deployment
2. Factory deployment
3. Environment configuration

## 2. Implement a script for creating orders
This script for creating orders handles the following tasks:

- Deploying [`BasicOrder`](main_contract) through [`OrderFactory`](agent_factory)
- Setting up [mock precompiles](precompiles)
- Parameter configuration

To implement this script, use the following code:

:::note GitHub
You can find the full code on GitHub: [`/script/CreateOrder.s.sol`](https://github.com/warden-protocol/wardenprotocol/blob/main/solidity/orders/script/CreateOrder.s.sol)
Expand All @@ -64,12 +76,6 @@ contract CreateOrder is Script {
}
```

This script handles the following tasks:

1. Order creation through factory
2. Mock precompiles setup
3. Parameter configuration

## Next steps

After creating implementing the deployment scripts, you can finally [deploy the trading Agent](deployment).
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
sidebar_position: 7
---

# Deploy the trading Agent
# Deploy the Basic Agent

## Overview

The following implementation will guide you through the process of how to deploy and test the basic Warden Agent.
This article will guide you through deploying the Basic Warden Agent and managing [orders](main_contract).

### 1. Deploy the Agent
## 1. Deploy the Agent

1. Set up the environment file (.env)
To deploy the Agent, take the following steps:

1. Set up the environment file (`.env`):

```bash
MNEMONIC="your mnemonic phrase here"
Expand All @@ -20,110 +22,133 @@ The following implementation will guide you through the process of how to deploy
FACTORY_OWNER_ADDRESS="0x6EA8AC1673402989E7B653AE4E83B54173719C30"
```

2. Compile the contract:
2. Compile the contracts:

```bash
forge build
```

3. Deploy the Base Contract:
3. Load the environment and run the [main deployment script](deploy_script#1-implement-the-main-deployment-script):

```bash
# Load environment
source .env

# Deploy Registry and Factory
forge script script/Deploy.s.sol:Deploy \
--rpc-url $RPC_URL \
--broadcast \
--chain-id $CHAIN_ID
```

This will deploy the [`Registry`](structure#3-implement-the-registry) and [`OrderFactory`](agent_factory) contracts.

4. Create an order
4. Run the [script for creating an order](deploy_script#1-implement-the-main-deployment-script):

```bash
forge script script/CreateOrder.s.sol:CreateOrder \
--rpc-url $RPC_URL \
--broadcast \
--sig "run(uint256,uint8,(string,string),(uint256,uint256,address),(uint256,address[],address,uint256),uint64,uint64, uint64,bytes,bytes)" \
3324181371 \ # threshold price
0 \ # LTE condition
'("ETH","USD")' \ # price pair
3324181371 \ # the threshold price
0 \ # LTE condition
'("ETH","USD")' \ # the price pair
'(100000000000000,11155111,0x467b...)' \ # tx fields
# ... other parameters
```

**Key parameters explained:**
The key parameters to specify include the following:

- `thresholdPrice`: Price level to trigger execution
- `thresholdPrice`: The price threshold to trigger execution
- `priceCondition`: 0 for LTE, 1 for GTE
- `pricePair`: Trading pair (e.g., "ETH/USD")
- `creatorDefinedTxFields`: Chain and transaction details
- `pricePair`: The trading pair e.g., "ETH/USD"
- `creatorDefinedTxFields`: The chain and transaction details
- `swapData`: Uniswap swap parameters
- `keyId`: Warden signing key ID
- `spaceNonce`: Nonce for the signing space
- `actionTimeoutHeight`: Timeout for execution
- `keyId`: The ID of the Warden key for signing transactions
- `spaceNonce`: The nonce for the signing space
- `actionTimeoutHeight`: The timeout for execution
- `expectedApproveExpression`: Conditions for approval
- `expectedRejectExpression`: Conditions for rejection

5. Verify the deployment:
5. Verify the deployment by getting the order details:

```bash
# Get order details
cast call $ORDER_ADDRESS "orderData()"
```

### 2. Monitor and manage orders
## 2. Monitor and manage orders

After deploying the Basic Agent, you can monitor and manage orders using the commands listed below.

### Monitor the order status

- Check if the order can be executed:

1. Monitor order status:

```bash
# Check if order can execute
cast call $ORDER_ADDRESS "canExecute()" --rpc-url $RPC_URL

# Check if order has been executed
```

- Check if the order is executed:

```
cast call $ORDER_ADDRESS "isExecuted()" --rpc-url $RPC_URL

# Get execution data
```

- Retrieve the execution data:

```
cast call $ORDER_ADDRESS "executionData()" --rpc-url $RPC_URL
```

2. Track in Registry:
### Get data from the registry

- Retrieve the order creator from the registry:

```bash
# Get order creator from registry
cast call $REGISTRY_ADDRESS "executions(address)" $ORDER_ADDRESS

# Get transaction details
```

- Retrieve the transaction details from the registry:

```bash
cast call $REGISTRY_ADDRESS "transactions(bytes32)" $TX_HASH
```

3. Monitor events:

### Monitor events

- Monitor the `Executed` [event](main_contract#monitoring-and-events):

```bash
# Watch for Executed events
cast logs $ORDER_ADDRESS "Executed()"
```

- Monitor the `NewTx` [event](main_contract#monitoring-and-events):

# Watch for NewTx events in Registry
```bash
cast logs $REGISTRY_ADDRESS "NewTx(address,bytes32)"
```

4. Utility commands:
### Get data from precompiles

```bash
# Get current price from Slinky
cast call $SLINKY_PRECOMPILE "getPrice(string,string)" "ETH" "USD"

# Check Warden key status
cast call $WARDEN_PRECOMPILE "keyById(uint64,int32[])" $KEY_ID []
```
- Get the current price from the [Slinky precompile](precompiles#11-create-a-slinky-precompile):

```bash
cast call $SLINKY_PRECOMPILE "getPrice(string,string)" "ETH" "USD"
```

- Check the Warden key status from the [Warden precompile](precompiles#11-create-a-warden-precompile):

```
cast call $WARDEN_PRECOMPILE "keyById(uint64,int32[])" $KEY_ID []
```

### Debug tools

5. Debug tools:
- Get the raw transaction data:

```bash
# Get raw transaction data
cast call $ORDER_ADDRESS "getTx()"

# Check callers list
```

- Check the list of callers:

```
cast call $ORDER_ADDRESS "callers()"
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
sidebar_position: 5
---

# Create the trading Agent
# Create the `BasicOrder` contract

## Overview

Let's create our main **trading Agent** that implements the automated Uniswap trading logic.
The `BasicOrder` contract implements **orders** that monitor prices and automatically perform swaps. It's the main part of the **trading Agent** and the core of the Basic Warden Agent.

To create an order, a user triggers the [`OrderFactory`](agent_factory) contract, and it deploys an instance of the `BasicOrder` contract. Then the trading Agent executes and manages orders, as shown in [Create the trading Agent structure](structure).

Create the `BasicOrder` contract

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 4

## Overview

**Mock precompiles** are essential for end-to-end testing of the Basic Agent. This article explains how to build and test two mock precompiles: Slinky and Warden.
**Mock precompiles** are essential for end-to-end testing of the Basic Agent. This article explains how to build and test two mock precompiles: **Slinky** and **Warden**.

:::note Structure
- Before you proceed, create a [`/mocks`](https://github.com/warden-protocol/wardenprotocol/blob/main/solidity/orders/mocks) directory for storing mock precompiles.
Expand Down Expand Up @@ -247,3 +247,5 @@ contract CreateOrder is Script {
## Next steps

After creating mock precompiles, you can [create the trading Agent](main_contract).

**Note:** When you deploy the Basic Agent, you'll be able to [get data from precompiles](deployment#get-data-from-precompiles).
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ sidebar_position: 3

## Overview

The main part of the Basic Warden Agent is the **trading Agent** that executes orders. This article will guide you through building a foundation for the trading Agent: you'll implement the core data structures and interfaces.
The main part of the Basic Warden Agent is the **trading Agent**. It executes and manages **orders** – instances of the [`BasicOrder`](main_contract) contract that monitor prices and automatically perform swaps.

This article will guide you through building a foundation for the trading Agent: you'll define the core data structures and interfaces for managing orders.

:::note Directory
Store the trading Agent structure in the [`/src`](https://github.com/warden-protocol/wardenprotocol/blob/main/solidity/orders/src) directory.
:::

## 1. Define trading types
## 1. Define data structures

First, create a library `Types.sol` with the core data structures:

Expand Down Expand Up @@ -60,7 +62,7 @@ You can find the full code on GitHub: [`/src/IExecution.sol`](https://github.com

```solidity title="/src/IExecution.sol"
interface IExecution {
// Check whether an order can be executed
// Check if an order can be executed
function canExecute() external view returns (bool);
// Execute an order
Expand Down Expand Up @@ -137,3 +139,5 @@ library RLPEncode {
## Next steps

After building the structure of the trading Agent, you can [create mock precompiles](precompiles).

**Note:** When you deploy the Basic Agent, you'll be able to [get data from the registry](deployment#get-data-from-the-registry).

0 comments on commit a6b3ef7

Please sign in to comment.