-
Notifications
You must be signed in to change notification settings - Fork 2
WIP new rates arch template #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| /** | ||
| * New rates server should use the following API | ||
| * POST /api/v3/rates | ||
| * BODY { | ||
| * "targetFiat": "USD", | ||
| * "crypto": [ | ||
| * { | ||
| * "isoDate": "2025-06-23T15:52:30.000Z", | ||
| * "pluginId": "bitcoin", | ||
| * }, | ||
| * { | ||
| * "isoDate": "2025-06-23T15:52:30.000Z", | ||
| * "pluginId": "ethereum" | ||
| * }, | ||
| * { | ||
| * "isoDate": "2025-06-23T15:52:30.000Z", | ||
| * "pluginId": "ethereum", | ||
| * "tokenId": "dac17f958d2ee523a2206206994597c13d831ec7", | ||
| * } | ||
| * ], | ||
| * "fiat": [{"fiatCode": "GBP"}, {"fiatCode": "EUR"}] | ||
| * } | ||
| * | ||
| * Response would be | ||
| * { | ||
| * "targetFiat": "USD", | ||
| * "crypto": [ | ||
| * { | ||
| * "isoDate": "2025-06-23T15:52:30.000Z", | ||
| * "pluginId": "bitcoin", | ||
| * "rate": 103102.23 | ||
| * }, | ||
| * { | ||
| * "isoDate": "2025-06-23T15:52:30.000Z", | ||
| * "pluginId": "ethereum" | ||
| * "rate": 2304.23 | ||
| * }, | ||
| * { | ||
| * "isoDate": "2025-06-23T15:52:30.000Z", | ||
| * "pluginId": "ethereum", | ||
| * "tokenId": "dac17f958d2ee523a2206206994597c13d831ec7", | ||
| * "rate": 1.002 | ||
| * } | ||
| * ], | ||
| * "fiat": [ | ||
| * { | ||
| * "fiatCode": "GBP", | ||
| * "rate": 1.32 | ||
| * }, { | ||
| * "fiatCode": "EUR" | ||
| * "rate": 1.08 | ||
| * } | ||
| * ] | ||
| * } | ||
| */ | ||
|
|
||
| /** | ||
| * If no date is provided, rate queries should round down to the nearest minute. | ||
| * If a date is provided, rate queries should round down to the nearest 5 min interval | ||
| * since most historical rates are only accurate to 5 minutes | ||
| */ | ||
|
|
||
| /** | ||
| * Crypto rates are stored in the `rates_data` | ||
| * database. | ||
| * | ||
| * Doc id uses isoDate as the docId | ||
| */ | ||
|
|
||
| const ratesDocExample = { | ||
| _id: '2025-06-23T15:55:00.000Z', | ||
| chains: { | ||
| bitcoin: { | ||
| currencyCode: 'BTC', | ||
| USD: 101234.09 | ||
| }, | ||
| ethereum: { | ||
| currencyCode: 'ETH', | ||
| USD: 2310.09 | ||
| } | ||
| }, | ||
| tokens: { | ||
| dac17f958d2ee523a2206206994597c13d831ec7: { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to |
||
| currencyCode: 'USDT', | ||
| USD: 1.0001 | ||
| }, | ||
| a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48: { | ||
| currencyCode: 'USDC', | ||
| USD: 1.0002 | ||
| } | ||
| }, | ||
| fiat: { | ||
| CAD: { USD: 0.73 }, | ||
| EUR: { USD: 1.15 }, | ||
| GBP: { USD: 1.35 } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * To prevent double querying assets that exist on | ||
| * multiple chains, a document will be used | ||
| * to map tokenId assets to another asset on a main chain | ||
| * like Ethereum. | ||
| * | ||
| * The examples below maps Arbitrum and Zksync to Ethereum and | ||
| * USDT/USDC on Solana to the same assets on Ethereum. | ||
| * | ||
| * These docs will be in the `rates_mappings` database | ||
| */ | ||
|
|
||
| // PluginID mappings should be manually edited, not autogenerated since | ||
| // these ONLY refer to Edge pluginIds and not partner slugs | ||
| const pluginIdMappings = { | ||
| _id: 'pluginIdMappings', | ||
| data: { | ||
| // Map arbitrum and zksync to ethereum since they are the same asset | ||
| arbitrum: 'ethereum', | ||
| zksync: 'ethereum' | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Token mappings should be auto generated from partner APIs. ie. the | ||
| * coingecko /api/v3/coins/list?include_platform=true endpoint will return all the | ||
| * contract addresses on all chains for each asset supported. | ||
| * | ||
| * The mappings below should be refreshed once per day | ||
| */ | ||
| const tokenMappings = { | ||
| _id: 'tokenMappings', | ||
| data: { | ||
| // USDT from solana to ethereum | ||
| Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB: { | ||
| sourceChain: 'solana', // Only used for easy visual reference | ||
| destChain: 'ethereum', // Only used for easy visual reference | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we determine a pluginId ranking to determine which chain is considered the source or trust the coingecko api to remain constant and use the first platform in the array?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What Paul, William, Matt said. mapping keep growing but always look up main db first, mapping 2nd. |
||
| currencyCode: 'USDT', // Only used for easy visual reference | ||
| tokenId: 'dac17f958d2ee523a2206206994597c13d831ec7' | ||
| }, | ||
| // USDC from solana to ethereum | ||
| EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: { | ||
| sourceChain: 'solana', // Only used for easy visual reference | ||
| destChain: 'ethereum', // Only used for easy visual reference | ||
| currencyCode: 'USDC', // Only used for easy visual reference | ||
| tokenId: 'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * For each rate provider there will be a document that maps | ||
| * the rate provider's unique identifiers to either pluginIds or tokenIds | ||
| * The pluginIdMap should be manually entered as it references Edge | ||
| * pluginIds. The tokenIdMap should be auto generated from partner APIs | ||
| * since it only references contract addresses. For the tokenIds, use the first | ||
| * chain that is returned by the partner API. All other chains would first | ||
| * get translated by the tokenMappings doc above. | ||
| */ | ||
|
|
||
| const coinmarketcapPluginIdMap = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both cmc and coingecko utilize platform ids which (in 99% of cases) don't match mainnet asset ids. This map should be platform ID and then we can add the mainnet assets to the tokenId mapping below |
||
| _id: 'coinmarketcapPluginIdMap', | ||
| data: { | ||
| // Mapping from Edge pluginIds to CMC ids of main chain assets | ||
| bitcoin: 1, | ||
| ethereum: 1027, | ||
| ripple: 52 | ||
| } | ||
| } | ||
|
|
||
| const coinmarketcapTokenIdMap = { | ||
| _id: 'coinmarketcapTokenIdMap', | ||
| data: { | ||
| // Maps the contract address to the CMC id | ||
| dac17f958d2ee523a2206206994597c13d831ec7: { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chains with numbered tokenIds may have collisions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use pluginId_tokenId as doc key instead |
||
| id: 825, | ||
| slug: 'tether' | ||
| }, | ||
| a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48: { | ||
| id: 3408, | ||
| slug: 'usd-coin' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Used to map legacy currency codes to pluginId/tokenId which | ||
| * would be used for a one time conversion of old db data to | ||
| * the new format. This needs to be hand edited :( | ||
| */ | ||
| const legacyCurrencyCodeMap = { | ||
| _id: 'legacyCurrencyCodeMap', | ||
| data: { | ||
| BTC: { pluginId: 'bitcoin', tokenId: null }, | ||
| ETH: { pluginId: 'ethereum', tokenId: null }, | ||
| XRP: { pluginId: 'ripple', tokenId: null }, | ||
| USDC: { | ||
| pluginId: 'ethereum', | ||
| tokenId: 'a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to: