Skip to content

Commit

Permalink
Add a base of the ERC20EthereumWeb3AtomexProtocolV1
Browse files Browse the repository at this point in the history
  • Loading branch information
skubarenko committed Aug 12, 2022
1 parent 38d98bc commit faa9f3c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 11 deletions.
52 changes: 52 additions & 0 deletions src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type BigNumber from 'bignumber.js';

import type {
AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters,
Transaction
} from '../../blockchain/index';
import type { AtomexNetwork, CurrenciesProvider } from '../../common/index';
import type { DeepReadonly } from '../../core';
import type { ERC20EthereumWeb3AtomexProtocolV1Options } from '../models/atomexProtocolOptions';

export class ERC20EthereumWeb3AtomexProtocolV1 implements AtomexProtocolV1 {
readonly version = 1;

constructor(
readonly atomexNetwork: AtomexNetwork,
protected readonly currenciesProvider: CurrenciesProvider,
protected readonly atomexProtocolOptions: DeepReadonly<ERC20EthereumWeb3AtomexProtocolV1Options>
) {
}

get currencyId() {
return this.atomexProtocolOptions.currencyId;
}

initiate(_params: AtomexProtocolV1InitiateParameters): Promise<Transaction> {
throw new Error('Method not implemented.');
}

getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
}

redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction> {
throw new Error('Method not implemented.');
}

getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise<BigNumber> {
throw new Error('Method not implemented.');
}

getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
}

refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction> {
throw new Error('Method not implemented.');
}

getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
}
}
1 change: 1 addition & 0 deletions src/ethereum/atomexProtocol/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { EthereumWeb3AtomexProtocolV1 } from './ethereumWeb3AtomexProtocolV1';
export { ERC20EthereumWeb3AtomexProtocolV1 } from './erc20EthereumWeb3AtomexProtocolV1';
26 changes: 17 additions & 9 deletions src/ethereum/config/defaultOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AtomexContext, AtomexBlockchainOptions, AtomexCurrencyOptions } from '../../atomex/index';
import { Web3BlockchainToolkitProvider } from '../../evm/index';
import { EthereumWeb3AtomexProtocolV1 } from '../atomexProtocol/index';
import { ERC20EthereumWeb3AtomexProtocolV1, EthereumWeb3AtomexProtocolV1 } from '../atomexProtocol/index';
import { EthereumBalancesProvider } from '../balancesProviders/index';
import type { EthereumCurrency } from '../models';
import { EthereumSwapTransactionsProvider } from '../swapTransactionsProviders/index';
Expand All @@ -14,14 +14,22 @@ const createAtomexProtocol = (
currency: EthereumCurrency,
atomexProtocolOptions: AtomexProtocolOptions[keyof AtomexProtocolOptions]
) => {
if (currency.type === 'native')
return new EthereumWeb3AtomexProtocolV1(
atomexContext.atomexNetwork,
atomexContext.providers.currenciesProvider,
atomexProtocolOptions
);

throw new Error(`Unknown Ethereum currency: ${currency.id}`);
switch (currency.type) {
case 'native':
return new EthereumWeb3AtomexProtocolV1(
atomexContext.atomexNetwork,
atomexContext.providers.currenciesProvider,
atomexProtocolOptions
);
case 'erc-20':
return new ERC20EthereumWeb3AtomexProtocolV1(
atomexContext.atomexNetwork,
atomexContext.providers.currenciesProvider,
atomexProtocolOptions
);
default:
throw new Error(`Unknown Ethereum currency: ${(currency as EthereumCurrency).id}`);
}
};

const createCurrencyOptions = (
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { EthereumWeb3AtomexProtocolV1 } from './atomexProtocol/index';
export { EthereumWeb3AtomexProtocolV1, ERC20EthereumWeb3AtomexProtocolV1 } from './atomexProtocol/index';
export { EthereumBalancesProvider } from './balancesProviders/index';
export { EthereumSwapTransactionsProvider } from './swapTransactionsProviders/index';
export { ethereumMainnetCurrencies, ethereumTestnetCurrencies, createDefaultEthereumBlockchainOptions } from './config/index';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { RestAtomexClient, WebSocketAtomexClient, MixedApiAtomexClient } from '.
export { DataSource, ImportantDataReceivingMode } from './common/index';
export { Web3BlockchainWallet } from './evm/index';
export { ExchangeManager, InMemoryExchangeSymbolsProvider } from './exchange/index';
export { EthereumWeb3AtomexProtocolV1 } from './ethereum/index';
export { EthereumWeb3AtomexProtocolV1, ERC20EthereumWeb3AtomexProtocolV1 } from './ethereum/index';
export { InMemoryAuthorizationManagerStore } from './stores/index';
export { TaquitoBlockchainWallet } from './tezos/index';
export * from './utils';
Expand Down

0 comments on commit faa9f3c

Please sign in to comment.