Skip to content

Commit ef54b6f

Browse files
committed
Add examples to builder codes and revshare
1 parent 446b816 commit ef54b6f

File tree

2 files changed

+135
-63
lines changed

2 files changed

+135
-63
lines changed

docs/pages/interaction/integration/integration-builder-codes.mdx

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,54 @@ Builder fees and addresses can be queried via the indexer using the `/orders` an
1515
- `partner address` - where fees will be routed
1616
- `fee (in ppm)` that will be charged on order matching
1717

18-
```go
19-
message Order {
20-
// The unique ID of this order. Meant to be unique across all orders.
21-
OrderId order_id = 1 [ (gogoproto.nullable) = false ];
22-
23-
...
24-
25-
// builder_code is the metadata for the partner or builder of an order.
26-
BuilderCodeParameters builder_code_params = 12;
18+
:::code-group
19+
20+
```typescript [TypeScript]
21+
// BuilderCodeParameters interface
22+
export interface IBuilderCodeParameters {
23+
builderAddress: string; // Address to receive the fee
24+
feePpm: number; // Fee in parts per million
2725
}
2826

29-
// BuilderCodeParameters represents the metadata for the
30-
// partner or builder of an order. This allows them to
31-
// specify a fee for providing there service
32-
// which will be paid out in the event of an order fill.
33-
message BuilderCodeParameters {
34-
// The address of the builder to which the fee will be paid.
35-
string builder_address = 1;
27+
// Example: Place an order with builder code parameters
28+
const order: IPlaceOrder = {
29+
clientId: 2,
30+
clobPairId: 1,
31+
side: Order_Side.SIDE_BUY,
32+
quantums: Long.fromNumber(1000000),
33+
subticks: Long.fromNumber(50000),
34+
timeInForce: Order_TimeInForce.TIME_IN_FORCE_UNSPECIFIED,
35+
reduceOnly: false,
36+
orderFlags: OrderFlags.SHORT_TERM,
37+
goodTilBlock: currentBlockHeight + 20,
38+
builderCodeParameters: {
39+
builderAddress: 'dydx1example_builder_address',
40+
feePpm: 1000, // 0.1% fee (1000 parts per million)
41+
}
42+
};
3643

37-
// The fee enforced on the order in ppm.
38-
uint32 fee_ppm = 2;
39-
}
44+
await client.validatorClient.post.placeOrder(
45+
subaccount,
46+
order.clientId,
47+
order.clobPairId,
48+
order.side,
49+
order.quantums,
50+
order.subticks,
51+
order.timeInForce,
52+
order.orderFlags,
53+
order.reduceOnly,
54+
order.goodTilBlock,
55+
undefined,
56+
0,
57+
undefined,
58+
undefined,
59+
order.builderCodeParameters,
60+
undefined
61+
);
4062
```
4163

64+
:::
65+
4266
:::note
4367
`BuilderCodeParameters` is an optional field
4468
:::

docs/pages/interaction/integration/integration-revshare.mdx

Lines changed: 92 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,34 @@ To participate in the Order Router Rev Share program, users need to propose and
1717

1818
## Voting in via Governance
1919

20-
To participate in the Order Router Rev Share program, you need to create and submit a governance proposal. Below is an example of what the governance message structure looks like:
21-
```json
22-
message Order {
23-
"messages": [
24-
{
25-
"@type": "/dydxprotocol.revshare.MsgSetOrderRouterRevShare",
26-
"authority": authority,
27-
"order_router_rev_share": {
28-
"address": {{your address}},
29-
"share_ppm": {{your requested ppm}},
30-
}
31-
}
32-
]
33-
}
20+
To participate in the Order Router Rev Share program, you need to create and submit a governance proposal. Below are examples of the governance message structure:
21+
22+
:::code-group
23+
24+
```python [Python]
25+
# Example: Set order router revenue share via governance
26+
from dydx_v4_client.node.client import NodeClient
27+
28+
# This method creates the governance message
29+
# Note: This requires governance authority to execute
30+
async def set_order_router_revenue_share_example():
31+
node = await NodeClient.connect(network.node)
32+
33+
# Set order router revenue share
34+
# authority: Governance authority address
35+
# address: Order router address that will receive revenue share
36+
# share_ppm: Revenue share in parts per million
37+
response = await node.set_order_router_revenue_share(
38+
authority="dydx1...", # Governance authority
39+
address="dydx1your_router_address", # Your order router address
40+
share_ppm=5000 # 0.5% revenue share (5000 parts per million)
41+
)
42+
43+
print(response)
3444
```
45+
46+
:::
47+
3548
The key components of this message are:
3649

