@raac/rpc 1.2.0-beta.14 → 1.2.0-beta.16

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.
@@ -124,6 +124,12 @@
124
124
  "name": "r-rpmdepmUSD (RpmUSD/DEpmUSD LP)",
125
125
  "contract": "0x79c9b8b1E679c1e1bD09a56Fde6a61aa8C0014Aa",
126
126
  "stakingToken": "0x421E9431E751c8fC02E53F8e54a1772aE6021BeD"
127
+ },
128
+ {
129
+ "id": "r-ireetpmUSD",
130
+ "name": "r-ireetpmUSD (iREET/pmUSD LP)",
131
+ "contract": "0x084D7252d83AD886348EC58f4b1e5261Ab7f67c9",
132
+ "stakingToken": "0x7F7d0924C9082F4C3F0D5D97bF9a26C3D3DEf706"
127
133
  }
128
134
  ]
129
135
  },
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkAccountHealth = void 0;
4
+ const _helpers_1 = require("./_helpers");
5
+ /**
6
+ * Whether a user's position is currently overcollateralised.
7
+ *
8
+ * Reserved collateral is scheduled to leave and so is netted out before the check, which is
9
+ * why a position can go unhealthy on requestUnlock alone, without any new borrowing.
10
+ */
11
+ const checkAccountHealth = async (chainId, account, provider) => {
12
+ const contract = await (0, _helpers_1.getLiquidLockerContract)(chainId, provider);
13
+ return contract.checkAccountHealth(account);
14
+ };
15
+ exports.checkAccountHealth = checkAccountHealth;
@@ -5,21 +5,29 @@ const ethers_1 = require("ethers");
5
5
  const _helpers_1 = require("./_helpers");
6
6
  const EPOCH_DURATION = 7 * 24 * 60 * 60;
7
7
  /**
8
- * Returns the user's pending (future) unlock entries.
8
+ * Returns the user's pending (future) unlock buckets.
9
+ *
10
+ * Reservations are partial: a bucket can be wholly open, wholly reserved, or split between
11
+ * the two, so `reserved` alone does not say how much of it is leaving. Use `openAmount` for
12
+ * what is still reservable via requestUnlock and `reservedAmount` for what is already scheduled.
9
13
  */
10
14
  const getUserLocks = async (chainId, account, provider) => {
11
15
  const contract = await (0, _helpers_1.getLiquidLockerContract)(chainId, provider);
12
16
  const result = await contract.getUserLocks(account);
13
17
  return result.map((entry) => {
14
- const pendingUnlock = entry.pendingUnlock ?? entry[0];
15
- const unlockEpoch = entry.unlockEpoch ?? entry[1];
16
- const reserved = entry.reserved ?? entry[2];
18
+ const pendingUnlock = entry.pendingUnlock;
19
+ const reservedAmount = entry.reservedAmount;
20
+ const unlockEpoch = entry.unlockEpoch;
21
+ const openAmount = pendingUnlock > reservedAmount ? pendingUnlock - reservedAmount : BigInt(0);
17
22
  return {
18
23
  pendingUnlock: ethers_1.ethers.formatEther(pendingUnlock),
24
+ reservedAmount: ethers_1.ethers.formatEther(reservedAmount),
25
+ openAmount: ethers_1.ethers.formatEther(openAmount),
19
26
  unlockEpoch: Number(unlockEpoch),
20
27
  unlockTimestamp: Number(unlockEpoch) * EPOCH_DURATION,
21
- reserved,
22
- raw: { pendingUnlock, unlockEpoch, reserved },
28
+ reserved: reservedAmount > BigInt(0),
29
+ fullyReserved: reservedAmount >= pendingUnlock && pendingUnlock > BigInt(0),
30
+ raw: { pendingUnlock, reservedAmount, openAmount, unlockEpoch },
23
31
  };
24
32
  });
25
33
  };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.previewWithdraw = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Projects how the caller's matured reservations would split on withdrawUnlocked.
