@ritbit/v4-client-js 2.2.2 → 2.2.4
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/__tests__/helpers/constants.ts +2 -1
- package/__tests__/lib/validation.test.ts +2 -2
- package/build/cjs/__tests__/helpers/constants.js +1 -1
- package/build/cjs/__tests__/lib/validation.test.js +1 -1
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event.js +89 -2
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event_info.js +45 -2
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/genesis.js +12 -11
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/params.js +12 -3
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.js +164 -30
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.lcd.js +65 -18
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.rpc.Query.js +13 -4
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.js +259 -8
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.rpc.msg.js +13 -1
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/withdrawal.js +81 -37
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/bridge/bridge.js +84 -4
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/signer/signer.js +19 -3
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/indexer/events/events.js +47 -7
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/transfer.js +72 -4
- package/build/cjs/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/tx.js +4 -4
- package/build/cjs/src/clients/composite-client.js +3 -3
- package/build/cjs/src/clients/modules/composer.js +1 -1
- package/build/cjs/src/clients/modules/get.js +11 -1
- package/build/cjs/src/clients/modules/markets.js +5 -1
- package/build/cjs/src/clients/modules/post.js +23 -7
- package/build/cjs/src/lib/validation.js +1 -1
- package/build/cjs/src/lib/vesting.js +25 -2
- package/build/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/build/esm/__tests__/helpers/constants.d.ts +2 -2
- package/build/esm/__tests__/helpers/constants.d.ts.map +1 -1
- package/build/esm/__tests__/helpers/constants.js +1 -1
- package/build/esm/__tests__/lib/validation.test.js +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event.d.ts +31 -0
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event.js +88 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event_info.d.ts +17 -0
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event_info.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/bridge_event_info.js +44 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/genesis.d.ts +7 -11
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/genesis.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/genesis.js +13 -12
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/params.d.ts +8 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/params.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/params.js +12 -3
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.d.ts +70 -51
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.js +164 -30
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.lcd.d.ts +5 -4
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.lcd.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.lcd.js +65 -18
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.rpc.Query.d.ts +18 -22
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.rpc.Query.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/query.rpc.Query.js +14 -5
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.d.ts +93 -2
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.js +260 -9
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.rpc.msg.d.ts +10 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.rpc.msg.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/tx.rpc.msg.js +14 -2
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/withdrawal.d.ts +33 -16
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/withdrawal.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/bridge/withdrawal.js +80 -36
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/bridge/bridge.d.ts +37 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/bridge/bridge.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/bridge/bridge.js +84 -4
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/signer/signer.d.ts +4 -0
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/signer/signer.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/daemons/signer/signer.js +19 -3
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/indexer/events/events.d.ts +23 -0
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/indexer/events/events.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/indexer/events/events.js +47 -7
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/rpc.query.d.ts +4 -3
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/rpc.query.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/transfer.d.ts +26 -0
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/transfer.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/transfer.js +71 -3
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/tx.d.ts +3 -3
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/tx.d.ts.map +1 -1
- package/build/esm/node_modules/@ritbit/v4-proto/src/codegen/ritbit/sending/tx.js +5 -5
- package/build/esm/src/clients/composite-client.d.ts +2 -1
- package/build/esm/src/clients/composite-client.d.ts.map +1 -1
- package/build/esm/src/clients/composite-client.js +3 -3
- package/build/esm/src/clients/modules/composer.js +1 -1
- package/build/esm/src/clients/modules/get.d.ts +6 -0
- package/build/esm/src/clients/modules/get.d.ts.map +1 -1
- package/build/esm/src/clients/modules/get.js +11 -1
- package/build/esm/src/clients/modules/markets.d.ts +1 -0
- package/build/esm/src/clients/modules/markets.d.ts.map +1 -1
- package/build/esm/src/clients/modules/markets.js +5 -1
- package/build/esm/src/clients/modules/post.d.ts +2 -1
- package/build/esm/src/clients/modules/post.d.ts.map +1 -1
- package/build/esm/src/clients/modules/post.js +23 -7
- package/build/esm/src/lib/validation.d.ts +2 -2
- package/build/esm/src/lib/validation.d.ts.map +1 -1
- package/build/esm/src/lib/validation.js +1 -1
- package/build/esm/src/lib/vesting.d.ts +16 -1
- package/build/esm/src/lib/vesting.d.ts.map +1 -1
- package/build/esm/src/lib/vesting.js +25 -2
- package/build/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/scripts/publish-if-not-exists.sh +2 -2
- package/src/clients/composite-client.ts +5 -1
- package/src/clients/modules/composer.ts +2 -2
- package/src/clients/modules/get.ts +17 -0
- package/src/clients/modules/markets.ts +5 -0
- package/src/clients/modules/post.ts +22 -1
- package/src/lib/validation.ts +2 -2
- package/src/lib/vesting.ts +35 -1
- package/ritbit-v4-client-js-2.2.1.tgz +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ritbit/v4-client-js",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
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",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@cosmjs/tendermint-rpc": "^0.32.4",
|
|
58
58
|
"@cosmjs/utils": "^0.32.4",
|
|
59
59
|
"@osmonauts/lcd": "^0.6.0",
|
|
60
|
-
"@ritbit/v4-proto": "^2.0.
|
|
60
|
+
"@ritbit/v4-proto": "^2.0.4",
|
|
61
61
|
"@scure/bip32": "^1.1.5",
|
|
62
62
|
"@scure/bip39": "^1.1.1",
|
|
63
63
|
"axios": "1.1.3",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Coin } from '@cosmjs/amino';
|
|
1
2
|
import { EncodeObject } from '@cosmjs/proto-signing';
|
|
2
3
|
import { Account, GasPrice, IndexedTx, StdFee } from '@cosmjs/stargate';
|
|
3
4
|
import { Method, tendermint37 } from '@cosmjs/tendermint-rpc';
|
|
@@ -187,6 +188,8 @@ export class CompositeClient {
|
|
|
187
188
|
memo?: string,
|
|
188
189
|
broadcastMode?: BroadcastMode,
|
|
189
190
|
account?: () => Promise<Account>,
|
|
191
|
+
gasAdjustment?: number,
|
|
192
|
+
additionalFeeCoins?: Coin[],
|
|
190
193
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
191
194
|
return this.validatorClient.post.send(
|
|
192
195
|
subaccount,
|
|
@@ -196,7 +199,8 @@ export class CompositeClient {
|
|
|
196
199
|
memo,
|
|
197
200
|
broadcastMode,
|
|
198
201
|
account,
|
|
199
|
-
|
|
202
|
+
gasAdjustment,
|
|
203
|
+
additionalFeeCoins,
|
|
200
204
|
);
|
|
201
205
|
}
|
|
202
206
|
|
|
@@ -69,7 +69,7 @@ import {
|
|
|
69
69
|
SubaccountId,
|
|
70
70
|
MsgCreateMarketPermissionless,
|
|
71
71
|
MsgCreateTransfer,
|
|
72
|
-
|
|
72
|
+
MsgTransfer,
|
|
73
73
|
MsgDepositToSubaccount,
|
|
74
74
|
MsgWithdrawFromSubaccount,
|
|
75
75
|
} from './proto-includes';
|
|
@@ -270,7 +270,7 @@ export class Composer {
|
|
|
270
270
|
number: recipientSubaccountNumber,
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
-
const transfer:
|
|
273
|
+
const transfer: MsgTransfer = {
|
|
274
274
|
sender,
|
|
275
275
|
recipient,
|
|
276
276
|
assetId,
|
|
@@ -468,6 +468,23 @@ export class Get {
|
|
|
468
468
|
return DistributionModule.QueryDelegationTotalRewardsResponse.decode(data);
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
+
/**
|
|
472
|
+
* @description Get bridge EventParams (chains, token mappings, withdrawal fees).
|
|
473
|
+
*
|
|
474
|
+
* @returns EventParams with bridge config including withdrawal_fee per TokenMapping
|
|
475
|
+
*/
|
|
476
|
+
async getBridgeEventParams(): Promise<BridgeModule.QueryEventParamsResponse> {
|
|
477
|
+
const requestData = Uint8Array.from(
|
|
478
|
+
BridgeModule.QueryEventParamsRequest.encode({}).finish(),
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
const data: Uint8Array = await this.sendQuery(
|
|
482
|
+
'/ritbit.bridge.Query/EventParams',
|
|
483
|
+
requestData,
|
|
484
|
+
);
|
|
485
|
+
return BridgeModule.QueryEventParamsResponse.decode(data);
|
|
486
|
+
}
|
|
487
|
+
|
|
471
488
|
/**
|
|
472
489
|
* @description Get all delayed complete bridge messages, optionally filtered by address.
|
|
473
490
|
*
|
|
@@ -6,6 +6,11 @@ import RestClient from './rest';
|
|
|
6
6
|
* @description REST endpoints for data unrelated to a particular address.
|
|
7
7
|
*/
|
|
8
8
|
export default class MarketsClient extends RestClient {
|
|
9
|
+
async getAssets(): Promise<Data> {
|
|
10
|
+
const uri = '/v4/assets';
|
|
11
|
+
return this.get(uri);
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
async getPerpetualMarkets(market?: string): Promise<Data> {
|
|
10
15
|
const uri = '/v4/perpetualMarkets';
|
|
11
16
|
return this.get(uri, { ticker: market });
|
|
@@ -188,6 +188,7 @@ export class Post {
|
|
|
188
188
|
broadcastMode?: BroadcastMode,
|
|
189
189
|
account?: () => Promise<Account>,
|
|
190
190
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
191
|
+
additionalFeeCoins?: Coin[],
|
|
191
192
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
192
193
|
const msgsPromise = messaging();
|
|
193
194
|
const accountPromise = account ? await account() : this.account(subaccount.address);
|
|
@@ -203,6 +204,7 @@ export class Post {
|
|
|
203
204
|
memo ?? this.defaultClientMemo,
|
|
204
205
|
broadcastMode ?? this.defaultBroadcastMode(msgs),
|
|
205
206
|
gasAdjustment,
|
|
207
|
+
additionalFeeCoins,
|
|
206
208
|
);
|
|
207
209
|
}
|
|
208
210
|
|
|
@@ -248,13 +250,14 @@ export class Post {
|
|
|
248
250
|
gasPrice: GasPrice = this.getGasPrice(),
|
|
249
251
|
memo?: string,
|
|
250
252
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
253
|
+
additionalFeeCoins?: Coin[],
|
|
251
254
|
): Promise<Uint8Array> {
|
|
252
255
|
// protocol expects timestamp nonce in UTC milliseconds, which is the unit returned by Date.now()
|
|
253
256
|
const sequence = this.useTimestampNonce
|
|
254
257
|
? Date.now() + this.timestampNonceOffsetMs
|
|
255
258
|
: account.sequence;
|
|
256
259
|
// Simulate transaction if no fee is specified.
|
|
257
|
-
|
|
260
|
+
let fee: StdFee = zeroFee
|
|
258
261
|
? {
|
|
259
262
|
amount: [],
|
|
260
263
|
gas: '1000000',
|
|
@@ -268,6 +271,22 @@ export class Post {
|
|
|
268
271
|
gasAdjustment,
|
|
269
272
|
);
|
|
270
273
|
|
|
274
|
+
if (additionalFeeCoins && additionalFeeCoins.length > 0) {
|
|
275
|
+
const byDenom = new Map<string, string>();
|
|
276
|
+
for (const c of fee.amount) {
|
|
277
|
+
const cur = byDenom.get(c.denom) ?? '0';
|
|
278
|
+
byDenom.set(c.denom, (BigInt(cur) + BigInt(c.amount)).toString());
|
|
279
|
+
}
|
|
280
|
+
for (const c of additionalFeeCoins) {
|
|
281
|
+
const cur = byDenom.get(c.denom) ?? '0';
|
|
282
|
+
byDenom.set(c.denom, (BigInt(cur) + BigInt(c.amount)).toString());
|
|
283
|
+
}
|
|
284
|
+
fee = {
|
|
285
|
+
...fee,
|
|
286
|
+
amount: Array.from(byDenom.entries()).map(([denom, amount]) => ({ denom, amount })),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
271
290
|
const txOptions: TransactionOptions = {
|
|
272
291
|
sequence,
|
|
273
292
|
accountNumber: account.accountNumber,
|
|
@@ -310,6 +329,7 @@ export class Post {
|
|
|
310
329
|
memo?: string,
|
|
311
330
|
broadcastMode?: BroadcastMode,
|
|
312
331
|
gasAdjustment: number = GAS_MULTIPLIER,
|
|
332
|
+
additionalFeeCoins?: Coin[],
|
|
313
333
|
): Promise<BroadcastTxAsyncResponse | BroadcastTxSyncResponse | IndexedTx> {
|
|
314
334
|
const signedTransaction = await this.signTransaction(
|
|
315
335
|
subaccount,
|
|
@@ -319,6 +339,7 @@ export class Post {
|
|
|
319
339
|
gasPrice,
|
|
320
340
|
memo,
|
|
321
341
|
gasAdjustment,
|
|
342
|
+
additionalFeeCoins,
|
|
322
343
|
);
|
|
323
344
|
return this.sendSignedTransaction(signedTransaction, broadcastMode);
|
|
324
345
|
}
|
package/src/lib/validation.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Long from 'long';
|
|
|
3
3
|
|
|
4
4
|
import { BECH32_PREFIX, MAX_SUBACCOUNT_NUMBER, MAX_UINT_32 } from '../clients/constants';
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
MsgTransfer,
|
|
7
7
|
OrderFlags,
|
|
8
8
|
ICancelOrder,
|
|
9
9
|
IPlaceOrder,
|
|
@@ -116,7 +116,7 @@ export function validateBatchCancelOrderMessage(
|
|
|
116
116
|
* @describe validateTransferMessage validates that a transfer to place has fields that would be
|
|
117
117
|
* valid on-chain.
|
|
118
118
|
*/
|
|
119
|
-
export function validateTransferMessage(transfer:
|
|
119
|
+
export function validateTransferMessage(transfer: MsgTransfer): UserError | undefined {
|
|
120
120
|
if (!verifySubaccountNumber(transfer.sender!!.number || 0)) {
|
|
121
121
|
return new UserError(
|
|
122
122
|
`senderSubaccountNumber: ${
|
package/src/lib/vesting.ts
CHANGED
|
@@ -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
|
-
*
|
|
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);
|
|
Binary file
|