@swapkit/api
Advanced tools
Comparing version 0.0.0-nightly-20240404190857 to 0.0.0-nightly-20240503191507
@@ -36,25 +36,3 @@ var __defProp = Object.defineProperty; | ||
}); | ||
// src/requestClient.ts | ||
import ky from "ky"; | ||
function setRequestClientConfig({ apiKey, ...config }) { | ||
kyClient = ky.create({ | ||
...config, | ||
headers: { ...defaultRequestHeaders, ...config.headers, "x-api-key": apiKey } | ||
}); | ||
} | ||
var getKyClient = function() { | ||
if (kyClient) | ||
return kyClient; | ||
kyClient = ky.create({ headers: defaultRequestHeaders }); | ||
return kyClient; | ||
}; | ||
var kyClient; | ||
var defaultRequestHeaders = typeof window !== "undefined" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }; | ||
var RequestClient = { | ||
get: (url, options) => getKyClient().get(url, options).json(), | ||
post: (url, options) => getKyClient().post(url, options).json() | ||
}; | ||
// src/microgard/endpoints.ts | ||
import {RequestClient} from "@swapkit/helpers"; | ||
function getTHORNameDetails(thorname) { | ||
@@ -103,2 +81,3 @@ return RequestClient.get(`${baseUrl}/thorname/lookup/${thorname}`); | ||
}); | ||
import {RequestClient as RequestClient2} from "@swapkit/helpers"; | ||
var baseUrl2 = function({ type = "thorchain", stagenet = false } = {}) { | ||
@@ -113,15 +92,15 @@ switch (type) { | ||
function getLastBlock(params) { | ||
return RequestClient.get(`${baseUrl2(params)}/lastblock`); | ||
return RequestClient2.get(`${baseUrl2(params)}/lastblock`); | ||
} | ||
function getThorchainQueue(params) { | ||
return RequestClient.get(`${baseUrl2(params)}/queue`); | ||
return RequestClient2.get(`${baseUrl2(params)}/queue`); | ||
} | ||
function getNodes(params) { | ||
return RequestClient.get(`${baseUrl2(params)}/nodes`); | ||
return RequestClient2.get(`${baseUrl2(params)}/nodes`); | ||
} | ||
function getMimirInfo(params) { | ||
return RequestClient.get(`${baseUrl2(params)}/mimir`); | ||
return RequestClient2.get(`${baseUrl2(params)}/mimir`); | ||
} | ||
function getInboundAddresses(params) { | ||
return RequestClient.get(`${baseUrl2(params)}/inbound_addresses`); | ||
return RequestClient2.get(`${baseUrl2(params)}/inbound_addresses`); | ||
} | ||
@@ -178,2 +157,3 @@ | ||
}); | ||
import {RequestClient as RequestClient3} from "@swapkit/helpers"; | ||
function getCachedPrices({ tokens, ...options }) { | ||
@@ -191,3 +171,3 @@ const body = new URLSearchParams; | ||
body.append("sparkline", "true"); | ||
return RequestClient.post(`${baseUrl3}/tokenlist/cached-price`, { | ||
return RequestClient3.post(`${baseUrl3}/tokenlist/cached-price`, { | ||
body: body.toString(), | ||
@@ -198,6 +178,6 @@ headers: { "Content-Type": "application/x-www-form-urlencoded" } | ||
function getSwapQuote(searchParams) { | ||
return RequestClient.get(`${baseUrl3}/aggregator/tokens/quote`, { searchParams }); | ||
return RequestClient3.get(`${baseUrl3}/aggregator/tokens/quote`, { searchParams }); | ||
} | ||
function getBorrowQuote(searchParams) { | ||
return RequestClient.get(`${baseUrl3}/aggregator/lending/borrow`, { | ||
return RequestClient3.get(`${baseUrl3}/aggregator/lending/borrow`, { | ||
searchParams | ||
@@ -207,18 +187,18 @@ }); | ||
function getRepayQuote(searchParams) { | ||
return RequestClient.get(`${baseUrl3}/aggregator/lending/repay`, { searchParams }); | ||
return RequestClient3.get(`${baseUrl3}/aggregator/lending/repay`, { searchParams }); | ||
} | ||
function getLendingAssets() { | ||
return RequestClient.get(`${baseUrl3}/aggregator/lending/assets`); | ||
return RequestClient3.get(`${baseUrl3}/aggregator/lending/assets`); | ||
} | ||
function getLoans(searchParams) { | ||
return RequestClient.get(`${baseUrl3}/aggregator/lending/loans`, { searchParams }); | ||
return RequestClient3.get(`${baseUrl3}/aggregator/lending/loans`, { searchParams }); | ||
} | ||
function getGasRates() { | ||
return RequestClient.get(`${baseUrl3}/resource-worker/gasPrice/getAll`); | ||
return RequestClient3.get(`${baseUrl3}/resource-worker/gasPrice/getAll`); | ||
} | ||
function getTxnDetails(txHash) { | ||
return RequestClient.get(`${baseUrl3}/apiusage/v2/txn`, { searchParams: { txHash } }); | ||
return RequestClient3.get(`${baseUrl3}/apiusage/v2/txn`, { searchParams: { txHash } }); | ||
} | ||
function getTokenListProviders() { | ||
return RequestClient.get(`${baseUrl3}/tokenlist/providers`); | ||
return RequestClient3.get(`${baseUrl3}/tokenlist/providers`); | ||
} | ||
@@ -241,4 +221,5 @@ var baseUrl3 = "https://api.thorswap.finance"; | ||
}); | ||
function getTokenList(tokenlist) { | ||
return RequestClient.get(`${baseUrl4}/token-list/${tokenlist}.json`); | ||
import {RequestClient as RequestClient4} from "@swapkit/helpers"; | ||
function getTokenList(tokenListName) { | ||
return RequestClient4.get(`${baseUrl4}/token-list/${tokenListName}.json`); | ||
} | ||
@@ -336,11 +317,8 @@ function getLogoForAsset(assetString) { | ||
export { | ||
setRequestClientConfig, | ||
defaultRequestHeaders, | ||
TxStatus, | ||
TransactionType, | ||
SwapKitApi, | ||
StreamingSwapProgressStatus, | ||
RequestClient | ||
StreamingSwapProgressStatus | ||
}; | ||
//# debugId=7476E866EBC285D064756e2164756e21 | ||
//# debugId=D2866E4DD0CDEC4C64756e2164756e21 |
{ | ||
"author": "swapkit-oss", | ||
"dependencies": { | ||
"@swapkit/types": "0.0.0-nightly-20240404190857", | ||
"ky": "1.2.3" | ||
"@swapkit/helpers": "0.0.0-nightly-20240503191507" | ||
}, | ||
"devDependencies": { | ||
"bun-types": "1.1.1" | ||
"bun-types": "1.1.2" | ||
}, | ||
@@ -20,4 +19,3 @@ "description": "SwapKit - API", | ||
"peerDependencies": { | ||
"@swapkit/types": "0.0.0-nightly-20240404190857", | ||
"ky": "^1.2.2" | ||
"@swapkit/helpers": "0.0.0-nightly-20240503191507" | ||
}, | ||
@@ -31,3 +29,3 @@ "react-native": "./src/index.ts", | ||
"build": "bun run ./build.ts", | ||
"clean": "rm -rf .turbo dist node_modules tsconfig.tsbuildinfo", | ||
"clean": "rm -rf .turbo dist node_modules *.tsbuildinfo", | ||
"lint": "biome check --apply ./src", | ||
@@ -40,3 +38,3 @@ "test": "echo 'bun test'", | ||
"types": "./src/index.ts", | ||
"version": "0.0.0-nightly-20240404190857" | ||
"version": "0.0.0-nightly-20240503191507" | ||
} |
@@ -10,3 +10,2 @@ import * as microgardEndpoints from "./microgard/endpoints.ts"; | ||
export * from "./thornode/types.ts"; | ||
export * from "./requestClient.ts"; | ||
@@ -13,0 +12,0 @@ export const SwapKitApi = { |
@@ -1,2 +0,2 @@ | ||
import { RequestClient } from "../requestClient.ts"; | ||
import { RequestClient } from "@swapkit/helpers"; | ||
import type { PoolDetail, PoolPeriod, THORNameDetails } from "./types.ts"; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { RequestClient } from "../requestClient.ts"; | ||
import { RequestClient } from "@swapkit/helpers"; | ||
import type { | ||
@@ -3,0 +3,0 @@ InboundAddressesItem, |
@@ -1,2 +0,2 @@ | ||
import { RequestClient } from "../requestClient.ts"; | ||
import { RequestClient } from "@swapkit/helpers"; | ||
import type { | ||
@@ -3,0 +3,0 @@ BorrowParams, |
@@ -1,96 +0,52 @@ | ||
import type { Chain, LedgerErrorCode, QuoteMode } from "@swapkit/types"; | ||
import type { Chain, LedgerErrorCode, QuoteMode } from "@swapkit/helpers"; | ||
export enum TransactionType { | ||
// Old quote mode | ||
SWAP_TC_TO_TC = "SWAP:TC-TC", | ||
SWAP_ETH_TO_TC = "SWAP:ERC20-TC", | ||
SWAP_TC_TO_ETH = "SWAP:TC-ERC20", | ||
SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", | ||
// Old quote mode: AVAX | ||
SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", | ||
SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", | ||
SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", | ||
SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", | ||
SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", | ||
// ATOM | ||
SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", | ||
SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", | ||
// BNB | ||
SWAP_TC_TO_BNB = "SWAP:TC-BNB", | ||
SWAP_BNB_TO_TC = "SWAP:BNB-TC", | ||
// BTC | ||
SWAP_TC_TO_BTC = "SWAP:TC-BTC", | ||
SWAP_BTC_TO_TC = "SWAP:BTC-TC", | ||
// BCH | ||
SWAP_TC_TO_BCH = "SWAP:TC-BCH", | ||
SWAP_BCH_TO_TC = "SWAP:BCH-TC", | ||
// LTC | ||
SWAP_TC_TO_LTC = "SWAP:TC-LTC", | ||
SWAP_LTC_TO_TC = "SWAP:LTC-TC", | ||
// DOGE | ||
SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", | ||
SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", | ||
// TC txns | ||
TC_STATUS = "TC:STATUS", // only track status | ||
TC_TRANSFER = "TC:TRANSFER", // only track status | ||
TC_DEPOSIT = "TC:DEPOSIT", | ||
TC_SEND = "TC:SEND", | ||
TC_SWITCH = "TC:SWITCH", | ||
TC_LP_ADD = "TC:ADDLIQUIDITY", | ||
TC_LP_WITHDRAW = "TC:WITHDRAW", // Supports 'WITHDRAWLIQUIDITY' as well | ||
TC_TNS_CREATE = "TC:TNS-CREATE", | ||
TC_TNS_EXTEND = "TC:TNS-EXTEND", | ||
TC_TNS_UPDATE = "TC:TNS-UPDATE", | ||
// SAVINGS | ||
TC_SAVINGS_ADD = "TC:ADDSAVINGS", | ||
TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", | ||
// LENDING | ||
TC_LENDING_OPEN = "TC:LENDINGOPEN", | ||
TC_LENDING_CLOSE = "TC:LENDINGCLOSE", | ||
// ERC-20 txns | ||
ETH_APPROVAL = "ETH:APPROVAL", | ||
ETH_STATUS = "ETH:STATUS", // only track status | ||
ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", | ||
ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", | ||
// AVAX | ||
AVAX_APPROVAL = "AVAX:APPROVAL", | ||
AVAX_STATUS = "AVAX:STATUS", // only track status | ||
AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", | ||
AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", | ||
// BSC | ||
BSC_APPROVAL = "BSC:APPROVAL", | ||
BSC_STATUS = "BSC:STATUS", // only track status | ||
BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", | ||
BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", | ||
// Generic types | ||
APPROVAL = "APPROVAL", | ||
STATUS = "STATUS", | ||
TRANSFER_TO_TC = "TRANSFER:IN", | ||
TRANSFER_FROM_TC = "TRANSFER:OUT", | ||
// Unsupported | ||
UNSUPPORTED = "UNSUPPORTED", | ||
// Lending | ||
TC_LENDING = "TC:LENDING", | ||
} | ||
export type FeeType = "AFFILIATE" | "LIQUIDITY" | "INBOUND" | "OUTBOUND" | "NETWORK"; | ||
export enum TxStatus { | ||
PENDING = "pending", | ||
SUCCESS = "success", | ||
CANCELLED = "cancelled", | ||
REFUNDED = "refunded", | ||
REPLACED = "replaced", | ||
ERROR = "error", | ||
UNKNOWN = "unknown", | ||
NOT_STARTED = "not_started", | ||
NOT_FOUND = "not_found", | ||
RETRIES_EXCEEDED = "retries_exceeded", | ||
STREAMING = "streaming", | ||
} | ||
export type EvmTransactionDetails = { | ||
contractAddress: string; | ||
contractMethod: string; | ||
contractParamNames: string[]; | ||
contractParams: (string | { from: string })[]; | ||
}; | ||
export enum StreamingSwapProgressStatus { | ||
NOT_STARTED = 0, | ||
SUCCESS = 1, | ||
REFUNDED = 2, | ||
} | ||
export type QuoteFee = { | ||
amount: string; | ||
asset: string; | ||
chain: Chain; | ||
protocol: string; | ||
type: FeeType; | ||
}; | ||
export type QuoteLegsV2 = { | ||
buyAmount: string; | ||
buyAmountUSD: string; | ||
buyAsset: string; | ||
destinationAddress: string; | ||
expiration: string; | ||
fees: Todo[]; | ||
memo: string; | ||
provider: string; | ||
sellAmount: string; | ||
sellAmountUSD: string; | ||
sellAsset: string; | ||
sourceAddress: string; | ||
}; | ||
export type QuoteRouteV2 = { | ||
buyAsset: string; | ||
destinationAddress: string; | ||
evmTransactionDetails?: EvmTransactionDetails; | ||
expectedBuyAmount: string; | ||
expectedBuyAmountUSD: string; | ||
expiration: string; | ||
legs: QuoteLegsV2[]; | ||
memo: string; | ||
sellAmount: number; | ||
sellAmountUSD: string; | ||
sellAsset: string; | ||
sourceAddress: string; | ||
targetAddress?: string; | ||
providers: string[]; | ||
}; | ||
export type QuoteResponse = { quoteId: string; routes: QuoteRoute[] }; | ||
@@ -408,2 +364,95 @@ | ||
export enum TransactionType { | ||
// Old quote mode | ||
SWAP_TC_TO_TC = "SWAP:TC-TC", | ||
SWAP_ETH_TO_TC = "SWAP:ERC20-TC", | ||
SWAP_TC_TO_ETH = "SWAP:TC-ERC20", | ||
SWAP_ETH_TO_ETH = "SWAP:ERC20-ERC20", | ||
// Old quote mode: AVAX | ||
SWAP_AVAX_TO_TC = "SWAP:AVAX-TC", | ||
SWAP_TC_TO_AVAX = "SWAP:TC-AVAX", | ||
SWAP_AVAX_TO_AVAX = "SWAP:AVAX-AVAX", | ||
SWAP_ETH_TO_AVAX = "SWAP:ETH-AVAX", | ||
SWAP_AVAX_TO_ETH = "SWAP:AVAX-ETH", | ||
// ATOM | ||
SWAP_TC_TO_GAIA = "SWAP:TC-GAIA", | ||
SWAP_GAIA_TO_TC = "SWAP:GAIA-TC", | ||
// BNB | ||
SWAP_TC_TO_BNB = "SWAP:TC-BNB", | ||
SWAP_BNB_TO_TC = "SWAP:BNB-TC", | ||
// BTC | ||
SWAP_TC_TO_BTC = "SWAP:TC-BTC", | ||
SWAP_BTC_TO_TC = "SWAP:BTC-TC", | ||
// BCH | ||
SWAP_TC_TO_BCH = "SWAP:TC-BCH", | ||
SWAP_BCH_TO_TC = "SWAP:BCH-TC", | ||
// LTC | ||
SWAP_TC_TO_LTC = "SWAP:TC-LTC", | ||
SWAP_LTC_TO_TC = "SWAP:LTC-TC", | ||
// DOGE | ||
SWAP_TC_TO_DOGE = "SWAP:TC-DOGE", | ||
SWAP_DOGE_TO_TC = "SWAP:DOGE-TC", | ||
// TC txns | ||
TC_STATUS = "TC:STATUS", // only track status | ||
TC_TRANSFER = "TC:TRANSFER", // only track status | ||
TC_DEPOSIT = "TC:DEPOSIT", | ||
TC_SEND = "TC:SEND", | ||
TC_SWITCH = "TC:SWITCH", | ||
TC_LP_ADD = "TC:ADDLIQUIDITY", | ||
TC_LP_WITHDRAW = "TC:WITHDRAW", // Supports 'WITHDRAWLIQUIDITY' as well | ||
TC_TNS_CREATE = "TC:TNS-CREATE", | ||
TC_TNS_EXTEND = "TC:TNS-EXTEND", | ||
TC_TNS_UPDATE = "TC:TNS-UPDATE", | ||
// SAVINGS | ||
TC_SAVINGS_ADD = "TC:ADDSAVINGS", | ||
TC_SAVINGS_WITHDRAW = "TC:WITHDRAWSAVINGS", | ||
// LENDING | ||
TC_LENDING_OPEN = "TC:LENDINGOPEN", | ||
TC_LENDING_CLOSE = "TC:LENDINGCLOSE", | ||
// ERC-20 txns | ||
ETH_APPROVAL = "ETH:APPROVAL", | ||
ETH_STATUS = "ETH:STATUS", // only track status | ||
ETH_TRANSFER_TO_TC = "ETH:TRANSFER:IN", | ||
ETH_TRANSFER_FROM_TC = "ETH:TRANSFER:OUT", | ||
// AVAX | ||
AVAX_APPROVAL = "AVAX:APPROVAL", | ||
AVAX_STATUS = "AVAX:STATUS", // only track status | ||
AVAX_TRANSFER_TO_TC = "AVAX:TRANSFER:IN", | ||
AVAX_TRANSFER_FROM_TC = "AVAX:TRANSFER:OUT", | ||
// BSC | ||
BSC_APPROVAL = "BSC:APPROVAL", | ||
BSC_STATUS = "BSC:STATUS", // only track status | ||
BSC_TRANSFER_TO_TC = "BSC:TRANSFER:IN", | ||
BSC_TRANSFER_FROM_TC = "BSC:TRANSFER:OUT", | ||
// Generic types | ||
APPROVAL = "APPROVAL", | ||
STATUS = "STATUS", | ||
TRANSFER_TO_TC = "TRANSFER:IN", | ||
TRANSFER_FROM_TC = "TRANSFER:OUT", | ||
// Unsupported | ||
UNSUPPORTED = "UNSUPPORTED", | ||
// Lending | ||
TC_LENDING = "TC:LENDING", | ||
} | ||
export enum TxStatus { | ||
PENDING = "pending", | ||
SUCCESS = "success", | ||
CANCELLED = "cancelled", | ||
REFUNDED = "refunded", | ||
REPLACED = "replaced", | ||
ERROR = "error", | ||
UNKNOWN = "unknown", | ||
NOT_STARTED = "not_started", | ||
NOT_FOUND = "not_found", | ||
RETRIES_EXCEEDED = "retries_exceeded", | ||
STREAMING = "streaming", | ||
} | ||
export enum StreamingSwapProgressStatus { | ||
NOT_STARTED = 0, | ||
SUCCESS = 1, | ||
REFUNDED = 2, | ||
} | ||
type Calldata = { | ||
@@ -410,0 +459,0 @@ amount: string; |
@@ -1,2 +0,2 @@ | ||
import { RequestClient } from "../requestClient.ts"; | ||
import { RequestClient } from "@swapkit/helpers"; | ||
@@ -7,4 +7,4 @@ import type { TokensResponse } from "./types.ts"; | ||
export function getTokenList(tokenlist: string) { | ||
return RequestClient.get<TokensResponse>(`${baseUrl}/token-list/${tokenlist}.json`); | ||
export function getTokenList(tokenListName: string) { | ||
return RequestClient.get<TokensResponse>(`${baseUrl}/token-list/${tokenListName}.json`); | ||
} | ||
@@ -11,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
2
58702
12
1171
+ Added@swapkit/helpers@0.0.0-nightly-20240503191507(transitive)
+ Added@swapkit/tokens@0.0.0-nightly-20240503191507(transitive)
- Removedky@1.2.3
- Removed@swapkit/types@0.0.0-nightly-20240404190857(transitive)