Skip to content

Commit

Permalink
pessimistic estimations of GDA (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmachado authored Feb 1, 2024
1 parent 023a2a2 commit 1777c36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/database/businessRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ class BusinessRepository {
return this.app.db.SQLRepository.executeSQLSelect(sqlquery, { bn: fromBlock });
}

async getGDAOutFlowRate(token, distributor) {
const sqlquery = `SELECT SUM(sumNewDistributorToPoolFlowRate) as aggrDistributorFlowRate FROM (SELECT SUM(newDistributorToPoolFlowRate) as sumNewDistributorToPoolFlowRate, pool from flowdistributionupdateds
where distributor = :distributor and superToken = :token
GROUP BY pool
HAVING MAX(blockNumber)) AS P`;
return this.app.db.SQLRepository.executeSQLSelect(sqlquery, { distributor: distributor, token: token });
}

async getAddressEstimations(address) {
return this.app.db.models.AccountEstimationModel.findAll({
attributes: ["address", "superToken", "estimation"],
Expand Down
7 changes: 5 additions & 2 deletions src/protocol/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class Protocol {
try {
this.app.client.addTotalRequest();
if (this.app.client.contracts.getGDAv1Address() === undefined) {
return 0;
return 0;
}
return this.app.client.contracts.GDAv1.methods.getNetFlow(token, account).call();
// return this.app.client.contracts.GDAv1.methods.getNetFlow(token, account).call();
const gdaUserNetFlow = await this.app.db.bizQueries.getGDAOutFlowRate(token, account);
return gdaUserNetFlow[0].aggrDistributorFlowRate === null ?
new BN(0) : (new BN(gdaUserNetFlow[0].aggrDistributorFlowRate.toString())).neg();
} catch (err) {
console.error(err);
throw Error(`Protocol.getGDAUserNetFlow(): ${err}`);
Expand Down

0 comments on commit 1777c36

Please sign in to comment.