Skip to content

Commit

Permalink
Temporary fix for the sifchain #84 #81
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunnini committed Apr 20, 2021
1 parent 84ab794 commit ecb1dc3
Showing 1 changed file with 53 additions and 44 deletions.
97 changes: 53 additions & 44 deletions packages/stores/src/query/cosmos/supply/inflation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,56 +41,65 @@ export class ObservableQueryInflation {
// If the staking pool info is fetched, this will consider this info for calculating the more accurate value.
@computed
get inflation(): IntPretty {
let dec: Dec | undefined;
try {
let dec: Dec | undefined;

// XXX: Hard coded part for the iris hub and sifchain.
// TODO: Remove this part.
const chainInfo = this.chainGetter.getChain(this.chainId);
if (chainInfo.chainId.startsWith("irishub")) {
dec = new Dec(
this._queryIrisMint.response?.data.result.inflation ?? "0"
).mul(DecUtils.getPrecisionDec(2));
} else if (chainInfo.chainId.startsWith("sifchain")) {
return new IntPretty(
new Dec(this._querySifchainAPY.liquidityAPY.toString())
);
} else {
dec = new Dec(this._queryMint.response?.data.result ?? "0").mul(
DecUtils.getPrecisionDec(2)
);
}
// XXX: Hard coded part for the iris hub and sifchain.
// TODO: Remove this part.
const chainInfo = this.chainGetter.getChain(this.chainId);
if (chainInfo.chainId.startsWith("irishub")) {
dec = new Dec(
this._queryIrisMint.response?.data.result.inflation ?? "0"
).mul(DecUtils.getPrecisionDec(2));
} else if (chainInfo.chainId.startsWith("sifchain")) {
return new IntPretty(
new Dec(this._querySifchainAPY.liquidityAPY.toString())
);
} else {
dec = new Dec(this._queryMint.response?.data.result ?? "0").mul(
DecUtils.getPrecisionDec(2)
);
}

if (!dec || dec.equals(new Dec(0))) {
return new IntPretty(new Int(0)).ready(false);
}
if (!dec || dec.equals(new Dec(0))) {
return new IntPretty(new Int(0)).ready(false);
}

if (
this._queryPool.response &&
this._querySupplyTotal.getQueryStakeDenom().response
) {
const bondedToken = new Dec(
this._queryPool.response.data.result.bonded_tokens
);
const totalStr = (() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const response = this._querySupplyTotal.getQueryStakeDenom().response!
.data.result;
if (
this._queryPool.response &&
this._querySupplyTotal.getQueryStakeDenom().response
) {
const bondedToken = new Dec(
this._queryPool.response.data.result.bonded_tokens
);
const totalStr = (() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const response = this._querySupplyTotal.getQueryStakeDenom().response!
.data.result;

if (typeof response === "string") {
return response;
} else {
return response.amount;
}
})();
const total = new Dec(totalStr);
if (total.gt(new Dec(0))) {
const ratio = bondedToken.quo(total);
if (typeof response === "string") {
return response;
} else {
return response.amount;
}
})();
const total = new Dec(totalStr);
if (total.gt(new Dec(0))) {
const ratio = bondedToken.quo(total);

dec = dec.quo(ratio);
// TODO: Rounding?
dec = dec.quo(ratio);
// TODO: Rounding?
}
}
}

return new IntPretty(dec);
return new IntPretty(dec);
} catch (e) {
console.log(e);
// XXX: There have been reported errors regarding Sifchain.
// However, I wasn’t able to reproduce the error so exact cause haven’t been identified.
// For now, use try-catch on suspect parts to resolve the issue. Will be on a lookout for a more permanent solution in the future.

return new IntPretty(new Int(0)).ready(false);
}
}
}

0 comments on commit ecb1dc3

Please sign in to comment.