@raac/rpc 2.0.0-beta.19 → 2.0.0-beta.20
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/dist/RPCLibrary.js
CHANGED
|
@@ -330,6 +330,7 @@ const voteGovernance_1 = require("./contracts/lockers/liquidLocker/voteGovernanc
|
|
|
330
330
|
const getUserInfo_1 = require("./contracts/lockers/liquidLocker/getUserInfo");
|
|
331
331
|
const getUserLocks_1 = require("./contracts/lockers/liquidLocker/getUserLocks");
|
|
332
332
|
const getGlobalInfo_1 = require("./contracts/lockers/liquidLocker/getGlobalInfo");
|
|
333
|
+
const getUnlockSchedule_1 = require("./contracts/lockers/liquidLocker/getUnlockSchedule");
|
|
333
334
|
const getConfig_1 = require("./contracts/lockers/liquidLocker/getConfig");
|
|
334
335
|
const isKeeper_1 = require("./contracts/lockers/liquidLocker/isKeeper");
|
|
335
336
|
const hasHarvestRole_1 = require("./contracts/lockers/liquidLocker/hasHarvestRole");
|
|
@@ -676,6 +677,7 @@ class RPCLibrary {
|
|
|
676
677
|
getUserInfo: getUserInfo_1.getUserInfo,
|
|
677
678
|
getUserLocks: getUserLocks_1.getUserLocks,
|
|
678
679
|
getGlobalInfo: getGlobalInfo_1.getGlobalInfo,
|
|
680
|
+
getUnlockSchedule: getUnlockSchedule_1.getUnlockSchedule,
|
|
679
681
|
getConfig: getConfig_1.getConfig,
|
|
680
682
|
isKeeper: isKeeper_1.isKeeper,
|
|
681
683
|
hasHarvestRole: hasHarvestRole_1.hasHarvestRole,
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUnlockSchedule = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const amount_1 = require("../../../utils/amount");
|
|
6
|
+
const rpcError_1 = require("../../../utils/rpcError");
|
|
7
|
+
const _helpers_1 = require("./_helpers");
|
|
8
|
+
/** The locker's epochs are veRAAC's: 7 days, numbered from the UNIX epoch. */
|
|
9
|
+
const EPOCH_SECONDS = 7 * 86_400;
|
|
10
|
+
/** At most one entry per epoch a lock can end in; a list longer than this is read no further. */
|
|
11
|
+
const MAX_ENTRIES = 104;
|
|
12
|
+
const BATCH = 16;
|
|
13
|
+
/**
|
|
14
|
+
* The RAAC scheduled to unlock from the liquid locker, by epoch: every entry of `epochEnds` from `processedEpochIndexes`
|
|
15
|
+
* on, with its `epochEndToLockAmount`. Processed epochs are left out (their RAAC is already withdrawable); an entry
|
|
16
|
+
* whose end has passed but is not processed yet is marked `due`.
|
|
17
|
+
*
|
|
18
|
+
* @param chainId - The chain/network to use.
|
|
19
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
20
|
+
* @returns Pending epochs in the order the locker schedules them, soonest first.
|
|
21
|
+
*/
|
|
22
|
+
const getUnlockSchedule = async (chainId, provider) => {
|
|
23
|
+
const contract = await (0, _helpers_1.getLiquidLockerContract)(chainId, provider);
|
|
24
|
+
try {
|
|
25
|
+
const runner = contract.runner?.provider ?? provider;
|
|
26
|
+
const [start, block] = await Promise.all([contract.processedEpochIndexes(), runner?.getBlock("latest")]);
|
|
27
|
+
const now = block ? Number(block.timestamp) : Math.floor(Date.now() / 1000);
|
|
28
|
+
const out = [];
|
|
29
|
+
// The array has no length getter: read it in parallel batches until an index past its end reverts.
|
|
30
|
+
const endAt = async (i) => {
|
|
31
|
+
try {
|
|
32
|
+
return await contract.epochEnds(i);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// Reading past the end of the array reverts; anything else is a real failure.
|
|
36
|
+
if (ethers_1.ethers.isError(error, "CALL_EXCEPTION"))
|
|
37
|
+
return null;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
for (let i = Number(start); i < Number(start) + MAX_ENTRIES; i += BATCH) {
|
|
42
|
+
const ends = await Promise.all(Array.from({ length: BATCH }, (_, k) => endAt(i + k)));
|
|
43
|
+
const found = ends.slice(0, ends.indexOf(null) < 0 ? BATCH : ends.indexOf(null));
|
|
44
|
+
const amounts = await Promise.all(found.map((end) => contract.epochEndToLockAmount(end)));
|
|
45
|
+
found.forEach((end, k) => {
|
|
46
|
+
if (amounts[k] === BigInt(0))
|
|
47
|
+
return;
|
|
48
|
+
const epochEnd = Number(end);
|
|
49
|
+
out.push({ epochEnd, epoch: Math.floor(epochEnd / EPOCH_SECONDS), amount: (0, amount_1.toTokenAmount)(chainId, "raactoken", amounts[k]), due: epochEnd <= now });
|
|
50
|
+
});
|
|
51
|
+
if (found.length < BATCH)
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
return out.sort((a, b) => a.epochEnd - b.epochEnd);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw (0, rpcError_1.toRpcError)("lockers.liquidLocker.getUnlockSchedule", error, { chainId, address: await contract.getAddress() });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
exports.getUnlockSchedule = getUnlockSchedule;
|
|
@@ -252,6 +252,7 @@ import { voteGovernance as voteGovernanceLiquidLocker } from "./contracts/locker
|
|
|
252
252
|
import { getUserInfo as getUserInfoLiquidLocker } from "./contracts/lockers/liquidLocker/getUserInfo";
|
|
253
253
|
import { getUserLocks as getUserLocksLiquidLocker } from "./contracts/lockers/liquidLocker/getUserLocks";
|
|
254
254
|
import { getGlobalInfo as getGlobalInfoLiquidLocker } from "./contracts/lockers/liquidLocker/getGlobalInfo";
|
|
255
|
+
import { getUnlockSchedule as getUnlockScheduleLiquidLocker } from "./contracts/lockers/liquidLocker/getUnlockSchedule";
|
|
255
256
|
import { getConfig as getConfigLiquidLocker } from "./contracts/lockers/liquidLocker/getConfig";
|
|
256
257
|
import { isKeeper as isKeeperLiquidLocker } from "./contracts/lockers/liquidLocker/isKeeper";
|
|
257
258
|
import { hasHarvestRole as hasHarvestRoleLiquidLocker } from "./contracts/lockers/liquidLocker/hasHarvestRole";
|
|
@@ -600,6 +601,7 @@ declare class RPCLibrary {
|
|
|
600
601
|
getUserInfo: typeof getUserInfoLiquidLocker;
|
|
601
602
|
getUserLocks: typeof getUserLocksLiquidLocker;
|
|
602
603
|
getGlobalInfo: typeof getGlobalInfoLiquidLocker;
|
|
604
|
+
getUnlockSchedule: typeof getUnlockScheduleLiquidLocker;
|
|
603
605
|
getConfig: typeof getConfigLiquidLocker;
|
|
604
606
|
isKeeper: typeof isKeeperLiquidLocker;
|
|
605
607
|
hasHarvestRole: typeof hasHarvestRoleLiquidLocker;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
export interface LockerUnlockEpoch {
|
|
5
|
+
/** UNIX seconds the epoch ends and its RAAC moves from locked to withdrawable. */
|
|
6
|
+
epochEnd: number;
|
|
7
|
+
/** `epochEnd / 7 days`, the epoch number the locker and veRAAC use. */
|
|
8
|
+
epoch: number;
|
|
9
|
+
/** RAAC that unlock requests scheduled for this epoch end. */
|
|
10
|
+
amount: TokenAmount;
|
|
11
|
+
/** The end has passed but the locker has not processed it yet; the next deposit, unlock or harvest does. */
|
|
12
|
+
due: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The RAAC scheduled to unlock from the liquid locker, by epoch: every entry of `epochEnds` from `processedEpochIndexes`
|
|
16
|
+
* on, with its `epochEndToLockAmount`. Processed epochs are left out (their RAAC is already withdrawable); an entry
|
|
17
|
+
* whose end has passed but is not processed yet is marked `due`.
|
|
18
|
+
*
|
|
19
|
+
* @param chainId - The chain/network to use.
|
|
20
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
21
|
+
* @returns Pending epochs in the order the locker schedules them, soonest first.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getUnlockSchedule: (chainId: ChainId, provider?: Provider) => Promise<LockerUnlockEpoch[]>;
|