Skip to content

Commit 177463d

Browse files
feat: support trove management operations (#121)
Co-authored-by: Sol <solofberlin@fastmail.com>
1 parent aa2b6f1 commit 177463d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3314
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ yarn-error.log*
3737
# AI files
3838
.claude/
3939
.specify/*
40+
IMPLEMENTATION_PLAN.md
4041

4142
.vscode/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mento-protocol/mento-sdk",
33
"description": "Official SDK for interacting with the Mento Protocol",
4-
"version": "3.0.0-beta.17",
4+
"version": "3.0.0-beta.24",
55
"license": "MIT",
66
"author": "Mento Labs",
77
"keywords": [

src/core/abis/activePool.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { parseAbi } from 'viem'
2+
3+
export const ACTIVE_POOL_ABI = parseAbi([
4+
'function getCollBalance() view returns (uint256)',
5+
'function getBoldDebt() view returns (uint256)',
6+
'function aggWeightedDebtSum() view returns (uint256)',
7+
'function aggRecordedDebt() view returns (uint256)',
8+
'function calcPendingAggInterest() view returns (uint256)',
9+
'function hasBeenShutDown() view returns (bool)',
10+
'function shutdownTime() view returns (uint256)',
11+
]) as any

src/core/abis/addressesRegistry.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { parseAbi } from 'viem'
2+
3+
export const ADDRESSES_REGISTRY_ABI = parseAbi([
4+
'function collToken() view returns (address)',
5+
'function borrowerOperations() view returns (address)',
6+
'function troveManager() view returns (address)',
7+
'function troveNFT() view returns (address)',
8+
'function metadataNFT() view returns (address)',
9+
'function stabilityPool() view returns (address)',
10+
'function priceFeed() view returns (address)',
11+
'function activePool() view returns (address)',
12+
'function defaultPool() view returns (address)',
13+
'function gasPoolAddress() view returns (address)',
14+
'function collSurplusPool() view returns (address)',
15+
'function sortedTroves() view returns (address)',
16+
'function interestRouter() view returns (address)',
17+
'function hintHelpers() view returns (address)',
18+
'function multiTroveGetter() view returns (address)',
19+
'function collateralRegistry() view returns (address)',
20+
'function boldToken() view returns (address)',
21+
'function gasToken() view returns (address)',
22+
'function liquidityStrategy() view returns (address)',
23+
]) as any
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { parseAbi } from 'viem'
2+
3+
/**
4+
* BorrowerOperations ABI for Bold protocol trove operations
5+
*
6+
* Note: `as any` is used because viem's parseAbi returns a complex readonly tuple type
7+
* that can cause type verbosity. This doesn't compromise type safety - viem's
8+
* readContract/writeContract still infer types correctly from the ABI at usage sites.
9+
*/
10+
export const BORROWER_OPERATIONS_ABI = parseAbi([
11+
// Core trove operations
12+
'function openTrove(address _owner, uint256 _ownerIndex, uint256 _ETHAmount, uint256 _boldAmount, uint256 _upperHint, uint256 _lowerHint, uint256 _annualInterestRate, uint256 _maxUpfrontFee, address _addManager, address _removeManager, address _receiver) returns (uint256)',
13+
'function openTroveAndJoinInterestBatchManager((address owner, uint256 ownerIndex, uint256 collAmount, uint256 boldAmount, uint256 upperHint, uint256 lowerHint, address interestBatchManager, uint256 maxUpfrontFee, address addManager, address removeManager, address receiver) _params) returns (uint256)',
14+
'function addColl(uint256 _troveId, uint256 _ETHAmount)',
15+
'function withdrawColl(uint256 _troveId, uint256 _amount)',
16+
'function withdrawBold(uint256 _troveId, uint256 _amount, uint256 _maxUpfrontFee)',
17+
'function repayBold(uint256 _troveId, uint256 _amount)',
18+
'function closeTrove(uint256 _troveId)',
19+
'function adjustTrove(uint256 _troveId, uint256 _collChange, bool _isCollIncrease, uint256 _debtChange, bool isDebtIncrease, uint256 _maxUpfrontFee)',
20+
'function adjustZombieTrove(uint256 _troveId, uint256 _collChange, bool _isCollIncrease, uint256 _boldChange, bool _isDebtIncrease, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee)',
21+
'function adjustTroveInterestRate(uint256 _troveId, uint256 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee)',
22+
'function applyPendingDebt(uint256 _troveId, uint256 _lowerHint, uint256 _upperHint)',
23+
'function claimCollateral()',
24+
25+
// Batch manager operations
26+
'function setInterestBatchManager(uint256 _troveId, address _newBatchManager, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee)',
27+
'function removeFromBatch(uint256 _troveId, uint256 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee)',
28+
'function switchBatchManager(uint256 _troveId, uint256 _removeUpperHint, uint256 _removeLowerHint, address _newBatchManager, uint256 _addUpperHint, uint256 _addLowerHint, uint256 _maxUpfrontFee)',
29+
30+
// Individual delegate
31+
'function setInterestIndividualDelegate(uint256 _troveId, address _delegate, uint128 _minInterestRate, uint128 _maxInterestRate, uint256 _newAnnualInterestRate, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee, uint256 _minInterestRateChangePeriod)',
32+
'function removeInterestIndividualDelegate(uint256 _troveId)',
33+
34+
// View functions
35+
'function hasBeenShutDown() view returns (bool)',
36+
'function interestBatchManagerOf(uint256 _troveId) view returns (address)',
37+
'function getInterestBatchManager(address _account) view returns ((uint128 minInterestRate, uint128 maxInterestRate, uint256 minInterestRateChangePeriod))',
38+
'function checkBatchManagerExists(address _batchManager) view returns (bool)',
39+
'function getInterestIndividualDelegateOf(uint256 _troveId) view returns ((address account, uint128 minInterestRate, uint128 maxInterestRate, uint256 minInterestRateChangePeriod))',
40+
41+
// Inherited view functions from LiquityBase
42+
'function getEntireBranchDebt() view returns (uint256)',
43+
'function getEntireBranchColl() view returns (uint256)',
44+
45+
'function systemParams() view returns (address)',
46+
'function CCR() view returns (uint256)',
47+
'function MCR() view returns (uint256)',
48+
49+
// Custom errors (BorrowerOperations.sol)
50+
'error IsShutDown()',
51+
'error TCRNotBelowSCR()',
52+
'error ZeroAdjustment()',
53+
'error NotOwnerNorInterestManager()',
54+
'error TroveInBatch()',
55+
'error TroveNotInBatch()',
56+
'error InterestNotInRange()',
57+
'error BatchInterestRateChangePeriodNotPassed()',
58+
'error DelegateInterestRateChangePeriodNotPassed()',
59+
'error TroveExists()',
60+
'error TroveNotOpen()',
61+
'error TroveNotActive()',
62+
'error TroveNotZombie()',
63+
'error TroveWithZeroDebt()',
64+
'error UpfrontFeeTooHigh()',
65+
'error ICRBelowMCR()',
66+
'error ICRBelowMCRPlusBCR()',
67+
'error RepaymentNotMatchingCollWithdrawal()',
68+
'error TCRBelowCCR()',
69+
'error DebtBelowMin()',
70+
'error CollWithdrawalTooHigh()',
71+
'error NotEnoughBoldBalance()',
72+
'error InterestRateTooLow()',
73+
'error InterestRateTooHigh()',
74+
'error InterestRateNotNew()',
75+
'error InvalidInterestBatchManager()',
76+
'error BatchManagerExists()',
77+
'error BatchManagerNotNew()',
78+
'error NewFeeNotLower()',
79+
'error CallerNotTroveManager()',
80+
'error CallerNotPriceFeed()',
81+
'error CallerNotSelf()',
82+
'error MinGeMax()',
83+
'error AnnualManagementFeeTooHigh()',
84+
'error MinInterestRateChangePeriodTooLow()',
85+
'error NewOracleFailureDetected()',
86+
'error BatchSharesRatioTooLow()',
87+
88+
// Custom errors (inherited from AddRemoveManagers)
89+
'error EmptyManager()',
90+
'error NotBorrower()',
91+
'error NotOwnerNorAddManager()',
92+
'error NotOwnerNorRemoveManager()',
93+
]) as any

src/core/abis/fpmm.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,33 @@ export const FPMM_ABI = parseAbi([
1515
'function rebalanceThresholdBelow() view returns (uint256)',
1616
'function liquidityStrategy(address) view returns (bool)',
1717
'function getRebalancingState() view returns (uint256, uint256, uint256, uint256, bool, uint16, uint256)',
18+
19+
// Custom errors
20+
'error ReferenceRateNotSet()',
21+
'error ReservesEmpty()',
22+
'error InvalidToken()',
23+
'error ZeroAddress()',
24+
'error ProtocolFeeRecipientRequired()',
25+
'error NotFeeSetter()',
26+
'error FeeTooHigh()',
27+
'error InsufficientLiquidityMinted()',
28+
'error InsufficientLiquidityBurned()',
29+
'error InsufficientOutputAmount()',
30+
'error InsufficientLiquidity()',
31+
'error InvalidToAddress()',
32+
'error InsufficientInputAmount()',
33+
'error NotLiquidityStrategy()',
34+
'error OneOutputAmountRequired()',
35+
'error PriceDifferenceTooSmall()',
36+
'error PriceDifferenceNotImproved()',
37+
'error PriceDifferenceMovedInWrongDirection()',
38+
'error PriceDifferenceMovedTooFarFromThresholds()',
39+
'error InsufficientAmount0In()',
40+
'error InsufficientAmount1In()',
41+
'error ReserveValueDecreased()',
42+
'error RebalanceIncentiveTooHigh()',
43+
'error RebalanceThresholdTooHigh()',
44+
'error RebalanceDirectionInvalid()',
45+
'error LimitDoesNotFitInInt120()',
46+
'error InvalidTokenDecimals()',
1847
])

src/core/abis/fpmmFactory.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,22 @@ import { parseAbi } from 'viem'
33
export const FPMM_FACTORY_ABI = parseAbi([
44
'function deployedFPMMAddresses() view returns (address[])',
55
'function isPool(address pool) view returns (bool)',
6+
7+
// Custom errors
8+
'error CreateXBytecodeHashMismatch()',
9+
'error ZeroAddress()',
10+
'error IdenticalTokenAddresses()',
11+
'error SortTokensZeroAddress()',
12+
'error InvalidOracleAdapter()',
13+
'error InvalidProxyAdmin()',
14+
'error InvalidOwner()',
15+
'error InvalidReferenceRateFeedID()',
16+
'error PairAlreadyExists()',
17+
'error ImplementationNotRegistered()',
18+
'error ImplementationAlreadyRegistered()',
19+
'error IndexOutOfBounds()',
20+
'error ImplementationIndexMismatch()',
21+
'error FeeTooHigh()',
22+
'error RebalanceIncentiveTooHigh()',
23+
'error RebalanceThresholdTooHigh()',
624
])

src/core/abis/hintHelpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { parseAbi } from 'viem'
2+
3+
export const HINT_HELPERS_ABI = parseAbi([
4+
'function getApproxHint(uint256 _collIndex, uint256 _interestRate, uint256 _numTrials, uint256 _inputRandomSeed) view returns (uint256 hintId, uint256 diff, uint256 latestRandomSeed)',
5+
'function predictOpenTroveUpfrontFee(uint256 _collIndex, uint256 _borrowedAmount, uint256 _interestRate) view returns (uint256)',
6+
'function predictAdjustTroveUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _debtIncrease) view returns (uint256)',
7+
'function predictAdjustInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _newInterestRate) view returns (uint256)',
8+
'function forcePredictAdjustInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _newInterestRate) view returns (uint256)',
9+
'function predictAdjustBatchInterestRateUpfrontFee(uint256 _collIndex, address _batchAddress, uint256 _newInterestRate) view returns (uint256)',
10+
'function predictJoinBatchInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, address _batchAddress) view returns (uint256)',
11+
]) as any

src/core/abis/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@ export * from './fpmm'
88
export * from './virtualPoolFactory'
99
export * from './virtualPool'
1010
export * from './router'
11-
export * from './breakerbox'
11+
export * from './breakerbox'
12+
export * from './borrowerOperations'
13+
export * from './troveManager'
14+
export * from './hintHelpers'
15+
export * from './sortedTroves'
16+
export * from './activePool'
17+
export * from './multiTroveGetter'
18+
export * from './troveNFT'
19+
export * from './priceFeed'
20+
export * from './addressesRegistry'
21+
export * from './systemParams'

src/core/abis/multiTroveGetter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { parseAbi } from 'viem'
2+
3+
/**
4+
* MultiTroveGetter ABI for batch trove queries
5+
*
6+
* Source: MultiTroveGetter.sol
7+
* Note: Both functions require `_collIndex` as first param — SDK passes `0n`.
8+
*/
9+
export const MULTI_TROVE_GETTER_ABI = parseAbi([
10+
'function getMultipleSortedTroves(uint256 _collIndex, int256 _startIdx, uint256 _count) view returns ((uint256 id, uint256 entireDebt, uint256 entireColl, uint256 redistBoldDebtGain, uint256 redistCollGain, uint256 accruedInterest, uint256 recordedDebt, uint256 annualInterestRate, uint256 accruedBatchManagementFee, uint256 lastInterestRateAdjTime, uint256 stake, uint256 lastDebtUpdateTime, address interestBatchManager, uint256 batchDebtShares, uint256 snapshotETH, uint256 snapshotBoldDebt)[])',
11+
'function getDebtPerInterestRateAscending(uint256 _collIndex, uint256 _startId, uint256 _maxIterations) view returns ((address interestBatchManager, uint256 interestRate, uint256 debt)[] data, uint256 currId)',
12+
]) as any

0 commit comments

Comments
 (0)