@mayanfinance/blink-sdk 0.1.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2026 Mayan Finance
3
+
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21
+ OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Blink SDK
2
+
3
+ A package for creating and tracking Blink orders.
4
+
5
+ ```
6
+ npm install @mayanfinance/blink-sdk
7
+ ```
8
+
9
+ ```ts
10
+ import { createBlinkClient } from "@mayanfinance/blink-sdk";
11
+
12
+ const { blink } = createBlinkClient({ apiKey: process.env.BLINK_API_KEY });
13
+ ```
14
+
15
+ The client talks to `https://api.hular.dev` unless `baseUrl` is passed. Full documentation is at https://docs.hular.dev.
@@ -0,0 +1,4 @@
1
+ export declare const parseAmount: (value: string, decimals: number) => bigint;
2
+ export declare const formatAmount: (raw: string | bigint, decimals?: number) => string;
3
+ export declare const trimAmount: (value: string, digits: number) => string;
4
+ export declare const formatUsdMicros: (micros: string) => string;
package/dist/amount.js ADDED
@@ -0,0 +1,32 @@
1
+ export const parseAmount = (value, decimals) => {
2
+ const [whole, fraction = ""] = value.trim().split(".");
3
+ const padded = fraction.slice(0, decimals).padEnd(decimals, "0");
4
+ return BigInt(`${whole === "" ? "0" : whole}${padded}`);
5
+ };
6
+ export const formatAmount = (raw, decimals) => {
7
+ const value = raw.toString();
8
+ if (decimals === undefined) {
9
+ return value;
10
+ }
11
+ const negative = value.startsWith("-");
12
+ const digits = (negative ? value.slice(1) : value).padStart(decimals + 1, "0");
13
+ const whole = digits.slice(0, digits.length - decimals);
14
+ const fraction = digits.slice(digits.length - decimals).replace(/0+$/, "");
15
+ return `${negative ? "-" : ""}${whole}${fraction ? `.${fraction}` : ""}`;
16
+ };
17
+ export const trimAmount = (value, digits) => {
18
+ const [whole, fraction] = value.split(".");
19
+ if (!fraction) {
20
+ return whole;
21
+ }
22
+ const cut = fraction.slice(0, digits).replace(/0+$/, "");
23
+ return cut ? `${whole}.${cut}` : whole;
24
+ };
25
+ export const formatUsdMicros = (micros) => {
26
+ const value = Number(micros) / 1_000_000;
27
+ return value.toLocaleString(undefined, {
28
+ style: "currency",
29
+ currency: "USD",
30
+ maximumFractionDigits: value < 1 ? 4 : 2,
31
+ });
32
+ };
@@ -0,0 +1,17 @@
1
+ import { type Client } from "@connectrpc/connect";
2
+ import { BlinkApi } from "./gen/blink/v1/api_pb.js";
3
+ import { AdminApi } from "./gen/blink/v1/admin_pb.js";
4
+ import { PartnerApi } from "./gen/blink/v1/partner_pb.js";
5
+ export declare const BLINK_API_URL = "https://api.hular.dev";
6
+ export interface BlinkClientOptions {
7
+ baseUrl?: string;
8
+ apiKey?: string;
9
+ token?: () => string | null;
10
+ telemetry?: boolean;
11
+ }
12
+ export interface BlinkClient {
13
+ blink: Client<typeof BlinkApi>;
14
+ partner: Client<typeof PartnerApi>;
15
+ admin: Client<typeof AdminApi>;
16
+ }
17
+ export declare const createBlinkClient: ({ baseUrl, apiKey, token, telemetry, }: BlinkClientOptions) => BlinkClient;
package/dist/client.js ADDED
@@ -0,0 +1,32 @@
1
+ import { createClient } from "@connectrpc/connect";
2
+ import { createGrpcWebTransport } from "@connectrpc/connect-web";
3
+ import { BlinkApi } from "./gen/blink/v1/api_pb.js";
4
+ import { AdminApi } from "./gen/blink/v1/admin_pb.js";
5
+ import { PartnerApi } from "./gen/blink/v1/partner_pb.js";
6
+ import { SDK_VERSION } from "./version.js";
7
+ export const BLINK_API_URL = "https://api.hular.dev";
8
+ export const createBlinkClient = ({ baseUrl = BLINK_API_URL, apiKey, token, telemetry = true, }) => {
9
+ const headers = (next) => (req) => {
10
+ if (apiKey) {
11
+ req.header.set("x-api-key", apiKey);
12
+ }
13
+ const session = token?.();
14
+ if (session) {
15
+ req.header.set("authorization", `Bearer ${session}`);
16
+ }
17
+ if (telemetry) {
18
+ req.header.set("x-blink-sdk-version", SDK_VERSION);
19
+ req.header.set("x-blink-sdk-platform", typeof window === "undefined" ? "node" : "browser");
20
+ }
21
+ return next(req);
22
+ };
23
+ const transport = createGrpcWebTransport({
24
+ baseUrl,
25
+ interceptors: [headers],
26
+ });
27
+ return {
28
+ blink: createClient(BlinkApi, transport),
29
+ partner: createClient(PartnerApi, transport),
30
+ admin: createClient(AdminApi, transport),
31
+ };
32
+ };
@@ -0,0 +1,64 @@
1
+ import type { BlinkClient } from "./client.js";
2
+ import type { ChainStatus, OrderParams } from "./gen/blink/v1/api_pb.js";
3
+ import { type ConnectedWallet, type WalletKind } from "./wallets.js";
4
+ export interface DepositStep {
5
+ kind: "approve" | "deposit";
6
+ fee?: bigint;
7
+ run: () => Promise<string>;
8
+ }
9
+ export interface GaslessQuote {
10
+ sponsorAddress?: string;
11
+ sponsorGasBudget?: bigint;
12
+ depositDeadline?: string;
13
+ }
14
+ export interface DepositOptions {
15
+ directTransfer?: boolean;
16
+ depositDeadline?: string;
17
+ }
18
+ export interface ChainAdapter {
19
+ readonly kind: WalletKind;
20
+ balance(owner: string, token: string): Promise<bigint>;
21
+ canPayGas(owner: string): Promise<boolean>;
22
+ steps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, options?: DepositOptions): Promise<DepositStep[]>;
23
+ gaslessSteps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, quote: GaslessQuote): Promise<DepositStep[]>;
24
+ }
25
+ export declare class InsufficientGasError extends Error {
26
+ readonly required: bigint;
27
+ readonly balance: bigint;
28
+ constructor(symbol: string, decimals: number, required: bigint, balance: bigint);
29
+ }
30
+ export declare class EvmChainAdapter implements ChainAdapter {
31
+ private client;
32
+ private chain;
33
+ private chainId;
34
+ readonly kind = "evm";
35
+ constructor(client: BlinkClient, chain: ChainStatus, chainId: bigint);
36
+ balance(owner: string, token: string): Promise<bigint>;
37
+ canPayGas(owner: string): Promise<boolean>;
38
+ private gasWithAllowance;
39
+ private assertCanPay;
40
+ steps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, options?: DepositOptions): Promise<DepositStep[]>;
41
+ gaslessSteps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, quote: GaslessQuote): Promise<DepositStep[]>;
42
+ }
43
+ export declare class SvmChainAdapter implements ChainAdapter {
44
+ private chain;
45
+ private client?;
46
+ readonly kind = "svm";
47
+ constructor(chain: ChainStatus, client?: BlinkClient | undefined);
48
+ balance(owner: string, token: string): Promise<bigint>;
49
+ canPayGas(owner: string): Promise<boolean>;
50
+ steps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, options?: DepositOptions): Promise<DepositStep[]>;
51
+ gaslessSteps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, quote: GaslessQuote): Promise<DepositStep[]>;
52
+ }
53
+ export declare class SuiChainAdapter implements ChainAdapter {
54
+ private chain;
55
+ private client?;
56
+ readonly kind = "sui";
57
+ constructor(chain: ChainStatus, client?: BlinkClient | undefined);
58
+ balance(owner: string, token: string): Promise<bigint>;
59
+ canPayGas(owner: string): Promise<boolean>;
60
+ steps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, options?: DepositOptions): Promise<DepositStep[]>;
61
+ gaslessSteps(wallet: ConnectedWallet, quoteHash: string, params: OrderParams, quote: GaslessQuote): Promise<DepositStep[]>;
62
+ }
63
+ export declare const createChainAdapter: (client: BlinkClient, chain: ChainStatus, chainId?: bigint) => ChainAdapter;
64
+ export declare const walletKindOf: (chain?: ChainStatus) => WalletKind;