Skip to content

Commit

Permalink
refactor: erc20 activity transfer amount in topic3
Browse files Browse the repository at this point in the history
  • Loading branch information
phamphong9981 committed Jul 30, 2024
1 parent c97ec7c commit 1c40569
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/services/evm/erc20_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Erc20Handler {
this.erc20Contracts[erc20Activity.erc20_contract_address];
if (!erc20Contract) {
throw new Error(
`Erc20 contract not found:${ erc20Activity.erc20_contract_address}`
`Erc20 contract not found:${erc20Activity.erc20_contract_address}`
);
}
// update from account balance if from != ZERO_ADDRESS
Expand Down Expand Up @@ -122,13 +122,13 @@ export class Erc20Handler {
type: AccountBalance.TYPE.ERC20_TOKEN,
});
} else if (erc20Contract.total_supply !== null) {
// update total supply
erc20Contract.total_supply = (
BigInt(erc20Contract.total_supply) + BigInt(erc20Activity.amount)
).toString();
// update last updated height
erc20Contract.last_updated_height = erc20Activity.height;
}
// update total supply
erc20Contract.total_supply = (
BigInt(erc20Contract.total_supply) + BigInt(erc20Activity.amount)
).toString();
// update last updated height
erc20Contract.last_updated_height = erc20Activity.height;
}
// update from account balance if to != ZERO_ADDRESS
if (erc20Activity.to !== ZERO_ADDRESS) {
// update to account balance
Expand Down Expand Up @@ -156,13 +156,13 @@ export class Erc20Handler {
type: AccountBalance.TYPE.ERC20_TOKEN,
});
} else if (erc20Contract.total_supply !== null) {
// update total supply
erc20Contract.total_supply = (
BigInt(erc20Contract.total_supply) - BigInt(erc20Activity.amount)
).toString();
// update last updated height
erc20Contract.last_updated_height = erc20Activity.height;
}
// update total supply
erc20Contract.total_supply = (
BigInt(erc20Contract.total_supply) - BigInt(erc20Activity.amount)
).toString();
// update last updated height
erc20Contract.last_updated_height = erc20Activity.height;
}
}

static async buildErc20Activities(
Expand Down Expand Up @@ -348,13 +348,14 @@ export class Erc20Handler {
logger: Moleculer.LoggerInstance
): Erc20Activity | undefined {
try {
const amountEncoded = e.data ? toHex(e.data) : e.topic3;
const [from, to, amount] = decodeAbiParameters(
[
ABI_TRANSFER_PARAMS.FROM,
ABI_TRANSFER_PARAMS.TO,
ABI_TRANSFER_PARAMS.VALUE,
],
(e.topic1 + e.topic2.slice(2) + toHex(e.data).slice(2)) as `0x${string}`
(e.topic1 + e.topic2.slice(2) + amountEncoded.slice(2)) as `0x${string}`
) as [string, string, bigint];
return Erc20Activity.fromJson({
evm_event_id: e.id,
Expand Down

0 comments on commit 1c40569

Please sign in to comment.