@raac/rpc 2.0.0-beta.12 → 2.0.0-beta.14
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 +53 -8
- package/dist/configs/chains/11155111.json +13 -0
- package/dist/contracts/complianceRegistry/getStatuses.js +40 -0
- package/dist/contracts/crvUSDToUSDOracle/getState.js +58 -0
- package/dist/contracts/curve/common/_helpers.js +57 -0
- package/dist/contracts/curve/common/addLiquidity.js +30 -0
- package/dist/contracts/curve/common/calcTokenAmount.js +23 -0
- package/dist/contracts/curve/common/calcWithdrawOneCoin.js +21 -0
- package/dist/contracts/curve/common/exchange.js +33 -0
- package/dist/contracts/curve/common/getDy.js +22 -0
- package/dist/contracts/curve/common/index.js +7 -0
- package/dist/contracts/curve/common/removeLiquidity.js +30 -0
- package/dist/contracts/curve/common/removeLiquidityOneCoin.js +31 -0
- package/dist/contracts/faucet/claim.js +37 -0
- package/dist/contracts/faucet/index.js +17 -0
- package/dist/contracts/feeCollector/getState.js +100 -0
- package/dist/contracts/getRoles.js +35 -0
- package/dist/contracts/housePrices/getState.js +41 -0
- package/dist/contracts/psm/getVaultSettings.js +60 -0
- package/dist/contracts/treasury/getState.js +46 -0
- package/dist/minter/emissionSchedule.js +90 -0
- package/dist/pools/lendingPool/getAdminState.js +47 -0
- package/dist/pools/rwaVault/getRegisteredAdapters.js +78 -0
- package/dist/pools/rwaVault/getSeedStatus.js +45 -0
- package/dist/pools/stabilityPool/getAdminState.js +42 -0
- package/dist/pools/stabilityPool/liquidation.js +297 -0
- package/dist/types/RPCLibrary.d.ts +44 -0
- package/dist/types/contracts/complianceRegistry/getStatuses.d.ts +25 -0
- package/dist/types/contracts/crvUSDToUSDOracle/getState.d.ts +36 -0
- package/dist/types/contracts/curve/common/_helpers.d.ts +10 -1
- package/dist/types/contracts/curve/common/addLiquidity.d.ts +14 -0
- package/dist/types/contracts/curve/common/calcTokenAmount.d.ts +10 -0
- package/dist/types/contracts/curve/common/calcWithdrawOneCoin.d.ts +8 -0
- package/dist/types/contracts/curve/common/exchange.d.ts +16 -0
- package/dist/types/contracts/curve/common/getDy.d.ts +8 -0
- package/dist/types/contracts/curve/common/index.d.ts +7 -0
- package/dist/types/contracts/curve/common/removeLiquidity.d.ts +14 -0
- package/dist/types/contracts/curve/common/removeLiquidityOneCoin.d.ts +15 -0
- package/dist/types/contracts/faucet/claim.d.ts +18 -0
- package/dist/types/contracts/faucet/index.d.ts +1 -0
- package/dist/types/contracts/feeCollector/getState.d.ts +42 -0
- package/dist/types/contracts/getRoles.d.ts +15 -0
- package/dist/types/contracts/housePrices/getState.d.ts +24 -0
- package/dist/types/contracts/psm/getVaultSettings.d.ts +38 -0
- package/dist/types/contracts/treasury/getState.d.ts +24 -0
- package/dist/types/minter/emissionSchedule.d.ts +53 -0
- package/dist/types/pools/lendingPool/getAdminState.d.ts +26 -0
- package/dist/types/pools/rwaVault/getRegisteredAdapters.d.ts +33 -0
- package/dist/types/pools/rwaVault/getSeedStatus.d.ts +27 -0
- package/dist/types/pools/stabilityPool/getAdminState.d.ts +25 -0
- package/dist/types/pools/stabilityPool/liquidation.d.ts +112 -0
- package/package.json +14 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains/index";
|
|
3
|
+
import { TokenAmount } from "../../utils/amount";
|
|
4
|
+
/** The six places a fee type splits into, as FeeCollector names them. */
|
|
5
|
+
export declare const FEE_TARGETS: readonly ["TREASURY", "REPAIR_FUND", "BURN", "VERAAC", "RAAC_CORP", "OTHER"];
|
|
6
|
+
export type FeeTarget = (typeof FEE_TARGETS)[number];
|
|
7
|
+
/** Fee type names used across the protocol; others show as their raw bytes32. */
|
|
8
|
+
export declare const KNOWN_FEE_TYPES: string[];
|
|
9
|
+
/** One fee type and how it splits, in basis points (the shares add up to at most 10_000; the contract adds the rest to the treasury). */
|
|
10
|
+
export interface FeeTypeInfo {
|
|
11
|
+
id: string;
|
|
12
|
+
/** The known name, or null when `id` is not one of `KNOWN_FEE_TYPES`. */
|
|
13
|
+
name: string | null;
|
|
14
|
+
shares: Record<FeeTarget, bigint>;
|
|
15
|
+
}
|
|
16
|
+
/** Fees collected for one token and fee type, still owed to each target. */
|
|
17
|
+
export interface CollectedFees {
|
|
18
|
+
token: string;
|
|
19
|
+
feeType: string;
|
|
20
|
+
amounts: Record<FeeTarget, TokenAmount>;
|
|
21
|
+
}
|
|
22
|
+
export interface FeeCollectorState {
|
|
23
|
+
paused: boolean;
|
|
24
|
+
/** Where each target's share is sent. */
|
|
25
|
+
targets: Record<FeeTarget, string>;
|
|
26
|
+
feeTypes: FeeTypeInfo[];
|
|
27
|
+
tokens: {
|
|
28
|
+
address: string;
|
|
29
|
+
symbol: string;
|
|
30
|
+
decimals: number;
|
|
31
|
+
}[];
|
|
32
|
+
/** Every token and fee type pair that has something owed. */
|
|
33
|
+
collected: CollectedFees[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reads the FeeCollector: pause state, targets, fee types and their splits, supported tokens, and what is still owed
|
|
37
|
+
* per token, fee type and target. Walks `supportedTokens(i)` until the index reverts.
|
|
38
|
+
* @param chainId The chain id.
|
|
39
|
+
* @param provider The provider to read with.
|
|
40
|
+
*/
|
|
41
|
+
declare function getState(chainId: ChainId, provider: Provider): Promise<FeeCollectorState>;
|
|
42
|
+
export default getState;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../configs/chains";
|
|
3
|
+
/** OpenZeppelin role ids: DEFAULT_ADMIN_ROLE is zero, every other role is the keccak of its name. */
|
|
4
|
+
export declare function roleId(role: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Which of an AccessControl contract's roles each account holds, e.g. to show what a Safe and a wallet may do.
|
|
7
|
+
* @param chainId The chain id, for error context.
|
|
8
|
+
* @param contractAddress The AccessControl contract.
|
|
9
|
+
* @param roles Role names ("GUARDIAN_ROLE", "DEFAULT_ADMIN_ROLE") or raw 32-byte ids.
|
|
10
|
+
* @param accounts The accounts to check.
|
|
11
|
+
* @param provider The provider to read with.
|
|
12
|
+
* @returns Keyed by lowercased account address, then by role as passed in.
|
|
13
|
+
*/
|
|
14
|
+
declare function getRoles(chainId: ChainId, contractAddress: string, roles: string[], accounts: string[], provider: Provider): Promise<Record<string, Record<string, boolean>>>;
|
|
15
|
+
export default getRoles;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains/index";
|
|
3
|
+
/** RAACHousePrices administration state. */
|
|
4
|
+
export interface HousePricesState {
|
|
5
|
+
owner: string;
|
|
6
|
+
/** The only account allowed to call `setHousePrice(s)`. */
|
|
7
|
+
oracle: string;
|
|
8
|
+
crvUSDToUSDOracle: string;
|
|
9
|
+
/** Properties that have a price. */
|
|
10
|
+
count: number;
|
|
11
|
+
/** UNIX seconds of the last price update. */
|
|
12
|
+
lastUpdateTimestamp: number;
|
|
13
|
+
/** Contracts notified of every price change. */
|
|
14
|
+
syncers: string[];
|
|
15
|
+
/** `MAX_SYNCERS`. */
|
|
16
|
+
maxSyncers: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Reads who administers RAACHousePrices, who may set prices, and its syncers.
|
|
20
|
+
* @param chainId The chain id.
|
|
21
|
+
* @param provider The provider to read with.
|
|
22
|
+
*/
|
|
23
|
+
declare function getState(chainId: ChainId, provider: Provider): Promise<HousePricesState>;
|
|
24
|
+
export default getState;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
/** The governance-controlled settings of a PSM vault, as stored. */
|
|
4
|
+
export interface PsmVaultSettings {
|
|
5
|
+
paused: boolean;
|
|
6
|
+
/** Basis points (of 10_000). */
|
|
7
|
+
swapFee: bigint;
|
|
8
|
+
minWithdrawFee: bigint;
|
|
9
|
+
maxWithdrawFee: bigint;
|
|
10
|
+
/** Seconds a redeem request waits before it can be claimed. */
|
|
11
|
+
withdrawTime: bigint;
|
|
12
|
+
/** Seconds a ready request stays claimable. */
|
|
13
|
+
withdrawTimeLimit: bigint;
|
|
14
|
+
circuitBreakerEnabled: boolean;
|
|
15
|
+
/** 18-decimal NAV floor (1e18 = a NAV of 1.00). */
|
|
16
|
+
navFloor: bigint;
|
|
17
|
+
/** 18-decimal ratio (1e18 = 100%). */
|
|
18
|
+
reserveRatioFloor: bigint;
|
|
19
|
+
/** Base asset (pmUSD) base units. */
|
|
20
|
+
rebalanceThreshold: bigint;
|
|
21
|
+
/** Savings token base units; `MaxUint256` means no cap. */
|
|
22
|
+
depositCap: bigint;
|
|
23
|
+
savingsTokenDecimals: number;
|
|
24
|
+
baseAsset: string;
|
|
25
|
+
savingsToken: string;
|
|
26
|
+
rateProvider: string;
|
|
27
|
+
rebalancer: string;
|
|
28
|
+
baseAssetModule: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Reads a PSM vault's settings from its storage getters only. Unlike `getVaultInfo`, nothing here touches the rate
|
|
32
|
+
* provider, so it still answers when the savings token price is stale (`StalePrice`), which is when an operator
|
|
33
|
+
* needs to see and change these settings.
|
|
34
|
+
* @param chainId - The chain/network to use.
|
|
35
|
+
* @param vaultKeyOrAddress - The vault's config key (e.g. "rpsm-susds") or its deployed address.
|
|
36
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getVaultSettings(chainId: ChainId, vaultKeyOrAddress: string, provider?: Provider): Promise<PsmVaultSettings>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains/index";
|
|
3
|
+
import { TokenAmount } from "../../utils/amount";
|
|
4
|
+
/** One token the Treasury supports. */
|
|
5
|
+
export interface TreasuryToken {
|
|
6
|
+
address: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
/** Null when the token's decimals could not be read; amounts then cannot be entered safely. */
|
|
9
|
+
decimals: number | null;
|
|
10
|
+
/** What the Treasury's own accounting holds (`getBalance`); `withdraw` is limited to this. */
|
|
11
|
+
tracked: TokenAmount;
|
|
12
|
+
/** The token's actual `balanceOf(treasury)`; null when unreadable. Differs from `tracked` for tokens sent directly or rebasing. */
|
|
13
|
+
held: TokenAmount | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reads every token the Treasury supports, with its tracked and actual balances. Walks `supportedTokens(i)` until the
|
|
17
|
+
* index reverts; any other error is thrown so a flaky node never returns a shortened list.
|
|
18
|
+
* @param chainId The chain id.
|
|
19
|
+
* @param provider The provider to read with.
|
|
20
|
+
*/
|
|
21
|
+
declare function getState(chainId: ChainId, provider: Provider): Promise<{
|
|
22
|
+
tokens: TreasuryToken[];
|
|
23
|
+
}>;
|
|
24
|
+
export default getState;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript port of contracts/libraries/minters/EmissionSchedule.sol. The schedule is pure (no storage), so the
|
|
3
|
+
* whole curve can be drawn without one RPC call per week; the only on-chain input is the activation timestamp
|
|
4
|
+
* (`mintingStartAtTimestamp`). All amounts are RAAC base units (18 decimals).
|
|
5
|
+
*/
|
|
6
|
+
/** RAAC emitted in each of the first 104 weeks. Divisible by 604800, so the per-second rate is exact. */
|
|
7
|
+
export declare const BASE_WEEKLY_EMISSION: bigint;
|
|
8
|
+
export declare const BASE_PER_SECOND: bigint;
|
|
9
|
+
/** First week of the reduction phase. */
|
|
10
|
+
export declare const WEEK_REDUCTION_START = 105;
|
|
11
|
+
/** The rate drops by 5% every this many weeks. */
|
|
12
|
+
export declare const WEEKS_PER_PERIOD = 13;
|
|
13
|
+
/** Weeks 781 and later emit nothing. */
|
|
14
|
+
export declare const LAST_EMISSION_WEEK = 780;
|
|
15
|
+
/**
|
|
16
|
+
* RAAC emitted per second during a 1-based schedule week.
|
|
17
|
+
* @param week The schedule week; 0 and weeks after 780 emit nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getEmissionPerSecondForWeek(week: number): bigint;
|
|
20
|
+
/**
|
|
21
|
+
* The 1-based schedule week a timestamp falls in, 0 before activation.
|
|
22
|
+
* @param activationTimestamp `mintingStartAtTimestamp`, in UNIX seconds.
|
|
23
|
+
* @param timestamp The moment to place, in UNIX seconds.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getMintingWeekForTimestamp(activationTimestamp: number, timestamp: number): number;
|
|
26
|
+
/** One week of the schedule. */
|
|
27
|
+
export interface EmissionWeek {
|
|
28
|
+
week: number;
|
|
29
|
+
/** RAAC base units per second. */
|
|
30
|
+
perSecond: bigint;
|
|
31
|
+
/** RAAC base units emitted over the whole week. */
|
|
32
|
+
weekly: bigint;
|
|
33
|
+
/** RAAC base units emitted from week 1 through the end of this week. */
|
|
34
|
+
cumulative: bigint;
|
|
35
|
+
}
|
|
36
|
+
/** Every week of the schedule, 1 through 780, with running totals. The last `cumulative` is the lifetime emission. */
|
|
37
|
+
export declare function getEmissionSchedule(): EmissionWeek[];
|
|
38
|
+
/** Where a moment sits on the schedule. */
|
|
39
|
+
export interface SchedulePosition {
|
|
40
|
+
/** 0 before activation, above 780 once emissions have ended. */
|
|
41
|
+
week: number;
|
|
42
|
+
/** Seconds elapsed in the current week. */
|
|
43
|
+
secondsIntoWeek: number;
|
|
44
|
+
perSecond: bigint;
|
|
45
|
+
/** RAAC base units the schedule allows from activation to `timestamp`, before any MAX_SUPPLY cap. */
|
|
46
|
+
scheduledToDate: bigint;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Places a moment on the schedule, e.g. to compare what has been minted with what the schedule allowed.
|
|
50
|
+
* @param activationTimestamp `mintingStartAtTimestamp`, in UNIX seconds.
|
|
51
|
+
* @param timestamp The moment to place, in UNIX seconds.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getSchedulePosition(activationTimestamp: number, timestamp: number): SchedulePosition;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
/** The lending pool's pause state, linked contracts, collateral adapters and reserve tokens. */
|
|
4
|
+
export interface LendingPoolAdminState {
|
|
5
|
+
paused: boolean;
|
|
6
|
+
primeRateOracle: string;
|
|
7
|
+
stabilityPool: string;
|
|
8
|
+
liquidationProxy: string;
|
|
9
|
+
/** The yield vault; the zero address when none is set. */
|
|
10
|
+
vault: string;
|
|
11
|
+
feeCollector: string;
|
|
12
|
+
/** Collateral adapters registered on the pool (`getAdapters()`). */
|
|
13
|
+
adapters: string[];
|
|
14
|
+
/** The asset depositors supply. */
|
|
15
|
+
reserveAsset: string;
|
|
16
|
+
rToken: string;
|
|
17
|
+
debtToken: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads what an operator administers on the lending pool, next to `getParameters` (risk and fee values) and
|
|
21
|
+
* `getLendingPoolInfo` (liquidity and rates).
|
|
22
|
+
* @param chainId The chain id.
|
|
23
|
+
* @param provider The provider to read with.
|
|
24
|
+
*/
|
|
25
|
+
declare function getAdminState(chainId: ChainId, provider: Provider): Promise<LendingPoolAdminState>;
|
|
26
|
+
export default getAdminState;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../utils/amount";
|
|
4
|
+
/** One adapter registered on the RWA vault, as the vault itself reports it. */
|
|
5
|
+
export interface RegisteredVaultAdapter {
|
|
6
|
+
address: string;
|
|
7
|
+
/** `getAssetType()`: "ERC721" or "ERC20"; "unknown" when the adapter could not be read. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** The asset the adapter holds: the NFT collection or the ERC20 token. */
|
|
10
|
+
token: string;
|
|
11
|
+
tokenSymbol: string;
|
|
12
|
+
/** 0 for NFTs. */
|
|
13
|
+
tokenDecimals: number;
|
|
14
|
+
/** Listed in `depositableAdapters`. */
|
|
15
|
+
depositable: boolean;
|
|
16
|
+
/** Listed in `redeemableERC721Adapters`. */
|
|
17
|
+
redeemable: boolean;
|
|
18
|
+
/** Oracle value of everything held, in crvUSD with 18 decimals; null when the adapter could not price it. */
|
|
19
|
+
value: TokenAmount | null;
|
|
20
|
+
/** Token ids held, for ERC721 adapters. */
|
|
21
|
+
tokenIds: bigint[];
|
|
22
|
+
/** Set when the adapter itself could not be read; the other asset fields are then placeholders. */
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Every adapter registered on the RWA vault, read from the vault's own arrays rather than the chain config (which
|
|
27
|
+
* `getAdapters` returns), with deposit and redemption flags and what each adapter holds. One adapter failing to read
|
|
28
|
+
* gives a row with `error` instead of failing the whole list.
|
|
29
|
+
* @param chainId The chain id.
|
|
30
|
+
* @param provider The provider to read with.
|
|
31
|
+
*/
|
|
32
|
+
declare function getRegisteredAdapters(chainId: ChainId, provider: Provider): Promise<RegisteredVaultAdapter[]>;
|
|
33
|
+
export default getRegisteredAdapters;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
/** Where the RWA vault's randomness request stands. */
|
|
4
|
+
export interface SeedStatus {
|
|
5
|
+
/** The VRF consumer the vault uses; the zero address when none is set (requests then revert). */
|
|
6
|
+
consumer: string;
|
|
7
|
+
/** UNIX seconds of the last request, 0 if never. */
|
|
8
|
+
lastRequest: number;
|
|
9
|
+
/** UNIX seconds of the last fulfilment, 0 if never. */
|
|
10
|
+
lastFulfil: number;
|
|
11
|
+
/** A request exists and has not been fulfilled yet. */
|
|
12
|
+
pending: boolean;
|
|
13
|
+
/** Seconds after which a pending request may be replaced (`MAX_STALL`). */
|
|
14
|
+
maxStall: number;
|
|
15
|
+
/** Seconds required between the last fulfilment and a new public request (`vrfRequestDelay`). */
|
|
16
|
+
delay: number;
|
|
17
|
+
/** Whether anyone may call `requestRandomSeed` (`allowVRFRequest`). */
|
|
18
|
+
allowed: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads the RWA vault's VRF consumer: the last request and fulfilment and the stall window, plus the vault's own
|
|
22
|
+
* request rules. With no consumer set, the time fields are 0.
|
|
23
|
+
* @param chainId The chain id.
|
|
24
|
+
* @param provider The provider to read with.
|
|
25
|
+
*/
|
|
26
|
+
declare function getSeedStatus(chainId: ChainId, provider: Provider): Promise<SeedStatus>;
|
|
27
|
+
export default getSeedStatus;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains/index";
|
|
3
|
+
import type { LiquidationSplit } from "./liquidation";
|
|
4
|
+
export interface StabilityPoolState {
|
|
5
|
+
owner: string;
|
|
6
|
+
paused: boolean;
|
|
7
|
+
managers: string[];
|
|
8
|
+
rwaVault: string;
|
|
9
|
+
liquidationStrategyProxy: string;
|
|
10
|
+
liquidationSwap: string;
|
|
11
|
+
feeCollector: string;
|
|
12
|
+
split: LiquidationSplit;
|
|
13
|
+
/** Seconds a withdrawal request waits before it can be withdrawn. */
|
|
14
|
+
withdrawTimelockDuration: number;
|
|
15
|
+
/** Seconds a ready request stays valid. */
|
|
16
|
+
withdrawTimelockDelay: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Owner, pause state, managers, linked contracts, liquidation split and withdraw timelock.
|
|
20
|
+
* @param chainId The chain id.
|
|
21
|
+
* @param provider The provider to read with.
|
|
22
|
+
* @throws When the configured address has no contract, which the generic decode error would hide.
|
|
23
|
+
*/
|
|
24
|
+
declare function getAdminState(chainId: ChainId, provider: Provider): Promise<StabilityPoolState>;
|
|
25
|
+
export default getAdminState;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Liquidation simulation for StabilityPool.liquidateBorrower, mirroring LiquidationStrategyProxy:
|
|
3
|
+
* 1. the seized collateral is deposited into the RWAVault for vault-token shares, unless it already is the vault token;
|
|
4
|
+
* 2. the stability pool's whole vault-token balance (the proxy runs under delegatecall) is split by BPS into
|
|
5
|
+
* mint (treasury fee), burn, swap and liquidity (fee collector);
|
|
6
|
+
* 3. only the swap slice becomes crvUSD, through LiquidationSwap and its Curve pool;
|
|
7
|
+
* 3b. LiquidationSwap reverts when slippage protection is on and get_dy falls below pricePerShare / oracle price
|
|
8
|
+
* less its tolerance, which is the case when Curve trades below the vault's value;
|
|
9
|
+
* 4. the crvUSD must cover the position's debt; any shortfall is withdrawn from the LendingPool with the pool's
|
|
10
|
+
* rTokens, so stability pool depositors pay it, and the call reverts (InsufficientBalance) if they hold too few.
|
|
11
|
+
*/
|
|
12
|
+
import { type Provider } from "ethers";
|
|
13
|
+
import { ChainId } from "../../configs/chains/index";
|
|
14
|
+
/** The four shares of the vault-token balance, in basis points; they must add up to 10_000. */
|
|
15
|
+
export interface LiquidationSplit {
|
|
16
|
+
mintBps: bigint;
|
|
17
|
+
burnBps: bigint;
|
|
18
|
+
swapBps: bigint;
|
|
19
|
+
liquidityBps: bigint;
|
|
20
|
+
}
|
|
21
|
+
export declare const SPLIT_KEYS: readonly ["mintBps", "burnBps", "swapBps", "liquidityBps"];
|
|
22
|
+
export declare const splitTotal: (s: LiquidationSplit) => bigint;
|
|
23
|
+
export declare const sameSplit: (a: LiquidationSplit, b: LiquidationSplit) => boolean;
|
|
24
|
+
/** The stability pool's liquidation route, read once per review. */
|
|
25
|
+
export interface LiquidationContext {
|
|
26
|
+
stabilityPool: string;
|
|
27
|
+
liquidationSwap: string;
|
|
28
|
+
liquidityPool: string;
|
|
29
|
+
rwaVault: string;
|
|
30
|
+
vaultToken: string;
|
|
31
|
+
vaultSymbol: string;
|
|
32
|
+
iIn: bigint;
|
|
33
|
+
iOut: bigint;
|
|
34
|
+
split: LiquidationSplit;
|
|
35
|
+
/** Vault tokens already in the stability pool; the split divides these too. */
|
|
36
|
+
poolVaultTokens: bigint;
|
|
37
|
+
/** rTokens the stability pool holds, which is the most a swap shortfall can draw from the LendingPool. */
|
|
38
|
+
rTokens: bigint;
|
|
39
|
+
/** LendingPool grace period, in seconds, before an insured position can be finalized. */
|
|
40
|
+
gracePeriod: number;
|
|
41
|
+
/** LiquidationSwap's own floor: null when protection is off, else pricePerShare / oracle price less its tolerance. */
|
|
42
|
+
slippage: {
|
|
43
|
+
bps: bigint;
|
|
44
|
+
pricePerShare: bigint;
|
|
45
|
+
oraclePrice: bigint;
|
|
46
|
+
} | null;
|
|
47
|
+
}
|
|
48
|
+
/** Everything liquidateBorrower needs for one position, plus its state on chain. */
|
|
49
|
+
export interface LiquidationTarget {
|
|
50
|
+
poolAdapter: string;
|
|
51
|
+
vaultAdapter: string;
|
|
52
|
+
user: string;
|
|
53
|
+
/** abi.encode(uint256): the tokenId for ERC721 collateral, the full deposited amount for ERC20. */
|
|
54
|
+
data: string;
|
|
55
|
+
assetType: string;
|
|
56
|
+
assetToken: string;
|
|
57
|
+
/** The collateral already is the vault token, so no RWAVault deposit happens. */
|
|
58
|
+
isVaultToken: boolean;
|
|
59
|
+
collateralValue: bigint;
|
|
60
|
+
/** getPositionScaledDebt: the debt with accrued interest, which is what the liquidation repays. */
|
|
61
|
+
debt: bigint;
|
|
62
|
+
isUnderLiquidation: boolean;
|
|
63
|
+
isInsured: boolean;
|
|
64
|
+
liquidationStartTime: number;
|
|
65
|
+
}
|
|
66
|
+
export interface LiquidationQuote {
|
|
67
|
+
split: LiquidationSplit;
|
|
68
|
+
/** Vault tokens this liquidation adds: shares minted for the collateral, or the collateral itself. */
|
|
69
|
+
sharesFromCollateral: bigint;
|
|
70
|
+
/** sharesFromCollateral plus the pool's existing balance: what the split divides. */
|
|
71
|
+
totalVaultTokens: bigint;
|
|
72
|
+
swapAmount: bigint;
|
|
73
|
+
/** get_dy from the deployed Curve pool; null when the quote reverted. */
|
|
74
|
+
swapOut: bigint | null;
|
|
75
|
+
/** LiquidationSwap's minimum output for swapAmount; null when its slippage protection is off. */
|
|
76
|
+
minSwapOut: bigint | null;
|
|
77
|
+
/** Debt the swap does not cover, drawn from depositors' rTokens; the whole debt when the quote reverted. */
|
|
78
|
+
shortfall: bigint;
|
|
79
|
+
coversDebt: boolean;
|
|
80
|
+
/** The collateral is worth less than the debt, so depositors lose whatever the split. */
|
|
81
|
+
badDebt: bigint;
|
|
82
|
+
/** get_dy for the whole balance: the most any split can recover. */
|
|
83
|
+
maxSwapOut: bigint | null;
|
|
84
|
+
/** How far the realised swap rate falls below the spot rate, in basis points. */
|
|
85
|
+
priceImpactBps: bigint | null;
|
|
86
|
+
/** The crvUSD side of the Curve pool; the swap can never return more. */
|
|
87
|
+
poolReserveOut: bigint | null;
|
|
88
|
+
}
|
|
89
|
+
export interface SuggestedSplit extends LiquidationSplit {
|
|
90
|
+
projectedOut: bigint;
|
|
91
|
+
/** No split covers the debt; this is the best effort (100% swap). */
|
|
92
|
+
bestEffort: boolean;
|
|
93
|
+
}
|
|
94
|
+
/** Reads the stability pool's liquidation route, split, balances and the LendingPool grace period. */
|
|
95
|
+
export declare function readLiquidationContext(chainId: ChainId, provider: Provider): Promise<LiquidationContext>;
|
|
96
|
+
/** Assembles liquidateBorrower's arguments and the position's state for one position id ("user:adapter:key"). */
|
|
97
|
+
export declare function readLiquidationTarget(chainId: ChainId, provider: Provider, ctx: LiquidationContext, positionId: string): Promise<LiquidationTarget>;
|
|
98
|
+
/** Prices the liquidation with `split`, using the deployed Curve pool's get_dy rather than the vault's oracle price. */
|
|
99
|
+
export declare function quoteLiquidation(provider: Provider, ctx: LiquidationContext, target: LiquidationTarget, split: LiquidationSplit): Promise<LiquidationQuote>;
|
|
100
|
+
/**
|
|
101
|
+
* The smallest swap share whose get_dy still covers the debt plus `bufferBps`, with the rest given back to mint,
|
|
102
|
+
* burn and liquidity in their current proportion. get_dy grows with dx, so a binary search over BPS is sound.
|
|
103
|
+
*/
|
|
104
|
+
export declare function suggestSplit(provider: Provider, ctx: LiquidationContext, target: LiquidationTarget, quote: LiquidationQuote, bufferBps?: bigint): Promise<SuggestedSplit | null>;
|
|
105
|
+
/** minSharesOut for the RWAVault deposit: previewDeposit less `slippageBps`. Zero when nothing is deposited. */
|
|
106
|
+
export declare const minSharesOut: (target: LiquidationTarget, quote: LiquidationQuote, slippageBps: bigint) => bigint;
|
|
107
|
+
/**
|
|
108
|
+
* Simulates liquidateBorrower from `sender` with the split overridden in storage (an eth_call state override), so a
|
|
109
|
+
* split change in the same batch is simulated rather than only checked. Returns null when the RPC or the storage
|
|
110
|
+
* layout cannot be used; otherwise the revert reason, or "" when it succeeds.
|
|
111
|
+
*/
|
|
112
|
+
export declare function simulateWithSplit(provider: Provider, ctx: LiquidationContext, sender: string, data: string, split: LiquidationSplit): Promise<string | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raac/rpc",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.14",
|
|
4
4
|
"description": "RPC Library for RAAC",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -11,7 +11,13 @@
|
|
|
11
11
|
"dev": "ts-node-dev --transpile-only --env-file=.env scripts/index.ts",
|
|
12
12
|
"build": "tsc && cp -r typechain-types dist/types && cp -r generated dist/generated",
|
|
13
13
|
"build:watch": "tsc --watch",
|
|
14
|
-
"test": "
|
|
14
|
+
"test": "npm run test:unit && npm run test:integration && npm run test:e2e",
|
|
15
|
+
"test:full": "npm run test:unit && npm run test:integration && npm run test:e2e && npm run test:browser",
|
|
16
|
+
"test:unit": "node -r ts-node/register -r tsconfig-paths/register --test tests/loader.unit.test.ts",
|
|
17
|
+
"test:integration": "node -r ts-node/register -r tsconfig-paths/register --test tests/loader.integration.test.ts",
|
|
18
|
+
"test:e2e": "npm run build && node -r ts-node/register -r tsconfig-paths/register --test tests/loader.e2e.test.ts",
|
|
19
|
+
"test:browser": "node tests/browser/server.js --local",
|
|
20
|
+
"test:browser:published": "open tests/browser/index.html",
|
|
15
21
|
"sync": "bash setup.sh",
|
|
16
22
|
"clean": "rm -rf dist",
|
|
17
23
|
"prebuild": "npm run clean",
|
|
@@ -28,14 +34,18 @@
|
|
|
28
34
|
"dependencies": {
|
|
29
35
|
"@raac/chainlinkjs": "1.0.1",
|
|
30
36
|
"csv-parser": "3.2.0",
|
|
31
|
-
"ethers": "6.
|
|
37
|
+
"ethers": "6.17.0",
|
|
32
38
|
"ethers5": "npm:ethers@5.8.0"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
35
41
|
"@anthropic-ai/sdk": "^0.127.0",
|
|
42
|
+
"esbuild": "0.24.2",
|
|
36
43
|
"eslint": "9.39.1",
|
|
37
44
|
"ts-node": "10.9.2",
|
|
38
45
|
"ts-node-dev": "2.0.0",
|
|
46
|
+
"tsconfig-paths": "4.2.0",
|
|
39
47
|
"typescript": "5.9.3"
|
|
40
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"browser": "dist/browser.js",
|
|
50
|
+
"module": "dist/browser.js"
|
|
41
51
|
}
|