-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the blockchain provider instead of currencies provider in the ato…
…mex protocol implementations; Extract the common functionality into a separated abstract class
- Loading branch information
1 parent
a93021b
commit 53673f5
Showing
12 changed files
with
181 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 12 additions & 15 deletions
27
src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Web3AtomexProtocolV1 } from './web3AtomexProtocolV1'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type BigNumber from 'bignumber.js'; | ||
import type Web3 from 'web3'; | ||
|
||
import type { | ||
AtomexBlockchainProvider, | ||
AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, | ||
Transaction, WalletsManager | ||
} from '../../blockchain/index'; | ||
import type { AtomexNetwork } from '../../common/index'; | ||
import type { DeepReadonly } from '../../core/index'; | ||
import type { Web3AtomexProtocolV1Options } from '../models/index'; | ||
|
||
export abstract class Web3AtomexProtocolV1 implements AtomexProtocolV1 { | ||
readonly version = 1; | ||
|
||
constructor( | ||
protected readonly blockchain: string, | ||
readonly atomexNetwork: AtomexNetwork, | ||
protected readonly atomexProtocolOptions: DeepReadonly<Web3AtomexProtocolV1Options>, | ||
protected readonly atomexBlockchainProvider: AtomexBlockchainProvider, | ||
protected readonly walletsManager: WalletsManager | ||
) { | ||
} | ||
|
||
get currencyId() { | ||
return this.atomexProtocolOptions.currencyId; | ||
} | ||
|
||
abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise<Transaction>; | ||
|
||
abstract getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>; | ||
|
||
abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction>; | ||
|
||
abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise<BigNumber>; | ||
|
||
abstract getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>; | ||
|
||
abstract refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction>; | ||
|
||
abstract getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>; | ||
|
||
protected async getReadonlyWeb3() { | ||
const toolkit = this.atomexBlockchainProvider.getReadonlyToolkit<Web3>('web3', this.blockchain); | ||
if (!toolkit) | ||
throw new Error('Web3 toolkit not found'); | ||
|
||
return toolkit; | ||
} | ||
|
||
protected async getWallet(address?: string) { | ||
const web3Wallet = await this.walletsManager.getWallet<Web3>(address, this.blockchain, 'web3'); | ||
if (!web3Wallet) | ||
throw new Error(`${this.blockchain} Web3 wallet not found`); | ||
|
||
return web3Wallet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletions
21
src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { TezosToolkit } from '@taquito/taquito'; | ||
import type BigNumber from 'bignumber.js'; | ||
|
||
import type { | ||
AtomexBlockchainProvider, | ||
AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, | ||
Transaction, WalletsManager | ||
} from '../../blockchain/index'; | ||
import type { AtomexNetwork } from '../../common/index'; | ||
import type { DeepReadonly } from '../../core/index'; | ||
import type { TaquitoAtomexProtocolV1Options } from '../models/index'; | ||
|
||
export abstract class TaquitoAtomexProtocolV1 implements AtomexProtocolV1 { | ||
readonly version = 1; | ||
|
||
constructor( | ||
protected readonly blockchain: string, | ||
readonly atomexNetwork: AtomexNetwork, | ||
protected readonly atomexProtocolOptions: DeepReadonly<TaquitoAtomexProtocolV1Options>, | ||
protected readonly atomexBlockchainProvider: AtomexBlockchainProvider, | ||
protected readonly walletsManager: WalletsManager | ||
) { | ||
} | ||
|
||
get currencyId() { | ||
return this.atomexProtocolOptions.currencyId; | ||
} | ||
|
||
abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise<Transaction>; | ||
|
||
abstract getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>; | ||
|
||
abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction>; | ||
|
||
abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise<BigNumber>; | ||
|
||
abstract getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>; | ||
|
||
abstract refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction>; | ||
|
||
abstract getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>; | ||
|
||
protected async getReadonlyTezosToolkit() { | ||
const toolkit = this.atomexBlockchainProvider.getReadonlyToolkit<TezosToolkit>('taquito', this.blockchain); | ||
if (!toolkit) | ||
throw new Error('Tezos toolkit not found'); | ||
|
||
return toolkit; | ||
} | ||
|
||
protected async getWallet(address?: string) { | ||
const taquitoWallet = await this.walletsManager.getWallet<TezosToolkit>(address, this.blockchain, 'taquito'); | ||
if (!taquitoWallet) | ||
throw new Error(`${this.blockchain} Taqutio wallet not found`); | ||
|
||
return taquitoWallet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters