@ritbit/v4-client-js 2.2.2 → 2.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ritbit/v4-client-js",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "General client library for the new RITBIT Chain",
5
5
  "main": "build/cjs/src/index.js",
6
6
  "module": "build/esm/src/index.js",
@@ -1,6 +1,14 @@
1
1
  import { Any } from 'cosmjs-types/google/protobuf/any';
2
2
  import * as Vesting from 'cosmjs-types/cosmos/vesting/v1beta1/vesting';
3
3
 
4
+ /** Один период вестинга (для PeriodicVestingAccount). */
5
+ export interface VestingPeriod {
6
+ /** Длительность периода в секундах. */
7
+ lengthSec: number;
8
+ /** Монеты, разблокируемые в конце периода. */
9
+ amount: Array<{ denom: string; amount: string }>;
10
+ }
11
+
4
12
  /**
5
13
  * Нормализованная информация о вестинг-аккаунте, достаточная для расчёта
6
14
  * разблокированной суммы. Типы Continuous/Delayed/Periodic/Base сводятся к этому виду.
@@ -12,6 +20,8 @@ export interface VestingInfo {
12
20
  startTimeSec: number;
13
21
  /** Конец вестинга (Unix секунды). */
14
22
  endTimeSec: number;
23
+ /** Периоды (только для PeriodicVestingAccount). */
24
+ vestingPeriods?: VestingPeriod[];
15
25
  }
16
26
 
17
27
  const VESTING_TYPE_URLS = [
@@ -74,6 +84,10 @@ export function decodeVestingFromAny(raw: Any): VestingInfo | null {
74
84
  })),
75
85
  startTimeSec: bigintToNumber(acc.startTime),
76
86
  endTimeSec: bigintToNumber(base.endTime),
87
+ vestingPeriods: acc.vestingPeriods.map((p) => ({
88
+ lengthSec: bigintToNumber(p.length),
89
+ amount: p.amount.map((c) => ({ denom: c.denom, amount: c.amount })),
90
+ })),
77
91
  };
78
92
  }
79
93
  case '/cosmos.vesting.v1beta1.BaseVestingAccount': {
@@ -98,7 +112,10 @@ export function decodeVestingFromAny(raw: Any): VestingInfo | null {
98
112
 
99
113
  /**
100
114
  * Считает разблокированную сумму в base units для денома по VestingInfo.
101
- * Линейная разблокировка от startTimeSec до endTimeSec.
115
+ *
116
+ * - Continuous / Delayed / Base: линейная разблокировка от startTimeSec до endTimeSec.
117
+ * - Periodic: каждый период — клифф; сумма периода разблокируется целиком
118
+ * по истечении его длительности (start + Σ lengths предыдущих + length текущего).
102
119
  */
103
120
  export function computeUnlockedAmount(
104
121
  info: VestingInfo,
@@ -112,6 +129,23 @@ export function computeUnlockedAmount(
112
129
  const nowSec = Math.floor(Date.now() / 1000);
113
130
  if (nowSec <= startTimeSec) return '0';
114
131
  if (nowSec >= endTimeSec) return entry.amount;
132
+
133
+ // Periodic: считаем по периодам (клиффы)
134
+ if (info.vestingPeriods?.length) {
135
+ let unlocked = BigInt(0);
136
+ let periodStartSec = startTimeSec;
137
+ for (const p of info.vestingPeriods) {
138
+ const periodEndSec = periodStartSec + p.lengthSec;
139
+ if (nowSec >= periodEndSec) {
140
+ const periodAmount = p.amount.find((c) => c.denom === denom)?.amount ?? '0';
141
+ unlocked += BigInt(periodAmount);
142
+ }
143
+ periodStartSec = periodEndSec;
144
+ }
145
+ return String(unlocked);
146
+ }
147
+
148
+ // Linear (Continuous / Delayed / Base)
115
149
  const period = endTimeSec - startTimeSec;
116
150
  const elapsed = nowSec - startTimeSec;
117
151
  const unlocked = (total * BigInt(elapsed)) / BigInt(period);