8
+ *
9
+ * A withdrawal never leaves the debt undercollateralised: whatever the position is short of
10
+ * the collateral the debt requires is relocked rather than paid out. Mirrors the same split
11
+ * withdrawUnlocked applies, so the preview cannot drift from the transaction.
12
+ */
13
+ const previewWithdraw = async (chainId, account, provider) => {
14
+ const contract = await (0, _helpers_1.getLiquidLockerContract)(chainId, provider);
15
+ const [payout, relock] = await contract.previewWithdraw(account);
16
+ return {
17
+ payout: ethers_1.ethers.formatEther(payout),
18
+ relock: ethers_1.ethers.formatEther(relock),
19
+ raw: { payout, relock },
20
+ };
21
+ };
22
+ exports.previewWithdraw = previewWithdraw;
@@ -3,14 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requestUnlock = void 0;
4
4
  const _helpers_1 = require("./_helpers");
5
5
  /**
6
- * Reserve `numLocks` of the caller's pending future-locks for unlock at their existing maturity epoch(s).
7
- * Health is checked against (totalLocked - newUnlock) and current debt.
6
+ * Schedule `amount` (in wei) of the caller's locked RAAC for unlock.
7
+ *
8
+ * The locker reserves against the caller's future unlock buckets soonest-maturing first,
9
+ * partial-reserving the boundary bucket. When the remainder left in that bucket would fall
10
+ * below veRAAC's minimum lock, the whole bucket is taken instead — so the amount actually
11
+ * scheduled can exceed `amount` by up to that minimum. Scheduling less than `amount`
12
+ * (open capacity is short) reverts with InsufficientToUnlock.
13
+ *
14
+ * Health is checked against (totalLocked - alreadyReserved - amount) and current debt,
15
+ * reverting with InsufficientCollateral when the remaining collateral would not back the debt.
8
16
  */
