@@ -33,15 +33,15 @@ const amount = Decimal.parse("123.456", 18);
3333amount .add (10 ).mul (2 ).div (3 );
3434
3535// Rounding
36- amount .dp (2 , RoundingMode .ROUND ); // 123.46
36+ amount .dp (2 , RoundingMode .ROUND ); // 123.46
3737
3838// Format
39- amount .toString (2 ); // "123.46" (trims zeros)
40- amount .toFixed (4 ); // "123.4560"
41- amount .toFormat (2 ); // "123.46" (with commas for large numbers)
39+ amount .toString (2 ); // "123.46" (trims zeros)
40+ amount .toFixed (4 ); // "123.4560"
41+ amount .toFormat (2 ); // "123.46" (with commas for large numbers)
4242
4343// Comparison
44- amount .gt (100 ); // true
44+ amount .gt (100 ); // true
4545amount .eq (123.456 ); // true
4646```
4747
@@ -60,8 +60,8 @@ import {
6060
6161// Calculate current LTV
6262const ltv = computeLTV ({
63- collateral: 1000000000000000000n , // 1 ETH collateral
64- borrowed: 500000000n , // 500 USDC borrowed
63+ collateral: 1000000000000000000n , // 1 ETH collateral
64+ borrowed: 500000000n , // 500 USDC borrowed
6565 priceRate: 2000000000000000000000n , // ETH = 2000 USDC
6666});
6767
@@ -70,9 +70,9 @@ const result = simulateBorrow({
7070 collateral: 1000000000000000000n ,
7171 borrowed: 0n ,
7272 priceRate: 2000000000000000000000n ,
73- lltv: 800000000000000000n , // 80% LLTV
74- supplyAmount: 500000000000000000n , // Adding 0.5 ETH
75- borrowAmount: 500000000n , // Borrowing 500 USDC
73+ lltv: 800000000000000000n , // 80% LLTV
74+ supplyAmount: 500000000000000000n , // Adding 0.5 ETH
75+ borrowAmount: 500000000n , // Borrowing 500 USDC
7676});
7777// result: { newLTV, newLiqPrice, newLoanable, newWithdrawable, ... }
7878```
@@ -107,24 +107,32 @@ const curve = getInterestRates({
107107});
108108```
109109
110- ### Vault Calculations
110+ ### Vault Simulation
111111
112112``` typescript
113113import {
114114 simulateVaultDeposit ,
115115 simulateVaultWithdraw ,
116- getVaultSharePrice ,
117- convertToShares ,
118- convertToAssets ,
116+ Decimal ,
119117} from " @lista-dao/moolah-sdk-core" ;
120118
121- // Simulate vault deposit
122- const result = simulateVaultDeposit ({
123- totalAssets ,
124- totalSupply ,
125- assets: depositAmount ,
119+ // Simulate vault deposit (user balance → locked in vault)
120+ const depositResult = simulateVaultDeposit ({
121+ depositAmount: Decimal .parse (" 100" , 18 ),
122+ userLocked: Decimal .parse (" 500" , 18 ),
123+ userBalance: Decimal .parse (" 1000" , 18 ),
124+ apy: Decimal .parse (" 0.05" , 18 ), // optional, for earnings projection
125+ assetPrice: Decimal .parse (" 1" , 18 ), // optional
126126});
127- // result: { shares, newTotalAssets, newTotalSupply }
127+ // depositResult: { locked, balance, yearlyEarnings?, monthlyEarnings? }
128+
129+ // Simulate vault withdraw
130+ const withdrawResult = simulateVaultWithdraw ({
131+ withdrawAmount: Decimal .parse (" 100" , 18 ),
132+ userLocked: Decimal .parse (" 500" , 18 ),
133+ userBalance: Decimal .parse (" 200" , 18 ),
134+ });
135+ // withdrawResult: { locked, balance, yearlyEarnings?, monthlyEarnings? }
128136```
129137
130138### Loan Calculations
@@ -149,7 +157,7 @@ const repayment = calculateFixedLoanRepayment({
149157``` typescript
150158import type {
151159 // Network
152- NetworkName , // 'bsc' | 'ethereum' | 'sepolia '
160+ NetworkName , // 'bsc' | 'ethereum'
153161
154162 // Tokens
155163 TokenInfo ,
@@ -168,8 +176,9 @@ import type {
168176 WriteSmartMarketConfig ,
169177
170178 // Broker
171- BrokerUserPosition ,
172- BrokerFixedTerm ,
179+ BrokerUserPositionsData ,
180+ FixedTermAndRate ,
181+ BrokerInfo ,
173182
174183 // Operations
175184 BuiltSupplyOperation ,
@@ -183,14 +192,10 @@ import type {
183192
184193``` typescript
185194import {
186- // ABIs
187- moolahAbi ,
188- moolahVaultAbi ,
189- interestRateModelAbi ,
190- erc20Abi ,
191- erc4626Abi ,
192-
193- // Address helpers
195+ MOOLAH_ABI ,
196+ MOOLAH_VAULT_ABI ,
197+ INTEREST_RATE_MODEL_ABI ,
198+ ERC20_ABI ,
194199 getContractAddress ,
195200 getContractAddressOptional ,
196201} from " @lista-dao/moolah-sdk-core" ;
@@ -209,11 +214,11 @@ import {
209214 isUsdtLikeToken ,
210215} from " @lista-dao/moolah-sdk-core" ;
211216
212- // Get API chain identifier
213- const apiChain = getApiChain (" bsc" ); // "BSC "
217+ // Get API chain identifier (for list APIs)
218+ const apiChain = getApiChain (" bsc" ); // "bsc "
214219
215220// Get API URL
216- const url = getListaApiUrl (" prod" ); // "https://api.lista.org"
221+ const url = getListaApiUrl (" prod" ); // "https://api.lista.org"
217222```
218223
219224## Package Architecture
@@ -227,22 +232,28 @@ This is a **zero-dependency core package** (except for Morpho SDK for interest c
227232```
228233moolah-sdk-core/
229234├── calculations/
230- │ ├── position.ts # LTV, loanable, withdrawable
235+ │ ├── position.ts # LTV, loanable, withdrawable (bigint)
231236│ ├── interestRate.ts # Borrow rates, APY
232- │ ├── vault.ts # Vault share calculations
233- │ └── loan.ts # Loan repayment calculations
237+ │ ├── stablepool.ts # Stable swap / LP math
238+ │ └── loan.ts # Loan repayment calculations
239+ ├── simulate/
240+ │ ├── market.ts # simulateMarketBorrow, simulateMarketRepay
241+ │ ├── vault.ts # simulateVaultDeposit, simulateVaultWithdraw
242+ │ └── smart.ts # Smart market simulate + LP breakdown
234243├── contracts/
235- │ ├── abi / # Contract ABIs
236- │ └── config.ts # Contract addresses
244+ │ ├── abis / # Contract ABIs
245+ │ └── config.ts # Contract addresses
237246├── types/
238- │ ├── market.ts # Market types
239- │ ├── vault.ts # Vault types
240- │ ├── loan.ts # Loan types
241- │ └── operations.ts # Operation result types
247+ │ ├── market.ts # Market types
248+ │ ├── vault.ts # Vault types
249+ │ ├── smart.ts # Smart market types
250+ │ ├── broker.ts # Broker types
251+ │ └── operations.ts # Operation result types
242252└── utils/
243- ├── decimal.ts # Decimal class
253+ ├── decimal.ts # Decimal class
244254 ├── fraction.ts # Fraction class
245- └── network.ts # Network helpers
255+ ├── apiChain.ts # getApiChain, getListaApiUrl
256+ └── network.ts # getNativeCurrencySymbol
246257```
247258
248259## License
0 commit comments