Socket
Socket
Sign inDemoInstall

@swapkit/helpers

Package Overview
Dependencies
3
Maintainers
2
Versions
135
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0-nightly-20240503191507 to 0.0.0-nightly-20240530180405

src/types/errors/apiV1.ts

14

package.json

@@ -5,12 +5,14 @@ {

"dependencies": {
"ky": "1.2.3"
"ky": "1.2.3",
"zod": "3.23.8"
},
"devDependencies": {
"@swapkit/tokens": "0.0.0-nightly-20240503191507",
"bun-types": "1.1.2",
"@swapkit/tokens": "0.0.0-nightly-20240530180405",
"bun-types": "1.1.8",
"ethers": "6.11.1"
},
"peerDependencies": {
"@swapkit/tokens": "0.0.0-nightly-20240503191507",
"ky": "1.2.3"
"@swapkit/tokens": "0.0.0-nightly-20240530180405",
"ky": "1.2.3",
"zod": "3.23.8"
},

@@ -40,3 +42,3 @@ "files": [

"types": "./src/index.ts",
"version": "0.0.0-nightly-20240503191507"
"version": "0.0.0-nightly-20240530180405"
}

@@ -10,4 +10,5 @@ import {

type Params = {
chain: Chain;
index: number;
chain: Chain;
addressIndex?: number;
type?: "legacy" | "ledgerLive" | "nativeSegwitMiddleAccount" | "segwit";

@@ -21,6 +22,6 @@ };

export function getDerivationPathFor({ chain, index, type }: Params) {
export function getDerivationPathFor({ chain, index, addressIndex = 0, type }: Params) {
if (EVMChains.includes(chain as EVMChain)) {
if (type === "legacy") return [44, 60, 0, index];
if (type === "ledgerLive") return [44, 60, index, 0, 0];
if (type === "ledgerLive") return [44, 60, index, 0, addressIndex];
return updatedLastIndex(NetworkDerivationPath[chain], index);

@@ -32,3 +33,3 @@ }

if (type === "nativeSegwitMiddleAccount") return [84, chainId, index, 0, 0];
if (type === "nativeSegwitMiddleAccount") return [84, chainId, index, 0, addressIndex];
if (type === "segwit") return [49, chainId, 0, 0, index];

@@ -35,0 +36,0 @@ if (type === "legacy") return [44, chainId, 0, 0, index];

import type { BrowserProvider } from "ethers";
import { ChainId, WalletOption } from "../types";
import {
ChainId,
type EIP6963AnnounceProviderEvent,
type EIP6963Provider,
WalletOption,
} from "../types";

@@ -145,3 +150,3 @@ export type EthereumWindowProvider = BrowserProvider & {

const listWeb3EVMWallets = () => {
export const listWeb3EVMWallets = () => {
const metamaskEnabled = window?.ethereum && !window.ethereum?.isBraveWallet;

@@ -168,2 +173,20 @@ // @ts-ignore that should be implemented in xdefi and hooked up via swapkit core

export function getEIP6963Wallets() {
const providers: EIP6963Provider[] = [];
function onAnnouncement(event: EIP6963AnnounceProviderEvent) {
if (providers.map((p) => p.info.uuid).includes(event.detail.info.uuid)) return;
providers.push(event.detail);
}
window.addEventListener("eip6963:announceProvider", onAnnouncement);
window.dispatchEvent(new Event("eip6963:requestProvider"));
function removeEIP6963EventListener() {
window.removeEventListener("eip6963:announceProvider", onAnnouncement);
}
return { providers, removeEIP6963EventListener };
}
export const okxMobileEnabled = () => {

@@ -170,0 +193,0 @@ const ua = navigator.userAgent;

@@ -1,2 +0,2 @@

import type { Options } from "ky";
import type { KyInstance, Options } from "ky";
import ky from "ky";

@@ -24,7 +24,16 @@

const getTypedBaseRequestClient = (ky: KyInstance) => ({
get: <T>(url: string | URL | Request, options?: Options) => ky.get(url, options).json<T>(),
post: <T>(url: string | URL | Request, options?: Options) => ky.post(url, options).json<T>(),
});
export const RequestClient = {
get: <T>(url: string | URL | Request, options?: Options) =>
getKyClient().get(url, options).json<T>(),
post: <T>(url: string | URL | Request, options?: Options) =>
getKyClient().post(url, options).json<T>(),
...getTypedBaseRequestClient(getKyClient()),
extend: (options: Options) => {
const extendedClient = getKyClient().extend(options);
return {
...getTypedBaseRequestClient(extendedClient),
extend: RequestClient.extend,
};
},
};

@@ -12,2 +12,3 @@ const errorMessages = {

core_plugin_swap_not_found: 10007,
core_approve_asset_target_invalid: 10008,
core_chain_halted: 10099,

@@ -77,2 +78,7 @@

/**
* SwapKit API
*/
api_v2_invalid_response: 40001,
/**
* Helpers

@@ -79,0 +85,0 @@ */

@@ -21,2 +21,3 @@ import { ExplorerUrl, RPCUrl } from "./network";

Polygon = "MATIC",
Radix = "RADIX",
THORChain = "THOR",

@@ -50,2 +51,3 @@ }

PolygonHex = "0x89",
Radix = "radix-mainnet",
THORChain = "thorchain-mainnet-v1",

@@ -80,2 +82,3 @@ THORChainStagenet = "thorchain-stagenet-v2",

[ChainId.Polygon]: Chain.Polygon,
[ChainId.Radix]: Chain.Radix,
[ChainId.THORChainStagenet]: Chain.THORChain,

@@ -109,2 +112,4 @@ [ChainId.THORChain]: Chain.THORChain,

ZEC = 8,
// TODO do some research on this
RADIX = 8,
}

@@ -111,0 +116,0 @@

@@ -30,2 +30,3 @@ import type { Chain } from "./chains";

OP = "m/44'/60'/0'/0",
RADIX = "////",
THOR = "m/44'/931'/0'/0",

@@ -55,4 +56,5 @@ }

// Polkadot and related network derivation path is not number based
RADIX: [0, 0, 0, 0, 0],
DOT: [0, 0, 0, 0, 0],
FLIP: [0, 0, 0, 0, 0],
};

@@ -11,1 +11,2 @@ export * from "./abis/erc20";

export * from "./sdk";
export * from "./quotes";

@@ -20,2 +20,3 @@ export enum RPCUrl {

Polygon = "https://polygon-rpc.com",
Radix = "https://radix-mainnet.rpc.grove.city/v1/326002fc/core",
THORChain = "https://rpc.thorswap.net",

@@ -43,3 +44,4 @@ THORChainStagenet = "https://stagenet-rpc.ninerealms.com",

Polygon = "https://polygonscan.com",
Radix = "https://dashboard.radixdlt.com",
THORChain = "https://runescan.io",
}

@@ -0,11 +1,15 @@

import { z } from "zod";
import type { AssetValue } from "../modules/assetValue";
import type { QuoteResponseRoute } from "./quotes";
export type GenericSwapParams = {
buyAsset: AssetValue;
sellAsset: AssetValue;
recipient: string;
buyAsset?: AssetValue;
sellAsset?: AssetValue;
recipient?: string;
feeOptionKey?: FeeOption;
route: QuoteResponseRoute;
};
export type SwapParams<PluginNames = string, T = GenericSwapParams> = T & {
pluginName: PluginNames;
pluginName?: PluginNames;
};

@@ -45,1 +49,79 @@

}
export const QuoteRequestSchema = z
.object({
sellAsset: z.string({
description: "Asset to sell",
}),
buyAsset: z.string({
description: "Asset to buy",
}),
sellAmount: z
.number({
description: "Amount of asset to sell",
})
.refine((amount) => amount > 0, {
message: "sellAmount must be greater than 0",
path: ["sellAmount"],
}),
providers: z.optional(
z.array(
z.string({
description: "List of providers to use",
}),
),
),
sourceAddress: z.optional(
z.string({
description: "Address to send asset from",
}),
),
destinationAddress: z.optional(
z.string({
description: "Address to send asset to",
}),
),
slippage: z.optional(
z.number({
description: "Slippage tolerance as a percentage. Default is 3%.",
}),
),
affiliate: z.optional(
z.string({
description: "Affiliate thorname",
}),
),
affiliateFee: z.optional(
z
.number({
description: "Affiliate fee in basis points",
})
.refine(
(fee) => {
return fee === Math.floor(fee) && fee >= 0;
},
{ message: "affiliateFee must be a positive integer", path: ["affiliateFee"] },
),
),
allowSmartContractSender: z.optional(
z.boolean({
description: "Allow smart contract as sender",
}),
),
allowSmartContractReceiver: z.optional(
z.boolean({
description: "Allow smart contract as recipient",
}),
),
disableSecurityChecks: z.optional(
z.boolean({
description: "Disable security checks",
}),
),
})
.refine((data) => data.sellAsset !== data.buyAsset, {
message: "Must be different",
path: ["sellAsset", "buyAsset"],
});
export type QuoteRequest = z.infer<typeof QuoteRequestSchema>;

@@ -5,5 +5,12 @@ import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolbox-cosmos";

import type { UTXOWallets } from "@swapkit/toolbox-utxo";
import type { Eip1193Provider } from "ethers";
import type { AssetValue } from "../modules/assetValue";
import type { Chain } from "./chains";
declare global {
interface WindowEventMap {
"eip6963:announceProvider": CustomEvent;
}
}
export enum WalletOption {

@@ -24,2 +31,5 @@ KEYSTORE = "KEYSTORE",

WALLETCONNECT = "WALLETCONNECT",
EIP6963 = "EIP6963",
EXODUS = "EXODUS",
RADIX_WALLET = "RADIX_WALLET",
}

@@ -50,1 +60,23 @@

>;
export type EIP6963ProviderInfo = {
walletId: string;
uuid: string;
name: string;
icon: string;
};
export type EIP6963ProviderDetail = {
info: EIP6963ProviderInfo;
provider: Eip1193Provider;
};
export type EIP6963Provider = {
info: EIP6963ProviderInfo;
provider: Eip1193Provider;
};
// This type represents the structure of an event dispatched by a wallet to announce its presence based on EIP-6963.
export type EIP6963AnnounceProviderEvent = Event & {
detail: EIP6963Provider;
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc