Skip to content

Commit

Permalink
Update the atomex protocol interface;
Browse files Browse the repository at this point in the history
Rename the corresponding types;
Create a base of the ethereum atomex protocol v1 implementation;
Create the corresponding config
  • Loading branch information
skubarenko committed Aug 11, 2022
1 parent 870788f commit 31e5948
Show file tree
Hide file tree
Showing 28 changed files with 470 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/atomex/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Atomex } from './atomex';
export { AtomexContext } from './atomexContext';

export type { AtomexOptions, NewSwapRequest } from './models/index';
export type { AtomexOptions, NewSwapRequest, AtomexBlockchainOptions } from './models/index';
4 changes: 2 additions & 2 deletions src/atomexBuilder/atomexBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class AtomexBuilder {

protected createDefaultBlockchainOptions(): Record<string, AtomexBlockchainOptions> {
return {
tezos: createDefaultTezosBlockchainOptions(),
ethereum: createDefaultEthereumBlockchainOptions()
tezos: createDefaultTezosBlockchainOptions(this.atomexContext),
ethereum: createDefaultEthereumBlockchainOptions(this.atomexContext)
};
}
}
2 changes: 1 addition & 1 deletion src/blockchain/atomexProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import type { AtomexNetwork } from '../common/index';

export interface AtomexProtocol {
readonly version: number;
readonly network: AtomexNetwork;
readonly atomexNetwork: AtomexNetwork;
}
20 changes: 10 additions & 10 deletions src/blockchain/atomexProtocolV1/atomexProtocolV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import type { BigNumber } from 'bignumber.js';
import type { Currency } from '../../common/index';
import type { AtomexProtocol } from '../atomexProtocol';
import type { Transaction } from '../models/index';
import type { InitiateParametersAtomexProtocolV1 } from './initiateParametersAtomexProtocolV1';
import type { RedeemParametersAtomexProtocolV1 } from './redeemParametersAtomexProtocolV1';
import type { RefundParametersAtomexProtocolV1 } from './refundParametersAtomexProtocolV1';
import type { AtomexProtocolV1InitiateParameters } from './initiateParameters';
import type { AtomexProtocolV1RedeemParameters } from './redeemParameters';
import type { AtomexProtocolV1RefundParameters } from './refundParameters';

export interface AtomexProtocolV1 extends AtomexProtocol {
readonly version: 1;
readonly currency: Currency;
readonly currencyId: Currency['id'];

initiate(params: InitiateParametersAtomexProtocolV1): Promise<Transaction>;
getEstimatedInitiateFees(params: Partial<InitiateParametersAtomexProtocolV1>): Promise<BigNumber>;
initiate(params: AtomexProtocolV1InitiateParameters): Promise<Transaction>;
getEstimatedInitiateFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>;

redeem(params: RedeemParametersAtomexProtocolV1): Promise<Transaction>;
getEstimatedRedeemFees(params: Partial<InitiateParametersAtomexProtocolV1>): Promise<BigNumber>;
redeem(params: AtomexProtocolV1RedeemParameters): Promise<Transaction>;
getEstimatedRedeemFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>;
getRedeemReward(nativeTokenUsdPrice: number, nativeTokenCurrencyPrice: number): Promise<BigNumber>;

refund(params: RefundParametersAtomexProtocolV1): Promise<Transaction>;
getEstimatedRefundFees(params: Partial<InitiateParametersAtomexProtocolV1>): Promise<BigNumber>;
refund(params: AtomexProtocolV1RefundParameters): Promise<Transaction>;
getEstimatedRefundFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>;
}
7 changes: 4 additions & 3 deletions src/blockchain/atomexProtocolV1/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type { AtomexProtocolV1 } from './atomexProtocolV1';
export type { InitiateParametersAtomexProtocolV1 } from './initiateParametersAtomexProtocolV1';
export type { RedeemParametersAtomexProtocolV1 } from './redeemParametersAtomexProtocolV1';
export type { RefundParametersAtomexProtocolV1 } from './refundParametersAtomexProtocolV1';
export type { AtomexProtocolV1Options } from './options';
export type { AtomexProtocolV1InitiateParameters } from './initiateParameters';
export type { AtomexProtocolV1RedeemParameters } from './redeemParameters';
export type { AtomexProtocolV1RefundParameters } from './refundParameters';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BigNumber } from 'bignumber.js';

export interface InitiateParametersAtomexProtocolV1 {
export interface AtomexProtocolV1InitiateParameters {
readonly amount: BigNumber;
readonly secretHash: string;
readonly receivingAddress: string;
Expand Down
8 changes: 8 additions & 0 deletions src/blockchain/atomexProtocolV1/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Currency } from '../../common/index';
import type { AtomexProtocolOptions } from '../models/index';

export interface AtomexProtocolV1Options extends AtomexProtocolOptions {
currencyId: Currency['id'];
swapContractAddress: string;
swapContractBlockId?: string;
}
3 changes: 3 additions & 0 deletions src/blockchain/atomexProtocolV1/redeemParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface AtomexProtocolV1RedeemParameters {
readonly secretHash: string;
}

This file was deleted.

3 changes: 3 additions & 0 deletions src/blockchain/atomexProtocolV1/refundParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface AtomexProtocolV1RefundParameters {
readonly secretHash: string;
}

This file was deleted.

6 changes: 3 additions & 3 deletions src/blockchain/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { WalletsManager } from './walletsManager';

export type { AtomexSignature, Transaction } from './models/index';
export type { AtomexProtocolOptions, AtomexSignature, Transaction } from './models/index';
export type { AtomexProtocol } from './atomexProtocol';
export type {
AtomexProtocolV1, InitiateParametersAtomexProtocolV1,
RedeemParametersAtomexProtocolV1, RefundParametersAtomexProtocolV1
AtomexProtocolV1, AtomexProtocolV1Options,
AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters
} from './atomexProtocolV1/index';
export type { BalancesProvider } from './balancesProvider';
export type { CurrencyBalanceProvider } from './currencyBalanceProvider';
Expand Down
3 changes: 3 additions & 0 deletions src/blockchain/models/atomexProtocolOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface AtomexProtocolOptions {
atomexProtocolVersion: number;
}
1 change: 1 addition & 0 deletions src/blockchain/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type { AtomexProtocolOptions } from './atomexProtocolOptions';
export type { AtomexSignature } from './atomexSignature';
export type { Transaction } from './transaction';
52 changes: 52 additions & 0 deletions src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.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 { EthereumAtomexProtocolV1Options } from '../models/atomexProtocolOptions';

export class EthereumWeb3AtomexProtocolV1 implements AtomexProtocolV1 {
readonly version = 1;

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

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(nativeTokenUsdPrice: number, nativeTokenCurrencyPrice: 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
@@ -0,0 +1 @@
export { EthereumWeb3AtomexProtocolV1 } from './ethereumWeb3AtomexProtocolV1';
Loading

0 comments on commit 31e5948

Please sign in to comment.