Code samples
This sections contains different ParsiQL code samples
The following Smart Trigger allows to monitor a defined Table of Uniswap Pair Pools, perform calculations and detect Swap spikes according to threshold.
In this example we observe the PRQ/ETH Pair's Pool and set the ETH (WETH to be precise) as the trading asset (
TradingAsset
) to set the thresholds against.
Dataset table for storing Uniswap Pairs Pool data
stream UniswapSwapSpikes
# We are interested in the Token Transfers for the Uniswap case.
from TokenTransfers
# We have a table with (interesting to us) Uniswap Pools. We want to monitor both BUYs and SELLs for them.
where @to in UniswapPools || @from in UniswapPools
process
# Basic initialization variable for later usage
let threshold = 0
let initiator = 0x0
let pool = 0x0
let action = ""
# If our Trading Asset is used for BUY operation
if @to in UniswapPools && @code_address == UniswapPools[@to].TradingAsset then
threshold = UniswapPools[@to].BuyThreshold
# The address that initiated the BUY operation
initiator = @from
# The pool that was
pool = @to
action = "BUY"
# If our Trading Asset is used for SELL operation
elseif @from in UniswapPools && @code_address == UniswapPools[@from].TradingAsset then
threshold = UniswapPools[@from].SellThreshold
initiator = @to
pool = @from
action = "SELL"
end
# Check that BUY or SELL happened
if action != "" then
# Additional check that we are dealing with ERC-20'ies
if @is_erc20 then
# We compare that the BUY/SELL amount is exceeding the defined (Buy/Sell)Threshold
if compare({value: @value, decimals: @erc20.decimals}, {value: threshold, decimals: 0}) >= 0 then
emit {@value, initiator, pool: UniswapPools[pool].Details, threshold, action, currency: @erc20.symbol, decimals: @erc20.decimals}
end
else
emit {@value, initiator, pool: UniswapPools[pool].Details, threshold, action, currency: "?", decimals: 18}
end
end