Skip to content

Commit

Permalink
fix event check (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmachado committed Jan 13, 2022
1 parent 5012ff3 commit 2beb41c
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 248 deletions.
5 changes: 5 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class App {
return this.db.queries.getEstimations();
}

// return PIC saved on database
async getPICInfo(onlyTokens) {
return this.db.queries.getPICInfo(onlyTokens);
}

// close agent processes and exit
async shutdown (force = false) {
this._isShutdown = true;
Expand Down
1 change: 1 addition & 0 deletions src/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Config {
this.SHUTDOWN_ON_ERROR = config.shutdown_on_error;
this.LIQUIDATION_JOB_AWAITS = config.liquidation_job_awaits;
this.ONLY_LISTED_TOKENS = config.only_listed_tokens === "true";
this.TOGA_CONTRACT = config.toga_contract;
} else {
this.HTTP_RPC_NODE = process.env.HTTP_RPC_NODE;
this.MNEMONIC = process.env.MNEMONIC;
Expand Down
21 changes: 21 additions & 0 deletions src/database/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ class Repository {
}
return UserConfig.create({ config: configString });
}

async getPICInfo(onlyTokens) {
let inSnipped = "";
if (onlyTokens !== undefined) {
inSnipped = "where address in (:tokens)";
}
const sqlquery = `SELECT address, symbol, name, pic from supertokens ${inSnipped}`;

if (inSnipped !== "") {
return this.app.db.query(sqlquery, {
replacements: {
tokens: onlyTokens
},
type: QueryTypes.SELECT
});
}

return this.app.db.query(sqlquery, {
type: QueryTypes.SELECT
});
}
}

module.exports = Repository;
2 changes: 1 addition & 1 deletion src/protocol/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Protocol {

async calculateAndSaveTokenDelay (superToken) {
try {
const tokenInfo = this.app.client.superTokenNames[superToken];
const tokenInfo = this.app.client.superTokenNames[superToken.toLowerCase()];
const currentTokenPIC = await this.getCurrentPIC(superToken);
const rewardAccount = await this.getRewardAddress(superToken);
const token = await SuperTokenModel.findOne({ where: { address: this.app.client.web3.utils.toChecksumAddress(superToken) } });
Expand Down
44 changes: 24 additions & 20 deletions src/web3client/eventTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,23 @@ class EventTracker {

async processIDAEvent (event) {
try {
if (this.app.client.isSuperTokenRegistered(event.token) && event.eventName === "IndexUpdated") {
this.app.logger.debug(`[IndexUpdated] - ${event.eventName} [${event.token}] - publisher ${event.publisher}`);
this.app.queues.estimationQueue.push([
{
self: this,
account: event.publisher,
token: event.token,
blockNumber: event.blockNumber,
blockHash: event.blockHash,
transactionHash: event.transactionHash,
parentCaller: "processIDAEvent"
}
]);
} else {
this.app.logger.debug(`[IDA]: token ${event.token} is not subscribed`);
if(event.eventName === "IndexUpdated") {
if (this.app.client.isSuperTokenRegistered(event.token)) {
this.app.logger.debug(`[IndexUpdated] - ${event.eventName} [${event.token}] - publisher ${event.publisher}`);
this.app.queues.estimationQueue.push([
{
self: this,
account: event.publisher,
token: event.token,
blockNumber: event.blockNumber,
blockHash: event.blockHash,
transactionHash: event.transactionHash,
parentCaller: "processIDAEvent"
}
]);
} else {
this.app.logger.debug(`[IDA]: token ${event.token} is not subscribed`);
}
}
} catch (err) {
this.app.logger.error(err);
Expand All @@ -182,11 +184,13 @@ class EventTracker {

async processTOGAEvent (event) {
try {
if (this.app.client.isSuperTokenRegistered(event.token) && event.eventName === "NewPic") {
this.app.logger.info(`[TOGA]: ${event.eventName} [${event.token}] new pic ${event.pic}`);
this.app.protocol.calculateAndSaveTokenDelay(event.token);
} else {
this.app.logger.debug(`[TOGA]: token ${event.token} is not subscribed`);
if(event.eventName === "NewPIC") {
if (this.app.client.isSuperTokenRegistered(event.token)) {
this.app.logger.info(`[TOGA]: ${event.eventName} [${event.token}] new pic ${event.pic}`);
this.app.protocol.calculateAndSaveTokenDelay(event.token);
} else {
this.app.logger.debug(`[TOGA]: token ${event.token} is not subscribed`);
}
}
} catch (err) {
this.app.logger.error(err);
Expand Down
Loading

0 comments on commit 2beb41c

Please sign in to comment.