@raac/rpc 2.0.0-beta.6 → 2.0.0-beta.8
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 +27 -2
- package/dist/artifacts/core/collectors/fee-streamer/RentStreamer.sol/RentStreamer.json +838 -0
- package/dist/artifacts/mocks/core/tokens/USDCTokenLimited.sol/USDCTokenLimited.json +558 -0
- package/dist/configs/chains/11155111.json +58 -3
- package/dist/contracts/curve/common/_helpers.js +39 -0
- package/dist/contracts/curve/common/getPools.js +36 -0
- package/dist/contracts/curve/common/getVirtualPrice.js +26 -0
- package/dist/contracts/curve/common/index.js +18 -0
- package/dist/contracts/findContract.js +3 -3
- package/dist/contracts/getContractAddress.js +1 -0
- package/dist/contracts/governance/gaugeSystems/_helpers.js +2 -2
- package/dist/contracts/rentStreamer/_helpers.js +19 -0
- package/dist/contracts/rentStreamer/getScheduled.js +19 -0
- package/dist/contracts/rentStreamer/getState.js +40 -0
- package/dist/contracts/rentStreamer/previewRelease.js +23 -0
- package/dist/contracts/rentStreamer/release.js +22 -0
- package/dist/contracts/rentStreamer/sync.js +21 -0
- package/dist/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.js +4 -4
- package/dist/types/RPCLibrary.d.ts +20 -1
- package/dist/types/contracts/curve/common/_helpers.d.ts +16 -0
- package/dist/types/contracts/curve/common/getPools.d.ts +30 -0
- package/dist/types/contracts/curve/common/getVirtualPrice.d.ts +13 -0
- package/dist/types/contracts/curve/common/index.d.ts +2 -0
- package/dist/types/contracts/rentStreamer/_helpers.d.ts +4 -0
- package/dist/types/contracts/rentStreamer/getScheduled.d.ts +12 -0
- package/dist/types/contracts/rentStreamer/getState.d.ts +33 -0
- package/dist/types/contracts/rentStreamer/previewRelease.d.ts +20 -0
- package/dist/types/contracts/rentStreamer/release.d.ts +12 -0
- package/dist/types/contracts/rentStreamer/sync.d.ts +11 -0
- package/dist/types/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.d.ts +3 -3
- package/dist/types/typechain-types/contracts/core/collectors/fee-streamer/RentStreamer.d.ts +422 -0
- package/dist/types/typechain-types/contracts/core/collectors/fee-streamer/index.d.ts +1 -0
- package/dist/types/typechain-types/contracts/core/collectors/index.d.ts +2 -0
- package/dist/types/typechain-types/contracts/mocks/core/tokens/USDCTokenLimited.d.ts +238 -0
- package/dist/types/typechain-types/contracts/mocks/core/tokens/index.d.ts +1 -0
- package/dist/types/typechain-types/factories/contracts/core/collectors/fee-streamer/RentStreamer__factory.d.ts +665 -0
- package/dist/types/typechain-types/factories/contracts/core/collectors/fee-streamer/index.d.ts +1 -0
- package/dist/types/typechain-types/factories/contracts/core/collectors/index.d.ts +1 -0
- package/dist/types/typechain-types/factories/contracts/mocks/core/tokens/USDCTokenLimited__factory.d.ts +439 -0
- package/dist/types/typechain-types/factories/contracts/mocks/core/tokens/index.d.ts +1 -0
- package/dist/types/typechain-types/index.d.ts +4 -0
- package/dist/types/user/_helpers.d.ts +23 -0
- package/dist/types/user/computeEffectiveReturn.d.ts +67 -0
- package/dist/types/user/getUserClaimables.d.ts +55 -0
- package/dist/types/user/getUserCollateral.d.ts +12 -0
- package/dist/types/user/getUserDebt.d.ts +18 -0
- package/dist/types/user/getUserFarming.d.ts +64 -0
- package/dist/types/user/getUserGovernance.d.ts +20 -0
- package/dist/types/user/getUserPortfolio.d.ts +61 -0
- package/dist/types/user/getUserWalletBalances.d.ts +20 -0
- package/dist/types/user/index.d.ts +9 -0
- package/dist/types/utils/amount.d.ts +7 -0
- package/dist/types/utils/artifacts.d.ts +198 -0
- package/dist/types/utils/contracts.d.ts +2 -0
- package/dist/user/_helpers.js +22 -0
- package/dist/user/computeEffectiveReturn.js +33 -0
- package/dist/user/getUserClaimables.js +97 -0
- package/dist/user/getUserCollateral.js +29 -0
- package/dist/user/getUserDebt.js +32 -0
- package/dist/user/getUserFarming.js +100 -0
- package/dist/user/getUserGovernance.js +35 -0
- package/dist/user/getUserPortfolio.js +109 -0
- package/dist/user/getUserWalletBalances.js +30 -0
- package/dist/user/index.js +24 -0
- package/dist/utils/amount.js +10 -0
- package/dist/utils/artifacts.js +4 -0
- package/dist/utils/contracts.js +5 -2
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
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.getCurvePools = exports.CURVE_POOL_READ_ABI = void 0;
|
|
7
|
+
exports.resolveCurvePool = resolveCurvePool;
|
|
8
|
+
exports.getCurvePoolContract = getCurvePoolContract;
|
|
9
|
+
const ethers_1 = require("ethers");
|
|
10
|
+
const chains_1 = __importDefault(require("../../../configs/chains"));
|
|
11
|
+
/**
|
|
12
|
+
* Reads every Curve pool flavour shares. Coin indexes differ (uint256 vs int128) only in swap and liquidity
|
|
13
|
+
* methods, which are not here.
|
|
14
|
+
*/
|
|
15
|
+
exports.CURVE_POOL_READ_ABI = [
|
|
16
|
+
"function coins(uint256) view returns (address)",
|
|
17
|
+
"function balances(uint256) view returns (uint256)",
|
|
18
|
+
"function totalSupply() view returns (uint256)",
|
|
19
|
+
"function balanceOf(address) view returns (uint256)",
|
|
20
|
+
"function get_virtual_price() view returns (uint256)",
|
|
21
|
+
];
|
|
22
|
+
const getCurvePools = (chainId) => chains_1.default[chainId]?.curve ?? {};
|
|
23
|
+
exports.getCurvePools = getCurvePools;
|
|
24
|
+
/** Resolves a Curve pool by its config key (any casing) or its address. */
|
|
25
|
+
function resolveCurvePool(chainId, poolAddressOrId) {
|
|
26
|
+
const pools = (0, exports.getCurvePools)(chainId);
|
|
27
|
+
const needle = poolAddressOrId.toLowerCase();
|
|
28
|
+
const entry = pools[needle] ?? Object.values(pools).find((pool) => pool.contract.toLowerCase() === needle);
|
|
29
|
+
if (!entry)
|
|
30
|
+
throw new Error(`Curve pool "${poolAddressOrId}" not configured for chain ${chainId}`);
|
|
31
|
+
return entry;
|
|
32
|
+
}
|
|
33
|
+
function getCurvePoolContract(chainId, poolAddressOrId, provider) {
|
|
34
|
+
if (!provider) {
|
|
35
|
+
provider = new ethers_1.ethers.JsonRpcProvider(chains_1.default[chainId].rpcs[0]);
|
|
36
|
+
}
|
|
37
|
+
const entry = resolveCurvePool(chainId, poolAddressOrId);
|
|
38
|
+
return { entry, contract: new ethers_1.ethers.Contract(entry.contract, exports.CURVE_POOL_READ_ABI, provider), provider };
|
|
39
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPool = exports.getPools = void 0;
|
|
4
|
+
const amount_1 = require("../../../utils/amount");
|
|
5
|
+
const contracts_1 = require("../../../utils/contracts");
|
|
6
|
+
const _helpers_1 = require("./_helpers");
|
|
7
|
+
const toPool = (chainId, entry) => ({
|
|
8
|
+
...entry,
|
|
9
|
+
coins: entry.coins.map((asset) => {
|
|
10
|
+
const info = (0, amount_1.getTokenInfo)(chainId, asset);
|
|
11
|
+
return {
|
|
12
|
+
asset,
|
|
13
|
+
address: (0, contracts_1.getContractAddress)(chainId, asset),
|
|
14
|
+
symbol: info?.symbol ?? asset,
|
|
15
|
+
decimals: info?.decimals ?? 18,
|
|
16
|
+
};
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Lists the Curve pools in the chain config.
|
|
21
|
+
*
|
|
22
|
+
* @param chainId - The chain/network to use.
|
|
23
|
+
* @returns Every configured pool with its flavour and coins in pool index order; empty when the chain has none.
|
|
24
|
+
*/
|
|
25
|
+
const getPools = (chainId) => Object.values((0, _helpers_1.getCurvePools)(chainId)).map((entry) => toPool(chainId, entry));
|
|
26
|
+
exports.getPools = getPools;
|
|
27
|
+
/**
|
|
28
|
+
* Looks up one Curve pool in the chain config. Reads the config only; no RPC call is made.
|
|
29
|
+
*
|
|
30
|
+
* @param chainId - The chain/network to use.
|
|
31
|
+
* @param poolAddressOrId - The pool's config key or its address.
|
|
32
|
+
* @returns The pool with its flavour and coins in pool index order.
|
|
33
|
+
* @throws If the pool is not configured on the chain.
|
|
34
|
+
*/
|
|
35
|
+
const getPool = (chainId, poolAddressOrId) => toPool(chainId, (0, _helpers_1.resolveCurvePool)(chainId, poolAddressOrId));
|
|
36
|
+
exports.getPool = getPool;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVirtualPrice = void 0;
|
|
4
|
+
const amount_1 = require("../../../utils/amount");
|
|
5
|
+
const rpcError_1 = require("../../../utils/rpcError");
|
|
6
|
+
const _helpers_1 = require("./_helpers");
|
|
7
|
+
/**
|
|
8
|
+
* Reads a Curve pool's virtual price: the value of one whole LP token in units of the pool's underlying coins,
|
|
9
|
+
* which only grows with fees. For a stableswap pool of $1 coins it is the LP token's USD price.
|
|
10
|
+
*
|
|
11
|
+
* @param chainId - The chain/network to use.
|
|
12
|
+
* @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
|
|
13
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
14
|
+
* @returns `get_virtual_price()` as an 18-decimal amount, e.g. 1.0021 underlying per LP token.
|
|
15
|
+
*/
|
|
16
|
+
const getVirtualPrice = async (chainId, poolAddressOrId, provider) => {
|
|
17
|
+
const { entry, contract } = (0, _helpers_1.getCurvePoolContract)(chainId, poolAddressOrId, provider);
|
|
18
|
+
try {
|
|
19
|
+
const price = await contract.get_virtual_price();
|
|
20
|
+
return (0, amount_1.toAmount)(price, amount_1.WAD_DECIMALS);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw (0, rpcError_1.toRpcError)("curve.common.getVirtualPrice", error, { chainId, address: entry.contract });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.getVirtualPrice = getVirtualPrice;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getPools"), exports);
|
|
18
|
+
__exportStar(require("./getVirtualPrice"), exports);
|
|
@@ -7,10 +7,10 @@ exports.findContract = void 0;
|
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const chains_1 = __importDefault(require("../configs/chains"));
|
|
9
9
|
const artifacts_1 = require("../utils/artifacts");
|
|
10
|
+
const contracts_1 = require("../utils/contracts");
|
|
10
11
|
/** Sections scanned in order; the first match wins. */
|
|
11
|
-
const FLAT_SECTIONS = ["contracts", "governance", "pools", "lockers", "zap", "psm", "nfts", "assets"];
|
|
12
|
+
const FLAT_SECTIONS = ["contracts", "governance", "pools", "lockers", "zap", "psm", "nfts", "assets", "curve"];
|
|
12
13
|
const abiKey = (key) => (key in artifacts_1.ABIS ? key : null);
|
|
13
|
-
const isDeployed = (address) => !!address && ethers_1.ethers.isAddress(address) && address !== ethers_1.ethers.ZeroAddress;
|
|
14
14
|
/** Builds every configured contract on the chain with its name and ABI key. */
|
|
15
15
|
function listContracts(chainId) {
|
|
16
16
|
const config = chains_1.default[chainId];
|
|
@@ -19,7 +19,7 @@ function listContracts(chainId) {
|
|
|
19
19
|
}
|
|
20
20
|
const found = [];
|
|
21
21
|
const push = (entry) => {
|
|
22
|
-
if (isDeployed(entry.address))
|
|
22
|
+
if ((0, contracts_1.isDeployed)(entry.address))
|
|
23
23
|
found.push({ ...entry, address: ethers_1.ethers.getAddress(entry.address) });
|
|
24
24
|
};
|
|
25
25
|
// gauges: { <system>: { label, gaugeType, controller, distributor, gauges: [{ id, name, contract }] } }
|
|
@@ -7,8 +7,8 @@ exports.resolveGauge = exports.lookupGauge = exports.listGauges = exports.resolv
|
|
|
7
7
|
const ethers_1 = require("ethers");
|
|
8
8
|
const chains_1 = __importDefault(require("../../../configs/chains"));
|
|
9
9
|
const _helpers_1 = require("../_helpers");
|
|
10
|
+
const contracts_1 = require("../../../utils/contracts");
|
|
10
11
|
exports.GAUGE_SYSTEM_IDS = ["raacgauges", "rwagauges"];
|
|
11
|
-
const isDeployed = (address) => !!address && ethers_1.ethers.isAddress(address) && address !== ethers_1.ethers.ZeroAddress;
|
|
12
12
|
/**
|
|
13
13
|
* Reads the `gauges` section of a chain config.
|
|
14
14
|
*
|
|
@@ -51,7 +51,7 @@ const resolveSystemContract = (chainId, ref, field, name) => {
|
|
|
51
51
|
return (0, _helpers_1.requireAddress)(ref, name);
|
|
52
52
|
}
|
|
53
53
|
const system = (0, exports.requireGaugeSystem)(chainId, ref);
|
|
54
|
-
if (!isDeployed(system[field])) {
|
|
54
|
+
if (!(0, contracts_1.isDeployed)(system[field])) {
|
|
55
55
|
throw new Error(`Gauge system "${system.id}" has no ${name} deployed on chainId: ${chainId}`);
|
|
56
56
|
}
|
|
57
57
|
return ethers_1.ethers.getAddress(system[field]);
|
|
@@ -0,0 +1,19 @@
|
|
|
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.getRentStreamerContract = getRentStreamerContract;
|
|
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
|
+
async function getRentStreamerContract(chainId, runner) {
|
|
12
|
+
if (!runner) {
|
|
13
|
+
const rpc = chains_1.default[chainId].rpcs[0];
|
|
14
|
+
runner = new ethers_1.ethers.JsonRpcProvider(rpc);
|
|
15
|
+
}
|
|
16
|
+
const address = (0, getContractAddress_1.getContractAddress)(chainId, "rentstreamer");
|
|
17
|
+
const abi = (0, artifacts_1.getABI)("rentstreamer");
|
|
18
|
+
return new ethers_1.ethers.Contract(address, abi, runner);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScheduled = void 0;
|
|
4
|
+
const amount_1 = require("../../utils/amount");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the amount bucketed for one epoch. Released epochs read zero.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain/network to use.
|
|
10
|
+
* @param epoch - Epoch start timestamp, a multiple of one week.
|
|
11
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
12
|
+
* @returns The scheduled amount in the streamed token's base units.
|
|
13
|
+
*/
|
|
14
|
+
const getScheduled = async (chainId, epoch, provider) => {
|
|
15
|
+
const contract = await (0, _helpers_1.getRentStreamerContract)(chainId, provider);
|
|
16
|
+
const [token, amount] = await Promise.all([contract.TOKEN(), contract.scheduled(epoch)]);
|
|
17
|
+
return (0, amount_1.toTokenAmount)(chainId, token, amount);
|
|
18
|
+
};
|
|
19
|
+
exports.getScheduled = getScheduled;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getState = void 0;
|
|
4
|
+
const amount_1 = require("../../utils/amount");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the RentStreamer's configuration and running totals.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain/network to use.
|
|
10
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
11
|
+
* @returns The streamer state; see `RentStreamerState` for the unit of each field.
|
|
12
|
+
*/
|
|
13
|
+
const getState = async (chainId, provider) => {
|
|
14
|
+
const contract = await (0, _helpers_1.getRentStreamerContract)(chainId, provider);
|
|
15
|
+
const [token, distributor, numEpochs, minBountyFee, maxBountyFee, bountyDuration, killed, processed, released, lastEpochProcessed] = await Promise.all([
|
|
16
|
+
contract.TOKEN(),
|
|
17
|
+
contract.GAUGE_REWARD_DISTRIBUTOR(),
|
|
18
|
+
contract.numEpochs(),
|
|
19
|
+
contract.minBountyFee(),
|
|
20
|
+
contract.maxBountyFee(),
|
|
21
|
+
contract.bountyDuration(),
|
|
22
|
+
contract.killed(),
|
|
23
|
+
contract.processed(),
|
|
24
|
+
contract.released(),
|
|
25
|
+
contract.lastEpochProcessed(),
|
|
26
|
+
]);
|
|
27
|
+
return {
|
|
28
|
+
token,
|
|
29
|
+
distributor,
|
|
30
|
+
numEpochs: Number(numEpochs),
|
|
31
|
+
minBountyFee: (0, amount_1.toScaled)(minBountyFee, amount_1.WAD_DECIMALS),
|
|
32
|
+
maxBountyFee: (0, amount_1.toScaled)(maxBountyFee, amount_1.WAD_DECIMALS),
|
|
33
|
+
bountyDuration: Number(bountyDuration),
|
|
34
|
+
killed,
|
|
35
|
+
processed: (0, amount_1.toTokenAmount)(chainId, token, processed),
|
|
36
|
+
released: (0, amount_1.toTokenAmount)(chainId, token, released),
|
|
37
|
+
lastEpochProcessed: Number(lastEpochProcessed),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
exports.getState = getState;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.previewRelease = void 0;
|
|
4
|
+
const amount_1 = require("../../utils/amount");
|
|
5
|
+
const _helpers_1 = require("./_helpers");
|
|
6
|
+
/**
|
|
7
|
+
* Previews what a `release` would move right now. All zero when the current epoch was already released or the
|
|
8
|
+
* streamer is killed. The bounty grows with time since the epoch start, so the real release can differ.
|
|
9
|
+
*
|
|
10
|
+
* @param chainId - The chain/network to use.
|
|
11
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
12
|
+
* @returns The release preview, in the streamed token's base units.
|
|
13
|
+
*/
|
|
14
|
+
const previewRelease = async (chainId, provider) => {
|
|
15
|
+
const contract = await (0, _helpers_1.getRentStreamerContract)(chainId, provider);
|
|
16
|
+
const [token, [amountToRelease, amountToDistribute, bountyFee]] = await Promise.all([contract.TOKEN(), contract.previewRelease()]);
|
|
17
|
+
return {
|
|
18
|
+
amountToRelease: (0, amount_1.toTokenAmount)(chainId, token, amountToRelease),
|
|
19
|
+
amountToDistribute: (0, amount_1.toTokenAmount)(chainId, token, amountToDistribute),
|
|
20
|
+
bountyFee: (0, amount_1.toTokenAmount)(chainId, token, bountyFee),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.previewRelease = previewRelease;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.release = void 0;
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Releases the current epoch's buckets: pays the keeper bounty and deposits the rest into the RWA
|
|
7
|
+
* GaugeRewardsDistributor. Permissionless, once per epoch; reverts while the RWA gauge system has no active gauge.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain/network to use.
|
|
10
|
+
* @param receiver - Address paid the bounty; the signer when omitted.
|
|
11
|
+
* @param signer - An ethers.js Signer instance (required).
|
|
12
|
+
* @returns The transaction.
|
|
13
|
+
*/
|
|
14
|
+
const release = async (chainId, receiver, signer) => {
|
|
15
|
+
if (!signer)
|
|
16
|
+
throw new Error("Signer is required");
|
|
17
|
+
const contract = await (0, _helpers_1.getRentStreamerContract)(chainId, signer);
|
|
18
|
+
const tx = receiver ? await contract["release(address)"](receiver) : await contract["release()"]();
|
|
19
|
+
await tx.wait();
|
|
20
|
+
return tx;
|
|
21
|
+
};
|
|
22
|
+
exports.release = release;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sync = void 0;
|
|
4
|
+
const _helpers_1 = require("./_helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Splits token sent to the streamer since the last sync over the next `numEpochs` weekly buckets. Permissionless;
|
|
7
|
+
* `release` also syncs first.
|
|
8
|
+
*
|
|
9
|
+
* @param chainId - The chain/network to use.
|
|
10
|
+
* @param signer - An ethers.js Signer instance (required).
|
|
11
|
+
* @returns The transaction.
|
|
12
|
+
*/
|
|
13
|
+
const sync = async (chainId, signer) => {
|
|
14
|
+
if (!signer)
|
|
15
|
+
throw new Error("Signer is required");
|
|
16
|
+
const contract = await (0, _helpers_1.getRentStreamerContract)(chainId, signer);
|
|
17
|
+
const tx = await contract.sync();
|
|
18
|
+
await tx.wait();
|
|
19
|
+
return tx;
|
|
20
|
+
};
|
|
21
|
+
exports.sync = sync;
|
|
@@ -9,16 +9,16 @@ const rpcError_1 = require("../../../../utils/rpcError");
|
|
|
9
9
|
* @param chainId The chain id, used to look up the adapter token's decimals in the token registry.
|
|
10
10
|
* @param adapterAddress The ERC20 asset adapter address.
|
|
11
11
|
* @param userAddress The user.
|
|
12
|
-
* @param
|
|
12
|
+
* @param runner The signer or provider to read with. A read-only provider is enough.
|
|
13
13
|
* @returns The deposited balance in base units of the adapter's token, with its registry decimals and symbol (18 decimals if the token is not in the registry).
|
|
14
14
|
*/
|
|
15
|
-
async function getERC20AdapterBalance(chainId, adapterAddress, userAddress,
|
|
16
|
-
if (!
|
|
15
|
+
async function getERC20AdapterBalance(chainId, adapterAddress, userAddress, runner) {
|
|
16
|
+
if (!runner) {
|
|
17
17
|
throw new Error("Wallet not connected");
|
|
18
18
|
}
|
|
19
19
|
try {
|
|
20
20
|
const abi = (0, artifacts_1.getABI)("erc20assetadapter");
|
|
21
|
-
const adapterContract = new ethers_1.ethers.Contract(adapterAddress, abi,
|
|
21
|
+
const adapterContract = new ethers_1.ethers.Contract(adapterAddress, abi, runner);
|
|
22
22
|
const [balance, token] = await Promise.all([
|
|
23
23
|
adapterContract.balanceOf(userAddress),
|
|
24
24
|
adapterContract.token(),
|
|
@@ -88,6 +88,11 @@ import { quoteBuy } from "./contracts/zeno/quoteBuy";
|
|
|
88
88
|
import { ChainId } from "./configs/chains";
|
|
89
89
|
import getBaseUri from "./nfts/getBaseUri";
|
|
90
90
|
import claimRewardFromPool from "./contracts/feeCollector/claimRewardFromPool";
|
|
91
|
+
import { getState as getStateRentStreamer } from "./contracts/rentStreamer/getState";
|
|
92
|
+
import { previewRelease as previewReleaseRentStreamer } from "./contracts/rentStreamer/previewRelease";
|
|
93
|
+
import { getScheduled as getScheduledRentStreamer } from "./contracts/rentStreamer/getScheduled";
|
|
94
|
+
import { sync as syncRentStreamer } from "./contracts/rentStreamer/sync";
|
|
95
|
+
import { release as releaseRentStreamer } from "./contracts/rentStreamer/release";
|
|
91
96
|
import getRawUserDepositsInLendingPool from "./pools/lendingPool/getRawUserDepositsInLendingPool";
|
|
92
97
|
import getRawUserDepositInStabilityPool from "./pools/stabilityPool/getRawUserDepositsInStabilityPool";
|
|
93
98
|
import getEligibleUserDeposits from "./pools/lendingPool/getEligibleUserDeposits";
|
|
@@ -134,11 +139,13 @@ import { cancelExit as cancelExitPsm } from "./contracts/psm/cancelExit";
|
|
|
134
139
|
import { redeem as redeemPsm } from "./contracts/psm/redeem";
|
|
135
140
|
import { swap as swapPsm } from "./contracts/psm/swap";
|
|
136
141
|
import { getABI } from "./utils/artifacts";
|
|
137
|
-
import { toAmount, toScaled, parseAmount, toDecimalString, serializeAmount, deserializeAmount, getAssetDecimals, getTokenInfo, toTokenAmount } from "./utils/amount";
|
|
142
|
+
import { toAmount, toScaled, parseAmount, toDecimalString, toNumber, serializeAmount, deserializeAmount, getAssetDecimals, getTokenInfo, toTokenAmount } from "./utils/amount";
|
|
138
143
|
import * as distributorMethods from "./contracts/governance/distributor";
|
|
139
144
|
import * as gaugeMethods from "./contracts/governance/gauge";
|
|
140
145
|
import * as controllerMethods from "./contracts/governance/gaugeController";
|
|
141
146
|
import * as gaugeSystemMethods from "./contracts/governance/gaugeSystems";
|
|
147
|
+
import * as curveCommonMethods from "./contracts/curve/common";
|
|
148
|
+
import * as userMethods from "./user";
|
|
142
149
|
import { cancel as cancelProposals } from "./contracts/governance/proposals/cancel";
|
|
143
150
|
import { getQuorumNumerator as getQuorumNumeratorProposals } from "./contracts/governance/proposals/getQuorumNumerator";
|
|
144
151
|
import { getVotingPeriod as getVotingPeriodProposals } from "./contracts/governance/proposals/getVotingPeriod";
|
|
@@ -316,6 +323,10 @@ declare class RPCLibrary {
|
|
|
316
323
|
address: JsonRpcSigner | string;
|
|
317
324
|
chainId: ChainId | bigint | null;
|
|
318
325
|
privateKey: any;
|
|
326
|
+
curve: {
|
|
327
|
+
common: typeof curveCommonMethods;
|
|
328
|
+
};
|
|
329
|
+
user: typeof userMethods;
|
|
319
330
|
prices: {
|
|
320
331
|
getPrices: typeof getPrices;
|
|
321
332
|
getTokenPriceUSD: typeof getTokenPriceUSD;
|
|
@@ -393,6 +404,13 @@ declare class RPCLibrary {
|
|
|
393
404
|
feeCollector: {
|
|
394
405
|
claimRewardFromPool: typeof claimRewardFromPool;
|
|
395
406
|
};
|
|
407
|
+
rentStreamer: {
|
|
408
|
+
getState: typeof getStateRentStreamer;
|
|
409
|
+
previewRelease: typeof previewReleaseRentStreamer;
|
|
410
|
+
getScheduled: typeof getScheduledRentStreamer;
|
|
411
|
+
sync: typeof syncRentStreamer;
|
|
412
|
+
release: typeof releaseRentStreamer;
|
|
413
|
+
};
|
|
396
414
|
getABI: typeof getABI;
|
|
397
415
|
pmTreasury: {
|
|
398
416
|
getCollateralRatio: typeof getCollateralRatio;
|
|
@@ -732,6 +750,7 @@ declare class RPCLibrary {
|
|
|
732
750
|
toScaled: typeof toScaled;
|
|
733
751
|
parseAmount: typeof parseAmount;
|
|
734
752
|
toDecimalString: typeof toDecimalString;
|
|
753
|
+
toNumber: typeof toNumber;
|
|
735
754
|
serializeAmount: typeof serializeAmount;
|
|
736
755
|
deserializeAmount: typeof deserializeAmount;
|
|
737
756
|
getAssetDecimals: typeof getAssetDecimals;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { CurvePoolEntry, CurvePools } from "../../../configs/chains/chain";
|
|
4
|
+
/**
|
|
5
|
+
* Reads every Curve pool flavour shares. Coin indexes differ (uint256 vs int128) only in swap and liquidity
|
|
6
|
+
* methods, which are not here.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CURVE_POOL_READ_ABI: string[];
|
|
9
|
+
export declare const getCurvePools: (chainId: ChainId) => CurvePools;
|
|
10
|
+
/** Resolves a Curve pool by its config key (any casing) or its address. */
|
|
11
|
+
export declare function resolveCurvePool(chainId: ChainId, poolAddressOrId: string): CurvePoolEntry;
|
|
12
|
+
export declare function getCurvePoolContract(chainId: ChainId, poolAddressOrId: string, provider?: Provider): {
|
|
13
|
+
entry: CurvePoolEntry;
|
|
14
|
+
contract: ethers.Contract;
|
|
15
|
+
provider: ethers.Provider;
|
|
16
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ChainId } from "../../../configs/chains";
|
|
2
|
+
import { CurvePoolEntry } from "../../../configs/chains/chain";
|
|
3
|
+
export interface CurvePoolCoin {
|
|
4
|
+
/** Asset key in the chain config, e.g. "pmusd". */
|
|
5
|
+
asset: string;
|
|
6
|
+
address: string;
|
|
7
|
+
/** From the token registry; the asset key when the registry has no symbol. */
|
|
8
|
+
symbol: string;
|
|
9
|
+
decimals: number;
|
|
10
|
+
}
|
|
11
|
+
export interface CurvePool extends Omit<CurvePoolEntry, "coins"> {
|
|
12
|
+
/** In pool index order: coins[i] is coin i on chain. */
|
|
13
|
+
coins: CurvePoolCoin[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Lists the Curve pools in the chain config.
|
|
17
|
+
*
|
|
18
|
+
* @param chainId - The chain/network to use.
|
|
19
|
+
* @returns Every configured pool with its flavour and coins in pool index order; empty when the chain has none.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getPools: (chainId: ChainId) => CurvePool[];
|
|
22
|
+
/**
|
|
23
|
+
* Looks up one Curve pool in the chain config. Reads the config only; no RPC call is made.
|
|
24
|
+
*
|
|
25
|
+
* @param chainId - The chain/network to use.
|
|
26
|
+
* @param poolAddressOrId - The pool's config key or its address.
|
|
27
|
+
* @returns The pool with its flavour and coins in pool index order.
|
|
28
|
+
* @throws If the pool is not configured on the chain.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getPool: (chainId: ChainId, poolAddressOrId: string) => CurvePool;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* Reads a Curve pool's virtual price: the value of one whole LP token in units of the pool's underlying coins,
|
|
6
|
+
* which only grows with fees. For a stableswap pool of $1 coins it is the LP token's USD price.
|
|
7
|
+
*
|
|
8
|
+
* @param chainId - The chain/network to use.
|
|
9
|
+
* @param poolAddressOrId - The pool's key in the chain config's `curve` section, or its address.
|
|
10
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
11
|
+
* @returns `get_virtual_price()` as an 18-decimal amount, e.g. 1.0021 underlying per LP token.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getVirtualPrice: (chainId: ChainId, poolAddressOrId: string, provider?: Provider) => Promise<TokenAmount>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../utils/amount";
|
|
4
|
+
/**
|
|
5
|
+
* Reads the amount bucketed for one epoch. Released epochs read zero.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param epoch - Epoch start timestamp, a multiple of one week.
|
|
9
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
10
|
+
* @returns The scheduled amount in the streamed token's base units.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getScheduled: (chainId: ChainId, epoch: bigint, provider?: Provider) => Promise<TokenAmount>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
import { ScaledValue, TokenAmount } from "../../utils/amount";
|
|
4
|
+
export interface RentStreamerState {
|
|
5
|
+
/** Streamed token (USDC). */
|
|
6
|
+
token: string;
|
|
7
|
+
/** GaugeRewardsDistributor every release deposits into. */
|
|
8
|
+
distributor: string;
|
|
9
|
+
/** Number of weekly buckets each synced amount is split over. */
|
|
10
|
+
numEpochs: number;
|
|
11
|
+
/** Keeper bounty at the start of an epoch, 18-decimal fraction of the released amount (1.0 = 100%). */
|
|
12
|
+
minBountyFee: ScaledValue;
|
|
13
|
+
/** Keeper bounty once `bountyDuration` has passed, 18-decimal fraction of the released amount (1.0 = 100%). */
|
|
14
|
+
maxBountyFee: ScaledValue;
|
|
15
|
+
/** Seconds over which the bounty ramps from min to max after an epoch starts. */
|
|
16
|
+
bountyDuration: number;
|
|
17
|
+
/** Whether the streamer was permanently shut down. */
|
|
18
|
+
killed: boolean;
|
|
19
|
+
/** Token synced into buckets and not yet released. */
|
|
20
|
+
processed: TokenAmount;
|
|
21
|
+
/** Token released so far, bounties included. */
|
|
22
|
+
released: TokenAmount;
|
|
23
|
+
/** Start timestamp of the last released epoch. */
|
|
24
|
+
lastEpochProcessed: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reads the RentStreamer's configuration and running totals.
|
|
28
|
+
*
|
|
29
|
+
* @param chainId - The chain/network to use.
|
|
30
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
31
|
+
* @returns The streamer state; see `RentStreamerState` for the unit of each field.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getState: (chainId: ChainId, provider?: Provider) => Promise<RentStreamerState>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
import { TokenAmount } from "../../utils/amount";
|
|
4
|
+
export interface RentStreamerReleasePreview {
|
|
5
|
+
/** Total the next release takes out of the buckets, bounty included. */
|
|
6
|
+
amountToRelease: TokenAmount;
|
|
7
|
+
/** Part deposited into the RWA GaugeRewardsDistributor. */
|
|
8
|
+
amountToDistribute: TokenAmount;
|
|
9
|
+
/** Part paid to the keeper that calls `release`. */
|
|
10
|
+
bountyFee: TokenAmount;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Previews what a `release` would move right now. All zero when the current epoch was already released or the
|
|
14
|
+
* streamer is killed. The bounty grows with time since the epoch start, so the real release can differ.
|
|
15
|
+
*
|
|
16
|
+
* @param chainId - The chain/network to use.
|
|
17
|
+
* @param provider - Optional ethers.js Provider instance.
|
|
18
|
+
* @returns The release preview, in the streamed token's base units.
|
|
19
|
+
*/
|
|
20
|
+
export declare const previewRelease: (chainId: ChainId, provider?: Provider) => Promise<RentStreamerReleasePreview>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Releases the current epoch's buckets: pays the keeper bounty and deposits the rest into the RWA
|
|
5
|
+
* GaugeRewardsDistributor. Permissionless, once per epoch; reverts while the RWA gauge system has no active gauge.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param receiver - Address paid the bounty; the signer when omitted.
|
|
9
|
+
* @param signer - An ethers.js Signer instance (required).
|
|
10
|
+
* @returns The transaction.
|
|
11
|
+
*/
|
|
12
|
+
export declare const release: (chainId: ChainId, receiver: string | undefined, signer: Signer) => Promise<import("ethers").ContractTransactionResponse>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
|
+
import { ChainId } from "../../configs/chains";
|
|
3
|
+
/**
|
|
4
|
+
* Splits token sent to the streamer since the last sync over the next `numEpochs` weekly buckets. Permissionless;
|
|
5
|
+
* `release` also syncs first.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - The chain/network to use.
|
|
8
|
+
* @param signer - An ethers.js Signer instance (required).
|
|
9
|
+
* @returns The transaction.
|
|
10
|
+
*/
|
|
11
|
+
export declare const sync: (chainId: ChainId, signer: Signer) => Promise<import("ethers").ContractTransactionResponse>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Signer } from "ethers";
|
|
1
|
+
import { Provider, Signer } from "ethers";
|
|
2
2
|
import { ChainId } from "../../../../configs/chains";
|
|
3
3
|
import { TokenAmount } from "../../../../utils/amount";
|
|
4
4
|
/**
|
|
@@ -6,8 +6,8 @@ import { TokenAmount } from "../../../../utils/amount";
|
|
|
6
6
|
* @param chainId The chain id, used to look up the adapter token's decimals in the token registry.
|
|
7
7
|
* @param adapterAddress The ERC20 asset adapter address.
|
|
8
8
|
* @param userAddress The user.
|
|
9
|
-
* @param
|
|
9
|
+
* @param runner The signer or provider to read with. A read-only provider is enough.
|
|
10
10
|
* @returns The deposited balance in base units of the adapter's token, with its registry decimals and symbol (18 decimals if the token is not in the registry).
|
|
11
11
|
*/
|
|
12
|
-
declare function getERC20AdapterBalance(chainId: ChainId, adapterAddress: string, userAddress: string,
|
|
12
|
+
declare function getERC20AdapterBalance(chainId: ChainId, adapterAddress: string, userAddress: string, runner: Signer | Provider): Promise<TokenAmount>;
|
|
13
13
|
export default getERC20AdapterBalance;
|