Skip to content

Commit

Permalink
accept payments on base
Browse files Browse the repository at this point in the history
  • Loading branch information
calebtuttle committed Dec 14, 2024
1 parent aa3d18a commit 97a1ec7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/constants/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const companyAddressOP = "0x03627Ac5A08056B50084d8B9cf550EB74a13C78A";

export const companyAddressFTM = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42";

export const companyAddressBase = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42";

export const companyAddressAVAX = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42";

export const companyAddressAurora = "0xbe20d0A27B79BA2E53c9DF150BadAa21D4783D42";
Expand All @@ -36,6 +38,7 @@ const supportedChainIds = [
1, // Ethereum
10, // Optimism
250, // Fantom
8453, // Base
43114, // Avalanche
1313161554, // Aurora
];
Expand Down Expand Up @@ -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"
);
Expand Down
3 changes: 3 additions & 0 deletions src/services/admin/refund-failed-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
fantomProvider,
avalancheProvider,
auroraProvider,
baseProvider,
supportedChainIds,
} from "../../constants/misc.js";
import logger from "../../utils/logger.js";
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/services/admin/refund-unused-transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
fantomProvider,
avalancheProvider,
auroraProvider,
baseProvider,
supportedChainIds,
} from "../../constants/misc.js";
import logger from "../../utils/logger.js";
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions src/services/admin/transfer-funds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion src/utils/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
fantomProvider,
avalancheProvider,
auroraProvider,
baseProvider,
} from "../constants/misc.js";
import { usdToETH, usdToFTM, usdToAVAX } from "./cmc.js";

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 97a1ec7

Please sign in to comment.