Skip to main content
Glama
routes_simple.cpython-313.pyc17.9 kB
� �s�h�A���SSKJrJrJr SSKJrJr SSKJrJrJ r J r J r SSK r SSK J r \ R"\5rSSKJr SSKJr SSKJr SS KJr SS KJr SS KJr \"5r\"5r\"5r\"5r \"5r\"5r!\RJ"S 5S5r&\RJ"S5S5r'\RJ"S5S5r(\RJ"S5S5r)\RJ"S5S5r*\RJ"SS/S9S5r+\RJ"SS/S9S5r,\RJ"SS/S9S5r-\RJ"SS /S9S!5r.\RJ"S"S /S9S#5r/\RJ"S$S /S9S%5r0\RJ"S&S/S9S'5r1\RJ"S(S/S9S)5r2\RJ"S*S/S9S+5r3\RJ"S,S/S9S-5r4\S.:Xa\Rj"S/S09 gg!\"a+r#\RIS \#35 SrSrSrSr SrSr!Sr#C#GN�Sr#C#ff=f)1�)�render_template�request�jsonify)�app�db)�User�Wallet� Transaction� Portfolio�ProtocolPositionN)�datetime)� DEXOperations)�LendingOperations)�YieldFarmingOperations)�PortfolioManager)� DeFiAIAgent)�PortfolioAnalyticsz$Could not import necessary modules: �/c��[S5$)z Landing pagez index.html�r���#c:\ONEDeFi\defimcp\routes_simple.py�indexr$s�� �<� (�(rz /dashboardc��[S5$)zDashboard pagezdashboard.htmlrrrr� dashboardr)s�� �+� ,�,rz /api-docsc��[S5$)zAPI documentation pagez api_docs.htmlrrrr�api_docsr.��� �?� +�+rz /ai-agentc��[S5$)zAI Agent interface pagez ai_agent.htmlrrrr� ai_agent_uir!3rrz /ai-featuresc��[S5$)zAI Features showcase pagezai_features.htmlrrrr� ai_featuresr#8s�� �-� .�.rz /api/v1/swap�POST)�methodsc ���[R"5n/SQnUHnX ;dM [SSU305S4s $ [(aT[R USUSUSUSUS UR S S 5UR S S 5S9n[U5$[SSSSRS/S-53USUR S S 5S.5$![ a<n[RSU35 [SS[U5S.5S4sSnA$SnAff=f![ aDn[RS[U535 [S[U5S.5S4sSnA$SnAff=f)zExecute DEX swap operation)�wallet_address� blockchain�token_in� token_out� amount_in�error�Missing required field: �r(r'r)r*r+�slippageg�?�protocol�uniswap)r(r'r)r*r+r/r0zSwap execution failed: FzSwap execution failed��successr,�details��NTz!Demo mode: Swap would be executed�0x��0�@�r3�message�tx_hashr(r0zSwap operation failed: �Internal server error�r,r4) r�get_jsonr�dex_ops� execute_swap�get� Exception�loggerr,�str�join��data�required_fields�field�result�es r�api_swaprM?s���)S����!��a��$�E�� ���+C�E�7�)K�L�M�s�R�R�%� �7� � �-�-�#�L�1�#'�(8�#9�!�*�-�"�;�/�"�;�/�!�X�X�j�#�6�!�X�X�j�)�<�.����v��&���>�������� � 3�4�5�"�<�0� �H�H�Z��;� �� ��� �� � �6�q�c�:�;��$�4�"�1�v� ��� ��� �� �S�� � �.�s�1�v�h�7�8��!8�S��V�L�M�s�R�R��S�sX�!D�D� D� AC�9D� D� 1D�D�D�D�D� E-�)9E(�"E-�(E-z /api/v1/lendc ��[R"5n/SQnUHnX ;dM [SSU305S4s $ [(a2[R USUSUSUSUS S 9n[U5$[SSSSRS/S-53USUSS.5$![ a<n[ RS U35 [S S [U5S.5S4sSnA$SnAff=f![ aDn[ RS[U535 [S[U5S.5S4sSnA$SnAff=f)zExecute lending operation)r'r(r0�token�amountr,r-r.r(r0r'rOrP)r(r0r'rOrPzLending execution failed: FzLending execution failedr2r5NTz$Demo mode: Lending would be executedr6r7r8r9r:zLending operation failed: r=r>) rr?r� lending_ops�lendrCrDr,rErFrGs r�api_lendrSmsw��&S����!��Z��$�E�� ���+C�E�7�)K�L�M�s�R�R�%� �;� �$�)�)�#�L�1�!�*�-�#'�(8�#9��w�-���>� *����v��&���A�������� � 3�4�5�"�<�0� ��,� �� ��� �� � �9�!��=�>��$�7�"�1�v� ��� ��� �� �S�� � �1�#�a�&��:�;��!8�S��V�L�M�s�R�R��S�sW�!C0�C0� C0� 0B'�:,C0�' C-�11C(�"C-�#C0�(C-�-C0�0 D>�:9D9�3D>�9D>z /api/v1/farmc��[R"5n/SQnUHnX ;dM [SSU305S4s $ USnUSnUSnUSn[R S US U35 S S [ R "5RS 53SUSU3USSSS/S.S.n[U5$![aDn[RS[U535 [S[U5S.5S4sSnA$SnAff=f)zFarm tokens for yield)r'r(� pool_addressrPr,r-r.r'r(rUrPzFarming request: z on T�0xfarmz %Y%m%d%H%M%SzSuccessfully farmed z tokens in pool z12.5%z$2.5M�COMP�SUSHI)�address�apy�tvl�rewards)r3r<r;� pool_infozFarming operation failed: r=r>r5N) rr?rrD�infor �utcnow�strftimerCr,rE) rHrIrJr'r(rUrP�responserLs r� farm_tokensrb�s1��#S����!��U��$�E�� ���+C�E�7�)K�L�M�s�R�R�%��.�/���,�'� ��N�+� ��h���� � �'��'7�t�J�<�H�I� ����� 1� :� :�>� J�K�L�-�f�X�5E�l�^�T�'���"�G�,� �  ���x� � �� �S�� � �1�#�a�&��:�;��!8�S��V�L�M�s�R�R��S�s(�!B0�B0�A4B0�0 C>�:9C9�3C>�9C>z"/api/v1/portfolio/<wallet_address>�GETc ���[(a#[RU5n[SU05$[SUSSS S S .S S SS ./SS.05$![a<n[R SU35 [SS[ U5S.5S4sSnA$SnAff=f![aDn[R S[ U535 [S[ U5S.5S4sSnA$SnAff=f)zGet portfolio information� portfoliozPortfolio fetch failed: NzFailed to fetch portfolio)rer,r4r5�`L�@�ETH�������@�@��@��symbolrP� value_usd�USDC�'� ��@�2025-01-01T00:00:00Z�r'�total_value_usd�tokens� last_updatedzPortfolio operation failed: r=r>)� portfolio_mgr� get_portfoliorrCrDr,rE)r'rerLs r� api_portfoliorw�s��S� �=� �)�7�7��G� �� �Y�7�8�8���&4�'/�#(�C�h�O�#)�U��R��%;�� � � ��� �� � �7��s�;�<��!%�8�"�1�v� ��� ��� ��* �S�� � �3�C��F�8�<�=��!8�S��V�L�M�s�R�R��S�sK� B�!A �B� B�1B �B�B� B�B� C#�9C�C#�C#z"/api/v1/positions/<wallet_address>c���SSSSSS.SSS S S S./n[S U05$![aDn[RS [ U535 [S[ U5S.5S4sSnA$SnAff=f)zGet DeFi positions�Aave�Lendingrm�10000z3.5%)r0�typerOrPrZ�Uniswap�LPzETH-USDC�5z8.2%� positionszPositions operation failed: r=r>r5N)rrCrDr,rE)r'�mock_positionsrLs r� api_positionsr��s��� S� ��V�w�_e� f�"�D�:�QT�]c� d� ��� �^�4�5�5�� �S�� � �3�C��F�8�<�=��!8�S��V�L�M�s�R�R��S�s�� A-�9A(�"A-�(A-z%/api/v1/transactions/<wallet_address>c��[RRSS[S9n[ [RRSS[S9S5nSSS S S S S .SSS SSS./n[ UUU[ U5S.5$![aDn[RS[U535 [ S[U5S.5S4sSnA$SnAff=f)zGet transaction history�page�)r|�per_page�2�dz0x123...�Swaprgrmz1.5z2024-01-15T10:00:00Z)r<r|� from_token�to_tokenrP� timestampz0x456...�Lend�5000z2024-01-14T11:30:00Z)r<r|rOrPr�)� transactionsr�r��totalzTransactions operation failed: r=r>r5N) r�argsrB�int�minr�lenrCrDr,rE)r'r�r��mock_transactionsrLs r�api_transactionsr��s���S��|�|�������4���w�|�|�'�'� �B�S�'�A�3�G�� #�F�%�U[�gl�|R� S�"�F�V�v�dz� {� ���-�� ��*�+�  � � �� �S�� � �6�s�1�v�h�?�@��!8�S��V�L�M�s�R�R��S�s�A9A<�< C �9C�?C �C z/api/v1/ai/portfolio-healthc���[R"5nURS5nURSS5nU(d[SS05S4$[(aT[R X5nU(aURS5(d[SS05S4$URS 05nO&US S S S S.SSSS./SS.n[ RS5 [(a-[RRU5n[SUS.5$[SS05S4$![aDn[ RS[U535 [S[U5S.5S4sSnA$SnAff=f)z!Get AI portfolio health diagnosisr'r(�ethereumr,zwallet_address is requiredr.r3zFailed to fetch portfolio datarerfrgrhrirjrmrnrorprqzGPortfolioAnalytics not available, using mock data for portfolio health.T)r3� diagnosis�AI Agent not availabler5zPortfolio health check failed: r=r>N)rr?rBr�portfolio_analyzerrvrD�warn�ai_agent�portfolio_doctor�diagnose_portfoliorCr,rE)rHr'r(�portfolio_result�portfolio_datar�rLs r�ai_portfolio_healthr� sp��)S����!�����"2�3���X�X�l�J�7� ���G�%A�B�C�S�H� H� � �1�?�?��[� �#�+;�+?�+?� �+J�+J���)I�J�K�S�P�P�-�1�1�+�r�B�N�#1�#+�$��(�K�%��X�N��!7��N� �K�K�a� b� �8� �1�1�D�D�^�T�I���&��� � �G�%=�>�?��D� D�� �S�� � �6�s�1�v�h�?�@��!8�S��V�L�M�s�R�R��S�s2�A D�A D�A0D� D� E*�&9E%�E*�%E*z/api/v1/ai/create-strategyc���[R"5nURSS5nURS5nURSS5nU(d[SS05S4$S nU(av[(aE[R X#5nU(a(URS 5(aURS 05nO&US S SSS.SSSS./SS.n[ RS5 [(a-[RRX5n[SUS.5$[SS05S4$![aDn[ RS[U535 [S[U5S.5S4sS nA$S nAff=f)z%Create AI-powered investment strategy�goalsr7r'r(r�r,zUser goals are requiredr.Nr3rerfrgrhrirjrmrnrorprqzHPortfolioAnalytics not available, using mock data for strategy creation.T)r3�strategyr�r5zStrategy creation failed: r=r>)rr?rBrr�rvrDr�r��strategy_sommelier�create_strategyrCr,rE)rH� user_goalsr'r(r�r�r�rLs r�ai_create_strategyr�9ss��*S����!���X�X�g�r�*� ����"2�3���X�X�l�J�7� ���G�%>�?�@�#�E� E��� �!�!�#5�#C�#C�N�#_� �#�(8�(<�(<�Y�(G�(G�%5�%9�%9�+�r�%J�N��'5�'/�#(�C�h�O�#)�U��R��%;�"��� � �f�g� �8��2�2�B�B�:�^�H���$��� � �G�%=�>�?��D� D�� �S�� � �1�#�a�&��:�;��!8�S��V�L�M�s�R�R��S�s+�AD(�"B6D(�D(�( E6�29E1�+E6�1E6z/api/v1/ai/chatc��[R"5nURSS5nURS5nURSS5nU(d[SS05S4$S nS nU(a�[(aE[R X#5nU(a(URS 5(aURS 05nO&US S SSS.SSSS./SS.n[ RS5 SSSS.SSSS./n[(a.[RRXU5n[SUS.5$[SS 05S!4$![aDn[ RS"[U535 [S#[U5S$.5S!4sS nA$S nAff=f)%zChat with AI assistantr;r7r'r(r�r,zMessage is requiredr.Nr3rerfrgrhrirjrmrnrorprqz;PortfolioAnalytics not available, using mock data for chat.�swapz100 USDCz 2024-01-01)r|rPr�rRz500 USDCz 2024-01-02T)r3rar�r5zAI chat failed: r=r>)rr?rBrr�rvrDr�r��chat_assistant�chatrCr,rE) rHr;r'r(r��transaction_historyr�rarLs r�ai_chatr�hs���2S����!���(�(�9�b�)�����"2�3���X�X�l�J�7� ���G�%:�;�<�c�A� A���"�� �!�!�#5�#C�#C�N�#_� �#�(8�(<�(<�Y�(G�(G�%5�%9�%9�+�r�%J�N��'5�'/�#(�C�h�O�#)�U��R��%;�"��� � �Y�Z� �:�L�Q��:�L�Q�#� � �8��.�.�3�3�G�M`�a�H���$��� � �G�%=�>�?��D� D�� �S�� � �'��A��x�0�1��!8�S��V�L�M�s�R�R��S�s+�AD7�"CD7�(D7�7 F�9F�:F�Fz/mcpc ��[R"5nSURS5SSURS5URS5S.S.n[U5$![ahn[ R S [U535 [SS [5;aWRS5OS S S [U5S.S.5S4sS nA$S nAff=f)zMCP JSON-RPC endpointz2.0�idTzMCP endpoint available�method�params)r3r;r�r�)�jsonrpcr�rKzMCP operation failed: � request_dataNi����zInternal error)�coder;rH)r�r�r,r5) rr?rBrrCrDr,rE�locals)r�rarLs r� mcp_endpointr��s�����'�'�)� ���"�"�4�(��3�&�*�*�8�4�&�*�*�8�4� �  ���x� � �� � �� � �-�c�!�f�X�6�7���,:�f�h�,F�,�"�"�4�(�D��+��A��� � � �� �� �s�AA� C �$AC�C �C �__main__T)�debug)6�flaskrrrrr�modelsrr r r r �loggingr � getLogger�__name__rD�defi_tools.dex_operationsr�defi_tools.lendingr�defi_tools.yield_farmingr�defi_tools.portfoliorr�r�portfolio_analyticsrr@rQ� farming_opsrur�� ImportErrorrL�warning�routerrrr!r#rMrSrbrwr�r�r�r�r�r��runrrr�<module>r�s���3�3��I�I��� � � �8� $���7�4�?�5�$�6��o�G�#�%�K�(�*�K�$�&�M��}�H�+�-�����3��)��)����<��-��-����;��,��,����;��,��,����>��/��/� ���>�F�8�,�+S�-�+S�Z���>�F�8�,�(S�-�(S�T���>�F�8�,�%S�-�%S�N��� /�%��A�S�B�S�@��� /�%��A� S�B� S���� 2�U�G�D�S�E�S�2��� (�6�(�;�+S�<�+S�Z��� '�&��:�,S�;�,S�\��� �v�h�/�4S�0�4S�n���6�F�8�$��%��> �z���G�G�$����K �� �N�N�9�!��=�>��G��K��K��M��H�����s�AH � H=� H8�8H=

Latest Blog Posts

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