@raac/rpc 2.0.0-beta.5 → 2.0.0-beta.7

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.
Files changed (70) hide show
  1. package/dist/RPCLibrary.js +46 -8
  2. package/dist/configs/chains/11155111.json +32 -2
  3. package/dist/configs/chains/8453.json +23 -2
  4. package/dist/contracts/curve/common/_helpers.js +39 -0
  5. package/dist/contracts/curve/common/getPools.js +36 -0
  6. package/dist/contracts/curve/common/getVirtualPrice.js +26 -0
  7. package/dist/contracts/curve/common/index.js +18 -0
  8. package/dist/contracts/findContract.js +3 -3
  9. package/dist/contracts/getContractAddress.js +1 -0
  10. package/dist/contracts/governance/gaugeSystems/_helpers.js +2 -2
  11. package/dist/contracts/zeno/_helpers.js +43 -0
  12. package/dist/contracts/zeno/buy.js +27 -0
  13. package/dist/contracts/zeno/getAuctionState.js +45 -0
  14. package/dist/contracts/zeno/getAuctions.js +7 -4
  15. package/dist/contracts/zeno/getBondState.js +47 -0
  16. package/dist/contracts/zeno/getPrice.js +23 -0
  17. package/dist/contracts/zeno/getZenos.js +6 -6
  18. package/dist/contracts/zeno/grantRole.js +46 -0
  19. package/dist/contracts/zeno/pause.js +42 -0
  20. package/dist/contracts/zeno/priceAt.js +20 -0
  21. package/dist/contracts/zeno/quoteBuy.js +33 -0
  22. package/dist/contracts/zeno/redeem.js +44 -0
  23. package/dist/contracts/zeno/setAuction.js +25 -0
  24. package/dist/contracts/zeno/sweepSurplus.js +26 -0
  25. package/dist/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.js +4 -4
  26. package/dist/types/RPCLibrary.d.ts +33 -1
  27. package/dist/types/contracts/curve/common/_helpers.d.ts +16 -0
  28. package/dist/types/contracts/curve/common/getPools.d.ts +30 -0
  29. package/dist/types/contracts/curve/common/getVirtualPrice.d.ts +13 -0
  30. package/dist/types/contracts/curve/common/index.d.ts +2 -0
  31. package/dist/types/contracts/zeno/_helpers.d.ts +17 -0
  32. package/dist/types/contracts/zeno/buy.d.ts +15 -0
  33. package/dist/types/contracts/zeno/getAuctionState.d.ts +45 -0
  34. package/dist/types/contracts/zeno/getAuctions.d.ts +3 -2
  35. package/dist/types/contracts/zeno/getBondState.d.ts +42 -0
  36. package/dist/types/contracts/zeno/getPrice.d.ts +12 -0
  37. package/dist/types/contracts/zeno/getZenos.d.ts +2 -2
  38. package/dist/types/contracts/zeno/grantRole.d.ts +22 -0
  39. package/dist/types/contracts/zeno/pause.d.ts +18 -0
  40. package/dist/types/contracts/zeno/priceAt.d.ts +20 -0
  41. package/dist/types/contracts/zeno/quoteBuy.d.ts +34 -0
  42. package/dist/types/contracts/zeno/redeem.d.ts +20 -0
  43. package/dist/types/contracts/zeno/setAuction.d.ts +13 -0
  44. package/dist/types/contracts/zeno/sweepSurplus.d.ts +14 -0
  45. package/dist/types/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.d.ts +3 -3
  46. package/dist/types/user/_helpers.d.ts +23 -0
  47. package/dist/types/user/computeEffectiveReturn.d.ts +67 -0
  48. package/dist/types/user/getUserClaimables.d.ts +55 -0
  49. package/dist/types/user/getUserCollateral.d.ts +12 -0
  50. package/dist/types/user/getUserDebt.d.ts +18 -0
  51. package/dist/types/user/getUserFarming.d.ts +64 -0
  52. package/dist/types/user/getUserGovernance.d.ts +20 -0
  53. package/dist/types/user/getUserPortfolio.d.ts +61 -0
  54. package/dist/types/user/getUserWalletBalances.d.ts +20 -0
  55. package/dist/types/user/index.d.ts +9 -0
  56. package/dist/types/utils/amount.d.ts +7 -0
  57. package/dist/types/utils/contracts.d.ts +2 -0
  58. package/dist/user/_helpers.js +22 -0
  59. package/dist/user/computeEffectiveReturn.js +33 -0
  60. package/dist/user/getUserClaimables.js +97 -0
  61. package/dist/user/getUserCollateral.js +29 -0
  62. package/dist/user/getUserDebt.js +32 -0
  63. package/dist/user/getUserFarming.js +100 -0
  64. package/dist/user/getUserGovernance.js +35 -0
  65. package/dist/user/getUserPortfolio.js +109 -0
  66. package/dist/user/getUserWalletBalances.js +30 -0
  67. package/dist/user/index.js +24 -0
  68. package/dist/utils/amount.js +10 -0
  69. package/dist/utils/contracts.js +5 -2
  70. package/package.json +1 -1
