@swapkit/helpers 1.0.0-rc.85 → 1.0.0-rc.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,17 +2,15 @@
2
2
  "author": "swapkit-oss",
3
3
  "description": "SwapKit - Helpers",
4
4
  "dependencies": {
5
- "@swapkit/api": "1.0.0-rc.50"
5
+ "ky": "1.2.3"
6
6
  },
7
7
  "devDependencies": {
8
- "@swapkit/tokens": "1.0.0-rc.46",
9
- "@swapkit/types": "1.0.0-rc.49",
10
- "bun-types": "1.1.1"
8
+ "@swapkit/tokens": "1.0.0-rc.47",
9
+ "bun-types": "1.1.2"
11
10
  },
12
11
  "peerDependencies": {
13
- "@swapkit/api": "1.0.0-rc.50",
14
- "@swapkit/tokens": "1.0.0-rc.46",
15
- "@swapkit/types": "1.0.0-rc.49"
12
+ "@swapkit/tokens": "1.0.0-rc.47",
13
+ "ky": "1.2.3"
16
14
  },
17
15
  "files": [
18
16
  "src/",
@@ -29,7 +27,7 @@
29
27
  },
30
28
  "scripts": {
31
29
  "build": "bun run ./build.ts",
32
- "clean": "rm -rf .turbo dist node_modules tsconfig.tsbuildinfo",
30
+ "clean": "rm -rf .turbo dist node_modules *.tsbuildinfo",
33
31
  "lint": "biome check --apply ./src",
34
32
  "test": "bun test",
35
33
  "test:coverage": "echo 'bun test --coverage'",
@@ -37,5 +35,5 @@
37
35
  },
38
36
  "type": "module",
39
37
  "types": "./src/index.ts",
40
- "version": "1.0.0-rc.85"
38
+ "version": "1.0.0-rc.86"
41
39
  }
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "bun:test";
2
- import { BaseDecimal, Chain } from "@swapkit/types";
2
+ import { BaseDecimal, Chain } from "@swapkit/helpers";
3
3
 
4
4
  import { getAssetType, getDecimal } from "../asset.ts";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "bun:test";
2
- import { Chain, MemoType } from "@swapkit/types";
2
+ import { Chain, MemoType } from "@swapkit/helpers";
3
3
 
4
4
  import { getMemoFor } from "../memo.ts";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "bun:test";
2
- import { Chain, type DerivationPathArray } from "@swapkit/types";
2
+ import { Chain, type DerivationPathArray } from "@swapkit/helpers";
3
3
 
4
4
  import { findAssetBy } from "../asset.ts";
5
5
  import { derivationPathToString, getTHORNameCost } from "../others.ts";
@@ -1,7 +1,7 @@
1
- import { RequestClient } from "@swapkit/api";
2
- import type { EVMChain } from "@swapkit/types";
3
- import { BaseDecimal, Chain, ChainToRPC, EVMChains, FeeOption } from "@swapkit/types";
4
- import type { TokenNames } from "../types.ts";
1
+ import { RequestClient } from "../modules/requestClient.ts";
2
+ import { BaseDecimal, Chain, ChainToRPC, type EVMChain, EVMChains } from "../types/chains.ts";
3
+ import type { TokenNames } from "../types/tokens.ts";
4
+ import { FeeOption } from "../types/transactions.ts";
5
5
 
6
6
  const getDecimalMethodHex = "0x313ce567";
7
7
 
@@ -1,6 +1,5 @@
1
- import { BaseDecimal } from "@swapkit/types";
2
-
3
1
  import { SwapKitNumber } from "../index.ts";
2
+ import { BaseDecimal } from "../types/chains.ts";
4
3
 
