Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready: Enable USDT (Polygon) #273

Open
wants to merge 12 commits into
base: polygon-prototype-staging
Choose a base branch
from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@polkadot/types": "^13.2.1",
"@polkadot/util": "^13.1.1",
"@polkadot/util-crypto": "^13.1.1",
"@rainbow-me/rainbowkit": "^2.1.7",
"@rainbow-me/rainbowkit": "^2.2.0",
"@sentry/react": "^8.36.0",
"@sentry/vite-plugin": "^2.22.6",
"@talismn/connect-components": "^1.1.8",
Expand Down
Binary file removed src/assets/coins/PEN.png
Binary file not shown.
Binary file removed src/assets/coins/USDT.png
Binary file not shown.
11 changes: 11 additions & 0 deletions src/assets/coins/USDT.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/assets/coins/USDT_POLYGON.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 0 additions & 12 deletions src/assets/coins/euro.svg

This file was deleted.

8 changes: 6 additions & 2 deletions src/components/InputKeys/PoolListItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Avatar, AvatarProps, Button } from 'react-daisyui';
import { Button } from 'react-daisyui';
import { CheckIcon } from '@heroicons/react/20/solid';
import { AssetIconType, useGetIcon } from '../../../hooks/useGetIcon';
import { InputTokenType, OutputTokenType } from '../../../constants/tokenConfig';
Expand Down Expand Up @@ -30,7 +30,11 @@ export function PoolListItem<T extends InputTokenType | OutputTokenType>({
className="items-center justify-start w-full h-auto gap-4 px-3 py-2 text-left border-0 bg-blackAlpha-200 hover:opacity-80 dark:bg-whiteAlpha-200"
>
<span className="relative">
<Avatar size={'xs' as AvatarProps['size']} letters={tokenSymbol} src={tokenIcon} className="text-xs" />
<div className="text-xs ">
<div className="w-10">
<img src={tokenIcon} alt={tokenSymbol} className="object-contain w-full h-full" />
</div>
</div>
{isSelected && (
<CheckIcon className="absolute -right-1 -top-1 w-5 h-5 p-[3px] text-white bg-green-600 rounded-full" />
)}
Expand Down
36 changes: 22 additions & 14 deletions src/constants/tokenConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { polygon } from 'wagmi/chains';
import { AssetIconType } from '../hooks/useGetIcon';

export type NetworkType = 'polygon';
export type NetworkType = typeof polygon.name;

export interface InputTokenDetails {
assetSymbol: string;
Expand All @@ -15,7 +16,7 @@ export interface InputTokenDetails {
network: NetworkType;
}

export type InputTokenType = 'usdc' | 'usdce';
export type InputTokenType = 'usdc' | 'usdce' | 'usdt';

export interface Fiat {
assetIcon: AssetIconType;
Expand Down Expand Up @@ -44,30 +45,37 @@ export interface OutputTokenDetails {
offrampFeesFixedComponent?: number;
supportsClientDomain: boolean;
}

const PENDULUM_USDC_AXL = {
pendulumErc20WrapperAddress: '6dhRvkn4FheTeSHuNdAA2bxgEWbKRo6vrLaibTENk5e8kBUo',
pendulumCurrencyId: { XCM: 12 },
pendulumAssetSymbol: 'USDC.axl',
};

export const INPUT_TOKEN_CONFIG: Record<InputTokenType, InputTokenDetails> = {
usdc: {
assetSymbol: 'USDC',
erc20AddressSourceChain: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', // USDC on Polygon
axelarEquivalent: {
pendulumErc20WrapperAddress: '6dhRvkn4FheTeSHuNdAA2bxgEWbKRo6vrLaibTENk5e8kBUo',
pendulumCurrencyId: { XCM: 12 },
pendulumAssetSymbol: 'USDC.axl',
},
axelarEquivalent: PENDULUM_USDC_AXL,
polygonAssetIcon: 'polygonUSDC',
decimals: 6,
network: 'polygon',
network: polygon.name,
},
usdce: {
assetSymbol: 'USDC.e',
erc20AddressSourceChain: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', // USDC.e on Polygon
axelarEquivalent: {
pendulumErc20WrapperAddress: '6dhRvkn4FheTeSHuNdAA2bxgEWbKRo6vrLaibTENk5e8kBUo',
pendulumCurrencyId: { XCM: 12 },
pendulumAssetSymbol: 'USDC.axl',
},
axelarEquivalent: PENDULUM_USDC_AXL,
polygonAssetIcon: 'polygonUSDC',
decimals: 6,
network: 'polygon',
network: polygon.name,
},
usdt: {
assetSymbol: 'USDT',
erc20AddressSourceChain: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', // USDT on Polygon
axelarEquivalent: PENDULUM_USDC_AXL,
polygonAssetIcon: 'polygonUSDT',
decimals: 6,
network: polygon.name,
},
};

Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useGetIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import EURC from '../assets/coins/EURC.png';
import EUR from '../assets/coins/EUR.svg';
import USDC from '../assets/coins/USDC.png';
import USDT from '../assets/coins/USDT.svg';
import USDC_POLYGON from '../assets/coins/USDC_POLYGON.svg';
import USDT_POLYGON from '../assets/coins/USDT_POLYGON.svg';
import ARS from '../assets/coins/ARS.png';

const ICONS = {
eurc: EURC,
eur: EUR,
eurc: EURC,
usdc: USDC,
usdt: USDT,
polygonUSDC: USDC_POLYGON,
polygonUSDT: USDT_POLYGON,
ars: ARS,
};

Expand Down
6 changes: 0 additions & 6 deletions src/services/evmTransactions.ts

This file was deleted.

17 changes: 9 additions & 8 deletions src/services/polkadot/ephemeral.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Keyring } from '@polkadot/api';
import { mnemonicGenerate } from '@polkadot/util-crypto';
import { getApiManagerInstance } from './polkadotApi';
import { getPendulumCurrencyId, INPUT_TOKEN_CONFIG } from '../../constants/tokenConfig';
import { waitForTransactionReceipt } from '@wagmi/core';
import axios from 'axios';
import Big from 'big.js';
import { ExecutionContext, OfframpingState } from '../offrampingFlow';
import { waitForEvmTransaction } from '../evmTransactions';

import { getPendulumCurrencyId, INPUT_TOKEN_CONFIG } from '../../constants/tokenConfig';
import { SIGNING_SERVICE_URL } from '../../constants/constants';
import { multiplyByPowerOfTen } from '../../helpers/contracts';
import axios from 'axios';
import { waitUntilTrue } from '../../helpers/function';
import { ExecutionContext, OfframpingState } from '../offrampingFlow';
import { fetchSigningServiceAccountId } from '../signingService';
import { SIGNING_SERVICE_URL } from '../../constants/constants';
import { isHashRegistered } from '../moonbeam';
import { waitUntilTrue } from '../../helpers/function';
import { getApiManagerInstance } from './polkadotApi';

const FUNDING_AMOUNT_UNITS = '0.1';

Expand Down Expand Up @@ -49,7 +50,7 @@ export async function pendulumFundEphemeral(
throw new Error('No squid router swap hash found');
}

await waitForEvmTransaction(squidRouterSwapHash, wagmiConfig);
await waitForTransactionReceipt(wagmiConfig, { hash: squidRouterSwapHash });

const isAlreadyFunded = await isEphemeralFunded(state);

Expand Down
3 changes: 2 additions & 1 deletion src/services/quotes/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Big from 'big.js';
import { SIGNING_SERVICE_URL } from '../../constants/constants';
import { polygon } from 'wagmi/chains';

const QUOTE_ENDPOINT = `${SIGNING_SERVICE_URL}/v1/quotes`;

type QuoteService = 'moonpay' | 'transak' | 'alchemypay';

type SupportedNetworks = 'polygon';
type SupportedNetworks = typeof polygon.name;

interface Quote {
// The price of crypto -> fiat, i.e. cryptoAmount * cryptoPrice = fiatAmount + totalFee
Expand Down
17 changes: 10 additions & 7 deletions src/services/squidrouter/process.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { getAccount, sendTransaction, writeContract } from '@wagmi/core';
import { getAccount, sendTransaction, waitForTransactionReceipt, writeContract } from '@wagmi/core';
import { SendTransactionErrorType, WriteContractErrorType } from 'viem';
import * as Sentry from '@sentry/react';

import { showToast, ToastMessage } from '../../helpers/notifications';
import { INPUT_TOKEN_CONFIG } from '../../constants/tokenConfig';
import erc20ABI from '../../contracts/ERC20';
import { ExecutionContext, OfframpingState } from '../offrampingFlow';
import { waitForEvmTransaction } from '../evmTransactions';
import { getRouteTransactionRequest } from './route';
import { showToast, ToastMessage } from '../../helpers/notifications';

export async function squidRouter(
state: OfframpingState,
{ wagmiConfig, setSigningPhase, trackEvent }: ExecutionContext,
): Promise<OfframpingState> {
const inputToken = INPUT_TOKEN_CONFIG[state.inputTokenType];
const fromTokenErc20Address = inputToken.erc20AddressSourceChain;

const accountData = getAccount(wagmiConfig);
if (accountData?.address === undefined) {
Expand All @@ -28,7 +26,12 @@ export async function squidRouter(
inputToken,
);

console.log('Asking for approval of', transactionRequest?.target, fromTokenErc20Address, state.inputAmount.units);
console.log(
'Asking for approval of',
transactionRequest?.target,
inputToken.erc20AddressSourceChain,
state.inputAmount.units,
);

setSigningPhase?.('started');

Expand All @@ -37,7 +40,7 @@ export async function squidRouter(
trackEvent({ event: 'signing_requested', index: 1 });
approvalHash = await writeContract(wagmiConfig, {
abi: erc20ABI,
address: fromTokenErc20Address,
address: inputToken.erc20AddressSourceChain,
functionName: 'approve',
args: [transactionRequest?.target, state.inputAmount.raw],
});
Expand All @@ -63,7 +66,7 @@ export async function squidRouter(

setSigningPhase?.('approved');

await waitForEvmTransaction(approvalHash, wagmiConfig);
await waitForTransactionReceipt(wagmiConfig, { hash: approvalHash });

let swapHash;
try {
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3980,9 +3980,9 @@ __metadata:
languageName: node
linkType: hard

"@rainbow-me/rainbowkit@npm:^2.1.7":
version: 2.1.7
resolution: "@rainbow-me/rainbowkit@npm:2.1.7"
"@rainbow-me/rainbowkit@npm:^2.2.0":
version: 2.2.0
resolution: "@rainbow-me/rainbowkit@npm:2.2.0"
dependencies:
"@vanilla-extract/css": "npm:1.15.5"
"@vanilla-extract/dynamic": "npm:2.1.2"
Expand All @@ -3997,7 +3997,7 @@ __metadata:
react-dom: ">=18"
viem: 2.x
wagmi: ^2.9.0
checksum: 10/759187003cb33173bba01cafd5205c59df9a3dcc30a454dfc2a9234a35820fcf716ec054ff88abb294a39d4f3419cfd6f73a52c03a018ccc458567a6e33910ad
checksum: 10/5848d39c2b34b533481ed636e44de2cde9d25cbe3fc5bebd77ce1e60ebddcb5cbfc3bfc3ecbc93a74c0fc8ddff4a4b098e2174b6a35a45231a0351e54ccd3ed4
languageName: node
linkType: hard

Expand Down Expand Up @@ -16738,7 +16738,7 @@ __metadata:
"@polkadot/util": "npm:^13.1.1"
"@polkadot/util-crypto": "npm:^13.1.1"
"@preact/preset-vite": "npm:^2.9.1"
"@rainbow-me/rainbowkit": "npm:^2.1.7"
"@rainbow-me/rainbowkit": "npm:^2.2.0"
"@sentry/react": "npm:^8.36.0"
"@sentry/vite-plugin": "npm:^2.22.6"
"@talismn/connect-components": "npm:^1.1.8"
Expand Down
Loading