Bots, Bots everywhere using OZ Defender
- Clone this repo.
- Hop into
/defender-script
- Run
yarn install --frozen-lockfile
.
Chainlink pricer autotask is a JS script that run every 1 min to push a specific asset price from Chainlink to the Oracle module through the pricer contract.
Every Chainlink pricer bot have:
- Relayer address: the wallet address used to make transactions (managed by OZ Defender)
- AddressBook address: Gamma Addressbook module
- Pricer address: the pricer contract that handle pushing the asset price to the Oracle module
- Add .env file
- Run
yarn chainlink-pricer
for Chainlink pricer. - run
yarn liquidate-me-bro
to run vault collateral threshold bot
- Loop through all Otoken contracts deployed from OtokenFactory
- Get the underlying, strike and collateral asset from the Otoken
- If
- One of those assets is equal to the pricer asset
- And current timestamp equal or passed the Otoken expiry timestamp
- And no price pushed before for this asset at this timestamp in the Oracle module
- And pricer locking period is passed
- Then get the round ID from chainlink that correspond to the asset price at the expiry timestamp
- Call the Pricer contract to submit price to Oracle module through
setExpiryPriceInOracle(expiryTimestamp, priceRoundId)
- Get current round ID and round timestamp
- If current round timestamp greater or equal expiry timestamp
- Get previous round ID and previosu round timestamp and store it
- If previous round timestamp is different than zero
- If previous round timestamp is less than expiry timestamp then exit loop (roundTimestamp >= expiry && previousRoundTimestamp < expiry => round ID found)
- Else store previous round ID and timestamp in current round ID and decrease ID by 1
Chainlink disputer autotoask is a JS script that run every 1 min to disputer new WETH/USD pushed prices in case a specific price deviate a %X from the off-chain source.
Chainlink disputer autotask have:
- Relayer address: the wallet address used to make transactions (managed by OZ Defender)
- AddressBook address: Gamma Addressbook module
- Add
API_KEY
andAPI_SECRET
(Relayer keys) andINFURA_KEY
into.env
file. - Run
yarn chainlink-pricer
for Chainlink pricer.
- Get ETH hourly prices from coinbase
- Loop through all Otoken contracts deployed from OtokenFactory
- If current timestamp equal or passed otoken expiry timestamp
- loop through coinbase prices array, and get the price that correspond to the expiry timestamp
- Get the underlying, strike and collateral asset from the Otoken
- If
- One of those assets is equal to WETH
- And locking period is passed
- And dispute period is not over
- Get asset price(WETH) from Oracle and divide it by 1e8
- If price is different then 0 (price is pushed from pricer), calculate difference between on-chain and off-chain price
- If difference greater than 0.1% of the off-chain price, dispute oracle price
by submitting off-chain price through
disputeExpiryPrice()
in Oracle.sol passingWETH address
,expiry timestamp
and thenew price
as args