@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.
- package/dist/RPCLibrary.js +46 -8
- package/dist/configs/chains/11155111.json +32 -2
- package/dist/configs/chains/8453.json +23 -2
- 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/zeno/_helpers.js +43 -0
- package/dist/contracts/zeno/buy.js +27 -0
- package/dist/contracts/zeno/getAuctionState.js +45 -0
- package/dist/contracts/zeno/getAuctions.js +7 -4
- package/dist/contracts/zeno/getBondState.js +47 -0
- package/dist/contracts/zeno/getPrice.js +23 -0
- package/dist/contracts/zeno/getZenos.js +6 -6
- package/dist/contracts/zeno/grantRole.js +46 -0
- package/dist/contracts/zeno/pause.js +42 -0
- package/dist/contracts/zeno/priceAt.js +20 -0
- package/dist/contracts/zeno/quoteBuy.js +33 -0
- package/dist/contracts/zeno/redeem.js +44 -0
- package/dist/contracts/zeno/setAuction.js +25 -0
- package/dist/contracts/zeno/sweepSurplus.js +26 -0
- package/dist/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.js +4 -4
- package/dist/types/RPCLibrary.d.ts +33 -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/zeno/_helpers.d.ts +17 -0
- package/dist/types/contracts/zeno/buy.d.ts +15 -0
- package/dist/types/contracts/zeno/getAuctionState.d.ts +45 -0
- package/dist/types/contracts/zeno/getAuctions.d.ts +3 -2
- package/dist/types/contracts/zeno/getBondState.d.ts +42 -0
- package/dist/types/contracts/zeno/getPrice.d.ts +12 -0
- package/dist/types/contracts/zeno/getZenos.d.ts +2 -2
- package/dist/types/contracts/zeno/grantRole.d.ts +22 -0
- package/dist/types/contracts/zeno/pause.d.ts +18 -0
- package/dist/types/contracts/zeno/priceAt.d.ts +20 -0
- package/dist/types/contracts/zeno/quoteBuy.d.ts +34 -0
- package/dist/types/contracts/zeno/redeem.d.ts +20 -0
- package/dist/types/contracts/zeno/setAuction.d.ts +13 -0
- package/dist/types/contracts/zeno/sweepSurplus.d.ts +14 -0
- package/dist/types/pools/lendingPool/adapters/erc20/getERC20AdapterBalance.d.ts +3 -3
- 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/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/contracts.js +5 -2
- package/package.json +1 -1
package/dist/RPCLibrary.js
CHANGED
|
@@ -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
|
|
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");
|
|
@@ -193,6 +204,10 @@ const distributorMethods = __importStar(require("./contracts/governance/distribu
|
|
|
193
204
|
const gaugeMethods = __importStar(require("./contracts/governance/gauge"));
|
|
194
205
|
const controllerMethods = __importStar(require("./contracts/governance/gaugeController"));
|
|
195
206
|
const gaugeSystemMethods = __importStar(require("./contracts/governance/gaugeSystems"));
|
|
207
|
+
// ===== Curve =====
|
|
208
|
+
const curveCommonMethods = __importStar(require("./contracts/curve/common"));
|
|
209
|
+
// ===== User aggregates (dashboard) =====
|
|
210
|
+
const userMethods = __importStar(require("./user"));
|
|
196
211
|
// Proposals
|
|
197
212
|
const cancel_1 = require("./contracts/governance/proposals/cancel");
|
|
198
213
|
const getQuorumNumerator_1 = require("./contracts/governance/proposals/getQuorumNumerator");
|
|
@@ -328,10 +343,10 @@ const getConfig_3 = require("./contracts/lockers/botLocker/getConfig");
|
|
|
328
343
|
const getUnlockWindow_1 = require("./contracts/lockers/botLocker/getUnlockWindow");
|
|
329
344
|
const getRoles_3 = require("./contracts/lockers/botLocker/getRoles");
|
|
330
345
|
const hasRole_3 = require("./contracts/lockers/botLocker/hasRole");
|
|
331
|
-
const
|
|
346
|
+
const grantRole_2 = require("./contracts/lockers/botLocker/grantRole");
|
|
332
347
|
const addRewardTokens_1 = require("./contracts/lockers/botLocker/addRewardTokens");
|
|
333
348
|
const distributeRewardToken_1 = require("./contracts/lockers/botLocker/distributeRewardToken");
|
|
334
|
-
const
|
|
349
|
+
const pause_3 = require("./contracts/lockers/botLocker/pause");
|
|
335
350
|
const rescueTokens_1 = require("./contracts/lockers/botLocker/rescueTokens");
|
|
336
351
|
// leRAAC token
|
|
337
352
|
const getBalance_8 = require("./contracts/tokens/leRAAC/getBalance");
|
|
@@ -389,6 +404,10 @@ class RPCLibrary {
|
|
|
389
404
|
chainId;
|
|
390
405
|
privateKey;
|
|
391
406
|
// prices
|
|
407
|
+
// Curve pools from the chain config's `curve` section
|
|
408
|
+
curve;
|
|
409
|
+
// Aggregate reads of one user's position and claimables, composed from the methods above
|
|
410
|
+
user;
|
|
392
411
|
prices;
|
|
393
412
|
// valid
|
|
394
413
|
assets;
|
|
@@ -644,12 +663,12 @@ class RPCLibrary {
|
|
|
644
663
|
getUnlockWindow: getUnlockWindow_1.getUnlockWindow,
|
|
645
664
|
getRoles: getRoles_3.getRoles,
|
|
646
665
|
hasRole: hasRole_3.hasRole,
|
|
647
|
-
grantRole:
|
|
648
|
-
revokeRole:
|
|
666
|
+
grantRole: grantRole_2.grantRole,
|
|
667
|
+
revokeRole: grantRole_2.revokeRole,
|
|
649
668
|
addRewardTokens: addRewardTokens_1.addRewardTokens,
|
|
650
669
|
distributeRewardToken: distributeRewardToken_1.distributeRewardToken,
|
|
651
|
-
pause:
|
|
652
|
-
unpause:
|
|
670
|
+
pause: pause_3.pause,
|
|
671
|
+
unpause: pause_3.unpause,
|
|
653
672
|
rescueTokens: rescueTokens_1.rescueTokens,
|
|
654
673
|
},
|
|
655
674
|
};
|
|
@@ -732,7 +751,7 @@ class RPCLibrary {
|
|
|
732
751
|
deposit: deposit_1.deposit,
|
|
733
752
|
requestExit: requestExit_1.requestExit,
|
|
734
753
|
cancelExit: cancelExit_1.cancelExit,
|
|
735
|
-
redeem:
|
|
754
|
+
redeem: redeem_2.redeem,
|
|
736
755
|
swap: swap_1.swap,
|
|
737
756
|
};
|
|
738
757
|
this.pools = {
|
|
@@ -820,7 +839,25 @@ class RPCLibrary {
|
|
|
820
839
|
getAuctions: getAuctions_1.default,
|
|
821
840
|
createZeno: createZeno_1.default,
|
|
822
841
|
getZenos: getZenos_1.default,
|
|
842
|
+
getAuctionState: getAuctionState_1.default,
|
|
843
|
+
getBondState: getBondState_1.default,
|
|
844
|
+
getPrice: getPrice_1.default,
|
|
845
|
+
buy: buy_1.default,
|
|
846
|
+
redeem: redeem_1.redeem,
|
|
847
|
+
redeemAll: redeem_1.redeemAll,
|
|
848
|
+
setAuction: setAuction_1.default,
|
|
849
|
+
sweepSurplus: sweepSurplus_1.default,
|
|
850
|
+
pause: pause_2.pause,
|
|
851
|
+
unpause: pause_2.unpause,
|
|
852
|
+
grantRole: grantRole_1.grantRole,
|
|
853
|
+
revokeRole: grantRole_1.revokeRole,
|
|
854
|
+
priceAt: priceAt_1.priceAt,
|
|
855
|
+
quoteBuy: quoteBuy_1.quoteBuy,
|
|
856
|
+
};
|
|
857
|
+
this.curve = {
|
|
858
|
+
common: curveCommonMethods,
|
|
823
859
|
};
|
|
860
|
+
this.user = userMethods;
|
|
824
861
|
this.prices = {
|
|
825
862
|
getPrices: getPrices_1.getPrices,
|
|
826
863
|
getTokenPriceUSD: tokenPricesUSD_1.getTokenPriceUSD,
|
|
@@ -834,6 +871,7 @@ class RPCLibrary {
|
|
|
834
871
|
toScaled: amount_1.toScaled,
|
|
835
872
|
parseAmount: amount_1.parseAmount,
|
|
836
873
|
toDecimalString: amount_1.toDecimalString,
|
|
874
|
+
toNumber: amount_1.toNumber,
|
|
837
875
|
serializeAmount: amount_1.serializeAmount,
|
|
838
876
|
deserializeAmount: amount_1.deserializeAmount,
|
|
839
877
|
getAssetDecimals: amount_1.getAssetDecimals,
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"auctionfactory": {
|
|
23
23
|
"id": "auctionfactory",
|
|
24
24
|
"name": "Auction Factory",
|
|
25
|
-
"contract": "
|
|
25
|
+
"contract": "0xeb4b30b853BCf687c91C3a20f3ad0816EEf002BD"
|
|
26
26
|
},
|
|
27
27
|
"zenofactory": {
|
|
28
28
|
"id": "zenofactory",
|
|
29
29
|
"name": "Zeno Factory",
|
|
30
|
-
"contract": "
|
|
30
|
+
"contract": "0x55F6F6801Bda0AD55753B4B89a525F1E36fC8333"
|
|
31
31
|
},
|
|
32
32
|
"raacminter": {
|
|
33
33
|
"id": "raacminter",
|
|
@@ -179,6 +179,36 @@
|
|
|
179
179
|
"contract": "0x7F7d0924C9082F4C3F0D5D97bF9a26C3D3DEf706"
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
|
+
"curve": {
|
|
183
|
+
"raac-pmusd": {
|
|
184
|
+
"id": "raac-pmusd",
|
|
185
|
+
"name": "RAAC / pmUSD",
|
|
186
|
+
"contract": "0xF65C691aE1782A9A504d6865F0dAeC88Ef46a592",
|
|
187
|
+
"flavour": "twocrypto",
|
|
188
|
+
"coins": ["pmusd", "raactoken"]
|
|
189
|
+
},
|
|
190
|
+
"ireet-pmusd": {
|
|
191
|
+
"id": "ireet-pmusd",
|
|
192
|
+
"name": "iREET / pmUSD",
|
|
193
|
+
"contract": "0x7F7d0924C9082F4C3F0D5D97bF9a26C3D3DEf706",
|
|
194
|
+
"flavour": "twocrypto",
|
|
195
|
+
"coins": ["pmusd", "rwaindextoken"]
|
|
196
|
+
},
|
|
197
|
+
"rpmusd-depmusd": {
|
|
198
|
+
"id": "rpmusd-depmusd",
|
|
199
|
+
"name": "RpmUSD / DEpmUSD",
|
|
200
|
+
"contract": "0x421E9431E751c8fC02E53F8e54a1772aE6021BeD",
|
|
201
|
+
"flavour": "stableswap",
|
|
202
|
+
"coins": ["rtoken", "detoken"]
|
|
203
|
+
},
|
|
204
|
+
"leraac-raac-pmusd": {
|
|
205
|
+
"id": "leraac-raac-pmusd",
|
|
206
|
+
"name": "leRAAC / RAAC / pmUSD",
|
|
207
|
+
"contract": "0x1D0805Bd3EF5338b66158770c28fD6f4Cd685F28",
|
|
208
|
+
"flavour": "tricrypto",
|
|
209
|
+
"coins": ["pmusd", "raactoken", "leraac"]
|
|
210
|
+
}
|
|
211
|
+
},
|
|
182
212
|
"nfts": {
|
|
183
213
|
"raacnft": {
|
|
184
214
|
"id": "raacnft",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"auctionfactory": {
|
|
23
23
|
"id": "auctionfactory",
|
|
24
24
|
"name": "Auction Factory",
|
|
25
|
-
"contract": "
|
|
25
|
+
"contract": "0x98eDDadCfde04dC22a0e62119617e74a6Bc77313"
|
|
26
26
|
},
|
|
27
27
|
"zenofactory": {
|
|
28
28
|
"id": "zenofactory",
|
|
29
29
|
"name": "Zeno Factory",
|
|
30
|
-
"contract": "
|
|
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,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,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
|
-
*
|
|
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,
|
|
44
|
-
totalZENORemaining: (0,
|
|
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;
|