@swapkit/helpers 1.0.0-rc.105 → 1.0.0-rc.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/types/wallet.ts +0 -2
package/dist/index.js.map
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"import { ExplorerUrl, RPCUrl } from \"./network\";\n\nexport enum Chain {\n Arbitrum = \"ARB\",\n Avalanche = \"AVAX\",\n Binance = \"BNB\",\n BinanceSmartChain = \"BSC\",\n Bitcoin = \"BTC\",\n BitcoinCash = \"BCH\",\n Cosmos = \"GAIA\",\n Dash = \"DASH\",\n Dogecoin = \"DOGE\",\n Ethereum = \"ETH\",\n Kujira = \"KUJI\",\n Litecoin = \"LTC\",\n Maya = \"MAYA\",\n Optimism = \"OP\",\n Polkadot = \"DOT\",\n Chainflip = \"FLIP\",\n Polygon = \"MATIC\",\n THORChain = \"THOR\",\n}\n\nexport enum ChainId {\n Arbitrum = \"42161\",\n ArbitrumHex = \"0xa4b1\",\n Avalanche = \"43114\",\n AvalancheHex = \"0xa86a\",\n Binance = \"Binance-Chain-Tigris\",\n BinanceSmartChain = \"56\",\n BinanceSmartChainHex = \"0x38\",\n Bitcoin = \"bitcoin\",\n BitcoinCash = \"bitcoincash\",\n Chainflip = \"chainflip\",\n Cosmos = \"cosmoshub-4\",\n Dash = \"dash\",\n Dogecoin = \"dogecoin\",\n Kujira = \"kaiyo-1\",\n Ethereum = \"1\",\n EthereumHex = \"0x1\",\n Litecoin = \"litecoin\",\n Maya = \"mayachain-mainnet-v1\",\n MayaStagenet = \"mayachain-stagenet-v1\",\n Optimism = \"10\",\n OptimismHex = \"0xa\",\n Polkadot = \"polkadot\",\n Polygon = \"137\",\n PolygonHex = \"0x89\",\n THORChain = \"thorchain-mainnet-v1\",\n THORChainStagenet = \"thorchain-stagenet-v2\",\n}\n\nexport const ChainIdToChain: Record<ChainId, Chain> = {\n [ChainId.ArbitrumHex]: Chain.Arbitrum,\n [ChainId.Arbitrum]: Chain.Arbitrum,\n [ChainId.AvalancheHex]: Chain.Avalanche,\n [ChainId.Avalanche]: Chain.Avalanche,\n [ChainId.BinanceSmartChainHex]: Chain.BinanceSmartChain,\n [ChainId.BinanceSmartChain]: Chain.BinanceSmartChain,\n [ChainId.Binance]: Chain.Binance,\n [ChainId.BitcoinCash]: Chain.BitcoinCash,\n [ChainId.Bitcoin]: Chain.Bitcoin,\n [ChainId.Chainflip]: Chain.Chainflip,\n [ChainId.Cosmos]: Chain.Cosmos,\n [ChainId.Dash]: Chain.Dash,\n [ChainId.Dogecoin]: Chain.Dogecoin,\n [ChainId.EthereumHex]: Chain.Ethereum,\n [ChainId.Kujira]: Chain.Kujira,\n [ChainId.Ethereum]: Chain.Ethereum,\n [ChainId.Litecoin]: Chain.Litecoin,\n [ChainId.MayaStagenet]: Chain.Maya,\n [ChainId.Maya]: Chain.Maya,\n [ChainId.OptimismHex]: Chain.Optimism,\n [ChainId.Optimism]: Chain.Optimism,\n [ChainId.Polkadot]: Chain.Polkadot,\n [ChainId.PolygonHex]: Chain.Polygon,\n [ChainId.Polygon]: Chain.Polygon,\n [ChainId.THORChainStagenet]: Chain.THORChain,\n [ChainId.THORChain]: Chain.THORChain,\n};\n\ntype ChainNameType = keyof typeof Chain;\nconst chainNames = Object.keys(Chain) as ChainNameType[];\nconst chains = Object.values(Chain) as Chain[];\n\nexport enum BaseDecimal {\n ARB = 18,\n AVAX = 18,\n BCH = 8,\n BNB = 8,\n BSC = 18,\n BTC = 8,\n DASH = 8,\n DOGE = 8,\n DOT = 10,\n ETH = 18,\n FLIP = 18,\n GAIA = 6,\n KUJI = 6,\n LTC = 8,\n MATIC = 18,\n MAYA = 10,\n OP = 18,\n THOR = 8,\n ZEC = 8,\n}\n\nexport type SubstrateChain = Chain.Polkadot | Chain.Chainflip;\nexport const SubstrateChains = [Chain.Polkadot, Chain.Chainflip];\n\nexport type EVMChain =\n | Chain.Ethereum\n | Chain.Avalanche\n | Chain.BinanceSmartChain\n | Chain.Arbitrum\n | Chain.Optimism\n | Chain.Polygon;\nexport const EVMChains = [\n Chain.Ethereum,\n Chain.Avalanche,\n Chain.BinanceSmartChain,\n Chain.Arbitrum,\n Chain.Optimism,\n Chain.Polygon,\n] as const;\n\nexport type UTXOChain =\n | Chain.Bitcoin\n | Chain.BitcoinCash\n | Chain.Dash\n | Chain.Dogecoin\n | Chain.Litecoin;\nexport const UTXOChains = [\n Chain.Bitcoin,\n Chain.BitcoinCash,\n Chain.Dash,\n Chain.Dogecoin,\n Chain.Litecoin,\n] as const;\n\nexport type CosmosChain =\n | Chain.Cosmos\n | Chain.THORChain\n | Chain.Binance\n | Chain.Maya\n | Chain.Kujira;\nexport const CosmosChains = [\n Chain.Cosmos,\n Chain.THORChain,\n Chain.Binance,\n Chain.Maya,\n Chain.Kujira,\n] as const;\n\nexport const TCSupportedChains = [\n Chain.Avalanche,\n Chain.Binance,\n Chain.BinanceSmartChain,\n Chain.Bitcoin,\n Chain.BitcoinCash,\n Chain.Cosmos,\n Chain.Dogecoin,\n Chain.Ethereum,\n Chain.Litecoin,\n Chain.THORChain,\n] as const;\n\nexport const MAYASupportedChains = [\n Chain.Arbitrum,\n Chain.Dash,\n Chain.Ethereum,\n Chain.Kujira,\n Chain.Maya,\n Chain.THORChain,\n] as const;\n\nconst ChainToChainName = chains.reduce(\n (acc, chain) => {\n const chainName = chainNames.find((key) => Chain[key as ChainNameType] === chain);\n\n if (chainName) acc[chain] = chainName;\n\n return acc;\n },\n {} as { [key in Chain]: ChainNameType },\n);\n\nexport const ChainToChainId = chains.reduce(\n (acc, chain) => {\n acc[chain] = ChainId[ChainToChainName[chain]];\n return acc;\n },\n {} as { [key in Chain]: ChainId },\n);\n\nexport const ChainToRPC = chains.reduce(\n (acc, chain) => {\n acc[chain] = RPCUrl[ChainToChainName[chain]];\n return acc;\n },\n {} as { [key in Chain]: RPCUrl },\n);\n\nexport const ChainToHexChainId = chains.reduce(\n (acc, chain) => {\n const chainString = `${ChainToChainName[chain]}Hex` as keyof typeof ChainId;\n\n acc[chain] = ChainId[chainString];\n return acc;\n },\n {} as { [key in Chain]: ChainId },\n);\n\nexport const ChainToExplorerUrl = chains.reduce(\n (acc, chain) => {\n acc[chain] = ExplorerUrl[ChainToChainName[chain]];\n return acc;\n },\n {} as { [key in Chain]: string },\n);\n",
|
|
10
10
|
"import type { AssetValue } from \"../modules/assetValue.ts\";\nimport type { Chain, CosmosChain, EVMChain, UTXOChain } from \"./chains.ts\";\nimport type { WalletOption } from \"./wallet.ts\";\n\nexport type ConnectConfig = {\n stagenet?: boolean;\n /**\n * @required\n */\n thorswapApiKey?: string;\n /**\n * @required for AVAX & BSC\n */\n covalentApiKey?: string;\n /**\n * @required for ETH\n */\n ethplorerApiKey?: string;\n /**\n * @required for BTC, BCH, LTC, DOGE\n */\n blockchairApiKey?: string;\n /**\n * @required for Walletconnect\n */\n walletConnectProjectId?: string;\n /**\n * @optional for Trezor config\n */\n trezorManifest?: {\n email: string;\n appUrl: string;\n };\n /**\n * @optional for KeepKey config\n */\n keepkeyConfig?: {\n apiKey: string;\n pairingInfo: {\n name: string;\n imageUrl: string;\n basePath: string;\n url: string;\n };\n };\n};\n\nexport type AddChainWalletParams<T extends Chain> = {\n address: string;\n balance: AssetValue[];\n walletType: WalletOption;\n chain: T;\n [key: string]: Todo;\n};\n\ntype ApisType = { [key in UTXOChain]?: string | Todo } & {\n [key in EVMChain]?: string | Todo;\n} & {\n [key in CosmosChain]?: string;\n};\n\nexport type ConnectWalletParams = {\n addChain: <T extends Chain>(params: AddChainWalletParams<T>) => void;\n apis: ApisType;\n config: ConnectConfig;\n rpcUrls: { [chain in Chain]?: string };\n};\n\nexport type Witness = {\n value: number;\n script: Buffer;\n};\n\nexport enum QuoteMode {\n TC_SUPPORTED_TO_TC_SUPPORTED = \"TC-TC\",\n TC_SUPPORTED_TO_ETH = \"TC-ERC20\",\n TC_SUPPORTED_TO_AVAX = \"TC-ARC20\",\n TC_SUPPORTED_TO_BSC = \"TC-BEP20\",\n ETH_TO_TC_SUPPORTED = \"ERC20-TC\",\n ETH_TO_ETH = \"ERC20-ERC20\",\n ETH_TO_AVAX = \"ERC20-ARC20\",\n ETH_TO_BSC = \"ERC20-BEP20\",\n AVAX_TO_TC_SUPPORTED = \"ARC20-TC\",\n AVAX_TO_ETH = \"ARC20-ERC20\",\n AVAX_TO_AVAX = \"ARC20-ARC20\",\n AVAX_TO_BSC = \"ARC20-BEP20\",\n BSC_TO_TC_SUPPORTED = \"BEP20-TC\",\n BSC_TO_ETH = \"BEP20-ERC20\",\n BSC_TO_AVAX = \"BEP20-ARC20\",\n BSC_TO_BSC = \"BEP20-BEP20\",\n}\n\nexport type Asset = {\n chain: Chain;\n symbol: string;\n ticker: string;\n synth?: boolean;\n};\n\nexport const AGG_SWAP = [QuoteMode.ETH_TO_ETH, QuoteMode.AVAX_TO_AVAX, QuoteMode.BSC_TO_BSC];\n\nexport const SWAP_IN = [\n QuoteMode.ETH_TO_TC_SUPPORTED,\n QuoteMode.ETH_TO_AVAX,\n QuoteMode.ETH_TO_BSC,\n QuoteMode.AVAX_TO_TC_SUPPORTED,\n QuoteMode.AVAX_TO_ETH,\n QuoteMode.AVAX_TO_BSC,\n QuoteMode.BSC_TO_TC_SUPPORTED,\n QuoteMode.BSC_TO_ETH,\n QuoteMode.BSC_TO_AVAX,\n];\n\nexport const SWAP_OUT = [\n QuoteMode.TC_SUPPORTED_TO_TC_SUPPORTED,\n QuoteMode.TC_SUPPORTED_TO_ETH,\n QuoteMode.TC_SUPPORTED_TO_AVAX,\n QuoteMode.TC_SUPPORTED_TO_BSC,\n];\n",
|
|
11
11
|
"import type { Chain } from \"./chains\";\n\nexport enum ContractAddress {\n ARB = \"0x0000000000000000000000000000000000000000\",\n AVAX = \"0x0000000000000000000000000000000000000000\",\n ETH = \"0x0000000000000000000000000000000000000000\",\n BSC = \"0x0000000000000000000000000000000000000000\",\n MATIC = \"0x0000000000000000000000000000000000001010\",\n OP = \"0x4200000000000000000000000000000000000042\",\n}\n\nexport enum DerivationPath {\n ARB = \"m/44'/60'/0'/0\",\n AVAX = \"m/44'/60'/0'/0\",\n BCH = \"m/44'/145'/0'/0\",\n BNB = \"m/44'/714'/0'/0\",\n BSC = \"m/44'/60'/0'/0\",\n BTC = \"m/84'/0'/0'/0\",\n DASH = \"m/44'/5'/0'/0\",\n DOGE = \"m/44'/3'/0'/0\",\n DOT = \"////\",\n ETH = \"m/44'/60'/0'/0\",\n FLIP = \"////\",\n GAIA = \"m/44'/118'/0'/0\",\n KUJI = \"m/44'/118'/0'/0\",\n LTC = \"m/84'/2'/0'/0\",\n MATIC = \"m/44'/60'/0'/0\",\n MAYA = \"m/44'/931'/0'/0\",\n OP = \"m/44'/60'/0'/0\",\n THOR = \"m/44'/931'/0'/0\",\n}\n\nexport type DerivationPathArray = [number, number, number, number, number?];\n\nexport const NetworkDerivationPath: Record<Chain, DerivationPathArray> = {\n ARB: [44, 60, 0, 0, 0],\n AVAX: [44, 60, 0, 0, 0],\n BCH: [44, 145, 0, 0, 0],\n BNB: [44, 714, 0, 0, 0],\n BSC: [44, 60, 0, 0, 0],\n BTC: [84, 0, 0, 0, 0],\n DASH: [44, 5, 0, 0, 0],\n DOGE: [44, 3, 0, 0, 0],\n ETH: [44, 60, 0, 0, 0],\n GAIA: [44, 118, 0, 0, 0],\n KUJI: [44, 118, 0, 0, 0],\n LTC: [84, 2, 0, 0, 0],\n MATIC: [44, 60, 0, 0, 0],\n MAYA: [44, 931, 0, 0, 0],\n OP: [44, 60, 0, 0, 0],\n THOR: [44, 931, 0, 0, 0],\n\n // Polkadot and related network derivation path is not number based\n DOT: [0, 0, 0, 0, 0],\n FLIP: [0, 0, 0, 0, 0],\n};\n",
|
|
12
|
-
"import type { Eip1193Provider } from \"ethers\";\nimport type { AssetValue } from \"../modules/assetValue\";\nimport type { Chain } from \"./chains\";\n\ndeclare global {\n interface WindowEventMap {\n \"eip6963:announceProvider\": CustomEvent;\n }\n}\n\nexport enum WalletOption {\n KEYSTORE = \"KEYSTORE\",\n KEEPKEY = \"KEEPKEY\",\n XDEFI = \"XDEFI\",\n METAMASK = \"METAMASK\",\n COINBASE_WEB = \"COINBASE_WEB\",\n COINBASE_MOBILE = \"COINBASE_MOBILE\",\n TREZOR = \"TREZOR\",\n TRUSTWALLET_WEB = \"TRUSTWALLET_WEB\",\n LEDGER = \"LEDGER\",\n KEPLR = \"KEPLR\",\n OKX = \"OKX\",\n OKX_MOBILE = \"OKX_MOBILE\",\n BRAVE = \"BRAVE\",\n WALLETCONNECT = \"WALLETCONNECT\",\n EIP6963 = \"EIP6963\",\n EXODUS = \"EXODUS\",\n}\n\nexport enum LedgerErrorCode {\n NoError = 0x9000,\n LockedDevice = 0x5515,\n TC_NotFound = 65535,\n}\n\nexport type ChainWallet = {\n chain: Chain;\n address: string;\n balance: AssetValue[];\n walletType: WalletOption;\n};\n\nexport type EmptyWallet = { [key in Chain]?: unknown };\n\nexport type BaseWallet<T extends EmptyWallet | unknown> = {\n // @ts-expect-error\n [key in Chain]: ChainWallet & T[key];\n};\n\nexport type
|
|
12
|
+
"import type { Eip1193Provider } from \"ethers\";\nimport type { AssetValue } from \"../modules/assetValue\";\nimport type { Chain } from \"./chains\";\n\ndeclare global {\n interface WindowEventMap {\n \"eip6963:announceProvider\": CustomEvent;\n }\n}\n\nexport enum WalletOption {\n KEYSTORE = \"KEYSTORE\",\n KEEPKEY = \"KEEPKEY\",\n XDEFI = \"XDEFI\",\n METAMASK = \"METAMASK\",\n COINBASE_WEB = \"COINBASE_WEB\",\n COINBASE_MOBILE = \"COINBASE_MOBILE\",\n TREZOR = \"TREZOR\",\n TRUSTWALLET_WEB = \"TRUSTWALLET_WEB\",\n LEDGER = \"LEDGER\",\n KEPLR = \"KEPLR\",\n OKX = \"OKX\",\n OKX_MOBILE = \"OKX_MOBILE\",\n BRAVE = \"BRAVE\",\n WALLETCONNECT = \"WALLETCONNECT\",\n EIP6963 = \"EIP6963\",\n EXODUS = \"EXODUS\",\n}\n\nexport enum LedgerErrorCode {\n NoError = 0x9000,\n LockedDevice = 0x5515,\n TC_NotFound = 65535,\n}\n\nexport type ChainWallet = {\n chain: Chain;\n address: string;\n balance: AssetValue[];\n walletType: WalletOption;\n};\n\nexport type EmptyWallet = { [key in Chain]?: unknown };\n\nexport type BaseWallet<T extends EmptyWallet | unknown> = {\n // @ts-expect-error\n [key in Chain]: ChainWallet & T[key];\n};\n\nexport type EIP6963ProviderInfo = {\n walletId: string;\n uuid: string;\n name: string;\n icon: string;\n};\n\nexport type EIP6963ProviderDetail = {\n info: EIP6963ProviderInfo;\n provider: Eip1193Provider;\n};\n\nexport type EIP6963Provider = {\n info: EIP6963ProviderInfo;\n provider: Eip1193Provider;\n};\n\n// This type represents the structure of an event dispatched by a wallet to announce its presence based on EIP-6963.\nexport type EIP6963AnnounceProviderEvent = Event & {\n detail: EIP6963Provider;\n};\n",
|
|
13
13
|
"import { z } from \"zod\";\nimport type { AssetValue } from \"../modules/assetValue\";\nimport type { QuoteResponseRoute } from \"./quotes\";\n\nexport type GenericSwapParams = {\n buyAsset?: AssetValue;\n sellAsset?: AssetValue;\n recipient?: string;\n feeOptionKey?: FeeOption;\n route: QuoteResponseRoute;\n};\n\nexport type SwapParams<PluginNames = string, T = GenericSwapParams> = T & {\n pluginName?: PluginNames;\n};\n\nexport enum FeeOption {\n Average = \"average\",\n Fast = \"fast\",\n Fastest = \"fastest\",\n}\n\nexport enum ApproveMode {\n Approve = \"approve\",\n CheckOnly = \"checkOnly\",\n}\n\nexport type ApproveReturnType<T extends ApproveMode> = T extends \"checkOnly\"\n ? Promise<boolean>\n : Promise<string>;\n\nexport type WalletTxParams = {\n feeOptionKey?: FeeOption;\n from?: string;\n memo?: string; // optional memo to pass\n recipient: string;\n};\n\nexport enum MemoType {\n BOND = \"BOND\",\n DEPOSIT = \"+\",\n LEAVE = \"LEAVE\",\n NAME_REGISTER = \"~\",\n UNBOND = \"UNBOND\",\n WITHDRAW = \"-\",\n OPEN_LOAN = \"$+\",\n CLOSE_LOAN = \"$-\",\n}\n\nexport const QuoteRequestSchema = z\n .object({\n sellAsset: z.string({\n description: \"Asset to sell\",\n }),\n buyAsset: z.string({\n description: \"Asset to buy\",\n }),\n sellAmount: z\n .number({\n description: \"Amount of asset to sell\",\n })\n .refine((amount) => amount > 0, {\n message: \"sellAmount must be greater than 0\",\n path: [\"sellAmount\"],\n }),\n providers: z.optional(\n z.array(\n z.string({\n description: \"List of providers to use\",\n }),\n ),\n ),\n sourceAddress: z.optional(\n z.string({\n description: \"Address to send asset from\",\n }),\n ),\n destinationAddress: z.optional(\n z.string({\n description: \"Address to send asset to\",\n }),\n ),\n slippage: z.optional(\n z.number({\n description: \"Slippage tolerance as a percentage. Default is 3%.\",\n }),\n ),\n affiliate: z.optional(\n z.string({\n description: \"Affiliate thorname\",\n }),\n ),\n affiliateFee: z.optional(\n z\n .number({\n description: \"Affiliate fee in basis points\",\n })\n .refine(\n (fee) => {\n return fee === Math.floor(fee) && fee >= 0;\n },\n { message: \"affiliateFee must be a positive integer\", path: [\"affiliateFee\"] },\n ),\n ),\n allowSmartContractSender: z.optional(\n z.boolean({\n description: \"Allow smart contract as sender\",\n }),\n ),\n allowSmartContractReceiver: z.optional(\n z.boolean({\n description: \"Allow smart contract as recipient\",\n }),\n ),\n disableSecurityChecks: z.optional(\n z.boolean({\n description: \"Disable security checks\",\n }),\n ),\n })\n .refine((data) => data.sellAsset !== data.buyAsset, {\n message: \"Must be different\",\n path: [\"sellAsset\", \"buyAsset\"],\n });\n\nexport type QuoteRequest = z.infer<typeof QuoteRequestSchema>;\n",
|
|
14
14
|
"import { z } from \"zod\";\n\nexport enum WarningCodeEnum {\n highSlippage = \"highSlippage\",\n highPriceImpact = \"highPriceImpact\",\n}\n\nexport const EVMTransactionDetailsParamsSchema = z.array(\n z.union([\n z.string(),\n z.number(),\n z.array(z.string()),\n z\n .object({\n from: z.string(),\n value: z.string(),\n })\n .describe(\"Parameters to pass to the contract method\"),\n ]),\n);\n\nexport type EVMTransactionDetailsParams = z.infer<typeof EVMTransactionDetailsParamsSchema>;\n\nexport const EVMTransactionDetailsSchema = z.object({\n contractAddress: z.string({\n description: \"Address of the contract to interact with\",\n }),\n contractMethod: z.string({\n description: \"Name of the method to call\",\n }),\n contractParams: EVMTransactionDetailsParamsSchema,\n // contractParamsStreaming: z.array(\n // z.string({\n // description:\n // \"If making a streaming swap through THORChain, parameters to pass to the contract method\",\n // }),\n // ),\n contractParamNames: z.array(\n z.string({\n description: \"Names of the parameters to pass to the contract method\",\n }),\n ),\n approvalToken: z.optional(\n z.string({\n description: \"Address of the token to approve spending of\",\n }),\n ),\n approvalSpender: z.optional(\n z.string({\n description: \"Address of the spender to approve\",\n }),\n ),\n});\n\nexport type EVMTransactionDetails = z.infer<typeof EVMTransactionDetailsSchema>;\n\nexport const EstimatedTimeSchema = z.object({\n inbound: z.optional(\n z.number({\n description: \"Time to receive inbound asset in seconds\",\n }),\n ),\n swap: z.optional(\n z.number({\n description: \"Time to swap assets in seconds\",\n }),\n ),\n outbound: z.optional(\n z.number({\n description: \"Time to receive outbound asset in seconds\",\n }),\n ),\n total: z.number({\n description: \"Total time in seconds\",\n }),\n});\n\nexport type EstimatedTime = z.infer<typeof EstimatedTimeSchema>;\n\nexport enum ProviderName {\n CHAINFLIP = \"CHAINFLIP\",\n TRADERJOE_V1 = \"TRADERJOE_V1\",\n PANGOLIN_V1 = \"PANGOLIN_V1\",\n UNISWAP_V2 = \"UNISWAP_V2\",\n THORCHAIN = \"THORCHAIN\",\n THORCHAIN_STREAMING = \"THORCHAIN_STREAMING\",\n MAYACHAIN = \"MAYACHAIN\",\n ONEINCH = \"ONEINCH\",\n SUSHISWAP_V2 = \"SUSHISWAP_V2\",\n WOOFI_V2 = \"WOOFI_V2\",\n PANCAKESWAP = \"PANCAKESWAP\",\n}\n\nexport enum FeeTypeEnum {\n LIQUIDITY = \"liquidity\",\n NETWORK = \"network\",\n INBOUND = \"inbound\",\n OUTBOUND = \"outbound\",\n AFFILIATE = \"affiliate\",\n TAX = \"tax\",\n}\n\nexport const FeesSchema = z.array(\n z.object({\n type: z.nativeEnum(FeeTypeEnum),\n amount: z.string(),\n asset: z.string(),\n chain: z.string(),\n protocol: z.nativeEnum(ProviderName),\n }),\n);\n\nexport type Fees = z.infer<typeof FeesSchema>;\n\nexport const RouteLegSchema = z.object({\n sellAsset: z.string({\n description: \"Asset to sell\",\n }),\n buyAsset: z.string({\n description: \"Asset to buy\",\n }),\n provider: z.nativeEnum(ProviderName),\n sourceAddress: z.string({\n description: \"Source address\",\n }),\n destinationAddress: z.string({\n description: \"Destination address\",\n }),\n estimatedTime: EstimatedTimeSchema.optional(),\n affiliate: z\n .string({\n description: \"Affiliate address\",\n })\n .optional(),\n affiliateFee: z\n .number({\n description: \"Affiliate fee\",\n })\n .optional(),\n slipPercentage: z.number({\n description: \"Slippage as a percentage\",\n }),\n});\n\nexport type RouteLeg = z.infer<typeof RouteLegSchema>;\n\nexport const RouteLegWithoutAddressesSchema = RouteLegSchema.omit({\n sourceAddress: true,\n destinationAddress: true,\n slipPercentage: true,\n});\n\nexport type RouteLegWithoutAddresses = z.infer<typeof RouteLegWithoutAddressesSchema>;\n\nexport const RouteQuoteMetadataAssetSchema = z.object({\n name: z.string({\n description: \"Asset name\",\n }),\n price: z.number({\n description: \"Price in USD\",\n }),\n image: z.string({\n description: \"Asset image\",\n }),\n});\n\nexport type RouteQuoteMetadataAsset = z.infer<typeof RouteQuoteMetadataAssetSchema>;\n\nexport const RouteQuoteMetadataSchema = z.object({\n priceImpact: z.number({\n description: \"Price impact\",\n }),\n assets: z.optional(z.array(RouteQuoteMetadataAssetSchema)),\n});\n\nexport const RouteQuoteWarningSchema = z.array(\n z.object({\n code: z.nativeEnum(WarningCodeEnum),\n display: z.string(),\n tooltip: z.string().optional(),\n }),\n);\n\nexport const RouteQuoteLegSchema = z.object({\n sellAsset: z.string({\n description: \"Asset to sell\",\n }),\n buyAsset: z.string({\n description: \"Asset to buy\",\n }),\n provider: z.nativeEnum(ProviderName),\n buyAmount: z.string({\n description: \"Amount of asset to buy\",\n }),\n buyAmountMaxSlippage: z.string({\n description: \"Amount of asset to buy\",\n }),\n sellAmount: z.string({\n description: \"Amount of asset to sell\",\n }),\n sourceAddress: z.string({\n description: \"Source address\",\n }),\n destinationAddress: z.string({\n description: \"Destination address\",\n }),\n slippageBps: z.number({\n description: \"Slippage in bps\",\n }),\n targetAddress: z.optional(\n z.string({\n description: \"Target address for contract call or transfer address\",\n }),\n ),\n inboundAddress: z.optional(\n z.string({\n description: \"Inbound address\",\n }),\n ),\n routerAddress: z.optional(\n z.string({\n description: \"Inbound address\",\n }),\n ),\n contractMethod: z.optional(\n z.string({\n description: \"Contract method\",\n }),\n ),\n fees: z.optional(FeesSchema),\n estimatedTime: z.optional(EstimatedTimeSchema),\n memo: z.optional(\n z.string({\n description: \"Memo\",\n }),\n ),\n expiration: z.optional(\n z.string({\n description: \"Expiration\",\n }),\n ),\n});\n\nexport type RouteQuoteLeg = z.infer<typeof RouteQuoteLegSchema>;\n\nexport const RouteQuoteSchema = z.object({\n providers: z.array(z.nativeEnum(ProviderName)),\n sellAsset: z.string({\n description: \"Asset to sell\",\n }),\n sellAmount: z.string({\n description: \"sell amount\",\n }),\n buyAsset: z.string({\n description: \"Asset to buy\",\n }),\n expectedBuyAmount: z.string({\n description: \"Expected Buy amount\",\n }),\n expectedBuyAmountMaxSlippage: z.string({\n description: \"Expected Buy amount max slippage\",\n }),\n sourceAddress: z.string({\n description: \"Source address\",\n }),\n destinationAddress: z.string({\n description: \"Destination address\",\n }),\n targetAddress: z.optional(\n z.string({\n description: \"Target address\",\n }),\n ),\n routerAddress: z.optional(\n z.string({\n description: \"Router address\",\n }),\n ),\n inboundAddress: z.optional(\n z.string({\n description: \"Inbound address\",\n }),\n ),\n expiration: z.optional(\n z.string({\n description: \"Expiration\",\n }),\n ),\n memo: z.optional(\n z.string({\n description: \"Memo\",\n }),\n ),\n evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),\n routePathArray: z.optional(z.array(z.string())),\n estimatedTime: z.optional(EstimatedTimeSchema),\n totalSlippageBps: z.number({\n description: \"Total slippage in bps\",\n }),\n legs: z.array(RouteQuoteLegSchema),\n // TODO use enum\n errorCode: z.optional(z.string()),\n warnings: RouteQuoteWarningSchema,\n meta: RouteQuoteMetadataSchema,\n});\n\nexport type RouteQuote = z.infer<typeof RouteQuoteSchema>;\n\nconst QuoteResponseRouteLegItem = z.object({\n provider: z.nativeEnum(ProviderName),\n sellAsset: z.string({\n description: \"Asset to sell\",\n }),\n sellAmount: z.string({\n description: \"Sell amount\",\n }),\n buyAsset: z.string({\n description: \"Asset to buy\",\n }),\n buyAmount: z.string({\n description: \"Buy amount\",\n }),\n buyAmountMaxSlippage: z.string({\n description: \"Buy amount max slippage\",\n }),\n fees: z.optional(FeesSchema), // TODO remove optionality\n});\n\nconst QuoteResponseRouteItem = z.object({\n providers: z.array(z.nativeEnum(ProviderName)),\n sellAsset: z.string({\n description: \"Asset to sell\",\n }),\n sellAmount: z.string({\n description: \"sell amount\",\n }),\n buyAsset: z.string({\n description: \"Asset to buy\",\n }),\n expectedBuyAmount: z.string({\n description: \"Expected Buy amount\",\n }),\n expectedBuyAmountMaxSlippage: z.string({\n description: \"Expected Buy amount max slippage\",\n }),\n sourceAddress: z.string({\n description: \"Source address\",\n }),\n destinationAddress: z.string({\n description: \"Destination address\",\n }),\n targetAddress: z.optional(\n z.string({\n description: \"Target address\",\n }),\n ),\n expiration: z.optional(\n z.string({\n description: \"Expiration\",\n }),\n ),\n memo: z.optional(\n z.string({\n description: \"Memo\",\n }),\n ),\n evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),\n estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality\n totalSlippageBps: z.number({\n description: \"Total slippage in bps\",\n }),\n legs: z.array(QuoteResponseRouteLegItem),\n warnings: RouteQuoteWarningSchema,\n meta: RouteQuoteMetadataSchema,\n});\n\nexport const QuoteResponseSchema = z.object({\n quoteId: z.string({\n description: \"Quote ID\",\n }),\n routes: z.array(QuoteResponseRouteItem),\n error: z.optional(\n z.string({\n description: \"Error message\",\n }),\n ),\n});\n\nexport type QuoteResponse = z.infer<typeof QuoteResponseSchema>;\nexport type QuoteResponseRoute = z.infer<typeof QuoteResponseRouteItem>;\nexport type QuoteResponseRouteLeg = z.infer<typeof QuoteResponseRouteLegItem>;\n",
|
|
15
15
|
"import { Chain } from \"../types/chains\";\n\n// Backward compatibility\nconst supportedChains = [...Object.values(Chain), \"TERRA\"];\n\nexport function validateIdentifier(identifier = \"\") {\n const uppercasedIdentifier = identifier.toUpperCase();\n\n const [chain] = uppercasedIdentifier.split(\".\") as [Chain, string];\n if (supportedChains.includes(chain)) return true;\n\n const [synthChain] = uppercasedIdentifier.split(\"/\") as [Chain, string];\n if (supportedChains.includes(synthChain)) return true;\n\n throw new Error(\n `Invalid identifier: ${identifier}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`,\n );\n}\n\nexport function validateTNS(name: string) {\n if (name.length > 30) return false;\n\n const regex = /^[a-zA-Z0-9+_-]+$/g;\n\n return !!name.match(regex);\n}\n",
|
package/package.json
CHANGED
package/src/types/wallet.ts
CHANGED