This documentation is provided by MorphoLabs, main contributor to Morpho DAO. For any question, reach out.
Morpho AaveV3-ETH Optimizer: SDK Documentation
Introduction
Morpho's AaveV3-ETH Optimizer SDK is a TypeScript-based toolkit for building decentralized applications (dApps) using Morpho-AaveV3 smart contracts.
The SDK is a "plug-and-play" adapter, easing the construction of any app or script that requires interaction with the Morpho AaveV3-ETH Optimizer contracts. It also provides seamless integration with RxJS for reactive programming, facilitating efficient handling of async data streams.
The SDK is still under development, and any feedback is welcome.
Prerequisites
Knowledge of blockchain, TypeScript, and decentralized applications.
Node.js (v.^14.0) and npm/yarn installed on your system.
and all other information on the other available markets.
Second example using getUserMarketsData()
exportconstmain=async () => {try {constadapter:MorphoAaveV3Adapter=MorphoAaveV3Adapter.fromChain({ _provider:getDefaultProvider("https://YOUR_HTTPS_ACCESS" ), });awaitadapter.connect("0x395012DF0D443a7639E46Fcb0DAF756a9Bbf3c6c"); // User selected randomlyawaitadapter.refreshAll("latest");constuserDataUsdc:any=adapter.getUserMarketsData()["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"// This is the USDC market ];console.log(userDataUsdc); } catch (error) {console.error(`Failed to run main function: ${error}`); }};main().then(() =>process.exit(0)).catch((error:Error) => {console.error(`Failed to run script: ${error}`);process.exit(1); });
Third example to retrieve the supply emission of MORPHO rewards emitted for 1000$ using getMarketsData(): on the WETH market:
exportconstmain=async () => {try {constadapter:MorphoAaveV3Adapter=MorphoAaveV3Adapter.fromChain();awaitadapter.refreshAll("latest");constmarketsData:any=adapter.getMarketsData();constmarketAddress="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; //WETH marketconstspecificMarketData= marketsData[marketAddress];constSECONDS_PER_YEAR=BigNumber.from(31_536_000);let supplyMorphoEmission:BigNumber=constants.Zero;constscalingValueUnderlying= utils.parseUnits("1000") // 1000$ in underlying.mul(pow10(18)).div(specificMarketData.usdPrice.mul(10**10)); supplyMorphoEmission = scalingValueUnderlying.mul(specificMarketData.supplyMorphoRewardsRate).mul(SECONDS_PER_YEAR) // in WAD.div(specificMarketData.totalMorphoSupply.add(scalingValueUnderlying)).div(pow10(18));console.log(supplyMorphoEmission.toString()); } catch (error) {console.error(`Failed to run main function: ${error}`); }};main().then(() =>process.exit(0)).catch((error:Error) => {console.error(`Failed to run script: ${error}`);process.exit(1); });
Will returns
BigNumber { _hex: '0x15', _isBigNumber:true }
Advanced Use
Developers seeking to make advanced customizations can find additional resources and extended documentation in the full documentation provided in the README.
If you have any questions or need further assistance, please don't hesitate to reach out on Discord.