@swapkit/helpers 1.0.0-rc.85 → 1.0.0-rc.87
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/dist/index.js +1040 -46
- package/dist/index.js.map +19 -14
- package/package.json +7 -9
- package/src/helpers/__tests__/asset.test.ts +1 -1
- package/src/helpers/__tests__/memo.test.ts +1 -1
- package/src/helpers/__tests__/others.test.ts +1 -1
- package/src/helpers/asset.ts +4 -4
- package/src/helpers/liquidity.ts +1 -2
- package/src/helpers/memo.ts +2 -1
- package/src/helpers/others.ts +1 -1
- package/src/helpers/validators.ts +1 -1
- package/src/index.ts +3 -1
- package/src/modules/__tests__/assetValue.test.ts +1 -1
- package/src/modules/assetValue.ts +4 -7
- package/src/modules/bigIntArithmetics.ts +1 -2
- package/src/modules/requestClient.ts +29 -0
- package/src/types/abis/erc20.ts +99 -0
- package/src/types/abis/tcEthVault.ts +496 -0
- package/src/types/chains.ts +219 -0
- package/src/types/commonTypes.ts +140 -0
- package/src/types/derivationPath.ts +56 -0
- package/src/types/index.ts +10 -0
- package/src/types/network.ts +43 -0
- package/src/types/sdk.ts +32 -0
- package/src/types/transactions.ts +71 -0
- package/src/types/wallet.ts +45 -0
- /package/src/{types.ts → types/tokens.ts} +0 -0
package/package.json
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"description": "SwapKit - Helpers",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"
|
|
5
|
+
"ky": "1.2.3"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
9
|
-
"
|
|
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/
|
|
14
|
-
"
|
|
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
|
|
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.
|
|
38
|
+
"version": "1.0.0-rc.87"
|
|
41
39
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { Chain, type DerivationPathArray } from "@swapkit/
|
|
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";
|
package/src/helpers/asset.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RequestClient } from "
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
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
|
|
package/src/helpers/liquidity.ts
CHANGED
package/src/helpers/memo.ts
CHANGED
package/src/helpers/others.ts
CHANGED
|
@@ -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
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "
|
|
1
|
+
export * from "./types/index.ts";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Helpers
|
|
@@ -7,11 +7,13 @@ export * from "./helpers/asset.ts";
|
|
|
7
7
|
export * from "./helpers/liquidity.ts";
|
|
8
8
|
export * from "./helpers/memo.ts";
|
|
9
9
|
export * from "./helpers/others.ts";
|
|
10
|
+
export * from "./helpers/validators.ts";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Modules
|
|
13
14
|
*/
|
|
14
15
|
export * from "./modules/assetValue.ts";
|
|
15
16
|
export * from "./modules/bigIntArithmetics.ts";
|
|
17
|
+
export * from "./modules/requestClient.ts";
|
|
16
18
|
export * from "./modules/swapKitError.ts";
|
|
17
19
|
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
|
|
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
|
|
@@ -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
|
+
];
|