@merkl/api 0.18.6 → 0.18.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/eden/index.d.ts +0 -35
- package/dist/src/factories/opportunityMetadata/implementations/Ajna.js +1 -1
- package/dist/src/factories/opportunityMetadata/implementations/Badger.js +1 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/libs/campaigns/utils/getUniswapV4Pools.js +31 -20
- package/dist/src/modules/v4/campaign/campaign.repository.js +1 -1
- package/dist/src/modules/v4/enso/enso.service.js +5 -5
- package/dist/src/modules/v4/kyberzap/kyberzap.service.js +5 -5
- package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +0 -7
- package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +0 -7
- package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +0 -28
- package/dist/src/modules/v4/opportunity/opportunity.service.js +1 -1
- package/dist/src/modules/v4/price/price.repository.js +1 -1
- package/dist/src/modules/v4/reward/reward.service.js +1 -1
- package/dist/src/modules/v4/router.d.ts +0 -7
- package/dist/src/modules/v4/token/token.repository.d.ts +2 -0
- package/dist/src/modules/v4/token/token.repository.js +13 -0
- package/dist/src/modules/v4/token/token.service.d.ts +23 -42
- package/dist/src/modules/v4/token/token.service.js +39 -31
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -51,7 +51,7 @@ export class TokenService {
|
|
51
51
|
* Fetches tokens and include balances
|
52
52
|
*/
|
53
53
|
static async fetchTokensAndBalances(chainId, userAddress, addresses) {
|
54
|
-
const tokens = await TokenService.
|
54
|
+
const tokens = await TokenService.findManyOrCreate(addresses?.map(address => ({ chainId, address })));
|
55
55
|
return TokenService.fetchBalances(chainId, userAddress, tokens.filter(t => t !== undefined));
|
56
56
|
}
|
57
57
|
/**
|
@@ -63,7 +63,7 @@ export class TokenService {
|
|
63
63
|
const verifiedTokens = await TokenService.findMany({ chainId: chainId, verified: true });
|
64
64
|
const nativeTokens = await TokenService.findMany({ chainId: chainId, isNative: true });
|
65
65
|
const additionalTokens = !!additionalTokenAddresses?.length
|
66
|
-
? await TokenService.
|
66
|
+
? await TokenService.findManyOrCreate(additionalTokenAddresses?.map(address => ({ chainId, address })))
|
67
67
|
: [];
|
68
68
|
const allTokens = verifiedTokens
|
69
69
|
.concat(additionalTokens.filter(t => t !== undefined))
|
@@ -85,9 +85,26 @@ export class TokenService {
|
|
85
85
|
// 2 - Find tokens with missing logos
|
86
86
|
const missingIcons = await TokenService.findMany({ missingIcons: true });
|
87
87
|
// 3 - Do the intersection of both
|
88
|
-
priceSources = priceSources.filter(p => missingIcons.find(t => t.symbol === p.symbol
|
88
|
+
priceSources = priceSources.filter(p => !!missingIcons.find(t => t.symbol === p.symbol));
|
89
89
|
log.info(`found ${priceSources.length} tokens with missing icons on coingecko.`);
|
90
90
|
// 4 - Loop through each and try to get the icon
|
91
|
+
for (const priceSource of priceSources) {
|
92
|
+
const coingeckoTicker = priceSource.args?.ticker;
|
93
|
+
if (!!coingeckoTicker) {
|
94
|
+
try {
|
95
|
+
const icon = await TokenRepository.fetchIconFromCoingeckoTicker(coingeckoTicker);
|
96
|
+
if (icon.length > 0) {
|
97
|
+
const res = await TokenRepository.updateMissingIconsPerSymbol(priceSource.symbol, icon);
|
98
|
+
log.info(`updated ${res.count} tokens with icon ${icon} ${priceSource.symbol}`);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
catch (e) {
|
102
|
+
console.error(e);
|
103
|
+
}
|
104
|
+
// Avoid rate limits, wait 1 min
|
105
|
+
await new Promise(resolve => setTimeout(resolve, 60_000));
|
106
|
+
}
|
107
|
+
}
|
91
108
|
}
|
92
109
|
static async fetchManyOnChain(chainId, addresses) {
|
93
110
|
const tokens = {};
|
@@ -137,30 +154,6 @@ export class TokenService {
|
|
137
154
|
await TokenService.updateAddressPrices(address, price);
|
138
155
|
}
|
139
156
|
}
|
140
|
-
/**
|
141
|
-
* Create token on database
|
142
|
-
* @param chainId
|
143
|
-
* @param address
|
144
|
-
*/
|
145
|
-
static async create(token) {
|
146
|
-
const id = TokenService.hashId(token);
|
147
|
-
return TokenRepository.upsert({ ...token, id });
|
148
|
-
}
|
149
|
-
/**
|
150
|
-
* Fetches symbol, address, decimals and creates token on database
|
151
|
-
* @param chainId
|
152
|
-
* @param address
|
153
|
-
*/
|
154
|
-
static async fillAndCreate(token) {
|
155
|
-
try {
|
156
|
-
const id = TokenService.hashId(token);
|
157
|
-
const filledData = await TokenService.fetchOnChain({ address: token.address, chainId: token.chainId });
|
158
|
-
return await TokenRepository.upsert({ ...filledData, ...token, id });
|
159
|
-
}
|
160
|
-
catch (e) {
|
161
|
-
console.error(e);
|
162
|
-
}
|
163
|
-
}
|
164
157
|
/**
|
165
158
|
* Read token from database
|
166
159
|
* @param chainId
|
@@ -190,7 +183,7 @@ export class TokenService {
|
|
190
183
|
* @returns the cumulated dollar value of all tokens
|
191
184
|
*/
|
192
185
|
static async getValue(tokenAmounts) {
|
193
|
-
const tokens = await TokenService.
|
186
|
+
const tokens = await TokenService.findManyOrCreate(tokenAmounts.map(({ address, chainId }) => ({ address, chainId })));
|
194
187
|
return tokenAmounts.reduce((sum, { amount, address, chainId }) => {
|
195
188
|
const token = tokens
|
196
189
|
.filter(t => t !== undefined)
|
@@ -228,7 +221,7 @@ export class TokenService {
|
|
228
221
|
* @param chainId
|
229
222
|
* @param address
|
230
223
|
*/
|
231
|
-
static async
|
224
|
+
static async findManyOrCreate(tokens) {
|
232
225
|
return await Promise.all(tokens.map(async (token) => {
|
233
226
|
const id = TokenService.hashId(token);
|
234
227
|
try {
|
@@ -276,7 +269,7 @@ export class TokenService {
|
|
276
269
|
const isVerified = properties.Verified.checkbox;
|
277
270
|
const coingeckoApiId = properties["CoinGecko API ID"].rich_text[0].plain_text;
|
278
271
|
const byteArray = await iconFile.bytes();
|
279
|
-
const [token] = await TokenService.
|
272
|
+
const [token] = await TokenService.findManyOrCreate([
|
280
273
|
{
|
281
274
|
chainId,
|
282
275
|
address,
|
@@ -316,9 +309,24 @@ export class TokenService {
|
|
316
309
|
});
|
317
310
|
}
|
318
311
|
/**
|
312
|
+
* Fetches symbol, address, decimals and creates token on database
|
313
|
+
* @param chainId
|
314
|
+
* @param address
|
315
|
+
*/
|
316
|
+
static async fillAndCreate(token) {
|
317
|
+
try {
|
318
|
+
const id = TokenService.hashId(token);
|
319
|
+
const filledData = await TokenService.fetchOnChain({ address: token.address, chainId: token.chainId });
|
320
|
+
return await TokenRepository.upsert({ ...filledData, ...token, id });
|
321
|
+
}
|
322
|
+
catch (e) {
|
323
|
+
console.error(e);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
/**
|
327
|
+
* @deprecated Should be useless now that the token list is not used anymore
|
319
328
|
* Get all tokens from https://github.com/AngleProtocol/angle-token-list and override icons from it
|
320
329
|
* TODO: use the bucket
|
321
|
-
* @deprecated Should be useless now that the token list is not used anymore
|
322
330
|
*/
|
323
331
|
static async fillTokenAndIconsFromTokenList() {
|
324
332
|
const tokenList = await getTokensListWithCache();
|