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

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 (33) hide show
  1. package/dist/RPCLibrary.js +33 -8
  2. package/dist/configs/chains/11155111.json +2 -2
  3. package/dist/configs/chains/8453.json +23 -2
  4. package/dist/contracts/zeno/_helpers.js +43 -0
  5. package/dist/contracts/zeno/buy.js +27 -0
  6. package/dist/contracts/zeno/getAuctionState.js +45 -0
  7. package/dist/contracts/zeno/getAuctions.js +7 -4
  8. package/dist/contracts/zeno/getBondState.js +47 -0
  9. package/dist/contracts/zeno/getPrice.js +23 -0
  10. package/dist/contracts/zeno/getZenos.js +6 -6
  11. package/dist/contracts/zeno/grantRole.js +46 -0
  12. package/dist/contracts/zeno/pause.js +42 -0
  13. package/dist/contracts/zeno/priceAt.js +20 -0
  14. package/dist/contracts/zeno/quoteBuy.js +33 -0
  15. package/dist/contracts/zeno/redeem.js +44 -0
  16. package/dist/contracts/zeno/setAuction.js +25 -0
  17. package/dist/contracts/zeno/sweepSurplus.js +26 -0
  18. package/dist/types/RPCLibrary.d.ts +25 -0
  19. package/dist/types/contracts/zeno/_helpers.d.ts +17 -0
  20. package/dist/types/contracts/zeno/buy.d.ts +15 -0
  21. package/dist/types/contracts/zeno/getAuctionState.d.ts +45 -0
  22. package/dist/types/contracts/zeno/getAuctions.d.ts +3 -2
  23. package/dist/types/contracts/zeno/getBondState.d.ts +42 -0
  24. package/dist/types/contracts/zeno/getPrice.d.ts +12 -0
  25. package/dist/types/contracts/zeno/getZenos.d.ts +2 -2
  26. package/dist/types/contracts/zeno/grantRole.d.ts +22 -0
  27. package/dist/types/contracts/zeno/pause.d.ts +18 -0
  28. package/dist/types/contracts/zeno/priceAt.d.ts +20 -0
  29. package/dist/types/contracts/zeno/quoteBuy.d.ts +34 -0
  30. package/dist/types/contracts/zeno/redeem.d.ts +20 -0
  31. package/dist/types/contracts/zeno/setAuction.d.ts +13 -0
  32. package/dist/types/contracts/zeno/sweepSurplus.d.ts +14 -0
  33. package/package.json +1 -1
@@ -133,6 +133,17 @@ const getAuctions_1 = __importDefault(require("./contracts/zeno/getAuctions"));
133
133
  const createAuction_1 = __importDefault(require("./contracts/zeno/createAuction"));
134
134
  const createZeno_1 = __importDefault(require("./contracts/zeno/createZeno"));
135
135
  const getZenos_1 = __importDefault(require("./contracts/zeno/getZenos"));
136
+ const getAuctionState_1 = __importDefault(require("./contracts/zeno/getAuctionState"));
137
+ const getBondState_1 = __importDefault(require("./contracts/zeno/getBondState"));
138
+ const getPrice_1 = __importDefault(require("./contracts/zeno/getPrice"));
139
+ const buy_1 = __importDefault(require("./contracts/zeno/buy"));
140
+ const redeem_1 = require("./contracts/zeno/redeem");
141
+ const setAuction_1 = __importDefault(require("./contracts/zeno/setAuction"));
142
+ const sweepSurplus_1 = __importDefault(require("./contracts/zeno/sweepSurplus"));
143
+ const pause_2 = require("./contracts/zeno/pause");
144
+ const grantRole_1 = require("./contracts/zeno/grantRole");
145
+ const priceAt_1 = require("./contracts/zeno/priceAt");
146
+ const quoteBuy_1 = require("./contracts/zeno/quoteBuy");
136
147
  const getBaseUri_1 = __importDefault(require("./nfts/getBaseUri"));
