From cd492c569f4209be23ab00dc6a069c08aa22cfad Mon Sep 17 00:00:00 2001 From: Martin Magnus Date: Fri, 25 Oct 2024 13:04:37 +0200 Subject: [PATCH] Fix 1Inch quoting issues (#81) Currently the 1Inch solver returns a ton of 403 errors while quoting. The reason is that the 1Inch API checks the `tx.origin` for legal requirements and for quote requests we currently send the zero address. Since that address obviously can't be the origin of any transaction they refuse to return quotes for those. To work around that we set `from` (our settlement contract) as the `tx.origin` for quote requests. Since the calldata generated for that will never get used to settle real orders this is okay. --- src/infra/dex/oneinch/dto.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/infra/dex/oneinch/dto.rs b/src/infra/dex/oneinch/dto.rs index f5f8be8..11ea819 100644 --- a/src/infra/dex/oneinch/dto.rs +++ b/src/infra/dex/oneinch/dto.rs @@ -97,12 +97,22 @@ impl Query { return None; }; + // 1Inch checks `origin` for legal reasons. + // If we provide the zero address the API will return status code 403. + // `order.owner` is only zero while quoting and calldata generated + // for quotes will not be used to actually settle orders to it's fine + // to send a different `origin` here. + let origin = match order.owner.is_zero() { + true => self.from_address, + false => order.owner, + }; + Some(Self { from_token_address: order.sell.0, to_token_address: order.buy.0, amount: order.amount.get(), slippage: Slippage::from_domain(slippage), - origin: order.owner, + origin, ..self }) }