5
4
  type ShareParams<T extends {}> = T & {
6
5
  liquidityUnits: string;
@@ -1,4 +1,5 @@
1
- import { Chain, MemoType } from "@swapkit/types";
1
+ import { Chain } from "../types/chains";
2
+ import { MemoType } from "../types/transactions";
2
3
 
3
4
  export type ThornameRegisterParam = {
4
5
  name: string;
@@ -1,5 +1,5 @@
1
- import type { DerivationPathArray } from "@swapkit/types";
2
1
  import { type ErrorKeys, SwapKitError } from "../modules/swapKitError";
2
+ import type { DerivationPathArray } from "../types/derivationPath";
3
3
 
4
4
  // 10 rune for register, 1 rune per year
5
5
  // MINIMUM_REGISTRATION_FEE = 11
@@ -1,4 +1,4 @@
1
- import { Chain } from "@swapkit/types";
1
+ import { Chain } from "../types/chains";
2
2
 
3
3
  // Backward compatibility
4
4
  const supportedChains = [...Object.values(Chain), "TERRA"];
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "@swapkit/api";
1
+ export * from "./types/index.ts";
2
2
 
3
3
  /**
4
4
  * Helpers
@@ -13,5 +13,6 @@ export * from "./helpers/others.ts";
13
13
  */
14
14
  export * from "./modules/assetValue.ts";
15
15
  export * from "./modules/bigIntArithmetics.ts";
16
+ export * from "./modules/requestClient.ts";
16
17
  export * from "./modules/swapKitError.ts";
17
18
  export * from "./modules/swapKitNumber.ts";
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
- import { BaseDecimal, Chain } from "@swapkit/types";
3
2
 
3
+ import { BaseDecimal, Chain } from "../../types/chains.ts";
4
4
  import { AssetValue, getMinAmountByChain } from "../assetValue.ts";
5
5
 
6
6
  describe("AssetValue", () => {
@@ -1,9 +1,8 @@
1
- import { BaseDecimal, Chain, ChainToChainId } from "@swapkit/types";
2
-
3
1
  import type { CommonAssetString } from "../helpers/asset.ts";
4
2
  import { getAssetType, getCommonAssetInfo, getDecimal, isGasAsset } from "../helpers/asset.ts";
5
3
  import { validateIdentifier } from "../helpers/validators.ts";
6
- import type { TokenNames, TokenTax } from "../types.ts";
4
+ import { BaseDecimal, Chain, type ChainId, ChainToChainId } from "../types/chains.ts";
5
+ import type { TokenNames, TokenTax } from "../types/tokens.ts";
7
6
 
8
7
  import type { NumberPrimitives } from "./bigIntArithmetics.ts";
9
8
  import { BigIntArithmetics, formatBigIntToSafeValue } from "./bigIntArithmetics.ts";
@@ -23,6 +22,7 @@ export class AssetValue extends BigIntArithmetics {
23
22
  tax?: TokenTax;
24
23
  ticker: string;
25
24
  type: ReturnType<typeof getAssetType>;
25
+ chainId: ChainId;
26
26
 
27
27
  constructor({
28
28
  value,
@@ -47,6 +47,7 @@ export class AssetValue extends BigIntArithmetics {
47
47
  this.address = assetInfo.address;
48
48
  this.isSynthetic = assetInfo.isSynthetic;
49
49
  this.isGasAsset = assetInfo.isGasAsset;
50
+ this.chainId = ChainToChainId[assetInfo.chain];
50
51
  }
51
52
 
52
53
  toString() {
@@ -61,10 +62,6 @@ export class AssetValue extends BigIntArithmetics {
61
62
  return this.chain === chain && this.symbol === symbol;
62
63
  }
63
64
 
64
- chainId() {
65
- return ChainToChainId[this.chain];
66
- }
67
-
68
65
  // THOR.RUNE
69
66
  // THOR.ETH.ETH
70
67
  // ETH.THOR-0x1234567890
@@ -1,5 +1,4 @@
1
- import { BaseDecimal } from "@swapkit/types";
2
-
1
+ import { BaseDecimal } from "../types/chains.ts";
3
2
  import type { SwapKitNumber } from "./swapKitNumber.ts";
4
3
 
5
4
  type NumberPrimitivesType = {
@@ -0,0 +1,29 @@
1
+ import type { Options } from "ky";
2
+ import ky from "ky";
3
+
4
+ let kyClient: typeof ky;
5
+
6
+ export const defaultRequestHeaders =
7
+ typeof window !== "undefined"
8
+ ? ({} as Record<string, string>)
9
+ : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" };
10
+
11
+ export function setRequestClientConfig({ apiKey, ...config }: Options & { apiKey?: string }) {
12
+ kyClient = ky.create({
13
+ ...config,
14
+ headers: { ...defaultRequestHeaders, ...config.headers, "x-api-key": apiKey },
15
+ });
16
+ }
17
+
18
+ function getKyClient() {
19
+ if (kyClient) return kyClient;
20
+ kyClient = ky.create({ headers: defaultRequestHeaders });
21
+ return kyClient;
22
+ }
23
+
24
+ export const RequestClient = {
25
+ get: <T>(url: string | URL | Request, options?: Options) =>
26
+ getKyClient().get(url, options).json<T>(),
27
+ post: <T>(url: string | URL | Request, options?: Options) =>
28
+ getKyClient().post(url, options).json<T>(),
29
+ };
@@ -0,0 +1,99 @@
1
+ export const erc20ABI = [
2
+ { inputs: [], stateMutability: "nonpayable", type: "constructor" },
3
+ {
4
+ anonymous: false,
5
+ inputs: [
6
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
7
+ { indexed: true, internalType: "address", name: "spender", type: "address" },
8
+ { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
9
+ ],
10
+ name: "Approval",
11
+ type: "event",
12
+ },
13
+ {
14
+ anonymous: false,
15
+ inputs: [
16
+ { indexed: true, internalType: "address", name: "from", type: "address" },
17
+ { indexed: true, internalType: "address", name: "to", type: "address" },
18
+ { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
19
+ ],
20
+ name: "Transfer",
21
+ type: "event",
22
+ },
23
+ {
24
+ inputs: [
25
+ { internalType: "address", name: "", type: "address" },
26
+ { internalType: "address", name: "", type: "address" },
27
+ ],
28
+ name: "allowance",
29
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
30
+ stateMutability: "view",
31
+ type: "function",
32
+ },
33
+ {
34
+ inputs: [
35
+ { internalType: "address", name: "spender", type: "address" },
36
+ { internalType: "uint256", name: "value", type: "uint256" },
37
+ ],
38
+ name: "approve",
39
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
40
+ stateMutability: "nonpayable",
41
+ type: "function",
42
+ },
43
+ {
44
+ inputs: [{ internalType: "address", name: "", type: "address" }],
45
+ name: "balanceOf",
46
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
47
+ stateMutability: "view",
48
+ type: "function",
49
+ },
50
+ {
51
+ inputs: [],
52
+ name: "decimals",
53
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
54
+ stateMutability: "view",
55
+ type: "function",
56
+ },
57
+ {
58
+ inputs: [],
59
+ name: "name",
60
+ outputs: [{ internalType: "string", name: "", type: "string" }],
61
+ stateMutability: "view",
62
+ type: "function",
63
+ },
64
+ {
65
+ inputs: [],
66
+ name: "symbol",
67
+ outputs: [{ internalType: "string", name: "", type: "string" }],
68
+ stateMutability: "view",
69
+ type: "function",
70
+ },
71
+ {
72
+ inputs: [],
73
+ name: "totalSupply",
74
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
75
+ stateMutability: "view",
76
+ type: "function",
77
+ },
78
+ {
79
+ inputs: [
80
+ { internalType: "address", name: "to", type: "address" },
81
+ { internalType: "uint256", name: "value", type: "uint256" },
82
+ ],
83
+ name: "transfer",
84
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
85
+ stateMutability: "nonpayable",
86
+ type: "function",
87
+ },
88
+ {
89
+ inputs: [
90
+ { internalType: "address", name: "from", type: "address" },
91
+ { internalType: "address", name: "to", type: "address" },
92
+ { internalType: "uint256", name: "value", type: "uint256" },
93
+ ],
94
+ name: "transferFrom",
95
+ outputs: [{ internalType: "bool", name: "success", type: "bool" }],
96
+ stateMutability: "nonpayable",
97
+ type: "function",
98
+ },
99
+ ];