Skip to main content
Glama

ONEDeFi MCP Server

by JMadhan1
lending.cpython-311.pyc14.5 kB
� R\�h38��h�ddlZddlZddlmZddlmZeje��ZGd�d��Z dS)�N)�EthereumClient)� PolygonClientc�~�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z d�Z d �Z d �Z d �Z d �Zd �Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�LendingOperationszLending protocol operationsc�p�t��|_t��|_ddd�ddid�|_dS)N�*0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9�*0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B)�aave�compoundr �*0x8dFf5E27EA6b7AC08EbFdf9eB090F32ee9a30fcf)�ethereum�polygon)r�ethereum_clientr�polygon_client� protocols)�selfs �,/home/runner/workspace/defi_tools/lending.py�__init__zLendingOperations.__init__ sN��-�/�/���+�o�o��� E�H��� �D��  � �����c�z� |���dkr|�||||��S|���dkr|�||||��Sdd|��d�S#t$rF}t�dt |������dt |��d�cYd}~Sd}~wwxYw)zLend asset to a protocolr rF�Unsupported blockchain: ��success�errorzLending operation failed: N)�lower�_lend_ethereum� _lend_polygon� Exception�loggerr�str�r� blockchain�protocol�wallet_address�token�amount�es r� lend_assetzLendingOperations.lend_assets��� 7����!�!�Z�/�/��*�*�8�^�U�F�S�S�S��!�!�#�#�y�0�0��)�)�(�N�E�6�R�R�R�#(�3Z�j�3Z�3Z�[�[�[��� 7� 7� 7� �L�L�>�c�!�f�f�>�>� ?� ?� ?�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7����(�/A*�/A*�"A*�* B:�4;B5�/B:�5B:c�v� |���dkr|�|||��S|���dkr|�|||��Sdd|��d�S#t$rF}t�dt |������dt |��d�cYd}~Sd}~wwxYw)zLend on Ethereumr r F�Unsupported protocol: rzEthereum lending failed: N)r�_lend_aave_ethereum�_lend_compound_ethereumrrrr �rr#r$r%r&r's rrz LendingOperations._lend_ethereum(s��� 7��~�~���6�)�)��/�/���v�N�N�N����!�!�Z�/�/��3�3�N�E�6�R�R�R�#(�3V�H�3V�3V�W�W�W��� 7� 7� 7� �L�L�=�S��V�V�=�=� >� >� >�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7����(�.A(�.A(� A(�( B8�2;B3�-B8�3B8c �� |jdd}ddd�ddd�ddd�d d d�gd d d �g}|j�|d|t|��|dg���}|j�|||d���}|r4d|dd |||�|��||�|��d�d�Sddd�S#t$rF}t� dt|������dt|��d�cYd}~Sd}~wwxYw)zLend to Aave on Ethereumr r �asset�address��name�typer&�uint256� onBehalfOf� referralCode�uint16�deposit�function��inputsr4r5r��abi�args�0�r$� to_address�data�valueT)� lending_pool� estimated_apy)r�tx_hashr#� operationr&r%�aToken�metadataF�Transaction failedrzAave lending failed: N) rr�encode_function_call�int�send_transaction�_get_atoken_address� _get_aave_apyrrrr � rr$r%r&rF� deposit_abi� function_datarHr's rr,z%LendingOperations._lend_aave_ethereum6s���1 7��>�*�5�f�=�L� %�i�8�8�%�y�9�9�)�9�=�=�+�X�>�>� � "�"� � � �K�!�0�E�E���N��S��[�[�.�!�<�F���M� �*�;�;�-�'�"�� <���G�� I�#�&� &�!*�$�"�"�6�6�u�=�=�(4�)-�);�);�E�)B�)B�!�!� � � �$)�3G�H�H�H��� 7� 7� 7� �L�L�9��Q���9�9� :� :� :�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���s$�B0B8�3B8�8 D�;D�=D�Dc ��� |�|��}|sdd|��d�Sddd�gddd �g}|j�|d t|��g� ��}|j�|||d � ��}|r!d|dd|||||�|��d�d�Sddd�S#t $rF}t�dt|������dt|��d�cYd}~Sd}~wwxYw)zLend to Compound on EthereumFz Unsupported token for Compound: r� mintAmountr6r3�mintr;r<rr>rArBTr )�ctoken_addressrG)rrHr#rIr&r%�cTokenrKrLzCompound lending failed: N) �_get_ctoken_addressrrMrNrO�_get_compound_apyrrrr ) rr$r%r&rX�mint_abirTrHr's rr-z)LendingOperations._lend_compound_ethereumks���/ 7�!�5�5�e�<�<�N�!� _�#(�3]�V[�3]�3]�^�^�^�%1�)�D�D�E��"����H�!�0�E�E��Q�K��&�k�k�]�F���M� �*�;�;�-�)�"�� <���G�� I�#�&� *�!'�$�"�,�*8�)-�)?�)?��)O�)O�!�!� � � �$)�3G�H�H�H��� 7� 7� 7� �L�L�=�S��V�V�=�=� >� >� >�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���s)�B"�A;B"�B"�" C2�,;C-�'C2�-C2c�� |���dkr|�|||��Sdd|��d�S#t$rF}t�dt |������dt |��d�cYd}~Sd}~wwxYw)zLend on Polygonr Fr+rzPolygon lending failed: N)r�_lend_aave_polygonrrrr r.s rrzLendingOperations._lend_polygon�s��� 7��~�~���6�)�)��.�.�~�u�f�M�M�M�#(�3V�H�3V�3V�W�W�W��� 7� 7� 7� �L�L�<�C��F�F�<�<� =� =� =�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���s�.9�9� B �;B�>B �B c ��� |jdd}ddd�ddd�ddd�d d d�gd d d �g}|j�|d|t|��|dg���}|j�|||d���}|r d|dd |||dd�d�Sddd�S#t $rF}t �dt|������dt|��d�cYd}~Sd}~wwxYw)zLend to Aave on Polygonrr r1r2r3r&r6r7r8r9r:r;r<rr>rArBT)rFr")rrHr#rIr&r%rKFrLrzAave Polygon lending failed: N) rrrMrNrOrrrr rRs rr^z$LendingOperations._lend_aave_polygon�sx��0 7��>�)�4�V�<�L� %�i�8�8�%�y�9�9�)�9�=�=�+�X�>�>� � "�"� � � �K�!�/�D�D���N��S��[�[�.�!�<�E���M� �)�:�:�-�'�"�� ;���G�� I�#�&� &�!*�$�"�(4�&/�!�!� � � �$)�3G�H�H�H��� 7� 7� 7� �L�L�A��Q���A�A� B� B� B�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���s$�B B� B� C!�;C�C!�C!c�z� |���dkr|�||||��S|���dkr|�||||��Sdd|��d�S#t$rF}t�dt |������dt |��d�cYd}~Sd}~wwxYw)z!Withdraw lent asset from protocolr rFrrzWithdrawal operation failed: N)r�_withdraw_ethereum�_withdraw_polygonrrrr r!s r�withdraw_assetz LendingOperations.withdraw_asset�s��� 7����!�!�Z�/�/��.�.�x���PV�W�W�W��!�!�#�#�y�0�0��-�-�h���v�V�V�V�#(�3Z�j�3Z�3Z�[�[�[��� 7� 7� 7� �L�L�A��Q���A�A� B� B� B�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���r)c�v� |���dkr|�|||��S|���dkr|�|||��Sdd|��d�S#t$rF}t�dt |������dt |��d�cYd}~Sd}~wwxYw)z Withdraw from Ethereum protocolsr r Fr+rzEthereum withdrawal failed: N)r�_withdraw_aave_ethereum�_withdraw_compound_ethereumrrrr r.s rraz$LendingOperations._withdraw_ethereum�s��� 7��~�~���6�)�)��3�3�N�E�6�R�R�R����!�!�Z�/�/��7�7���v�V�V�V�#(�3V�H�3V�3V�W�W�W��� 7� 7� 7� �L�L�@��A���@�@� A� A� A�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���r/c��� |jdd}ddd�ddd�ddd�gd d d �g}|d krd dzdz nt|��}|j�|d|||g���}|j�|||d���}|r d|dd ||d�Sddd�S#t $rF} t �dt| ������dt| ��d�cYd} ~ Sd} ~ wwxYw)zWithdraw from Aave on Ethereumr r r1r2r3r&r6�to�withdrawr;r<�max���rr>rArBT)rrHr#rIr&r%FrLrzAave withdrawal failed: N) rrNrrMrOrrrr ) rr$r%r&rF� withdraw_abi�withdraw_amountrTrHr's rrez)LendingOperations._withdraw_aave_ethereum�st��* 7��>�*�5�f�=�L�%�i�8�8�%�y�9�9�!�9�5�5�� #�"����L�-3�e�O�O�a��f�q�j�j��V���O� �0�E�E� ��O��_�n�=�F���M� �*�;�;�-�'�"�� <���G�� I�#�&� &�!+�$�"� ���$)�3G�H�H�H��� 7� 7� 7� �L�L�<�C��F�F�<�<� =� =� =�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���s$�BB�B� C(�";C#�C(�#C(c�� g}|���dkrU|�|��}|�|��|�|��}|�|��nB|���dkr*|�|��}|�|��d|d�S#t $rF}t �dt|������dt|��d�cYd}~Sd}~wwxYw) z"Get lending positions for a walletr rT)r� positionsz!Failed to get lending positions: FrN) r�_get_aave_positions_ethereum�extend� _get_compound_positions_ethereum�_get_aave_positions_polygonrrrr )rr"r$rq�aave_positions�compound_positionsr's r�get_lending_positionsz'LendingOperations.get_lending_positions(s'�� 7��I����!�!�Z�/�/�!%�!B�!B�>�!R�!R��� � ��0�0�0�&*�%J�%J�>�%Z�%Z�"�� � �!3�4�4�4�4��!�!�#�#�y�0�0�!%�!A�!A�.�!Q�!Q��� � ��0�0�0�#�)�<�<� <��� 7� 7� 7� �L�L�E�S��V�V�E�E� F� F� F�$�s�1�v�v�6�6� 6� 6� 6� 6� 6� 6����� 7���s�B5B8�8 D�;D�=D�Dc�8�ddd�}|�||��S)z'Get aToken address for underlying token�*0x028171bCA77440897B824Ca71D1c56caC55b68A3�*0x030bA81f1c18d280636F32af80b9AAd02Cf0854e��*0xA0b86a33E6411D40Ecaa6C4A6E5d75d8b3c7FD68�*0x6B175474E89094C44Da98b954EedeAC495271d0F��get)rr%�atoken_mappings rrPz%LendingOperations._get_atoken_addressAs/��;g�:f� � ���!�!�%��/�/�/rc�6�ddd�}|�|��S)z'Get cToken address for underlying token�*0x39AA39c021dfbaE8faC545936693aC917d5E7563�*0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643r|r)rr%�ctoken_mappings rrZz%LendingOperations._get_ctoken_addressJs-��;g�:f� � ���!�!�%�(�(�(rc��dS)zGet current Aave APY for tokeng @�)rr%s rrQzLendingOperations._get_aave_apyR� ���src��dS)z#Get current Compound APY for cTokengffffff@r�)rrXs rr[z#LendingOperations._get_compound_apyWr�rc��gS)zGet Aave positions on Ethereumr��rr$s rrrz.LendingOperations._get_aave_positions_ethereum\� ��� rc��gS)z"Get Compound positions on Ethereumr�r�s rrtz2LendingOperations._get_compound_positions_ethereumar�rc��gS)zGet Aave positions on Polygonr�r�s rruz-LendingOperations._get_aave_positions_polygonfr�rN)�__name__� __module__� __qualname__�__doc__rr(rr,r-rr^rcrarerxrPrZrQr[rrrtrur�rrrrs,������%�%�  �  �  � 7� 7� 7� 7� 7� 7�37�37�37�j17�17�17�f 7� 7� 7�27�27�27�h 7� 7� 7� 7� 7� 7�,7�,7�,7�\7�7�7�20�0�0�)�)�)���� ��� ��� ��� ����rr) �os�logging�blockchain.ethereumr�blockchain.polygonr� getLoggerr�rrr�rr�<module>r�s��� � � � �����.�.�.�.�.�.�,�,�,�,�,�,� �� �8� $� $��a�a�a�a�a�a�a�a�a�ar

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JMadhan1/OneDefi-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server