3750
- `address` - The address of the order router that will receive the revenue share. This is also the id you place in your order message
@@ -45,19 +58,26 @@ The process for updating an existing order router's revenue share is the same as
4558

4659
To update the revenue share percentage for an existing order router, create a governance message with the same structure:
4760

48-
```json
49-
"messages": [
50-
{
51-
"@type": "/dydxprotocol.revshare.MsgSetOrderRouterRevShare",
52-
"authority": authority,
53-
"order_router_rev_share": {
54-
"address": {{your existing address}},
55-
"share_ppm": {{your new requested ppm}},
56-
}
57-
}
58-
]
61+
:::code-group
62+
63+
```python [Python]
64+
# Update existing order router revenue share
65+
async def update_order_router_revenue_share_example():
66+
node = await NodeClient.connect(network.node)
67+
68+
# Update with new revenue share percentage
69+
# Note: address must match the previously approved order router address
70+
response = await node.set_order_router_revenue_share(
71+
authority="dydx1...", # Governance authority
72+
address="dydx1your_existing_router_address", # Existing approved address
73+
share_ppm=7500 # New revenue share: 0.75% (7500 parts per million)
74+
)
75+
76+
print(response)
5977
```
6078

79+
:::
80+
6181
The proposal must go through the standard governance voting process and receive a passing vote before the updated revenue share percentage takes effect.
6282

6383
:::note
@@ -71,19 +91,27 @@ The proposal must go through the standard governance voting process and receive
7191
To delete an order router's revenue share configuration, you simply need to set the revenue share percentage to 0. This process follows the same governance workflow as setting up or updating a revenue share.
7292

7393
Submit a governance proposal with the following message structure:
74-
```json
75-
"messages": [
76-
{
77-
"@type": "/dydxprotocol.revshare.MsgSetOrderRouterRevShare",
78-
"authority": authority,
79-
"order_router_rev_share": {
80-
"address": {{your existing address}},
81-
"share_ppm": 0,
82-
}
83-
}
84-
]
94+
95+
:::code-group
96+
97+
```python [Python]
98+
# Delete order router revenue share by setting share_ppm to 0
99+
async def delete_order_router_revenue_share_example():
100+
node = await NodeClient.connect(network.node)
101+
102+
# Set share_ppm to 0 to disable revenue share
103+
# Note: address must match the previously approved order router address
104+
response = await node.set_order_router_revenue_share(
105+
authority="dydx1...", # Governance authority
106+
address="dydx1your_existing_router_address", # Existing approved address
107+
share_ppm=0 # Setting to 0 disables revenue share
108+
)
109+
110+
print(response)
85111
```
86112

113+
:::
114+
87115
:::note
88116
Key points to note:
89117

@@ -100,16 +128,36 @@ The `order_router_address` field is set when an order is placed
100128

101129
- `order_router_address` - the ID of the order router and where fees will be sent to
102130

103-
```go
104-
message Order {
105-
// The unique ID of this order. Meant to be unique across all orders.
106-
OrderId order_id = 1 [ (gogoproto.nullable) = false ];
107-
...
108-
// order_router_address is the metadata for the frontend order router.
109-
string order_router_address = 13;
110-
}
131+
:::code-group
132+
133+
```python [Python]
134+
# Place an order with order router address for revenue share
135+
from dydx_v4_client.node.market import Market
136+
from v4_proto.dydxprotocol.clob.order_pb2 import Order
137+
138+
market = Market(market_data)
139+
current_block = await node.latest_block_height()
140+
141+
new_order = market.order(
142+
order_id=order_id,
143+
order_type=OrderType.MARKET,
144+
side=Order.Side.SIDE_SELL,
145+
size=0.0001,
146+
price=0, # Market order
147+
time_in_force=Order.TimeInForce.TIME_IN_FORCE_UNSPECIFIED,
148+
reduce_only=False,
149+
good_til_block=current_block + 10,
150+
order_router_address='dydx1your_router_address', # Order router address (must be voted in via governance)
151+
)
152+
153+
transaction = await node.place_order(
154+
wallet=wallet,
155+
order=new_order,
156+
)
111157
```
112158

159+
:::
160+
113161
## Order Validation Checks
114162

115163
- Ensure the `order_router_address` field is valid and already voted in via governance

0 commit comments

Comments
 (0)