@raac/rpc 2.0.0-beta.14 → 2.0.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.
package/dist/RPCLibrary.js
CHANGED
|
@@ -158,6 +158,7 @@ const getRawUserDepositsInStabilityPool_1 = __importDefault(require("./pools/sta
|
|
|
158
158
|
const getEligibleUserDeposits_1 = __importDefault(require("./pools/lendingPool/getEligibleUserDeposits"));
|
|
159
159
|
const getMintPrice_1 = __importDefault(require("./nfts/getMintPrice"));
|
|
160
160
|
const getMintFeePercentage_1 = __importDefault(require("./nfts/getMintFeePercentage"));
|
|
161
|
+
const getPriceStaleness_1 = __importStar(require("./nfts/getPriceStaleness"));
|
|
161
162
|
const getAllTokens_1 = __importDefault(require("./nfts/getAllTokens"));
|
|
162
163
|
const totalNFTSupply_1 = __importDefault(require("./nfts/totalNFTSupply"));
|
|
163
164
|
const getTokenURI_1 = __importDefault(require("./nfts/getTokenURI"));
|
|
@@ -497,6 +498,8 @@ class RPCLibrary {
|
|
|
497
498
|
totalSupply: totalNFTSupply_1.default,
|
|
498
499
|
getMintPrice: getMintPrice_1.default,
|
|
499
500
|
getMintFeePercentage: getMintFeePercentage_1.default,
|
|
501
|
+
getPriceStalenessThreshold: getPriceStaleness_1.default,
|
|
502
|
+
isHousePriceStale: getPriceStaleness_1.isHousePriceStale,
|
|
500
503
|
getAllTokens: getAllTokens_1.default,
|
|
501
504
|
getTokenURI: getTokenURI_1.default,
|
|
502
505
|
getTotalPropertiesCount: getTotalPropertiesCount_1.default,
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"complianceregistry": {
|
|
78
78
|
"id": "complianceregistry",
|
|
79
79
|
"name": "Compliance Registry",
|
|
80
|
-
"contract": "
|
|
80
|
+
"contract": "0x6e35c61A73ec5d1779038DF78CbB8183f76fCD4b"
|
|
81
81
|
},
|
|
82
82
|
"rwaindextokencollector": {
|
|
83
83
|
"id": "rwaindextokencollector",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHousePriceStale = isHousePriceStale;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const contracts_1 = require("../utils/contracts");
|
|
6
|
+
const artifacts_1 = require("../utils/artifacts");
|
|
7
|
+
const rpcError_1 = require("../utils/rpcError");
|
|
8
|
+
// RAACNFT storage: token at slot 13, TRADE_FEE_PERCENTAGE at 17, PRICE_STALENESS_THRESHOLD at 18, feeCollector at 19.
|
|
9
|
+
const TOKEN_SLOT = 13;
|
|
10
|
+
const TRADE_FEE_SLOT = 17;
|
|
11
|
+
const THRESHOLD_SLOT = 18;
|
|
12
|
+
const FEE_COLLECTOR_SLOT = 19;
|
|
13
|
+
/**
|
|
14
|
+
* Reads RAACNFT's `PRICE_STALENESS_THRESHOLD`, the maximum age of a house price that `mint` accepts. The variable has
|
|
15
|
+
* no getter, so it is read from storage slot 18, trusted only when the neighbouring slots match `token()`,
|
|
16
|
+
* `TRADE_FEE_PERCENTAGE()` and `feeCollector()` (the layout is as expected).
|
|
17
|
+
* @param chainId The chain id.
|
|
18
|
+
* @param provider The provider to read with.
|
|
19
|
+
* @returns The threshold in seconds (0 turns the check off), or null when the storage layout could not be confirmed.
|
|
20
|
+
*/
|
|
21
|
+
async function getPriceStalenessThreshold(chainId, provider) {
|
|
22
|
+
const at = (0, contracts_1.getContractAddress)(chainId, "raacnft");
|
|
23
|
+
try {
|
|
24
|
+
const nft = new ethers_1.ethers.Contract(at, (0, artifacts_1.getABI)("raacnft"), provider);
|
|
25
|
+
const [token, tradeFee, feeCollector, ...slots] = await Promise.all([
|
|
26
|
+
nft.token(),
|
|
27
|
+
nft.TRADE_FEE_PERCENTAGE(),
|
|
28
|
+
nft.feeCollector(),
|
|
29
|
+
...[TOKEN_SLOT, TRADE_FEE_SLOT, FEE_COLLECTOR_SLOT, THRESHOLD_SLOT].map((slot) => provider.getStorage(at, slot)),
|
|
30
|
+
]);
|
|
31
|
+
const [tokenSlot, tradeFeeSlot, feeCollectorSlot, threshold] = slots.map((v) => BigInt(v));
|
|
32
|
+
const layoutOk = tokenSlot === BigInt(token) && tradeFeeSlot === tradeFee && feeCollectorSlot === BigInt(feeCollector);
|
|
33
|
+
return layoutOk ? Number(threshold) : null;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
throw (0, rpcError_1.toRpcError)("nfts.getPriceStalenessThreshold", error, { chainId, address: at });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether RAACNFT's `mint` would reject a house price as stale (`StalePriceData`), as `_validatePriceFreshness` decides:
|
|
41
|
+
* a price never set, or older than the threshold when the threshold is not 0. Only minting checks this; the lending
|
|
42
|
+
* pool's NFT adapter values collateral at the price whatever its age.
|
|
43
|
+
* @param priceTimestamp Unix seconds of the house price update; 0 when never priced.
|
|
44
|
+
* @param threshold `getPriceStalenessThreshold` in seconds.
|
|
45
|
+
* @param now Unix seconds to judge at, normally the latest block's timestamp.
|
|
46
|
+
* @returns True when a mint of this token would revert with `StalePriceData`.
|
|
47
|
+
*/
|
|
48
|
+
function isHousePriceStale(priceTimestamp, threshold, now) {
|
|
49
|
+
return priceTimestamp === 0 || (threshold > 0 && now > priceTimestamp + threshold);
|
|
50
|
+
}
|
|
51
|
+
exports.default = getPriceStalenessThreshold;
|
|
@@ -100,6 +100,7 @@ import getRawUserDepositInStabilityPool from "./pools/stabilityPool/getRawUserDe
|
|
|
100
100
|
import getEligibleUserDeposits from "./pools/lendingPool/getEligibleUserDeposits";
|
|
101
101
|
import getMintPrice from "./nfts/getMintPrice";
|
|
102
102
|
import getMintFeePercentage from "./nfts/getMintFeePercentage";
|
|
103
|
+
import getPriceStalenessThreshold, { isHousePriceStale } from "./nfts/getPriceStaleness";
|
|
103
104
|
import getAllTokens from "./nfts/getAllTokens";
|
|
104
105
|
import totalNFTSupply from "./nfts/totalNFTSupply";
|
|
105
106
|
import getTokenURI from "./nfts/getTokenURI";
|
|
@@ -379,6 +380,8 @@ declare class RPCLibrary {
|
|
|
379
380
|
totalSupply: typeof totalNFTSupply;
|
|
380
381
|
getMintPrice: typeof getMintPrice;
|
|
381
382
|
getMintFeePercentage: typeof getMintFeePercentage;
|
|
383
|
+
getPriceStalenessThreshold: typeof getPriceStalenessThreshold;
|
|
384
|
+
isHousePriceStale: typeof isHousePriceStale;
|
|
382
385
|
getAllTokens: typeof getAllTokens;
|
|
383
386
|
getTokenURI: typeof getTokenURI;
|
|
384
387
|
getTotalPropertiesCount: typeof getTotalPropertiesCount;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../configs/chains/index";
|
|
3
|
+
/**
|
|
4
|
+
* Reads RAACNFT's `PRICE_STALENESS_THRESHOLD`, the maximum age of a house price that `mint` accepts. The variable has
|
|
5
|
+
* no getter, so it is read from storage slot 18, trusted only when the neighbouring slots match `token()`,
|
|
6
|
+
* `TRADE_FEE_PERCENTAGE()` and `feeCollector()` (the layout is as expected).
|
|
7
|
+
* @param chainId The chain id.
|
|
8
|
+
* @param provider The provider to read with.
|
|
9
|
+
* @returns The threshold in seconds (0 turns the check off), or null when the storage layout could not be confirmed.
|
|
10
|
+
*/
|
|
11
|
+
declare function getPriceStalenessThreshold(chainId: ChainId, provider: Provider): Promise<number | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Whether RAACNFT's `mint` would reject a house price as stale (`StalePriceData`), as `_validatePriceFreshness` decides:
|
|
14
|
+
* a price never set, or older than the threshold when the threshold is not 0. Only minting checks this; the lending
|
|
15
|
+
* pool's NFT adapter values collateral at the price whatever its age.
|
|
16
|
+
* @param priceTimestamp Unix seconds of the house price update; 0 when never priced.
|
|
17
|
+
* @param threshold `getPriceStalenessThreshold` in seconds.
|
|
18
|
+
* @param now Unix seconds to judge at, normally the latest block's timestamp.
|
|
19
|
+
* @returns True when a mint of this token would revert with `StalePriceData`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isHousePriceStale(priceTimestamp: number, threshold: number, now: number): boolean;
|
|
22
|
+
export default getPriceStalenessThreshold;
|