@swapkit/helpers
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -10,8 +10,8 @@ { | ||
"devDependencies": { | ||
"@swapkit/toolbox-cosmos": "1.0.13", | ||
"@swapkit/toolbox-evm": "1.1.7", | ||
"@swapkit/toolbox-solana": "1.0.12", | ||
"@swapkit/toolbox-radix": "1.0.12", | ||
"@swapkit/toolbox-substrate": "1.1.7", | ||
"@swapkit/toolbox-utxo": "1.0.12" | ||
"@swapkit/toolbox-cosmos": "1.0.14", | ||
"@swapkit/toolbox-evm": "1.1.8", | ||
"@swapkit/toolbox-solana": "1.0.13", | ||
"@swapkit/toolbox-radix": "1.0.13", | ||
"@swapkit/toolbox-substrate": "1.1.8", | ||
"@swapkit/toolbox-utxo": "1.0.13" | ||
}, | ||
@@ -41,3 +41,3 @@ "files": [ | ||
"types": "./src/index.ts", | ||
"version": "1.2.3" | ||
"version": "1.2.4" | ||
} |
@@ -25,6 +25,8 @@ type Options = Parameters<typeof fetch>[1] & { | ||
const { searchParams, json, body } = options; | ||
const headers = { ...defaultRequestHeaders, ...config.headers, ...options.headers } as Record< | ||
string, | ||
string | ||
>; | ||
const headers = { | ||
...defaultRequestHeaders, | ||
...config.headers, | ||
...options.headers, | ||
...(json ? { "Content-Type": "application/json" } : {}), | ||
} as Record<string, string>; | ||
@@ -31,0 +33,0 @@ const bodyToSend = json ? JSON.stringify(json) : body; |
import { z } from "zod"; | ||
export enum ErrorCode { | ||
unknownError = "unknownError", | ||
test_error = "test_error", | ||
providerDetailsError = "providerDetailsError", | ||
blockHeaderNotFound = "blockHeaderNotFound", | ||
blockHashNotFoundAtHeight = "blockHashNotFoundAtHeight", | ||
blockHashNotFoundAtHash = "blockHashNotFoundAtHash", | ||
txHashMissing = "txHashMissing", | ||
assetValueMissingInfo = "assetValueMissingInfo", | ||
invalidAsset = "invalidAsset", | ||
blockIsRequired = "blockIsRequired", | ||
currentBlockHeaderNotFound = "currentBlockHeaderNotFound", | ||
failedToRetrieveBalance = "failedToRetrieveBalance", | ||
failedToRetrieveBlock = "failedToRetrieveBlock", | ||
failedToRetrieveFees = "failedToRetrieveFees", | ||
notImplementedBCH = "notImplementedBCH", | ||
notImplementedDoge = "notImplementedDoge", | ||
noPoolsFound = "noPoolsFound", | ||
noVaultsFound = "noVaultsFound", | ||
noTxFound = "noTxFound", | ||
noInputCoinFound = "noInputCoinFound", | ||
noBlockDataFound = "noBlockDataFound", | ||
multipleCosmosMessages = "multipleCosmosMessages", | ||
heightOrHashNotProvided = "heightOrHashNotProvided", | ||
unknownDenom = "unknownDenom", | ||
invalidBlockHeight = "invalidBlockHeight", | ||
timestampExtrinsicNoArgumentsForBlock = "timestampExtrinsicNoArgumentsForBlock", | ||
timestampExtrinsicNoTimestampForBlock = "timestampExtrinsicNoTimestampForBlock", | ||
noTimestampExtrinsicForHash = "noTimestampExtrinsicForHash", | ||
timestampExtrinsicNoArgumentsForHash = "timestampExtrinsicNoArgumentsForHash", | ||
txMemoUndefined = "txMemoUndefined", | ||
txMemoIncorrect = "txMemoIncorrect", | ||
txTypeNotFound = "txTypeNotFound", | ||
txNoMessage = "txNoMessage", | ||
txNotFound = "txNotFound", | ||
txReceiptNotFound = "txReceiptNotFound", | ||
txParsingError = "txParsingError", | ||
blockNotFound = "blockNotFound", | ||
balanceNotFound = "balanceNotFound", | ||
configError = "configError", | ||
noQuoteResponse = "noQuoteResponse", | ||
noPoolAssetsFound = "noPoolAssetsFound", | ||
noThorchainPools = "noThorchainPools", | ||
noMayachainPools = "noMayachainPools", | ||
invalidAffiliateFee = "invalidAffiliateFee", | ||
invalidBuyAssetAddress = "invalidBuyAssetAddress", | ||
invalidSellAssetAddress = "invalidSellAssetAddress", | ||
invalidSourceAddress = "invalidSourceAddress", | ||
invalidDestinationAddress = "invalidDestinationAddress", | ||
sourceAddressIsSmartContract = "sourceAddressIsSmartContract", | ||
destinationAddressIsSmartContract = "destinationAddressIsSmartContract", | ||
invalidChainId = "invalidChainId", | ||
unsupportedChainId = "unsupportedChainId", | ||
unsupportedEVMChainId = "unsupportedEVMChainId", | ||
noWhitelistTokens = "noWhitelistTokens", | ||
failedFetchGasPrice = "failedFetchGasPrice", | ||
failedToCreateDepositChannel = "failedToCreateDepositChannel", | ||
noProviderDetailsFound = "noProviderDetailsFound", | ||
noTokenListsFound = "noTokenListsFound", | ||
tokenNotFound = "tokenNotFound", | ||
tokenPriceNotFound = "tokenPriceNotFound", | ||
swapAmountTooSmall = "swapAmountTooSmall", | ||
legsArrayIsEmpty = "legsArrayIsEmpty", | ||
failedToFetchQuoteForLeg = "failedToFetchQuoteForLeg", | ||
noBlockHeaderFound = "noBlockHeaderFound", | ||
failedToSimulateSwap = "failedToSimulateSwap", | ||
addressScreeningFailed = "addressScreeningFailed", | ||
noLiquidtyProvidersFound = "noLiquidtyProvidersFound", | ||
noSaversFound = "noSaversFound", | ||
noInboundAddressesFound = "noInboundAddressesFound", | ||
noInboundAddressFoundForChain = "noInboundAddressFoundForChain", | ||
noLastBlocksFound = "noLastBlocksFound", | ||
noVersionFound = "noVersionFound", | ||
noConstantsFound = "noConstantsFound", | ||
noMimirsFound = "noMimirsFound", | ||
noRoutesFound = "noRoutesFound", | ||
quoteNotFound = "quoteNotFound", | ||
ledgerSignFailed = "ledgerSignFailed", | ||
ledgerFetchSwapFailed = "ledgerFetchSwapFailed", | ||
failedToFetchTx = "failedToFetchTx", | ||
failedBuildTransactionDetails = "failedBuildTransactionDetails", | ||
noLegsForRoute = "noLegsForRoute", | ||
noRouterAddressFound = "noRouterAddressFound", | ||
noAggregatorAddressFound = "noAggregatorAddressFound", | ||
noContractInstanceFound = "noContractInstanceFound", | ||
noContractAddressFound = "noContractAddressFound", | ||
invalidAffiliate = "invalidAffiliate", | ||
providerNotfound = "No provider found", | ||
noRecordFound = "No Record found", | ||
slippageTooLow = "Slippage too low", | ||
tradingHalted = "tradingHalted", | ||
noWrappedGasAsset = "noWrappedGasAsset", | ||
aggregatorAddressNotFound = "aggregatorAddressNotFound", | ||
routerAddressNotFound = "routerAddressNotFound", | ||
dummyAddressNotFound = "dummyAddressNotFound", | ||
trackerError = "trackerError", | ||
noOhlcvDataFound = "noOhlcvDataFound", | ||
noTradingPairs = "noTradingPairs", | ||
noLoanPositionFound = "noLoanPositionFound", | ||
noLendingAvailability = "noLendingAvailability", | ||
lendingRepayTooSmall = "lendingRepayTooSmall", | ||
missingState = "missingState", | ||
ledgerSwapNotFound = "ledgerSwapNotFound", | ||
ledgerSwapNotReadyForTracking = "ledgerSwapNotReadyForTracking", | ||
errorEstimatingGas = "errorEstimatingGas", | ||
apiKeyInvalid = "apiKeyInvalid", | ||
apiKeyFailedToUpdate = "apiKeyFailedToUpdate", | ||
apiKeyExpired = "apiKeyExpired", | ||
unauthorized = "unauthorized", | ||
failedToCreateMemo = "failedToCreateMemo", | ||
radixIncorrectInstructions = "radixIncorrectInstructions", | ||
invalidAddressForChain = "invalidAddressForChain", | ||
} | ||
export enum WarningCodeEnum { | ||
@@ -8,2 +122,27 @@ highSlippage = "highSlippage", | ||
export const EVMTransactionSchema = z.object({ | ||
to: z.string({ | ||
description: "Address of the recipient", | ||
}), | ||
from: z.string({ | ||
description: "Address of the sender", | ||
}), | ||
gas: z | ||
.number({ | ||
description: "Gas limit", | ||
}) | ||
.optional(), | ||
gasPrice: z | ||
.string({ | ||
description: "Gas price", | ||
}) | ||
.optional(), | ||
value: z.string({ | ||
description: "Value to send", | ||
}), | ||
data: z.string({ | ||
description: "Data to send", | ||
}), | ||
}); | ||
export const EVMTransactionDetailsParamsSchema = z.array( | ||
@@ -186,65 +325,25 @@ z.union([ | ||
export const RouteQuoteLegSchema = z.object({ | ||
export type EVMTransaction = z.infer<typeof EVMTransactionSchema>; | ||
const QuoteResponseRouteLegItemDev = z.object({ | ||
provider: z.nativeEnum(ProviderName), | ||
sellAsset: z.string({ | ||
description: "Asset to sell", | ||
}), | ||
sellAmount: z.string({ | ||
description: "Sell amount", | ||
}), | ||
buyAsset: z.string({ | ||
description: "Asset to buy", | ||
}), | ||
provider: z.nativeEnum(ProviderName), | ||
buyAmount: z.string({ | ||
description: "Amount of asset to buy", | ||
description: "Buy amount", | ||
}), | ||
buyAmountMaxSlippage: z.string({ | ||
description: "Amount of asset to buy", | ||
description: "Buy amount max slippage", | ||
}), | ||
sellAmount: z.string({ | ||
description: "Amount of asset to sell", | ||
}), | ||
sourceAddress: z.string({ | ||
description: "Source address", | ||
}), | ||
destinationAddress: z.string({ | ||
description: "Destination address", | ||
}), | ||
slippageBps: z.number({ | ||
description: "Slippage in bps", | ||
}), | ||
targetAddress: z.optional( | ||
z.string({ | ||
description: "Target address for contract call or transfer address", | ||
}), | ||
), | ||
inboundAddress: z.optional( | ||
z.string({ | ||
description: "Inbound address", | ||
}), | ||
), | ||
routerAddress: z.optional( | ||
z.string({ | ||
description: "Inbound address", | ||
}), | ||
), | ||
contractMethod: z.optional( | ||
z.string({ | ||
description: "Contract method", | ||
}), | ||
), | ||
fees: z.optional(FeesSchema), | ||
estimatedTime: z.optional(EstimatedTimeSchema), | ||
memo: z.optional( | ||
z.string({ | ||
description: "Memo", | ||
}), | ||
), | ||
expiration: z.optional( | ||
z.string({ | ||
description: "Expiration", | ||
}), | ||
), | ||
fees: z.optional(FeesSchema), // TODO remove optionality | ||
}); | ||
export type RouteQuoteLeg = z.infer<typeof RouteQuoteLegSchema>; | ||
export const RouteQuoteSchema = z.object({ | ||
const QuoteResponseRouteItemDev = z.object({ | ||
providers: z.array(z.nativeEnum(ProviderName)), | ||
@@ -255,3 +354,3 @@ sellAsset: z.string({ | ||
sellAmount: z.string({ | ||
description: "sell amount", | ||
description: "Sell amount", | ||
}), | ||
@@ -278,12 +377,2 @@ buyAsset: z.string({ | ||
), | ||
routerAddress: z.optional( | ||
z.string({ | ||
description: "Router address", | ||
}), | ||
), | ||
inboundAddress: z.optional( | ||
z.string({ | ||
description: "Inbound address", | ||
}), | ||
), | ||
expiration: z.optional( | ||
@@ -299,11 +388,10 @@ z.string({ | ||
), | ||
evmTransactionDetails: z.optional(EVMTransactionDetailsSchema), | ||
routePathArray: z.optional(z.array(z.string())), | ||
estimatedTime: z.optional(EstimatedTimeSchema), | ||
fees: FeesSchema, | ||
tx: z.optional(EVMTransactionSchema), | ||
transaction: z.optional(z.unknown()), // Can take many forms depending on the chains | ||
estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality | ||
totalSlippageBps: z.number({ | ||
description: "Total slippage in bps", | ||
}), | ||
legs: z.array(RouteQuoteLegSchema), | ||
// TODO use enum | ||
errorCode: z.optional(z.string()), | ||
legs: z.array(QuoteResponseRouteLegItemDev), | ||
warnings: RouteQuoteWarningSchema, | ||
@@ -313,4 +401,18 @@ meta: RouteQuoteMetadataSchema, | ||
export type RouteQuote = z.infer<typeof RouteQuoteSchema>; | ||
export const QuoteResponseSchemaDev = z.object({ | ||
quoteId: z.string({ | ||
description: "Quote ID", | ||
}), | ||
routes: z.array(QuoteResponseRouteItemDev), | ||
error: z.optional( | ||
z.string({ | ||
description: "Error message", | ||
}), | ||
), | ||
}); | ||
export type QuoteResponseDev = z.infer<typeof QuoteResponseSchemaDev>; | ||
export type QuoteResponseRouteDev = z.infer<typeof QuoteResponseRouteItemDev>; | ||
export type QuoteResponseRouteLegDev = z.infer<typeof QuoteResponseRouteLegItemDev>; | ||
const QuoteResponseRouteLegItem = z.object({ | ||
@@ -342,3 +444,3 @@ provider: z.nativeEnum(ProviderName), | ||
sellAmount: z.string({ | ||
description: "sell amount", | ||
description: "Sell amount", | ||
}), | ||
@@ -376,2 +478,3 @@ buyAsset: z.string({ | ||
evmTransactionDetails: z.optional(EVMTransactionDetailsSchema), | ||
transaction: z.optional(z.unknown()), // Can take many forms depending on the chains | ||
estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality | ||
@@ -378,0 +481,0 @@ totalSlippageBps: z.number({ |
@@ -7,3 +7,3 @@ import type { CovalentApiType, EthplorerApiType } from "@swapkit/toolbox-evm"; | ||
import type { Chain, CosmosChain, UTXOChain } from "./chains"; | ||
import type { QuoteResponseRoute } from "./quotes"; | ||
import { ProviderName, type QuoteResponseRoute } from "./quotes"; | ||
@@ -88,5 +88,15 @@ type CovalentChains = | ||
z.array( | ||
z.string({ | ||
description: "List of providers to use", | ||
}), | ||
z | ||
.string({ | ||
description: "List of providers to use", | ||
}) | ||
.refine( | ||
(provider) => { | ||
return ProviderName[provider as ProviderName] !== undefined; | ||
}, | ||
{ | ||
message: "Invalid provider", | ||
path: ["providers"], | ||
}, | ||
), | ||
), | ||
@@ -141,2 +151,7 @@ ), | ||
), | ||
includeTx: z.optional( | ||
z.boolean({ | ||
description: "Set to true to include an transaction object (EVM only)", | ||
}), | ||
), | ||
}) | ||
@@ -143,0 +158,0 @@ .refine((data) => data.sellAsset !== data.buyAsset, { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
463851
5674