Skip to content

Commit

Permalink
feat: handle multiple networks for ubiquity dollar
Browse files Browse the repository at this point in the history
  • Loading branch information
whilefoo committed Sep 28, 2024
1 parent 5fb3c53 commit a0ebf5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 0 additions & 4 deletions functions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { getGiftCardById } from "./post-order";
import { fallbackIntlMastercard, fallbackIntlVisa, masterCardIntlSkus, visaIntlSkus } from "./reloadly-lists";
import { AccessToken, ReloadlyFailureResponse } from "./types";

export const permitAllowedChainIds = [1, 5, 100, 31337];

export const ubiquityDollarAllowedChainIds = [1, 31337];

export const commonHeaders = {
"Content-Type": "application/json",
Accept: "application/com.reloadly.giftcards-v1+json",
Expand Down
20 changes: 18 additions & 2 deletions shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@ export enum Tokens {
WXDAI = "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d",
}

export const permitAllowedChainIds = [1, 5, 100, 31337];

export const ubiquityDollarAllowedChainIds = [1, 100, 31337];

export const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
export const ubiquityDollarErc20Address = "0x0F644658510c95CB46955e55D7BA9DDa9E9fBEc6";
export const giftCardTreasuryAddress = "0xD51B09ad92e08B962c994374F4e417d4AD435189";

export const chainIdToRewardTokenMap = {
export const ubiquityDollarChainAddresses: Record<number, string> = {
1: "0x0F644658510c95CB46955e55D7BA9DDa9E9fBEc6",
100: "0xC6ed4f520f6A4e4DC27273509239b7F8A68d2068",
31337: "0x0F644658510c95CB46955e55D7BA9DDa9E9fBEc6",
};

export const chainIdToRewardTokenMap: Record<number, string> = {
1: Tokens.DAI,
100: Tokens.WXDAI,
31337: Tokens.WXDAI,
};

export const chainIdToNameMap: Record<number, string> = {
1: "Ethereum",
5: "Goerli Testnet",
100: "Gnosis",
31337: "Local Testnet",
};
5 changes: 3 additions & 2 deletions static/scripts/ubiquity-dollar/gift-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { BigNumberish, ethers } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { erc20Abi } from "../rewards/abis";
import { TransactionResponse } from "@ethersproject/providers";
import { giftCardTreasuryAddress, ubiquityDollarErc20Address } from "../../../shared/constants";
import { giftCardTreasuryAddress, ubiquityDollarChainAddresses } from "../../../shared/constants";
import { app } from "./app-state";
import { ubiquityDollarAllowedChainIds } from "../../../functions/helpers";
import { ubiquityDollarAllowedChainIds } from "../../../shared/constants";
import { getGiftCardHtml } from "../rewards/gift-cards/gift-card";
import { showTransactionHistory } from "./transaction-history";
import { getOrder, postOrder, getBestCard, getReedemCode } from "../shared/api";
Expand Down Expand Up @@ -167,6 +167,7 @@ async function mintGiftCard(productId: number) {
return;
}

const ubiquityDollarErc20Address = ubiquityDollarChainAddresses[chainId];
const erc20Contract = new ethers.Contract(ubiquityDollarErc20Address, erc20Abi, signer);

const tx: TransactionResponse = await erc20Contract.transfer(giftCardTreasuryAddress, amount);
Expand Down

0 comments on commit a0ebf5e

Please sign in to comment.