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 31bc9d4 commit f813372
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 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
40 changes: 20 additions & 20 deletions src/services/evm/erc20_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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 @@ -220,7 +223,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 @@ -248,31 +254,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 @@ -296,10 +296,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 f813372

Please sign in to comment.