diff --git a/src/UsdcAssetAdapter.ts b/src/Erc20AssetAdapter.ts similarity index 93% rename from src/UsdcAssetAdapter.ts rename to src/Erc20AssetAdapter.ts index b9a7c0f..8468b90 100644 --- a/src/UsdcAssetAdapter.ts +++ b/src/Erc20AssetAdapter.ts @@ -66,7 +66,7 @@ export interface Web3Client { endBlock?: number; } -export class UsdcAssetAdapter implements AssetAdapter { +export class Erc20AssetAdapter implements AssetAdapter { private cancelCallback: ((reason: Error) => void) | null = null; private stopped = false; @@ -137,7 +137,7 @@ export class UsdcAssetAdapter implements AssetAdapter { if (amount.toNumber() !== value) { console.warn( - `Found USDC HTLC, but amount does not match. Expected ${value}, found ${amount.toNumber()}`, + `Found ERC-20 HTLC, but amount does not match. Expected ${value}, found ${amount.toNumber()}`, ); return false; } @@ -158,7 +158,7 @@ export class UsdcAssetAdapter implements AssetAdapter> { - throw new Error('Method "fundHtlc" not available for USDC HTLCs'); + throw new Error('Method "fundHtlc" not available for ERC-20 HTLCs'); } public async awaitHtlcSettlement(htlcId: string): Promise> { @@ -175,7 +175,7 @@ export class UsdcAssetAdapter implements AssetAdapter> { - throw new Error('Method "settleHtlc" not available for USDC HTLCs'); + throw new Error('Method "settleHtlc" not available for ERC-20 HTLCs'); } public async awaitSettlementConfirmation(htlcId: string): Promise> { diff --git a/src/IAssetAdapter.ts b/src/IAssetAdapter.ts index 4ac5950..ce5e4b6 100644 --- a/src/IAssetAdapter.ts +++ b/src/IAssetAdapter.ts @@ -1,25 +1,26 @@ import { BitcoinClient, TransactionDetails as BitcoinTransactionDetails } from './BitcoinAssetAdapter'; +import { GenericEvent as Erc20TransactionDetails, Web3Client } from './Erc20AssetAdapter'; import { HtlcDetails as EuroHtlcDetails, OasisClient } from './EuroAssetAdapter'; import { NimiqClient, TransactionDetails as NimiqTransactionDetails } from './NimiqAssetAdapter'; -import { GenericEvent as UsdcTransactionDetails, Web3Client } from './UsdcAssetAdapter'; export enum SwapAsset { NIM = 'NIM', BTC = 'BTC', USDC = 'USDC', USDC_MATIC = 'USDC_MATIC', + USDT = 'USDT', // Alternatively USDT_MATIC EUR = 'EUR', } export type Transaction = TAsset extends SwapAsset.NIM ? NimiqTransactionDetails : TAsset extends SwapAsset.BTC ? BitcoinTransactionDetails - : TAsset extends SwapAsset.USDC | SwapAsset.USDC_MATIC ? UsdcTransactionDetails + : TAsset extends SwapAsset.USDC | SwapAsset.USDC_MATIC | SwapAsset.USDT ? Erc20TransactionDetails : TAsset extends SwapAsset.EUR ? EuroHtlcDetails : never; export type Client = TAsset extends SwapAsset.NIM ? NimiqClient : TAsset extends SwapAsset.BTC ? BitcoinClient - : TAsset extends SwapAsset.USDC | SwapAsset.USDC_MATIC ? Web3Client + : TAsset extends SwapAsset.USDC | SwapAsset.USDC_MATIC | SwapAsset.USDT ? Web3Client : TAsset extends SwapAsset.EUR ? OasisClient : never; diff --git a/src/SwapHandler.ts b/src/SwapHandler.ts index 4242bf9..2c2b55d 100644 --- a/src/SwapHandler.ts +++ b/src/SwapHandler.ts @@ -1,9 +1,9 @@ import { BitcoinAssetAdapter } from './BitcoinAssetAdapter'; +import { Erc20AssetAdapter } from './Erc20AssetAdapter'; import { EuroAssetAdapter } from './EuroAssetAdapter'; import { AssetAdapter, SwapAsset } from './IAssetAdapter'; import type { Client, Transaction } from './IAssetAdapter'; import { NimiqAssetAdapter } from './NimiqAssetAdapter'; -import { UsdcAssetAdapter } from './UsdcAssetAdapter'; // Re-export to centralize exports export { Client, SwapAsset, Transaction }; @@ -13,7 +13,7 @@ export type Contract = { address: string, data: TAsset extends SwapAsset.NIM ? string : never, script: TAsset extends SwapAsset.BTC ? string : never, - contract: TAsset extends SwapAsset.USDC | SwapAsset.USDC_MATIC ? string : never, + contract: TAsset extends SwapAsset.USDC | SwapAsset.USDC_MATIC | SwapAsset.USDT ? string : never, }, }; @@ -47,7 +47,10 @@ export class SwapHandler return new BitcoinAssetAdapter(client as Client) as AssetAdapter; case SwapAsset.USDC: case SwapAsset.USDC_MATIC: - return new UsdcAssetAdapter(client as Client) as AssetAdapter< + case SwapAsset.USDT: + return new Erc20AssetAdapter( + client as Client, + ) as AssetAdapter< SwapAsset >; case SwapAsset.EUR: