Skip to content

Commit

Permalink
feat(#114): improve profitability check in case of non-ada pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhxyz committed Oct 17, 2024
1 parent fd886c2 commit fc33d14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions geniusyield-orderbot-framework/src/GeniusYield/OrderBot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ data OrderBot = OrderBot
, botTakeMatches :: [MatchResult] -> IO [MatchResult]
-- ^ How and how many matching results do the bot takes to build, sign and
-- submit every iteration.
, botLovelaceWarningThreshold :: Maybe Natural
-- ^ See 'botCLovelaceWarningThreshold'.
}

{- | Currently, we only have the parallel execution strategy: @MultiAssetTraverse@,
Expand Down Expand Up @@ -128,6 +130,7 @@ runOrderBot
, botAssetPairFilter
, botRescanDelay
, botTakeMatches
, botLovelaceWarningThreshold
} = do
withCfgProviders cfg "" $ \providers -> do
let logInfo = gyLogInfo providers "SOR"
Expand All @@ -146,6 +149,7 @@ runOrderBot
, " Wallet Addresses: " ++ show (Txt.unpack . addressToText <$> botAddrs)
, " Change Address: " ++ (Txt.unpack . addressToText $ botChangeAddr)
, " Collateral: " ++ show botCollateral
, " Lovelace balance warning threshold: " ++ show botLovelaceWarningThreshold
, " Scan delay (µs): " ++ show botRescanDelay
, " Token Pairs to scan:"
, unlines (map (("\t - " ++) . show) botAssetPairFilter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Data.List (nub)
import Data.Random (sample, shuffle)
import Data.String (IsString (..))
import qualified Data.Vector as V
import Data.Word (Word64)
import GHC.Generics (Generic)
import GeniusYield.OrderBot
import GeniusYield.OrderBot.MatchingStrategy (MatchResult)
Expand Down Expand Up @@ -79,13 +80,14 @@ data OrderBotConfig
, botCRandomizeMatchesFound :: Bool
-- ^ A boolean that dictates whether the bot chooses the tx to submit at
-- random (to decrease collisions), or not (to maximize profit)
, botCLovelaceWarningThreshold :: Maybe Natural
-- ^ If bot's lovelace balance falls below this value, bot would log warning logs.
}
deriving stock (Show, Eq, Generic)

instance FromEnv OrderBotConfig where
fromEnv _ =
OrderBotConfig
<$> (Right . parseCBORSKey <$> env "BOTC_SKEY")
(OrderBotConfig . Right . parseCBORSKey <$> env "BOTC_SKEY")
<*> (fmap fromString <$> envMaybe "BOTC_STAKE_ADDRESS")
<*> (fmap fromString <$> envMaybe "BOTC_COLLATERAL")
<*> envWithMsg ("Invalid Strategy. Must be one of: " ++ show allStrategies) "BOTC_EXECUTION_STRAT"
Expand All @@ -94,6 +96,8 @@ instance FromEnv OrderBotConfig where
<*> envIntWithMsg "BOTC_MAX_ORDERS_MATCHES"
<*> envIntWithMsg "BOTC_MAX_TXS_PER_ITERATION"
<*> envWithMsg "Must be either 'True' or 'False'" "BOTC_RANDOMIZE_MATCHES_FOUND"
-- Apparently, there is no `Var` instance for `Natural` in `System.Envy`.
<*> (fmap (fromIntegral @Word64 @Natural) <$> envMaybe "BOTC_LOVELACE_WARNING_THRESHOLD")
where
parseCBORSKey :: String -> GYPaymentSigningKey
parseCBORSKey s =
Expand All @@ -115,8 +119,7 @@ envWithMsg msg name = maybe (throwError $ unwords ["Error parsing enviroment var

instance FromJSON OrderBotConfig where
parseJSON (Object obj) =
OrderBotConfig
<$> (Left <$> obj .: "signingKeyFP")
(OrderBotConfig . Left <$> (obj .: "signingKeyFP"))
<*> obj .:? "stakeAddress"
<*> obj .:? "collateral"
<*> obj .: "strategy"
Expand All @@ -125,6 +128,7 @@ instance FromJSON OrderBotConfig where
<*> obj .: "maxOrderMatches"
<*> obj .: "maxTxsPerIteration"
<*> obj .: "randomizeMatchesFound"
<*> obj .:? "lovelaceWarningThreshold"
parseJSON _ = fail "Expecting object value"

parseScanTokenPairs :: Value -> Aeson.Parser [OrderAssetPair]
Expand Down Expand Up @@ -152,6 +156,7 @@ buildOrderBot
, botCMaxOrderMatches
, botCMaxTxsPerIteration
, botCRandomizeMatchesFound
, botCLovelaceWarningThreshold
} = do
skey <- either readPaymentSigningKey return botCSkey
maxOrderMatch <- intToNatural "Max Order matches amount" botCMaxOrderMatches
Expand All @@ -170,6 +175,7 @@ buildOrderBot
, botAssetPairFilter = nub oneEquivalentAssetPair
, botRescanDelay = botCRescanDelay
, botTakeMatches = takeMatches botCRandomizeMatchesFound maxTxPerIter
, botLovelaceWarningThreshold = botCLovelaceWarningThreshold
}
where
buildCollateral :: Maybe (GYTxOutRef, Bool)
Expand Down

0 comments on commit fc33d14

Please sign in to comment.