137
148
  const claimRewardFromPool_1 = __importDefault(require("./contracts/feeCollector/claimRewardFromPool"));
138
149
  const getRawUserDepositsInLendingPool_1 = __importDefault(require("./pools/lendingPool/getRawUserDepositsInLendingPool"));
@@ -179,7 +190,7 @@ const previewProportionalSplit_1 = require("./contracts/psm/previewProportionalS
179
190
  const deposit_1 = require("./contracts/psm/deposit");
180
191
  const requestExit_1 = require("./contracts/psm/requestExit");
181
192
  const cancelExit_1 = require("./contracts/psm/cancelExit");
182
- const redeem_1 = require("./contracts/psm/redeem");
193
+ const redeem_2 = require("./contracts/psm/redeem");
183
194
  const swap_1 = require("./contracts/psm/swap");
184
195
  const artifacts_1 = require("./utils/artifacts");
185
196
  const rpcError_1 = require("./utils/rpcError");
@@ -328,10 +339,10 @@ const getConfig_3 = require("./contracts/lockers/botLocker/getConfig");
328
339
  const getUnlockWindow_1 = require("./contracts/lockers/botLocker/getUnlockWindow");
329
340
  const getRoles_3 = require("./contracts/lockers/botLocker/getRoles");
330
341
  const hasRole_3 = require("./contracts/lockers/botLocker/hasRole");
331
- const grantRole_1 = require("./contracts/lockers/botLocker/grantRole");
342
+ const grantRole_2 = require("./contracts/lockers/botLocker/grantRole");
332
343
  const addRewardTokens_1 = require("./contracts/lockers/botLocker/addRewardTokens");
333
344
  const distributeRewardToken_1 = require("./contracts/lockers/botLocker/distributeRewardToken");
334
- const pause_2 = require("./contracts/lockers/botLocker/pause");
345
+ const pause_3 = require("./contracts/lockers/botLocker/pause");
335
346
  const rescueTokens_1 = require("./contracts/lockers/botLocker/rescueTokens");
336
347
  // leRAAC token
337
348
  const getBalance_8 = require("./contracts/tokens/leRAAC/getBalance");
@@ -644,12 +655,12 @@ class RPCLibrary {
644
655
  getUnlockWindow: getUnlockWindow_1.getUnlockWindow,
645
656
  getRoles: getRoles_3.getRoles,
646
657
  hasRole: hasRole_3.hasRole,
647
- grantRole: grantRole_1.grantRole,
648
- revokeRole: grantRole_1.revokeRole,
658
+ grantRole: grantRole_2.grantRole,
659
+ revokeRole: grantRole_2.revokeRole,
649
660
  addRewardTokens: addRewardTokens_1.addRewardTokens,
650
661
  distributeRewardToken: distributeRewardToken_1.distributeRewardToken,
651
- pause: pause_2.pause,
652
- unpause: pause_2.unpause,
662
+ pause: pause_3.pause,
663
+ unpause: pause_3.unpause,
653
664
  rescueTokens: rescueTokens_1.rescueTokens,
654
665
  },
655
666
  };
@@ -732,7 +743,7 @@ class RPCLibrary {
732
743
  deposit: deposit_1.deposit,
733
744
  requestExit: requestExit_1.requestExit,
734
745
  cancelExit: cancelExit_1.cancelExit,
735
- redeem: redeem_1.redeem,
746
+ redeem: redeem_2.redeem,
736
747
  swap: swap_1.swap,
737
748
  };
