-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release (pre Mises integration) to prod (#169)
Merge pull request #169 from madfish-solutions/development
- Loading branch information
Showing
15 changed files
with
887 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"author": "Inokentii Mazhara <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@covalenthq/client-sdk": "^1.0.2", | ||
"@ethersproject/address": "^5.7.0", | ||
"@ethersproject/hash": "^5.7.0", | ||
"@ethersproject/strings": "^5.7.0", | ||
|
@@ -16,6 +17,7 @@ | |
"@taquito/tzip12": "14.0.0", | ||
"@taquito/tzip16": "14.0.0", | ||
"@taquito/utils": "14.0.0", | ||
"async-retry": "^1.3.3", | ||
"axios": "^0.27.2", | ||
"bignumber.js": "^9.1.0", | ||
"body-parser": "^1.20.2", | ||
|
@@ -49,6 +51,7 @@ | |
"db-migration": "cd migrations/notifications && npx ts-node index.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/async-retry": "^1.4.8", | ||
"@types/body-parser": "^1.19.2", | ||
"@types/express": "^4.17.17", | ||
"@types/express-jwt": "^7.4.2", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ChainID, CovalentClient } from '@covalenthq/client-sdk'; | ||
import retry from 'async-retry'; | ||
|
||
import { EnvVars } from '../../config'; | ||
import { CodedError } from '../../utils/errors'; | ||
|
||
const client = new CovalentClient(EnvVars.COVALENT_API_KEY, { enableRetry: false, threadCount: 10 }); | ||
|
||
const RETRY_OPTIONS = { maxRetryTime: 30_000 }; | ||
|
||
export const getEvmBalances = async (walletAddress: string, chainId: string) => | ||
await retry( | ||
async () => | ||
client.BalanceService.getTokenBalancesForWalletAddress(Number(chainId) as ChainID, walletAddress, { | ||
nft: true, | ||
noNftAssetMetadata: true, | ||
quoteCurrency: 'USD', | ||
noSpam: false | ||
}).then(({ data, error, error_message, error_code }) => { | ||
if (error) { | ||
throw new CodedError(Number(error_code) || 500, error_message); | ||
} | ||
|
||
return data; | ||
}), | ||
RETRY_OPTIONS | ||
); | ||
|
||
export const getEvmTokensMetadata = async (walletAddress: string, chainId: string) => | ||
await retry( | ||
async () => | ||
client.BalanceService.getTokenBalancesForWalletAddress(Number(chainId) as ChainID, walletAddress, { | ||
nft: false, | ||
quoteCurrency: 'USD', | ||
noSpam: false | ||
}).then(({ data, error, error_message, error_code }) => { | ||
if (error) { | ||
throw new CodedError(Number(error_code) || 500, error_message); | ||
} | ||
|
||
return data; | ||
}), | ||
RETRY_OPTIONS | ||
); | ||
|
||
const CHAIN_IDS_WITHOUT_CACHE_SUPPORT = [10, 11155420, 43114, 43113]; | ||
|
||
export const getEvmCollectiblesMetadata = async (walletAddress: string, chainId: string) => { | ||
const withUncached = CHAIN_IDS_WITHOUT_CACHE_SUPPORT.includes(Number(chainId)); | ||
|
||
return await retry( | ||
async () => | ||
client.NftService.getNftsForAddress(Number(chainId) as ChainID, walletAddress, { | ||
withUncached, | ||
noSpam: false | ||
}).then(({ data, error, error_message, error_code }) => { | ||
if (error) { | ||
throw new CodedError(Number(error_code) || 500, error_message); | ||
} | ||
|
||
return data; | ||
}), | ||
RETRY_OPTIONS | ||
); | ||
}; | ||
|
||
export const getStringifiedResponse = (response: any) => | ||
JSON.stringify(response, (_, value) => (typeof value === 'bigint' ? value.toString() : value)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Router } from 'express'; | ||
|
||
import { withCodedExceptionHandler, withEvmQueryValidation } from '../../utils/express-helpers'; | ||
import { getEvmBalances, getEvmCollectiblesMetadata, getEvmTokensMetadata, getStringifiedResponse } from './covalent'; | ||
|
||
export const evmRouter = Router(); | ||
|
||
evmRouter | ||
.get( | ||
'/balances', | ||
withCodedExceptionHandler( | ||
withEvmQueryValidation(async (_1, res, _2, evmQueryParams) => { | ||
const { walletAddress, chainId } = evmQueryParams; | ||
|
||
const data = await getEvmBalances(walletAddress, chainId); | ||
|
||
res.status(200).send(getStringifiedResponse(data)); | ||
}) | ||
) | ||
) | ||
.get( | ||
'/tokens-metadata', | ||
withCodedExceptionHandler( | ||
withEvmQueryValidation(async (_1, res, _2, evmQueryParams) => { | ||
const { walletAddress, chainId } = evmQueryParams; | ||
|
||
const data = await getEvmTokensMetadata(walletAddress, chainId); | ||
|
||
res.status(200).send(getStringifiedResponse(data)); | ||
}) | ||
) | ||
) | ||
.get( | ||
'/collectibles-metadata', | ||
withCodedExceptionHandler( | ||
withEvmQueryValidation(async (_1, res, _2, evmQueryParams) => { | ||
const { walletAddress, chainId } = evmQueryParams; | ||
|
||
const data = await getEvmCollectiblesMetadata(walletAddress, chainId); | ||
|
||
res.status(200).send(getStringifiedResponse(data)); | ||
}) | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.