@@ -7,14 +7,14 @@ const ethers_1 = require("ethers");
7
7
  const chains_1 = __importDefault(require("../../configs/chains"));
8
8
  const contracts_1 = require("../../utils/contracts");
9
9
  const artifacts_1 = require("../../utils/artifacts");
10
- const amount_1 = require("../../utils/amount");
11
10
  const rpcError_1 = require("../../utils/rpcError");
11
+ const _helpers_1 = require("./_helpers");
12
12
  /**
13
13
  * Lists every ZENO bond created by the ZENOFactory.
14
14
  * @param chainId The chain id.
15
15
  * @param provider The provider to read with. Defaults to the chain's first configured RPC.
16
- * @returns One record per bond. Amounts take decimals from the chain config registry and fall back to 18 when the
17
- * bond is not listed.
16
+ * @returns One record per bond. ZENO shares its underlying's decimals, so amounts take the underlying's from the chain
17
+ * config registry and fall back to 18 when it is not listed.
18
18
  */
19
19
  async function getZenos(chainId, provider) {
20
20
  if (!provider) {
@@ -26,14 +26,14 @@ async function getZenos(chainId, provider) {
26
26
  const zenoAddresses = await zenoFactoryContract.getZENOs();
27
27
  return await Promise.all(zenoAddresses.map(async (address) => {
28
28
  const zenoContract = new ethers_1.ethers.Contract(address, (0, artifacts_1.getABI)("zeno"), provider);
29
- const details = await zenoContract.getDetails();
29
+ const [details, underlying] = await Promise.all([zenoContract.getDetails(), zenoContract.underlyingAsset()]);
30
30
  return {
31
31
  zenoAddress: details.zenoAddress,
32
32
  maturityDate: details.maturityDate,
33
33
  name: details.name,
34
34
  symbol: details.symbol,
35
- totalMinted: (0, amount_1.toTokenAmount)(chainId, details.zenoAddress, details.totalMinted),
36
- totalRedeemed: (0, amount_1.toTokenAmount)(chainId, details.zenoAddress, details.totalRedeemed),
35
+ totalMinted: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalMinted, details.symbol),
36
+ totalRedeemed: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalRedeemed, details.symbol),
37
37
  };
38
38
  }));
39
39
  }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.grantRole = grantRole;
