Skip to content

Commit

Permalink
refactor: review
Browse files Browse the repository at this point in the history
  • Loading branch information
phamphong9981 committed Jul 26, 2024
1 parent c7d4e71 commit 0dab396
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
5 changes: 1 addition & 4 deletions ci/config.json.ci
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,7 @@
"blocksPerCall": 100,
"millisecondRepeatJob": 5000,
"chunkSizeInsert": 1000,
"extensionActivityContract": {
"deposit": ["0xE974cC14c93FC6077B0d65F98832B846C5454A0B"],
"withdrawal":["0xE974cC14c93FC6077B0d65F98832B846C5454A0B"]
}
"wrapExtensionContract": ["0xe974cc14c93fc6077b0d65f98832b846c5454a0b"]
},
"erc721": {
"key": "erc721",
Expand Down
5 changes: 1 addition & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,7 @@
"blocksPerCall": 100,
"millisecondRepeatJob": 2000,
"chunkSizeInsert": 1000,
"extensionActivityContract": {
"deposit": ["0xe974cc14c93fc6077b0d65f98832b846c5454a0b"],
"withdrawal":["0xe974cc14c93fc6077b0d65f98832b846c5454a0b"]
}
"wrapExtensionContract": ["0xe974cc14c93fc6077b0d65f98832b846c5454a0b"]
},
"erc721": {
"key": "erc721",
Expand Down
8 changes: 4 additions & 4 deletions src/services/evm/erc20.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ export default class Erc20Service extends BullableService {
if (activity) {
erc20Activities.push(activity);
}
} else {
const extensionActivities = Erc20Handler.buildExtensionActivity(
} else if (config.erc20.wrapExtensionContract.includes(e.address)) {
const wrapActivity = Erc20Handler.buildWrapExtensionActivity(
e,
this.logger
);
if (extensionActivities) {
erc20Activities.push(extensionActivities);
if (wrapActivity) {
erc20Activities.push(wrapActivity);
}
}
});
Expand Down
43 changes: 21 additions & 22 deletions src/services/evm/erc20_handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { decodeAbiParameters, keccak256, toHex } from 'viem';
import { Dictionary } from 'lodash';
import Moleculer from 'moleculer';
import { decodeAbiParameters, keccak256, toHex } from 'viem';
import { Erc20Activity, EvmEvent } from '../../models';
import { AccountBalance } from '../../models/account_balance';
import { ZERO_ADDRESS } from './constant';
import config from '../../../config.json' assert { type: 'json' };

export const ERC20_ACTION = {
TRANSFER: 'transfer',
Expand Down Expand Up @@ -122,7 +121,10 @@ export class Erc20Handler {
}
}

static buildTransferActivity(e: EvmEvent, logger: Moleculer.LoggerInstance) {
static buildTransferActivity(
e: EvmEvent,
logger: Moleculer.LoggerInstance
): Erc20Activity | undefined {
try {
const [from, to, amount] = decodeAbiParameters(
[
Expand Down Expand Up @@ -150,7 +152,10 @@ export class Erc20Handler {
}
}

static buildApprovalActivity(e: EvmEvent, logger: Moleculer.LoggerInstance) {
static buildApprovalActivity(
e: EvmEvent,
logger: Moleculer.LoggerInstance
): Erc20Activity | undefined {
try {
const [from, to, amount] = decodeAbiParameters(
[
Expand Down Expand Up @@ -178,31 +183,25 @@ export class Erc20Handler {
}
}

static buildExtensionActivity(e: EvmEvent, logger: Moleculer.LoggerInstance) {
const contractAddr = e.address;
if (
e.topic0 === ERC20_EVENT_TOPIC0.DEPOSIT &&
// check contract address is in support deposit list
config.erc20.extensionActivityContract.deposit.includes(contractAddr)
) {
const activity = Erc20Handler.buildDepositActivity(e, logger);
static buildWrapExtensionActivity(
e: EvmEvent,
logger: Moleculer.LoggerInstance
): Erc20Activity | undefined {
if (e.topic0 === ERC20_EVENT_TOPIC0.DEPOSIT) {
const activity = Erc20Handler.buildWrapDepositActivity(e, logger);
return activity;
}
if (
e.topic0 === ERC20_EVENT_TOPIC0.WITHDRAWAL &&
// check contract address is in support withdrawal list
config.erc20.extensionActivityContract.withdrawal.includes(contractAddr)
) {
const activity = Erc20Handler.buildWithdrawalActivity(e, logger);
if (e.topic0 === ERC20_EVENT_TOPIC0.WITHDRAWAL) {
const activity = Erc20Handler.buildWrapWithdrawalActivity(e, logger);
return activity;
}
return undefined;
}

private static buildDepositActivity(
private static buildWrapDepositActivity(
e: EvmEvent,
logger: Moleculer.LoggerInstance
) {
): Erc20Activity | undefined {
try {
const [to, amount] = decodeAbiParameters(
[ABI_TRANSFER_PARAMS.TO, ABI_APPROVAL_PARAMS.VALUE],
Expand All @@ -226,10 +225,10 @@ export class Erc20Handler {
}
}

private static buildWithdrawalActivity(
private static buildWrapWithdrawalActivity(
e: EvmEvent,
logger: Moleculer.LoggerInstance
) {
): Erc20Activity | undefined {
try {
const [from, amount] = decodeAbiParameters(
[ABI_TRANSFER_PARAMS.FROM, ABI_APPROVAL_PARAMS.VALUE],
Expand Down

0 comments on commit 0dab396

Please sign in to comment.