From 86fbca950653e760d5e58effa20356a1168e85a4 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 16 Dec 2024 16:56:12 -0500 Subject: [PATCH] fix verification logic and emails for base network streams --- src/provider.ts | 68 +++++++++++++++++++ .../checkUserSuperTokenBalancesQueue.ts | 23 ++++++- src/services/recurringDonationService.ts | 14 ++-- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/src/provider.ts b/src/provider.ts index 85a9c66aa..95d4c8bf5 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -42,8 +42,76 @@ export const superTokensToToken = { DAIx: 'DAI', OPx: 'OP', GIVx: 'GIV', + DEGENx: 'DEGEN', + cbBTCx: 'cbBTC', }; +export const superTokensBase = [ + { + underlyingToken: { + decimals: 6, + id: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', + name: 'USD Coin', + symbol: 'USDC', + coingeckoId: 'usd-coin', + }, + decimals: 18, + id: '0xD04383398dD2426297da660F9CCA3d439AF9ce1b', + name: 'Super USD Coin', + symbol: 'USDCx', + isSuperToken: true, + coingeckoId: 'usd-coin', + }, + { + underlyingToken: { + name: 'Ethereum', + symbol: 'ETH', + decimals: 18, + id: '0x0000000000000000000000000000000000000000', + }, + decimals: 18, + id: '0x46fd5cfB4c12D87acD3a13e92BAa53240C661D93', + name: 'Super ETH', + symbol: 'ETHx', + }, + { + underlyingToken: { + decimals: 8, + id: '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf', + name: 'Coinbase Wrapped BTC', + symbol: 'cbBTC', + }, + decimals: 18, + id: '0xDFd428908909CB5E24F5e79E6aD6BDE10bdf2327', + name: 'Super Coinbase Wrapped BTC', + symbol: 'cbBTCx', + }, + { + underlyingToken: { + decimals: 18, + id: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb', + name: 'DAI Stablecoin', + symbol: 'DAI', + }, + decimals: 18, + id: '0x708169c8C87563Ce904E0a7F3BFC1F3b0b767f41', + name: 'Super DAI Stablecoin', + symbol: 'DAIx', + }, + { + underlyingToken: { + decimals: 18, + id: '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed', + name: 'Degen', + symbol: 'DEGEN', + }, + decimals: 18, + id: '0x1efF3Dd78F4A14aBfa9Fa66579bD3Ce9E1B30529', + name: 'Super Degen', + symbol: 'DEGENx', + }, +]; + export const superTokens = [ { underlyingToken: { diff --git a/src/services/cronJobs/checkUserSuperTokenBalancesQueue.ts b/src/services/cronJobs/checkUserSuperTokenBalancesQueue.ts index 567ad9671..c034bf91d 100644 --- a/src/services/cronJobs/checkUserSuperTokenBalancesQueue.ts +++ b/src/services/cronJobs/checkUserSuperTokenBalancesQueue.ts @@ -13,7 +13,12 @@ import { findRecurringDonationById, } from '../../repositories/recurringDonationRepository'; import { getCurrentDateFormatted } from '../../utils/utils'; -import { getNetworkNameById, superTokens } from '../../provider'; +import { + getNetworkNameById, + NETWORK_IDS, + superTokens, + superTokensBase, +} from '../../provider'; import { NOTIFICATIONS_EVENT_NAMES } from '../../analytics/analytics'; const runCheckUserSuperTokenBalancesQueue = new Bull( @@ -112,10 +117,24 @@ export const validateDonorSuperTokenBalance = async ( if (!accountBalances || accountBalances.length === 0) return; + let superTokenDataArray = superTokens; + + if ( + recurringDonation.networkId === NETWORK_IDS.BASE_SEPOLIA || + recurringDonation.networkId === NETWORK_IDS.BASE_MAINNET + ) { + superTokenDataArray = superTokensBase; + } else if ( + recurringDonation.networkId === NETWORK_IDS.OPTIMISM_SEPOLIA || + recurringDonation.networkId === NETWORK_IDS.OPTIMISTIC + ) { + superTokenDataArray = superTokens; + } + for (const tokenBalance of accountBalances) { const { maybeCriticalAtTimestamp, token } = tokenBalance; if (!user!.email) continue; - const tokenSymbol = superTokens.find(t => t.id === token.id) + const tokenSymbol = superTokenDataArray.find(t => t.id === token.id) ?.underlyingToken.symbol; // We shouldn't notify the user if the token is not the same as the recurring donation if (tokenSymbol !== recurringDonation.currency) continue; diff --git a/src/services/recurringDonationService.ts b/src/services/recurringDonationService.ts index cb1f286e3..3a4c3ff06 100644 --- a/src/services/recurringDonationService.ts +++ b/src/services/recurringDonationService.ts @@ -33,7 +33,6 @@ import { } from './donationService'; import { calculateGivbackFactor } from './givbackService'; import { updateUserTotalDonated, updateUserTotalReceived } from './userService'; -import config from '../config'; import { User } from '../entities/user'; import { NOTIFICATIONS_EVENT_NAMES } from '../analytics/analytics'; import { relatedActiveQfRoundForProject } from './qfRoundService'; @@ -122,18 +121,17 @@ export const createRelatedDonationsToStream = async ( }); } } + let networkId: number = recurringDonation.networkId; + + if (networkId === NETWORK_IDS.BASE_SEPOLIA) { + networkId = NETWORK_IDS.BASE_MAINNET; + } + // create donation if any virtual period is missing if (uniquePeriods.length === 0) return; for (const streamPeriod of uniquePeriods) { try { - const environment = config.get('ENVIRONMENT') as string; - - const networkId: number = - environment !== 'production' - ? NETWORK_IDS.OPTIMISM_SEPOLIA - : NETWORK_IDS.OPTIMISTIC; - const symbolCurrency = recurringDonation.currency.includes('x') ? superTokensToToken[recurringDonation.currency] : recurringDonation.currency;