diff --git a/packages/asset-service/package.json b/packages/asset-service/package.json index fe70f3f88..d0d4a4eb6 100644 --- a/packages/asset-service/package.json +++ b/packages/asset-service/package.json @@ -22,7 +22,8 @@ "type-check": "tsc --project ./tsconfig.json --noEmit" }, "dependencies": { - "lodash": "^4.17.21" + "lodash": "^4.17.21", + "@shapeshiftoss/types": "^1.0.0" }, "devDependencies": { "@types/lodash": "^4.14.172" diff --git a/packages/asset-service/src/generateAssetData/baseAssets.ts b/packages/asset-service/src/generateAssetData/baseAssets.ts index f38f72000..c4acff073 100644 --- a/packages/asset-service/src/generateAssetData/baseAssets.ts +++ b/packages/asset-service/src/generateAssetData/baseAssets.ts @@ -1,4 +1,4 @@ -import { BaseAsset, ContractTypes, NetworkTypes, ChainTypes } from '../types' +import { BaseAsset, ContractTypes, NetworkTypes, ChainTypes } from '@shapeshiftoss/types' export const baseAssets: Array = [ { diff --git a/packages/asset-service/src/generateAssetData/ethTokens/index.ts b/packages/asset-service/src/generateAssetData/ethTokens/index.ts index 7160e7aab..49ce51997 100644 --- a/packages/asset-service/src/generateAssetData/ethTokens/index.ts +++ b/packages/asset-service/src/generateAssetData/ethTokens/index.ts @@ -1,5 +1,5 @@ import axios from 'axios' -import { ContractTypes, TokenAsset } from '../../types' +import { ContractTypes, TokenAsset } from '@shapeshiftoss/types' import lodash from 'lodash' import { tokensToOverride } from './overrides' diff --git a/packages/asset-service/src/generateAssetData/ethTokens/overrides.ts b/packages/asset-service/src/generateAssetData/ethTokens/overrides.ts index 0ee824617..3d9f94f8e 100644 --- a/packages/asset-service/src/generateAssetData/ethTokens/overrides.ts +++ b/packages/asset-service/src/generateAssetData/ethTokens/overrides.ts @@ -1,4 +1,4 @@ -import { TokenAsset, ContractTypes } from '../../types' +import { TokenAsset, ContractTypes } from '@shapeshiftoss/types' export const tokensToOverride: Array = [ // example overriding FOX token with custom values instead of goingecko diff --git a/packages/asset-service/src/generateAssetData/generateAssetData.ts b/packages/asset-service/src/generateAssetData/generateAssetData.ts index ec6f2ffd6..b17093ea8 100644 --- a/packages/asset-service/src/generateAssetData/generateAssetData.ts +++ b/packages/asset-service/src/generateAssetData/generateAssetData.ts @@ -1,8 +1,7 @@ import fs from 'fs' import { baseAssets } from './baseAssets' import { getTokens } from './ethTokens' -import { BaseAsset, NetworkTypes } from '../types' -import { ChainTypes } from '..' +import { BaseAsset, ChainTypes, NetworkTypes } from '@shapeshiftoss/types' const generateAssetData = async () => { const generatedAssetData = await Promise.all( diff --git a/packages/asset-service/src/index.ts b/packages/asset-service/src/index.ts index 8f2cb696c..eff96ece1 100644 --- a/packages/asset-service/src/index.ts +++ b/packages/asset-service/src/index.ts @@ -1,2 +1 @@ -export * from './types' export * from './service/AssetService' diff --git a/packages/asset-service/src/service/AssetService.test.ts b/packages/asset-service/src/service/AssetService.test.ts index 94fdb09e6..6df68b92f 100644 --- a/packages/asset-service/src/service/AssetService.test.ts +++ b/packages/asset-service/src/service/AssetService.test.ts @@ -1,5 +1,5 @@ import axios from 'axios' -import { Asset, ChainTypes, NetworkTypes } from '../types' +import { Asset, ChainTypes, NetworkTypes } from '@shapeshiftoss/types' import { AssetService, flattenAssetData, indexAssetData } from './AssetService' import { mockBaseAssets, mockAssets, mockIndexedAssetData } from './AssetServiceTestData' diff --git a/packages/asset-service/src/service/AssetService.ts b/packages/asset-service/src/service/AssetService.ts index 0c4abb4ca..6541e08b9 100644 --- a/packages/asset-service/src/service/AssetService.ts +++ b/packages/asset-service/src/service/AssetService.ts @@ -1,4 +1,4 @@ -import { BaseAsset, Asset, NetworkTypes, ChainTypes } from '../types' +import { BaseAsset, Asset, NetworkTypes, ChainTypes } from '@shapeshiftoss/types' import axios from 'axios' import localAssetData from './generatedAssetData.json' diff --git a/packages/asset-service/src/service/AssetServiceTestData.ts b/packages/asset-service/src/service/AssetServiceTestData.ts index a67349f80..c757de5e3 100644 --- a/packages/asset-service/src/service/AssetServiceTestData.ts +++ b/packages/asset-service/src/service/AssetServiceTestData.ts @@ -1,5 +1,5 @@ import { IndexedAssetData } from '..' -import { Asset, BaseAsset, ChainTypes, ContractTypes, NetworkTypes } from '../types' +import { Asset, BaseAsset, ChainTypes, ContractTypes, NetworkTypes } from '@shapeshiftoss/types' export const mockBaseAssets: BaseAsset[] = [ { diff --git a/packages/asset-service/src/types.ts b/packages/asset-service/src/types.ts deleted file mode 100644 index db9785642..000000000 --- a/packages/asset-service/src/types.ts +++ /dev/null @@ -1,44 +0,0 @@ -type AbstractAsset = { - chain: ChainTypes - network: NetworkTypes - symbol: string - name: string - precision: number - slip44: number - color: string - secondaryColor: string - icon: string - explorer: string - explorerTxLink: string - sendSupport: boolean - receiveSupport: boolean -} - -type OmittedTokenAssetFields = 'chain' | 'network' | 'slip44' | 'explorer' | 'explorerTxLink' -type TokenAssetFields = { - tokenId: string - contractType: ContractTypes -} -export type TokenAsset = Omit & TokenAssetFields -export type BaseAsset = AbstractAsset & { tokens?: TokenAsset[] } -export type Asset = AbstractAsset & Partial - -export enum ContractTypes { - ERC20 = 'ERC20', - ERC721 = 'ERC721', - OTHER = 'OTHER', - NONE = 'NONE' -} - -export enum ChainTypes { - Ethereum = 'ethereum', - Bitcoin = 'bitcoin', - Litecoin = 'litecoin' -} - -export enum NetworkTypes { - MAINNET = 'MAINNET', - TESTNET = 'TESTNET', // BTC, lTC, etc... - ETH_ROPSTEN = 'ETH_ROPSTEN', - ETH_RINKEBY = 'ETH_RINKEBY' -} diff --git a/packages/chain-adapters/package.json b/packages/chain-adapters/package.json index bc6217e1e..756dc0b24 100644 --- a/packages/chain-adapters/package.json +++ b/packages/chain-adapters/package.json @@ -24,6 +24,7 @@ "dependencies": { "@shapeshiftoss/hdwallet-core": "^1.15.5-alpha.0", "@shapeshiftoss/hdwallet-native": "^1.15.5-alpha.1", + "@shapeshiftoss/types": "^1.0.0", "axios": "^0.21.1", "bignumber.js": "^9.0.1", "ethers": "^5.4.4", diff --git a/packages/chain-adapters/src/ChainAdapterCLI.ts b/packages/chain-adapters/src/ChainAdapterCLI.ts index 326f40e60..519122d34 100644 --- a/packages/chain-adapters/src/ChainAdapterCLI.ts +++ b/packages/chain-adapters/src/ChainAdapterCLI.ts @@ -1,5 +1,5 @@ import { ChainAdapterManager } from './ChainAdapterManager' -import { ChainIdentifier } from '.' +import { ChainTypes } from '@shapeshiftoss/types' import { NativeAdapterArgs, NativeHDWallet } from '@shapeshiftoss/hdwallet-native' import { HDWallet } from '@shapeshiftoss/hdwallet-core' import dotenv from 'dotenv' @@ -20,14 +20,14 @@ const getWallet = async (): Promise => { } const unchainedUrls = { - [ChainIdentifier.Ethereum]: 'http://localhost:31300/api/v1' + [ChainTypes.Ethereum]: 'http://localhost:31300/api/v1' } const main = async () => { try { const chainAdapterManager = new ChainAdapterManager(unchainedUrls) const wallet = await getWallet() - const ethChainAdapter = chainAdapterManager.byChain(ChainIdentifier.Ethereum) + const ethChainAdapter = chainAdapterManager.byChain(ChainTypes.Ethereum) const address = await ethChainAdapter.getAddress({ wallet, path: defaultEthPath }) const balanceInfo = await ethChainAdapter.getBalance(address) diff --git a/packages/chain-adapters/src/ChainAdapterManager.test.ts b/packages/chain-adapters/src/ChainAdapterManager.test.ts index 2617a8e99..1c59b5097 100644 --- a/packages/chain-adapters/src/ChainAdapterManager.test.ts +++ b/packages/chain-adapters/src/ChainAdapterManager.test.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ -import { ChainIdentifier } from './api' +import { ChainTypes } from '@shapeshiftoss/types' import { ChainAdapterManager } from './ChainAdapterManager' import { EthereumChainAdapter } from './ethereum' @@ -40,7 +40,7 @@ describe('ChainAdapterManager', () => { it('should add a network', () => { expect( // @ts-ignore - getCAM().addChain(ChainIdentifier.Ethereum, () => new EthereumChainAdapter()) + getCAM().addChain(ChainTypes.Ethereum, () => new EthereumChainAdapter()) ).toBeUndefined() }) }) @@ -54,8 +54,8 @@ describe('ChainAdapterManager', () => { it('should get an adapter factory', () => { const cam = getCAM() - const adapter = cam.byChain(ChainIdentifier.Ethereum) - const adapter2 = cam.byChain(ChainIdentifier.Ethereum) + const adapter = cam.byChain(ChainTypes.Ethereum) + const adapter2 = cam.byChain(ChainTypes.Ethereum) // @ts-ignore expect(adapter).toBeInstanceOf(EthereumChainAdapter) expect(adapter2).toBe(adapter) @@ -64,7 +64,7 @@ describe('ChainAdapterManager', () => { describe('getSupportedChains', () => { it('should return array of keys', () => { - expect(getCAM().getSupportedChains()).toStrictEqual([ChainIdentifier.Ethereum]) + expect(getCAM().getSupportedChains()).toStrictEqual([ChainTypes.Ethereum]) }) }) diff --git a/packages/chain-adapters/src/ChainAdapterManager.ts b/packages/chain-adapters/src/ChainAdapterManager.ts index b8b47f2a3..e05d67dd9 100644 --- a/packages/chain-adapters/src/ChainAdapterManager.ts +++ b/packages/chain-adapters/src/ChainAdapterManager.ts @@ -1,26 +1,33 @@ -import { ChainAdapter, ChainIdentifier } from './api' +import { ChainAdapter } from './api' +import { ChainTypes } from '@shapeshiftoss/types' import { EthereumChainAdapter } from './ethereum' import { UnchainedProvider } from './providers' -export type UnchainedUrls = Record +export type UnchainedUrls = Record const chainAdapterMap = { - [ChainIdentifier.Ethereum]: EthereumChainAdapter + [ChainTypes.Ethereum]: EthereumChainAdapter } as const export class ChainAdapterManager { - private supported: Map ChainAdapter> = new Map() + private supported: Map ChainAdapter> = new Map() private instances: Map = new Map() constructor(unchainedUrls: UnchainedUrls) { if (!unchainedUrls) { throw new Error('Blockchain urls required') } - ;(Object.keys(unchainedUrls) as Array).forEach((key: ChainIdentifier) => { - const Adapter = chainAdapterMap[key] - if (!Adapter) throw new Error(`No chain adapter for ${key}`) - this.addChain(key, () => new Adapter({ provider: new UnchainedProvider(unchainedUrls[key]) })) - }) + // TODO(0xdef1cafe): loosen this from ChainTypes.Ethereum to ChainTypes once we implement more than ethereum + ;(Object.keys(unchainedUrls) as Array).forEach( + (key: ChainTypes.Ethereum) => { + const Adapter = chainAdapterMap[key] + if (!Adapter) throw new Error(`No chain adapter for ${key}`) + this.addChain( + key, + () => new Adapter({ provider: new UnchainedProvider(unchainedUrls[key]) }) + ) + } + ) } /** @@ -30,17 +37,17 @@ export class ChainAdapterManager { * import { ChainAdapterManager, UtxoChainAdapter } from 'chain-adapters' * const manager = new ChainAdapterManager(client) * manager.addChain('bitcoin', () => new UtxoChainAdapter('BTG', client)) - * @param {ChainIdentifier} network - Coin/network symbol from Asset query + * @param {ChainTypes} network - Coin/network symbol from Asset query * @param {Function} factory - A function that returns a ChainAdapter instance */ - addChain(chain: ChainIdentifier, factory: () => ChainAdapter): void { + addChain(chain: ChainTypes, factory: () => ChainAdapter): void { if (typeof chain !== 'string' || typeof factory !== 'function') { throw new Error('Parameter validation error') } this.supported.set(chain, factory) } - getSupportedChains(): Array { + getSupportedChains(): Array { return Array.from(this.supported.keys()) } @@ -49,7 +56,7 @@ export class ChainAdapterManager { } /*** Get a ChainAdapter instance for a network */ - byChain(chain: ChainIdentifier): ChainAdapter { + byChain(chain: ChainTypes): ChainAdapter { let adapter = this.instances.get(chain) if (!adapter) { const factory = this.supported.get(chain) diff --git a/packages/chain-adapters/src/api.ts b/packages/chain-adapters/src/api.ts index 9c534b34c..7427795d6 100644 --- a/packages/chain-adapters/src/api.ts +++ b/packages/chain-adapters/src/api.ts @@ -1,135 +1,22 @@ import { Params } from './types/Params.type' -import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core' - -export type Transaction = { - network: string - symbol: string - txid: string - status: string - from: string - to: string - blockHash: string - blockHeight: number - confirmations: number - timestamp: number - value: string - fee: string -} - -export type TxHistoryResponse = { - page: number - totalPages: number - txs: number - transactions: Transaction[] -} - -export type Token = { - type: string - name: string - path?: string - contract?: string - transfers: number - symbol?: string - decimals?: number - balance?: string - totalReceived?: string - totalSent?: string -} - -export type BalanceResponse = { - network: string - symbol: string - address: string - balance: string - unconfirmedBalance: string - unconfirmedTxs: number - txs: number - tokens: Token[] -} - -export type BroadcastTxResponse = { - network: string - txid: string -} - -export type BuildSendTxInput = { - to: string - value: string - wallet: HDWallet - path: string - /*** In base units */ - fee?: string - /*** Optional param for eth txs indicating what ERC20 is being sent */ - erc20ContractAddress?: string - limit?: string -} - -export type SignTxInput = { - txToSign: ETHSignTx - wallet: HDWallet -} -export type GetAddressInput = { - wallet: HDWallet - path: string -} - -export type GetFeeDataInput = { - contractAddress?: string - from: string - to: string - value: string -} - -export enum FeeDataKey { - Slow = 'slow', - Average = 'average', - Fast = 'fast' -} - -export type FeeDataType = { - feeUnitPrice: string - networkFee: string - feeUnits: string -} - -export type FeeData = { - [FeeDataKey.Slow]: FeeDataType - [FeeDataKey.Average]: FeeDataType - [FeeDataKey.Fast]: FeeDataType -} - -export enum ChainIdentifier { - Ethereum = 'ethereum' -} - -export enum ValidAddressResultType { - Valid = 'valid', - Invalid = 'invalid' -} - -export type ValidAddressResult = { - /** - * Is this Address valid - */ - valid: boolean - /** - * Result type of valid address - */ - result: ValidAddressResultType -} - -export type FeeEstimateInput = { - to: string - from: string - data: string - value: string -} +import { ETHSignTx } from '@shapeshiftoss/hdwallet-core' +import { + BalanceResponse, + BuildSendTxInput, + ChainTypes, + FeeDataEstimate, + GetAddressInput, + GetFeeDataInput, + SignTxInput, + TxHistoryResponse, + ValidAddressResult +} from '@shapeshiftoss/types' export interface ChainAdapter { /** * Get type of adapter */ - getType(): ChainIdentifier + getType(): ChainTypes /** * Get the balance of an address @@ -143,13 +30,13 @@ export interface ChainAdapter { buildSendTransaction( input: BuildSendTxInput - ): Promise<{ txToSign: ETHSignTx; estimatedFees: FeeData }> + ): Promise<{ txToSign: ETHSignTx; estimatedFees: FeeDataEstimate }> getAddress(input: GetAddressInput): Promise signTransaction(signTxInput: SignTxInput): Promise - getFeeData(input: Partial): Promise + getFeeData(input: Partial): Promise broadcastTransaction(hex: string): Promise diff --git a/packages/chain-adapters/src/ethereum/EthereumChainAdapter.ts b/packages/chain-adapters/src/ethereum/EthereumChainAdapter.ts index 69971efc1..dba55be9b 100644 --- a/packages/chain-adapters/src/ethereum/EthereumChainAdapter.ts +++ b/packages/chain-adapters/src/ethereum/EthereumChainAdapter.ts @@ -1,26 +1,27 @@ +import WAValidator from 'multicoin-address-validator' +import axios from 'axios' +import BigNumber from 'bignumber.js' +import { bip32ToAddressNList, ETHSignTx, ETHWallet } from '@shapeshiftoss/hdwallet-core' +import { numberToHex } from 'web3-utils' +import { Contract } from '@ethersproject/contracts' import { - ChainAdapter, TxHistoryResponse, BuildSendTxInput, SignTxInput, GetAddressInput, GetFeeDataInput, - FeeData, BalanceResponse, - ChainIdentifier, + ChainTypes, ValidAddressResult, - ValidAddressResultType -} from '../api' + ValidAddressResultType, + FeeDataEstimate +} from '@shapeshiftoss/types' + import { BlockchainProvider } from '../types/BlockchainProvider.type' import { Params } from '../types/Params.type' import { ErrorHandler } from '../error/ErrorHandler' -import { bip32ToAddressNList, ETHSignTx, ETHWallet } from '@shapeshiftoss/hdwallet-core' -import { numberToHex } from 'web3-utils' -import { Contract } from '@ethersproject/contracts' import erc20Abi from './erc20Abi.json' -import WAValidator from 'multicoin-address-validator' -import axios from 'axios' -import BigNumber from 'bignumber.js' +import { ChainAdapter } from '..' export type EthereumChainAdapterDependencies = { provider: BlockchainProvider @@ -62,8 +63,8 @@ export class EthereumChainAdapter implements ChainAdapter { this.provider = deps.provider } - getType = (): ChainIdentifier => { - return ChainIdentifier.Ethereum + getType = (): ChainTypes => { + return ChainTypes.Ethereum } getBalance = async (address: string): Promise => { @@ -85,7 +86,7 @@ export class EthereumChainAdapter implements ChainAdapter { buildSendTransaction = async ( tx: BuildSendTxInput - ): Promise<{ txToSign: ETHSignTx; estimatedFees: FeeData }> => { + ): Promise<{ txToSign: ETHSignTx; estimatedFees: FeeDataEstimate }> => { try { const { to, erc20ContractAddress, path, wallet, fee, limit } = tx const value = erc20ContractAddress ? '0' : tx?.value @@ -145,7 +146,12 @@ export class EthereumChainAdapter implements ChainAdapter { return this.provider.broadcastTx(hex) } - getFeeData = async ({ to, from, contractAddress, value }: GetFeeDataInput): Promise => { + getFeeData = async ({ + to, + from, + contractAddress, + value + }: GetFeeDataInput): Promise => { const { data: responseData } = await axios.get('https://gas.api.0x.org/') const fees = responseData.result.find((result) => result.source === 'MEDIAN') diff --git a/packages/chain-adapters/src/providers/UnchainedProvider.ts b/packages/chain-adapters/src/providers/UnchainedProvider.ts index f3964480b..dae4f30c4 100644 --- a/packages/chain-adapters/src/providers/UnchainedProvider.ts +++ b/packages/chain-adapters/src/providers/UnchainedProvider.ts @@ -1,7 +1,12 @@ import axios, { AxiosInstance } from 'axios' import { Params } from '../types/Params.type' import { BlockchainProvider } from '../types/BlockchainProvider.type' -import { TxHistoryResponse, BalanceResponse, BroadcastTxResponse, FeeEstimateInput } from '..' +import { + TxHistoryResponse, + BalanceResponse, + BroadcastTxResponse, + FeeEstimateInput +} from '@shapeshiftoss/types' import https from 'https' const axiosClient = (baseURL: string) => diff --git a/packages/chain-adapters/src/types/BlockchainProvider.type.ts b/packages/chain-adapters/src/types/BlockchainProvider.type.ts index 0d1e3d8ce..0d4f36c13 100644 --- a/packages/chain-adapters/src/types/BlockchainProvider.type.ts +++ b/packages/chain-adapters/src/types/BlockchainProvider.type.ts @@ -1,5 +1,5 @@ import { Params } from './Params.type' -import { TxHistoryResponse, FeeEstimateInput, BalanceResponse } from '../api' +import { TxHistoryResponse, FeeEstimateInput, BalanceResponse } from '@shapeshiftoss/types' export interface BlockchainProvider { getBalance: (address: string) => Promise diff --git a/packages/market-service/package.json b/packages/market-service/package.json index 3f53f262c..bb0075834 100644 --- a/packages/market-service/package.json +++ b/packages/market-service/package.json @@ -1,7 +1,7 @@ { "name": "@shapeshiftoss/market-service", "version": "1.0.0", - "description": "Package to share reusable code", + "description": "ShapeShift market data service", "homepage": "", "license": "MIT", "main": "./dist/index.js", @@ -21,7 +21,7 @@ "type-check": "tsc --project ./tsconfig.json --noEmit" }, "dependencies": { - "@shapeshiftoss/asset-service": "^1.0.0", + "@shapeshiftoss/types": "^1.0.0", "axios": "^0.21.2", "dayjs": "^1.10.6" }, diff --git a/packages/market-service/src/api.ts b/packages/market-service/src/api.ts index 62a08b083..b7dba0fd6 100644 --- a/packages/market-service/src/api.ts +++ b/packages/market-service/src/api.ts @@ -1,49 +1,7 @@ -export enum ChainTypes { - Ethereum = 'ethereum', - Bitcoin = 'bitcoin', - Litecoin = 'litecoin' -} - -export type MarketData = { - price: string - marketCap: string - volume: string - changePercent24Hr: number -} - -export enum HistoryTimeframe { - HOUR = '1H', - DAY = '24H', - WEEK = '1W', - MONTH = '1M', - YEAR = '1Y', - ALL = 'All' -} - -export type HistoryData = { - price: number - date: string -} - -export type PriceHistoryArgs = { - chain: ChainTypes - timeframe: HistoryTimeframe - tokenId?: string -} - -export type MarketDataArgs = { - chain: ChainTypes - tokenId?: string -} - -export type MarketDataType = (args: MarketDataArgs) => Promise - -export type PriceHistoryType = (args: PriceHistoryArgs) => Promise +import { MarketDataType, PriceHistoryType } from '@shapeshiftoss/types' export interface MarketService { baseUrl: string - getMarketData: MarketDataType - getPriceHistory: PriceHistoryType } diff --git a/packages/market-service/src/coingecko/coingecko.test.ts b/packages/market-service/src/coingecko/coingecko.test.ts index 21dd824e8..bdd52b1e9 100644 --- a/packages/market-service/src/coingecko/coingecko.test.ts +++ b/packages/market-service/src/coingecko/coingecko.test.ts @@ -1,5 +1,6 @@ import axios from 'axios' -import { ChainTypes, getMarketData, getPriceHistory, HistoryTimeframe } from '..' +import { getMarketData, getPriceHistory } from '..' +import { ChainTypes, HistoryTimeframe } from '@shapeshiftoss/types' jest.mock('axios') diff --git a/packages/market-service/src/coingecko/coingecko.ts b/packages/market-service/src/coingecko/coingecko.ts index f9c4012d3..7751ce472 100644 --- a/packages/market-service/src/coingecko/coingecko.ts +++ b/packages/market-service/src/coingecko/coingecko.ts @@ -2,13 +2,14 @@ import axios from 'axios' import dayjs from 'dayjs' import { ChainTypes, - MarketService, MarketData, HistoryData, HistoryTimeframe, PriceHistoryArgs, MarketDataArgs -} from '../api' +} from '@shapeshiftoss/types' + +import { MarketService } from '../api' // tons more parms here: https://www.coingecko.com/en/api/documentation type CoinGeckoAssetData = { diff --git a/packages/market-service/src/index.ts b/packages/market-service/src/index.ts index e2a0dd748..44dc58e59 100644 --- a/packages/market-service/src/index.ts +++ b/packages/market-service/src/index.ts @@ -1,20 +1,25 @@ import { CoinGeckoMarketService } from './coingecko/coingecko' -import * as api from './api' +import { MarketService } from './api' +import { + HistoryData, + MarketDataArgs, + MarketDataType, + PriceHistoryArgs, + PriceHistoryType +} from '@shapeshiftoss/types' -export * from './api' - -export const getDefaultMarketService = (): api.MarketService => { +export const getDefaultMarketService = (): MarketService => { return new CoinGeckoMarketService() } -export const getMarketData: api.MarketDataType = async ({ chain, tokenId }: api.MarketDataArgs) => { +export const getMarketData: MarketDataType = async ({ chain, tokenId }: MarketDataArgs) => { return getDefaultMarketService().getMarketData({ chain, tokenId }) } -export const getPriceHistory: api.PriceHistoryType = ({ +export const getPriceHistory: PriceHistoryType = ({ chain, timeframe, tokenId -}: api.PriceHistoryArgs): Promise => { +}: PriceHistoryArgs): Promise => { return getDefaultMarketService().getPriceHistory({ chain, timeframe, tokenId }) } diff --git a/packages/swapper/package.json b/packages/swapper/package.json index 0c8a86e51..09443aeed 100644 --- a/packages/swapper/package.json +++ b/packages/swapper/package.json @@ -17,9 +17,9 @@ "type-check": "tsc --project ./tsconfig.json --noEmit" }, "dependencies": { - "@shapeshiftoss/asset-service": "^1.0.0", "@shapeshiftoss/chain-adapters": "^1.0.0", "@shapeshiftoss/hdwallet-core": "^1.16.2-alpha.0", + "@shapeshiftoss/types": "^1.0.0", "axios": "^0.21.4", "web3": "^1.5.2", "bignumber.js": "^9.0.1", diff --git a/packages/swapper/src/api.ts b/packages/swapper/src/api.ts index e91b06ac5..cc95674a9 100644 --- a/packages/swapper/src/api.ts +++ b/packages/swapper/src/api.ts @@ -1,96 +1,8 @@ -import { Asset } from '@shapeshiftoss/asset-service' import { HDWallet } from '@shapeshiftoss/hdwallet-core' - -export enum SwapperType { - Zrx = '0x', - Thorchain = 'Thorchain' -} +import { Asset, BuildQuoteTxArgs, GetQuoteInput, Quote, SwapperType } from '@shapeshiftoss/types' export class SwapError extends Error {} -export interface FeeData { - fee?: string - gas?: string - estimatedGas?: string - gasPrice?: string - approvalFee?: string - protocolFee?: string - minimumProtocolFee?: string - receiveNetworkFee?: string -} - -export type SwapSource = { - name: string - proportion: string -} - -export interface QuoteResponse { - price: string - guaranteedPrice: string - to: string - data?: string - value?: string - gas?: string - estimatedGas?: string - gasPrice?: string - protocolFee?: string - minimumProtocolFee?: string - buyTokenAddress?: string - sellTokenAddress?: string - buyAmount?: string - sellAmount?: string - allowanceTarget?: string - sources?: Array -} -export interface Quote { - success: boolean - statusCode?: number - statusReason?: string - sellAssetAccountId?: string - buyAssetAccountId?: string - sellAsset: Asset - buyAsset: Asset - rate?: string - depositAddress?: string // this is dex contract address for eth swaps - receiveAddress?: string - buyAmount?: string - sellAmount?: string - minimum?: string | null - maximum?: string | null - guaranteedPrice?: string - slipScore?: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - txData?: any // unsigned tx if available at quote time - value?: string - feeData?: FeeData - allowanceContract?: string - allowanceGrantRequired?: boolean - slippage?: string - priceImpact?: string - orderId?: string - sources?: Array - timestamp?: number -} - -export interface GetQuoteInput { - sellAsset: Asset - buyAsset: Asset - sellAmount?: string - buyAmount?: string - sellAssetAccountId?: string - buyAssetAccountId?: string - slippage?: string - priceImpact?: string - sendMax?: boolean - minimumPrice?: string - minimum?: string -} - -export type BuildQuoteTxArgs = { - input: GetQuoteInput - wallet: HDWallet -} - export interface Swapper { /** Returns the swapper type */ getType(): SwapperType diff --git a/packages/swapper/src/manager/SwapperManager.test.ts b/packages/swapper/src/manager/SwapperManager.test.ts index d8ce93125..dd5612478 100644 --- a/packages/swapper/src/manager/SwapperManager.test.ts +++ b/packages/swapper/src/manager/SwapperManager.test.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import Web3 from 'web3' -import { SwapperType } from '../api' import { ThorchainSwapper, ZrxSwapper } from '../swappers' import { SwapperManager } from './SwapperManager' import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters' +import { SwapperType } from '@shapeshiftoss/types' describe('SwapperManager', () => { const zrxSwapperDeps = { diff --git a/packages/swapper/src/manager/SwapperManager.ts b/packages/swapper/src/manager/SwapperManager.ts index 7823c8e3c..9e171da61 100644 --- a/packages/swapper/src/manager/SwapperManager.ts +++ b/packages/swapper/src/manager/SwapperManager.ts @@ -1,5 +1,5 @@ -import { GetQuoteInput, Swapper, SwapperType } from '..' -import { Quote } from '../api' +import { Swapper } from '..' +import { GetQuoteInput, Quote, SwapperType } from '@shapeshiftoss/types' export class SwapperError extends Error { constructor(message: string) { diff --git a/packages/swapper/src/swappers/thorchain/ThorchainSwapper.ts b/packages/swapper/src/swappers/thorchain/ThorchainSwapper.ts index 8870f8f60..5f9ad6aa4 100644 --- a/packages/swapper/src/swappers/thorchain/ThorchainSwapper.ts +++ b/packages/swapper/src/swappers/thorchain/ThorchainSwapper.ts @@ -1,5 +1,5 @@ -import { Asset } from '@shapeshiftoss/asset-service' -import { Swapper, SwapperType } from '../../api' +import { Asset, SwapperType } from '@shapeshiftoss/types' +import { Swapper } from '../../api' export class ThorchainSwapper implements Swapper { getType() { diff --git a/packages/swapper/src/swappers/zrx/ZrxSwapper.test.ts b/packages/swapper/src/swappers/zrx/ZrxSwapper.test.ts index e033400ba..a83d00057 100644 --- a/packages/swapper/src/swappers/zrx/ZrxSwapper.test.ts +++ b/packages/swapper/src/swappers/zrx/ZrxSwapper.test.ts @@ -1,9 +1,16 @@ import Web3 from 'web3' import { HDWallet } from '@shapeshiftoss/hdwallet-core' import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters' -import { ChainTypes, NetworkTypes, ContractTypes, Asset } from '@shapeshiftoss/asset-service' +import { + ChainTypes, + NetworkTypes, + ContractTypes, + Asset, + GetQuoteInput, + SwapperType +} from '@shapeshiftoss/types' import { ZrxSwapper } from '..' -import { GetQuoteInput, SwapperType, ZrxError } from '../..' +import { ZrxError } from '../..' import { DEFAULT_SLIPPAGE } from './utils/constants' import { buildQuoteTx } from '../zrx/buildQuoteTx/buildQuoteTx' import { getZrxQuote } from './getQuote/getQuote' @@ -16,7 +23,7 @@ jest.mock('./getQuote/getQuote', () => ({ getZrxQuote: jest.fn() })) -const BTC = ({ +const BTC = { name: 'bitcoin', chain: ChainTypes.Bitcoin, network: NetworkTypes.MAINNET, @@ -31,9 +38,8 @@ const BTC = ({ sendSupport: false, receiveSupport: false, symbol: 'BTC' - // TODO: remove the type casts from test files when we unify `ChainTypes` and `ChainIdentifier` -} as unknown) as Asset -const WETH = ({ +} +const WETH = { name: 'WETH', chain: ChainTypes.Ethereum, network: NetworkTypes.MAINNET, @@ -49,8 +55,8 @@ const WETH = ({ sendSupport: true, receiveSupport: true, symbol: 'WETH' -} as unknown) as Asset -const FOX = ({ +} +const FOX = { name: 'Fox', chain: ChainTypes.Ethereum, network: NetworkTypes.MAINNET, @@ -66,7 +72,7 @@ const FOX = ({ explorerTxLink: 'https://etherscan.io/tx/', receiveSupport: true, symbol: 'FOX' -} as unknown) as Asset +} const setupQuote = () => { const sellAmount = '1000000000000000000' diff --git a/packages/swapper/src/swappers/zrx/ZrxSwapper.ts b/packages/swapper/src/swappers/zrx/ZrxSwapper.ts index 6eba4ac0a..2268cec2b 100644 --- a/packages/swapper/src/swappers/zrx/ZrxSwapper.ts +++ b/packages/swapper/src/swappers/zrx/ZrxSwapper.ts @@ -1,7 +1,14 @@ import Web3 from 'web3' -import { Asset, ChainTypes } from '@shapeshiftoss/asset-service' +import { + Asset, + BuildQuoteTxArgs, + ChainTypes, + GetQuoteInput, + Quote, + SwapperType +} from '@shapeshiftoss/types' import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters' -import { BuildQuoteTxArgs, GetQuoteInput, Quote, Swapper, SwapperType } from '../../api' +import { Swapper } from '../../api' import { buildQuoteTx } from './buildQuoteTx/buildQuoteTx' import { getZrxQuote } from './getQuote/getQuote' diff --git a/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.test.ts b/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.test.ts index a93557a1a..90d4367a9 100644 --- a/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.test.ts +++ b/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.test.ts @@ -1,12 +1,12 @@ import BigNumber from 'bignumber.js' -import { ChainAdapterManager, ChainIdentifier } from '@shapeshiftoss/chain-adapters' +import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters' import { HDWallet } from '@shapeshiftoss/hdwallet-core' import Web3 from 'web3' import { buildQuoteTx } from './buildQuoteTx' import { setupQuote } from '../utils/test-data/setupSwapQuote' -import { GetQuoteInput } from '../../../api' import { zrxService } from '../utils/zrxService' import { APPROVAL_GAS_LIMIT, MAX_SLIPPAGE } from '../utils/constants' +import { ChainTypes, GetQuoteInput } from '@shapeshiftoss/types' jest.mock('web3') @@ -51,6 +51,7 @@ const mockQuoteResponse = { name: 'WETH', network: 'MAINNET', precision: 18, + slip44: 60, receiveSupport: true, secondaryColor: '#FFFFFF', sendSupport: true, @@ -70,7 +71,10 @@ const mockQuoteResponse = { color: '#FFFFFF', contractType: 'ERC20', icon: 'https://assets.coincap.io/assets/icons/fox@2x.png', - name: 'Fox', + name: 'FOX', + slip44: 60, + explorer: 'https://etherscan.io', + explorerTxLink: 'https://etherscan.io/tx/', network: 'MAINNET', precision: 18, receiveSupport: true, @@ -89,7 +93,7 @@ const mockQuoteResponse = { const setup = () => { const unchainedUrls = { - [ChainIdentifier.Ethereum]: 'http://localhost:31300/api/v1' + [ChainTypes.Ethereum]: 'http://localhost:31300/api/v1' } const ethNodeUrl = 'http://localhost:1000' const adapterManager = new ChainAdapterManager(unchainedUrls) diff --git a/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.ts b/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.ts index 973a796ae..0a0120dd7 100644 --- a/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.ts +++ b/packages/swapper/src/swappers/zrx/buildQuoteTx/buildQuoteTx.ts @@ -1,8 +1,9 @@ import BigNumber from 'bignumber.js' import { AxiosResponse } from 'axios' import * as rax from 'retry-axios' -import { ChainAdapter, ChainIdentifier } from '@shapeshiftoss/chain-adapters' -import { Quote, SwapError, BuildQuoteTxArgs } from '../../..' +import { ChainAdapter } from '@shapeshiftoss/chain-adapters' +import { SwapError } from '../../..' +import { ChainTypes, Quote, BuildQuoteTxArgs } from '@shapeshiftoss/types' import { ZrxSwapperDeps } from '../ZrxSwapper' import { applyAxiosRetry } from '../utils/applyAxiosRetry' import { erc20AllowanceAbi } from '../utils/abi/erc20-abi' @@ -81,10 +82,7 @@ export async function buildQuoteTx( ) } - // TODO: (ryankk) Remove the type cast when we unify ChainIdentifier and ChainTypes - const adapter: ChainAdapter = adapterManager.byChain( - (buyAsset.chain as unknown) as ChainIdentifier - ) + const adapter: ChainAdapter = adapterManager.byChain(buyAsset.chain) const receiveAddress = await adapter.getAddress({ wallet, path: DEFAULT_ETH_PATH }) if (new BigNumber(slippage || 0).gt(MAX_SLIPPAGE)) { diff --git a/packages/swapper/src/swappers/zrx/getQuote/getQuote.test.ts b/packages/swapper/src/swappers/zrx/getQuote/getQuote.test.ts index ffd59b415..005e7cf99 100644 --- a/packages/swapper/src/swappers/zrx/getQuote/getQuote.test.ts +++ b/packages/swapper/src/swappers/zrx/getQuote/getQuote.test.ts @@ -1,4 +1,4 @@ -import { ChainTypes, ContractTypes, NetworkTypes, Asset } from '@shapeshiftoss/asset-service' +import { ChainTypes, ContractTypes, NetworkTypes, Asset } from '@shapeshiftoss/types' import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters' import Web3 from 'web3' import BigNumber from 'bignumber.js' diff --git a/packages/swapper/src/swappers/zrx/getQuote/getQuote.ts b/packages/swapper/src/swappers/zrx/getQuote/getQuote.ts index 870c41de1..f80f7160a 100644 --- a/packages/swapper/src/swappers/zrx/getQuote/getQuote.ts +++ b/packages/swapper/src/swappers/zrx/getQuote/getQuote.ts @@ -1,7 +1,7 @@ -import { ChainTypes } from '@shapeshiftoss/asset-service' import { AxiosResponse } from 'axios' import BigNumber from 'bignumber.js' -import { GetQuoteInput, Quote, QuoteResponse, SwapSource } from '../../..' +import { ChainTypes, GetQuoteInput, Quote, QuoteResponse, SwapSource } from '@shapeshiftoss/types' + import { MAX_ZRX_TRADE, APPROVAL_GAS_LIMIT, DEFAULT_SOURCE } from '../utils/constants' import { zrxService } from '../utils/zrxService' import { normalizeAmount } from '../utils/helpers/helpers' diff --git a/packages/swapper/src/swappers/zrx/utils/helpers/helpers.ts b/packages/swapper/src/swappers/zrx/utils/helpers/helpers.ts index 1c2c02687..4ba4a477a 100644 --- a/packages/swapper/src/swappers/zrx/utils/helpers/helpers.ts +++ b/packages/swapper/src/swappers/zrx/utils/helpers/helpers.ts @@ -1,7 +1,8 @@ import BigNumber from 'bignumber.js' import { AbiItem } from 'web3-utils' import Web3 from 'web3' -import { Quote, SwapError } from '../../../../api' +import { SwapError } from '../../../../api' +import { Quote } from '@shapeshiftoss/types' export type GetAllowanceRequiredArgs = { quote: Quote diff --git a/packages/swapper/src/swappers/zrx/utils/test-data/setupSwapQuote.ts b/packages/swapper/src/swappers/zrx/utils/test-data/setupSwapQuote.ts index 62912ab72..b2e691858 100644 --- a/packages/swapper/src/swappers/zrx/utils/test-data/setupSwapQuote.ts +++ b/packages/swapper/src/swappers/zrx/utils/test-data/setupSwapQuote.ts @@ -1,9 +1,9 @@ -import { ContractTypes, NetworkTypes, ChainTypes, Asset } from '@shapeshiftoss/asset-service' +import { ContractTypes, NetworkTypes, ChainTypes } from '@shapeshiftoss/types' import { DEFAULT_SLIPPAGE } from '../constants' export const setupQuote = () => { - const sellAsset = ({ - name: 'Fox', + const sellAsset = { + name: 'FOX', chain: ChainTypes.Ethereum, network: NetworkTypes.MAINNET, precision: 18, @@ -12,12 +12,14 @@ export const setupQuote = () => { color: '#FFFFFF', secondaryColor: '#FFFFFF', icon: 'https://assets.coincap.io/assets/icons/fox@2x.png', + slip44: 60, + explorer: 'https://etherscan.io', + explorerTxLink: 'https://etherscan.io/tx/', sendSupport: true, receiveSupport: true, symbol: 'FOX' - // TODO: remove the type casts from test files when we unify `ChainTypes` and `ChainIdentifier` - } as unknown) as Asset - const buyAsset = ({ + } + const buyAsset = { name: 'WETH', chain: ChainTypes.Ethereum, network: NetworkTypes.MAINNET, @@ -27,12 +29,13 @@ export const setupQuote = () => { color: '#FFFFFF', secondaryColor: '#FFFFFF', icon: 'https://assets.coingecko.com/coins/images/2518/thumb/weth.png?1628852295', + slip44: 60, explorer: 'https://etherscan.io', explorerTxLink: 'https://etherscan.io/tx/', sendSupport: true, receiveSupport: true, symbol: 'WETH' - } as unknown) as Asset + } const quoteInput = { sellAsset, diff --git a/packages/types/README.md b/packages/types/README.md new file mode 100644 index 000000000..303b1a3d9 --- /dev/null +++ b/packages/types/README.md @@ -0,0 +1,13 @@ +## ShapeShift Types + +## Getting Started + +```sh +yarn add @shapeshiftoss/types +``` + +## Usage + +```ts +import { Asset, ChainTypes, Network } from '@shapeshiftoss/types' +``` diff --git a/packages/types/package.json b/packages/types/package.json new file mode 100644 index 000000000..d452799db --- /dev/null +++ b/packages/types/package.json @@ -0,0 +1,22 @@ +{ + "name": "@shapeshiftoss/types", + "version": "1.0.0", + "description": "Common types shared across packages", + "repository": "https://github.com/shapeshift/lib", + "license": "MIT", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "yarn clean && tsc --project tsconfig.build.json", + "dev": "tsc --watch", + "clean": "rm -rf dist", + "test": "jest test", + "type-check": "tsc --project ./tsconfig.json --noEmit" + }, + "devDependencies": { + "@shapeshiftoss/hdwallet-core": "^1.16.3" + } +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts new file mode 100644 index 000000000..c9f6f047d --- /dev/null +++ b/packages/types/src/index.ts @@ -0,0 +1 @@ +export * from './types' diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts new file mode 100644 index 000000000..40145fb25 --- /dev/null +++ b/packages/types/src/types.ts @@ -0,0 +1,298 @@ +import { ETHSignTx, HDWallet } from '@shapeshiftoss/hdwallet-core' + +// asset-service + +type AbstractAsset = { + chain: ChainTypes + network: NetworkTypes + symbol: string + name: string + precision: number + slip44: number + color: string + secondaryColor: string + icon: string + explorer: string + explorerTxLink: string + sendSupport: boolean + receiveSupport: boolean +} + +type OmittedTokenAssetFields = 'chain' | 'network' | 'slip44' | 'explorer' | 'explorerTxLink' +type TokenAssetFields = { + tokenId: string + contractType: ContractTypes +} +export type TokenAsset = Omit & TokenAssetFields +export type BaseAsset = AbstractAsset & { tokens?: TokenAsset[] } +export type Asset = AbstractAsset & Partial + +export enum ContractTypes { + ERC20 = 'ERC20', + ERC721 = 'ERC721', + OTHER = 'OTHER', + NONE = 'NONE' +} + +export enum ChainTypes { + Ethereum = 'ethereum', + Bitcoin = 'bitcoin', + Litecoin = 'litecoin' +} + +export enum NetworkTypes { + MAINNET = 'MAINNET', + TESTNET = 'TESTNET', // BTC, LTC, etc... + ETH_ROPSTEN = 'ETH_ROPSTEN', + ETH_RINKEBY = 'ETH_RINKEBY' +} + +// market-service + +export type MarketData = { + price: string + marketCap: string + volume: string + changePercent24Hr: number +} + +export enum HistoryTimeframe { + HOUR = '1H', + DAY = '24H', + WEEK = '1W', + MONTH = '1M', + YEAR = '1Y', + ALL = 'All' +} + +export type HistoryData = { + price: number + date: string +} + +export type PriceHistoryArgs = { + chain: ChainTypes + timeframe: HistoryTimeframe + tokenId?: string +} + +export type MarketDataArgs = { + chain: ChainTypes + tokenId?: string +} + +export type MarketDataType = (args: MarketDataArgs) => Promise + +export type PriceHistoryType = (args: PriceHistoryArgs) => Promise + +// swapper + +export enum SwapperType { + Zrx = '0x', + Thorchain = 'Thorchain' +} + +export type FeeData = { + fee?: string + gas?: string + estimatedGas?: string + gasPrice?: string + approvalFee?: string + protocolFee?: string + minimumProtocolFee?: string + receiveNetworkFee?: string +} + +export type SwapSource = { + name: string + proportion: string +} + +export type QuoteResponse = { + price: string + guaranteedPrice: string + to: string + data?: string + value?: string + gas?: string + estimatedGas?: string + gasPrice?: string + protocolFee?: string + minimumProtocolFee?: string + buyTokenAddress?: string + sellTokenAddress?: string + buyAmount?: string + sellAmount?: string + allowanceTarget?: string + sources?: Array +} +export type Quote = { + success: boolean + statusCode?: number + statusReason?: string + sellAssetAccountId?: string + buyAssetAccountId?: string + sellAsset: Asset + buyAsset: Asset + rate?: string + depositAddress?: string // this is dex contract address for eth swaps + receiveAddress?: string + buyAmount?: string + sellAmount?: string + minimum?: string | null + maximum?: string | null + guaranteedPrice?: string + slipScore?: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + txData?: any // unsigned tx if available at quote time + value?: string + feeData?: FeeData + allowanceContract?: string + allowanceGrantRequired?: boolean + slippage?: string + priceImpact?: string + orderId?: string + sources?: Array + timestamp?: number +} + +export type GetQuoteInput = { + sellAsset: Asset + buyAsset: Asset + sellAmount?: string + buyAmount?: string + sellAssetAccountId?: string + buyAssetAccountId?: string + slippage?: string + priceImpact?: string + sendMax?: boolean + minimumPrice?: string + minimum?: string +} + +export type BuildQuoteTxArgs = { + input: GetQuoteInput + wallet: HDWallet +} + +// chain-adapters + +export type Transaction = { + network: string + symbol: string + txid: string + status: string + from: string + to: string + blockHash: string + blockHeight: number + confirmations: number + timestamp: number + value: string + fee: string +} + +export type TxHistoryResponse = { + page: number + totalPages: number + txs: number + transactions: Transaction[] +} + +export type Token = { + type: string + name: string + path?: string + contract?: string + transfers: number + symbol?: string + decimals?: number + balance?: string + totalReceived?: string + totalSent?: string +} + +export type BalanceResponse = { + network: string + symbol: string + address: string + balance: string + unconfirmedBalance: string + unconfirmedTxs: number + txs: number + tokens: Token[] +} + +export type BroadcastTxResponse = { + network: string + txid: string +} + +export type BuildSendTxInput = { + to: string + value: string + wallet: HDWallet + path: string + /*** In base units */ + fee?: string + /*** Optional param for eth txs indicating what ERC20 is being sent */ + erc20ContractAddress?: string + limit?: string +} + +export type SignTxInput = { + txToSign: ETHSignTx + wallet: HDWallet +} +export type GetAddressInput = { + wallet: HDWallet + path: string +} + +export type GetFeeDataInput = { + contractAddress?: string + from: string + to: string + value: string +} + +export enum FeeDataKey { + Slow = 'slow', + Average = 'average', + Fast = 'fast' +} + +export type FeeDataType = { + feeUnitPrice: string + networkFee: string + feeUnits: string +} + +export type FeeDataEstimate = { + [FeeDataKey.Slow]: FeeDataType + [FeeDataKey.Average]: FeeDataType + [FeeDataKey.Fast]: FeeDataType +} + +export enum ValidAddressResultType { + Valid = 'valid', + Invalid = 'invalid' +} + +export type ValidAddressResult = { + /** + * Is this Address valid + */ + valid: boolean + /** + * Result type of valid address + */ + result: ValidAddressResultType +} + +export type FeeEstimateInput = { + to: string + from: string + data: string + value: string +} diff --git a/packages/types/tsconfig.build.json b/packages/types/tsconfig.build.json new file mode 100644 index 000000000..c2a90f098 --- /dev/null +++ b/packages/types/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "outDir": "./dist", + "resolveJsonModule": true, + "declaration": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "src/integration", "**/*.test.ts", "**/*.spec.ts"] +} diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json new file mode 100644 index 000000000..d7928d476 --- /dev/null +++ b/packages/types/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "outDir": "./dist" + }, + "watchOptions": { + // Use native file system events for files and directories + "watchFile": "useFsEvents", + "watchDirectory": "useFsEvents", + // Poll files for updates more frequently + // when they're updated a lot. (use as fallback) + "fallbackPolling": "dynamicPriority", + // Don't coalesce watch notification + "synchronousWatchDirectory": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "src/integration", "**/*.test.ts", "**/*.spec.ts"] +} diff --git a/yarn.lock b/yarn.lock index 4034fa6d9..139b2a205 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2299,6 +2299,15 @@ lodash "^4.17.21" rxjs "^6.4.0" +"@shapeshiftoss/hdwallet-core@^1.16.3": + version "1.16.3" + resolved "https://registry.yarnpkg.com/@shapeshiftoss/hdwallet-core/-/hdwallet-core-1.16.3.tgz#fdcf642c7220f605668801d0246c6c0d1218bc80" + integrity sha512-qm4mr3CSH0+p5rITZuqpa05h8MKqPcGAn+0pZuV5ssP0lTUTyHSWSU74DcBKFrforSWc3ActL+eFOyUl9lRmJw== + dependencies: + eventemitter2 "^5.0.1" + lodash "^4.17.21" + rxjs "^6.4.0" + "@shapeshiftoss/hdwallet-native@^1.15.5-alpha.1": version "1.16.1" resolved "https://registry.yarnpkg.com/@shapeshiftoss/hdwallet-native/-/hdwallet-native-1.16.1.tgz#ee3c7253b7e192a80154c7480e311c4e30baf4bb"