Section 9. Create a Direct Order [Agora]
To create a direct order, follow these steps:
- Deploy Task Manager, Authz Diamond and RAC (as described in Section 3)
- Deploy Trezor Diamond (as described in Section 5)
- Deploy Agora Diamond (as described in Section 6)
-
Create ERC20 Tokens (as described in Section 7)
Note: You should deploy two tokens, a base token and a quote token.
-
Create a Pair (as described in Section 8) with your base token and quote token
- Giving access to Trezor Diamond. follow these steps:
Step 1: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu. This will bring up the Deploy Trezor Diamond section.
Step 2: Copy Trezor Diamond Address
From the deployed diamond table, in the Address column, click on the Copy icon.
Step 3: Navigate to Deploy RAC Diamond
From the left-hand side of the page, select the Resource Access Controllermenu. This will bring up the Deploy RAC Diamond section.
Step 4: Giving access to Trezor Diamond
- From the deployed diamond table, click on the settings icon
- Navigate to the Functions and Permissions tab
- Find updateResourceQuota from Function Signature column and click on Add Permissions
- Enter the Trezor Diamond Address in Caller Account field to grant access
- Click on the Add Permission button
- Confirm the transaction in your wallet

7. Add permission to grantRole function in Trezor Diamond
Step 1: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu.
Step 2: Giving permission to grantRole function
- From the deployed diamond table, click on the settings icon
- Navigate to the Functions and Permissions tab
- Find grantRole from Function Signature column and click on Add Permissions
- Click on the Add Permission button
- Confirm the transaction in your wallet

