@ledgerhq/ledger-wallet-framework 3.1.0 → 3.2.0-nightly.20260829020445
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 +21 -0
- package/jest.config.js +2 -0
- package/lib/serialization/index.d.ts +1 -0
- package/lib/serialization/index.d.ts.map +1 -1
- package/lib/serialization/index.js +6 -1
- package/lib/serialization/index.js.map +1 -1
- package/lib/serialization/staking.d.ts +6 -0
- package/lib/serialization/staking.d.ts.map +1 -0
- package/lib/serialization/staking.js +175 -0
- package/lib/serialization/staking.js.map +1 -0
- package/lib-es/serialization/index.d.ts +1 -0
- package/lib-es/serialization/index.d.ts.map +1 -1
- package/lib-es/serialization/index.js +1 -0
- package/lib-es/serialization/index.js.map +1 -1
- package/lib-es/serialization/staking.d.ts +6 -0
- package/lib-es/serialization/staking.d.ts.map +1 -0
- package/lib-es/serialization/staking.js +169 -0
- package/lib-es/serialization/staking.js.map +1 -0
- package/package.json +16 -15
- package/src/serialization/index.ts +6 -0
- package/src/serialization/staking.test.ts +237 -0
- package/src/serialization/staking.ts +208 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ledgerhq/ledger-wallet-framework
|
|
2
2
|
|
|
3
|
+
## 3.2.0-nightly.20260829020445
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#20935](https://github.com/LedgerHQ/ledger-live/pull/20935) [`27388a8`](https://github.com/LedgerHQ/ledger-live/commit/27388a894eaac67b8e162a60f6d3368aad0a8682) Thanks [@dilaouid](https://github.com/dilaouid)! - Move Solana staking onto the generic `StakingResources` account attribute.
|
|
8
|
+
|
|
9
|
+
**Breaking for `@ledgerhq/coin-solana`.** `SolanaResources`, `SolanaResourcesRaw`, `toSolanaResourcesRaw` and `fromSolanaResourcesRaw` are gone. `SolanaAccount` is now an alias of `StakingAccount`, so read staking data from `account.stakingResources` instead of `account.solanaResources`. A stake is a `StakingDelegation` or a `StakingUnbonding` (`SolanaStakingPosition`) rather than a `SolanaStake`: its stake account address is `positionId`, its validator is `validatorAddress`, and the former `activation.active` / `activation.inactive` / `withdrawable` fields are `activeAmount` / `inactiveAmount` / `withdrawableAmount`. `listSolanaStakingPositions`, `solanaActivationState` and `stakeActions` from `@ledgerhq/coin-solana/logic` cover the common access patterns. Accounts already persisted with a `solanaResources` blob are migrated on hydration, so no resync is needed.
|
|
10
|
+
|
|
11
|
+
`@ledgerhq/types-live` gains `StakingPositionDetails`, mixed into `StakingDelegation` and `StakingUnbonding` for chains that materialize each position as its own on-chain account, plus `actionFeeReserve` on `StakingResources`. Both are optional, so other chains are unaffected.
|
|
12
|
+
|
|
13
|
+
`@ledgerhq/wallet-cli`'s `earn positions` output changes shape: on `EarnSolanaStake`, `stakeBalance` and `withdrawable` go from `number` to an integer decimal string, so lamport amounts above `Number.MAX_SAFE_INTEGER` stay exact. Anything reading those two fields numerically needs updating.
|
|
14
|
+
|
|
15
|
+
`@ledgerhq/ledger-wallet-framework` now exports the generic `StakingResources` serializer (`toStakingResourcesRaw`, `fromStakingResourcesRaw`, `assignStakingResourcesToAccountRaw`, `assignStakingResourcesFromAccountRaw`), moved out of the EVM family in `live-common` so every coin module can use it.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`27388a8`](https://github.com/LedgerHQ/ledger-live/commit/27388a894eaac67b8e162a60f6d3368aad0a8682), [`e21305a`](https://github.com/LedgerHQ/ledger-live/commit/e21305abce18f0a9408bf6c0e2bb47d5c992e06a)]:
|
|
20
|
+
- @ledgerhq/types-live@6.122.0-nightly.20260829020445
|
|
21
|
+
- @ledgerhq/live-env@3.2.0-nightly.20260829020445
|
|
22
|
+
- @ledgerhq/live-currency-format@0.14.3-nightly.20260829020445
|
|
23
|
+
|
|
3
24
|
## 3.1.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/jest.config.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = {
|
|
|
14
14
|
"default",
|
|
15
15
|
...(process.env.CI ? ["github-actions"] : []),
|
|
16
16
|
["jest-sonar", { outputName: "sonar-executionTests-report.xml", reportedFilePath: "absolute" }],
|
|
17
|
+
"@ledgerhq/test-quarantine/jest",
|
|
17
18
|
],
|
|
18
19
|
// wallet-framework-test-setup wires domain data into the framework's ports at test time.
|
|
19
20
|
// Loaded by relative path (not as a package dep) so the public framework carries no
|
|
@@ -21,6 +22,7 @@ module.exports = {
|
|
|
21
22
|
setupFilesAfterEnv: [
|
|
22
23
|
"<rootDir>/../wallet-framework-test-setup/src/index.js",
|
|
23
24
|
"<rootDir>/src/setup.ts",
|
|
25
|
+
"@ledgerhq/test-quarantine/jest-retries",
|
|
24
26
|
],
|
|
25
27
|
testEnvironment: "node",
|
|
26
28
|
moduleNameMapper: {
|
|
@@ -2,4 +2,5 @@ export { fromAccountRaw, toAccountRaw } from "./account";
|
|
|
2
2
|
export * from "./nft";
|
|
3
3
|
export * from "./operation";
|
|
4
4
|
export * from "./transaction";
|
|
5
|
+
export { assignStakingResourcesFromAccountRaw, assignStakingResourcesToAccountRaw, fromStakingResourcesRaw, toStakingResourcesRaw, } from "./staking";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,oCAAoC,EACpC,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,WAAW,CAAC"}
|
|
@@ -14,11 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.toAccountRaw = exports.fromAccountRaw = void 0;
|
|
17
|
+
exports.toStakingResourcesRaw = exports.fromStakingResourcesRaw = exports.assignStakingResourcesToAccountRaw = exports.assignStakingResourcesFromAccountRaw = exports.toAccountRaw = exports.fromAccountRaw = void 0;
|
|
18
18
|
var account_1 = require("./account");
|
|
19
19
|
Object.defineProperty(exports, "fromAccountRaw", { enumerable: true, get: function () { return account_1.fromAccountRaw; } });
|
|
20
20
|
Object.defineProperty(exports, "toAccountRaw", { enumerable: true, get: function () { return account_1.toAccountRaw; } });
|
|
21
21
|
__exportStar(require("./nft"), exports);
|
|
22
22
|
__exportStar(require("./operation"), exports);
|
|
23
23
|
__exportStar(require("./transaction"), exports);
|
|
24
|
+
var staking_1 = require("./staking");
|
|
25
|
+
Object.defineProperty(exports, "assignStakingResourcesFromAccountRaw", { enumerable: true, get: function () { return staking_1.assignStakingResourcesFromAccountRaw; } });
|
|
26
|
+
Object.defineProperty(exports, "assignStakingResourcesToAccountRaw", { enumerable: true, get: function () { return staking_1.assignStakingResourcesToAccountRaw; } });
|
|
27
|
+
Object.defineProperty(exports, "fromStakingResourcesRaw", { enumerable: true, get: function () { return staking_1.fromStakingResourcesRaw; } });
|
|
28
|
+
Object.defineProperty(exports, "toStakingResourcesRaw", { enumerable: true, get: function () { return staking_1.toStakingResourcesRaw; } });
|
|
24
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAyD;AAAhD,yGAAA,cAAc,OAAA;AAAE,uGAAA,YAAY,OAAA;AACrC,wCAAsB;AACtB,8CAA4B;AAC5B,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAyD;AAAhD,yGAAA,cAAc,OAAA;AAAE,uGAAA,YAAY,OAAA;AACrC,wCAAsB;AACtB,8CAA4B;AAC5B,gDAA8B;AAC9B,qCAKmB;AAJjB,+HAAA,oCAAoC,OAAA;AACpC,6HAAA,kCAAkC,OAAA;AAClC,kHAAA,uBAAuB,OAAA;AACvB,gHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Account, AccountRaw, StakingResources, StakingResourcesRaw } from "@ledgerhq/types-live";
|
|
2
|
+
export declare function toStakingResourcesRaw(r: StakingResources): StakingResourcesRaw;
|
|
3
|
+
export declare function fromStakingResourcesRaw(r: StakingResourcesRaw): StakingResources;
|
|
4
|
+
export declare function assignStakingResourcesToAccountRaw(account: Account, accountRaw: AccountRaw): void;
|
|
5
|
+
export declare function assignStakingResourcesFromAccountRaw(accountRaw: AccountRaw, account: Account): void;
|
|
6
|
+
//# sourceMappingURL=staking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../../src/serialization/staking.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EASV,gBAAgB,EAChB,mBAAmB,EAGpB,MAAM,sBAAsB,CAAC;AAgJ9B,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,gBAAgB,GAAG,mBAAmB,CAa9E;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAahF;AAED,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAOjG;AAED,wBAAgB,oCAAoC,CAClD,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,GACf,IAAI,CAKN"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toStakingResourcesRaw = toStakingResourcesRaw;
|
|
4
|
+
exports.fromStakingResourcesRaw = fromStakingResourcesRaw;
|
|
5
|
+
exports.assignStakingResourcesToAccountRaw = assignStakingResourcesToAccountRaw;
|
|
6
|
+
exports.assignStakingResourcesFromAccountRaw = assignStakingResourcesFromAccountRaw;
|
|
7
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
8
|
+
/**
|
|
9
|
+
* This package compiles with `exactOptionalPropertyTypes`, so an absent optional field has to be
|
|
10
|
+
* left out of the object entirely rather than set to `undefined`. Key absence is also part of the
|
|
11
|
+
* contract downstream: coin-solana discriminates its position union on `"pendingRewards" in
|
|
12
|
+
* position`.
|
|
13
|
+
*/
|
|
14
|
+
function definedOnly(fields) {
|
|
15
|
+
const defined = {};
|
|
16
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
17
|
+
if (value !== undefined) {
|
|
18
|
+
defined[key] = value;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return defined;
|
|
22
|
+
}
|
|
23
|
+
function toAmountRaw(value) {
|
|
24
|
+
return bignumber_js_1.BigNumber.isBigNumber(value) ? value.toString() : undefined;
|
|
25
|
+
}
|
|
26
|
+
function fromAmountRaw(value) {
|
|
27
|
+
return typeof value === "string" ? new bignumber_js_1.BigNumber(value) : undefined;
|
|
28
|
+
}
|
|
29
|
+
function asString(value) {
|
|
30
|
+
return typeof value === "string" ? value : undefined;
|
|
31
|
+
}
|
|
32
|
+
function asBoolean(value) {
|
|
33
|
+
return typeof value === "boolean" ? value : undefined;
|
|
34
|
+
}
|
|
35
|
+
function asNumber(value) {
|
|
36
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
37
|
+
return undefined;
|
|
38
|
+
const parsed = Number(value);
|
|
39
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
40
|
+
}
|
|
41
|
+
function toPositionDetailsRaw(p) {
|
|
42
|
+
return definedOnly({
|
|
43
|
+
positionId: p.positionId,
|
|
44
|
+
activeAmount: toAmountRaw(p.activeAmount),
|
|
45
|
+
inactiveAmount: toAmountRaw(p.inactiveAmount),
|
|
46
|
+
withdrawableAmount: toAmountRaw(p.withdrawableAmount),
|
|
47
|
+
canStake: p.canStake,
|
|
48
|
+
canWithdraw: p.canWithdraw,
|
|
49
|
+
lockedReserve: toAmountRaw(p.lockedReserve),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function fromPositionDetailsRaw(p) {
|
|
53
|
+
return definedOnly({
|
|
54
|
+
positionId: asString(p.positionId),
|
|
55
|
+
activeAmount: fromAmountRaw(p.activeAmount),
|
|
56
|
+
inactiveAmount: fromAmountRaw(p.inactiveAmount),
|
|
57
|
+
withdrawableAmount: fromAmountRaw(p.withdrawableAmount),
|
|
58
|
+
canStake: asBoolean(p.canStake),
|
|
59
|
+
canWithdraw: asBoolean(p.canWithdraw),
|
|
60
|
+
lockedReserve: fromAmountRaw(p.lockedReserve),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function toStakingDelegationRaw(d) {
|
|
64
|
+
return {
|
|
65
|
+
...toPositionDetailsRaw(d),
|
|
66
|
+
...definedOnly({
|
|
67
|
+
validatorId: d.validatorId,
|
|
68
|
+
validatorName: d.validatorName,
|
|
69
|
+
shares: toAmountRaw(d.shares),
|
|
70
|
+
}),
|
|
71
|
+
validatorAddress: d.validatorAddress,
|
|
72
|
+
amount: d.amount.toString(),
|
|
73
|
+
pendingRewards: d.pendingRewards.toString(),
|
|
74
|
+
status: d.status,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function fromStakingDelegationRaw(d) {
|
|
78
|
+
return {
|
|
79
|
+
...fromPositionDetailsRaw(d),
|
|
80
|
+
...definedOnly({
|
|
81
|
+
validatorId: asString(d.validatorId),
|
|
82
|
+
validatorName: asString(d.validatorName),
|
|
83
|
+
shares: fromAmountRaw(d.shares),
|
|
84
|
+
}),
|
|
85
|
+
validatorAddress: d.validatorAddress,
|
|
86
|
+
amount: new bignumber_js_1.BigNumber(d.amount),
|
|
87
|
+
pendingRewards: new bignumber_js_1.BigNumber(d.pendingRewards),
|
|
88
|
+
status: d.status,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function toStakingRedelegationRaw(r) {
|
|
92
|
+
return {
|
|
93
|
+
validatorSrcAddress: r.validatorSrcAddress,
|
|
94
|
+
validatorDstAddress: r.validatorDstAddress,
|
|
95
|
+
amount: r.amount.toString(),
|
|
96
|
+
completionDate: r.completionDate.toISOString(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function fromStakingRedelegationRaw(r) {
|
|
100
|
+
return {
|
|
101
|
+
validatorSrcAddress: r.validatorSrcAddress,
|
|
102
|
+
validatorDstAddress: r.validatorDstAddress,
|
|
103
|
+
amount: new bignumber_js_1.BigNumber(r.amount),
|
|
104
|
+
completionDate: new Date(r.completionDate),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function toStakingUnbondingRaw(u) {
|
|
108
|
+
return {
|
|
109
|
+
...toPositionDetailsRaw(u),
|
|
110
|
+
...definedOnly({
|
|
111
|
+
validatorId: u.validatorId,
|
|
112
|
+
validatorName: u.validatorName,
|
|
113
|
+
withdrawId: u.withdrawId?.toString(),
|
|
114
|
+
status: u.status,
|
|
115
|
+
}),
|
|
116
|
+
validatorAddress: u.validatorAddress,
|
|
117
|
+
amount: u.amount.toString(),
|
|
118
|
+
completionDate: u.completionDate.toISOString(),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function fromStakingUnbondingRaw(u) {
|
|
122
|
+
return {
|
|
123
|
+
...fromPositionDetailsRaw(u),
|
|
124
|
+
...definedOnly({
|
|
125
|
+
validatorId: asString(u.validatorId),
|
|
126
|
+
validatorName: asString(u.validatorName),
|
|
127
|
+
withdrawId: asNumber(u.withdrawId),
|
|
128
|
+
status: u.status,
|
|
129
|
+
}),
|
|
130
|
+
validatorAddress: u.validatorAddress,
|
|
131
|
+
amount: new bignumber_js_1.BigNumber(u.amount),
|
|
132
|
+
completionDate: new Date(u.completionDate),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function toStakingResourcesRaw(r) {
|
|
136
|
+
return {
|
|
137
|
+
...definedOnly({
|
|
138
|
+
validators: r.validators,
|
|
139
|
+
actionFeeReserve: toAmountRaw(r.actionFeeReserve),
|
|
140
|
+
}),
|
|
141
|
+
delegations: r.delegations.map(toStakingDelegationRaw),
|
|
142
|
+
redelegations: r.redelegations.map(toStakingRedelegationRaw),
|
|
143
|
+
unbondings: r.unbondings.map(toStakingUnbondingRaw),
|
|
144
|
+
delegatedBalance: r.delegatedBalance.toString(),
|
|
145
|
+
pendingRewardsBalance: r.pendingRewardsBalance.toString(),
|
|
146
|
+
unbondingBalance: r.unbondingBalance.toString(),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function fromStakingResourcesRaw(r) {
|
|
150
|
+
return {
|
|
151
|
+
...definedOnly({
|
|
152
|
+
validators: r.validators,
|
|
153
|
+
actionFeeReserve: fromAmountRaw(r.actionFeeReserve),
|
|
154
|
+
}),
|
|
155
|
+
delegations: (r.delegations ?? []).map(fromStakingDelegationRaw),
|
|
156
|
+
redelegations: (r.redelegations ?? []).map(fromStakingRedelegationRaw),
|
|
157
|
+
unbondings: (r.unbondings ?? []).map(fromStakingUnbondingRaw),
|
|
158
|
+
delegatedBalance: new bignumber_js_1.BigNumber(r.delegatedBalance ?? "0"),
|
|
159
|
+
pendingRewardsBalance: new bignumber_js_1.BigNumber(r.pendingRewardsBalance ?? "0"),
|
|
160
|
+
unbondingBalance: new bignumber_js_1.BigNumber(r.unbondingBalance ?? "0"),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function assignStakingResourcesToAccountRaw(account, accountRaw) {
|
|
164
|
+
const stakingAccount = account;
|
|
165
|
+
if (stakingAccount.stakingResources) {
|
|
166
|
+
accountRaw.stakingResources = toStakingResourcesRaw(stakingAccount.stakingResources);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function assignStakingResourcesFromAccountRaw(accountRaw, account) {
|
|
170
|
+
const stakingResourcesRaw = accountRaw.stakingResources;
|
|
171
|
+
if (stakingResourcesRaw) {
|
|
172
|
+
account.stakingResources = fromStakingResourcesRaw(stakingResourcesRaw);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=staking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking.js","sourceRoot":"","sources":["../../src/serialization/staking.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAyC;AAkBzC;;;;;GAKG;AACH,SAAS,WAAW,CAClB,MAAS;IAET,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,OAAkE,CAAC;AAC5E,CAAC;AAED,SAAS,WAAW,CAAC,KAA4B;IAC/C,OAAO,wBAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,KAAyB;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,wBAAS,CAAC,K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UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,uBAAuB,CAAC;QAC7D,gBAAgB,EAAE,IAAI,wBAAS,CAAC,CAAC,CAAC,gBAAgB,IAAI,GAAG,CAAC;QAC1D,qBAAqB,EAAE,IAAI,wBAAS,CAAC,CAAC,CAAC,qBAAqB,IAAI,GAAG,CAAC;QACpE,gBAAgB,EAAE,IAAI,wBAAS,CAAC,CAAC,CAAC,gBAAgB,IAAI,GAAG,CAAC;KAC3D,CAAC;AACJ,CAAC;AAED,4CAAmD,OAAgB,EAAE,UAAsB;IACzF,MAAM,cAAc,GAAG,OAAyB,CAAC;IACjD,IAAI,cAAc,CAAC,gBAAgB,EAAE,CAAC;QACnC,UAAgC,CAAC,gBAAgB,GAAG,qBAAqB,CACxE,cAAc,CAAC,gBAAgB,CAChC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,8CACE,UAAsB,EACtB,OAAgB;IAEhB,MAAM,mBAAmB,GAAI,UAAgC,CAAC,gBAAgB,CAAC;IAC/E,IAAI,mBAAmB,EAAE,CAAC;QACvB,OAA0B,CAAC,gBAAgB,GAAG,uBAAuB,CAAC,mBAAmB,CAAC,CAAC;IAC9F,CAAC;AACH,CAAC"}
|
|
@@ -2,4 +2,5 @@ export { fromAccountRaw, toAccountRaw } from "./account";
|
|
|
2
2
|
export * from "./nft";
|
|
3
3
|
export * from "./operation";
|
|
4
4
|
export * from "./transaction";
|
|
5
|
+
export { assignStakingResourcesFromAccountRaw, assignStakingResourcesToAccountRaw, fromStakingResourcesRaw, toStakingResourcesRaw, } from "./staking";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,oCAAoC,EACpC,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,WAAW,CAAC"}
|
|
@@ -2,4 +2,5 @@ export { fromAccountRaw, toAccountRaw } from "./account";
|
|
|
2
2
|
export * from "./nft";
|
|
3
3
|
export * from "./operation";
|
|
4
4
|
export * from "./transaction";
|
|
5
|
+
export { assignStakingResourcesFromAccountRaw, assignStakingResourcesToAccountRaw, fromStakingResourcesRaw, toStakingResourcesRaw, } from "./staking";
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,oCAAoC,EACpC,kCAAkC,EAClC,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Account, AccountRaw, StakingResources, StakingResourcesRaw } from "@ledgerhq/types-live";
|
|
2
|
+
export declare function toStakingResourcesRaw(r: StakingResources): StakingResourcesRaw;
|
|
3
|
+
export declare function fromStakingResourcesRaw(r: StakingResourcesRaw): StakingResources;
|
|
4
|
+
export declare function assignStakingResourcesToAccountRaw(account: Account, accountRaw: AccountRaw): void;
|
|
5
|
+
export declare function assignStakingResourcesFromAccountRaw(accountRaw: AccountRaw, account: Account): void;
|
|
6
|
+
//# sourceMappingURL=staking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../../src/serialization/staking.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EASV,gBAAgB,EAChB,mBAAmB,EAGpB,MAAM,sBAAsB,CAAC;AAgJ9B,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,gBAAgB,GAAG,mBAAmB,CAa9E;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAahF;AAED,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,IAAI,CAOjG;AAED,wBAAgB,oCAAoC,CAClD,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,GACf,IAAI,CAKN"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
/**
|
|
3
|
+
* This package compiles with `exactOptionalPropertyTypes`, so an absent optional field has to be
|
|
4
|
+
* left out of the object entirely rather than set to `undefined`. Key absence is also part of the
|
|
5
|
+
* contract downstream: coin-solana discriminates its position union on `"pendingRewards" in
|
|
6
|
+
* position`.
|
|
7
|
+
*/
|
|
8
|
+
function definedOnly(fields) {
|
|
9
|
+
const defined = {};
|
|
10
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
11
|
+
if (value !== undefined) {
|
|
12
|
+
defined[key] = value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return defined;
|
|
16
|
+
}
|
|
17
|
+
function toAmountRaw(value) {
|
|
18
|
+
return BigNumber.isBigNumber(value) ? value.toString() : undefined;
|
|
19
|
+
}
|
|
20
|
+
function fromAmountRaw(value) {
|
|
21
|
+
return typeof value === "string" ? new BigNumber(value) : undefined;
|
|
22
|
+
}
|
|
23
|
+
function asString(value) {
|
|
24
|
+
return typeof value === "string" ? value : undefined;
|
|
25
|
+
}
|
|
26
|
+
function asBoolean(value) {
|
|
27
|
+
return typeof value === "boolean" ? value : undefined;
|
|
28
|
+
}
|
|
29
|
+
function asNumber(value) {
|
|
30
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
31
|
+
return undefined;
|
|
32
|
+
const parsed = Number(value);
|
|
33
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
34
|
+
}
|
|
35
|
+
function toPositionDetailsRaw(p) {
|
|
36
|
+
return definedOnly({
|
|
37
|
+
positionId: p.positionId,
|
|
38
|
+
activeAmount: toAmountRaw(p.activeAmount),
|
|
39
|
+
inactiveAmount: toAmountRaw(p.inactiveAmount),
|
|
40
|
+
withdrawableAmount: toAmountRaw(p.withdrawableAmount),
|
|
41
|
+
canStake: p.canStake,
|
|
42
|
+
canWithdraw: p.canWithdraw,
|
|
43
|
+
lockedReserve: toAmountRaw(p.lockedReserve),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function fromPositionDetailsRaw(p) {
|
|
47
|
+
return definedOnly({
|
|
48
|
+
positionId: asString(p.positionId),
|
|
49
|
+
activeAmount: fromAmountRaw(p.activeAmount),
|
|
50
|
+
inactiveAmount: fromAmountRaw(p.inactiveAmount),
|
|
51
|
+
withdrawableAmount: fromAmountRaw(p.withdrawableAmount),
|
|
52
|
+
canStake: asBoolean(p.canStake),
|
|
53
|
+
canWithdraw: asBoolean(p.canWithdraw),
|
|
54
|
+
lockedReserve: fromAmountRaw(p.lockedReserve),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function toStakingDelegationRaw(d) {
|
|
58
|
+
return {
|
|
59
|
+
...toPositionDetailsRaw(d),
|
|
60
|
+
...definedOnly({
|
|
61
|
+
validatorId: d.validatorId,
|
|
62
|
+
validatorName: d.validatorName,
|
|
63
|
+
shares: toAmountRaw(d.shares),
|
|
64
|
+
}),
|
|
65
|
+
validatorAddress: d.validatorAddress,
|
|
66
|
+
amount: d.amount.toString(),
|
|
67
|
+
pendingRewards: d.pendingRewards.toString(),
|
|
68
|
+
status: d.status,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function fromStakingDelegationRaw(d) {
|
|
72
|
+
return {
|
|
73
|
+
...fromPositionDetailsRaw(d),
|
|
74
|
+
...definedOnly({
|
|
75
|
+
validatorId: asString(d.validatorId),
|
|
76
|
+
validatorName: asString(d.validatorName),
|
|
77
|
+
shares: fromAmountRaw(d.shares),
|
|
78
|
+
}),
|
|
79
|
+
validatorAddress: d.validatorAddress,
|
|
80
|
+
amount: new BigNumber(d.amount),
|
|
81
|
+
pendingRewards: new BigNumber(d.pendingRewards),
|
|
82
|
+
status: d.status,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function toStakingRedelegationRaw(r) {
|
|
86
|
+
return {
|
|
87
|
+
validatorSrcAddress: r.validatorSrcAddress,
|
|
88
|
+
validatorDstAddress: r.validatorDstAddress,
|
|
89
|
+
amount: r.amount.toString(),
|
|
90
|
+
completionDate: r.completionDate.toISOString(),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function fromStakingRedelegationRaw(r) {
|
|
94
|
+
return {
|
|
95
|
+
validatorSrcAddress: r.validatorSrcAddress,
|
|
96
|
+
validatorDstAddress: r.validatorDstAddress,
|
|
97
|
+
amount: new BigNumber(r.amount),
|
|
98
|
+
completionDate: new Date(r.completionDate),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function toStakingUnbondingRaw(u) {
|
|
102
|
+
return {
|
|
103
|
+
...toPositionDetailsRaw(u),
|
|
104
|
+
...definedOnly({
|
|
105
|
+
validatorId: u.validatorId,
|
|
106
|
+
validatorName: u.validatorName,
|
|
107
|
+
withdrawId: u.withdrawId?.toString(),
|
|
108
|
+
status: u.status,
|
|
109
|
+
}),
|
|
110
|
+
validatorAddress: u.validatorAddress,
|
|
111
|
+
amount: u.amount.toString(),
|
|
112
|
+
completionDate: u.completionDate.toISOString(),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function fromStakingUnbondingRaw(u) {
|
|
116
|
+
return {
|
|
117
|
+
...fromPositionDetailsRaw(u),
|
|
118
|
+
...definedOnly({
|
|
119
|
+
validatorId: asString(u.validatorId),
|
|
120
|
+
validatorName: asString(u.validatorName),
|
|
121
|
+
withdrawId: asNumber(u.withdrawId),
|
|
122
|
+
status: u.status,
|
|
123
|
+
}),
|
|
124
|
+
validatorAddress: u.validatorAddress,
|
|
125
|
+
amount: new BigNumber(u.amount),
|
|
126
|
+
completionDate: new Date(u.completionDate),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export function toStakingResourcesRaw(r) {
|
|
130
|
+
return {
|
|
131
|
+
...definedOnly({
|
|
132
|
+
validators: r.validators,
|
|
133
|
+
actionFeeReserve: toAmountRaw(r.actionFeeReserve),
|
|
134
|
+
}),
|
|
135
|
+
delegations: r.delegations.map(toStakingDelegationRaw),
|
|
136
|
+
redelegations: r.redelegations.map(toStakingRedelegationRaw),
|
|
137
|
+
unbondings: r.unbondings.map(toStakingUnbondingRaw),
|
|
138
|
+
delegatedBalance: r.delegatedBalance.toString(),
|
|
139
|
+
pendingRewardsBalance: r.pendingRewardsBalance.toString(),
|
|
140
|
+
unbondingBalance: r.unbondingBalance.toString(),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export function fromStakingResourcesRaw(r) {
|
|
144
|
+
return {
|
|
145
|
+
...definedOnly({
|
|
146
|
+
validators: r.validators,
|
|
147
|
+
actionFeeReserve: fromAmountRaw(r.actionFeeReserve),
|
|
148
|
+
}),
|
|
149
|
+
delegations: (r.delegations ?? []).map(fromStakingDelegationRaw),
|
|
150
|
+
redelegations: (r.redelegations ?? []).map(fromStakingRedelegationRaw),
|
|
151
|
+
unbondings: (r.unbondings ?? []).map(fromStakingUnbondingRaw),
|
|
152
|
+
delegatedBalance: new BigNumber(r.delegatedBalance ?? "0"),
|
|
153
|
+
pendingRewardsBalance: new BigNumber(r.pendingRewardsBalance ?? "0"),
|
|
154
|
+
unbondingBalance: new BigNumber(r.unbondingBalance ?? "0"),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export function assignStakingResourcesToAccountRaw(account, accountRaw) {
|
|
158
|
+
const stakingAccount = account;
|
|
159
|
+
if (stakingAccount.stakingResources) {
|
|
160
|
+
accountRaw.stakingResources = toStakingResourcesRaw(stakingAccount.stakingResources);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function assignStakingResourcesFromAccountRaw(accountRaw, account) {
|
|
164
|
+
const stakingResourcesRaw = accountRaw.stakingResources;
|
|
165
|
+
if (stakingResourcesRaw) {
|
|
166
|
+
account.stakingResources = fromStakingResourcesRaw(stakingResourcesRaw);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=staking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking.js","sourceRoot":"","sources":["../../src/serialization/staking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAkBzC;;;;;GAKG;AACH,SAAS,WAAW,CAClB,MAAS;IAET,MAAM,OAAO,GAA4B,EAAE,CAAC;IAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,OAAkE,CA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
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0-nightly.20260829020445",
|
|
4
4
|
"description": "Framework for Ledger Wallet",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -96,13 +96,13 @@
|
|
|
96
96
|
},
|
|
97
97
|
"license": "Apache-2.0",
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"@ledgerhq/coin-module-framework": "8.
|
|
99
|
+
"@ledgerhq/coin-module-framework": "8.2.0",
|
|
100
100
|
"@ledgerhq/logs": "6.17.0",
|
|
101
101
|
"axios": "1.13.5",
|
|
102
102
|
"bignumber.js": "^9.1.2",
|
|
103
103
|
"bip32-path": "^0.4.2",
|
|
104
104
|
"eip55": "^2.1.0",
|
|
105
|
-
"expect": "30.
|
|
105
|
+
"expect": "30.4.1",
|
|
106
106
|
"imurmurhash": "^0.1.4",
|
|
107
107
|
"invariant": "^2.2.2",
|
|
108
108
|
"lodash": "4.17.21",
|
|
@@ -110,32 +110,33 @@
|
|
|
110
110
|
"rxjs": "7.8.2",
|
|
111
111
|
"uuid": "11.1.0",
|
|
112
112
|
"zod": "4.3.6",
|
|
113
|
-
"@ledgerhq/devices": "8.17.0",
|
|
114
|
-
"@ledgerhq/hw-transport": "^6.35.7",
|
|
115
|
-
"@ledgerhq/live-currency-format": "^0.14.2",
|
|
116
113
|
"@ledgerhq/live-config": "^3.8.0",
|
|
117
|
-
"@ledgerhq/
|
|
114
|
+
"@ledgerhq/hw-transport": "^6.35.7",
|
|
115
|
+
"@ledgerhq/live-currency-format": "^0.14.3-nightly.20260829020445",
|
|
116
|
+
"@ledgerhq/live-env": "^3.2.0-nightly.20260829020445",
|
|
118
117
|
"@ledgerhq/live-network": "^3.0.0",
|
|
119
|
-
"@ledgerhq/types-live": "^6.
|
|
118
|
+
"@ledgerhq/types-live": "^6.122.0-nightly.20260829020445",
|
|
119
|
+
"@ledgerhq/devices": "8.17.0"
|
|
120
120
|
},
|
|
121
121
|
"devDependencies": {
|
|
122
|
+
"@swc/core": "1.15.11",
|
|
123
|
+
"@swc/jest": "0.2.39",
|
|
122
124
|
"@types/imurmurhash": "^0.1.4",
|
|
123
|
-
"@types/node": "24.12.0",
|
|
124
125
|
"@types/invariant": "^2.2.2",
|
|
125
126
|
"@types/jest": "30.0.0",
|
|
126
127
|
"@types/lodash": "^4.17.21",
|
|
128
|
+
"@types/node": "24.12.0",
|
|
127
129
|
"@types/numeral": "^2.0.2",
|
|
128
130
|
"cross-env": "^7.0.3",
|
|
129
|
-
"jest": "30.
|
|
131
|
+
"jest": "30.4.1",
|
|
130
132
|
"oxfmt": "0.64.0",
|
|
131
133
|
"oxlint": "1.79.0",
|
|
132
134
|
"timemachine": "^0.3.2",
|
|
133
|
-
"@
|
|
134
|
-
"@swc/core": "1.15.11",
|
|
135
|
-
"@domain/entity-currency-crypto": "^0.10.0",
|
|
135
|
+
"@domain/entity-currency-crypto": "^0.11.0-nightly.20260829020445",
|
|
136
136
|
"@ledgerhq/hw-transport-node-speculos": "^6.34.7",
|
|
137
|
-
"@ledgerhq/
|
|
138
|
-
"@ledgerhq/
|
|
137
|
+
"@ledgerhq/live-dmk-speculos": "^0.10.7-nightly.20260829020445",
|
|
138
|
+
"@ledgerhq/test-quarantine": "0.0.0",
|
|
139
|
+
"@ledgerhq/wallet-framework-test-setup": "^0.1.8-nightly.20260829020445"
|
|
139
140
|
},
|
|
140
141
|
"scripts": {
|
|
141
142
|
"clean": "rm -rf lib lib-es",
|
|
@@ -2,3 +2,9 @@ export { fromAccountRaw, toAccountRaw } from "./account";
|
|
|
2
2
|
export * from "./nft";
|
|
3
3
|
export * from "./operation";
|
|
4
4
|
export * from "./transaction";
|
|
5
|
+
export {
|
|
6
|
+
assignStakingResourcesFromAccountRaw,
|
|
7
|
+
assignStakingResourcesToAccountRaw,
|
|
8
|
+
fromStakingResourcesRaw,
|
|
9
|
+
toStakingResourcesRaw,
|
|
10
|
+
} from "./staking";
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
AccountRaw,
|
|
5
|
+
StakingAccount,
|
|
6
|
+
StakingAccountRaw,
|
|
7
|
+
StakingResources,
|
|
8
|
+
StakingResourcesRaw,
|
|
9
|
+
} from "@ledgerhq/types-live";
|
|
10
|
+
import {
|
|
11
|
+
assignStakingResourcesFromAccountRaw,
|
|
12
|
+
assignStakingResourcesToAccountRaw,
|
|
13
|
+
fromStakingResourcesRaw,
|
|
14
|
+
toStakingResourcesRaw,
|
|
15
|
+
} from "./staking";
|
|
16
|
+
|
|
17
|
+
const minimalResources: StakingResources = {
|
|
18
|
+
delegations: [
|
|
19
|
+
{
|
|
20
|
+
validatorAddress: "validator-1",
|
|
21
|
+
amount: new BigNumber(100),
|
|
22
|
+
pendingRewards: new BigNumber(5),
|
|
23
|
+
status: "bonded",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
redelegations: [],
|
|
27
|
+
unbondings: [],
|
|
28
|
+
delegatedBalance: new BigNumber(100),
|
|
29
|
+
pendingRewardsBalance: new BigNumber(5),
|
|
30
|
+
unbondingBalance: new BigNumber(0),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const fullResources: StakingResources = {
|
|
34
|
+
delegations: [
|
|
35
|
+
{
|
|
36
|
+
validatorAddress: "validator-1",
|
|
37
|
+
validatorId: "id-1",
|
|
38
|
+
validatorName: "Validator One",
|
|
39
|
+
amount: new BigNumber(100),
|
|
40
|
+
pendingRewards: new BigNumber(5),
|
|
41
|
+
status: "activating",
|
|
42
|
+
shares: new BigNumber(42),
|
|
43
|
+
positionId: "position-1",
|
|
44
|
+
activeAmount: new BigNumber(80),
|
|
45
|
+
inactiveAmount: new BigNumber(20),
|
|
46
|
+
withdrawableAmount: new BigNumber(15),
|
|
47
|
+
canStake: true,
|
|
48
|
+
canWithdraw: false,
|
|
49
|
+
lockedReserve: new BigNumber(3),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
redelegations: [
|
|
53
|
+
{
|
|
54
|
+
validatorSrcAddress: "validator-1",
|
|
55
|
+
validatorDstAddress: "validator-2",
|
|
56
|
+
amount: new BigNumber(50),
|
|
57
|
+
completionDate: new Date("2026-01-02T03:04:05.000Z"),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
unbondings: [
|
|
61
|
+
{
|
|
62
|
+
validatorAddress: "validator-2",
|
|
63
|
+
validatorId: "id-2",
|
|
64
|
+
validatorName: "Validator Two",
|
|
65
|
+
amount: new BigNumber(70),
|
|
66
|
+
completionDate: new Date("2026-02-03T04:05:06.000Z"),
|
|
67
|
+
withdrawId: 7,
|
|
68
|
+
status: "withdrawable",
|
|
69
|
+
positionId: "position-2",
|
|
70
|
+
activeAmount: new BigNumber(0),
|
|
71
|
+
inactiveAmount: new BigNumber(70),
|
|
72
|
+
withdrawableAmount: new BigNumber(70),
|
|
73
|
+
canStake: false,
|
|
74
|
+
canWithdraw: true,
|
|
75
|
+
lockedReserve: new BigNumber(1),
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
delegatedBalance: new BigNumber(100),
|
|
79
|
+
pendingRewardsBalance: new BigNumber(5),
|
|
80
|
+
unbondingBalance: new BigNumber(70),
|
|
81
|
+
validators: [
|
|
82
|
+
{
|
|
83
|
+
validatorAddress: "validator-1",
|
|
84
|
+
validatorId: "id-1",
|
|
85
|
+
name: "Validator One",
|
|
86
|
+
votingPower: 1,
|
|
87
|
+
commission: 0.05,
|
|
88
|
+
estimatedYearlyRewardsRate: 0.07,
|
|
89
|
+
tokens: "1000",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
actionFeeReserve: new BigNumber(9),
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
describe("staking resources serialization", () => {
|
|
96
|
+
it("roundtrips every field of a fully populated resources object", () => {
|
|
97
|
+
expect(fromStakingResourcesRaw(toStakingResourcesRaw(fullResources))).toEqual(fullResources);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("serializes BigNumber and Date fields to JSON-safe primitives", () => {
|
|
101
|
+
const raw = toStakingResourcesRaw(fullResources);
|
|
102
|
+
|
|
103
|
+
expect(raw.delegatedBalance).toBe("100");
|
|
104
|
+
expect(raw.actionFeeReserve).toBe("9");
|
|
105
|
+
expect(raw.delegations[0]).toMatchObject({
|
|
106
|
+
amount: "100",
|
|
107
|
+
pendingRewards: "5",
|
|
108
|
+
shares: "42",
|
|
109
|
+
activeAmount: "80",
|
|
110
|
+
inactiveAmount: "20",
|
|
111
|
+
withdrawableAmount: "15",
|
|
112
|
+
lockedReserve: "3",
|
|
113
|
+
canStake: true,
|
|
114
|
+
canWithdraw: false,
|
|
115
|
+
});
|
|
116
|
+
expect(raw.redelegations[0].completionDate).toBe("2026-01-02T03:04:05.000Z");
|
|
117
|
+
expect(raw.unbondings[0]).toMatchObject({
|
|
118
|
+
completionDate: "2026-02-03T04:05:06.000Z",
|
|
119
|
+
withdrawId: "7",
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("omits absent optional fields instead of writing undefined", () => {
|
|
124
|
+
const raw = toStakingResourcesRaw(minimalResources);
|
|
125
|
+
|
|
126
|
+
expect(raw).not.toHaveProperty("validators");
|
|
127
|
+
expect(raw).not.toHaveProperty("actionFeeReserve");
|
|
128
|
+
for (const key of [
|
|
129
|
+
"positionId",
|
|
130
|
+
"activeAmount",
|
|
131
|
+
"inactiveAmount",
|
|
132
|
+
"withdrawableAmount",
|
|
133
|
+
"canStake",
|
|
134
|
+
"canWithdraw",
|
|
135
|
+
"lockedReserve",
|
|
136
|
+
"shares",
|
|
137
|
+
"validatorId",
|
|
138
|
+
"validatorName",
|
|
139
|
+
]) {
|
|
140
|
+
expect(raw.delegations[0]).not.toHaveProperty(key);
|
|
141
|
+
}
|
|
142
|
+
expect(fromStakingResourcesRaw(raw)).toEqual(minimalResources);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("preserves canStake/canWithdraw set to false through a roundtrip", () => {
|
|
146
|
+
const resources: StakingResources = {
|
|
147
|
+
...minimalResources,
|
|
148
|
+
delegations: [
|
|
149
|
+
{
|
|
150
|
+
...minimalResources.delegations[0],
|
|
151
|
+
canStake: false,
|
|
152
|
+
canWithdraw: false,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const revived = fromStakingResourcesRaw(toStakingResourcesRaw(resources));
|
|
158
|
+
|
|
159
|
+
expect(revived.delegations[0].canStake).toBe(false);
|
|
160
|
+
expect(revived.delegations[0].canWithdraw).toBe(false);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("defaults missing collections and balances when reviving a partial raw payload", () => {
|
|
164
|
+
const revived = fromStakingResourcesRaw({} as StakingResourcesRaw);
|
|
165
|
+
|
|
166
|
+
expect(revived).toEqual({
|
|
167
|
+
delegations: [],
|
|
168
|
+
redelegations: [],
|
|
169
|
+
unbondings: [],
|
|
170
|
+
delegatedBalance: new BigNumber(0),
|
|
171
|
+
pendingRewardsBalance: new BigNumber(0),
|
|
172
|
+
unbondingBalance: new BigNumber(0),
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it.each(["not-a-number", "", " "])(
|
|
177
|
+
"omits a malformed persisted withdrawId (%p) instead of reviving it as NaN",
|
|
178
|
+
withdrawId => {
|
|
179
|
+
const revived = fromStakingResourcesRaw({
|
|
180
|
+
delegations: [],
|
|
181
|
+
redelegations: [],
|
|
182
|
+
unbondings: [
|
|
183
|
+
{
|
|
184
|
+
validatorAddress: "validator-1",
|
|
185
|
+
amount: "10",
|
|
186
|
+
completionDate: "2026-02-03T04:05:06.000Z",
|
|
187
|
+
withdrawId,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
delegatedBalance: "0",
|
|
191
|
+
pendingRewardsBalance: "0",
|
|
192
|
+
unbondingBalance: "10",
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(revived.unbondings[0]).not.toHaveProperty("withdrawId");
|
|
196
|
+
},
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
it("revives a well-formed persisted withdrawId, including 0", () => {
|
|
200
|
+
const raw = toStakingResourcesRaw({
|
|
201
|
+
...minimalResources,
|
|
202
|
+
unbondings: [
|
|
203
|
+
{
|
|
204
|
+
validatorAddress: "validator-1",
|
|
205
|
+
amount: new BigNumber(10),
|
|
206
|
+
completionDate: new Date("2026-02-03T04:05:06.000Z"),
|
|
207
|
+
withdrawId: 0,
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expect(raw.unbondings[0].withdrawId).toBe("0");
|
|
213
|
+
expect(fromStakingResourcesRaw(raw).unbondings[0].withdrawId).toBe(0);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("assigns resources in both directions on an account", () => {
|
|
217
|
+
const account = { stakingResources: fullResources } as unknown as Account;
|
|
218
|
+
const accountRaw = {} as AccountRaw;
|
|
219
|
+
assignStakingResourcesToAccountRaw(account, accountRaw);
|
|
220
|
+
|
|
221
|
+
const revivedAccount = {} as Account;
|
|
222
|
+
assignStakingResourcesFromAccountRaw(accountRaw, revivedAccount);
|
|
223
|
+
|
|
224
|
+
expect((accountRaw as StakingAccountRaw).stakingResources).toBeDefined();
|
|
225
|
+
expect((revivedAccount as StakingAccount).stakingResources).toEqual(fullResources);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("leaves the target untouched when there is nothing to assign", () => {
|
|
229
|
+
const accountRaw = {} as AccountRaw;
|
|
230
|
+
assignStakingResourcesToAccountRaw({} as Account, accountRaw);
|
|
231
|
+
expect(accountRaw).not.toHaveProperty("stakingResources");
|
|
232
|
+
|
|
233
|
+
const account = {} as Account;
|
|
234
|
+
assignStakingResourcesFromAccountRaw({} as AccountRaw, account);
|
|
235
|
+
expect(account).not.toHaveProperty("stakingResources");
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type {
|
|
3
|
+
Account,
|
|
4
|
+
AccountRaw,
|
|
5
|
+
StakingAccount,
|
|
6
|
+
StakingAccountRaw,
|
|
7
|
+
StakingDelegation,
|
|
8
|
+
StakingDelegationRaw,
|
|
9
|
+
StakingPositionDetails,
|
|
10
|
+
StakingPositionDetailsRaw,
|
|
11
|
+
StakingRedelegation,
|
|
12
|
+
StakingRedelegationRaw,
|
|
13
|
+
StakingResources,
|
|
14
|
+
StakingResourcesRaw,
|
|
15
|
+
StakingUnbonding,
|
|
16
|
+
StakingUnbondingRaw,
|
|
17
|
+
} from "@ledgerhq/types-live";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This package compiles with `exactOptionalPropertyTypes`, so an absent optional field has to be
|
|
21
|
+
* left out of the object entirely rather than set to `undefined`. Key absence is also part of the
|
|
22
|
+
* contract downstream: coin-solana discriminates its position union on `"pendingRewards" in
|
|
23
|
+
* position`.
|
|
24
|
+
*/
|
|
25
|
+
function definedOnly<T extends object>(
|
|
26
|
+
fields: T,
|
|
27
|
+
): Partial<{ [K in keyof T]-?: Exclude<T[K], undefined> }> {
|
|
28
|
+
const defined: Record<string, unknown> = {};
|
|
29
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
30
|
+
if (value !== undefined) {
|
|
31
|
+
defined[key] = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return defined as Partial<{ [K in keyof T]-?: Exclude<T[K], undefined> }>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function toAmountRaw(value: BigNumber | undefined): string | undefined {
|
|
38
|
+
return BigNumber.isBigNumber(value) ? value.toString() : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function fromAmountRaw(value: string | undefined): BigNumber | undefined {
|
|
42
|
+
return typeof value === "string" ? new BigNumber(value) : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function asString(value: string | undefined): string | undefined {
|
|
46
|
+
return typeof value === "string" ? value : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function asBoolean(value: boolean | undefined): boolean | undefined {
|
|
50
|
+
return typeof value === "boolean" ? value : undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function asNumber(value: string | undefined): number | undefined {
|
|
54
|
+
if (typeof value !== "string" || value.trim() === "") return undefined;
|
|
55
|
+
const parsed = Number(value);
|
|
56
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function toPositionDetailsRaw(p: StakingPositionDetails): StakingPositionDetailsRaw {
|
|
60
|
+
return definedOnly({
|
|
61
|
+
positionId: p.positionId,
|
|
62
|
+
activeAmount: toAmountRaw(p.activeAmount),
|
|
63
|
+
inactiveAmount: toAmountRaw(p.inactiveAmount),
|
|
64
|
+
withdrawableAmount: toAmountRaw(p.withdrawableAmount),
|
|
65
|
+
canStake: p.canStake,
|
|
66
|
+
canWithdraw: p.canWithdraw,
|
|
67
|
+
lockedReserve: toAmountRaw(p.lockedReserve),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function fromPositionDetailsRaw(p: StakingPositionDetailsRaw): StakingPositionDetails {
|
|
72
|
+
return definedOnly({
|
|
73
|
+
positionId: asString(p.positionId),
|
|
74
|
+
activeAmount: fromAmountRaw(p.activeAmount),
|
|
75
|
+
inactiveAmount: fromAmountRaw(p.inactiveAmount),
|
|
76
|
+
withdrawableAmount: fromAmountRaw(p.withdrawableAmount),
|
|
77
|
+
canStake: asBoolean(p.canStake),
|
|
78
|
+
canWithdraw: asBoolean(p.canWithdraw),
|
|
79
|
+
lockedReserve: fromAmountRaw(p.lockedReserve),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function toStakingDelegationRaw(d: StakingDelegation): StakingDelegationRaw {
|
|
84
|
+
return {
|
|
85
|
+
...toPositionDetailsRaw(d),
|
|
86
|
+
...definedOnly({
|
|
87
|
+
validatorId: d.validatorId,
|
|
88
|
+
validatorName: d.validatorName,
|
|
89
|
+
shares: toAmountRaw(d.shares),
|
|
90
|
+
}),
|
|
91
|
+
validatorAddress: d.validatorAddress,
|
|
92
|
+
amount: d.amount.toString(),
|
|
93
|
+
pendingRewards: d.pendingRewards.toString(),
|
|
94
|
+
status: d.status,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function fromStakingDelegationRaw(d: StakingDelegationRaw): StakingDelegation {
|
|
99
|
+
return {
|
|
100
|
+
...fromPositionDetailsRaw(d),
|
|
101
|
+
...definedOnly({
|
|
102
|
+
validatorId: asString(d.validatorId),
|
|
103
|
+
validatorName: asString(d.validatorName),
|
|
104
|
+
shares: fromAmountRaw(d.shares),
|
|
105
|
+
}),
|
|
106
|
+
validatorAddress: d.validatorAddress,
|
|
107
|
+
amount: new BigNumber(d.amount),
|
|
108
|
+
pendingRewards: new BigNumber(d.pendingRewards),
|
|
109
|
+
status: d.status,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function toStakingRedelegationRaw(r: StakingRedelegation): StakingRedelegationRaw {
|
|
114
|
+
return {
|
|
115
|
+
validatorSrcAddress: r.validatorSrcAddress,
|
|
116
|
+
validatorDstAddress: r.validatorDstAddress,
|
|
117
|
+
amount: r.amount.toString(),
|
|
118
|
+
completionDate: r.completionDate.toISOString(),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function fromStakingRedelegationRaw(r: StakingRedelegationRaw): StakingRedelegation {
|
|
123
|
+
return {
|
|
124
|
+
validatorSrcAddress: r.validatorSrcAddress,
|
|
125
|
+
validatorDstAddress: r.validatorDstAddress,
|
|
126
|
+
amount: new BigNumber(r.amount),
|
|
127
|
+
completionDate: new Date(r.completionDate),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function toStakingUnbondingRaw(u: StakingUnbonding): StakingUnbondingRaw {
|
|
132
|
+
return {
|
|
133
|
+
...toPositionDetailsRaw(u),
|
|
134
|
+
...definedOnly({
|
|
135
|
+
validatorId: u.validatorId,
|
|
136
|
+
validatorName: u.validatorName,
|
|
137
|
+
withdrawId: u.withdrawId?.toString(),
|
|
138
|
+
status: u.status,
|
|
139
|
+
}),
|
|
140
|
+
validatorAddress: u.validatorAddress,
|
|
141
|
+
amount: u.amount.toString(),
|
|
142
|
+
completionDate: u.completionDate.toISOString(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function fromStakingUnbondingRaw(u: StakingUnbondingRaw): StakingUnbonding {
|
|
147
|
+
return {
|
|
148
|
+
...fromPositionDetailsRaw(u),
|
|
149
|
+
...definedOnly({
|
|
150
|
+
validatorId: asString(u.validatorId),
|
|
151
|
+
validatorName: asString(u.validatorName),
|
|
152
|
+
withdrawId: asNumber(u.withdrawId),
|
|
153
|
+
status: u.status,
|
|
154
|
+
}),
|
|
155
|
+
validatorAddress: u.validatorAddress,
|
|
156
|
+
amount: new BigNumber(u.amount),
|
|
157
|
+
completionDate: new Date(u.completionDate),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function toStakingResourcesRaw(r: StakingResources): StakingResourcesRaw {
|
|
162
|
+
return {
|
|
163
|
+
...definedOnly({
|
|
164
|
+
validators: r.validators,
|
|
165
|
+
actionFeeReserve: toAmountRaw(r.actionFeeReserve),
|
|
166
|
+
}),
|
|
167
|
+
delegations: r.delegations.map(toStakingDelegationRaw),
|
|
168
|
+
redelegations: r.redelegations.map(toStakingRedelegationRaw),
|
|
169
|
+
unbondings: r.unbondings.map(toStakingUnbondingRaw),
|
|
170
|
+
delegatedBalance: r.delegatedBalance.toString(),
|
|
171
|
+
pendingRewardsBalance: r.pendingRewardsBalance.toString(),
|
|
172
|
+
unbondingBalance: r.unbondingBalance.toString(),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function fromStakingResourcesRaw(r: StakingResourcesRaw): StakingResources {
|
|
177
|
+
return {
|
|
178
|
+
...definedOnly({
|
|
179
|
+
validators: r.validators,
|
|
180
|
+
actionFeeReserve: fromAmountRaw(r.actionFeeReserve),
|
|
181
|
+
}),
|
|
182
|
+
delegations: (r.delegations ?? []).map(fromStakingDelegationRaw),
|
|
183
|
+
redelegations: (r.redelegations ?? []).map(fromStakingRedelegationRaw),
|
|
184
|
+
unbondings: (r.unbondings ?? []).map(fromStakingUnbondingRaw),
|
|
185
|
+
delegatedBalance: new BigNumber(r.delegatedBalance ?? "0"),
|
|
186
|
+
pendingRewardsBalance: new BigNumber(r.pendingRewardsBalance ?? "0"),
|
|
187
|
+
unbondingBalance: new BigNumber(r.unbondingBalance ?? "0"),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function assignStakingResourcesToAccountRaw(account: Account, accountRaw: AccountRaw): void {
|
|
192
|
+
const stakingAccount = account as StakingAccount;
|
|
193
|
+
if (stakingAccount.stakingResources) {
|
|
194
|
+
(accountRaw as StakingAccountRaw).stakingResources = toStakingResourcesRaw(
|
|
195
|
+
stakingAccount.stakingResources,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function assignStakingResourcesFromAccountRaw(
|
|
201
|
+
accountRaw: AccountRaw,
|
|
202
|
+
account: Account,
|
|
203
|
+
): void {
|
|
204
|
+
const stakingResourcesRaw = (accountRaw as StakingAccountRaw).stakingResources;
|
|
205
|
+
if (stakingResourcesRaw) {
|
|
206
|
+
(account as StakingAccount).stakingResources = fromStakingResourcesRaw(stakingResourcesRaw);
|
|
207
|
+
}
|
|
208
|
+
}
|