Skip to content

Commit

Permalink
feat: add scam filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnoW committed Mar 24, 2023
1 parent ff40a18 commit ecc414a
Show file tree
Hide file tree
Showing 31 changed files with 140 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/wise-tomatoes-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moralisweb3/common-evm-utils': minor
'@moralisweb3/evm-api': minor
---

Add spam detection
9 changes: 9 additions & 0 deletions packages/common/evmUtils/src/dataTypes/Erc20/Erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Erc20Token implements MoralisDataObject {
logoHash: maybe(value.logoHash),
thumbnail: maybe(value.thumbnail),
chain: EvmChain.create(value.chain, core),
possibleSpam: value.possibleSpam,
});

/**
Expand Down Expand Up @@ -229,4 +230,12 @@ export class Erc20Token implements MoralisDataObject {
get thumbnail() {
return this._value.thumbnail;
}

/**
* @returns possibility of the token being a spam token
* @example transfer.possibleSpam // true
*/
get possibleSpam() {
return this._value.possibleSpam;
}
}
3 changes: 3 additions & 0 deletions packages/common/evmUtils/src/dataTypes/Erc20/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EvmChain, EvmChainish } from '../EvmChain';
* thumbnail: null,
* decimals: "6",
* chain: 1,
* possibleSpam: false,
* }
* ```
*/
Expand All @@ -27,6 +28,7 @@ export interface Erc20Input {
logo?: string | null;
logoHash?: string | null;
thumbnail?: string | null;
possibleSpam?: boolean;
}

/**
Expand All @@ -41,4 +43,5 @@ export interface Erc20Data {
logo?: string | null;
logoHash?: string | null;
thumbnail?: string | null;
possibleSpam?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const exampleInput: Erc20ApprovalInput = {
transactionHash: '0xb7b4d321e2ab26c1cde1a2ef49413e21b65dcc663d6de8f75ddbdd868b98b4bf',
transactionIndex: 4,
logIndex: 25,
possibleSpam: false,
value: '100000000000000000000000000000',
};

Expand Down Expand Up @@ -43,6 +44,7 @@ describe('Erc20Approval', () => {
expect(erc20Approval.transactionHash).toBe('0xb7b4d321e2ab26c1cde1a2ef49413e21b65dcc663d6de8f75ddbdd868b98b4bf');
expect(erc20Approval.transactionIndex).toBe(4);
expect(erc20Approval.logIndex).toBe(25);
expect(erc20Approval.possibleSpam).toBe(false);
expect(erc20Approval.value.toString()).toBe('100000000000000000000000000000');
});

Expand All @@ -65,6 +67,7 @@ describe('Erc20Approval', () => {
transactionHash: '0xb7b4d321e2ab26c1cde1a2ef49413e21b65dcc663d6de8f75ddbdd868b98b4bf',
transactionIndex: 4,
logIndex: 25,
possibleSpam: false,
value: '100000000000000000000000000000',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,12 @@ export class Erc20Approval implements MoralisDataObject {
get logIndex() {
return this._data.logIndex;
}

/**
* @returns possibility of the token being a spam token
* @example transfer.possibleSpam // true
*/
get possibleSpam() {
return this._data.possibleSpam;
}
}
3 changes: 3 additions & 0 deletions packages/common/evmUtils/src/dataTypes/Erc20Approval/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { EvmChain, EvmChainish } from '../EvmChain';
* transactionHash: "0xb7b4d321e2ab26c1cde1a2ef49413e21b65dcc663d6de8f75ddbdd868b98b4bf",
* transactionIndex: "4",
* logIndex: "25",
* possibleSpam: false,
* value: "100000000000000000000000000000"
* }
* ```
Expand All @@ -32,6 +33,7 @@ export interface Erc20ApprovalInput {
transactionIndex: number;
logIndex: number;
value: BigNumberish;
possibleSpam: boolean;
}

