@nimiq/fastspot-api
Advanced tools
Comparing version 1.8.0 to 1.9.0
import { RequestAsset, SwapAsset, Estimate, PreSwap, ContractWithEstimate, Swap, Limits, UserLimits, AssetList, ReferralCodes } from './types'; | ||
export declare function init(url: string, key: string, referral?: ReferralCodes): void; | ||
export declare function init(url: string, key: string, options?: Partial<{ | ||
referral?: ReferralCodes; | ||
customFetch?: typeof fetch; | ||
}>): void; | ||
export declare function getEstimate(from: RequestAsset<SwapAsset>, to: SwapAsset): Promise<Estimate>; | ||
@@ -16,2 +19,4 @@ export declare function getEstimate(from: SwapAsset, to: RequestAsset<SwapAsset>): Promise<Estimate>; | ||
y?: string; | ||
} | { | ||
asset: SwapAsset.BTC_LN; | ||
}, refund?: { | ||
@@ -18,0 +23,0 @@ asset: SwapAsset.NIM | SwapAsset.BTC | SwapAsset.USDC | SwapAsset.USDC_MATIC; |
@@ -15,3 +15,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
let REFERRAL; | ||
export function init(url, key, referral) { | ||
let FETCH; | ||
export function init(url, key, options) { | ||
if (!url || !key) | ||
@@ -21,3 +22,4 @@ throw new Error('url and key must be provided'); | ||
API_KEY = key; | ||
REFERRAL = referral; | ||
REFERRAL = options === null || options === void 0 ? void 0 : options.referral; | ||
FETCH = (options === null || options === void 0 ? void 0 : options.customFetch) || fetch; | ||
} | ||
@@ -28,3 +30,3 @@ function api(path, method, options) { | ||
throw new Error('API URL and key not set, call init() first'); | ||
const response = yield fetch(`${API_URL}${path}`, Object.assign({ method, headers: Object.assign({ 'Content-Type': 'application/json', 'X-FAST-ApiKey': API_KEY }, options === null || options === void 0 ? void 0 : options.headers) }, ((options === null || options === void 0 ? void 0 : options.body) ? { body: JSON.stringify(options.body) } : {}))); | ||
const response = yield FETCH(`${API_URL}${path}`, Object.assign({ method, headers: Object.assign({ 'Content-Type': 'application/json', 'X-FAST-ApiKey': API_KEY }, options === null || options === void 0 ? void 0 : options.headers) }, ((options === null || options === void 0 ? void 0 : options.body) ? { body: JSON.stringify(options.body) } : {}))); | ||
if (!response.ok) { | ||
@@ -96,3 +98,5 @@ const error = yield response.json(); | ||
? { [redeem.asset]: Object.assign({ kty: redeem.kty, crv: redeem.crv, x: redeem.x }, (redeem.y ? { y: redeem.y } : {})) } | ||
: { [redeem.asset]: redeem.address } }, (refund ? { refund: { [refund.asset]: 'address' in refund ? refund.address : '' } } : {})), (uid ? { uid } : {})), | ||
: redeem.asset === SwapAsset.BTC_LN | ||
? {} | ||
: { [redeem.asset]: redeem.address } }, (refund ? { refund: { [refund.asset]: 'address' in refund ? refund.address : '' } } : {})), (uid ? { uid } : {})), | ||
}); | ||
@@ -99,0 +103,0 @@ return convertSwap(result); |
@@ -42,2 +42,7 @@ import { SwapAsset, Precision, } from './types'; | ||
break; | ||
case SwapAsset.BTC_LN: | ||
htlc = { | ||
nodeId: contract.intermediary.nodeId, | ||
}; | ||
break; | ||
case SwapAsset.USDC: | ||
@@ -60,2 +65,3 @@ case SwapAsset.USDC_MATIC: | ||
return { | ||
id: contract.id, | ||
asset: contract.asset, | ||
@@ -62,0 +68,0 @@ refundAddress: ((_a = contract.refund) === null || _a === void 0 ? void 0 : _a.address) || '', |
export declare enum SwapAsset { | ||
NIM = "NIM", | ||
BTC = "BTC", | ||
BTC_LN = "BTC_LN", | ||
USDC = "USDC", | ||
@@ -18,2 +19,3 @@ USDC_MATIC = "USDC_MATIC", | ||
readonly BTC: 8; | ||
readonly BTC_LN: 8; | ||
readonly USDC: 6; | ||
@@ -86,3 +88,3 @@ readonly USDC_MATIC: 6; | ||
address: string; | ||
}; | ||
} | null; | ||
recipient: T extends SwapAsset.EUR ? { | ||
@@ -109,2 +111,7 @@ kty: string; | ||
scriptBytes: string; | ||
} : T extends SwapAsset.BTC_LN ? { | ||
nodeId: string; | ||
amount: string; | ||
hash: string; | ||
request: string; | ||
} : T extends SwapAsset.USDC | SwapAsset.USDC_MATIC ? { | ||
@@ -204,2 +211,5 @@ address: string; | ||
}; | ||
export declare type BtcLnHtlcDetails = { | ||
nodeId: string; | ||
}; | ||
export declare type EurHtlcDetails = { | ||
@@ -213,4 +223,5 @@ address: string; | ||
}; | ||
export declare type HtlcDetails = NimHtlcDetails | BtcHtlcDetails | UsdcHtlcDetails | EurHtlcDetails; | ||
export declare type HtlcDetails = NimHtlcDetails | BtcHtlcDetails | BtcLnHtlcDetails | UsdcHtlcDetails | EurHtlcDetails; | ||
export declare type Contract<T extends SwapAsset> = { | ||
id: string; | ||
asset: T; | ||
@@ -223,3 +234,3 @@ refundAddress: string; | ||
status: ContractStatus; | ||
htlc: T extends SwapAsset.NIM ? NimHtlcDetails : T extends SwapAsset.BTC ? BtcHtlcDetails : T extends SwapAsset.USDC | SwapAsset.USDC_MATIC ? UsdcHtlcDetails : T extends SwapAsset.EUR ? EurHtlcDetails : never; | ||
htlc: T extends SwapAsset.NIM ? NimHtlcDetails : T extends SwapAsset.BTC ? BtcHtlcDetails : T extends SwapAsset.BTC_LN ? BtcLnHtlcDetails : T extends SwapAsset.USDC | SwapAsset.USDC_MATIC ? UsdcHtlcDetails : T extends SwapAsset.EUR ? EurHtlcDetails : never; | ||
}; | ||
@@ -226,0 +237,0 @@ export declare type ContractWithEstimate<T extends SwapAsset> = Estimate & { |
@@ -5,2 +5,3 @@ export var SwapAsset; | ||
SwapAsset["BTC"] = "BTC"; | ||
SwapAsset["BTC_LN"] = "BTC_LN"; | ||
SwapAsset["USDC"] = "USDC"; | ||
@@ -17,2 +18,3 @@ SwapAsset["USDC_MATIC"] = "USDC_MATIC"; | ||
[SwapAsset.BTC]: 8, | ||
[SwapAsset.BTC_LN]: 8, | ||
[SwapAsset.USDC]: 6, | ||
@@ -19,0 +21,0 @@ [SwapAsset.USDC_MATIC]: 6, |
{ | ||
"name": "@nimiq/fastspot-api", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Typescript library to interact with the Fastspot API", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:nimiq/fastspot-api.git", |
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
38534
702