Skip to content

Commit 5a89c1c

Browse files
authored
Merge pull request #490 from solidityteam/fix/liq-parse
fix: liquidity can be object or number
2 parents c758e02 + def4fe5 commit 5a89c1c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

indexer/src/services/pair-service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,15 @@ export class PairService {
794794
// Parse the parameters
795795
const [sender, to, token0Ref, token1Ref, amount0, amount1, liquidity] = JSON.parse(
796796
event.parameters,
797-
) as [string, string, TokenReference, TokenReference, TokenAmount, TokenAmount, number];
797+
) as [
798+
string,
799+
string,
800+
TokenReference,
801+
TokenReference,
802+
TokenAmount,
803+
TokenAmount,
804+
TokenAmount,
805+
];
798806

799807
// Convert TokenAmount to string representation
800808
const amount0Str = typeof amount0 === 'number' ? amount0.toString() : amount0.decimal;
@@ -836,10 +844,12 @@ export class PairService {
836844
);
837845

838846
let totalSupply = Number(pair.totalSupply);
847+
const liquidityStr =
848+
typeof liquidity === 'number' ? liquidity.toString() : liquidity.decimal;
839849
if (event.name === 'ADD_LIQUIDITY') {
840-
totalSupply = Number(pair.totalSupply) + Number(liquidity);
850+
totalSupply = Number(pair.totalSupply) + Number(liquidityStr);
841851
} else {
842-
totalSupply = Number(pair.totalSupply) - Number(liquidity);
852+
totalSupply = Number(pair.totalSupply) - Number(liquidityStr);
843853
}
844854
await pair.update(
845855
{

0 commit comments

Comments
 (0)