@ledgerhq/coin-module-framework 0.1.9 → 1.0.5
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/CHANGELOG.md +30 -0
- package/lib/api/errors.d.ts +4 -0
- package/lib/api/errors.d.ts.map +1 -0
- package/lib/api/errors.js +10 -0
- package/lib/api/errors.js.map +1 -0
- package/lib/api/index.d.ts +7 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +23 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/types.d.ts +568 -0
- package/lib/api/types.d.ts.map +1 -0
- package/lib/api/types.js +3 -0
- package/lib/api/types.js.map +1 -0
- package/lib/config.d.ts +43 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +21 -0
- package/lib/config.js.map +1 -0
- package/lib/currencies/formatCurrencyUnit.d.ts +2 -0
- package/lib/currencies/formatCurrencyUnit.d.ts.map +1 -0
- package/lib/currencies/formatCurrencyUnit.js +7 -0
- package/lib/currencies/formatCurrencyUnit.js.map +1 -0
- package/lib/currencies/index.d.ts +3 -0
- package/lib/currencies/index.d.ts.map +1 -0
- package/lib/currencies/index.js +9 -0
- package/lib/currencies/index.js.map +1 -0
- package/lib/currencies/parseCurrencyUnit.d.ts +2 -0
- package/lib/currencies/parseCurrencyUnit.d.ts.map +1 -0
- package/lib/currencies/parseCurrencyUnit.js +6 -0
- package/lib/currencies/parseCurrencyUnit.js.map +1 -0
- package/lib/errors.d.ts +5 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +7 -0
- package/lib/errors.js.map +1 -0
- package/lib/features/types.d.ts +46 -0
- package/lib/features/types.d.ts.map +1 -0
- package/lib/features/types.js +18 -0
- package/lib/features/types.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +40 -0
- package/lib/index.js.map +1 -0
- package/lib/setup.d.ts +2 -0
- package/lib/setup.d.ts.map +1 -0
- package/lib/setup.js +6 -0
- package/lib/setup.js.map +1 -0
- package/lib/test/utils.d.ts +20 -0
- package/lib/test/utils.d.ts.map +1 -0
- package/lib/test/utils.js +3 -0
- package/lib/test/utils.js.map +1 -0
- package/lib/utils.d.ts +6 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +18 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/api/errors.d.ts +4 -0
- package/lib-es/api/errors.d.ts.map +1 -0
- package/lib-es/api/errors.js +6 -0
- package/lib-es/api/errors.js.map +1 -0
- package/lib-es/api/index.d.ts +7 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +7 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/types.d.ts +568 -0
- package/lib-es/api/types.d.ts.map +1 -0
- package/lib-es/api/types.js +2 -0
- package/lib-es/api/types.js.map +1 -0
- package/lib-es/config.d.ts +43 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +19 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts +2 -0
- package/lib-es/currencies/formatCurrencyUnit.d.ts.map +1 -0
- package/lib-es/currencies/formatCurrencyUnit.js +2 -0
- package/lib-es/currencies/formatCurrencyUnit.js.map +1 -0
- package/lib-es/currencies/index.d.ts +3 -0
- package/lib-es/currencies/index.d.ts.map +1 -0
- package/lib-es/currencies/index.js +3 -0
- package/lib-es/currencies/index.js.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts +2 -0
- package/lib-es/currencies/parseCurrencyUnit.d.ts.map +1 -0
- package/lib-es/currencies/parseCurrencyUnit.js +2 -0
- package/lib-es/currencies/parseCurrencyUnit.js.map +1 -0
- package/lib-es/errors.d.ts +5 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +4 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/features/types.d.ts +46 -0
- package/lib-es/features/types.d.ts.map +1 -0
- package/lib-es/features/types.js +14 -0
- package/lib-es/features/types.js.map +1 -0
- package/lib-es/index.d.ts +6 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +5 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/setup.d.ts +2 -0
- package/lib-es/setup.d.ts.map +1 -0
- package/lib-es/setup.js +4 -0
- package/lib-es/setup.js.map +1 -0
- package/lib-es/test/utils.d.ts +20 -0
- package/lib-es/test/utils.d.ts.map +1 -0
- package/lib-es/test/utils.js +2 -0
- package/lib-es/test/utils.js.map +1 -0
- package/lib-es/utils.d.ts +6 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +13 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +1 -1
- package/tsconfig.build.json +5 -2
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
1
|
# @ledgerhq/coin-module-framework
|
|
2
|
+
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#459](https://github.com/LedgerHQ/alpaca-coin-module/pull/459) [`61b0ea2`](https://github.com/LedgerHQ/alpaca-coin-module/commit/61b0ea2b8cf58e9adb5aa1fa14d719473e7cd9e1) Thanks [@francois-guerin-ledger](https://github.com/francois-guerin-ledger)! - chore: use typescript 6
|
|
8
|
+
|
|
9
|
+
## 1.0.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#445](https://github.com/LedgerHQ/alpaca-coin-module/pull/445) [`0be97ab`](https://github.com/LedgerHQ/alpaca-coin-module/commit/0be97ab127915e86907974ff6f26a6e5adacabd3) Thanks [@francois-guerin-ledger](https://github.com/francois-guerin-ledger)! - Add CI support for publishing @ledgerhq/coin-module-framework to the configured registry
|
|
14
|
+
|
|
15
|
+
## 1.0.3
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#438](https://github.com/LedgerHQ/alpaca-coin-module/pull/438) [`1b3d04f`](https://github.com/LedgerHQ/alpaca-coin-module/commit/1b3d04f0c806e678ff189bc6b003bcb917f3de1b) Thanks [@francois-guerin-ledger](https://github.com/francois-guerin-ledger)! - bump version to test the release
|
|
20
|
+
|
|
21
|
+
## 1.0.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#436](https://github.com/LedgerHQ/alpaca-coin-module/pull/436) [`17e9ac3`](https://github.com/LedgerHQ/alpaca-coin-module/commit/17e9ac39c0e5ae3640d17226d22839119bd2f999) Thanks [@francois-guerin-ledger](https://github.com/francois-guerin-ledger)! - increase patch version to test the release
|
|
26
|
+
|
|
27
|
+
## 1.0.1
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#433](https://github.com/LedgerHQ/alpaca-coin-module/pull/433) [`52e4726`](https://github.com/LedgerHQ/alpaca-coin-module/commit/52e4726cdfaf6a23a6a4655287c0812045af49a9) Thanks [@francois-guerin-ledger](https://github.com/francois-guerin-ledger)! - increase patch version to trigger a new publish
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,CAAC,EAAE,MAAM;CAG7B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IncorrectTypeError = void 0;
|
|
4
|
+
class IncorrectTypeError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(`IncorrectType: ${message}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.IncorrectTypeError = IncorrectTypeError;
|
|
10
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAgB;QAC1B,KAAK,CAAC,kBAAkB,OAAO,EAAE,CAAC,CAAA;IACpC,CAAC;CACF;AAJD,gDAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
|
package/lib/api/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Module related to all API exposition constraints and helper.
|
|
4
|
+
* One consumer of this API is Alpaca.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./errors"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,2CAAwB;AACxB,0CAAuB"}
|
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
export type BroadcastConfig = {
|
|
2
|
+
mevProtected: boolean;
|
|
3
|
+
sponsored?: boolean;
|
|
4
|
+
source?: TransactionSource;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* TransactionSource identifies the origin of a transaction
|
|
8
|
+
*/
|
|
9
|
+
export type TransactionSource = {
|
|
10
|
+
type: 'dApp' | 'live-app' | 'coin-module' | 'swap';
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
export type BlockInfo = {
|
|
14
|
+
height: number;
|
|
15
|
+
hash: string;
|
|
16
|
+
time: Date;
|
|
17
|
+
parent?: ParentBlock;
|
|
18
|
+
};
|
|
19
|
+
export type ParentBlock = Pick<BlockInfo, 'height' | 'hash'>;
|
|
20
|
+
export type Unit = {
|
|
21
|
+
name: string;
|
|
22
|
+
code: string;
|
|
23
|
+
magnitude: number;
|
|
24
|
+
showAllDigits?: boolean;
|
|
25
|
+
prefixCode?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type AssetInfo = {
|
|
28
|
+
type: 'native';
|
|
29
|
+
name?: string;
|
|
30
|
+
unit?: Unit;
|
|
31
|
+
} | {
|
|
32
|
+
type: string;
|
|
33
|
+
assetReference?: string;
|
|
34
|
+
assetOwner?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
unit?: Unit;
|
|
37
|
+
};
|
|
38
|
+
export type Operation<MemoType extends Memo = MemoNotSupported> = {
|
|
39
|
+
id: string;
|
|
40
|
+
type: string;
|
|
41
|
+
senders: string[];
|
|
42
|
+
recipients: string[];
|
|
43
|
+
value: bigint;
|
|
44
|
+
asset: AssetInfo;
|
|
45
|
+
/**
|
|
46
|
+
* Optional memo associated with the operation.
|
|
47
|
+
* Use a `Memo` interface like `StringMemo<"text">`, `MapMemo<Kind, Value>`, or `MyMemo`.
|
|
48
|
+
* Defaults to `MemoNotSupported`.
|
|
49
|
+
*/
|
|
50
|
+
memo?: MemoType;
|
|
51
|
+
/**
|
|
52
|
+
* Arbitrary per-blockchain extra fields.
|
|
53
|
+
* This can include things like status, error messages, swap info, etc.
|
|
54
|
+
*/
|
|
55
|
+
details?: Record<string, unknown>;
|
|
56
|
+
tx: {
|
|
57
|
+
hash: string;
|
|
58
|
+
block: BlockInfo;
|
|
59
|
+
fees: bigint;
|
|
60
|
+
feesPayer?: string;
|
|
61
|
+
date: Date;
|
|
62
|
+
/** If the transaction has failed, fees have been paid but other balance changes are not effective.*/
|
|
63
|
+
failed: boolean;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export type Transaction = {
|
|
67
|
+
type: string;
|
|
68
|
+
recipient: string;
|
|
69
|
+
amount: bigint;
|
|
70
|
+
fee: bigint;
|
|
71
|
+
} & Record<string, unknown>;
|
|
72
|
+
/**
|
|
73
|
+
* A block along with its {@link BlockTransaction}, not specific to a particular account/address.
|
|
74
|
+
*/
|
|
75
|
+
export type Block = {
|
|
76
|
+
/** The block metadata. */
|
|
77
|
+
info: BlockInfo;
|
|
78
|
+
/**
|
|
79
|
+
* The block transactions.
|
|
80
|
+
*
|
|
81
|
+
* It should include at least all transactions where an EOA is involved, however it is OK to ignore other types of
|
|
82
|
+
* transactions that cannot cause balance changes (eg: validator vote transactions on Solana).
|
|
83
|
+
*/
|
|
84
|
+
transactions: BlockTransaction[];
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A transaction belonging to a {@link Block}, not specific to a particular account/address.
|
|
88
|
+
*/
|
|
89
|
+
export type BlockTransaction = {
|
|
90
|
+
/** The transaction hash/digest (globally unique identifier). */
|
|
91
|
+
hash: string;
|
|
92
|
+
/** If the transaction has been failed, fees have been paid but other balance changes are not effective.*/
|
|
93
|
+
failed: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* The operations/instructions included in this transaction.
|
|
96
|
+
*
|
|
97
|
+
* It should include at least all operations where an EOA is involved, however it is OK to ignore other types of
|
|
98
|
+
* operations that cannot cause balance changes (eg: validator vote instructions on Solana).
|
|
99
|
+
*
|
|
100
|
+
* Note that fees are accounted for separately, so operations must not represent fees.
|
|
101
|
+
*/
|
|
102
|
+
operations: BlockOperation[];
|
|
103
|
+
/** Network specific details for this transaction. */
|
|
104
|
+
details?: Record<string, unknown>;
|
|
105
|
+
/** The fee amount paid for this transaction, in base unit of the network native coin, always positive or zero. */
|
|
106
|
+
fees: bigint;
|
|
107
|
+
/** The address that paid for this transaction's fees. */
|
|
108
|
+
feesPayer?: string;
|
|
109
|
+
};
|
|
110
|
+
/** An operation belonging to a {@link BlockTransaction}. */
|
|
111
|
+
export type BlockOperation = TransferBlockOperation | OtherBlockOperation;
|
|
112
|
+
/** An asset transfer that occurred in a {@link BlockTransaction}. */
|
|
113
|
+
export type TransferBlockOperation = {
|
|
114
|
+
/** Operation type discriminator. */
|
|
115
|
+
type: 'transfer';
|
|
116
|
+
/** The impacted address (can be sender or recipient based on signum of <code>amount</code>). */
|
|
117
|
+
address: string;
|
|
118
|
+
/** The peer participant in the transfer (optional as it may be not known). */
|
|
119
|
+
peer?: string;
|
|
120
|
+
/** The transferred asset. */
|
|
121
|
+
asset: AssetInfo;
|
|
122
|
+
/**
|
|
123
|
+
* The signed amount of the transfer, i.e. impact of the transfer on <code>address</code> balance (positive for
|
|
124
|
+
* incoming, negative for outgoing).
|
|
125
|
+
*/
|
|
126
|
+
amount: bigint;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* An unclassified type of operation that occurred in a {@link BlockTransaction}.
|
|
130
|
+
*
|
|
131
|
+
* Implementations are free to partially/completely omit this kind of operations.
|
|
132
|
+
*/
|
|
133
|
+
export type OtherBlockOperation = {
|
|
134
|
+
type: 'other';
|
|
135
|
+
} & Record<string, unknown>;
|
|
136
|
+
export type Account = {
|
|
137
|
+
currencyName: string;
|
|
138
|
+
address: string;
|
|
139
|
+
balance: bigint;
|
|
140
|
+
currencyUnit: Unit;
|
|
141
|
+
spendableBalance: bigint;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* A component of an account/address balance, for a single asset.
|
|
145
|
+
*
|
|
146
|
+
* @see AlpacaApi#getBalance
|
|
147
|
+
*/
|
|
148
|
+
export type Balance = {
|
|
149
|
+
/** The balance value, in base unit of {@link asset} (always positive). */
|
|
150
|
+
value: bigint;
|
|
151
|
+
/** The balance asset. */
|
|
152
|
+
asset: AssetInfo;
|
|
153
|
+
/** The non-spendable part of {@link value} (eg: minimum balance requirement, or reserved for rent). */
|
|
154
|
+
locked?: bigint;
|
|
155
|
+
/** The {@link Stake} this balance is part of, if any. */
|
|
156
|
+
stake?: Stake;
|
|
157
|
+
};
|
|
158
|
+
/** The state of a {@link Stake}. */
|
|
159
|
+
export type StakeState = 'inactive' | 'activating' | 'active' | 'deactivating';
|
|
160
|
+
/**
|
|
161
|
+
* A staking position, for a single address/asset/state.
|
|
162
|
+
*
|
|
163
|
+
* Note that on blockchains that allow heterogeneous assets/states in a single account, a staking account is represented
|
|
164
|
+
* as several {@link Stake}.
|
|
165
|
+
*
|
|
166
|
+
* @see Reward
|
|
167
|
+
* @see AlpacaApi#getStakes
|
|
168
|
+
*/
|
|
169
|
+
export type Stake = {
|
|
170
|
+
/** An immutable, globally unique id of the stake. Depending on the blockchain, it could simply be the account address,
|
|
171
|
+
* or a synthetic identifier. */
|
|
172
|
+
uid: string;
|
|
173
|
+
/** The owning account address. Depending on the blockchain, it can be the staking account address or directly the
|
|
174
|
+
* main one. */
|
|
175
|
+
address: string;
|
|
176
|
+
/** The validator/staking pool/delegate address. */
|
|
177
|
+
delegate?: string;
|
|
178
|
+
/** The stake status, see {@link StakeState}. */
|
|
179
|
+
state: StakeState;
|
|
180
|
+
/** UTC date of last state change. */
|
|
181
|
+
stateUpdatedAt?: Date;
|
|
182
|
+
/** UTC date of initial stake creation. */
|
|
183
|
+
createdAt?: Date;
|
|
184
|
+
/** The staked asset. */
|
|
185
|
+
asset: AssetInfo;
|
|
186
|
+
/** The amount owned by the stake, in base unit of {@link asset} (deposits + rewards). */
|
|
187
|
+
amount: bigint;
|
|
188
|
+
/** The part of {@link amount} that was deposited (<code>amount = amount_deposited + amount_rewarded</code>). */
|
|
189
|
+
amountDeposited?: bigint;
|
|
190
|
+
/** The part of {@link amount} that was rewarded (<code>amount = amount_deposited + amount_rewarded</code>). */
|
|
191
|
+
amountRewarded?: bigint;
|
|
192
|
+
/** A free form map of network specific fields. */
|
|
193
|
+
details?: Record<string, unknown>;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* A staking reward distribution event.
|
|
197
|
+
*
|
|
198
|
+
* @see Stake
|
|
199
|
+
* @see AlpacaApi#getRewards
|
|
200
|
+
*/
|
|
201
|
+
export type Reward = {
|
|
202
|
+
/** {@link Stake#uid} via which this reward was obtained. */
|
|
203
|
+
stake: string;
|
|
204
|
+
/** The reward asset. */
|
|
205
|
+
asset: AssetInfo;
|
|
206
|
+
/** The reward amount. */
|
|
207
|
+
amount: bigint;
|
|
208
|
+
/** UTC date at which reward was effectively credited to the account (not emitted). */
|
|
209
|
+
receivedAt: Date;
|
|
210
|
+
/** If applicable, the transaction hash that distributed the reward. */
|
|
211
|
+
transactionHash?: string;
|
|
212
|
+
/** A free form map of network specific fields. */
|
|
213
|
+
details?: Record<string, unknown>;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Computational payload processed by Blockchains, such as
|
|
217
|
+
* calldata on EVM or instruction data on Solana
|
|
218
|
+
*/
|
|
219
|
+
export interface TxData {
|
|
220
|
+
type: string;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Default implementation when no computational payload is supported
|
|
224
|
+
* by the underlying Blockchain
|
|
225
|
+
*/
|
|
226
|
+
export interface TxDataNotSupported extends TxData {
|
|
227
|
+
type: 'none';
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Implementation with bufferized computational payload
|
|
231
|
+
*/
|
|
232
|
+
export interface BufferTxData extends TxData {
|
|
233
|
+
type: 'buffer';
|
|
234
|
+
value: Buffer;
|
|
235
|
+
}
|
|
236
|
+
export interface Memo {
|
|
237
|
+
type: string;
|
|
238
|
+
}
|
|
239
|
+
export interface MemoNotSupported extends Memo {
|
|
240
|
+
type: 'none';
|
|
241
|
+
}
|
|
242
|
+
export interface StringMemo<Kind extends string = 'text'> extends Memo {
|
|
243
|
+
type: 'string';
|
|
244
|
+
kind: Kind;
|
|
245
|
+
value: string;
|
|
246
|
+
}
|
|
247
|
+
export interface MapMemo<Kind extends string, Value> extends Memo {
|
|
248
|
+
type: string;
|
|
249
|
+
memos: Map<Kind, Value>;
|
|
250
|
+
}
|
|
251
|
+
export interface TypedMapMemo<KindToValueMap extends Record<string, unknown>> extends Memo {
|
|
252
|
+
type: string;
|
|
253
|
+
memos: Map<keyof KindToValueMap, KindToValueMap[keyof KindToValueMap]>;
|
|
254
|
+
}
|
|
255
|
+
type MaybeMemo<MemoType extends Memo> = MemoType extends MemoNotSupported ? object : {
|
|
256
|
+
memo: MemoType;
|
|
257
|
+
};
|
|
258
|
+
type MaybeTxData<TxDataType extends TxData> = TxDataType extends TxDataNotSupported ? object : {
|
|
259
|
+
data: TxDataType;
|
|
260
|
+
};
|
|
261
|
+
export type FeesStrategy = 'slow' | 'medium' | 'fast' | 'custom';
|
|
262
|
+
export type StakingOperation = 'delegate' | 'undelegate' | 'redelegate';
|
|
263
|
+
export type TransactionIntent<MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported> = {
|
|
264
|
+
intentType: 'transaction' | 'staking';
|
|
265
|
+
type: string;
|
|
266
|
+
sender: string;
|
|
267
|
+
recipient: string;
|
|
268
|
+
amount: bigint;
|
|
269
|
+
asset: AssetInfo;
|
|
270
|
+
useAllAmount?: boolean;
|
|
271
|
+
feesStrategy?: FeesStrategy;
|
|
272
|
+
senderPublicKey?: string;
|
|
273
|
+
sequence?: bigint;
|
|
274
|
+
expiration?: number;
|
|
275
|
+
sponsored?: boolean;
|
|
276
|
+
} & MaybeMemo<MemoType> & MaybeTxData<TxDataType>;
|
|
277
|
+
export type StakingTransactionIntent<MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported> = TransactionIntent & {
|
|
278
|
+
intentType: 'staking';
|
|
279
|
+
mode: StakingOperation;
|
|
280
|
+
valAddress: string;
|
|
281
|
+
dstValAddress?: string;
|
|
282
|
+
} & MaybeMemo<MemoType> & MaybeTxData<TxDataType>;
|
|
283
|
+
export type SendTransactionIntent<MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported> = TransactionIntent & {
|
|
284
|
+
intentType: 'transaction';
|
|
285
|
+
} & MaybeMemo<MemoType> & MaybeTxData<TxDataType>;
|
|
286
|
+
export type TransactionValidation = {
|
|
287
|
+
errors: Record<string, Error>;
|
|
288
|
+
warnings: Record<string, Error>;
|
|
289
|
+
estimatedFees: bigint;
|
|
290
|
+
totalFees?: bigint;
|
|
291
|
+
amount: bigint;
|
|
292
|
+
totalSpent: bigint;
|
|
293
|
+
};
|
|
294
|
+
export type FeeEstimation = {
|
|
295
|
+
value: bigint;
|
|
296
|
+
parameters?: Record<string, unknown>;
|
|
297
|
+
};
|
|
298
|
+
/** Response of {@link AlpacaApi#craftTransaction}. */
|
|
299
|
+
export type CraftedTransaction = {
|
|
300
|
+
/** The serialized transaction (encoding is blockchain dependent). */
|
|
301
|
+
transaction: string;
|
|
302
|
+
/** Blockchain specific details (eg: UTXOs referenced in the transaction). */
|
|
303
|
+
details?: Record<string, unknown>;
|
|
304
|
+
};
|
|
305
|
+
/** A pagination cursor. */
|
|
306
|
+
export type Cursor = string;
|
|
307
|
+
/** A paginated response. */
|
|
308
|
+
export type Page<T> = {
|
|
309
|
+
items: T[];
|
|
310
|
+
next?: Cursor | undefined;
|
|
311
|
+
};
|
|
312
|
+
/** Options for {@link AlpacaApi#listOperations}. */
|
|
313
|
+
export type ListOperationsOptions = {
|
|
314
|
+
/**
|
|
315
|
+
* The minimum block height for which to fetch operations (inclusive).
|
|
316
|
+
*
|
|
317
|
+
* Implementation must raise a "not supported" error if `minHeight` is non-zero and not supported.
|
|
318
|
+
*/
|
|
319
|
+
minHeight: number;
|
|
320
|
+
/**
|
|
321
|
+
* A pagination cursor to resume listing.
|
|
322
|
+
*
|
|
323
|
+
* Implementation must guarantee the cursor is not volatile, i.e. it can be used long after the last request and still
|
|
324
|
+
* provide consistent results - for instance, a date or transaction hash.
|
|
325
|
+
*/
|
|
326
|
+
cursor?: Cursor;
|
|
327
|
+
/**
|
|
328
|
+
* The maximum number of operations to fetch (note this is a soft limit, the implementation may return less or more
|
|
329
|
+
* operations to not waste RPC calls).
|
|
330
|
+
*
|
|
331
|
+
* Implementation must raise a "not supported" error if limit is set and not supported.
|
|
332
|
+
*/
|
|
333
|
+
limit?: number;
|
|
334
|
+
/**
|
|
335
|
+
* The chronological order of the operations (within one page as well as globally when concatenating all pages).
|
|
336
|
+
*
|
|
337
|
+
* Implementation must raise a "not supported" error if order is set and not supported.
|
|
338
|
+
*/
|
|
339
|
+
order?: 'asc' | 'desc';
|
|
340
|
+
};
|
|
341
|
+
/** A network validator */
|
|
342
|
+
export type Validator = {
|
|
343
|
+
/** Address of the validator. */
|
|
344
|
+
address: string;
|
|
345
|
+
/** Human-readable name of the validator. */
|
|
346
|
+
name: string;
|
|
347
|
+
/** Human-readable description of the validator. */
|
|
348
|
+
description?: string | undefined;
|
|
349
|
+
/** URL of the entity running the validator. */
|
|
350
|
+
url?: string | undefined;
|
|
351
|
+
/** URL of the logo for the validator. */
|
|
352
|
+
logo?: string | undefined;
|
|
353
|
+
/** Amount of native asset in the pool (in base unit of chain native currency). */
|
|
354
|
+
balance?: bigint | undefined;
|
|
355
|
+
/** Validator commission (a bigint serialized as a string). */
|
|
356
|
+
commissionRate?: string | undefined;
|
|
357
|
+
/** Validator Annual Percentage Yield (floating point number between 0 and 1). */
|
|
358
|
+
apy?: number | undefined;
|
|
359
|
+
};
|
|
360
|
+
export type AccountInfo = {
|
|
361
|
+
isNewAccount: boolean;
|
|
362
|
+
balance: string;
|
|
363
|
+
ownerCount: number;
|
|
364
|
+
sequence: number;
|
|
365
|
+
};
|
|
366
|
+
export type AddressValidationCurrencyParameters = {
|
|
367
|
+
currencyId: string;
|
|
368
|
+
networkId: number;
|
|
369
|
+
};
|
|
370
|
+
export type AlpacaApi<MemoType extends Memo = MemoNotSupported, TxDataType extends TxData = TxDataNotSupported> = {
|
|
371
|
+
/**
|
|
372
|
+
* Get the latest block information from the network.
|
|
373
|
+
*
|
|
374
|
+
* This must return the same result as {@link getBlockInfo} for the latest block height.
|
|
375
|
+
*
|
|
376
|
+
* @returns the latest block metadata (height, hash, time)
|
|
377
|
+
* @see getBlockInfo
|
|
378
|
+
* @see getBlock
|
|
379
|
+
*/
|
|
380
|
+
lastBlock: () => Promise<BlockInfo>;
|
|
381
|
+
/**
|
|
382
|
+
* Get block information for a specific block height.
|
|
383
|
+
*
|
|
384
|
+
* This must return the same result as {@link lastBlock} for the latest block height.
|
|
385
|
+
*
|
|
386
|
+
* This API is optional and may not be supported on all networks: implementation should raise a "not supported" error
|
|
387
|
+
* in such case.
|
|
388
|
+
*
|
|
389
|
+
* @param height the block height to query
|
|
390
|
+
* @returns the block metadata (height, hash, time)
|
|
391
|
+
* @throws "not supported" if the blockchain does not support querying historical blocks
|
|
392
|
+
*/
|
|
393
|
+
getBlockInfo: (height: number) => Promise<BlockInfo>;
|
|
394
|
+
/**
|
|
395
|
+
* Get a full block with all its transactions.
|
|
396
|
+
*
|
|
397
|
+
* This returns the complete block data including all transactions and their operations.
|
|
398
|
+
*
|
|
399
|
+
* This must return the same block info as {@link getBlockInfo} for the same height.
|
|
400
|
+
*
|
|
401
|
+
* This API is optional and may not be supported on all networks: implementation should raise a "not supported" error
|
|
402
|
+
* in such case.
|
|
403
|
+
*
|
|
404
|
+
* @param height the block height to query
|
|
405
|
+
* @returns the complete block with transactions
|
|
406
|
+
* @throws "not supported" if the blockchain does not support querying full blocks
|
|
407
|
+
*/
|
|
408
|
+
getBlock: (height: number) => Promise<Block>;
|
|
409
|
+
/**
|
|
410
|
+
* Get the list of validators available on the network.
|
|
411
|
+
* @param cursor a pagination cursor to resume listing (the implementation must guarantee the cursor is not volatile,
|
|
412
|
+
* i.e. it can be used long after the last request and still provide consistent results - for instance,
|
|
413
|
+
* a date or transaction hash).
|
|
414
|
+
* The concrete implementation may return all validators in a single page when the underlying SDK
|
|
415
|
+
* does not provide cursor-based pagination.
|
|
416
|
+
*/
|
|
417
|
+
getValidators: (cursor?: Cursor) => Promise<Page<Validator>>;
|
|
418
|
+
/**
|
|
419
|
+
* Get the balance(s) for an address/account.
|
|
420
|
+
*
|
|
421
|
+
* Returns all asset balances associated with the address, including the native asset and any tokens/sub-assets. Each
|
|
422
|
+
* balance includes the total value and optionally locked/staked amounts.
|
|
423
|
+
*
|
|
424
|
+
* If account is not found, implementation must return an empty balance.
|
|
425
|
+
*
|
|
426
|
+
* @param address the account address
|
|
427
|
+
* @returns an array of balances for all assets held by the address
|
|
428
|
+
* @see getStakes
|
|
429
|
+
* @see listOperations
|
|
430
|
+
*/
|
|
431
|
+
getBalance: (address: string) => Promise<Balance[]>;
|
|
432
|
+
/**
|
|
433
|
+
* List operations for an address/account.
|
|
434
|
+
*
|
|
435
|
+
* If account is not found, implementation must return an empty result.
|
|
436
|
+
*
|
|
437
|
+
* @param address the owner account address
|
|
438
|
+
* @param options see {@link ListOperationsOptions}
|
|
439
|
+
* @returns a page of operations
|
|
440
|
+
* @see getBalance
|
|
441
|
+
*/
|
|
442
|
+
listOperations: (address: string, options: ListOperationsOptions) => Promise<Page<Operation>>;
|
|
443
|
+
/**
|
|
444
|
+
* Get staking positions owned by an address/account.
|
|
445
|
+
*
|
|
446
|
+
* Results are returned in no particular order, in pages that can be of variable size. Page size is controlled by
|
|
447
|
+
* implementation and should minimize number of RPC calls (typically by aligning with SDK/RPC API pages).
|
|
448
|
+
*
|
|
449
|
+
* Results could include closed/deleted staking positions, this is implementation dependent.
|
|
450
|
+
*
|
|
451
|
+
* Since this API can make no sense/be complex to implement/require too many RPC calls on some blockchains, it is
|
|
452
|
+
* optional: implementation should raise a "not supported" error in such case.
|
|
453
|
+
*
|
|
454
|
+
* @param address the owner account address
|
|
455
|
+
* @param cursor a pagination cursor to resume listing (the implementation must guarantee the cursor is not volatile,
|
|
456
|
+
* i.e. it can be used long after the last request and still provide consistent results - for instance,
|
|
457
|
+
* a date or transaction hash)
|
|
458
|
+
* @see getBalance
|
|
459
|
+
* @see getRewards
|
|
460
|
+
*/
|
|
461
|
+
getStakes: (address: string, cursor?: Cursor) => Promise<Page<Stake>>;
|
|
462
|
+
/**
|
|
463
|
+
* Get staking reward distribution events since address/account inception.
|
|
464
|
+
*
|
|
465
|
+
* Results are returned in ascending chronological order, in pages that can be of variable size. Page size is
|
|
466
|
+
* controlled by implementation and should minimize number of RPC calls (typically by aligning with SDK/RPC API pages).
|
|
467
|
+
*
|
|
468
|
+
* Note that since staking implementations vary from one blockchain to another, some points are implementation dependent:
|
|
469
|
+
* - depending on the blockchain account model, the exact meaning of <code>address</code> can be:
|
|
470
|
+
* - a parent account => history will include all staking subaccounts
|
|
471
|
+
* - a single staking position/subaccount address
|
|
472
|
+
* - depending on the reward distribution mechanisms, reward events can be transactions, or blocks/epochs, or
|
|
473
|
+
* generated synthetically (eg: daily)
|
|
474
|
+
*
|
|
475
|
+
* Since this API can make no sense/be complex to implement/require too many RPC calls on some blockchains, it is
|
|
476
|
+
* optional: implementation should raise a "not supported" error in such case.
|
|
477
|
+
*
|
|
478
|
+
* @param address the account address (see doc, exact scope of the request is implementation dependent)
|
|
479
|
+
* @param cursor a pagination cursor to resume listing (the implementation must guarantee the cursor is not volatile,
|
|
480
|
+
* i.e. it can be used long after the last request and still provide consistent results - for instance,
|
|
481
|
+
* a date or transaction hash)
|
|
482
|
+
* @see getBalance
|
|
483
|
+
* @see getStakes
|
|
484
|
+
*/
|
|
485
|
+
getRewards: (address: string, cursor?: Cursor) => Promise<Page<Reward>>;
|
|
486
|
+
/**
|
|
487
|
+
* Craft an unsigned transaction from a transaction intent.
|
|
488
|
+
*
|
|
489
|
+
* The crafted transaction is ready to be signed by the hardware wallet and then combined
|
|
490
|
+
* with the signature using {@link combine}.
|
|
491
|
+
*
|
|
492
|
+
* @param transactionIntent the transaction intent describing what the user wants to do
|
|
493
|
+
* @param customFees optional custom fees to use instead of the default estimation
|
|
494
|
+
* @returns the crafted transaction with optional blockchain-specific details
|
|
495
|
+
* @see craftRawTransaction
|
|
496
|
+
*/
|
|
497
|
+
craftTransaction: (transactionIntent: TransactionIntent<MemoType, TxDataType>, customFees?: FeeEstimation) => Promise<CraftedTransaction>;
|
|
498
|
+
/**
|
|
499
|
+
* Craft an unsigned transaction from a raw/pre-built transaction.
|
|
500
|
+
*
|
|
501
|
+
* This is an alternative to {@link craftTransaction} for cases where the transaction
|
|
502
|
+
* is already built externally (e.g., by a dApp or smart contract interaction).
|
|
503
|
+
*
|
|
504
|
+
* @param transaction the raw transaction to wrap/prepare for signing
|
|
505
|
+
* @param sender the sender address
|
|
506
|
+
* @param publicKey the sender's public key
|
|
507
|
+
* @param sequence the account sequence/nonce (to prevent replay attacks)
|
|
508
|
+
* @returns the crafted transaction ready for signing
|
|
509
|
+
* @throws "not supported" if the blockchain does not support raw transaction crafting
|
|
510
|
+
* @see craftTransaction
|
|
511
|
+
*/
|
|
512
|
+
craftRawTransaction: (transaction: string, sender: string, publicKey: string, sequence: bigint) => Promise<CraftedTransaction>;
|
|
513
|
+
/**
|
|
514
|
+
* Estimate the fees for a transaction intent.
|
|
515
|
+
*
|
|
516
|
+
* The estimation should be based on current network conditions (e.g., gas price, fee rate).
|
|
517
|
+
*
|
|
518
|
+
* @param transactionIntent the transaction intent describing what the user wants to do
|
|
519
|
+
* @param customFeesParameters optional blockchain-specific parameters to customize the fee estimation
|
|
520
|
+
* (e.g., gas limit, priority fee)
|
|
521
|
+
* @returns the estimated fees and optional parameters that can be passed to {@link craftTransaction}
|
|
522
|
+
*/
|
|
523
|
+
estimateFees: (transactionIntent: TransactionIntent<MemoType, TxDataType>, customFeesParameters?: FeeEstimation['parameters']) => Promise<FeeEstimation>;
|
|
524
|
+
/**
|
|
525
|
+
* Combine a crafted transaction with a signature to produce a signed transaction ready for broadcast.
|
|
526
|
+
*
|
|
527
|
+
* @param tx the unsigned/crafted transaction (as returned by {@link craftTransaction})
|
|
528
|
+
* @param signature the signature produced by the hardware wallet
|
|
529
|
+
* @param pubkey the public key used to sign (required for some blockchains to verify/embed in the transaction)
|
|
530
|
+
* @returns the signed transaction ready for {@link broadcast}
|
|
531
|
+
*/
|
|
532
|
+
combine: (tx: string, signature: string, pubkey?: string) => string | Promise<string>;
|
|
533
|
+
/**
|
|
534
|
+
* Broadcast a signed transaction to the network.
|
|
535
|
+
*
|
|
536
|
+
* @param tx the signed transaction (encoding is blockchain dependent, typically hex-encoded)
|
|
537
|
+
* @param broadcastConfig optional configuration for the broadcast (e.g., retry settings)
|
|
538
|
+
* @returns the transaction hash/digest once successfully submitted to the network
|
|
539
|
+
* @throws if the transaction is rejected by the network (e.g., invalid signature, insufficient funds)
|
|
540
|
+
*/
|
|
541
|
+
broadcast: (tx: string, broadcastConfig?: BroadcastConfig) => Promise<string>;
|
|
542
|
+
/**
|
|
543
|
+
* Validate a transaction intent.
|
|
544
|
+
*
|
|
545
|
+
* @param transactionIntent the transaction intent describing what the user wants to do
|
|
546
|
+
* @param balances current balances of the intent sender
|
|
547
|
+
* @param customFees optional custom fees to use instead of the default estimation
|
|
548
|
+
* @returns additional values the intent has been validated with, and optional errors/warnings
|
|
549
|
+
*/
|
|
550
|
+
validateIntent: (transactionIntent: TransactionIntent<MemoType, TxDataType>, balances: Balance[], customFees?: FeeEstimation) => Promise<TransactionValidation>;
|
|
551
|
+
/**
|
|
552
|
+
* Get the next sequence number (nonce) for an address
|
|
553
|
+
*
|
|
554
|
+
* @param address the account address
|
|
555
|
+
* @returns the next usable sequence number
|
|
556
|
+
*/
|
|
557
|
+
getNextSequence: (address: string) => Promise<bigint>;
|
|
558
|
+
/**
|
|
559
|
+
* Validate whether an address is well-formed for the blockchain.
|
|
560
|
+
*
|
|
561
|
+
* @param address the address to validate
|
|
562
|
+
* @param parameters currency-specific validation parameters
|
|
563
|
+
* @returns `true` if the address is valid, `false` otherwise
|
|
564
|
+
*/
|
|
565
|
+
validateAddress: (address: string, parameters: Partial<AddressValidationCurrencyParameters>) => Promise<boolean>;
|
|
566
|
+
};
|
|
567
|
+
export {};
|
|
568
|
+
//# sourceMappingURL=types.d.ts.map
|