DEX Rate Arbitrage Detection
use ChainlinkPrice, CoingeckoPrice, Approximately, Call from hexagate;
/* Query Uniswap V3 USDT-WETH pool */
source UniWETH: tuple<integer, integer, integer, integer, integer, integer, boolean> = Call {
contract: 0xc7bBeC68d12a0d1830360F8Ec58fA599bA1b0e9b,
signature: "function slot0() returns (uint160 sqrtPriceX96,int24 tick,uint16 observationIndex,uint16 observationCardinality,uint16 observationCardinalityNext,uint8 feeProtocol,bool unlocked);"
};
/* Query Pancake V3 USDT-WETH pool */
source PancakeWETH: tuple<integer, integer, integer, integer, integer, integer, boolean> = Call {
contract: 0x6CA298D2983aB03Aa1dA7679389D955A4eFEE15C,
signature: "function slot0() returns (uint160 sqrtPriceX96,int24 tick,uint16 observationIndex,uint16 observationCardinality,uint16 observationCardinalityNext,uint32 feeProtocol,bool unlocked);"
};
/* Calculating a price in Uniswap/PancakeSwap is as follows price = (sqrtPriceX96X(10**8) / 2**96) ** 2 */
source priceInUni: integer = (UniWETH[0] * (10**8) / 79228162514264337593543950336)**2;
source priceInPancake: integer = (PancakeWETH[0] * (10**8) / 79228162514264337593543950336)**2;
source approx1: boolean = Approximately {
source: priceInUni,
target: priceInPancake,
percent: 1
};
rule {
description: "WETH/USDT more than 1% price deveation in DEXes",
condition: approx1
};Last updated