/**
Expand All @@ -49,4 +51,5 @@ export interface Erc20ApprovalData {
transactionIndex: number;
logIndex: number;
value: BigNumber;
possibleSpam: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const exampleInput: Erc20TransferInput = {
transactionIndex: 4,
logIndex: 25,
value: '100000000000000000000000000000',
possibleSpam: false,
};

describe('Erc20Transfer', () => {
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('Erc20Transfer', () => {
expect(erc20Mint.transactionHash).toBe('0xb7b4d321e2ab26c1cde1a2ef49413e21b65dcc663d6de8f75ddbdd868b98b4bf');
expect(erc20Mint.transactionIndex).toBe(4);
expect(erc20Mint.logIndex).toBe(25);
expect(erc20Mint.possibleSpam).toBe(false);
expect(erc20Mint.value.toString()).toBe('100000000000000000000000000000');
});

Expand All @@ -72,6 +74,7 @@ describe('Erc20Transfer', () => {
transactionHash: '0xb7b4d321e2ab26c1cde1a2ef49413e21b65dcc663d6de8f75ddbdd868b98b4bf',
transactionIndex: 4,
logIndex: 25,
possibleSpam: false,
value: '100000000000000000000000000000',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,12 @@ export class Erc20Transfer implements MoralisDataObject {
get logIndex() {
return this._data.logIndex;
}

/**
* @returns possibility of the token being a spam token
* @example transfer.possibleSpam // true
*/
get possibleSpam() {
return this._data.possibleSpam;
}
}
7 changes: 5 additions & 2 deletions packages/common/evmUtils/src/dataTypes/Erc20Transfer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import { EvmChain, EvmChainish } from '../EvmChain';
* blockTimestamp: "2021-04-02T10:07:54.000Z",
* blockHash: "0x0372c302e3c52e8f2e15d155e2c545e6d802e479236564af052759253b20fd86",
* blockNumber: "12526958",
* transactionHash: "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09"
* transactionIndex: 3;
* transactionHash: "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
* transactionIndex: 3,
* possibleSpam: false,
* logIndex: 2
* }
* ```
Expand All @@ -34,6 +35,7 @@ export interface Erc20TransferInput {
value: BigNumberish;
transactionIndex: number;
logIndex: number;
possibleSpam: boolean;
}

/**
Expand All @@ -51,4 +53,5 @@ export interface Erc20TransferData {
value: BigNumber;
transactionIndex: number;
logIndex: number;
possibleSpam: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('EvmNftMedia', () => {
expect(erc20Mint.mimetype).toBe('image/png');
expect(erc20Mint.parentHash).toBe('0x21ba1263dd63696f0d9ede101b00a4e2f4985a854483076c92a3415624fca051');
expect(erc20Mint.status).toBe('success');
expect(erc20Mint.updatedAt.toISOString()).toBe('2023-03-17T14:12:24.192Z');
expect(erc20Mint.updatedAt?.toISOString()).toBe('2023-03-17T14:12:24.192Z');
expect(erc20Mint.originalMediaUrl).toBe('original_url');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Core, { MoralisDataObject, dateInputToDate, CoreProvider } from '@moralisweb3/common-core';
import Core, { MoralisDataObject, dateInputToDate, CoreProvider, maybe } from '@moralisweb3/common-core';
import { EvmChain } from '../EvmChain';
import { EvmNftMediaInput, EvmNftMediaData } from './types';

Expand All @@ -16,7 +16,7 @@ export class EvmNftMedia implements MoralisDataObject {
* const media = EvmNftMedia.create(data);
*```
*/
static create(data: EvmNftMedia | EvmNftMediaInput, core?: Core) {
static create(data: EvmNftMediaInput, core?: Core) {
if (data instanceof EvmNftMedia) {
return data;
}
Expand All @@ -34,7 +34,7 @@ export class EvmNftMedia implements MoralisDataObject {
static parse = (data: EvmNftMediaInput, core: Core): EvmNftMediaData => ({
...data,
chain: EvmChain.create(data.chain, core),
updatedAt: dateInputToDate(data.updatedAt),
updatedAt: maybe(data.updatedAt, (date) => dateInputToDate(date)),
});

/**
Expand Down
19 changes: 13 additions & 6 deletions packages/common/evmUtils/src/dataTypes/EvmNftMedia/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { DateInput } from '@moralisweb3/common-core';
import { EvmChain, EvmChainish } from '../EvmChain';

export type EvmNftMediaCategory = 'image' | 'video' | 'audio';
export type EvmNftMediaStatus =
| 'success'
| 'processing'
| 'unsupported_media'
| 'invalid_url'
| 'host_unavailable'
| 'temporarily_unavailable';

export type EvmNftMediaItem = {
height: number;
Expand All @@ -11,9 +18,9 @@ export type EvmNftMediaItem = {

export interface EvmNftMediaInput {
chain: EvmChainish;
status: string;
updatedAt: DateInput;
originalMediaUrl: string;
status?: EvmNftMediaStatus;
updatedAt?: DateInput;
originalMediaUrl?: string;
category?: EvmNftMediaCategory;
mimetype?: string;
parentHash?: string;
Expand All @@ -26,9 +33,9 @@ export interface EvmNftMediaInput {

export interface EvmNftMediaData {
chain: EvmChain;
status: string;
updatedAt: Date;
originalMediaUrl: string;
status?: EvmNftMediaStatus;
updatedAt?: Date;
originalMediaUrl?: string;
category?: EvmNftMediaCategory;
mimetype?: string;
parentHash?: string;
Expand Down
54 changes: 45 additions & 9 deletions packages/common/evmUtils/src/operations/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ export interface components {
* @example 1234
*/
value: string;
/**
* @description Indicates if a contract is possibly a spam contract
* @example false
*/
possible_spam: boolean;
};
erc20Burn: {
/** @example 0x3105d328c66d8d55092358cf595d54608178e9b5 */
Expand Down Expand Up @@ -621,6 +626,11 @@ export interface components {
* @example 1234
*/
value: string;
/**
* @description Indicates if a contract is possibly a spam contract
* @example false
*/
possible_spam: boolean;
};
erc20TransfersResponse: {
/** @description The cursor to get to the next page */
Expand Down Expand Up @@ -1221,6 +1231,11 @@ export interface components {
* @example 123456789
*/
balance: string;
/**
* @description Indicates if a contract is possibly a spam contract
* @example false
*/
possible_spam: boolean;
};
nativeBalance: {
/**
Expand Down Expand Up @@ -1711,28 +1726,39 @@ export interface components {
url: string;
};
mediaCollection: {
/** @description Information about the original media file */
original: components["schemas"]["mediaItem"];
/** @description Preview media file, lowest quality (for images 100px x 100px) */
low: components["schemas"]["mediaItem"];
/** @description Preview media file, medium quality (for images 250px x 250px) */
medium: components["schemas"]["mediaItem"];
/** @description Preview media file, highest quality (for images 500px x 500px) */
high: components["schemas"]["mediaItem"];
} & {
original: unknown;
};
media: {
status: string;
updatedAt: string;
/** @description The mimetype of the media file [see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types] */
mimetype: string;
mimetype?: string;
/** @enum {undefined} */
category: "image" | "audio" | "video";
category?: "image" | "audio" | "video";
/**
* @description <table><tr><td>success</td><td>The NFT Preview was created / retrieved successfully</td></tr><tr><td>processing</td><td>The NFT Preview was not found and has been submitted for generation.</td></tr><tr><td>unsupported_media</td><td>The mime-type of the NFT's media file indicates a type not currently supported.</td></tr><tr><td>invalid_url</td><td>The 'image' URL from the NFT's metadata is not a valid URL and cannot be processed.</td></tr><tr><td>host_unavailable</td><td>The 'image' URL from the NFT's metadata returned an HttpCode indicating the host / file is not available.</td></tr><tr><td>temporarily_unavailable</td><td>The attempt to load / parse the NFT media file failed (usually due to rate limiting) and will be tried again at next request.</td></tr></table>
* @enum {undefined}
*/
status?:
| "success"
| "processing"
| "unsupported_media"
| "invalid_url"
| "host_unavailable"
| "temporarily_unavailable";
/** @description The url of the original media file. */
original_media_url: string;
original_media_url?: string;
/** @description The timestamp of the last update to this NFT media record. */
updatedAt?: string;
/** @description Hash value of the original media file. */
parent_hash: string;
parent_hash?: string;
/** @description Preview item associated with the original */
media_collection: components["schemas"]["mediaCollection"];
media_collection?: components["schemas"]["mediaCollection"];
};
nftOwnerCollection: {
/**
Expand Down Expand Up @@ -1947,6 +1973,11 @@ export interface components {
* @example 2
*/
log_index: number;
/**
* @description Indicates if a contract is possibly a spam contract
* @example false
*/
possible_spam: boolean;
};
historicalNftTransfer: {
/**
Expand Down Expand Up @@ -2032,6 +2063,11 @@ export interface components {
thumbnail?: string;
block_number?: string;
validated?: string;
/**
* @description Indicates if a contract is possibly a spam contract
* @example false
*/
possible_spam: boolean;
};
metadataResync: {
/** @description The status of the resync request */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function deserializeResponse(
logo: token.logo,
thumbnail: token.thumbnail,
chain: EvmChainResolver.resolve(request.chain, core),
possibleSpam: token.possible_spam,
},
},
core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const mockGetErc20Approvals = MockScenarios.create(
transaction_index: '148',
log_index: '356',
value: '80000000000000000',
possible_spam: false,
},
{
from_wallet: '0xbafa44efe7901e04e39dad13167d089c559c1138',
Expand All @@ -53,6 +54,7 @@ export const mockGetErc20Approvals = MockScenarios.create(
transaction_index: '148',
log_index: '355',
value: '80000000000000000',
possible_spam: false,
},
{
from_wallet: '0xa7ba1c6d5ffa3ce2542e04bc3e4b4021bcc2e134',
Expand All @@ -65,6 +67,7 @@ export const mockGetErc20Approvals = MockScenarios.create(
transaction_index: '141',
log_index: '340',
value: '115792089237316195423570985008687907853269984665640563249457584007913129639935',
possible_spam: false,
},
],
},
Expand Down
Loading

0 comments on commit ecc414a

Please sign in to comment.