8. Make Trezor a Finalizer
Step 1: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu. This will bring up the Deploy Trezor Diamond section.
Step 2: Copy Trezor Diamond Address
From the deployed diamond table, in the Address column, click on the Copy icon.
Step 3: Navigate to Deploy Task Manager
From the left-hand side of the page, select the Conclave menu. Once it appears, choose the Task Managers submenu. This will bring up the Deploy Task Manager section.
Step 4: Create a new Admin Task
- From the Task Manager you have deployed, click on the New… button
- Click on Admin Task
- Enter “Make Trezor a Finalizer” as the name
Step 5: Approve Admin Task
- From the Task Manager you have deployed, click on the Approve… button
- Click on Admin Task
- Confirm the transaction in your wallet Note: Approval is required from 50% of Admins (Admins specified in Section 3-1, Step 2, Row 3).
Step 6: Make Trezor a Finalizer
- From the Task Manager you have deployed, click on the Add…button
- Click on Finalizer
- Click on Reference Admin Task, select the Admin Task you have deployed
- Enter Trezor Diamond Address (which you copy in step 2) in Account field
- Click on the Add Finalizer button
- Confirm the transaction in your wallet
9. Create and Approve a Task
Step 1: Navigate to Deploy Task Manager
From the left-hand side of the page, select the Conclave menu. Once it appears, choose the Task Managers submenu. This will bring up the Deploy Task Manager section.
Step 2: Create a new Task
- From the Task Manager you have deployed, click on the New… button
- Click on Task
- Enter the desired task Name
Step 3: Approve Task
- From the Task Manager you have deployed, click on the Approve… button
- Click on Task
- Confirm the transaction in your wallet Note: Approval is required from 50% of Admins (Admins specified in Section 3-1, Step 2, Row 3).
10. Giving access to Agora Diamond (to use transferErc20VaultBalance function in Trezor diamond)
Step 1: Navigate to Agora > Orderbooks
From the left-hand side of the page, select the Agora menu. Once it appears, choose the Orderbooks submenu.
Step 2: Copy Agora Diamond Address
From the deployed diamond table, in the Address column, click on the Copy icon.
Step 3: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu. This will bring up the Deploy Trezor Diamond section.
Step 4: Giving access to Agora Diamond
- From the deployed diamond table, click on the settings icon.
- Navigate to the Functions and Permissions tab
- Find transferErc20VaultBalance from Function Signature column and click on Add Permissions
- Enter the Agora Diamond Address in Caller Account field to grant access
- Click on the Add Permission button
- Confirm the transaction in your wallet
11. Set RAC Props in Agora Diamond
Step 1: Navigate to Resource Access Controller
From the left-hand side of the page, select the Resource Access Controller menu.
Step 2: Copy RAC Diamond Address
From the deployed diamond table, in the Address column, click on the Copy icon.
Step 3: Navigate to Agora Diamond > Orderbooks
From the left-hand side of the page, select the Agora menu. Once it appears, choose the Orderbooks submenu.
Step 4: Giving permission to setAddress function
- From the deployed diamond table, click on the settings icon
- Navigate to the Functions and Permissions tab
- Find setAddress from Function Signature column and click on Add Permissions
- Click on the Add Permission button
- Confirm the transaction in your wallet
Step 5: Set RAC address Props in Agora Diamond
- Navigate to the Facet Settings tab
- Navigate to the props facet
- Navigate to the Address Props tab
- Click on the Set Value button
- Enter ‘rac.address’ as Key and paste the RAC Diamond Address (that you have copied in step 2) as Value
- Click on the Set Value button
- Confirm the transaction in your wallet
Step 6: Giving permission to setInt function
- Navigate to the Functions and Permissions tab
- Find setInt from Function Signature column and click on Add Permissions
- Click on the Add Permission button
- Confirm the transaction in your wallet
Step 7: Set RAC integer Props in Agora Diamond
- Navigate to the Facet Settings tab
- Navigate to the props facet
- Navigate to the Integer Props tab (this tab is open by default)
- Click on the Set Value button
- Enter ‘rac.domain.id’ as Key and ‘999’ as Value
- Click on the Set Value button
- Confirm the transaction in your wallet
12. Set RAC Props in Trezor Diamond
Step 1: Navigate to Resource Access Controller
From the left-hand side of the page, select the Resource Access Controller menu.
Step 2: Copy RAC Diamond Address
From the deployed diamond table, in the Address column, click on the Copy icon.
Step 3: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu.
Step 4: Giving permission to setAddress function
- From the deployed diamond table, click on the settings icon
- Navigate to the Functions and Permissions tab
- Find setAddress from Function Signature column and click on Add Permissions
- Click on the Add Permission button
- Confirm the transaction in your wallet
Step 5: Set RAC address Props in Trezor Diamond
- Navigate to the Facet Settings tab
- Navigate to the props facet
- Navigate to the Address Props tab
- Click on the Set Value button
- Enter ‘rac.address’ as Key and paste the RAC Diamond Address (that you have copied in step 2) as Value
- Click on the Set Value button
- Confirm the transaction in your wallet
Step 6: Giving permission to setInt function
- Navigate to the Functions and Permissions tab
- Find setInt from Function Signature column and click on Add Permissions
- Click on the Add Permission button
- Confirm the transaction in your wallet
Step 7: Set RAC integer Props in Trezor Diamond
- Navigate to the Facet Settings tab
- Navigate to the props facet
- Navigate to the Integer Props tab (this tab is open by default)
- Click on the Set Value button
- Enter ‘rac.domain.id’ as Key and ‘999’ as Value
- Click on the Set Value button
- Confirm the transaction in your wallet
13. Create Ledger in Trezor Diamond
Step 1: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu.
Step 2: Giving permission to createLedger function
- From the deployed diamond table, click on the settings icon
- Navigate to the Functions and Permissions tab
- Find createLedger from Function Signature column and click on Add Permissions
- Click on the Add Permission button
- Confirm the transaction in your wallet
Step 3: Create Ledger
- Navigate to the Facet Settings tab
- Navigate to the ledger-lister facet
- Click on the Create Ledger button
- Enter ‘Default’ as Name
- Click on the Create Ledger button
- Confirm the transaction in your wallet
14. Deposit Tokens in Trezor
Step 1: Navigate to Trezor Diamond
From the left-hand side of the page, select the Trezor menu.
Step 2: Deposit Tokens
- Navigate to the erc20-vault facet
- Navigate to the Deposit tab
- Enter your wallet address
- Click on Erc20 Token field and select your token
- Enter the desired Amount
- Click on the Deposit button
- Confirm the transaction in your wallet
15. Call createDirectOrder function (Using Deployed Contract Address)
To call a function using the deployed contract's address with Hardhat, you should:
1. Get contract address
2. Setup a new Hardhat script: In your Hardhat project, create a new script file (e.g., scripts/interact.js).
3. Define an async function to call createDirectOrder
4. Run the Script with Hardhat:
npx hardhat run scripts/interact.js --network ppr2
→ In *hardhat.config.js**` file add the network settings:
require("@nomiclabs/hardhat-ethers");
ppr2: {
// find url in: metamask wallet > Settings > Networks > Pulse PPR2
url: 'https://ppr2.dev.metapolitan.io',
// accounts: 0x + metamask wallet private key
accounts: ["0xcb7e81f3c77e5cef80d02a056f3547056e6ce9a42ef18f008a0a6473c8f124b5"],
},
→ In common.js file add the network settings:
if (network === 'ppr2'){
return {
name: network,
isGoerli: false,
isMainnet: true,
};
→ Sample codes (in scripts/interact.js):
/* eslint-disable no-undef */
async function main() {
const [admin1] = await ethers.getSigners();
//================================= attach diamond contracts
const AgoraEngineDirectOrderManagerFacetContractFactory = await hre.ethers.getContractFactory('AgoraEngineDirectOrderManagerFacet',);
agoraEngineDirectOrderManagerContract = await AgoraEngineDirectOrderManagerFacetContractFactory.attach("0x41b5d3a138b5449778d519d315dfc706db2ac8c4");
const AgoraEngineOrderStatsFacetContractFactory = await hre.ethers.getContractFactory('AgoraEngineOrderStatsFacet',);
agoraEngineOrderStatsContract = await AgoraEngineOrderStatsFacetContractFactory.attach("0x41b5d3a138b5449778d519d315dfc706db2ac8c4");
const RBACFacetContractFactory = await hre.ethers.getContractFactory('RBACFacet',);
trezorRBACContract = await RBACFacetContractFactory.attach("0x5cb3627261e3a33e6a6b38b490265f5bbfc53b12");
//================================== Create Direct Order
// AgoraEngine contract must be a balance manager
await trezorRBACContract.connect(admin1).grantRole(
4,
'DEFAULT',
"0x41b5d3a138b5449778d519d315dfc706db2ac8c4",
'0x046f8734229b82080d188b9b7247b766dfce75b7f83075eb7cdbf07b03ef6716'
);
const tx = await agoraEngineDirectOrderManagerContract.connect(admin1).createDirectOrder(
"0xd3c92c2817246ce95e16873e68ee1133508beb14b325e08ac89bd8c7893c50af", {
bid: true,
directlyFillable: true,
orderType: 1,
quantity: 6,
price: 12 * 10 ** 6,
slippage: 0,
expireTs: 0,
data: ethers.utils.toUtf8Bytes('a good buy'),
}
);
const receipt = await tx.wait();
const event = receipt.events?.find(
(event) => event.event === 'DirectOrderCreate'
);
console.log(event);
const getOrders = await agoraEngineOrderStatsContract.connect(admin1).getOrders(
'0xd3c92c2817246ce95e16873e68ee1133508beb14b325e08ac89bd8c7893c50af',
[1, 2, 3]
)
console.log(getOrders);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
Note: To call the createDirectOrder function, first you should make Agora Diamond Contract a balance manager by calling grantRole function just once (for the future createDirectOrder calls, remove or comment out the grantRole).
The addresses used in the code are:
- Deployed Agora diamond contract address: 0x41b5d3a138b5449778d519d315dfc706db2ac8c4
- Deployed Trezor diamond contract address: 0x5cb3627261e3a33e6a6b38b490265f5bbfc53b12
- pairId: 0xd3c92c2817246ce95e16873e68ee1133508beb14b325e08ac89bd8c7893c50af