Skip to content

Commit

Permalink
add valid conversion routes
Browse files Browse the repository at this point in the history
  • Loading branch information
prettyirrelevant committed Oct 16, 2024
1 parent 16700dc commit 91d014a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/bridgebloc/apps/conversions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from .views import (
CCTPTokenConversionInitialisationAPIView,
ValidTokenConversionRoutesAPIView,
TokenConversionAPIView,
TokenConversionsAPIView,
)

urlpatterns = [
path('conversions', TokenConversionsAPIView.as_view(), name='all-conversions-by-user'),
path('conversions/routes', ValidTokenConversionRoutesAPIView.as_view(), name='conversion-routes'),
path('conversions/cctp', CCTPTokenConversionInitialisationAPIView.as_view(), name='bridge-with-cctp'),
path('conversions/<str:uuid>', TokenConversionAPIView.as_view(), name='get-conversion'),
]
23 changes: 23 additions & 0 deletions backend/bridgebloc/apps/conversions/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
from typing import Any

from django.db import transaction
Expand All @@ -7,6 +8,7 @@
from rest_framework.generics import GenericAPIView, ListAPIView, RetrieveAPIView
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from bridgebloc.apps.accounts.permissions import IsAuthenticated
from bridgebloc.common.helpers import success_response
Expand All @@ -17,6 +19,27 @@
from .permissions import IsOwner
from .serializers import CCTPTokenConversionInitialisationSerializer, TokenConversionSerializer
from .types import ConversionMethod
from ...evm.types import ChainID


class ValidTokenConversionRoutesAPIView(APIView):
def get(self, request: Request, *args: Any, **kwargs: Any) -> Response: # noqa: ARG002
data: dict[str, Any] = defaultdict(lambda: defaultdict()) # pylint:disable=unnecessary-lambda

mainnet_chains = [chain for chain in ChainID if not chain.name.endswith('TESTNET')]
testnet_chains = [chain for chain in ChainID if chain.name.endswith('TESTNET')]

for source_chain in mainnet_chains:
for target_chain in mainnet_chains:
if source_chain != target_chain:
data[source_chain.name.lower()][target_chain.name.lower()] = ConversionMethod.CCTP

for source_chain in testnet_chains:
for target_chain in testnet_chains:
if source_chain != target_chain:
data[source_chain.name.lower()][target_chain.name.lower()] = ConversionMethod.CCTP

return success_response(data=data)


class TokenConversionAPIView(RetrieveAPIView):
Expand Down

0 comments on commit 91d014a

Please sign in to comment.