@mento-protocol/mento-sdk 3.2.7 → 3.3.0-beta.0
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/cache/routes.d.ts +13 -0
- package/dist/cache/routes.js +14588 -0
- package/dist/cache/tokens.d.ts +68 -0
- package/dist/cache/tokens.js +514 -0
- package/dist/core/abis/activePool.d.ts +2 -0
- package/dist/core/abis/activePool.js +14 -0
- package/dist/core/abis/addressesRegistry.d.ts +2 -0
- package/dist/core/abis/addressesRegistry.js +26 -0
- package/dist/core/abis/bipoolmanager.d.ts +34 -0
- package/dist/core/abis/bipoolmanager.js +72 -0
- package/dist/core/abis/borrowerOperations.d.ts +9 -0
- package/dist/core/abis/borrowerOperations.js +89 -0
- package/dist/core/abis/breakerbox.d.ts +13 -0
- package/dist/core/abis/breakerbox.js +8 -0
- package/dist/core/abis/broker.d.ts +2 -0
- package/dist/core/abis/broker.js +9 -0
- package/dist/core/abis/erc20.d.ts +9 -0
- package/dist/core/abis/erc20.js +21 -0
- package/dist/core/abis/fpmm.d.ts +270 -0
- package/dist/core/abis/fpmm.js +49 -0
- package/dist/core/abis/fpmmFactory.d.ts +85 -0
- package/dist/core/abis/fpmmFactory.js +26 -0
- package/dist/core/abis/hintHelpers.d.ts +2 -0
- package/dist/core/abis/hintHelpers.js +14 -0
- package/dist/core/abis/index.d.ts +22 -0
- package/dist/core/abis/index.js +38 -0
- package/dist/core/abis/liquidityStrategy.d.ts +132 -0
- package/dist/core/abis/liquidityStrategy.js +10 -0
- package/dist/core/abis/multiTroveGetter.d.ts +8 -0
- package/dist/core/abis/multiTroveGetter.js +15 -0
- package/dist/core/abis/priceFeed.d.ts +7 -0
- package/dist/core/abis/priceFeed.js +16 -0
- package/dist/core/abis/pricingmodule.d.ts +2 -0
- package/dist/core/abis/pricingmodule.js +6 -0
- package/dist/core/abis/reserve.d.ts +3 -0
- package/dist/core/abis/reserve.js +18 -0
- package/dist/core/abis/router.d.ts +521 -0
- package/dist/core/abis/router.js +45 -0
- package/dist/core/abis/sortedTroves.d.ts +2 -0
- package/dist/core/abis/sortedTroves.js +15 -0
- package/dist/core/abis/systemParams.d.ts +2 -0
- package/dist/core/abis/systemParams.js +14 -0
- package/dist/core/abis/troveManager.d.ts +2 -0
- package/dist/core/abis/troveManager.js +27 -0
- package/dist/core/abis/troveNFT.d.ts +2 -0
- package/dist/core/abis/troveNFT.js +9 -0
- package/dist/core/abis/virtualPool.d.ts +50 -0
- package/dist/core/abis/virtualPool.js +11 -0
- package/dist/core/abis/virtualPoolFactory.d.ts +59 -0
- package/dist/core/abis/virtualPoolFactory.js +17 -0
- package/dist/core/constants/addresses.d.ts +18 -0
- package/dist/core/constants/addresses.js +125 -0
- package/dist/core/constants/borrowConstants.d.ts +10 -0
- package/dist/core/constants/borrowConstants.js +16 -0
- package/dist/core/constants/borrowRegistries.d.ts +7 -0
- package/dist/core/constants/borrowRegistries.js +34 -0
- package/dist/core/constants/chainId.d.ts +8 -0
- package/dist/core/constants/chainId.js +12 -0
- package/dist/core/constants/contractNames.d.ts +21 -0
- package/dist/core/constants/contractNames.js +24 -0
- package/dist/core/constants/index.d.ts +6 -0
- package/dist/core/constants/index.js +22 -0
- package/dist/core/errors/base.d.ts +8 -0
- package/dist/core/errors/base.js +17 -0
- package/dist/core/errors/index.d.ts +4 -0
- package/dist/core/errors/index.js +20 -0
- package/dist/core/errors/oracle.d.ts +9 -0
- package/dist/core/errors/oracle.js +15 -0
- package/dist/core/errors/router.d.ts +14 -0
- package/dist/core/errors/router.js +24 -0
- package/dist/core/types/borrow.d.ts +87 -0
- package/dist/core/types/borrow.js +3 -0
- package/dist/core/types/contractAddresses.d.ts +42 -0
- package/dist/core/types/contractAddresses.js +3 -0
- package/dist/core/types/index.d.ts +10 -0
- package/dist/core/types/index.js +26 -0
- package/dist/core/types/liquidity.d.ts +194 -0
- package/dist/core/types/liquidity.js +3 -0
- package/dist/core/types/pool.d.ts +208 -0
- package/dist/core/types/pool.js +14 -0
- package/dist/core/types/provider.d.ts +45 -0
- package/dist/core/types/provider.js +3 -0
- package/dist/core/types/route.d.ts +62 -0
- package/dist/core/types/route.js +3 -0
- package/dist/core/types/token.d.ts +21 -0
- package/dist/core/types/token.js +3 -0
- package/dist/core/types/tradingLimits.d.ts +91 -0
- package/dist/core/types/tradingLimits.js +3 -0
- package/dist/core/types/tradingMode.d.ts +24 -0
- package/dist/core/types/tradingMode.js +31 -0
- package/dist/core/types/transaction.d.ts +45 -0
- package/dist/core/types/transaction.js +3 -0
- package/dist/esm/cache/routes.js +14583 -0
- package/dist/esm/cache/tokens.js +506 -0
- package/dist/esm/core/abis/activePool.js +10 -0
- package/dist/esm/core/abis/addressesRegistry.js +22 -0
- package/dist/esm/core/abis/bipoolmanager.js +68 -0
- package/dist/esm/core/abis/borrowerOperations.js +85 -0
- package/dist/esm/core/abis/breakerbox.js +4 -0
- package/dist/esm/core/abis/broker.js +5 -0
- package/dist/esm/core/abis/erc20.js +17 -0
- package/dist/esm/core/abis/fpmm.js +45 -0
- package/dist/esm/core/abis/fpmmFactory.js +22 -0
- package/dist/esm/core/abis/hintHelpers.js +10 -0
- package/dist/esm/core/abis/index.js +21 -0
- package/dist/esm/core/abis/liquidityStrategy.js +6 -0
- package/dist/esm/core/abis/multiTroveGetter.js +11 -0
- package/dist/esm/core/abis/priceFeed.js +12 -0
- package/dist/esm/core/abis/pricingmodule.js +2 -0
- package/dist/esm/core/abis/reserve.js +14 -0
- package/dist/esm/core/abis/router.js +41 -0
- package/dist/esm/core/abis/sortedTroves.js +11 -0
- package/dist/esm/core/abis/systemParams.js +10 -0
- package/dist/esm/core/abis/troveManager.js +23 -0
- package/dist/esm/core/abis/troveNFT.js +5 -0
- package/dist/esm/core/abis/virtualPool.js +7 -0
- package/dist/esm/core/abis/virtualPoolFactory.js +13 -0
- package/dist/esm/core/constants/addresses.js +119 -0
- package/dist/esm/core/constants/borrowConstants.js +12 -0
- package/dist/esm/core/constants/borrowRegistries.js +29 -0
- package/dist/esm/core/constants/chainId.js +8 -0
- package/dist/esm/core/constants/contractNames.js +20 -0
- package/dist/esm/core/constants/index.js +5 -0
- package/dist/esm/core/errors/base.js +12 -0
- package/dist/esm/core/errors/index.js +3 -0
- package/dist/esm/core/errors/oracle.js +10 -0
- package/dist/esm/core/errors/router.js +18 -0
- package/dist/esm/core/types/borrow.js +1 -0
- package/dist/esm/core/types/contractAddresses.js +1 -0
- package/dist/esm/core/types/index.js +9 -0
- package/dist/esm/core/types/liquidity.js +1 -0
- package/dist/esm/core/types/pool.js +10 -0
- package/dist/esm/core/types/provider.js +1 -0
- package/dist/esm/core/types/route.js +1 -0
- package/dist/esm/core/types/token.js +1 -0
- package/dist/esm/core/types/tradingLimits.js +1 -0
- package/dist/esm/core/types/tradingMode.js +26 -0
- package/dist/esm/core/types/transaction.js +1 -0
- package/dist/esm/index.js +139 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/services/borrow/BorrowService.js +455 -0
- package/dist/esm/services/borrow/borrowHelpers.js +3 -0
- package/dist/esm/services/borrow/borrowMath.js +127 -0
- package/dist/esm/services/borrow/index.js +3 -0
- package/dist/esm/services/borrow/internal/borrowApprovalService.js +48 -0
- package/dist/esm/services/borrow/internal/borrowContextStore.js +35 -0
- package/dist/esm/services/borrow/internal/borrowErc20.js +38 -0
- package/dist/esm/services/borrow/internal/borrowHints.js +27 -0
- package/dist/esm/services/borrow/internal/borrowPositionParser.js +82 -0
- package/dist/esm/services/borrow/internal/borrowReadService.js +271 -0
- package/dist/esm/services/borrow/internal/borrowRegistryReader.js +108 -0
- package/dist/esm/services/borrow/internal/borrowTransactionService.js +271 -0
- package/dist/esm/services/borrow/internal/borrowTypes.js +1 -0
- package/dist/esm/services/borrow/internal/borrowValidation.js +89 -0
- package/dist/esm/services/index.js +8 -0
- package/dist/esm/services/liquidity/LiquidityService.js +163 -0
- package/dist/esm/services/liquidity/basicLiquidity.js +162 -0
- package/dist/esm/services/liquidity/index.js +1 -0
- package/dist/esm/services/liquidity/liquidityHelpers.js +95 -0
- package/dist/esm/services/liquidity/rebalance.js +59 -0
- package/dist/esm/services/liquidity/zapHelpers.js +181 -0
- package/dist/esm/services/liquidity/zapIn.js +131 -0
- package/dist/esm/services/liquidity/zapOut.js +248 -0
- package/dist/esm/services/pools/PoolService.js +204 -0
- package/dist/esm/services/pools/index.js +1 -0
- package/dist/esm/services/pools/poolDetails.js +209 -0
- package/dist/esm/services/pools/poolDiscovery.js +112 -0
- package/dist/esm/services/pools/rebalancePreview.js +181 -0
- package/dist/esm/services/quotes/QuoteService.js +85 -0
- package/dist/esm/services/quotes/index.js +1 -0
- package/dist/esm/services/routes/RouteService.js +268 -0
- package/dist/esm/services/routes/index.js +1 -0
- package/dist/esm/services/swap/SwapService.js +247 -0
- package/dist/esm/services/swap/index.js +1 -0
- package/dist/esm/services/tokens/index.js +1 -0
- package/dist/esm/services/tokens/tokenService.js +285 -0
- package/dist/esm/services/trading/TradingLimitsService.js +154 -0
- package/dist/esm/services/trading/TradingService.js +222 -0
- package/dist/esm/services/trading/index.js +2 -0
- package/dist/esm/utils/chainConfig.js +122 -0
- package/dist/esm/utils/costUtils.js +56 -0
- package/dist/esm/utils/deadline.js +22 -0
- package/dist/esm/utils/index.js +9 -0
- package/dist/esm/utils/multicall.js +47 -0
- package/dist/esm/utils/pathEncoder.js +69 -0
- package/dist/esm/utils/rateFeed.js +23 -0
- package/dist/esm/utils/retry.js +24 -0
- package/dist/esm/utils/routeUtils.js +361 -0
- package/dist/esm/utils/routes.js +2 -0
- package/dist/esm/utils/sortUtils.js +33 -0
- package/dist/esm/utils/tokens.js +2 -0
- package/dist/esm/utils/tradingLimits.js +163 -0
- package/dist/esm/utils/validation.js +30 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +158 -0
- package/dist/services/borrow/BorrowService.d.ts +381 -0
- package/dist/services/borrow/BorrowService.js +460 -0
- package/dist/services/borrow/borrowHelpers.d.ts +4 -0
- package/dist/services/borrow/borrowHelpers.js +13 -0
- package/dist/services/borrow/borrowMath.d.ts +21 -0
- package/dist/services/borrow/borrowMath.js +137 -0
- package/dist/services/borrow/index.d.ts +4 -0
- package/dist/services/borrow/index.js +20 -0
- package/dist/services/borrow/internal/borrowApprovalService.d.ts +14 -0
- package/dist/services/borrow/internal/borrowApprovalService.js +53 -0
- package/dist/services/borrow/internal/borrowContextStore.d.ts +11 -0
- package/dist/services/borrow/internal/borrowContextStore.js +40 -0
- package/dist/services/borrow/internal/borrowErc20.d.ts +5 -0
- package/dist/services/borrow/internal/borrowErc20.js +43 -0
- package/dist/services/borrow/internal/borrowHints.d.ts +7 -0
- package/dist/services/borrow/internal/borrowHints.js +31 -0
- package/dist/services/borrow/internal/borrowPositionParser.d.ts +4 -0
- package/dist/services/borrow/internal/borrowPositionParser.js +87 -0
- package/dist/services/borrow/internal/borrowReadService.d.ts +31 -0
- package/dist/services/borrow/internal/borrowReadService.js +276 -0
- package/dist/services/borrow/internal/borrowRegistryReader.d.ts +5 -0
- package/dist/services/borrow/internal/borrowRegistryReader.js +113 -0
- package/dist/services/borrow/internal/borrowTransactionService.d.ts +23 -0
- package/dist/services/borrow/internal/borrowTransactionService.js +276 -0
- package/dist/services/borrow/internal/borrowTypes.d.ts +15 -0
- package/dist/services/borrow/internal/borrowTypes.js +3 -0
- package/dist/services/borrow/internal/borrowValidation.d.ts +14 -0
- package/dist/services/borrow/internal/borrowValidation.js +104 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.js +25 -0
- package/dist/services/liquidity/LiquidityService.d.ts +139 -0
- package/dist/services/liquidity/LiquidityService.js +168 -0
- package/dist/services/liquidity/basicLiquidity.d.ts +11 -0
- package/dist/services/liquidity/basicLiquidity.js +172 -0
- package/dist/services/liquidity/index.d.ts +2 -0
- package/dist/services/liquidity/index.js +18 -0
- package/dist/services/liquidity/liquidityHelpers.d.ts +19 -0
- package/dist/services/liquidity/liquidityHelpers.js +104 -0
- package/dist/services/liquidity/rebalance.d.ts +6 -0
- package/dist/services/liquidity/rebalance.js +64 -0
- package/dist/services/liquidity/zapHelpers.d.ts +100 -0
- package/dist/services/liquidity/zapHelpers.js +192 -0
- package/dist/services/liquidity/zapIn.d.ts +18 -0
- package/dist/services/liquidity/zapIn.js +138 -0
- package/dist/services/liquidity/zapOut.d.ts +9 -0
- package/dist/services/liquidity/zapOut.js +255 -0
- package/dist/services/pools/PoolService.d.ts +69 -0
- package/dist/services/pools/PoolService.js +209 -0
- package/dist/services/pools/index.d.ts +2 -0
- package/dist/services/pools/index.js +18 -0
- package/dist/services/pools/poolDetails.d.ts +13 -0
- package/dist/services/pools/poolDetails.js +216 -0
- package/dist/services/pools/poolDiscovery.d.ts +12 -0
- package/dist/services/pools/poolDiscovery.js +117 -0
- package/dist/services/pools/rebalancePreview.d.ts +5 -0
- package/dist/services/pools/rebalancePreview.js +186 -0
- package/dist/services/quotes/QuoteService.d.ts +51 -0
- package/dist/services/quotes/QuoteService.js +91 -0
- package/dist/services/quotes/index.d.ts +2 -0
- package/dist/services/quotes/index.js +18 -0
- package/dist/services/routes/RouteService.d.ts +117 -0
- package/dist/services/routes/RouteService.js +306 -0
- package/dist/services/routes/index.d.ts +2 -0
- package/dist/services/routes/index.js +18 -0
- package/dist/services/swap/SwapService.d.ts +198 -0
- package/dist/services/swap/SwapService.js +252 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.js +18 -0
- package/dist/services/tokens/index.d.ts +2 -0
- package/dist/services/tokens/index.js +18 -0
- package/dist/services/tokens/tokenService.d.ts +55 -0
- package/dist/services/tokens/tokenService.js +290 -0
- package/dist/services/trading/TradingLimitsService.d.ts +38 -0
- package/dist/services/trading/TradingLimitsService.js +159 -0
- package/dist/services/trading/TradingService.d.ts +115 -0
- package/dist/services/trading/TradingService.js +227 -0
- package/dist/services/trading/index.d.ts +3 -0
- package/dist/services/trading/index.js +19 -0
- package/dist/utils/chainConfig.d.ts +16 -0
- package/dist/utils/chainConfig.js +127 -0
- package/dist/utils/costUtils.d.ts +12 -0
- package/dist/utils/costUtils.js +60 -0
- package/dist/utils/deadline.d.ts +21 -0
- package/dist/utils/deadline.js +26 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +26 -0
- package/dist/utils/multicall.d.ts +30 -0
- package/dist/utils/multicall.js +52 -0
- package/dist/utils/pathEncoder.d.ts +34 -0
- package/dist/utils/pathEncoder.js +73 -0
- package/dist/utils/rateFeed.d.ts +18 -0
- package/dist/utils/rateFeed.js +27 -0
- package/dist/utils/retry.d.ts +12 -0
- package/dist/utils/retry.js +28 -0
- package/dist/utils/routeUtils.d.ts +295 -0
- package/dist/utils/routeUtils.js +371 -0
- package/dist/utils/routes.d.ts +3 -0
- package/dist/utils/routes.js +8 -0
- package/dist/utils/sortUtils.d.ts +24 -0
- package/dist/utils/sortUtils.js +39 -0
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.js +13 -0
- package/dist/utils/tradingLimits.d.ts +41 -0
- package/dist/utils/tradingLimits.js +171 -0
- package/dist/utils/validation.d.ts +19 -0
- package/dist/utils/validation.js +34 -0
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAddressesFromRegistry = resolveAddressesFromRegistry;
|
|
4
|
+
exports.readSystemParams = readSystemParams;
|
|
5
|
+
const abis_1 = require("../../../core/abis");
|
|
6
|
+
const multicall_1 = require("../../../utils/multicall");
|
|
7
|
+
const validation_1 = require("../../../utils/validation");
|
|
8
|
+
function readNoArgsContract(publicClient, address, abi, functionName) {
|
|
9
|
+
const readContract = publicClient.readContract;
|
|
10
|
+
return readContract({ address, abi, functionName, args: [] });
|
|
11
|
+
}
|
|
12
|
+
async function readNoArgsContracts(publicClient, contracts) {
|
|
13
|
+
if (contracts.length === 0) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const results = await (0, multicall_1.multicall)(publicClient, contracts.map((contract) => ({
|
|
17
|
+
...contract,
|
|
18
|
+
abi: contract.abi,
|
|
19
|
+
args: [],
|
|
20
|
+
})), { allowFailure: false });
|
|
21
|
+
return results.map((result) => {
|
|
22
|
+
if (result.status === 'failure') {
|
|
23
|
+
throw result.error;
|
|
24
|
+
}
|
|
25
|
+
return result.result;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function requireAddress(value, fieldName) {
|
|
29
|
+
if (typeof value !== 'string') {
|
|
30
|
+
throw new Error(`${fieldName} must be a string address`);
|
|
31
|
+
}
|
|
32
|
+
(0, validation_1.validateAddress)(value, fieldName);
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function requireBigInt(value, fieldName) {
|
|
36
|
+
if (typeof value !== 'bigint') {
|
|
37
|
+
throw new Error(`${fieldName} must be a bigint`);
|
|
38
|
+
}
|
|
39
|
+
if (value < 0n) {
|
|
40
|
+
throw new Error(`${fieldName} cannot be negative`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
async function resolveAddressesFromRegistry(publicClient, registryAddress) {
|
|
45
|
+
(0, validation_1.validateAddress)(registryAddress, 'registryAddress');
|
|
46
|
+
const registry = registryAddress;
|
|
47
|
+
const [borrowerOperationsRaw, troveManagerRaw, sortedTrovesRaw, activePoolRaw, defaultPoolRaw, hintHelpersRaw, multiTroveGetterRaw, collTokenRaw, debtTokenRaw, troveNFTRaw, metadataNFTRaw, stabilityPoolRaw, priceFeedRaw, collSurplusPoolRaw, interestRouterRaw, collateralRegistryRaw, gasTokenRaw, gasPoolAddressRaw, liquidityStrategyRaw,] = await readNoArgsContracts(publicClient, [
|
|
48
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'borrowerOperations' },
|
|
49
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'troveManager' },
|
|
50
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'sortedTroves' },
|
|
51
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'activePool' },
|
|
52
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'defaultPool' },
|
|
53
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'hintHelpers' },
|
|
54
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'multiTroveGetter' },
|
|
55
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'collToken' },
|
|
56
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'boldToken' },
|
|
57
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'troveNFT' },
|
|
58
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'metadataNFT' },
|
|
59
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'stabilityPool' },
|
|
60
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'priceFeed' },
|
|
61
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'collSurplusPool' },
|
|
62
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'interestRouter' },
|
|
63
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'collateralRegistry' },
|
|
64
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'gasToken' },
|
|
65
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'gasPoolAddress' },
|
|
66
|
+
{ address: registry, abi: abis_1.ADDRESSES_REGISTRY_ABI, functionName: 'liquidityStrategy' },
|
|
67
|
+
]);
|
|
68
|
+
return {
|
|
69
|
+
borrowerOperations: requireAddress(borrowerOperationsRaw, 'borrowerOperations'),
|
|
70
|
+
troveManager: requireAddress(troveManagerRaw, 'troveManager'),
|
|
71
|
+
sortedTroves: requireAddress(sortedTrovesRaw, 'sortedTroves'),
|
|
72
|
+
activePool: requireAddress(activePoolRaw, 'activePool'),
|
|
73
|
+
defaultPool: requireAddress(defaultPoolRaw, 'defaultPool'),
|
|
74
|
+
hintHelpers: requireAddress(hintHelpersRaw, 'hintHelpers'),
|
|
75
|
+
multiTroveGetter: requireAddress(multiTroveGetterRaw, 'multiTroveGetter'),
|
|
76
|
+
collToken: requireAddress(collTokenRaw, 'collToken'),
|
|
77
|
+
debtToken: requireAddress(debtTokenRaw, 'debtToken'),
|
|
78
|
+
troveNFT: requireAddress(troveNFTRaw, 'troveNFT'),
|
|
79
|
+
metadataNFT: requireAddress(metadataNFTRaw, 'metadataNFT'),
|
|
80
|
+
stabilityPool: requireAddress(stabilityPoolRaw, 'stabilityPool'),
|
|
81
|
+
priceFeed: requireAddress(priceFeedRaw, 'priceFeed'),
|
|
82
|
+
collSurplusPool: requireAddress(collSurplusPoolRaw, 'collSurplusPool'),
|
|
83
|
+
interestRouter: requireAddress(interestRouterRaw, 'interestRouter'),
|
|
84
|
+
collateralRegistry: requireAddress(collateralRegistryRaw, 'collateralRegistry'),
|
|
85
|
+
gasToken: requireAddress(gasTokenRaw, 'gasToken'),
|
|
86
|
+
gasPoolAddress: requireAddress(gasPoolAddressRaw, 'gasPoolAddress'),
|
|
87
|
+
liquidityStrategy: requireAddress(liquidityStrategyRaw, 'liquidityStrategy'),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function readSystemParams(publicClient, borrowerOperations) {
|
|
91
|
+
(0, validation_1.validateAddress)(borrowerOperations, 'borrowerOperations');
|
|
92
|
+
const systemParamsAddressRaw = await readNoArgsContract(publicClient, borrowerOperations, abis_1.BORROWER_OPERATIONS_ABI, 'systemParams');
|
|
93
|
+
const systemParamsAddress = requireAddress(systemParamsAddressRaw, 'systemParamsAddress');
|
|
94
|
+
const [ccrRaw, mcrRaw, scrRaw, bcrRaw, minDebtRaw, ethGasCompensationRaw, minAnnualInterestRateRaw,] = await readNoArgsContracts(publicClient, [
|
|
95
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'CCR' },
|
|
96
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'MCR' },
|
|
97
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'SCR' },
|
|
98
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'BCR' },
|
|
99
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'MIN_DEBT' },
|
|
100
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'ETH_GAS_COMPENSATION' },
|
|
101
|
+
{ address: systemParamsAddress, abi: abis_1.SYSTEM_PARAMS_ABI, functionName: 'MIN_ANNUAL_INTEREST_RATE' },
|
|
102
|
+
]);
|
|
103
|
+
return {
|
|
104
|
+
mcr: requireBigInt(mcrRaw, 'MCR'),
|
|
105
|
+
ccr: requireBigInt(ccrRaw, 'CCR'),
|
|
106
|
+
scr: requireBigInt(scrRaw, 'SCR'),
|
|
107
|
+
bcr: requireBigInt(bcrRaw, 'BCR'),
|
|
108
|
+
minDebt: requireBigInt(minDebtRaw, 'MIN_DEBT'),
|
|
109
|
+
ethGasCompensation: requireBigInt(ethGasCompensationRaw, 'ETH_GAS_COMPENSATION'),
|
|
110
|
+
minAnnualInterestRate: requireBigInt(minAnnualInterestRateRaw, 'MIN_ANNUAL_INTEREST_RATE'),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=borrowRegistryReader.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
|
+
import { AdjustTroveParams, CallParams, OpenTroveParams } from '../../../core/types';
|
|
3
|
+
import { DeploymentContext } from './borrowTypes';
|
|
4
|
+
export declare class BorrowTransactionService {
|
|
5
|
+
private publicClient;
|
|
6
|
+
constructor(publicClient: PublicClient);
|
|
7
|
+
buildOpenTroveTransaction(ctx: DeploymentContext, params: OpenTroveParams): Promise<CallParams>;
|
|
8
|
+
buildAdjustTroveTransaction(ctx: DeploymentContext, params: AdjustTroveParams): CallParams;
|
|
9
|
+
buildAdjustZombieTroveTransaction(ctx: DeploymentContext, params: AdjustTroveParams): Promise<CallParams>;
|
|
10
|
+
buildCloseTroveTransaction(ctx: DeploymentContext, troveId: string): CallParams;
|
|
11
|
+
buildAddCollTransaction(ctx: DeploymentContext, troveId: string, amount: bigint): CallParams;
|
|
12
|
+
buildWithdrawCollTransaction(ctx: DeploymentContext, troveId: string, amount: bigint): CallParams;
|
|
13
|
+
buildBorrowMoreTransaction(ctx: DeploymentContext, troveId: string, amount: bigint, maxFee: bigint): CallParams;
|
|
14
|
+
buildRepayDebtTransaction(ctx: DeploymentContext, troveId: string, amount: bigint): CallParams;
|
|
15
|
+
buildAdjustInterestRateTransaction(ctx: DeploymentContext, troveId: string, newRate: bigint, maxFee: bigint): Promise<CallParams>;
|
|
16
|
+
buildClaimCollateralTransaction(ctx: DeploymentContext): CallParams;
|
|
17
|
+
buildSetBatchManagerTransaction(ctx: DeploymentContext, troveId: string, manager: string, maxFee: bigint): Promise<CallParams>;
|
|
18
|
+
buildRemoveFromBatchTransaction(ctx: DeploymentContext, troveId: string, newRate: bigint, maxFee: bigint): Promise<CallParams>;
|
|
19
|
+
buildSwitchBatchManagerTransaction(ctx: DeploymentContext, troveId: string, newManager: string, maxFee: bigint): Promise<CallParams>;
|
|
20
|
+
buildSetInterestDelegateTransaction(ctx: DeploymentContext, troveId: string, delegate: string, minRate: bigint, maxRate: bigint, newRate: bigint, maxFee: bigint, minChangePeriod: bigint): Promise<CallParams>;
|
|
21
|
+
buildRemoveInterestDelegateTransaction(ctx: DeploymentContext, troveId: string): CallParams;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=borrowTransactionService.d.ts.map
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BorrowTransactionService = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const abis_1 = require("../../../core/abis");
|
|
6
|
+
const borrowHints_1 = require("./borrowHints");
|
|
7
|
+
const borrowValidation_1 = require("./borrowValidation");
|
|
8
|
+
const ZERO_VALUE_HEX = '0x0';
|
|
9
|
+
class BorrowTransactionService {
|
|
10
|
+
constructor(publicClient) {
|
|
11
|
+
this.publicClient = publicClient;
|
|
12
|
+
}
|
|
13
|
+
async buildOpenTroveTransaction(ctx, params) {
|
|
14
|
+
const owner = (0, borrowValidation_1.requireAddress)(params.owner, 'owner');
|
|
15
|
+
const ownerIndex = (0, borrowValidation_1.requireNonNegativeInteger)(params.ownerIndex, 'ownerIndex');
|
|
16
|
+
const collAmount = (0, borrowValidation_1.requirePositiveBigInt)(params.collAmount, 'collAmount');
|
|
17
|
+
const boldAmount = (0, borrowValidation_1.requirePositiveBigInt)(params.boldAmount, 'boldAmount');
|
|
18
|
+
const annualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(params.annualInterestRate, 'annualInterestRate');
|
|
19
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(params.maxUpfrontFee, 'maxUpfrontFee');
|
|
20
|
+
const addManager = (0, borrowValidation_1.optionalAddressOrZero)(params.addManager, 'addManager');
|
|
21
|
+
const removeManager = (0, borrowValidation_1.optionalAddressOrZero)(params.removeManager, 'removeManager');
|
|
22
|
+
const receiver = (0, borrowValidation_1.optionalAddressOrZero)(params.receiver, 'receiver');
|
|
23
|
+
const hints = await (0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, annualInterestRate);
|
|
24
|
+
const data = params.interestBatchManager
|
|
25
|
+
? (0, viem_1.encodeFunctionData)({
|
|
26
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
27
|
+
functionName: 'openTroveAndJoinInterestBatchManager',
|
|
28
|
+
args: [
|
|
29
|
+
{
|
|
30
|
+
owner,
|
|
31
|
+
ownerIndex: BigInt(ownerIndex),
|
|
32
|
+
collAmount,
|
|
33
|
+
boldAmount,
|
|
34
|
+
upperHint: hints.upper,
|
|
35
|
+
lowerHint: hints.lower,
|
|
36
|
+
interestBatchManager: (0, borrowValidation_1.requireAddress)(params.interestBatchManager, 'interestBatchManager'),
|
|
37
|
+
maxUpfrontFee,
|
|
38
|
+
addManager,
|
|
39
|
+
removeManager,
|
|
40
|
+
receiver,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
: (0, viem_1.encodeFunctionData)({
|
|
45
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
46
|
+
functionName: 'openTrove',
|
|
47
|
+
args: [
|
|
48
|
+
owner,
|
|
49
|
+
BigInt(ownerIndex),
|
|
50
|
+
collAmount,
|
|
51
|
+
boldAmount,
|
|
52
|
+
hints.upper,
|
|
53
|
+
hints.lower,
|
|
54
|
+
annualInterestRate,
|
|
55
|
+
maxUpfrontFee,
|
|
56
|
+
addManager,
|
|
57
|
+
removeManager,
|
|
58
|
+
receiver,
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
to: ctx.addresses.borrowerOperations,
|
|
63
|
+
data,
|
|
64
|
+
value: ZERO_VALUE_HEX,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
buildAdjustTroveTransaction(ctx, params) {
|
|
68
|
+
const troveId = (0, borrowValidation_1.parseTroveId)(params.troveId);
|
|
69
|
+
const collChange = (0, borrowValidation_1.requireNonNegativeBigInt)(params.collChange, 'collChange');
|
|
70
|
+
const debtChange = (0, borrowValidation_1.requireNonNegativeBigInt)(params.debtChange, 'debtChange');
|
|
71
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(params.maxUpfrontFee, 'maxUpfrontFee');
|
|
72
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
73
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
74
|
+
functionName: 'adjustTrove',
|
|
75
|
+
args: [troveId, collChange, params.isCollIncrease, debtChange, params.isDebtIncrease, maxUpfrontFee],
|
|
76
|
+
});
|
|
77
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
78
|
+
}
|
|
79
|
+
async buildAdjustZombieTroveTransaction(ctx, params) {
|
|
80
|
+
const troveId = (0, borrowValidation_1.parseTroveId)(params.troveId);
|
|
81
|
+
const collChange = (0, borrowValidation_1.requireNonNegativeBigInt)(params.collChange, 'collChange');
|
|
82
|
+
const debtChange = (0, borrowValidation_1.requireNonNegativeBigInt)(params.debtChange, 'debtChange');
|
|
83
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(params.maxUpfrontFee, 'maxUpfrontFee');
|
|
84
|
+
const currentRate = (await this.publicClient.readContract({
|
|
85
|
+
address: ctx.addresses.troveManager,
|
|
86
|
+
abi: abis_1.TROVE_MANAGER_ABI,
|
|
87
|
+
functionName: 'getTroveAnnualInterestRate',
|
|
88
|
+
args: [troveId],
|
|
89
|
+
}));
|
|
90
|
+
const hints = await (0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, currentRate);
|
|
91
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
92
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
93
|
+
functionName: 'adjustZombieTrove',
|
|
94
|
+
args: [
|
|
95
|
+
troveId,
|
|
96
|
+
collChange,
|
|
97
|
+
params.isCollIncrease,
|
|
98
|
+
debtChange,
|
|
99
|
+
params.isDebtIncrease,
|
|
100
|
+
hints.upper,
|
|
101
|
+
hints.lower,
|
|
102
|
+
maxUpfrontFee,
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
106
|
+
}
|
|
107
|
+
buildCloseTroveTransaction(ctx, troveId) {
|
|
108
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
109
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
110
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
111
|
+
functionName: 'closeTrove',
|
|
112
|
+
args: [parsedTroveId],
|
|
113
|
+
});
|
|
114
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
115
|
+
}
|
|
116
|
+
buildAddCollTransaction(ctx, troveId, amount) {
|
|
117
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
118
|
+
const collAmount = (0, borrowValidation_1.requirePositiveBigInt)(amount, 'amount');
|
|
119
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
120
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
121
|
+
functionName: 'addColl',
|
|
122
|
+
args: [parsedTroveId, collAmount],
|
|
123
|
+
});
|
|
124
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
125
|
+
}
|
|
126
|
+
buildWithdrawCollTransaction(ctx, troveId, amount) {
|
|
127
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
128
|
+
const collAmount = (0, borrowValidation_1.requirePositiveBigInt)(amount, 'amount');
|
|
129
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
130
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
131
|
+
functionName: 'withdrawColl',
|
|
132
|
+
args: [parsedTroveId, collAmount],
|
|
133
|
+
});
|
|
134
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
135
|
+
}
|
|
136
|
+
buildBorrowMoreTransaction(ctx, troveId, amount, maxFee) {
|
|
137
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
138
|
+
const borrowAmount = (0, borrowValidation_1.requirePositiveBigInt)(amount, 'amount');
|
|
139
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(maxFee, 'maxFee');
|
|
140
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
141
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
142
|
+
functionName: 'withdrawBold',
|
|
143
|
+
args: [parsedTroveId, borrowAmount, maxUpfrontFee],
|
|
144
|
+
});
|
|
145
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
146
|
+
}
|
|
147
|
+
buildRepayDebtTransaction(ctx, troveId, amount) {
|
|
148
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
149
|
+
const repayAmount = (0, borrowValidation_1.requirePositiveBigInt)(amount, 'amount');
|
|
150
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
151
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
152
|
+
functionName: 'repayBold',
|
|
153
|
+
args: [parsedTroveId, repayAmount],
|
|
154
|
+
});
|
|
155
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
156
|
+
}
|
|
157
|
+
async buildAdjustInterestRateTransaction(ctx, troveId, newRate, maxFee) {
|
|
158
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
159
|
+
const newAnnualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(newRate, 'newRate');
|
|
160
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(maxFee, 'maxFee');
|
|
161
|
+
const hints = await (0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, newAnnualInterestRate);
|
|
162
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
163
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
164
|
+
functionName: 'adjustTroveInterestRate',
|
|
165
|
+
args: [parsedTroveId, newAnnualInterestRate, hints.upper, hints.lower, maxUpfrontFee],
|
|
166
|
+
});
|
|
167
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
168
|
+
}
|
|
169
|
+
buildClaimCollateralTransaction(ctx) {
|
|
170
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
171
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
172
|
+
functionName: 'claimCollateral',
|
|
173
|
+
args: [],
|
|
174
|
+
});
|
|
175
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
176
|
+
}
|
|
177
|
+
async buildSetBatchManagerTransaction(ctx, troveId, manager, maxFee) {
|
|
178
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
179
|
+
const newBatchManager = (0, borrowValidation_1.requireAddress)(manager, 'manager');
|
|
180
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(maxFee, 'maxFee');
|
|
181
|
+
const currentRate = (await this.publicClient.readContract({
|
|
182
|
+
address: ctx.addresses.troveManager,
|
|
183
|
+
abi: abis_1.TROVE_MANAGER_ABI,
|
|
184
|
+
functionName: 'getTroveAnnualInterestRate',
|
|
185
|
+
args: [parsedTroveId],
|
|
186
|
+
}));
|
|
187
|
+
const hints = await (0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, currentRate);
|
|
188
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
189
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
190
|
+
functionName: 'setInterestBatchManager',
|
|
191
|
+
args: [parsedTroveId, newBatchManager, hints.upper, hints.lower, maxUpfrontFee],
|
|
192
|
+
});
|
|
193
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
194
|
+
}
|
|
195
|
+
async buildRemoveFromBatchTransaction(ctx, troveId, newRate, maxFee) {
|
|
196
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
197
|
+
const newAnnualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(newRate, 'newRate');
|
|
198
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(maxFee, 'maxFee');
|
|
199
|
+
const hints = await (0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, newAnnualInterestRate);
|
|
200
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
201
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
202
|
+
functionName: 'removeFromBatch',
|
|
203
|
+
args: [parsedTroveId, newAnnualInterestRate, hints.upper, hints.lower, maxUpfrontFee],
|
|
204
|
+
});
|
|
205
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
206
|
+
}
|
|
207
|
+
async buildSwitchBatchManagerTransaction(ctx, troveId, newManager, maxFee) {
|
|
208
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
209
|
+
const managerAddress = (0, borrowValidation_1.requireAddress)(newManager, 'newManager');
|
|
210
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(maxFee, 'maxFee');
|
|
211
|
+
const currentRate = (await this.publicClient.readContract({
|
|
212
|
+
address: ctx.addresses.troveManager,
|
|
213
|
+
abi: abis_1.TROVE_MANAGER_ABI,
|
|
214
|
+
functionName: 'getTroveAnnualInterestRate',
|
|
215
|
+
args: [parsedTroveId],
|
|
216
|
+
}));
|
|
217
|
+
const [removeHints, addHints] = await Promise.all([
|
|
218
|
+
(0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, currentRate),
|
|
219
|
+
(0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, currentRate),
|
|
220
|
+
]);
|
|
221
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
222
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
223
|
+
functionName: 'switchBatchManager',
|
|
224
|
+
args: [
|
|
225
|
+
parsedTroveId,
|
|
226
|
+
removeHints.upper,
|
|
227
|
+
removeHints.lower,
|
|
228
|
+
managerAddress,
|
|
229
|
+
addHints.upper,
|
|
230
|
+
addHints.lower,
|
|
231
|
+
maxUpfrontFee,
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
235
|
+
}
|
|
236
|
+
async buildSetInterestDelegateTransaction(ctx, troveId, delegate, minRate, maxRate, newRate, maxFee, minChangePeriod) {
|
|
237
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
238
|
+
const delegateAddress = (0, borrowValidation_1.requireAddress)(delegate, 'delegate');
|
|
239
|
+
const minInterestRate = (0, borrowValidation_1.requireUint128)(minRate, 'minRate');
|
|
240
|
+
const maxInterestRate = (0, borrowValidation_1.requireUint128)(maxRate, 'maxRate');
|
|
241
|
+
const newAnnualInterestRate = (0, borrowValidation_1.requireNonNegativeBigInt)(newRate, 'newRate');
|
|
242
|
+
const maxUpfrontFee = (0, borrowValidation_1.requireNonNegativeBigInt)(maxFee, 'maxFee');
|
|
243
|
+
const minRateChangePeriod = (0, borrowValidation_1.requireNonNegativeBigInt)(minChangePeriod, 'minChangePeriod');
|
|
244
|
+
if (minInterestRate > maxInterestRate) {
|
|
245
|
+
throw new Error('minRate cannot be greater than maxRate');
|
|
246
|
+
}
|
|
247
|
+
const hints = await (0, borrowHints_1.getTroveOperationHints)(this.publicClient, ctx, newAnnualInterestRate);
|
|
248
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
249
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
250
|
+
functionName: 'setInterestIndividualDelegate',
|
|
251
|
+
args: [
|
|
252
|
+
parsedTroveId,
|
|
253
|
+
delegateAddress,
|
|
254
|
+
minInterestRate,
|
|
255
|
+
maxInterestRate,
|
|
256
|
+
newAnnualInterestRate,
|
|
257
|
+
hints.upper,
|
|
258
|
+
hints.lower,
|
|
259
|
+
maxUpfrontFee,
|
|
260
|
+
minRateChangePeriod,
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
264
|
+
}
|
|
265
|
+
buildRemoveInterestDelegateTransaction(ctx, troveId) {
|
|
266
|
+
const parsedTroveId = (0, borrowValidation_1.parseTroveId)(troveId);
|
|
267
|
+
const data = (0, viem_1.encodeFunctionData)({
|
|
268
|
+
abi: abis_1.BORROWER_OPERATIONS_ABI,
|
|
269
|
+
functionName: 'removeInterestIndividualDelegate',
|
|
270
|
+
args: [parsedTroveId],
|
|
271
|
+
});
|
|
272
|
+
return { to: ctx.addresses.borrowerOperations, data, value: ZERO_VALUE_HEX };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.BorrowTransactionService = BorrowTransactionService;
|
|
276
|
+
//# sourceMappingURL=borrowTransactionService.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BorrowContractAddresses, SystemParams } from '../../../core/types';
|
|
2
|
+
export interface DeploymentContext {
|
|
3
|
+
addresses: BorrowContractAddresses;
|
|
4
|
+
systemParams: SystemParams;
|
|
5
|
+
}
|
|
6
|
+
export type InterestBatchManagerData = {
|
|
7
|
+
minInterestRate: bigint;
|
|
8
|
+
maxInterestRate: bigint;
|
|
9
|
+
minInterestRateChangePeriod: bigint;
|
|
10
|
+
};
|
|
11
|
+
export type DebtPerInterestRateItem = {
|
|
12
|
+
interestRate: bigint;
|
|
13
|
+
debt: bigint;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=borrowTypes.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
export declare const MAX_SAFE_INTEGER_BIGINT: bigint;
|
|
3
|
+
export declare function requireDebtTokenSymbol(symbol: string): string;
|
|
4
|
+
export declare function requireAddress(address: string, fieldName: string): Address;
|
|
5
|
+
export declare function optionalAddressOrZero(value: string | undefined, fieldName: string): Address;
|
|
6
|
+
export declare function parseTroveId(troveId: string): bigint;
|
|
7
|
+
export declare function formatTroveId(troveId: bigint): string;
|
|
8
|
+
export declare function deriveTroveId(opener: string, owner: string, ownerIndex: number): bigint;
|
|
9
|
+
export declare function requireNonNegativeInteger(value: number, fieldName: string): number;
|
|
10
|
+
export declare function requireNonNegativeBigInt(value: bigint, fieldName: string): bigint;
|
|
11
|
+
export declare function requirePositiveBigInt(value: bigint, fieldName: string): bigint;
|
|
12
|
+
export declare function requireUint128(value: bigint, fieldName: string): bigint;
|
|
13
|
+
export declare function ceilSqrt(value: bigint): bigint;
|
|
14
|
+
//# sourceMappingURL=borrowValidation.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_SAFE_INTEGER_BIGINT = void 0;
|
|
4
|
+
exports.requireDebtTokenSymbol = requireDebtTokenSymbol;
|
|
5
|
+
exports.requireAddress = requireAddress;
|
|
6
|
+
exports.optionalAddressOrZero = optionalAddressOrZero;
|
|
7
|
+
exports.parseTroveId = parseTroveId;
|
|
8
|
+
exports.formatTroveId = formatTroveId;
|
|
9
|
+
exports.deriveTroveId = deriveTroveId;
|
|
10
|
+
exports.requireNonNegativeInteger = requireNonNegativeInteger;
|
|
11
|
+
exports.requireNonNegativeBigInt = requireNonNegativeBigInt;
|
|
12
|
+
exports.requirePositiveBigInt = requirePositiveBigInt;
|
|
13
|
+
exports.requireUint128 = requireUint128;
|
|
14
|
+
exports.ceilSqrt = ceilSqrt;
|
|
15
|
+
const viem_1 = require("viem");
|
|
16
|
+
const validation_1 = require("../../../utils/validation");
|
|
17
|
+
const UINT128_MAX = (1n << 128n) - 1n;
|
|
18
|
+
exports.MAX_SAFE_INTEGER_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
19
|
+
const TROVE_ID_PARAMETERS = (0, viem_1.parseAbiParameters)('address opener, address owner, uint256 ownerIndex');
|
|
20
|
+
function requireDebtTokenSymbol(symbol) {
|
|
21
|
+
if (typeof symbol !== 'string' || symbol.trim().length === 0) {
|
|
22
|
+
throw new Error('debtTokenSymbol must be a non-empty string');
|
|
23
|
+
}
|
|
24
|
+
return symbol.trim();
|
|
25
|
+
}
|
|
26
|
+
function requireAddress(address, fieldName) {
|
|
27
|
+
(0, validation_1.validateAddress)(address, fieldName);
|
|
28
|
+
return address;
|
|
29
|
+
}
|
|
30
|
+
function optionalAddressOrZero(value, fieldName) {
|
|
31
|
+
if (!value)
|
|
32
|
+
return viem_1.zeroAddress;
|
|
33
|
+
return requireAddress(value, fieldName);
|
|
34
|
+
}
|
|
35
|
+
function parseTroveId(troveId) {
|
|
36
|
+
if (typeof troveId !== 'string' || troveId.trim().length === 0) {
|
|
37
|
+
throw new Error('troveId must be a non-empty string');
|
|
38
|
+
}
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = BigInt(troveId);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new Error(`Invalid troveId: ${troveId}`);
|
|
45
|
+
}
|
|
46
|
+
if (parsed < 0n) {
|
|
47
|
+
throw new Error('troveId cannot be negative');
|
|
48
|
+
}
|
|
49
|
+
return parsed;
|
|
50
|
+
}
|
|
51
|
+
function formatTroveId(troveId) {
|
|
52
|
+
return `0x${troveId.toString(16)}`;
|
|
53
|
+
}
|
|
54
|
+
function deriveTroveId(opener, owner, ownerIndex) {
|
|
55
|
+
const openerAddress = (0, viem_1.getAddress)(requireAddress(opener, 'opener'));
|
|
56
|
+
const ownerAddress = (0, viem_1.getAddress)(requireAddress(owner, 'owner'));
|
|
57
|
+
const validatedOwnerIndex = requireNonNegativeInteger(ownerIndex, 'ownerIndex');
|
|
58
|
+
return BigInt((0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)(TROVE_ID_PARAMETERS, [openerAddress, ownerAddress, BigInt(validatedOwnerIndex)])));
|
|
59
|
+
}
|
|
60
|
+
function requireNonNegativeInteger(value, fieldName) {
|
|
61
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
62
|
+
throw new Error(`${fieldName} must be a non-negative safe integer`);
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
function requireNonNegativeBigInt(value, fieldName) {
|
|
67
|
+
if (typeof value !== 'bigint' || value < 0n) {
|
|
68
|
+
throw new Error(`${fieldName} must be a non-negative bigint`);
|
|
69
|
+
}
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
function requirePositiveBigInt(value, fieldName) {
|
|
73
|
+
if (typeof value !== 'bigint' || value <= 0n) {
|
|
74
|
+
throw new Error(`${fieldName} must be a positive bigint`);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function requireUint128(value, fieldName) {
|
|
79
|
+
const parsed = requireNonNegativeBigInt(value, fieldName);
|
|
80
|
+
if (parsed > UINT128_MAX) {
|
|
81
|
+
throw new Error(`${fieldName} exceeds uint128 max value`);
|
|
82
|
+
}
|
|
83
|
+
return parsed;
|
|
84
|
+
}
|
|
85
|
+
function integerSqrt(value) {
|
|
86
|
+
if (value < 0n) {
|
|
87
|
+
throw new Error('Cannot compute square root of a negative bigint');
|
|
88
|
+
}
|
|
89
|
+
if (value < 2n) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
let x0 = value;
|
|
93
|
+
let x1 = (x0 + 1n) >> 1n;
|
|
94
|
+
while (x1 < x0) {
|
|
95
|
+
x0 = x1;
|
|
96
|
+
x1 = (x1 + value / x1) >> 1n;
|
|
97
|
+
}
|
|
98
|
+
return x0;
|
|
99
|
+
}
|
|
100
|
+
function ceilSqrt(value) {
|
|
101
|
+
const floor = integerSqrt(value);
|
|
102
|
+
return floor * floor === value ? floor : floor + 1n;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=borrowValidation.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
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("./pools"), exports);
|
|
18
|
+
__exportStar(require("./routes"), exports);
|
|
19
|
+
__exportStar(require("./quotes"), exports);
|
|
20
|
+
__exportStar(require("./swap"), exports);
|
|
21
|
+
__exportStar(require("./trading"), exports);
|
|
22
|
+
__exportStar(require("./borrow"), exports);
|
|
23
|
+
__exportStar(require("./tokens"), exports);
|
|
24
|
+
__exportStar(require("./liquidity"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|