opynfinance / gamma-bots Goto Github PK
View Code? Open in Web Editor NEWBots used for Gamma Protocol
Bots used for Gamma Protocol
We can use a config file for all the addresses, e.g. relayerAddress
, addressbookAddress
, chainlinkAggregatorAddress
to minimize the overhead.
There're huge refactor opportunity to adopt the Guard Clause design pattern.
Simple idea is whenever you see there's an if block with no associate else block, you can refactor it a bit to only have a small if - and return
syntax instead of a huge if () {}
. I believe this is a great pattern to follow because as logics get more complicated, we could end up having like 20 if condition and our code will looks like this without this pattern:
if(a) {
// something
if(b) {
// something
if (c) {
// something
if (d) {
// something
}
}
}
}
This is also the pattern we're trying to adopt in the frontend. I think we can try it here as well:
The current code structure is like this.
if(hour == expiryHour) {
if (expiryPrice[0].toString() == '0' && isLockingPeriodOver) {
// round id for expiry timestamp
// check if otoken price is not on-chain, and latest chainlink round timestamp is greater than otoken expiry timestamp and locking period over
if (priceRoundTimestamp.toString() >= expiryTimestamp) {
for (let j = priceRoundId.sub(1); j > 0; j = j.sub(1)) {
previousRoundId = j;
previousRoundTimestamp = await chainlinkAggregator.getTimestamp(j);
if (previousRoundTimestamp.toString() != '0') {
if (previousRoundTimestamp.toString() < expiryTimestamp.toString()) {
break;
}
else {
priceRoundId = previousRoundId;
priceRoundTimestamp = previousRoundTimestamp;
}
}
}
console.log('Found round id: ', priceRoundId.toString());
console.log('Found round timestamp: ', priceRoundTimestamp.toString());
let tx = await pricer.setExpiryPriceInOracle(expiryTimestamp, priceRoundId, {gasLimit: '1000000'});
console.log('Tx hash: ', tx.hash);
}
else {
console.log('Chainlink latest round timestamp is not grater than or equal the expiry timestamp ')
}
}
It could be refactor to the following to avoid nested if block,
if(hour !== expiryHour) return
let expiryPrice = await oracle.getExpiryPrice(pricerAsset, expiryTimestamp);
let isLockingPeriodOver = await oracle.isLockingPeriodOver(pricerAsset, expiryTimestamp);
if (expiryPrice[0].toString() !== '0' || !isLockingPeriodOver) return
// round id for expiry timestamp
let priceRoundId = await chainlinkAggregator.latestRound();
let priceRoundTimestamp = await chainlinkAggregator.getTimestamp(priceRoundId);
// round id before price round id
let previousRoundId;
let previousRoundTimestamp;
// check if otoken price is not on-chain, and latest chainlink round timestamp is greater than otoken expiry timestamp and locking period over
if (priceRoundTimestamp.toString() < expiryTimestamp) {
console.log('Chainlink latest round timestamp is not grater than or equal the expiry timestamp ')
return
}
for (let j = priceRoundId.sub(1); j > 0; j = j.sub(1)) {
previousRoundId = j;
previousRoundTimestamp = await chainlinkAggregator.getTimestamp(j);
if (previousRoudTimestamp.toString() === '0') continue
if (previousRoundTimestamp.toString() < expiryTimestamp.toString()) {
break;
}
else {
priceRoundId = previousRoundId;
priceRoundTimestamp = previousRoundTimestamp;
}
}
console.log('Found round id: ', priceRoundId.toString());
console.log('Found round timestamp: ', priceRoundTimestamp.toString());
let tx = await pricer.setExpiryPriceInOracle(expiryTimestamp, priceRoundId, {gasLimit: '1000000'});
console.log('Tx hash: ', tx.hash);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.