crosslightning-sdk-base
Advanced tools
@@ -10,4 +10,8 @@ import { ISwapPrice } from "../swaps/ISwapPrice"; | ||
| }; | ||
| export type CoinAddresses = { | ||
| [token in "USDC" | "USDT" | "WBTC" | "ETH"]?: string; | ||
| }; | ||
| export declare class CoinGeckoSwapPrice extends ISwapPrice { | ||
| static createCoinsMap(wbtcAdress?: string, usdcAddress?: string, usdtAddress?: string): CoinsMapType; | ||
| static createCoinsMapFromTokens(tokens: CoinAddresses, nativeTokenCoinGeckoId?: string): CoinsMapType; | ||
| url: string; | ||
@@ -24,2 +28,3 @@ COINS_MAP: CoinsMapType; | ||
| getToBtcSwapAmount(fromAmount: BN, fromToken: TokenAddress): Promise<BN>; | ||
| shouldIgnore(tokenAddress: TokenAddress): boolean; | ||
| } |
@@ -41,2 +41,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| } | ||
| static createCoinsMapFromTokens(tokens, nativeTokenCoinGeckoId) { | ||
| const coinMap = {}; | ||
| if (tokens.WBTC != null) { | ||
| coinMap[tokens.WBTC] = { | ||
| coinId: "wrapped-bitcoin", | ||
| decimals: 8 | ||
| }; | ||
| } | ||
| if (tokens.USDC != null) { | ||
| coinMap[tokens.USDC] = { | ||
| coinId: "usd-coin", | ||
| decimals: 6 | ||
| }; | ||
| } | ||
| if (tokens.USDT != null) { | ||
| coinMap[tokens.USDT] = { | ||
| coinId: "tether", | ||
| decimals: 6 | ||
| }; | ||
| } | ||
| if (tokens.ETH != null || nativeTokenCoinGeckoId != null) { | ||
| coinMap[tokens.ETH] = { | ||
| coinId: nativeTokenCoinGeckoId, | ||
| decimals: 18 | ||
| }; | ||
| } | ||
| return coinMap; | ||
| } | ||
| constructor(maxAllowedFeeDiffPPM, coinsMap, url) { | ||
@@ -124,2 +152,8 @@ super(maxAllowedFeeDiffPPM); | ||
| } | ||
| shouldIgnore(tokenAddress) { | ||
| const coin = this.COINS_MAP[tokenAddress]; | ||
| if (coin == null) | ||
| throw new Error("Token not found"); | ||
| return coin.coinId === "$ignore"; | ||
| } | ||
| } |
@@ -22,2 +22,3 @@ import * as BN from "bn.js"; | ||
| abstract getFromBtcSwapAmount(fromAmount: BN, toToken: TokenAddress): Promise<BN>; | ||
| abstract shouldIgnore(tokenAddress: TokenAddress): boolean; | ||
| } |
@@ -17,2 +17,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| if (this.shouldIgnore(token)) | ||
| return true; | ||
| const totalSats = amountSats.mul(new BN(1000000).add(feePPM)).div(new BN(1000000)) | ||
@@ -32,2 +34,4 @@ .add(satsBaseFee); | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| if (this.shouldIgnore(token)) | ||
| return true; | ||
| const totalSats = amountSats.mul(new BN(1000000).sub(feePPM)).div(new BN(1000000)) | ||
@@ -34,0 +38,0 @@ .sub(satsBaseFee); |
+1
-1
| { | ||
| "name": "crosslightning-sdk-base", | ||
| "version": "2.0.4", | ||
| "version": "2.0.5", | ||
| "description": "CrossLightning SDK chain-agnostic base", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -14,2 +14,6 @@ import {ISwapPrice} from "../swaps/ISwapPrice"; | ||
| export type CoinAddresses = { | ||
| [token in "USDC" | "USDT" | "WBTC" | "ETH"]?: string; | ||
| }; | ||
| export class CoinGeckoSwapPrice extends ISwapPrice { | ||
@@ -49,2 +53,35 @@ | ||
| static createCoinsMapFromTokens(tokens: CoinAddresses, nativeTokenCoinGeckoId?: string): CoinsMapType { | ||
| const coinMap = {}; | ||
| if(tokens.WBTC!=null) { | ||
| coinMap[tokens.WBTC] = { | ||
| coinId: "wrapped-bitcoin", | ||
| decimals: 8 | ||
| }; | ||
| } | ||
| if(tokens.USDC!=null) { | ||
| coinMap[tokens.USDC] = { | ||
| coinId: "usd-coin", | ||
| decimals: 6 | ||
| }; | ||
| } | ||
| if(tokens.USDT!=null) { | ||
| coinMap[tokens.USDT] = { | ||
| coinId: "tether", | ||
| decimals: 6 | ||
| }; | ||
| } | ||
| if(tokens.ETH!=null || nativeTokenCoinGeckoId!=null) { | ||
| coinMap[tokens.ETH] = { | ||
| coinId: nativeTokenCoinGeckoId, | ||
| decimals: 18 | ||
| }; | ||
| } | ||
| return coinMap; | ||
| } | ||
| url: string; | ||
@@ -145,2 +182,10 @@ COINS_MAP: CoinsMapType = { | ||
| shouldIgnore(tokenAddress: TokenAddress): boolean { | ||
| const coin = this.COINS_MAP[tokenAddress]; | ||
| if(coin==null) throw new Error("Token not found"); | ||
| return coin.coinId==="$ignore"; | ||
| } | ||
| } |
@@ -13,2 +13,4 @@ import * as BN from "bn.js"; | ||
| async isValidAmountSend(amountSats: BN,satsBaseFee: BN, feePPM: BN, paidToken: BN, token: TokenAddress): Promise<boolean> { | ||
| if(this.shouldIgnore(token)) return true; | ||
| const totalSats = amountSats.mul(new BN(1000000).add(feePPM)).div(new BN(1000000)) | ||
@@ -33,2 +35,4 @@ .add(satsBaseFee); | ||
| async isValidAmountReceive(amountSats: BN,satsBaseFee: BN, feePPM: BN, receiveToken: BN, token: TokenAddress): Promise<boolean> { | ||
| if(this.shouldIgnore(token)) return true; | ||
| const totalSats = amountSats.mul(new BN(1000000).sub(feePPM)).div(new BN(1000000)) | ||
@@ -68,2 +72,4 @@ .sub(satsBaseFee); | ||
| abstract shouldIgnore(tokenAddress: TokenAddress): boolean; | ||
| } |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
434606
0.67%9826
0.85%