738
749
  this.pools = {
@@ -820,6 +831,20 @@ class RPCLibrary {
820
831
  getAuctions: getAuctions_1.default,
821
832
  createZeno: createZeno_1.default,
822
833
  getZenos: getZenos_1.default,
834
+ getAuctionState: getAuctionState_1.default,
835
+ getBondState: getBondState_1.default,
836
+ getPrice: getPrice_1.default,
837
+ buy: buy_1.default,
838
+ redeem: redeem_1.redeem,
839
+ redeemAll: redeem_1.redeemAll,
840
+ setAuction: setAuction_1.default,
841
+ sweepSurplus: sweepSurplus_1.default,
842
+ pause: pause_2.pause,
843
+ unpause: pause_2.unpause,
844
+ grantRole: grantRole_1.grantRole,
845
+ revokeRole: grantRole_1.revokeRole,
846
+ priceAt: priceAt_1.priceAt,
847
+ quoteBuy: quoteBuy_1.quoteBuy,
823
848
  };
824
849
  this.prices = {
825
850
  getPrices: getPrices_1.getPrices,
@@ -22,12 +22,12 @@
22
22
  "auctionfactory": {
23
23
  "id": "auctionfactory",
24
24
  "name": "Auction Factory",
25
- "contract": "0xC644A84734A7329eE46d3B6704746179d272f990"
25
+ "contract": "0xeb4b30b853BCf687c91C3a20f3ad0816EEf002BD"
26
26
  },
27
27
  "zenofactory": {
28
28
  "id": "zenofactory",
29
29
  "name": "Zeno Factory",
30
- "contract": "0xa9eE59A113bCB4B2CC10f802D1efF0Bae1Ab91D2"
30
+ "contract": "0x55F6F6801Bda0AD55753B4B89a525F1E36fC8333"
31
31
  },
32
32
  "raacminter": {
33
33
  "id": "raacminter",
@@ -22,12 +22,12 @@
22
22
  "auctionfactory": {
23
23
  "id": "auctionfactory",
24
24
  "name": "Auction Factory",
25
- "contract": "0xC644A84734A7329eE46d3B6704746179d272f990"
25
+ "contract": "0x98eDDadCfde04dC22a0e62119617e74a6Bc77313"
26
26
  },
27
27
  "zenofactory": {
28
28
  "id": "zenofactory",
29
29
  "name": "Zeno Factory",
30
- "contract": "0xa9eE59A113bCB4B2CC10f802D1efF0Bae1Ab91D2"
30
+ "contract": "0x95bD8D42f30351685e96C62EDdc0d0613bf9a87A"
31
31
  },
32
32
  "raacminter": {
33
33
  "id": "raacminter",
@@ -299,6 +299,27 @@
299
299
  "symbol": "leRAAC",
300
300
  "decimals": 18,
301
301
  "contract": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
302
+ },
303
+ "zenocrvusd": {
304
+ "id": "zenocrvusd",
305
+ "name": "crvUSD (bond seed mock)",
306
+ "symbol": "crvUSD",
307
+ "decimals": 18,
308
+ "contract": "0x2B574555158337Cd46d47c2Ca57E4698A1f04e70"
309
+ },
310
+ "zenousdc": {
311
+ "id": "zenousdc",
312
+ "name": "USDC (bond seed mock)",
313
+ "symbol": "USDC",
314
+ "decimals": 6,
315
+ "contract": "0xcA8b49076D1A8039599e24979abf819af784c27a"
316
+ },
317
+ "zenousdt": {
318
+ "id": "zenousdt",
319
+ "name": "USDT (bond seed mock)",
320
+ "symbol": "USDT",
321
+ "decimals": 6,
322
+ "contract": "0xc039b3B46814D8388e5205D37Dd0D154D806F1f4"
302
323
  }
303
324
  },
304
325
  "lockers": {
@@ -0,0 +1,43 @@
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.ERC20_ABI = void 0;
7
+ exports.getZenoContract = getZenoContract;
8
+ exports.getAuctionContract = getAuctionContract;
9
+ exports.toZenoAmount = toZenoAmount;
10
+ exports.addressOrNull = addressOrNull;
11
+ const ethers_1 = require("ethers");
12
+ const chains_1 = __importDefault(require("../../configs/chains"));
13
+ const artifacts_1 = require("../../utils/artifacts");
14
+ const amount_1 = require("../../utils/amount");
15
+ /** The one ERC20 call the zeno methods make: the underlying held by a ZENO. */
16
+ exports.ERC20_ABI = ["function balanceOf(address) view returns (uint256)"];
17
+ /** A ZENO bond. Bonds are created by the factory, so the address is passed in rather than read from the config. */
18
+ function getZenoContract(chainId, zeno, runner) {
19
+ if (!runner) {
20
+ const rpc = chains_1.default[chainId].rpcs[0];
21
+ runner = new ethers_1.ethers.JsonRpcProvider(rpc);
22
+ }
23
+ return new ethers_1.ethers.Contract(zeno, (0, artifacts_1.getABI)("zeno"), runner);
24
+ }
25
+ /** A ZENO auction. Auctions are created by the factory, so the address is passed in rather than read from the config. */
26
+ function getAuctionContract(chainId, auction, runner) {
27
+ if (!runner) {
28
+ const rpc = chains_1.default[chainId].rpcs[0];
29
+ runner = new ethers_1.ethers.JsonRpcProvider(rpc);
30
+ }
31
+ return new ethers_1.ethers.Contract(auction, (0, artifacts_1.getABI)("auction"), runner);
32
+ }
33
+ /**
34
+ * A ZENO amount. ZENO takes its decimals from its underlying, so they come from the underlying's registry entry; a
35
+ * ZENO address itself is never in the registry. Falls back to 18 decimals when the underlying is not listed.
36
+ */
37
+ function toZenoAmount(chainId, underlying, value, symbol) {
38
+ return (0, amount_1.toAmount)(value, (0, amount_1.getTokenInfo)(chainId, underlying)?.decimals ?? amount_1.WAD_DECIMALS, symbol);
39
+ }
40
+ /** `ZENO.auction()` and other unset address fields read as the zero address; this maps that to null. */
41
+ function addressOrNull(address) {
42
+ return address === ethers_1.ethers.ZeroAddress ? null : address;
43
+ }
@@ -0,0 +1,27 @@
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
+ * Buys ZENO: spends exactly `paymentAmount` of the payment token, sent to the issuer, at the price of the block it is
7
+ * mined in. Needs a payment token allowance for the auction (`wallet.assets.approveAsset`). Reverts while paused,
8
+ * outside the auction window, when the ZENO out would exceed what is left, or when it is below `minZenoOut`.
9
+ * @param chainId The chain id.
10
+ * @param auction The auction address.
11
+ * @param paymentAmount Payment token to spend, in base units.
12
+ * @param minZenoOut The least ZENO to accept, in ZENO base units; `quoteBuy` sizes it.
13
+ * @param signer The buyer, who receives the ZENO.
14
+ * @returns The transaction receipt; its `ZENOPurchased` log carries the ZENO minted and the price paid.
15
+ */
16
+ async function buy(chainId, auction, paymentAmount, minZenoOut, signer) {
17
+ if (!signer)
18
+ throw new Error("Signer is required");
19
+ try {
20
+ const tx = await (0, _helpers_1.getAuctionContract)(chainId, auction, signer).buy(paymentAmount, minZenoOut);
21
+ return await tx.wait();
22
+ }
23
+ catch (error) {
24
+ throw (0, rpcError_1.toRpcError)("zeno.buy", error, { chainId, address: auction });
25
+ }
26
+ }
27
+ exports.default = buy;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const amount_1 = require("../../utils/amount");
4
+ const rpcError_1 = require("../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Reads one auction's terms and live state.
8
+ * @param chainId The chain id.
9
+ * @param auction The auction address.
10
+ * @param provider The provider to read with. Defaults to the chain's first configured RPC.
11
+ * @returns The auction's state.
12
+ */
13
+ async function getAuctionState(chainId, auction, provider) {
14
+ try {
15
+ const contract = (0, _helpers_1.getAuctionContract)(chainId, auction, provider);
16
+ const [details, paymentToken, paused, ended] = await Promise.all([
17
+ contract.getDetails(),
18
+ contract.token(),
19
+ contract.paused(),
20
+ contract.checkAuctionEnded(),
21
+ ]);
22
+ const underlying = await (0, _helpers_1.getZenoContract)(chainId, details.zenoAddress, contract.runner).underlyingAsset();
23
+ return {
24
+ auction: details.auctionAddress,
25
+ zeno: details.zenoAddress,
26
+ paymentToken,
27
+ issuer: details.issuer,
28
+ fundingMode: Number(details.fundingMode),
29
+ startTime: details.auctionStartTime,
30
+ endTime: details.auctionEndTime,
31
+ startingPrice: (0, amount_1.toTokenAmount)(chainId, paymentToken, details.startingPrice),
32
+ reservePrice: (0, amount_1.toTokenAmount)(chainId, paymentToken, details.reservePrice),
33
+ isFixedPrice: details.startingPrice === details.reservePrice,
34
+ price: (0, amount_1.toTokenAmount)(chainId, paymentToken, details.price),
35
+ totalAllocated: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalZENOAllocated),
36
+ totalRemaining: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalZENORemaining),
37
+ paused,
38
+ ended,
39
+ };
40
+ }
41
+ catch (error) {
42
+ throw (0, rpcError_1.toRpcError)("zeno.getAuctionState", error, { chainId, address: auction });
43
+ }
44
+ }
45
+ exports.default = getAuctionState;
@@ -9,12 +9,14 @@ const contracts_1 = require("../../utils/contracts");
9
9
  const artifacts_1 = require("../../utils/artifacts");
10
10
  const amount_1 = require("../../utils/amount");
11
11
  const rpcError_1 = require("../../utils/rpcError");
12
+ const _helpers_1 = require("./_helpers");
12
13
  /**
13
14
  * Lists every auction created by the AuctionFactory.
14
15
  * @param chainId The chain id.
15
16
  * @param provider The provider to read with. Defaults to the chain's first configured RPC.
16
- * @returns One record per auction. Price amounts use the auction's payment token, ZENO amounts the ZENO
17
- * token; decimals and symbols come from the chain config registry and fall back to 18 when the token is not listed.
17
+ * @returns One record per auction. Price amounts use the auction's payment token, ZENO amounts the ZENO's underlying,
18
+ * whose decimals ZENO shares; decimals and symbols come from the chain config registry and fall back to 18 when the
19
+ * token is not listed.
18
20
  */
19
21
  async function getAuctions(chainId, provider) {
20
22
  if (!provider) {
@@ -30,6 +32,7 @@ async function getAuctions(chainId, provider) {
30
32
  auctionContract.getDetails(),
31
33
  auctionContract.token(),
32
34
  ]);
35
+ const underlying = await (0, _helpers_1.getZenoContract)(chainId, details.zenoAddress, provider).underlyingAsset();
33
36
  return {
34
37
  auctionAddress: details.auctionAddress,
35
38
  zenoAddress: details.zenoAddress,
@@ -40,8 +43,8 @@ async function getAuctions(chainId, provider) {
40
43
  startingPrice: (0, amount_1.toTokenAmount)(chainId, tokenAddress, details.startingPrice),
41
44
  reservePrice: (0, amount_1.toTokenAmount)(chainId, tokenAddress, details.reservePrice),
42
45
  price: (0, amount_1.toTokenAmount)(chainId, tokenAddress, details.price),
43
- totalZENOAllocated: (0, amount_1.toTokenAmount)(chainId, details.zenoAddress, details.totalZENOAllocated),
44
- totalZENORemaining: (0, amount_1.toTokenAmount)(chainId, details.zenoAddress, details.totalZENORemaining),
46
+ totalZENOAllocated: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalZENOAllocated),
47
+ totalZENORemaining: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalZENORemaining),
45
48
  fundingMode: Number(details.fundingMode),
46
49
  };
47
50
  }));
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ethers_1 = require("ethers");
4
+ const amount_1 = require("../../utils/amount");
5
+ const rpcError_1 = require("../../utils/rpcError");
6
+ const _helpers_1 = require("./_helpers");
7
+ /**
8
+ * Reads a ZENO bond's live state: supply, collateral and whether it can be redeemed. Collateral is read here rather
9
+ * than indexed, because top-ups are plain transfers on the underlying that no ZENO event records.
10
+ * @param chainId The chain id.
11
+ * @param zeno The ZENO bond address.
12
+ * @param provider The provider to read with. Defaults to the chain's first configured RPC.
13
+ * @returns The bond's state.
14
+ */
15
+ async function getBondState(chainId, zeno, provider) {
16
+ try {
17
+ const contract = (0, _helpers_1.getZenoContract)(chainId, zeno, provider);
18
+ const [details, underlying, auction, totalSupply, sweepableSurplus, isRedeemable] = await Promise.all([
19
+ contract.getDetails(),
20
+ contract.underlyingAsset(),
21
+ contract.auction(),
22
+ contract.totalSupply(),
23
+ contract.sweepableSurplus(),
24
+ contract.isRedeemable(),
25
+ ]);
26
+ const collateral = await new ethers_1.ethers.Contract(underlying, _helpers_1.ERC20_ABI, contract.runner).balanceOf(zeno);
27
+ return {
28
+ zeno: details.zenoAddress,
29
+ name: details.name,
30
+ symbol: details.symbol,
31
+ underlying,
32
+ auction: (0, _helpers_1.addressOrNull)(auction),
33
+ maturityDate: details.maturityDate,
34
+ isRedeemable,
35
+ totalMinted: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalMinted, details.symbol),
36
+ totalSupply: (0, _helpers_1.toZenoAmount)(chainId, underlying, totalSupply, details.symbol),
37
+ totalRedeemed: (0, _helpers_1.toZenoAmount)(chainId, underlying, details.totalRedeemed, details.symbol),
38
+ collateral: (0, amount_1.toTokenAmount)(chainId, underlying, collateral),
39
+ sweepableSurplus: (0, amount_1.toTokenAmount)(chainId, underlying, sweepableSurplus),
40
+ isFunded: collateral >= totalSupply,
41
+ };
42
+ }
43
+ catch (error) {
44
+ throw (0, rpcError_1.toRpcError)("zeno.getBondState", error, { chainId, address: zeno });
45
+ }
46
+ }
47
+ exports.default = getBondState;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const amount_1 = require("../../utils/amount");
4
+ const rpcError_1 = require("../../utils/rpcError");
5
+ const _helpers_1 = require("./_helpers");
6
+ /**
7
+ * Reads an auction's current price. Read it right before `buy` to size `minZenoOut`: a Dutch price falls every block.
8
+ * @param chainId The chain id.
9
+ * @param auction The auction address.
10
+ * @param provider The provider to read with. Defaults to the chain's first configured RPC.
11
+ * @returns The price in payment token base units per whole ZENO.
12
+ */
13
+ async function getPrice(chainId, auction, provider) {
14
+ try {
15
+ const contract = (0, _helpers_1.getAuctionContract)(chainId, auction, provider);
16
+ const [price, paymentToken] = await Promise.all([contract.getPrice(), contract.token()]);
17
+ return (0, amount_1.toTokenAmount)(chainId, paymentToken, price);
18
+ }
19
+ catch (error) {
20
+ throw (0, rpcError_1.toRpcError)("zeno.getPrice", error, { chainId, address: auction });
21
+ }
22
+ }
23
+ exports.default = getPrice;
@@ -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;
@@ -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";
@@ -696,6 +707,20 @@ declare class RPCLibrary {
696
707
  getAuctions: typeof getAuctions;
697
708
  createZeno: typeof createZeno;
698
709
  getZenos: typeof getZenos;
710
+ getAuctionState: typeof getAuctionState;
711
+ getBondState: typeof getBondState;
712
+ getPrice: typeof getAuctionPrice;
713
+ buy: typeof buyZeno;
714
+ redeem: typeof redeemZeno;
715
+ redeemAll: typeof redeemAllZeno;
716
+ setAuction: typeof setAuction;
717
+ sweepSurplus: typeof sweepSurplus;
718
+ pause: typeof pauseAuction;
719
+ unpause: typeof unpauseAuction;
720
+ grantRole: typeof grantRoleAuction;
721
+ revokeRole: typeof revokeRoleAuction;
722
+ priceAt: typeof priceAt;
723
+ quoteBuy: typeof quoteBuy;
699
724
  };