4
+ exports.revokeRole = revokeRole;
5
+ const rpcError_1 = require("../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Grants an auction role, e.g. PAUSER_ROLE to a guardian bot. DEFAULT_ADMIN_ROLE only.
9
+ * @param chainId The chain id.
10
+ * @param auction The auction address.
11
+ * @param role The bytes32 role identifier: `keccak256("PAUSER_ROLE")`, or the zero hash for DEFAULT_ADMIN_ROLE.
12
+ * @param account The address to grant it to.
13
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
14
+ * @returns The transaction receipt.
15
+ */
16
+ async function grantRole(chainId, auction, role, account, signer) {
17
+ if (!signer)
18
+ throw new Error("Signer is required");
19
+ try {
20
+ const tx = await (0, _helpers_1.getAuctionContract)(chainId, auction, signer).grantRole(role, account);
21
+ return await tx.wait();
22
+ }
23
+ catch (error) {
24
+ throw (0, rpcError_1.toRpcError)("zeno.grantRole", error, { chainId, address: auction });
25
+ }
26
+ }
27
+ /**
28
+ * Revokes an auction role. DEFAULT_ADMIN_ROLE only.
29
+ * @param chainId The chain id.
30
+ * @param auction The auction address.
31
+ * @param role The bytes32 role identifier: `keccak256("PAUSER_ROLE")`, or the zero hash for DEFAULT_ADMIN_ROLE.
32
+ * @param account The address to revoke it from.
33
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
34
+ * @returns The transaction receipt.
35
+ */
36
+ async function revokeRole(chainId, auction, role, account, signer) {
37
+ if (!signer)
38
+ throw new Error("Signer is required");
39
+ try {
40
+ const tx = await (0, _helpers_1.getAuctionContract)(chainId, auction, signer).revokeRole(role, account);
41
+ return await tx.wait();
42
+ }
43
+ catch (error) {
44
+ throw (0, rpcError_1.toRpcError)("zeno.revokeRole", error, { chainId, address: auction });
45
+ }
46
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pause = pause;
4
+ exports.unpause = unpause;
5
+ const rpcError_1 = require("../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Halts `buy` on an auction. PAUSER_ROLE only. A Dutch price keeps falling while paused.
9
+ * @param chainId The chain id.
10
+ * @param auction The auction address.
11
+ * @param signer A PAUSER_ROLE holder.
12
+ * @returns The transaction receipt.
13
+ */
14
+ async function pause(chainId, auction, signer) {
15
+ if (!signer)
16
+ throw new Error("Signer is required");
17
+ try {
18
+ const tx = await (0, _helpers_1.getAuctionContract)(chainId, auction, signer).pause();
19
+ return await tx.wait();
20
+ }
21
+ catch (error) {
22
+ throw (0, rpcError_1.toRpcError)("zeno.pause", error, { chainId, address: auction });
23
+ }
24
+ }
25
+ /**
26
+ * Resumes `buy` on an auction. DEFAULT_ADMIN_ROLE only, so a compromised pauser cannot reopen buying.
27
+ * @param chainId The chain id.
28
+ * @param auction The auction address.
29
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
30
+ * @returns The transaction receipt.
31
+ */
32
+ async function unpause(chainId, auction, signer) {
33
+ if (!signer)
34
+ throw new Error("Signer is required");
35
+ try {
36
+ const tx = await (0, _helpers_1.getAuctionContract)(chainId, auction, signer).unpause();
37
+ return await tx.wait();
38
+ }
39
+ catch (error) {
40
+ throw (0, rpcError_1.toRpcError)("zeno.unpause", error, { chainId, address: auction });
41
+ }
42
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.priceAt = void 0;
4
+ /**
5
+ * An auction's price at `now`, computed locally without an RPC call. Mirrors `Auction.getPrice()` exactly, truncating
6
+ * division included: the starting price before the window, the reserve from `endTime` on, a linear fall between.
7
+ *
8
+ * @param terms The auction's price terms, e.g. from `getAuctionState` or the subgraph's `BondAuction`.
9
+ * @param now UNIX timestamp (seconds). Use the latest block timestamp to match the contract exactly.
10
+ * @returns The price in payment token base units per whole ZENO.
11
+ */
12
+ const priceAt = (terms, now) => {
13
+ if (now < terms.startTime)
14
+ return terms.startingPrice;
15
+ if (now >= terms.endTime)
16
+ return terms.reservePrice;
17
+ return (terms.startingPrice -
18
+ ((terms.startingPrice - terms.reservePrice) * (now - terms.startTime)) / (terms.endTime - terms.startTime));
19
+ };
20
+ exports.priceAt = priceAt;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quoteBuy = void 0;
4
+ const BPS = 10000n;
5
+ /**
6
+ * What a buy mints, computed locally without an RPC call with `Auction.buy`'s integer maths:
7
+ * `zenoOut = paymentAmount * 10^zenoDecimals / price`, truncated.
8
+ *
9
+ * A Dutch price only falls, so a buy mined after the quote mints at least `zenoOut`; `minZenoOut` guards against a
10
+ * fixed price or a stale quote. The same fall means a payment at exactly `maxPayment` can revert a block later, so
11
+ * leave headroom when buying out the remainder.
12
+ *
13
+ * @param input The price, payment, ZENO decimals, remaining supply and slippage tolerance.
14
+ * @returns The ZENO out, the `minZenoOut` to send, and the payment ceiling.
15
+ */
16
+ const quoteBuy = (input) => {
17
+ if (input.price <= 0n)
18
+ throw new Error("Price must be positive");
19
+ const slippageBps = input.slippageBps ?? 0n;
20
+ if (slippageBps < 0n || slippageBps > BPS)
21
+ throw new Error("Slippage must be between 0 and 10000 bps");
22
+ const scale = 10n ** BigInt(input.zenoDecimals);
23
+ const zenoOut = (input.paymentAmount * scale) / input.price;
24
+ // floor(p * scale / price) <= remaining <=> p * scale < (remaining + 1) * price
25
+ const maxPayment = ((input.totalRemaining + 1n) * input.price - 1n) / scale;
26
+ return {
27
+ zenoOut,
28
+ minZenoOut: (zenoOut * (BPS - slippageBps)) / BPS,
29
+ maxPayment,
30
+ exceedsRemaining: input.paymentAmount > maxPayment,
31
+ };
32
+ };
33
+ exports.quoteBuy = quoteBuy;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redeem = redeem;
4
+ exports.redeemAll = redeemAll;
5
+ const rpcError_1 = require("../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Redeems ZENO 1:1 for the underlying. Reverts before maturity, and while the bond's collateral is short of its
9
+ * outstanding supply (`getBondState(...).isFunded`).
10
+ * @param chainId The chain id.
11
+ * @param zeno The ZENO bond address.
12
+ * @param amount ZENO to redeem, in base units.
13
+ * @param signer The holder, who receives the underlying.
14
+ * @returns The transaction receipt.
15
+ */
16
+ async function redeem(chainId, zeno, amount, signer) {
17
+ if (!signer)
18
+ throw new Error("Signer is required");
19
+ try {
20
+ const tx = await (0, _helpers_1.getZenoContract)(chainId, zeno, signer).redeem(amount);
21
+ return await tx.wait();
22
+ }
23
+ catch (error) {
24
+ throw (0, rpcError_1.toRpcError)("zeno.redeem", error, { chainId, address: zeno });
25
+ }
26
+ }
27
+ /**
28
+ * Redeems the signer's whole ZENO balance for the underlying. Same conditions as `redeem`.
29
+ * @param chainId The chain id.
30
+ * @param zeno The ZENO bond address.
31
+ * @param signer The holder, who receives the underlying.
32
+ * @returns The transaction receipt.
33
+ */
34
+ async function redeemAll(chainId, zeno, signer) {
35
+ if (!signer)
36
+ throw new Error("Signer is required");
37
+ try {
38
+ const tx = await (0, _helpers_1.getZenoContract)(chainId, zeno, signer).redeemAll();
39
+ return await tx.wait();
40
+ }
41
+ catch (error) {
42
+ throw (0, rpcError_1.toRpcError)("zeno.redeemAll", error, { chainId, address: zeno });
43
+ }
44
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rpcError_1 = require("../../utils/rpcError");
4
+ const _helpers_1 = require("./_helpers");
5
+ /**
6
+ * Binds a ZENO to the auction that sells it. One-shot, ZENO owner only; reverts unless the auction's `zeno()` points
7
+ * back at this ZENO. Until it is set, the auction's buys revert.
8
+ * @param chainId The chain id.
9
+ * @param zeno The ZENO bond address.
10
+ * @param auction The auction created for it.
11
+ * @param signer The ZENO owner.
12
+ * @returns The transaction receipt.
13
+ */
14
+ async function setAuction(chainId, zeno, auction, signer) {
15
+ if (!signer)
16
+ throw new Error("Signer is required");
17
+ try {
18
+ const tx = await (0, _helpers_1.getZenoContract)(chainId, zeno, signer).setAuction(auction);
19
+ return await tx.wait();
20
+ }
21
+ catch (error) {
22
+ throw (0, rpcError_1.toRpcError)("zeno.setAuction", error, { chainId, address: zeno });
23
+ }
24
+ }
25
+ exports.default = setAuction;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rpcError_1 = require("../../utils/rpcError");
4
+ const _helpers_1 = require("./_helpers");
5
+ /**
6
+ * Sweeps underlying held above the ZENO's outstanding supply: unsold prefill, overpayments and post-maturity residue.
7
+ * ZENO owner only, and only once the bound auction has ended. `getBondState(...).sweepableSurplus` is the most it takes.
8
+ * @param chainId The chain id.
9
+ * @param zeno The ZENO bond address.
10
+ * @param to The recipient of the underlying.
11
+ * @param amount Underlying to sweep, in base units.
12
+ * @param signer The ZENO owner.
13
+ * @returns The transaction receipt.
14
+ */
15
+ async function sweepSurplus(chainId, zeno, to, amount, signer) {
16
+ if (!signer)
17
+ throw new Error("Signer is required");
18
+ try {
19
+ const tx = await (0, _helpers_1.getZenoContract)(chainId, zeno, signer).sweepSurplus(to, amount);
20
+ return await tx.wait();
21
+ }
22
+ catch (error) {
23
+ throw (0, rpcError_1.toRpcError)("zeno.sweepSurplus", error, { chainId, address: zeno });
24
+ }
25
+ }
26
+ exports.default = sweepSurplus;
@@ -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 signer The signer to read with.
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, signer) {
16
- if (!signer) {
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, signer);
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(),
@@ -74,6 +74,17 @@ import getAuctions from "./contracts/zeno/getAuctions";
74
74
  import createAuction from "./contracts/zeno/createAuction";
75
75
  import createZeno from "./contracts/zeno/createZeno";
76
76
  import getZenos from "./contracts/zeno/getZenos";
77
+ import getAuctionState from "./contracts/zeno/getAuctionState";
78
+ import getBondState from "./contracts/zeno/getBondState";
79
+ import getAuctionPrice from "./contracts/zeno/getPrice";
80
+ import buyZeno from "./contracts/zeno/buy";
81
+ import { redeem as redeemZeno, redeemAll as redeemAllZeno } from "./contracts/zeno/redeem";
82
+ import setAuction from "./contracts/zeno/setAuction";
83
+ import sweepSurplus from "./contracts/zeno/sweepSurplus";
84
+ import { pause as pauseAuction, unpause as unpauseAuction } from "./contracts/zeno/pause";
85
+ import { grantRole as grantRoleAuction, revokeRole as revokeRoleAuction } from "./contracts/zeno/grantRole";
86
+ import { priceAt } from "./contracts/zeno/priceAt";
87
+ import { quoteBuy } from "./contracts/zeno/quoteBuy";
77
88
  import { ChainId } from "./configs/chains";
78
89
  import getBaseUri from "./nfts/getBaseUri";
79
90
  import claimRewardFromPool from "./contracts/feeCollector/claimRewardFromPool";
@@ -123,11 +134,13 @@ import { cancelExit as cancelExitPsm } from "./contracts/psm/cancelExit";
123
134
  import { redeem as redeemPsm } from "./contracts/psm/redeem";
124
135
  import { swap as swapPsm } from "./contracts/psm/swap";
125
136
  import { getABI } from "./utils/artifacts";
126
- import { toAmount, toScaled, parseAmount, toDecimalString, serializeAmount, deserializeAmount, getAssetDecimals, getTokenInfo, toTokenAmount } from "./utils/amount";
137
+ import { toAmount, toScaled, parseAmount, toDecimalString, toNumber, serializeAmount, deserializeAmount, getAssetDecimals, getTokenInfo, toTokenAmount } from "./utils/amount";
127
138
  import * as distributorMethods from "./contracts/governance/distributor";
128
139
  import * as gaugeMethods from "./contracts/governance/gauge";
129
140
  import * as controllerMethods from "./contracts/governance/gaugeController";
130
141
  import * as gaugeSystemMethods from "./contracts/governance/gaugeSystems";
142
+ import * as curveCommonMethods from "./contracts/curve/common";
143
+ import * as userMethods from "./user";
131
144
  import { cancel as cancelProposals } from "./contracts/governance/proposals/cancel";
132
145
  import { getQuorumNumerator as getQuorumNumeratorProposals } from "./contracts/governance/proposals/getQuorumNumerator";
133
146
  import { getVotingPeriod as getVotingPeriodProposals } from "./contracts/governance/proposals/getVotingPeriod";
@@ -305,6 +318,10 @@ declare class RPCLibrary {
305
318
  address: JsonRpcSigner | string;
306
319
  chainId: ChainId | bigint | null;
307
320
  privateKey: any;
321
+ curve: {
322
+ common: typeof curveCommonMethods;
323
+ };
324
+ user: typeof userMethods;
308
325
  prices: {
309
326
  getPrices: typeof getPrices;
310
327
  getTokenPriceUSD: typeof getTokenPriceUSD;
@@ -696,6 +713,20 @@ declare class RPCLibrary {
696
713
  getAuctions: typeof getAuctions;
697
714
  createZeno: typeof createZeno;
698
715
  getZenos: typeof getZenos;
716
+ getAuctionState: typeof getAuctionState;
717
+ getBondState: typeof getBondState;
718
+ getPrice: typeof getAuctionPrice;
719
+ buy: typeof buyZeno;
720
+ redeem: typeof redeemZeno;
721
+ redeemAll: typeof redeemAllZeno;
722
+ setAuction: typeof setAuction;
723
+ sweepSurplus: typeof sweepSurplus;
724
+ pause: typeof pauseAuction;
725
+ unpause: typeof unpauseAuction;
726
+ grantRole: typeof grantRoleAuction;
727
+ revokeRole: typeof revokeRoleAuction;
728
+ priceAt: typeof priceAt;
729
+ quoteBuy: typeof quoteBuy;
699
730
  };
700
731
  provider: any;
701
732
  estimateGasPrice: any;
@@ -707,6 +738,7 @@ declare class RPCLibrary {
707
738
  toScaled: typeof toScaled;
708
739
  parseAmount: typeof parseAmount;
709
740
  toDecimalString: typeof toDecimalString;
741
+ toNumber: typeof toNumber;
710
742
  serializeAmount: typeof serializeAmount;
711
743
  deserializeAmount: typeof deserializeAmount;
712
744
  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,2 @@
1
+ export * from "./getPools";
2
+ export * from "./getVirtualPrice";
@@ -0,0 +1,17 @@
1
+ import { Provider, Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ import { TokenAmount } from "../../utils/amount";
4
+ import { Auction, ZENO } from "../../typechain-types";
5
+ /** The one ERC20 call the zeno methods make: the underlying held by a ZENO. */
6
+ export declare const ERC20_ABI: string[];
7
+ /** A ZENO bond. Bonds are created by the factory, so the address is passed in rather than read from the config. */
8
+ export declare function getZenoContract(chainId: ChainId, zeno: string, runner?: Provider | Signer): ZENO;
9
+ /** A ZENO auction. Auctions are created by the factory, so the address is passed in rather than read from the config. */
10
+ export declare function getAuctionContract(chainId: ChainId, auction: string, runner?: Provider | Signer): Auction;
11
+ /**
12
+ * A ZENO amount. ZENO takes its decimals from its underlying, so they come from the underlying's registry entry; a
13
+ * ZENO address itself is never in the registry. Falls back to 18 decimals when the underlying is not listed.
14
+ */
15
+ export declare function toZenoAmount(chainId: ChainId, underlying: string, value: bigint, symbol?: string): TokenAmount;
16
+ /** `ZENO.auction()` and other unset address fields read as the zero address; this maps that to null. */
17
+ export declare function addressOrNull(address: string): string | null;
@@ -0,0 +1,15 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Buys ZENO: spends exactly `paymentAmount` of the payment token, sent to the issuer, at the price of the block it is
5
+ * mined in. Needs a payment token allowance for the auction (`wallet.assets.approveAsset`). Reverts while paused,
6
+ * outside the auction window, when the ZENO out would exceed what is left, or when it is below `minZenoOut`.
7
+ * @param chainId The chain id.
8
+ * @param auction The auction address.
9
+ * @param paymentAmount Payment token to spend, in base units.
10
+ * @param minZenoOut The least ZENO to accept, in ZENO base units; `quoteBuy` sizes it.
11
+ * @param signer The buyer, who receives the ZENO.
12
+ * @returns The transaction receipt; its `ZENOPurchased` log carries the ZENO minted and the price paid.
13
+ */
14
+ declare function buy(chainId: ChainId, auction: string, paymentAmount: bigint, minZenoOut: bigint, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
15
+ export default buy;
@@ -0,0 +1,45 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ import { TokenAmount } from "../../utils/amount";
4
+ import { FundingMode } from "./createAuction";
5
+ /** A ZENO auction's terms and live state. Prices take the payment token's decimals, ZENO amounts the underlying's. */
6
+ export interface AuctionState {
7
+ /** The auction contract. */
8
+ auction: string;
9
+ /** The ZENO bond it sells. */
10
+ zeno: string;
11
+ /** What buyers pay with. */
12
+ paymentToken: string;
13
+ /** Receives every payment. */
14
+ issuer: string;
15
+ fundingMode: FundingMode;
16
+ /** UNIX timestamp (seconds) buying opens. */
17
+ startTime: bigint;
18
+ /** UNIX timestamp (seconds) buying closes, unless it sells out first. */
19
+ endTime: bigint;
20
+ /** Price at `startTime`, in payment token base units per whole ZENO. */
21
+ startingPrice: TokenAmount;
22
+ /** Price at and after `endTime`; equal to `startingPrice` for a fixed-price bond. */
23
+ reservePrice: TokenAmount;
24
+ /** True when the price does not decay. */
25
+ isFixedPrice: boolean;
26
+ /** `getPrice()` as of the block read. A Dutch price keeps falling every block, also while paused. */
27
+ price: TokenAmount;
28
+ /** ZENO on offer. */
29
+ totalAllocated: TokenAmount;
30
+ /** ZENO not yet sold; `buy` reverts when it would mint more. */
31
+ totalRemaining: TokenAmount;
32
+ /** True while `buy` is halted by the pauser. */
33
+ paused: boolean;
34
+ /** True once past `endTime` or sold out, as `checkAuctionEnded()` says. */
35
+ ended: boolean;
36
+ }
37
+ /**
38
+ * Reads one auction's terms and live state.
39
+ * @param chainId The chain id.
40
+ * @param auction The auction address.
41
+ * @param provider The provider to read with. Defaults to the chain's first configured RPC.
42
+ * @returns The auction's state.
43
+ */
44
+ declare function getAuctionState(chainId: ChainId, auction: string, provider?: Provider): Promise<AuctionState>;
45
+ export default getAuctionState;
@@ -33,8 +33,9 @@ export interface AuctionDetails {
33
33
  * Lists every auction created by the AuctionFactory.
34
34
  * @param chainId The chain id.
35
35
  * @param provider The provider to read with. Defaults to the chain's first configured RPC.
36
- * @returns One record per auction. Price amounts use the auction's payment token, ZENO amounts the ZENO
37
- * token; decimals and symbols come from the chain config registry and fall back to 18 when the token is not listed.
36
+ * @returns One record per auction. Price amounts use the auction's payment token, ZENO amounts the ZENO's underlying,
37
+ * whose decimals ZENO shares; decimals and symbols come from the chain config registry and fall back to 18 when the
38
+ * token is not listed.
38
39
  */
39
40
  declare function getAuctions(chainId: ChainId, provider?: Provider): Promise<AuctionDetails[]>;
40
41
  export default getAuctions;
@@ -0,0 +1,42 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ import { TokenAmount } from "../../utils/amount";
4
+ /** A ZENO bond's live state. ZENO amounts take the underlying's decimals. */
5
+ export interface BondState {
6
+ /** The ZENO bond contract. */
7
+ zeno: string;
8
+ /** ERC20 name, e.g. `ZENO Bond 20270101`. */
9
+ name: string;
10
+ /** ERC20 symbol, e.g. `ZENO-20270101`. */
11
+ symbol: string;
12
+ /** What 1 ZENO redeems for at maturity. */
13
+ underlying: string;
14
+ /** The auction bound by `setAuction`, the only one that can mint; null until it is set. */
15
+ auction: string | null;
16
+ /** UNIX timestamp (seconds) the bond matures. */
17
+ maturityDate: bigint;
18
+ /** True once maturity has passed. Redemption also needs `isFunded`. */
19
+ isRedeemable: boolean;
20
+ /** ZENO minted over the bond's lifetime; never falls. */
21
+ totalMinted: TokenAmount;
22
+ /** ZENO outstanding, still to be redeemed. */
23
+ totalSupply: TokenAmount;
24
+ /** ZENO redeemed for the underlying. */
25
+ totalRedeemed: TokenAmount;
26
+ /** Underlying held by the ZENO, in the underlying's base units. */
27
+ collateral: TokenAmount;
28
+ /** Underlying above outstanding supply, which the owner may sweep once the auction has ended. */
29
+ sweepableSurplus: TokenAmount;
30
+ /** True when collateral covers outstanding supply. `redeem` reverts with `InsufficientCollateral` while it is false, which only a Float bond the issuer has not topped up can reach. */
31
+ isFunded: boolean;
32
+ }
33
+ /**
34
+ * Reads a ZENO bond's live state: supply, collateral and whether it can be redeemed. Collateral is read here rather
35
+ * than indexed, because top-ups are plain transfers on the underlying that no ZENO event records.
36
+ * @param chainId The chain id.
37
+ * @param zeno The ZENO bond address.
38
+ * @param provider The provider to read with. Defaults to the chain's first configured RPC.
39
+ * @returns The bond's state.
40
+ */
41
+ declare function getBondState(chainId: ChainId, zeno: string, provider?: Provider): Promise<BondState>;
42
+ export default getBondState;
@@ -0,0 +1,12 @@
1
+ import { Provider } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ import { TokenAmount } from "../../utils/amount";
4
+ /**
5
+ * Reads an auction's current price. Read it right before `buy` to size `minZenoOut`: a Dutch price falls every block.
6
+ * @param chainId The chain id.
7
+ * @param auction The auction address.
8
+ * @param provider The provider to read with. Defaults to the chain's first configured RPC.
9
+ * @returns The price in payment token base units per whole ZENO.
10
+ */
11
+ declare function getPrice(chainId: ChainId, auction: string, provider?: Provider): Promise<TokenAmount>;
12
+ export default getPrice;
@@ -20,8 +20,8 @@ export interface ZenoDetails {
20
20
  * Lists every ZENO bond created by the ZENOFactory.
21
21
  * @param chainId The chain id.
22
22
  * @param provider The provider to read with. Defaults to the chain's first configured RPC.
23
- * @returns One record per bond. Amounts take decimals from the chain config registry and fall back to 18 when the
24
- * bond is not listed.
23
+ * @returns One record per bond. ZENO shares its underlying's decimals, so amounts take the underlying's from the chain
24
+ * config registry and fall back to 18 when it is not listed.
25
25
  */
26
26
  declare function getZenos(chainId: ChainId, provider?: Provider): Promise<ZenoDetails[]>;
27
27
  export default getZenos;
@@ -0,0 +1,22 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Grants an auction role, e.g. PAUSER_ROLE to a guardian bot. DEFAULT_ADMIN_ROLE only.
5
+ * @param chainId The chain id.
6
+ * @param auction The auction address.
7
+ * @param role The bytes32 role identifier: `keccak256("PAUSER_ROLE")`, or the zero hash for DEFAULT_ADMIN_ROLE.
8
+ * @param account The address to grant it to.
9
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
10
+ * @returns The transaction receipt.
11
+ */
12
+ export declare function grantRole(chainId: ChainId, auction: string, role: string, account: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
13
+ /**
14
+ * Revokes an auction role. DEFAULT_ADMIN_ROLE only.
15
+ * @param chainId The chain id.
16
+ * @param auction The auction address.
17
+ * @param role The bytes32 role identifier: `keccak256("PAUSER_ROLE")`, or the zero hash for DEFAULT_ADMIN_ROLE.
18
+ * @param account The address to revoke it from.
19
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
20
+ * @returns The transaction receipt.
21
+ */
22
+ export declare function revokeRole(chainId: ChainId, auction: string, role: string, account: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;