Skip to content

Commit d1d73d4

Browse files
authored
Bug: correct fill rate in ER Limo simple searcher example (#2049)
* correct fill rate, choose simpler option * address comments, make python updates * minor fixes * fixed comment
1 parent 0331d3c commit d1d73d4

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

express_relay/sdk/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/express-relay-js",
3-
"version": "0.12.0",
3+
"version": "0.12.2",
44
"description": "Utilities for interacting with the express relay protocol",
55
"homepage": "https://github.com/pyth-network/pyth-crosschain/tree/main/express_relay/sdk/js",
66
"author": "Douro Labs",

express_relay/sdk/js/src/examples/simpleSearcherLimo.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,27 @@ class SimpleSearcherLimo {
8282
const outputMintDecimals = await this.getMintDecimalsCached(
8383
order.state.outputMint
8484
);
85+
const effectiveFillRate = Math.min(
86+
this.fillRate,
87+
(100 * order.state.remainingInputAmount.toNumber()) /
88+
order.state.initialInputAmount.toNumber()
89+
);
8590
const inputAmountDecimals = new Decimal(
86-
order.state.remainingInputAmount.toNumber()
91+
order.state.initialInputAmount.toNumber()
8792
)
8893
.div(new Decimal(10).pow(inputMintDecimals))
89-
.mul(this.fillRate)
94+
.mul(effectiveFillRate)
9095
.div(100);
9196

9297
const outputAmountDecimals = new Decimal(
9398
order.state.expectedOutputAmount.toNumber()
9499
)
95100
.div(new Decimal(10).pow(outputMintDecimals))
96-
.mul(this.fillRate)
101+
.mul(effectiveFillRate)
97102
.div(100);
98103

99104
console.log("Order address", order.address.toBase58());
100-
console.log("Fill rate", this.fillRate);
105+
console.log("Fill rate", effectiveFillRate);
101106
console.log(
102107
"Sell token",
103108
order.state.inputMint.toBase58(),
@@ -218,7 +223,8 @@ const argv = yargs(hideBin(process.argv))
218223
demandOption: true,
219224
})
220225
.option("fill-rate", {
221-
description: "How much of the order to fill in percentage. Default is 100%",
226+
description:
227+
"How much of the initial order size to fill in percentage. Default is 100%",
222228
type: "number",
223229
default: 100,
224230
})

express_relay/sdk/python/express_relay/searcher/examples/simple_searcher_svm.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,17 @@ async def assess_opportunity(self, opp: OpportunitySvm) -> BidSvm:
109109
order: OrderStateAndAddress = {"address": opp.order_address, "state": opp.order}
110110
input_mint_decimals = await self.get_mint_decimals(order["state"].input_mint)
111111
output_mint_decimals = await self.get_mint_decimals(order["state"].output_mint)
112-
input_amount_decimals = Decimal(
113-
order["state"].remaining_input_amount
114-
) / Decimal(10**input_mint_decimals)
112+
effective_fill_rate = min(
113+
self.fill_rate,
114+
100
115+
* order["state"].remaining_input_amount
116+
/ order["state"].initial_input_amount,
117+
)
118+
input_amount_decimals = Decimal(order["state"].initial_input_amount) / Decimal(
119+
10**input_mint_decimals
120+
)
115121
input_amount_decimals = (
116-
input_amount_decimals * Decimal(self.fill_rate) / Decimal(100)
122+
input_amount_decimals * Decimal(effective_fill_rate) / Decimal(100)
117123
)
118124
output_amount_decimals = Decimal(
119125
order["state"].expected_output_amount
@@ -127,7 +133,9 @@ async def assess_opportunity(self, opp: OpportunitySvm) -> BidSvm:
127133
self.private_key.pubkey(),
128134
order,
129135
input_amount_decimals,
136+
output_amount_decimals,
130137
input_mint_decimals,
138+
output_mint_decimals,
131139
self.svm_config["express_relay_program"],
132140
)
133141
router = self.limo_client.get_pda_authority(
@@ -215,7 +223,7 @@ async def main():
215223
"--fill-rate",
216224
type=int,
217225
default=100,
218-
help="How much of the order to fill in percentage. Default is 100%",
226+
help="How much of the initial order size to fill in percentage. Default is 100%",
219227
)
220228

221229
args = parser.parse_args()

express_relay/sdk/python/express_relay/svm/generated/limo/instructions/take_order.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
class TakeOrderArgs(typing.TypedDict):
1010
input_amount: int
11+
output_amount: int
1112

1213

13-
layout = borsh.CStruct("input_amount" / borsh.U64)
14+
layout = borsh.CStruct("input_amount" / borsh.U64, "output_amount" / borsh.U64)
1415

1516

1617
class TakeOrderAccounts(typing.TypedDict):
@@ -90,6 +91,7 @@ def take_order(
9091
encoded_args = layout.build(
9192
{
9293
"input_amount": args["input_amount"],
94+
"output_amount": args["output_amount"],
9395
}
9496
)
9597
data = identifier + encoded_args

express_relay/sdk/python/express_relay/svm/limo_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,20 @@ async def take_order_ix(
189189
taker: Pubkey,
190190
order: OrderStateAndAddress,
191191
input_amount_decimals: Decimal,
192+
output_amount_decimals: Decimal,
192193
input_mint_decimals: int,
194+
output_mint_decimals: int,
193195
express_relay_program_id: Pubkey,
194196
) -> List[Instruction]:
195197
"""
196198
Returns the instructions to fulfill an order as a taker.
197199
Args:
198200
taker: The taker's public key
199201
order: The order to fulfill
200-
input_amount_decimals: The amount of input tokens to take multiplied by 10 ** input_mint_decimals
202+
input_amount_decimals: The amount of input tokens to take. Will be multiplied by 10 ** input_mint_decimals in this method.
203+
output_amount_decimals: The amount of output tokens to provide. Will be multiplied by 10 ** output_mint_decimals in this method.
201204
input_mint_decimals: input mint decimals (can be fetched via get_mint_decimals)
205+
output_mint_decimals: output mint decimals (can be fetched via get_mint_decimals)
202206
express_relay_program_id: Express relay program id
203207
204208
Returns:
@@ -260,7 +264,10 @@ async def take_order_ix(
260264
TakeOrderArgs(
261265
input_amount=int(
262266
input_amount_decimals * (10**input_mint_decimals)
263-
)
267+
),
268+
output_amount=int(
269+
output_amount_decimals * (10**output_mint_decimals)
270+
),
264271
),
265272
{
266273
"taker": taker,

express_relay/sdk/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "express-relay"
3-
version = "0.10.1"
3+
version = "0.12.2"
44
description = "Utilities for searchers and protocols to interact with the Express Relay protocol."
55
authors = ["dourolabs"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)