From 97a1ec7598fb661dff73125f52099333c2e704ec Mon Sep 17 00:00:00 2001 From: Caleb Tuttle <1calebtuttle@gmail.com> Date: Sat, 14 Dec 2024 14:06:09 -0500 Subject: [PATCH] accept payments on base --- src/constants/misc.js | 6 ++++++ src/services/admin/refund-failed-session.js | 3 +++ .../admin/refund-unused-transaction.js | 3 +++ src/services/admin/transfer-funds.js | 19 +++++++++++++++++++ src/utils/transactions.js | 12 +++++++++++- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/constants/misc.js b/src/constants/misc.js index 9f19e8a..f02eeec 100644 --- a/src/constants/misc.js +++ b/src/constants/misc.js @@ -10,6 +10,8 @@ export const companyAddressOP = "0x03627Ac5A08056B50084d8B9cf550EB74a13C78A"; export const companyAddressFTM = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42"; +export const companyAddressBase = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42"; + export const companyAddressAVAX = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42"; export const companyAddressAurora = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42"; @@ -36,6 +38,7 @@ const supportedChainIds = [ 1, // Ethereum 10, // Optimism 250, // Fantom + 8453, // Base 43114, // Avalanche 1313161554, // Aurora ]; @@ -73,6 +76,9 @@ export const optimismProvider = new ethers.providers.JsonRpcProvider( export const optimismGoerliProvider = new ethers.providers.JsonRpcProvider( process.env.OPTIMISM_GOERLI_RPC_URL ); +export const baseProvider = new ethers.providers.JsonRpcProvider( + process.env.BASE_RPC_URL +); export const fantomProvider = new ethers.providers.JsonRpcProvider( "https://rpc.ftm.tools" ); diff --git a/src/services/admin/refund-failed-session.js b/src/services/admin/refund-failed-session.js index 4243ac4..e551533 100644 --- a/src/services/admin/refund-failed-session.js +++ b/src/services/admin/refund-failed-session.js @@ -10,6 +10,7 @@ import { fantomProvider, avalancheProvider, auroraProvider, + baseProvider, supportedChainIds, } from "../../constants/misc.js"; import logger from "../../utils/logger.js"; @@ -58,6 +59,8 @@ export async function refundFailedSession(req, res) { provider = optimismProvider; } else if (session.chainId === 250) { provider = fantomProvider; + } else if (chainId === 8453) { + provider = baseProvider; } else if (session.chainId === 43114) { provider = avalancheProvider; } else if (session.chainId === 1313161554) { diff --git a/src/services/admin/refund-unused-transaction.js b/src/services/admin/refund-unused-transaction.js index 146cba4..648c811 100644 --- a/src/services/admin/refund-unused-transaction.js +++ b/src/services/admin/refund-unused-transaction.js @@ -10,6 +10,7 @@ import { fantomProvider, avalancheProvider, auroraProvider, + baseProvider, supportedChainIds, } from "../../constants/misc.js"; import logger from "../../utils/logger.js"; @@ -65,6 +66,8 @@ export async function refundUnusedTransaction(req, res) { provider = optimismProvider; } else if (chainId === 250) { provider = fantomProvider; + } else if (chainId === 8453) { + provider = baseProvider; } else if (chainId === 43114) { provider = avalancheProvider; } else if (chainId === 1313161554) { diff --git a/src/services/admin/transfer-funds.js b/src/services/admin/transfer-funds.js index eb1b9c6..84fbc48 100644 --- a/src/services/admin/transfer-funds.js +++ b/src/services/admin/transfer-funds.js @@ -5,10 +5,12 @@ import { fantomProvider, avalancheProvider, auroraProvider, + baseProvider, companyENS, companyAddressOP, companyAddressFTM, companyAddressAVAX, + companyAddressBase, } from "../../constants/misc.js"; import { pinoOptions, logger } from "../../utils/logger.js"; @@ -93,6 +95,23 @@ async function transferFunds(req, res) { txReceipts["fantom"] = await tx.wait(); } + // Transfer ETH on Base \\ + const baseWallet = new ethers.Wallet( + process.env.PAYMENTS_PRIVATE_KEY, + baseProvider + ); + const balanceBase = await baseWallet.getBalance(); + // If balance is less than 0.2 ETH, don't transfer. Otherwise, send 0.15 ETH. + // We keep some ETH to pay for refunds. + if (balanceBase.gte(ethers.utils.parseEther("0.2"))) { + const tx = await baseWallet.sendTransaction({ + to: companyAddressBase, + value: ethers.utils.parseEther("0.15"), + }); + + txReceipts["base"] = await tx.wait(); + } + // Transfer AVAX on Avalanche \\ const avalancheWallet = new ethers.Wallet( process.env.PAYMENTS_PRIVATE_KEY, diff --git a/src/utils/transactions.js b/src/utils/transactions.js index ba821b1..3f20fb3 100644 --- a/src/utils/transactions.js +++ b/src/utils/transactions.js @@ -8,6 +8,7 @@ import { fantomProvider, avalancheProvider, auroraProvider, + baseProvider, } from "../constants/misc.js"; import { usdToETH, usdToFTM, usdToAVAX } from "./cmc.js"; @@ -18,6 +19,8 @@ function getTransaction(chainId, txHash) { return optimismProvider.getTransaction(txHash); } else if (chainId === 250) { return fantomProvider.getTransaction(txHash); + } else if (chainId === 8453) { + return baseProvider.getTransaction(txHash); } else if (chainId === 43114) { return avalancheProvider.getTransaction(txHash); } else if (process.env.NODE_ENV === "development" && chainId === 420) { @@ -66,7 +69,7 @@ async function validateTxForSessionCreation(session, chainId, txHash, desiredAmo const expectedAmountInUSD = desiredAmount * 0.95; let expectedAmountInToken; - if ([1, 10, 1313161554].includes(chainId)) { + if ([1, 10, 1313161554, 8453].includes(chainId)) { expectedAmountInToken = await usdToETH(expectedAmountInUSD); } else if (chainId === 250) { expectedAmountInToken = await usdToFTM(expectedAmountInUSD); @@ -78,6 +81,11 @@ async function validateTxForSessionCreation(session, chainId, txHash, desiredAmo // } else if (process.env.NODE_ENV === "development" && chainId === 420) { expectedAmountInToken = await usdToETH(expectedAmountInUSD); + } else { + return { + status: 400, + error: `Unsupported chain ID: ${chainId}`, + } } if (!txReceipt.blockHash || txReceipt.confirmations === 0) { @@ -125,6 +133,8 @@ async function refundMintFeeOnChain(session, to) { provider = optimismProvider; } else if (session.chainId === 250) { provider = fantomProvider; + } else if (chainId === 8453) { + provider = baseProvider; } else if (session.chainId === 43114) { provider = avalancheProvider; } else if (session.chainId === 1313161554) {