@piprail/sdk 1.0.0 → 1.1.1

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.
@@ -1,157 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13;// src/errors.ts
2
- var PipRailError = class extends Error {
3
- constructor(message, options) {
4
- super(message, options);
5
- this.name = this.constructor.name;
6
- }
7
- };
8
- var InsufficientFundsError = (_class = class extends PipRailError {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
9
- __init() {this.code = "INSUFFICIENT_FUNDS"}
10
- }, _class);
11
- function toInsufficientFundsError(err) {
12
- const message = err instanceof Error ? err.message : String(err);
13
- if (/insufficient (funds|balance|lamports|fee)|not enough|exceeds (the )?balance|underfunded|low[_ ]?reserve|debit the account/i.test(
14
- message
15
- )) {
16
- return new InsufficientFundsError(
17
- err instanceof Error ? err.message : "Insufficient funds for the payment.",
18
- { cause: err }
19
- );
20
- }
21
- return null;
22
- }
23
- var WrongChainError = (_class2 = class extends PipRailError {constructor(...args2) { super(...args2); _class2.prototype.__init2.call(this); }
24
- __init2() {this.code = "WRONG_CHAIN"}
25
- }, _class2);
26
- var PaymentTimeoutError = (_class3 = class extends PipRailError {constructor(...args3) { super(...args3); _class3.prototype.__init3.call(this); }
27
- __init3() {this.code = "PAYMENT_TIMEOUT"}
28
- }, _class3);
29
- var MaxRetriesExceededError = (_class4 = class extends PipRailError {constructor(...args4) { super(...args4); _class4.prototype.__init4.call(this); }
30
- __init4() {this.code = "MAX_RETRIES_EXCEEDED"}
31
- }, _class4);
32
- var PaymentDeclinedError = (_class5 = class extends PipRailError {constructor(...args5) { super(...args5); _class5.prototype.__init5.call(this); }
33
- __init5() {this.code = "PAYMENT_DECLINED"}
34
- }, _class5);
35
- var ConfirmationTimeoutError = (_class6 = class extends PipRailError {constructor(...args6) { super(...args6); _class6.prototype.__init6.call(this); }
36
- __init6() {this.code = "CONFIRMATION_TIMEOUT"}
37
- }, _class6);
38
- var InvalidEnvelopeError = (_class7 = class extends PipRailError {constructor(...args7) { super(...args7); _class7.prototype.__init7.call(this); }
39
- __init7() {this.code = "INVALID_ENVELOPE"}
40
- }, _class7);
41
- var NoCompatibleAcceptError = (_class8 = class extends PipRailError {constructor(...args8) { super(...args8); _class8.prototype.__init8.call(this); }
42
- __init8() {this.code = "NO_COMPATIBLE_ACCEPT"}
43
- }, _class8);
44
- var NonReplayableBodyError = (_class9 = class extends PipRailError {constructor(...args9) { super(...args9); _class9.prototype.__init9.call(this); }
45
- __init9() {this.code = "NON_REPLAYABLE_BODY"}
46
- }, _class9);
47
- var WrongFamilyError = (_class10 = class extends PipRailError {constructor(...args10) { super(...args10); _class10.prototype.__init10.call(this); }
48
- __init10() {this.code = "WRONG_FAMILY"}
49
- }, _class10);
50
- var UnknownTokenError = (_class11 = class extends PipRailError {constructor(...args11) { super(...args11); _class11.prototype.__init11.call(this); }
51
- __init11() {this.code = "UNKNOWN_TOKEN"}
52
- }, _class11);
53
- var MissingDriverError = (_class12 = class extends PipRailError {constructor(...args12) { super(...args12); _class12.prototype.__init12.call(this); }
54
- __init12() {this.code = "MISSING_DRIVER"}
55
- }, _class12);
56
- var UnsupportedNetworkError = (_class13 = class extends PipRailError {constructor(...args13) { super(...args13); _class13.prototype.__init13.call(this); }
57
- __init13() {this.code = "UNSUPPORTED_NETWORK"}
58
- }, _class13);
59
-
60
- // src/drivers/shared.ts
61
- var FAMILY_LABEL = {
62
- evm: "EVM",
63
- solana: "Solana",
64
- ton: "TON",
65
- stellar: "Stellar",
66
- xrpl: "XRPL",
67
- tron: "Tron",
68
- sui: "Sui",
69
- near: "NEAR"
70
- };
71
- var FAMILY_TOKEN = {
72
- evm: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
73
- solana: { key: "mint", shape: "{ mint }", hint: "{ mint, decimals }" },
74
- ton: { key: "master", shape: "{ master }", hint: "{ master, decimals }" },
75
- stellar: { key: "code", shape: "{ issuer, code }", hint: "{ issuer, code, decimals }" },
76
- xrpl: { key: "currencyHex", shape: "{ issuer, currencyHex }", hint: "{ issuer, currencyHex, decimals }" },
77
- tron: { key: "address", shape: "{ address }", hint: "{ address, decimals }" },
78
- sui: { key: "coinType", shape: "{ coinType }", hint: "{ coinType, decimals }" },
79
- near: { key: "contractId", shape: "{ contractId }", hint: "{ contractId, decimals }" }
80
- };
81
- function rejectForeignToken(token, family, network) {
82
- const own = FAMILY_TOKEN[family];
83
- for (const fam of Object.keys(FAMILY_TOKEN)) {
84
- if (fam === family) continue;
85
- if (FAMILY_TOKEN[fam].key === own.key) continue;
86
- if (FAMILY_TOKEN[fam].key in token) {
87
- throw new WrongFamilyError(
88
- `chain ${network} is ${FAMILY_LABEL[family]}; a ${FAMILY_LABEL[fam]} ${FAMILY_TOKEN[fam].shape} token can't be used \u2014 pass ${own.hint}.`
89
- );
90
- }
91
- }
92
- }
93
-
94
- // src/util/units.ts
95
- function parseUnits(value, decimals) {
96
- if (!/^\d+(\.\d+)?$/.test(value)) {
97
- throw new Error(`parseUnits: "${value}" is not a non-negative decimal amount.`);
98
- }
99
- const [whole, frac = ""] = value.split(".");
100
- if (frac.length > decimals) {
101
- throw new Error(
102
- `parseUnits: "${value}" has more than ${decimals} decimal places.`
103
- );
104
- }
105
- const fracPadded = frac.padEnd(decimals, "0");
106
- return BigInt(whole + fracPadded);
107
- }
108
- function floorUnits(value, decimals) {
109
- if (!/^\d+(\.\d+)?$/.test(value)) {
110
- throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
111
- }
112
- const [whole, frac = ""] = value.split(".");
113
- const fracTrunc = frac.slice(0, decimals).padEnd(decimals, "0");
114
- return BigInt(whole + fracTrunc);
115
- }
116
- function formatUnits(value, decimals) {
117
- const negative = value < 0n;
118
- const digits = (negative ? -value : value).toString().padStart(decimals + 1, "0");
119
- const whole = digits.slice(0, digits.length - decimals);
120
- const frac = digits.slice(digits.length - decimals).replace(/0+$/, "");
121
- return `${negative ? "-" : ""}${whole}${frac ? `.${frac}` : ""}`;
122
- }
123
-
124
- // src/util/cost.ts
125
- function nativeCost(opts) {
126
- return {
127
- feeSymbol: opts.symbol,
128
- feeDecimals: opts.decimals,
129
- fee: opts.fee.toString(),
130
- feeFormatted: formatUnits(opts.fee, opts.decimals),
131
- basis: opts.basis,
132
- ...opts.detail ? { detail: opts.detail } : {}
133
- };
134
- }
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
- exports.PipRailError = PipRailError; exports.InsufficientFundsError = InsufficientFundsError; exports.toInsufficientFundsError = toInsufficientFundsError; exports.WrongChainError = WrongChainError; exports.PaymentTimeoutError = PaymentTimeoutError; exports.MaxRetriesExceededError = MaxRetriesExceededError; exports.PaymentDeclinedError = PaymentDeclinedError; exports.ConfirmationTimeoutError = ConfirmationTimeoutError; exports.InvalidEnvelopeError = InvalidEnvelopeError; exports.NoCompatibleAcceptError = NoCompatibleAcceptError; exports.NonReplayableBodyError = NonReplayableBodyError; exports.WrongFamilyError = WrongFamilyError; exports.UnknownTokenError = UnknownTokenError; exports.MissingDriverError = MissingDriverError; exports.UnsupportedNetworkError = UnsupportedNetworkError; exports.rejectForeignToken = rejectForeignToken; exports.parseUnits = parseUnits; exports.floorUnits = floorUnits; exports.formatUnits = formatUnits; exports.nativeCost = nativeCost;