Skip to content

Commit

Permalink
fix verification logic and emails for base network streams
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Dec 16, 2024
1 parent 196c329 commit 86fbca9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 10 deletions.
68 changes: 68 additions & 0 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
23 changes: 21 additions & 2 deletions src/services/cronJobs/checkUserSuperTokenBalancesQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/services/recurringDonationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 86fbca9

Please sign in to comment.