9
- const requestUnlock = async (chainId, numLocks, signer) => {
17
+ const requestUnlock = async (chainId, amount, signer) => {
10
18
  if (!signer)
11
19
  throw new Error("Signer is required");
12
20
  const contract = await (0, _helpers_1.getLiquidLockerContract)(chainId, signer);
13
- const tx = await contract.requestUnlock(numLocks);
21
+ const tx = await contract.requestUnlock(amount);
14
22
  await tx.wait();
15
23
  return tx;
16
24
  };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getMinLockAmount = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const chains_1 = __importDefault(require("../../../configs/chains"));
9
+ const getContractAddress_1 = require("../../getContractAddress");
10
+ const artifacts_1 = require("../../../utils/artifacts");
11
+ /**
12
+ * Gets the smallest lock veRAAC will accept, in wei.
13
+ *
14
+ * Consumers that schedule unlocks need this: the liquid locker refuses to leave a remainder
15
+ * below this threshold in a bucket, taking the whole bucket instead, so an unlock request can
16
+ * be rounded up by as much as this amount.
17
+ *
18
+ * @param chainId - The chain/network to use.
19
+ * @param provider - Optional ethers.js Provider instance.
20
+ * @returns The minimum lock amount in wei.
21
+ */
22
+ const getMinLockAmount = async (chainId, provider) => {
23
+ if (!provider) {
24
+ const rpc = chains_1.default[chainId].rpcs[0];
25
+ provider = new ethers_1.ethers.JsonRpcProvider(rpc);
26
+ }
27
+ const contractAddress = (0, getContractAddress_1.getContractAddress)(chainId, "veraac");
28
+ const abi = (0, artifacts_1.getABI)("veraac");
29
+ // Not cast to VeRAACToken: the checked-in typechain declaration predates
30
+ // getMinLockAmount, though the ABI this resolves carries it.
31
+ const contract = new ethers_1.ethers.Contract(contractAddress, abi, provider);
32
+ return (await contract.getMinLockAmount());
33
+ };
34
+ exports.getMinLockAmount = getMinLockAmount;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.distributeRewards = exports.finalizeRagequit = exports.ragequitLock = exports.ragequitAll = exports.claimReward = exports.withdraw = exports.extend = exports.increaseWithApproval = exports.increase = exports.lockWithApproval = exports.lock = exports.getMaxUnclaimedDistributions = exports.getRagequitEpochs = exports.getRagequitRequest = exports.getCheckpoint = exports.getUserPointHistory = exports.getEarned = exports.getClaimable = exports.getClaimed = exports.getRawTotalSupply = exports.getRawBalanceOf = exports.getTotalSupplyAtTime = exports.getTotalSupplyAt = exports.getBalanceAtTime = exports.getBalanceAt = exports.getEffectiveLockEnd = exports.getMinLockEnd = exports.getMaxLockEnd = exports.getGlobalLockInfo = exports.getLocks = exports.getLockedBalance = exports.getTotalSupply = exports.getBalance = void 0;
3
+ exports.distributeRewards = exports.finalizeRagequit = exports.ragequitLock = exports.ragequitAll = exports.claimReward = exports.withdraw = exports.extend = exports.increaseWithApproval = exports.increase = exports.lockWithApproval = exports.lock = exports.getMaxUnclaimedDistributions = exports.getRagequitEpochs = exports.getRagequitRequest = exports.getCheckpoint = exports.getUserPointHistory = exports.getEarned = exports.getClaimable = exports.getClaimed = exports.getRawTotalSupply = exports.getRawBalanceOf = exports.getTotalSupplyAtTime = exports.getTotalSupplyAt = exports.getBalanceAtTime = exports.getBalanceAt = exports.getEffectiveLockEnd = exports.getMinLockAmount = exports.getMinLockEnd = exports.getMaxLockEnd = exports.getGlobalLockInfo = exports.getLocks = exports.getLockedBalance = exports.getTotalSupply = exports.getBalance = void 0;
4
4
  var getBalance_1 = require("./getBalance");
5
5
  Object.defineProperty(exports, "getBalance", { enumerable: true, get: function () { return getBalance_1.getBalance; } });
6
6
  var getTotalSupply_1 = require("./getTotalSupply");
@@ -15,6 +15,8 @@ var getMaxLockEnd_1 = require("./getMaxLockEnd");
15
15
  Object.defineProperty(exports, "getMaxLockEnd", { enumerable: true, get: function () { return getMaxLockEnd_1.getMaxLockEnd; } });
16
16
  var getMinLockEnd_1 = require("./getMinLockEnd");
17
17
  Object.defineProperty(exports, "getMinLockEnd", { enumerable: true, get: function () { return getMinLockEnd_1.getMinLockEnd; } });
18
+ var getMinLockAmount_1 = require("./getMinLockAmount");
19
+ Object.defineProperty(exports, "getMinLockAmount", { enumerable: true, get: function () { return getMinLockAmount_1.getMinLockAmount; } });
18
20
  var getEffectiveLockEnd_1 = require("./getEffectiveLockEnd");
19
21
  Object.defineProperty(exports, "getEffectiveLockEnd", { enumerable: true, get: function () { return getEffectiveLockEnd_1.getEffectiveLockEnd; } });
20
22
  var getBalanceAt_1 = require("./getBalanceAt");
@@ -182,6 +182,7 @@ import { getRawBalanceOf as getVeRAACRawBalanceOf } from "./contracts/tokens/veR
182
182
  import { getRawTotalSupply as getVeRAACRawTotalSupply } from "./contracts/tokens/veRAAC/getRawTotalSupply";
183
183
  import { getEffectiveLockEnd as getVeRAACEffectiveLockEnd } from "./contracts/tokens/veRAAC/getEffectiveLockEnd";
184
184
  import { getMinLockEnd as getVeRAACMinLockEnd } from "./contracts/tokens/veRAAC/getMinLockEnd";
185
+ import { getMinLockAmount as getVeRAACMinLockAmount } from "./contracts/tokens/veRAAC/getMinLockAmount";
185
186
  import { getMaxUnclaimedDistributions as getVeRAACMaxUnclaimedDistributions } from "./contracts/tokens/veRAAC/getMaxUnclaimedDistributions";
186
187
  import { getBalance as getRAACBalance } from "./contracts/tokens/RAAC/getBalance";
187
188
  import { getTotalSupply as getRAACTotalSupply } from "./contracts/tokens/RAAC/getTotalSupply";
@@ -202,6 +203,8 @@ import { getUserLocks as getUserLocksLiquidLocker } from "./contracts/lockers/li
202
203
  import { getGlobalInfo as getGlobalInfoLiquidLocker } from "./contracts/lockers/liquidLocker/getGlobalInfo";
203
204
  import { getConfig as getConfigLiquidLocker } from "./contracts/lockers/liquidLocker/getConfig";
204
205
  import { isKeeper as isKeeperLiquidLocker } from "./contracts/lockers/liquidLocker/isKeeper";
206
+ import { previewWithdraw as previewWithdrawLiquidLocker } from "./contracts/lockers/liquidLocker/previewWithdraw";
207
+ import { checkAccountHealth as checkAccountHealthLiquidLocker } from "./contracts/lockers/liquidLocker/checkAccountHealth";
205
208
  import { deposit as depositMaturityVault } from "./contracts/lockers/maturityVault/deposit";
206
209
  import { depositFor as depositForMaturityVault } from "./contracts/lockers/maturityVault/depositFor";
207
210
  import { withdraw as withdrawMaturityVault } from "./contracts/lockers/maturityVault/withdraw";
@@ -440,6 +443,7 @@ declare class RPCLibrary {
440
443
  getRawTotalSupply: typeof getVeRAACRawTotalSupply;
441
444
  getEffectiveLockEnd: typeof getVeRAACEffectiveLockEnd;
442
445
  getMinLockEnd: typeof getVeRAACMinLockEnd;
446
+ getMinLockAmount: typeof getVeRAACMinLockAmount;
443
447
  getMaxUnclaimedDistributions: typeof getVeRAACMaxUnclaimedDistributions;
444
448
  };
445
449
  crvUSD: {
@@ -487,6 +491,8 @@ declare class RPCLibrary {
487
491
  getGlobalInfo: typeof getGlobalInfoLiquidLocker;
488
492
  getConfig: typeof getConfigLiquidLocker;
489
493
  isKeeper: typeof isKeeperLiquidLocker;
494
+ previewWithdraw: typeof previewWithdrawLiquidLocker;
495
+ checkAccountHealth: typeof checkAccountHealthLiquidLocker;
490
496
  };
491
497
  maturityVault: {
492
498
  deposit: typeof depositMaturityVault;
@@ -0,0 +1,9 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../../configs/chains";
3
+ /**
4
+ * Whether a user's position is currently overcollateralised.
5
+ *
6
+ * Reserved collateral is scheduled to leave and so is netted out before the check, which is
7
+ * why a position can go unhealthy on requestUnlock alone, without any new borrowing.
8
+ */
9
+ export declare const checkAccountHealth: (chainId: ChainId, account: string, provider?: Provider) => Promise<boolean>;
@@ -1,17 +1,30 @@
1
1
  import { Provider } from "ethers";
2
2
  import { ChainId } from "../../../configs/chains";
3
3
  export interface PendingUnlockInfo {
4
+ /** Total RAAC held in this bucket, maturing at the start of `unlockEpoch`. */
4
5
  pendingUnlock: string;
6
+ /** The portion of `pendingUnlock` already scheduled to unlock. */
7
+ reservedAmount: string;
8
+ /** The portion still open, which auto-relocks at maturity unless reserved first. */
9
+ openAmount: string;
5
10
  unlockEpoch: number;
6
11
  unlockTimestamp: number;
12
+ /** Any part of this bucket is scheduled to unlock. */
7
13
  reserved: boolean;
14
+ /** The whole bucket is scheduled to unlock; nothing here will relock. */
15
+ fullyReserved: boolean;
8
16
  raw: {
9
17
  pendingUnlock: bigint;
18
+ reservedAmount: bigint;
19
+ openAmount: bigint;
10
20
  unlockEpoch: bigint;
11
- reserved: boolean;
12
21
  };
13
22
  }
14
23
  /**
15
- * Returns the user's pending (future) unlock entries.
24
+ * Returns the user's pending (future) unlock buckets.
25
+ *
26
+ * Reservations are partial: a bucket can be wholly open, wholly reserved, or split between
27
+ * the two, so `reserved` alone does not say how much of it is leaving. Use `openAmount` for
28
+ * what is still reservable via requestUnlock and `reservedAmount` for what is already scheduled.
16
29
  */
17
30
  export declare const getUserLocks: (chainId: ChainId, account: string, provider?: Provider) => Promise<PendingUnlockInfo[]>;
@@ -0,0 +1,20 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../../configs/chains";
3
+ export interface LiquidLockerWithdrawPreview {
4
+ /** RAAC that would be paid out to the user. */
5
+ payout: string;
6
+ /** RAAC that would be relocked instead, to keep the outstanding debt backed. */
7
+ relock: string;
8
+ raw: {
9
+ payout: bigint;
10
+ relock: bigint;
11
+ };
12
+ }
13
+ /**
14
+ * Projects how the caller's matured reservations would split on withdrawUnlocked.
15
+ *
16
+ * A withdrawal never leaves the debt undercollateralised: whatever the position is short of
17
+ * the collateral the debt requires is relocked rather than paid out. Mirrors the same split
18
+ * withdrawUnlocked applies, so the preview cannot drift from the transaction.
19
+ */
20
+ export declare const previewWithdraw: (chainId: ChainId, account: string, provider?: Provider) => Promise<LiquidLockerWithdrawPreview>;
@@ -1,7 +1,15 @@
1
1
  import { Signer } from "ethers";
2
2
  import { ChainId } from "../../../configs/chains";
3
3
  /**
4
- * Reserve `numLocks` of the caller's pending future-locks for unlock at their existing maturity epoch(s).
5
- * Health is checked against (totalLocked - newUnlock) and current debt.
4
+ * Schedule `amount` (in wei) of the caller's locked RAAC for unlock.
5
+ *
6
+ * The locker reserves against the caller's future unlock buckets soonest-maturing first,
7
+ * partial-reserving the boundary bucket. When the remainder left in that bucket would fall
8
+ * below veRAAC's minimum lock, the whole bucket is taken instead — so the amount actually
9
+ * scheduled can exceed `amount` by up to that minimum. Scheduling less than `amount`
10
+ * (open capacity is short) reverts with InsufficientToUnlock.
11
+ *
12
+ * Health is checked against (totalLocked - alreadyReserved - amount) and current debt,
13
+ * reverting with InsufficientCollateral when the remaining collateral would not back the debt.
6
14
  */
7
- export declare const requestUnlock: (chainId: ChainId, numLocks: number | bigint, signer: Signer) => Promise<import("ethers").ContractTransactionResponse>;
15
+ export declare const requestUnlock: (chainId: ChainId, amount: string | number | bigint, signer: Signer) => Promise<import("ethers").ContractTransactionResponse>;
@@ -0,0 +1,14 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../../configs/chains";
3
+ /**
4
+ * Gets the smallest lock veRAAC will accept, in wei.
5
+ *
6
+ * Consumers that schedule unlocks need this: the liquid locker refuses to leave a remainder
7
+ * below this threshold in a bucket, taking the whole bucket instead, so an unlock request can
8
+ * be rounded up by as much as this amount.
9
+ *
10
+ * @param chainId - The chain/network to use.
11
+ * @param provider - Optional ethers.js Provider instance.
12
+ * @returns The minimum lock amount in wei.
13
+ */
14
+ export declare const getMinLockAmount: (chainId: ChainId, provider?: Provider) => Promise<bigint>;
@@ -5,6 +5,7 @@ export { getLocks, type LockedBalance } from "./getLocks";
5
5
  export { getGlobalLockInfo, type GlobalLockInfo } from "./getGlobalLockInfo";
6
6
  export { getMaxLockEnd } from "./getMaxLockEnd";
7
7
  export { getMinLockEnd } from "./getMinLockEnd";
8
+ export { getMinLockAmount } from "./getMinLockAmount";
8
9
  export { getEffectiveLockEnd } from "./getEffectiveLockEnd";
9
10
  export { getBalanceAt } from "./getBalanceAt";
10
11
  export { getBalanceAtTime } from "./getBalanceAtTime";