diff --git a/.vscode/settings.json b/.vscode/settings.json index f067784f..4fa89e8e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,6 +22,7 @@ "atomex", "tezos", "outdir", - "esbuild" + "esbuild", + "taquito" ] } diff --git a/src/atomex/index.ts b/src/atomex/index.ts index 3e5ffcc3..50bc40ef 100644 --- a/src/atomex/index.ts +++ b/src/atomex/index.ts @@ -1,4 +1,9 @@ export { Atomex } from './atomex'; export { AtomexContext } from './atomexContext'; +export { SwapOperationCompleteStage } from './models/index'; -export type { AtomexOptions, NewSwapRequest } from './models/index'; +export type { + NewSwapRequest, + AtomexOptions, AtomexBlockchainNetworkOptions, AtomexBlockchainOptions, AtomexCurrencyOptions, + AtomexManagers, AtomexServices, +} from './models/index'; diff --git a/src/atomex/models/index.ts b/src/atomex/models/index.ts index 8ef202b9..f8476bef 100644 --- a/src/atomex/models/index.ts +++ b/src/atomex/models/index.ts @@ -1,4 +1,7 @@ -export type { AtomexOptions, AtomexBlockchainOptions, AtomexServices } from './atomexOptions'; +export type { + AtomexOptions, AtomexBlockchainOptions, AtomexBlockchainNetworkOptions, AtomexCurrencyOptions, + AtomexManagers, AtomexServices +} from './atomexOptions'; export type { NewSwapRequest } from './newSwapRequest'; export { SwapOperationCompleteStage } from './swapOperationCompleteStage'; diff --git a/src/atomexBuilder/atomexBuilder.ts b/src/atomexBuilder/atomexBuilder.ts index 70851015..63300654 100644 --- a/src/atomexBuilder/atomexBuilder.ts +++ b/src/atomexBuilder/atomexBuilder.ts @@ -106,8 +106,8 @@ export class AtomexBuilder { protected createDefaultBlockchainOptions(): Record { return { - tezos: createDefaultTezosBlockchainOptions(), - ethereum: createDefaultEthereumBlockchainOptions() + tezos: createDefaultTezosBlockchainOptions(this.atomexContext), + ethereum: createDefaultEthereumBlockchainOptions(this.atomexContext) }; } } diff --git a/src/blockchain/atomexBlockchainProvider.ts b/src/blockchain/atomexBlockchainProvider.ts index 3c0516f3..76903ca3 100644 --- a/src/blockchain/atomexBlockchainProvider.ts +++ b/src/blockchain/atomexBlockchainProvider.ts @@ -51,7 +51,7 @@ export class AtomexBlockchainProvider implements CurrenciesProvider { return this.getCurrencyInfo(currencyId)?.currency; } - async getReadonlyToolkit(toolkitId: string, blockchain?: string): Promise { + async getReadonlyToolkit(toolkitId: string, blockchain?: string): Promise { const providerToolkitPromises: Array> = []; for (const provider of this.blockchainToolkitProviders) { if (provider.toolkitId === toolkitId) @@ -61,7 +61,7 @@ export class AtomexBlockchainProvider implements CurrenciesProvider { const providerToolkitResults = await Promise.all(providerToolkitPromises); for (const providerResult of providerToolkitResults) { if (providerResult) - return providerResult; + return providerResult as Toolkit; } return Promise.resolve(undefined); diff --git a/src/blockchain/atomexProtocol.ts b/src/blockchain/atomexProtocol.ts index 1802e807..068ee1ac 100644 --- a/src/blockchain/atomexProtocol.ts +++ b/src/blockchain/atomexProtocol.ts @@ -2,5 +2,5 @@ import type { AtomexNetwork } from '../common/index'; export interface AtomexProtocol { readonly version: number; - readonly network: AtomexNetwork; + readonly atomexNetwork: AtomexNetwork; } diff --git a/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts b/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts index fcc5bc64..66c86cfa 100644 --- a/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts +++ b/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts @@ -3,20 +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; - getEstimatedInitiateFees(params: Partial): Promise; + initiate(params: AtomexProtocolV1InitiateParameters): Promise; + getEstimatedInitiateFees(params: Partial): Promise; - redeem(params: RedeemParametersAtomexProtocolV1): Promise; - getEstimatedRedeemFees(params: Partial): Promise; + redeem(params: AtomexProtocolV1RedeemParameters): Promise; + getEstimatedRedeemFees(params: Partial): Promise; + getRedeemReward(nativeTokenPriceInUsd: number, nativeTokenPriceInCurrency: number): Promise; - refund(params: RefundParametersAtomexProtocolV1): Promise; - getEstimatedRefundFees(params: Partial): Promise; + refund(params: AtomexProtocolV1RefundParameters): Promise; + getEstimatedRefundFees(params: Partial): Promise; } diff --git a/src/blockchain/atomexProtocolV1/guards.ts b/src/blockchain/atomexProtocolV1/guards.ts new file mode 100644 index 00000000..1dc78c92 --- /dev/null +++ b/src/blockchain/atomexProtocolV1/guards.ts @@ -0,0 +1,6 @@ +import type { AtomexProtocol } from '../atomexProtocol'; +import type { AtomexProtocolV1 } from './atomexProtocolV1'; + +export const isAtomexProtocolV1 = (atomexProtocol: AtomexProtocol): atomexProtocol is AtomexProtocolV1 => { + return atomexProtocol.version === 1; +}; diff --git a/src/blockchain/atomexProtocolV1/index.ts b/src/blockchain/atomexProtocolV1/index.ts index 00cf4a29..08c90e45 100644 --- a/src/blockchain/atomexProtocolV1/index.ts +++ b/src/blockchain/atomexProtocolV1/index.ts @@ -1,4 +1,7 @@ +export { isAtomexProtocolV1 } from './guards'; + 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'; diff --git a/src/blockchain/atomexProtocolV1/initiateParametersAtomexProtocolV1.ts b/src/blockchain/atomexProtocolV1/initiateParameters.ts similarity index 82% rename from src/blockchain/atomexProtocolV1/initiateParametersAtomexProtocolV1.ts rename to src/blockchain/atomexProtocolV1/initiateParameters.ts index 73cb9a92..69285beb 100644 --- a/src/blockchain/atomexProtocolV1/initiateParametersAtomexProtocolV1.ts +++ b/src/blockchain/atomexProtocolV1/initiateParameters.ts @@ -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; diff --git a/src/blockchain/atomexProtocolV1/options.ts b/src/blockchain/atomexProtocolV1/options.ts new file mode 100644 index 00000000..5ec93a80 --- /dev/null +++ b/src/blockchain/atomexProtocolV1/options.ts @@ -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; +} diff --git a/src/blockchain/atomexProtocolV1/redeemParameters.ts b/src/blockchain/atomexProtocolV1/redeemParameters.ts new file mode 100644 index 00000000..71163cd8 --- /dev/null +++ b/src/blockchain/atomexProtocolV1/redeemParameters.ts @@ -0,0 +1,3 @@ +export interface AtomexProtocolV1RedeemParameters { + readonly secretHash: string; +} diff --git a/src/blockchain/atomexProtocolV1/redeemParametersAtomexProtocolV1.ts b/src/blockchain/atomexProtocolV1/redeemParametersAtomexProtocolV1.ts deleted file mode 100644 index 30adcf3f..00000000 --- a/src/blockchain/atomexProtocolV1/redeemParametersAtomexProtocolV1.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface RedeemParametersAtomexProtocolV1 { - readonly secretHash: string; -} diff --git a/src/blockchain/atomexProtocolV1/refundParameters.ts b/src/blockchain/atomexProtocolV1/refundParameters.ts new file mode 100644 index 00000000..acbd185d --- /dev/null +++ b/src/blockchain/atomexProtocolV1/refundParameters.ts @@ -0,0 +1,3 @@ +export interface AtomexProtocolV1RefundParameters { + readonly secretHash: string; +} diff --git a/src/blockchain/atomexProtocolV1/refundParametersAtomexProtocolV1.ts b/src/blockchain/atomexProtocolV1/refundParametersAtomexProtocolV1.ts deleted file mode 100644 index c0d3b224..00000000 --- a/src/blockchain/atomexProtocolV1/refundParametersAtomexProtocolV1.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface RefundParametersAtomexProtocolV1 { - readonly secretHash: string; -} diff --git a/src/blockchain/index.ts b/src/blockchain/index.ts index 549c7f1a..01fe8224 100644 --- a/src/blockchain/index.ts +++ b/src/blockchain/index.ts @@ -1,10 +1,11 @@ export { WalletsManager } from './walletsManager'; +export { isAtomexProtocolV1 } from './atomexProtocolV1/index'; -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'; diff --git a/src/blockchain/models/atomexProtocolOptions.ts b/src/blockchain/models/atomexProtocolOptions.ts new file mode 100644 index 00000000..08ef15ce --- /dev/null +++ b/src/blockchain/models/atomexProtocolOptions.ts @@ -0,0 +1,3 @@ +export interface AtomexProtocolOptions { + atomexProtocolVersion: number; +} diff --git a/src/blockchain/models/index.ts b/src/blockchain/models/index.ts index d3a585c4..05fa6acc 100644 --- a/src/blockchain/models/index.ts +++ b/src/blockchain/models/index.ts @@ -1,2 +1,3 @@ +export type { AtomexProtocolOptions } from './atomexProtocolOptions'; export type { AtomexSignature } from './atomexSignature'; export type { Transaction } from './transaction'; diff --git a/src/blockchain/walletsManager.ts b/src/blockchain/walletsManager.ts index 5f5389f1..2835eea4 100644 --- a/src/blockchain/walletsManager.ts +++ b/src/blockchain/walletsManager.ts @@ -21,13 +21,17 @@ export class WalletsManager { return Promise.resolve(result); } - async getWallet(address?: string, blockchain?: string, toolkit?: string): Promise { + async getWallet(address?: string, blockchain?: string, toolkit?: string): Promise | undefined> { if (!this.wallets.size || (!address && !blockchain && !toolkit)) return undefined; - const walletPromises: Array> = []; + const walletPromises: Array, + address: string | undefined, + blockchain: string | undefined + ]>> = []; - for (const wallet of this.wallets) { + for (const wallet of this.wallets as Set>) { if (toolkit && wallet.id !== toolkit) continue; diff --git a/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts b/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts new file mode 100644 index 00000000..1d3a681b --- /dev/null +++ b/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts @@ -0,0 +1,54 @@ +import type BigNumber from 'bignumber.js'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + Transaction, WalletsManager +} from '../../blockchain/index'; +import type { AtomexNetwork } from '../../common/index'; +import type { DeepReadonly } from '../../core/index'; +import { Web3AtomexProtocolV1 } from '../../evm/index'; +import type { ERC20EthereumWeb3AtomexProtocolV1Options } from '../models/index'; + +export class ERC20EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { + constructor( + atomexNetwork: AtomexNetwork, + protected readonly atomexProtocolOptions: DeepReadonly, + atomexBlockchainProvider: AtomexBlockchainProvider, + walletsManager: WalletsManager + ) { + super('ethereum', atomexNetwork, atomexProtocolOptions, atomexBlockchainProvider, walletsManager); + } + + get currencyId() { + return this.atomexProtocolOptions.currencyId; + } + + initiate(_params: AtomexProtocolV1InitiateParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedInitiateFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + redeem(_params: AtomexProtocolV1RedeemParameters): Promise { + throw new Error('Method not implemented.'); + } + + getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRedeemFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + refund(_params: AtomexProtocolV1RefundParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRefundFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts b/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts new file mode 100644 index 00000000..487ed575 --- /dev/null +++ b/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts @@ -0,0 +1,50 @@ +import type BigNumber from 'bignumber.js'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + Transaction, WalletsManager +} from '../../blockchain/index'; +import type { AtomexNetwork } from '../../common/index'; +import type { DeepReadonly } from '../../core/index'; +import { Web3AtomexProtocolV1 } from '../../evm/index'; +import type { EthereumWeb3AtomexProtocolV1Options } from '../models/index'; + +export class EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { + constructor( + atomexNetwork: AtomexNetwork, + protected readonly atomexProtocolOptions: DeepReadonly, + atomexBlockchainProvider: AtomexBlockchainProvider, + walletsManager: WalletsManager + ) { + super('ethereum', atomexNetwork, atomexProtocolOptions, atomexBlockchainProvider, walletsManager); + } + + initiate(_params: AtomexProtocolV1InitiateParameters): Promise { + throw new Error('Method not implemented.'); + } + + async getEstimatedInitiateFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + redeem(_params: AtomexProtocolV1RedeemParameters): Promise { + throw new Error('Method not implemented.'); + } + + getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRedeemFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + refund(_params: AtomexProtocolV1RefundParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRefundFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/src/ethereum/atomexProtocol/index.ts b/src/ethereum/atomexProtocol/index.ts new file mode 100644 index 00000000..102aff87 --- /dev/null +++ b/src/ethereum/atomexProtocol/index.ts @@ -0,0 +1,2 @@ +export { EthereumWeb3AtomexProtocolV1 } from './ethereumWeb3AtomexProtocolV1'; +export { ERC20EthereumWeb3AtomexProtocolV1 } from './erc20EthereumWeb3AtomexProtocolV1'; diff --git a/src/ethereum/config/atomexProtocol/base.ts b/src/ethereum/config/atomexProtocol/base.ts new file mode 100644 index 00000000..4e8bd48b --- /dev/null +++ b/src/ethereum/config/atomexProtocol/base.ts @@ -0,0 +1,285 @@ +import type { AbiItem } from 'web3-utils'; + +export const ethereumWeb3AtomexProtocolV1ABI: AbiItem[] = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + } + ], + name: 'Activated', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + }, + { + indexed: false, + internalType: 'address', + name: '_sender', + type: 'address' + }, + { + indexed: false, + internalType: 'uint256', + name: '_value', + type: 'uint256' + } + ], + name: 'Added', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + }, + { + indexed: true, + internalType: 'address', + name: '_participant', + type: 'address' + }, + { + indexed: false, + internalType: 'address', + name: '_initiator', + type: 'address' + }, + { + indexed: false, + internalType: 'uint256', + name: '_refundTimestamp', + type: 'uint256' + }, + { + indexed: false, + internalType: 'uint256', + name: '_countdown', + type: 'uint256' + }, + { + indexed: false, + internalType: 'uint256', + name: '_value', + type: 'uint256' + }, + { + indexed: false, + internalType: 'uint256', + name: '_payoff', + type: 'uint256' + }, + { + indexed: false, + internalType: 'bool', + name: '_active', + type: 'bool' + } + ], + name: 'Initiated', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + }, + { + indexed: false, + internalType: 'bytes32', + name: '_secret', + type: 'bytes32' + } + ], + name: 'Redeemed', + type: 'event' + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + } + ], + name: 'Refunded', + type: 'event' + }, + { + constant: true, + inputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32' + } + ], + name: 'swaps', + outputs: [ + { + internalType: 'bytes32', + name: 'hashedSecret', + type: 'bytes32' + }, + { + internalType: 'address payable', + name: 'initiator', + type: 'address' + }, + { + internalType: 'address payable', + name: 'participant', + type: 'address' + }, + { + internalType: 'uint256', + name: 'refundTimestamp', + type: 'uint256' + }, + { + internalType: 'uint256', + name: 'countdown', + type: 'uint256' + }, + { + internalType: 'uint256', + name: 'value', + type: 'uint256' + }, + { + internalType: 'uint256', + name: 'payoff', + type: 'uint256' + }, + { + internalType: 'bool', + name: 'active', + type: 'bool' + }, + { + internalType: 'enum Atomex.State', + name: 'state', + type: 'uint8' + } + ], + payable: false, + stateMutability: 'view', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + }, + { + internalType: 'address payable', + name: '_participant', + type: 'address' + }, + { + internalType: 'uint256', + name: '_refundTimestamp', + type: 'uint256' + }, + { + internalType: 'uint256', + name: '_payoff', + type: 'uint256' + } + ], + name: 'initiate', + outputs: [], + payable: true, + stateMutability: 'payable', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + } + ], + name: 'add', + outputs: [], + payable: true, + stateMutability: 'payable', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + } + ], + name: 'activate', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + }, + { + internalType: 'bytes32', + name: '_secret', + type: 'bytes32' + } + ], + name: 'redeem', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + }, + { + constant: false, + inputs: [ + { + internalType: 'bytes32', + name: '_hashedSecret', + type: 'bytes32' + } + ], + name: 'refund', + outputs: [], + payable: false, + stateMutability: 'nonpayable', + type: 'function' + } +]; diff --git a/src/ethereum/config/atomexProtocol/index.ts b/src/ethereum/config/atomexProtocol/index.ts new file mode 100644 index 00000000..8e84f847 --- /dev/null +++ b/src/ethereum/config/atomexProtocol/index.ts @@ -0,0 +1,2 @@ +export { mainnetEthereumWeb3AtomexProtocolV1Options } from './mainnetV1Options'; +export { testnetEthereumWeb3AtomexProtocolV1Options } from './testnetV1Options'; diff --git a/src/ethereum/config/atomexProtocol/mainnetV1Options.ts b/src/ethereum/config/atomexProtocol/mainnetV1Options.ts new file mode 100644 index 00000000..a2bb57bd --- /dev/null +++ b/src/ethereum/config/atomexProtocol/mainnetV1Options.ts @@ -0,0 +1,28 @@ +import type { EthereumWeb3AtomexProtocolV1Options } from '../../models/index'; +import { ethereumWeb3AtomexProtocolV1ABI } from './base'; + +const mainnetNativeEthereumWeb3AtomexProtocolV1Options: EthereumWeb3AtomexProtocolV1Options = { + atomexProtocolVersion: 1, + currencyId: 'ETH', + swapContractAddress: '0xe9c251cbb4881f9e056e40135e7d3ea9a7d037df', + swapContractBlockId: '8168569', + initiateOperation: { + gasLimit: { + withoutReward: 200000, + withReward: 210000 + } + }, + redeemOperation: { + gasLimit: 140000 + }, + refundOperation: { + gasLimit: 90000 + }, + defaultGasPriceInGwei: 90, + maxGasPriceInGwei: 650, + abi: ethereumWeb3AtomexProtocolV1ABI +}; + +export const mainnetEthereumWeb3AtomexProtocolV1Options = { + ETH: mainnetNativeEthereumWeb3AtomexProtocolV1Options +} as const; diff --git a/src/ethereum/config/atomexProtocol/testnetV1Options.ts b/src/ethereum/config/atomexProtocol/testnetV1Options.ts new file mode 100644 index 00000000..68e72f2b --- /dev/null +++ b/src/ethereum/config/atomexProtocol/testnetV1Options.ts @@ -0,0 +1,12 @@ +import type { EthereumWeb3AtomexProtocolV1Options } from '../../models/index'; +import { mainnetEthereumWeb3AtomexProtocolV1Options } from './mainnetV1Options'; + +const testnetNativeEthereumWeb3AtomexProtocolV1Options: EthereumWeb3AtomexProtocolV1Options = { + ...mainnetEthereumWeb3AtomexProtocolV1Options.ETH, + swapContractAddress: '0x512fe6B803bA327DCeFBF2Cec7De333f761B0f2b', + swapContractBlockId: '6954501', +}; + +export const testnetEthereumWeb3AtomexProtocolV1Options = { + ETH: testnetNativeEthereumWeb3AtomexProtocolV1Options +} as const; diff --git a/src/ethereum/config/currencies.ts b/src/ethereum/config/currencies.ts index 4374b250..7c6dfc96 100644 --- a/src/ethereum/config/currencies.ts +++ b/src/ethereum/config/currencies.ts @@ -1,7 +1,6 @@ -import type { AtomexBlockchainNetworkOptions } from '../../atomex/models/atomexOptions'; -import type { EthereumCurrency } from '../models/currency'; +import type { EthereumCurrency, NativeEthereumCurrency } from '../models/currency'; -const ethereumNativeCurrency: EthereumCurrency = { +const nativeEthereumCurrency: NativeEthereumCurrency = { id: 'ETH', name: 'Ethereum', symbol: 'ETH', @@ -10,10 +9,10 @@ const ethereumNativeCurrency: EthereumCurrency = { type: 'native' }; -export const ethereumMainnetCurrencies: AtomexBlockchainNetworkOptions['currencies'] = [ - ethereumNativeCurrency +export const ethereumMainnetCurrencies: EthereumCurrency[] = [ + nativeEthereumCurrency ]; -export const ethereumTestnetCurrencies: AtomexBlockchainNetworkOptions['currencies'] = [ - ethereumNativeCurrency +export const ethereumTestnetCurrencies: EthereumCurrency[] = [ + nativeEthereumCurrency ]; diff --git a/src/ethereum/config/defaultOptions.ts b/src/ethereum/config/defaultOptions.ts index 9e612418..8e524ccd 100644 --- a/src/ethereum/config/defaultOptions.ts +++ b/src/ethereum/config/defaultOptions.ts @@ -1,13 +1,71 @@ -import type { AtomexBlockchainOptions } from '../../atomex/models/index'; -import { Web3BlockchainToolkitProvider } from '../../evm'; +import type { AtomexContext, AtomexBlockchainOptions, AtomexCurrencyOptions } from '../../atomex/index'; +import { Web3BlockchainToolkitProvider } from '../../evm/index'; +import { ERC20EthereumWeb3AtomexProtocolV1, EthereumWeb3AtomexProtocolV1 } from '../atomexProtocol/index'; import { EthereumBalancesProvider } from '../balancesProviders/index'; +import type { EthereumCurrency } from '../models'; import { EthereumSwapTransactionsProvider } from '../swapTransactionsProviders/index'; +import { mainnetEthereumWeb3AtomexProtocolV1Options, testnetEthereumWeb3AtomexProtocolV1Options } from './atomexProtocol'; import { ethereumMainnetCurrencies, ethereumTestnetCurrencies } from './currencies'; -export const createDefaultEthereumBlockchainOptions = (): AtomexBlockchainOptions => { +type AtomexProtocolOptions = typeof mainnetEthereumWeb3AtomexProtocolV1Options | typeof testnetEthereumWeb3AtomexProtocolV1Options; + +const createAtomexProtocol = ( + atomexContext: AtomexContext, + currency: EthereumCurrency, + atomexProtocolOptions: AtomexProtocolOptions[keyof AtomexProtocolOptions] +) => { + switch (currency.type) { + case 'native': + return new EthereumWeb3AtomexProtocolV1( + atomexContext.atomexNetwork, + atomexProtocolOptions, + atomexContext.providers.blockchainProvider, + atomexContext.managers.walletsManager + ); + case 'erc-20': + return new ERC20EthereumWeb3AtomexProtocolV1( + atomexContext.atomexNetwork, + atomexProtocolOptions, + atomexContext.providers.blockchainProvider, + atomexContext.managers.walletsManager + ); + default: + throw new Error(`Unknown Ethereum currency: ${(currency as EthereumCurrency).id}`); + } +}; + +const createCurrencyOptions = ( + atomexContext: AtomexContext, + currencies: EthereumCurrency[], + atomexProtocolOptions: AtomexProtocolOptions +): Record => { + const result: Record = {}; + const currenciesMap = currencies.reduce>( + (obj, currency) => { + obj[currency.id] = currency; + + return obj; + }, + {} + ); + + for (const options of Object.values(atomexProtocolOptions)) { + const currency = currenciesMap[options.currencyId]; + if (!currency) + throw new Error(`The ${options.currencyId} currency not found`); + + result[currency.id] = { + atomexProtocol: createAtomexProtocol(atomexContext, currency, options) + }; + } + + return result; +}; + +export const createDefaultEthereumBlockchainOptions = (atomexContext: AtomexContext): AtomexBlockchainOptions => { const blockchain = 'ethereum'; - const mainnetRpcUrl = 'https://eth-mainnet.public.blastapi.io'; - const testNetRpcUrl = 'https://rpc.goerli.mudit.blog'; + const mainnetRpcUrl = 'https://mainnet.infura.io/v3/df01d4ef450640a2a48d9af4c2078eaf/'; + const testNetRpcUrl = 'https://goerli.infura.io/v3/df01d4ef450640a2a48d9af4c2078eaf/'; const balancesProvider = new EthereumBalancesProvider(); const swapTransactionsProvider = new EthereumSwapTransactionsProvider(); @@ -16,7 +74,7 @@ export const createDefaultEthereumBlockchainOptions = (): AtomexBlockchainOption mainnet: { rpcUrl: mainnetRpcUrl, currencies: ethereumMainnetCurrencies, - currencyOptions: {}, + currencyOptions: createCurrencyOptions(atomexContext, ethereumMainnetCurrencies, mainnetEthereumWeb3AtomexProtocolV1Options), blockchainToolkitProvider: new Web3BlockchainToolkitProvider(blockchain, mainnetRpcUrl), balancesProvider, swapTransactionsProvider, @@ -24,7 +82,7 @@ export const createDefaultEthereumBlockchainOptions = (): AtomexBlockchainOption testnet: { rpcUrl: testNetRpcUrl, currencies: ethereumTestnetCurrencies, - currencyOptions: {}, + currencyOptions: createCurrencyOptions(atomexContext, ethereumTestnetCurrencies, testnetEthereumWeb3AtomexProtocolV1Options), blockchainToolkitProvider: new Web3BlockchainToolkitProvider(blockchain, testNetRpcUrl), balancesProvider, swapTransactionsProvider, diff --git a/src/ethereum/config/index.ts b/src/ethereum/config/index.ts index afc1bb7a..a0a66e6c 100644 --- a/src/ethereum/config/index.ts +++ b/src/ethereum/config/index.ts @@ -1,2 +1,3 @@ export { ethereumMainnetCurrencies, ethereumTestnetCurrencies } from './currencies'; export { createDefaultEthereumBlockchainOptions } from './defaultOptions'; +export { mainnetEthereumWeb3AtomexProtocolV1Options, testnetEthereumWeb3AtomexProtocolV1Options } from './atomexProtocol'; diff --git a/src/ethereum/index.ts b/src/ethereum/index.ts index 883ce4d3..a1ae6f25 100644 --- a/src/ethereum/index.ts +++ b/src/ethereum/index.ts @@ -1,3 +1,4 @@ +export { EthereumWeb3AtomexProtocolV1, ERC20EthereumWeb3AtomexProtocolV1 } from './atomexProtocol/index'; +export { EthereumBalancesProvider } from './balancesProviders/index'; +export { EthereumSwapTransactionsProvider } from './swapTransactionsProviders/index'; export { ethereumMainnetCurrencies, ethereumTestnetCurrencies, createDefaultEthereumBlockchainOptions } from './config/index'; -export { EthereumBalancesProvider } from './balancesProviders'; -export { EthereumSwapTransactionsProvider } from './swapTransactionsProviders'; diff --git a/src/ethereum/models/atomexProtocolOptions.ts b/src/ethereum/models/atomexProtocolOptions.ts new file mode 100644 index 00000000..2849bd61 --- /dev/null +++ b/src/ethereum/models/atomexProtocolOptions.ts @@ -0,0 +1,9 @@ +import type { AbiItem } from 'web3-utils'; + +import type { Web3AtomexProtocolV1Options } from '../../evm/index'; + +export interface EthereumWeb3AtomexProtocolV1Options extends Web3AtomexProtocolV1Options { + abi: AbiItem[]; +} + +export type ERC20EthereumWeb3AtomexProtocolV1Options = EthereumWeb3AtomexProtocolV1Options; diff --git a/src/ethereum/models/currency.ts b/src/ethereum/models/currency.ts index 9f0f832f..abaee846 100644 --- a/src/ethereum/models/currency.ts +++ b/src/ethereum/models/currency.ts @@ -1,6 +1,6 @@ import type { Currency } from '../../common/index'; -export interface EthereumCurrency extends Currency { +export interface NativeEthereumCurrency extends Currency { readonly name: 'Ethereum'; readonly symbol: 'ETH'; readonly blockchain: 'ethereum'; @@ -13,3 +13,7 @@ export interface ERC20EthereumCurrency extends Currency { readonly type: 'erc-20'; readonly contractAddress: string; } + +export type EthereumCurrency = + | NativeEthereumCurrency + | ERC20EthereumCurrency; diff --git a/src/ethereum/models/index.ts b/src/ethereum/models/index.ts index b06a5a5c..f9a7ac04 100644 --- a/src/ethereum/models/index.ts +++ b/src/ethereum/models/index.ts @@ -1 +1,2 @@ -export type { EthereumCurrency, ERC20EthereumCurrency } from './currency'; +export type { EthereumCurrency, NativeEthereumCurrency, ERC20EthereumCurrency } from './currency'; +export type { EthereumWeb3AtomexProtocolV1Options, ERC20EthereumWeb3AtomexProtocolV1Options } from './atomexProtocolOptions'; diff --git a/src/evm/atomexProtocol/index.ts b/src/evm/atomexProtocol/index.ts new file mode 100644 index 00000000..7cb4620b --- /dev/null +++ b/src/evm/atomexProtocol/index.ts @@ -0,0 +1 @@ +export { Web3AtomexProtocolV1 } from './web3AtomexProtocolV1'; diff --git a/src/evm/atomexProtocol/web3AtomexProtocolV1.ts b/src/evm/atomexProtocol/web3AtomexProtocolV1.ts new file mode 100644 index 00000000..869063fa --- /dev/null +++ b/src/evm/atomexProtocol/web3AtomexProtocolV1.ts @@ -0,0 +1,58 @@ +import type BigNumber from 'bignumber.js'; +import type Web3 from 'web3'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + BlockchainWallet, 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, + protected readonly atomexBlockchainProvider: AtomexBlockchainProvider, + protected readonly walletsManager: WalletsManager + ) { + } + + get currencyId() { + return this.atomexProtocolOptions.currencyId; + } + + abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise; + + abstract getEstimatedInitiateFees(_params: Partial): Promise; + + abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise; + + abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise; + + abstract getEstimatedRedeemFees(_params: Partial): Promise; + + abstract refund(_params: AtomexProtocolV1RefundParameters): Promise; + + abstract getEstimatedRefundFees(_params: Partial): Promise; + + protected async getReadonlyWeb3(): Promise { + const toolkit = await this.atomexBlockchainProvider.getReadonlyToolkit('web3', this.blockchain); + if (!toolkit) + throw new Error('Web3 toolkit not found'); + + return toolkit; + } + + protected async getWallet(address?: string): Promise> { + const web3Wallet = await this.walletsManager.getWallet(address, this.blockchain, 'web3'); + if (!web3Wallet) + throw new Error(`${this.blockchain} Web3 wallet not found`); + + return web3Wallet; + } +} diff --git a/src/evm/index.ts b/src/evm/index.ts index cdd3c0de..f336785c 100644 --- a/src/evm/index.ts +++ b/src/evm/index.ts @@ -1,2 +1,5 @@ -export { Web3BlockchainWallet } from './wallets'; -export { Web3BlockchainToolkitProvider } from './blockchainToolkitProviders'; +export { Web3AtomexProtocolV1 } from './atomexProtocol/index'; +export { Web3BlockchainWallet } from './wallets/index'; +export { Web3BlockchainToolkitProvider } from './blockchainToolkitProviders/index'; + +export type { Web3AtomexProtocolV1Options } from './models/index'; diff --git a/src/evm/models/index.ts b/src/evm/models/index.ts new file mode 100644 index 00000000..d070f5cd --- /dev/null +++ b/src/evm/models/index.ts @@ -0,0 +1 @@ +export type { Web3AtomexProtocolV1Options } from './web3AtomexProtocolV1Options'; diff --git a/src/evm/models/web3AtomexProtocolV1Options.ts b/src/evm/models/web3AtomexProtocolV1Options.ts new file mode 100644 index 00000000..2d7c796e --- /dev/null +++ b/src/evm/models/web3AtomexProtocolV1Options.ts @@ -0,0 +1,18 @@ +import type { AtomexProtocolV1Options } from '../../blockchain/index'; + +export interface Web3AtomexProtocolV1Options extends AtomexProtocolV1Options { + initiateOperation: { + gasLimit: { + withoutReward: number; + withReward: number; + }; + }; + redeemOperation: { + gasLimit: number; + }; + refundOperation: { + gasLimit: number; + }; + defaultGasPriceInGwei: number; + maxGasPriceInGwei: number; +} diff --git a/src/exchange/exchangeManager.ts b/src/exchange/exchangeManager.ts index 74a5d4c7..21f90dd4 100644 --- a/src/exchange/exchangeManager.ts +++ b/src/exchange/exchangeManager.ts @@ -2,7 +2,7 @@ import type { BigNumber } from 'bignumber.js'; import { nanoid } from 'nanoid'; import { AtomexService, DataSource, ImportantDataReceivingMode, Side } from '../common/index'; -import { EventEmitter, type ToEventEmitter, type Result } from '../core/index'; +import { EventEmitter, type ToEventEmitter } from '../core/index'; import type { ExchangeService, ExchangeServiceEvents } from './exchangeService'; import type { ManagedExchangeSymbolsProvider } from './exchangeSymbolsProvider'; import { symbolsHelper } from './helpers/index'; @@ -176,10 +176,6 @@ export class ExchangeManager implements AtomexService { throw new Error('Not implemented'); } - getRewardForRedeem(_nativeTokenUsdPrice: number, _nativeTokenCurrencyPrice: number): Promise> { - throw new Error('Not implemented'); - } - protected attachEvents() { this.exchangeService.events.orderUpdated.addListener(this.handleExchangeServiceOrderUpdated); this.exchangeService.events.orderBookUpdated.addListener(this.handleExchangeServiceOrderBookUpdated); diff --git a/src/index.ts b/src/index.ts index 52eb4628..af97b6a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,16 +6,20 @@ export { LocalStorageAuthorizationManagerStore, DefaultSerializedAuthTokenMapper export { RestAtomexClient, WebSocketAtomexClient, MixedApiAtomexClient } from './clients/index'; export { DataSource, ImportantDataReceivingMode } from './common/index'; export { Web3BlockchainWallet } from './evm/index'; -export { ExchangeManager, InMemoryExchangeSymbolsProvider } from './exchange'; +export { ExchangeManager, InMemoryExchangeSymbolsProvider } from './exchange/index'; +export { EthereumWeb3AtomexProtocolV1, ERC20EthereumWeb3AtomexProtocolV1 } from './ethereum/index'; export { InMemoryAuthorizationManagerStore } from './stores/index'; -export { TaquitoBlockchainWallet } from './tezos/index'; +export { + TaquitoBlockchainWallet, + TezosTaquitoAtomexProtocolV1, FA12TezosTaquitoAtomexProtocolV1, FA2TezosTaquitoAtomexProtocolV1 +} from './tezos/index'; export * from './utils'; export type { AtomexOptions, NewSwapRequest } from './atomex/index'; export type { AuthToken, AuthorizationManagerOptions } from './authorization/index'; export type { AtomexProtocol, Transaction, - AtomexProtocolV1, InitiateParametersAtomexProtocolV1, RedeemParametersAtomexProtocolV1, RefundParametersAtomexProtocolV1, + AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, AtomexSignature, BlockchainWallet, BalancesProvider, SwapTransactionsProvider, TransactionsProvider } from './blockchain/index'; @@ -25,6 +29,6 @@ export type { AtomexClient } from './clients/index'; export type { AtomexNetwork, Currency, Side, CurrenciesProvider, CollectionSelector } from './common/index'; export type { AtomexStore, AuthorizationManagerStore } from './stores/index'; export type { Swap, SwapParticipant, SwapParticipantRequisites, SwapParticipantStatus } from './swaps/index'; -export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './tezos/index'; +export type { TezosCurrency, NativeTezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from './tezos/index'; export * as legacy from './legacy/index'; diff --git a/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts new file mode 100644 index 00000000..07d5b693 --- /dev/null +++ b/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts @@ -0,0 +1,54 @@ +import type BigNumber from 'bignumber.js'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + Transaction, WalletsManager +} from '../../blockchain/index'; +import type { AtomexNetwork } from '../../common/index'; +import type { DeepReadonly } from '../../core/index'; +import type { FA12TezosTaquitoAtomexProtocolV1Options } from '../models/index'; +import { TaquitoAtomexProtocolV1 } from './taquitoAtomexProtocolV1'; + +export class FA12TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { + constructor( + atomexNetwork: AtomexNetwork, + protected readonly atomexProtocolOptions: DeepReadonly, + atomexBlockchainProvider: AtomexBlockchainProvider, + walletsManager: WalletsManager + ) { + super('tezos', atomexNetwork, atomexProtocolOptions, atomexBlockchainProvider, walletsManager); + } + + get currencyId() { + return this.atomexProtocolOptions.currencyId; + } + + initiate(_params: AtomexProtocolV1InitiateParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedInitiateFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + redeem(_params: AtomexProtocolV1RedeemParameters): Promise { + throw new Error('Method not implemented.'); + } + + getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRedeemFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + refund(_params: AtomexProtocolV1RefundParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRefundFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts new file mode 100644 index 00000000..c98dbd39 --- /dev/null +++ b/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts @@ -0,0 +1,54 @@ +import type BigNumber from 'bignumber.js'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + Transaction, WalletsManager +} from '../../blockchain/index'; +import type { AtomexNetwork } from '../../common/index'; +import type { DeepReadonly } from '../../core/index'; +import type { FA2TezosTaquitoAtomexProtocolV1Options } from '../models/index'; +import { TaquitoAtomexProtocolV1 } from './taquitoAtomexProtocolV1'; + +export class FA2TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { + constructor( + atomexNetwork: AtomexNetwork, + protected readonly atomexProtocolOptions: DeepReadonly, + atomexBlockchainProvider: AtomexBlockchainProvider, + walletsManager: WalletsManager + ) { + super('tezos', atomexNetwork, atomexProtocolOptions, atomexBlockchainProvider, walletsManager); + } + + get currencyId() { + return this.atomexProtocolOptions.currencyId; + } + + initiate(_params: AtomexProtocolV1InitiateParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedInitiateFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + redeem(_params: AtomexProtocolV1RedeemParameters): Promise { + throw new Error('Method not implemented.'); + } + + getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRedeemFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + refund(_params: AtomexProtocolV1RefundParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRefundFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/src/tezos/atomexProtocol/index.ts b/src/tezos/atomexProtocol/index.ts new file mode 100644 index 00000000..971d23de --- /dev/null +++ b/src/tezos/atomexProtocol/index.ts @@ -0,0 +1,3 @@ +export { TezosTaquitoAtomexProtocolV1 } from './tezosTaquitoAtomexProtocolV1'; +export { FA12TezosTaquitoAtomexProtocolV1 } from './fa12TezosTaquitoAtomexProtocolV1'; +export { FA2TezosTaquitoAtomexProtocolV1 } from './fa2TezosTaquitoAtomexProtocolV1'; diff --git a/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts new file mode 100644 index 00000000..0bbe320d --- /dev/null +++ b/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts @@ -0,0 +1,58 @@ +import type { TezosToolkit } from '@taquito/taquito'; +import type BigNumber from 'bignumber.js'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + BlockchainWallet, 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, + protected readonly atomexBlockchainProvider: AtomexBlockchainProvider, + protected readonly walletsManager: WalletsManager + ) { + } + + get currencyId() { + return this.atomexProtocolOptions.currencyId; + } + + abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise; + + abstract getEstimatedInitiateFees(_params: Partial): Promise; + + abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise; + + abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise; + + abstract getEstimatedRedeemFees(_params: Partial): Promise; + + abstract refund(_params: AtomexProtocolV1RefundParameters): Promise; + + abstract getEstimatedRefundFees(_params: Partial): Promise; + + protected async getReadonlyTezosToolkit(): Promise { + const toolkit = await this.atomexBlockchainProvider.getReadonlyToolkit('taquito', this.blockchain); + if (!toolkit) + throw new Error('Tezos toolkit not found'); + + return toolkit; + } + + protected async getWallet(address?: string): Promise> { + const taquitoWallet = await this.walletsManager.getWallet(address, this.blockchain, 'taquito'); + if (!taquitoWallet) + throw new Error(`${this.blockchain} Taqutio wallet not found`); + + return taquitoWallet; + } +} diff --git a/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts new file mode 100644 index 00000000..08d57161 --- /dev/null +++ b/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts @@ -0,0 +1,54 @@ +import type BigNumber from 'bignumber.js'; + +import type { + AtomexBlockchainProvider, + AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + Transaction, WalletsManager +} from '../../blockchain/index'; +import type { AtomexNetwork } from '../../common/index'; +import type { DeepReadonly } from '../../core/index'; +import type { TezosTaquitoAtomexProtocolV1Options } from '../models/index'; +import { TaquitoAtomexProtocolV1 } from './taquitoAtomexProtocolV1'; + +export class TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { + constructor( + atomexNetwork: AtomexNetwork, + protected readonly atomexProtocolOptions: DeepReadonly, + atomexBlockchainProvider: AtomexBlockchainProvider, + walletsManager: WalletsManager + ) { + super('tezos', atomexNetwork, atomexProtocolOptions, atomexBlockchainProvider, walletsManager); + } + + get currencyId() { + return this.atomexProtocolOptions.currencyId; + } + + initiate(_params: AtomexProtocolV1InitiateParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedInitiateFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + redeem(_params: AtomexProtocolV1RedeemParameters): Promise { + throw new Error('Method not implemented.'); + } + + getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRedeemFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } + + refund(_params: AtomexProtocolV1RefundParameters): Promise { + throw new Error('Method not implemented.'); + } + + getEstimatedRefundFees(_params: Partial): Promise { + throw new Error('Method not implemented.'); + } +} diff --git a/src/tezos/config/atomexProtocol/base.ts b/src/tezos/config/atomexProtocol/base.ts new file mode 100644 index 00000000..531691ae --- /dev/null +++ b/src/tezos/config/atomexProtocol/base.ts @@ -0,0 +1,90 @@ + +import type { FA12TezosTaquitoAtomexProtocolV1Options, FA2TezosTaquitoAtomexProtocolV1Options } from '../../models/index'; + +export const mainnetFA12TezosTaquitoAtomexProtocolV1OptionsBase: Omit< + FA12TezosTaquitoAtomexProtocolV1Options, + 'currencyId' | 'swapContractAddress' | 'swapContractBlockId' +> = { + atomexProtocolVersion: 1, + initiateOperation: { + fee: 11000, + gasLimit: 110000, + storageLimit: 350, + }, + redeemOperation: { + fee: 11000, + gasLimit: 15000, + storageLimit: 257 + }, + refundOperation: { + fee: 11000, + gasLimit: 110000, + storageLimit: 257, + } +}; + +export const mainnetFA2TezosTaquitoAtomexProtocolV1OptionsBase: Omit< + FA2TezosTaquitoAtomexProtocolV1Options, + 'currencyId' | 'swapContractAddress' | 'swapContractBlockId' +> = { + atomexProtocolVersion: 1, + initiateOperation: { + fee: 350000, + gasLimit: 400000, + storageLimit: 250, + }, + redeemOperation: { + fee: 120000, + gasLimit: 400000, + storageLimit: 257 + }, + refundOperation: { + fee: 120000, + gasLimit: 400000, + storageLimit: 257, + } +}; + +export const testnetFA12TezosTaquitoAtomexProtocolV1OptionsBase: Omit< + FA12TezosTaquitoAtomexProtocolV1Options, + 'currencyId' | 'swapContractAddress' | 'swapContractBlockId' +> = { + atomexProtocolVersion: 1, + initiateOperation: { + fee: 2000, + gasLimit: 15000, + storageLimit: 350, + }, + redeemOperation: { + fee: 2500, + gasLimit: 20000, + storageLimit: 257 + }, + refundOperation: { + fee: 2500, + gasLimit: 15000, + storageLimit: 257, + } +}; + +export const testnetFA2TezosTaquitoAtomexProtocolV1OptionsBase: Omit< + FA2TezosTaquitoAtomexProtocolV1Options, + 'currencyId' | 'swapContractAddress' | 'swapContractBlockId' +> = { + atomexProtocolVersion: 1, + initiateOperation: { + fee: 350000, + gasLimit: 400000, + storageLimit: 250, + }, + redeemOperation: { + fee: 120000, + gasLimit: 400000, + storageLimit: 257 + }, + refundOperation: { + fee: 120000, + gasLimit: 400000, + storageLimit: 257, + } +}; diff --git a/src/tezos/config/atomexProtocol/index.ts b/src/tezos/config/atomexProtocol/index.ts new file mode 100644 index 00000000..e8c8c160 --- /dev/null +++ b/src/tezos/config/atomexProtocol/index.ts @@ -0,0 +1,2 @@ +export { mainnetTezosTaquitoAtomexProtocolV1Options } from './mainnetV1Options'; +export { testnetTezosTaquitoAtomexProtocolV1Options } from './testnetV1Options'; diff --git a/src/tezos/config/atomexProtocol/mainnetV1Options.ts b/src/tezos/config/atomexProtocol/mainnetV1Options.ts new file mode 100644 index 00000000..c5c5ccbf --- /dev/null +++ b/src/tezos/config/atomexProtocol/mainnetV1Options.ts @@ -0,0 +1,61 @@ +import type { FA12TezosTaquitoAtomexProtocolV1Options, FA2TezosTaquitoAtomexProtocolV1Options, TezosTaquitoAtomexProtocolV1Options } from '../../models/index'; +import { mainnetFA12TezosTaquitoAtomexProtocolV1OptionsBase, mainnetFA2TezosTaquitoAtomexProtocolV1OptionsBase } from './base'; + +const mainnetNativeTezosTaquitoAtomexProtocolV1Options: TezosTaquitoAtomexProtocolV1Options = { + atomexProtocolVersion: 1, + currencyId: 'XTZ', + swapContractAddress: 'KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL', + swapContractBlockId: '513046', + initiateOperation: { + fee: 2000, + gasLimit: 11000, + storageLimit: 257 + }, + redeemOperation: { + fee: 2000, + gasLimit: 15000, + storageLimit: 257 + }, + refundOperation: { + fee: 1600, + gasLimit: 13000, + storageLimit: 257, + } +}; + +const mainnetTZBTCTezosTaquitoAtomexProtocolV1Options: FA12TezosTaquitoAtomexProtocolV1Options = { + ...mainnetFA12TezosTaquitoAtomexProtocolV1OptionsBase, + currencyId: 'TZBTC', + swapContractAddress: 'KT1Ap287P1NzsnToSJdA4aqSNjPomRaHBZSr', + swapContractBlockId: '900350', + redeemOperation: { + ...mainnetFA12TezosTaquitoAtomexProtocolV1OptionsBase.redeemOperation, + gasLimit: 180000 + } +}; + +const mainnetKUSDTezosTaquitoAtomexProtocolV1Options: FA12TezosTaquitoAtomexProtocolV1Options = { + ...mainnetFA12TezosTaquitoAtomexProtocolV1OptionsBase, + currencyId: 'KUSD', + swapContractAddress: 'KT1EpQVwqLGSH7vMCWKJnq6Uxi851sEDbhWL', + swapContractBlockId: '1358868', + redeemOperation: { + ...mainnetFA12TezosTaquitoAtomexProtocolV1OptionsBase.redeemOperation, + gasLimit: 110000 + } +}; + + +const mainnetUSDtTezosTaquitoAtomexProtocolV1Options: FA2TezosTaquitoAtomexProtocolV1Options = { + ...mainnetFA2TezosTaquitoAtomexProtocolV1OptionsBase, + currencyId: 'USDT_XTZ', + swapContractAddress: 'KT1Ays1Chwx3ArnHGoQXchUgDsvKe9JboUjj', + swapContractBlockId: '2496680' +}; + +export const mainnetTezosTaquitoAtomexProtocolV1Options = { + XTZ: mainnetNativeTezosTaquitoAtomexProtocolV1Options, + TZBTC: mainnetTZBTCTezosTaquitoAtomexProtocolV1Options, + KUSD: mainnetKUSDTezosTaquitoAtomexProtocolV1Options, + USDT_XTZ: mainnetUSDtTezosTaquitoAtomexProtocolV1Options +} as const; diff --git a/src/tezos/config/atomexProtocol/testnetV1Options.ts b/src/tezos/config/atomexProtocol/testnetV1Options.ts new file mode 100644 index 00000000..4fb718d8 --- /dev/null +++ b/src/tezos/config/atomexProtocol/testnetV1Options.ts @@ -0,0 +1,37 @@ +import type { FA2TezosTaquitoAtomexProtocolV1Options, TezosTaquitoAtomexProtocolV1Options } from '../../models/index'; +import { testnetFA2TezosTaquitoAtomexProtocolV1OptionsBase } from './base'; + +const testnetNativeTezosTaquitoAtomexProtocolV1Options: TezosTaquitoAtomexProtocolV1Options = { + atomexProtocolVersion: 1, + currencyId: 'XTZ', + swapContractAddress: 'KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL', + swapContractBlockId: '513046', + initiateOperation: { + fee: 2000, + gasLimit: 11000, + storageLimit: 257 + }, + redeemOperation: { + fee: 2000, + gasLimit: 15000, + storageLimit: 257 + }, + refundOperation: { + fee: 1600, + gasLimit: 13000, + storageLimit: 257, + } +}; + + +const testnetUSDtTezosTaquitoAtomexProtocolV1Options: FA2TezosTaquitoAtomexProtocolV1Options = { + ...testnetFA2TezosTaquitoAtomexProtocolV1OptionsBase, + currencyId: 'USDT_XTZ', + swapContractAddress: 'KT1BWvRQnVVowZZLGkct9A7sdj5YEe8CdUhR', + swapContractBlockId: '665321' +}; + +export const testnetTezosTaquitoAtomexProtocolV1Options = { + XTZ: testnetNativeTezosTaquitoAtomexProtocolV1Options, + USDT_XTZ: testnetUSDtTezosTaquitoAtomexProtocolV1Options +} as const; diff --git a/src/tezos/config/currencies.ts b/src/tezos/config/currencies.ts index 11c4515a..e4d987eb 100644 --- a/src/tezos/config/currencies.ts +++ b/src/tezos/config/currencies.ts @@ -1,7 +1,6 @@ -import type { AtomexBlockchainNetworkOptions } from '../../atomex/models/atomexOptions'; -import type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from '../models/index'; +import type { NativeTezosCurrency, TezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from '../models/index'; -const tezosNativeCurrency: TezosCurrency = { +const nativeTezosCurrency: NativeTezosCurrency = { id: 'XTZ', name: 'Tezos', symbol: 'XTZ', @@ -10,7 +9,7 @@ const tezosNativeCurrency: TezosCurrency = { type: 'native' }; -const tzBtcCurrency: TezosFA12Currency = { +const tzBtcCurrency: FA12TezosCurrency = { id: 'TZBTC', name: 'tzBTC', symbol: 'tzBTC', @@ -20,7 +19,17 @@ const tzBtcCurrency: TezosFA12Currency = { decimals: 8, }; -const usdtCurrency: TezosFA2Currency = { +const kusdCurrency: FA12TezosCurrency = { + id: 'KUSD', + name: 'Kolibri USD', + symbol: 'kUSD', + blockchain: 'tezos', + type: 'fa1.2', + contractAddress: 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV', + decimals: 18 +}; + +const usdtCurrency: FA2TezosCurrency = { id: 'USDT_XTZ', name: 'Tether USD', symbol: 'USDt', @@ -31,14 +40,15 @@ const usdtCurrency: TezosFA2Currency = { decimals: 6, }; -export const tezosMainnetCurrencies: AtomexBlockchainNetworkOptions['currencies'] = [ - tezosNativeCurrency, +export const tezosMainnetCurrencies: TezosCurrency[] = [ + nativeTezosCurrency, tzBtcCurrency, + kusdCurrency, usdtCurrency ]; -export const tezosTestnetCurrencies: AtomexBlockchainNetworkOptions['currencies'] = [ - tezosNativeCurrency, - ({ ...tzBtcCurrency, contractAddress: 'KT1DM4k79uSx5diQnwqDiF4XeA86aCBxBD35' } as TezosFA12Currency), - ({ ...usdtCurrency, contractAddress: 'KT1BWvRQnVVowZZLGkct9A7sdj5YEe8CdUhR' } as TezosFA2Currency) +export const tezosTestnetCurrencies: TezosCurrency[] = [ + nativeTezosCurrency, + ({ ...tzBtcCurrency, contractAddress: 'KT1DM4k79uSx5diQnwqDiF4XeA86aCBxBD35' } as FA12TezosCurrency), + ({ ...usdtCurrency, contractAddress: 'KT1BWvRQnVVowZZLGkct9A7sdj5YEe8CdUhR' } as FA2TezosCurrency) ]; diff --git a/src/tezos/config/defaultOptions.ts b/src/tezos/config/defaultOptions.ts index 057a59ec..624525e4 100644 --- a/src/tezos/config/defaultOptions.ts +++ b/src/tezos/config/defaultOptions.ts @@ -1,10 +1,76 @@ -import type { AtomexBlockchainOptions } from '../../atomex/models/index'; +import type { AtomexContext, AtomexBlockchainOptions, AtomexCurrencyOptions } from '../../atomex/index'; +import { FA12TezosTaquitoAtomexProtocolV1, FA2TezosTaquitoAtomexProtocolV1, TezosTaquitoAtomexProtocolV1 } from '../atomexProtocol'; import { TezosBalancesProvider } from '../balancesProviders/index'; import { TaquitoBlockchainToolkitProvider } from '../blockchainToolkitProviders/index'; +import type { TezosCurrency } from '../models'; import { TezosSwapTransactionsProvider } from '../swapTransactionsProviders/index'; +import { mainnetTezosTaquitoAtomexProtocolV1Options, testnetTezosTaquitoAtomexProtocolV1Options } from './atomexProtocol'; import { tezosMainnetCurrencies, tezosTestnetCurrencies } from './currencies'; -export const createDefaultTezosBlockchainOptions = (): AtomexBlockchainOptions => { +type AtomexProtocolOptions = typeof mainnetTezosTaquitoAtomexProtocolV1Options | typeof testnetTezosTaquitoAtomexProtocolV1Options; + +const createAtomexProtocol = ( + atomexContext: AtomexContext, + currency: TezosCurrency, + atomexProtocolOptions: AtomexProtocolOptions[keyof AtomexProtocolOptions] +) => { + switch (currency.type) { + case 'native': + return new TezosTaquitoAtomexProtocolV1( + atomexContext.atomexNetwork, + atomexProtocolOptions, + atomexContext.providers.blockchainProvider, + atomexContext.managers.walletsManager + ); + case 'fa1.2': + return new FA12TezosTaquitoAtomexProtocolV1( + atomexContext.atomexNetwork, + atomexProtocolOptions, + atomexContext.providers.blockchainProvider, + atomexContext.managers.walletsManager + ); + case 'fa2': + return new FA2TezosTaquitoAtomexProtocolV1( + atomexContext.atomexNetwork, + atomexProtocolOptions, + atomexContext.providers.blockchainProvider, + atomexContext.managers.walletsManager + ); + default: + throw new Error(`Unknown Tezos currency: ${(currency as TezosCurrency).id}`); + } + +}; + +const createCurrencyOptions = ( + atomexContext: AtomexContext, + currencies: TezosCurrency[], + atomexProtocolOptions: AtomexProtocolOptions +): Record => { + const result: Record = {}; + const currenciesMap = currencies.reduce>( + (obj, currency) => { + obj[currency.id] = currency; + + return obj; + }, + {} + ); + + for (const options of Object.values(atomexProtocolOptions)) { + const currency = currenciesMap[options.currencyId]; + if (!currency) + throw new Error(`The ${options.currencyId} currency not found`); + + result[currency.id] = { + atomexProtocol: createAtomexProtocol(atomexContext, currency, options) + }; + } + + return result; +}; + +export const createDefaultTezosBlockchainOptions = (atomexContext: AtomexContext): AtomexBlockchainOptions => { const mainnetRpcUrl = 'https://rpc.tzkt.io/mainnet/'; const testNetRpcUrl = 'https://rpc.tzkt.io/ithacanet/'; const balancesProvider = new TezosBalancesProvider(); @@ -14,7 +80,7 @@ export const createDefaultTezosBlockchainOptions = (): AtomexBlockchainOptions = mainnet: { rpcUrl: mainnetRpcUrl, currencies: tezosMainnetCurrencies, - currencyOptions: {}, + currencyOptions: createCurrencyOptions(atomexContext, tezosMainnetCurrencies, mainnetTezosTaquitoAtomexProtocolV1Options), blockchainToolkitProvider: new TaquitoBlockchainToolkitProvider(mainnetRpcUrl), balancesProvider, swapTransactionsProvider, @@ -22,7 +88,7 @@ export const createDefaultTezosBlockchainOptions = (): AtomexBlockchainOptions = testnet: { rpcUrl: testNetRpcUrl, currencies: tezosTestnetCurrencies, - currencyOptions: {}, + currencyOptions: createCurrencyOptions(atomexContext, tezosTestnetCurrencies, testnetTezosTaquitoAtomexProtocolV1Options), blockchainToolkitProvider: new TaquitoBlockchainToolkitProvider(testNetRpcUrl), balancesProvider, swapTransactionsProvider, diff --git a/src/tezos/config/index.ts b/src/tezos/config/index.ts index d80101f5..dda2d93d 100644 --- a/src/tezos/config/index.ts +++ b/src/tezos/config/index.ts @@ -1,2 +1,3 @@ export { tezosMainnetCurrencies, tezosTestnetCurrencies } from './currencies'; export { createDefaultTezosBlockchainOptions } from './defaultOptions'; +export { mainnetTezosTaquitoAtomexProtocolV1Options } from './atomexProtocol/index'; diff --git a/src/tezos/index.ts b/src/tezos/index.ts index 769eb879..4f73dbb1 100644 --- a/src/tezos/index.ts +++ b/src/tezos/index.ts @@ -1,6 +1,8 @@ export { TaquitoBlockchainWallet } from './wallets/index'; -export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './models/index'; -export { tezosMainnetCurrencies, tezosTestnetCurrencies, createDefaultTezosBlockchainOptions } from './config/index'; +export { TezosTaquitoAtomexProtocolV1, FA12TezosTaquitoAtomexProtocolV1, FA2TezosTaquitoAtomexProtocolV1 } from './atomexProtocol/index'; export { TezosBalancesProvider } from './balancesProviders'; export { TezosSwapTransactionsProvider } from './swapTransactionsProviders'; export { TaquitoBlockchainToolkitProvider } from './blockchainToolkitProviders'; +export { tezosMainnetCurrencies, tezosTestnetCurrencies, createDefaultTezosBlockchainOptions } from './config/index'; + +export type { TezosCurrency, NativeTezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from './models/index'; diff --git a/src/tezos/models/atomexProtocolOptions.ts b/src/tezos/models/atomexProtocolOptions.ts new file mode 100644 index 00000000..0a888cb0 --- /dev/null +++ b/src/tezos/models/atomexProtocolOptions.ts @@ -0,0 +1,24 @@ +import type { AtomexProtocolV1Options } from '../../blockchain/index'; + +export interface TaquitoAtomexProtocolV1Options extends AtomexProtocolV1Options { + initiateOperation: { + fee: number; + gasLimit: number; + storageLimit: number; + }; + redeemOperation: { + fee: number; + gasLimit: number; + storageLimit: number; + }; + refundOperation: { + fee: number; + gasLimit: number; + storageLimit: number; + }; +} + +export type TezosTaquitoAtomexProtocolV1Options = TaquitoAtomexProtocolV1Options; + +export type FA12TezosTaquitoAtomexProtocolV1Options = TezosTaquitoAtomexProtocolV1Options; +export type FA2TezosTaquitoAtomexProtocolV1Options = TezosTaquitoAtomexProtocolV1Options; diff --git a/src/tezos/models/currency.ts b/src/tezos/models/currency.ts index 4b6e302b..6c570333 100644 --- a/src/tezos/models/currency.ts +++ b/src/tezos/models/currency.ts @@ -1,6 +1,6 @@ import type { Currency } from '../../common/index'; -export interface TezosCurrency extends Currency { +export interface NativeTezosCurrency extends Currency { readonly name: 'Tezos'; readonly symbol: 'XTZ'; readonly blockchain: 'tezos'; @@ -8,15 +8,20 @@ export interface TezosCurrency extends Currency { readonly decimals: 6; } -export interface TezosFA12Currency extends Currency { +export interface FA12TezosCurrency extends Currency { readonly blockchain: 'tezos'; readonly type: 'fa1.2'; readonly contractAddress: string; } -export interface TezosFA2Currency extends Currency { +export interface FA2TezosCurrency extends Currency { readonly blockchain: 'tezos'; readonly type: 'fa2'; readonly contractAddress: string; readonly tokenId: number; } + +export type TezosCurrency = + | NativeTezosCurrency + | FA12TezosCurrency + | FA2TezosCurrency; diff --git a/src/tezos/models/index.ts b/src/tezos/models/index.ts index dfb9bbef..89918dd7 100644 --- a/src/tezos/models/index.ts +++ b/src/tezos/models/index.ts @@ -1,4 +1,8 @@ export { TezosAtomexSigningDataType } from './tezosAtomexSigningDataType'; export type { SigPrefix } from './sigPrefix'; -export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './currency'; +export type { TezosCurrency, NativeTezosCurrency, FA12TezosCurrency, FA2TezosCurrency } from './currency'; +export type { + TaquitoAtomexProtocolV1Options, TezosTaquitoAtomexProtocolV1Options, + FA12TezosTaquitoAtomexProtocolV1Options, FA2TezosTaquitoAtomexProtocolV1Options +} from './atomexProtocolOptions'; diff --git a/tests/blockchain/atomexBlockchainProvider.test.ts b/tests/blockchain/atomexBlockchainProvider.test.ts index 64cb846c..85ad54d1 100644 --- a/tests/blockchain/atomexBlockchainProvider.test.ts +++ b/tests/blockchain/atomexBlockchainProvider.test.ts @@ -20,7 +20,7 @@ describe('Atomex Blockchain Provider', () => { }; const tezosNativeCurrencyOptions: AtomexCurrencyOptions = { - atomexProtocol: { network: 'mainnet', version: 1 } + atomexProtocol: { atomexNetwork: 'mainnet', version: 1 } }; const ethereumNativeCurrency: Currency = { diff --git a/tests/testHelpers/testCurrenciesProvider.ts b/tests/testHelpers/testCurrenciesProvider.ts index 403efa04..74c3da54 100644 --- a/tests/testHelpers/testCurrenciesProvider.ts +++ b/tests/testHelpers/testCurrenciesProvider.ts @@ -1,7 +1,7 @@ import { InMemoryCurrenciesProvider } from '../../src/common/index'; import { ethereumMainnetCurrencies } from '../../src/ethereum/index'; import type { ERC20EthereumCurrency } from '../../src/ethereum/models/index'; -import type { Currency, TezosFA12Currency } from '../../src/index'; +import type { Currency, FA12TezosCurrency } from '../../src/index'; import { tezosMainnetCurrencies } from '../../src/tezos/index'; const btcCurrency: Currency = { @@ -22,7 +22,7 @@ const ltcCurrency: Currency = { decimals: 8, }; -const kusdCurrency: TezosFA12Currency = { +const kusdCurrency: FA12TezosCurrency = { id: 'KUSD', name: 'Kolibri USD', blockchain: 'tezos',