700
725
  provider: any;
701
726
  estimateGasPrice: any;
@@ -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>;
@@ -0,0 +1,18 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Halts `buy` on an auction. PAUSER_ROLE only. A Dutch price keeps falling while paused.
5
+ * @param chainId The chain id.
6
+ * @param auction The auction address.
7
+ * @param signer A PAUSER_ROLE holder.
8
+ * @returns The transaction receipt.
9
+ */
10
+ export declare function pause(chainId: ChainId, auction: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
11
+ /**
12
+ * Resumes `buy` on an auction. DEFAULT_ADMIN_ROLE only, so a compromised pauser cannot reopen buying.
13
+ * @param chainId The chain id.
14
+ * @param auction The auction address.
15
+ * @param signer A DEFAULT_ADMIN_ROLE holder.
16
+ * @returns The transaction receipt.
17
+ */
18
+ export declare function unpause(chainId: ChainId, auction: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
@@ -0,0 +1,20 @@
1
+ /** The auction terms that set its price. All values as the contract stores them. */
2
+ export interface AuctionPriceTerms {
3
+ /** UNIX timestamp (seconds). */
4
+ startTime: bigint;
5
+ /** UNIX timestamp (seconds). */
6
+ endTime: bigint;
7
+ /** Payment token base units per whole ZENO. */
8
+ startingPrice: bigint;
9
+ /** Payment token base units per whole ZENO. */
10
+ reservePrice: bigint;
11
+ }
12
+ /**
13
+ * An auction's price at `now`, computed locally without an RPC call. Mirrors `Auction.getPrice()` exactly, truncating
14
+ * division included: the starting price before the window, the reserve from `endTime` on, a linear fall between.
15
+ *
16
+ * @param terms The auction's price terms, e.g. from `getAuctionState` or the subgraph's `BondAuction`.
17
+ * @param now UNIX timestamp (seconds). Use the latest block timestamp to match the contract exactly.
18
+ * @returns The price in payment token base units per whole ZENO.
19
+ */
20
+ export declare const priceAt: (terms: AuctionPriceTerms, now: bigint) => bigint;
@@ -0,0 +1,34 @@
1
+ export interface BuyQuoteInput {
2
+ /** Price in payment token base units per whole ZENO, from `priceAt` or `getPrice`. */
3
+ price: bigint;
4
+ /** Payment token to spend, in base units. */
5
+ paymentAmount: bigint;
6
+ /** ZENO decimals, equal to the underlying's. */
7
+ zenoDecimals: number;
8
+ /** ZENO left to sell, in base units (`totalRemaining`). */
9
+ totalRemaining: bigint;
10
+ /** Tolerance below `zenoOut` for `minZenoOut`, in basis points (10000 = 100%). Defaults to 0. */
11
+ slippageBps?: bigint;
12
+ }
13
+ export interface BuyQuote {
14
+ /** ZENO minted for `paymentAmount` at `price`, in base units. */
15
+ zenoOut: bigint;
16
+ /** `zenoOut` less the slippage tolerance; pass it to `buy` as `minZenoOut`. */
17
+ minZenoOut: bigint;
18
+ /** The largest payment `buy` accepts at `price`; anything above mints more than `totalRemaining` and reverts. */
19
+ maxPayment: bigint;
20
+ /** True when `paymentAmount` is above `maxPayment`. */
21
+ exceedsRemaining: boolean;
22
+ }
23
+ /**
24
+ * What a buy mints, computed locally without an RPC call with `Auction.buy`'s integer maths:
25
+ * `zenoOut = paymentAmount * 10^zenoDecimals / price`, truncated.
26
+ *
27
+ * A Dutch price only falls, so a buy mined after the quote mints at least `zenoOut`; `minZenoOut` guards against a
28
+ * fixed price or a stale quote. The same fall means a payment at exactly `maxPayment` can revert a block later, so
29
+ * leave headroom when buying out the remainder.
30
+ *
31
+ * @param input The price, payment, ZENO decimals, remaining supply and slippage tolerance.
32
+ * @returns The ZENO out, the `minZenoOut` to send, and the payment ceiling.
33
+ */
34
+ export declare const quoteBuy: (input: BuyQuoteInput) => BuyQuote;
@@ -0,0 +1,20 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Redeems ZENO 1:1 for the underlying. Reverts before maturity, and while the bond's collateral is short of its
5
+ * outstanding supply (`getBondState(...).isFunded`).
6
+ * @param chainId The chain id.
7
+ * @param zeno The ZENO bond address.
8
+ * @param amount ZENO to redeem, in base units.
9
+ * @param signer The holder, who receives the underlying.
10
+ * @returns The transaction receipt.
11
+ */
12
+ export declare function redeem(chainId: ChainId, zeno: string, amount: bigint, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
13
+ /**
14
+ * Redeems the signer's whole ZENO balance for the underlying. Same conditions as `redeem`.
15
+ * @param chainId The chain id.
16
+ * @param zeno The ZENO bond address.
17
+ * @param signer The holder, who receives the underlying.
18
+ * @returns The transaction receipt.
19
+ */
20
+ export declare function redeemAll(chainId: ChainId, zeno: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
@@ -0,0 +1,13 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Binds a ZENO to the auction that sells it. One-shot, ZENO owner only; reverts unless the auction's `zeno()` points
5
+ * back at this ZENO. Until it is set, the auction's buys revert.
6
+ * @param chainId The chain id.
7
+ * @param zeno The ZENO bond address.
8
+ * @param auction The auction created for it.
9
+ * @param signer The ZENO owner.
10
+ * @returns The transaction receipt.
11
+ */
12
+ declare function setAuction(chainId: ChainId, zeno: string, auction: string, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
13
+ export default setAuction;
@@ -0,0 +1,14 @@
1
+ import { Signer } from "ethers";
2
+ import { ChainId } from "../../configs/chains";
3
+ /**
4
+ * Sweeps underlying held above the ZENO's outstanding supply: unsold prefill, overpayments and post-maturity residue.
5
+ * ZENO owner only, and only once the bound auction has ended. `getBondState(...).sweepableSurplus` is the most it takes.
6
+ * @param chainId The chain id.
7
+ * @param zeno The ZENO bond address.
8
+ * @param to The recipient of the underlying.
9
+ * @param amount Underlying to sweep, in base units.
10
+ * @param signer The ZENO owner.
11
+ * @returns The transaction receipt.
12
+ */
13
+ declare function sweepSurplus(chainId: ChainId, zeno: string, to: string, amount: bigint, signer: Signer): Promise<import("ethers").ContractTransactionReceipt>;
14
+ export default sweepSurplus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raac/rpc",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.6",
4
4
  "description": "RPC Library for RAAC",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",