Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit cfa72fa

Browse files
authored
Revert "Remove backfill token types job" (#255)
* Revert "Remove backfill token types job (#252)" This reverts commit 1f50816. * Update backfill-token-types.js
1 parent f3a8cfe commit cfa72fa

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/jobs/backfill-token-types.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const signale = require('signale');
2+
3+
const { TOKEN_TYPE } = require('../constants');
4+
const Fill = require('../model/fill');
5+
const Token = require('../model/token');
6+
7+
const logger = signale.scope('backfill token types');
8+
9+
const getTokenType = assetProxyId => {
10+
return {
11+
'0xf47261b0': TOKEN_TYPE.ERC20,
12+
'0x02571792': TOKEN_TYPE.ERC721,
13+
}[assetProxyId];
14+
};
15+
16+
const backfillTokenTypes = async () => {
17+
const tokens = await Token.find({ type: null }).limit(100);
18+
19+
logger.info(`found ${tokens.length} without their type set`);
20+
21+
if (tokens.length === 0) {
22+
return;
23+
}
24+
25+
await Promise.all(
26+
tokens.map(async token => {
27+
const fill = await Fill.findOne({ 'assets.tokenAddress': token.address });
28+
29+
if (fill === null) {
30+
logger.warn(`unable to find fill matching ${token.address}`);
31+
return;
32+
}
33+
34+
let tokenType;
35+
36+
if (
37+
fill.protocolVersion === 1 ||
38+
fill.protocolVersion === undefined ||
39+
fill.protocolVersion === null
40+
) {
41+
tokenType = TOKEN_TYPE.ERC20;
42+
} else if (fill.makerAsset.tokenAddress === token.address) {
43+
tokenType = getTokenType(fill.makerAsset.assetProxyId);
44+
} else {
45+
tokenType = getTokenType(fill.takerAsset.assetProxyId);
46+
}
47+
48+
console.log(tokenType);
49+
50+
token.set({ type: tokenType });
51+
await token.save();
52+
53+
logger.success(`set token type for ${token.address}`);
54+
}),
55+
);
56+
};
57+
58+
module.exports = backfillTokenTypes;

src/jobs/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('lodash');
22

33
const backfillRelayerRelationships = require('./backfill-relayer-relationships');
4+
const backfillTokenTypes = require('./backfill-token-types');
45
const cacheRelayerMetrics = require('./cache-relayer-metrics');
56
const cacheTokenMetrics = require('./cache-token-metrics');
67
const cacheTokenStats = require('./cache-token-stats');
@@ -17,6 +18,7 @@ const updateTokenPrices = require('./update-token-prices');
1718

1819
const jobFns = {
1920
backfillRelayerRelationships,
21+
backfillTokenTypes,
2022
cacheRelayerMetrics,
2123
cacheTokenMetrics,
2224
cacheTokenStats,

0 commit comments

Comments
 (0)