Coder Social home page Coder Social logo

frontend's Introduction

🌟 Soroswap Frontend @ Soroban Preview 10🌟

Welcome to Soroswap, a decentralized exchange (DEX) that draws inspiration from the Uniswap V2 protocol and is specifically tailored for the Soroban network.

Before you begin, ensure you have met the following requirements:

  • docker >= v24.0.2
  • Freighter Wallet v5.6.3 Please use this version. You can have an intependent environment following the instructios in this post

🛠 Setting Up Soroswap 🛠

  1. Clone the Repository

    git clone https://github.com/soroswap/frontend.git
    cd frontend
  2. Set Up Environment Variables

    Copy the .env.example file to create a new .env file:

    cp .env.local.example .env

    Now, edit the .env file and provide the NEXT_PUBLIC_BACKEND_URL, NEXT_PUBLIC_SOROSWAP_BACKEND_API_KEY and NEXT_PUBLIC_TEST_TOKENS_ADMIN_SECRET_KEY variables. This will tell the frontend where to look for:

    • the list of known tokens
    • the SoroswapFactory address
    • the SoroswapRouter address
    • the admin key for token minting

    If you are following the instructions in https://github.com/soroswap/core in order to deploy the smart contacts in your local environment and serve the API. you should have:

    NEXT_PUBLIC_BACKEND_URL=http://localhost:8010

    If you don't want to use the backend, you should also set the following variable:

    NEXT_PUBLIC_SOROSWAP_BACKEND_ENABLED=false

    Also, the variable NEXT_PUBLIC_TEST_TOKENS_ADMIN_SECRET_KEY should be the same as the one that deployed the tokens in the core repository.

    If you are ready for production, you can take Futurenet Contracts information from https://api.soroswap.finance and just do

    cp .env.production.example .env

    ❗️❗️ Note that some Futurenet RPC's might not have the same version, so we recomend you to connect to a local quickstart node following the instructions in https://github.com/soroswap/core; and setting up your Freighter Wallet as in step 6.

  3. Start Docker

    Navigate to the the run.sh script inside the docker folder

    bash docker/run.sh

    This script will set up and start the Docker containers required for Soroswap.

  4. Install the Dependencies

    After the Docker container is up, you will be inside the root folder on the container. Then, install the dependencies using Yarn:

    yarn install
  5. Run the Development Instance

    Now you are ready to start the development instance. Run the following command:

    yarn dev

    This will start the Soroswap development instance.

  6. Configure your Freigher Wallet

    For Standalone network

    Name Local Standalone
    HORIZON RPC URL http://localhost:8000
    SOROBAN RPC URL http://localhost:8000/soroban/rpc
    Passphrase Standalone Network ; February 2017
    Friendbot http://localhost:8000/friendbot
    Allow HTTP connection Enabled
    Switch to this network Enabled

    For Futurenet network

    Name Local Futurenet
    HORIZON RPC URL http://localhost:8000
    SOROBAN RPC URL http://localhost:8000/soroban/rpc
    Passphrase Test SDF Future Network ; October 2022
    Friendbot http://localhost:8000/friendbot
    Allow HTTP connection Enabled
    Switch to this network Enabled

    ** Important:** You should also do: Preferences> Allow experimental mode

  7. Last, but not least, add some lumens to your Freighter wallet!

    Do it directly on the wallet or use:

    For Standalone: http://localhost:8000/friendbot?addr=<your address> For Futurenet, visit: https://laboratory.stellar.org/#create-account

🚀 Congrats! 🚀

You have successfully set up Soroswap on your local machine! Start swapping, pooling, and exploring the possibilities of decentralized finance (DeFi) on the Soroban network.

🧪🔨 Testing 🧪🔨

To execute the tests, you must first start the development container. To do this, run the following command from your host machine:

bash docker/run.sh

Once the development container is running, you can install the dependencies for the tests by running the following command:

## 🧪🔨 Testing 🧪🔨
To execute the tests, you must first start the development container. To do this, run the following command from your host machine:

```bash
bash docker/run.sh

Once the development container is running, you can install the dependencies for the tests by running the following command:

yarn install

Finally, to run the tests, run the following command from within the development container:

yarn test

This will run all of the unit and integration tests for the project.

The tests are written using Vitest & testing-library.

For more information on Vitest, please see the Vitest documentation: https://vitest.dev/.

For more information on Testing Library, please see the Testing Library documentation: https://testing-library.com/docs/react-testing-library/intro/

Contributing

If you find a bug or have a feature request, please create an issue or submit a pull request. Contributions are always welcome!

License: MIT

Acknowledgments

Special thanks to the Uniswap team for providing the base protocol on which Soroswap is built.
Thank you to the Stellar Community for the continuous support.


Made with ❤️ by the Soroswap Team.

frontend's People

Contributors

abstract829 avatar benjaguiloff avatar chopan123 avatar dependabot[bot] avatar esteblock avatar joaquinsoza avatar josefredes avatar jtschuwirth avatar mattpoblete avatar the-syndrome avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

frontend's Issues

Swap: Modal

Add a review swap modal, same as the one in uniswap for now. should popup after clicking swap button, if #70 is already working the swap function should be called after this popup

Image

i think this same modal changes after to a waiting for confirmation ( waiting for the user to sign the transaction in the wallet) and then it turns into a transaction submitted, so research how uniswap modal works, we should bring the logic to our app

Please refer to uniswap interface for the styled components and how the component is compose. I've been running this project locally to see the files and its workings.

Add CommonBasses.tsx from uniswap

The common bases file shows up in the token selector modal as the "most used or base tokens"

Image

the one with ETH, DAI, USDC, etc

just get the files from uniswap interface, fix the styled css and show it in the token selector

useTokenFromActiveNetwork -> Search token

In the search currency modal, when you type and address the app should look for the token information in the blockchain

The function is already there and its being used, but it returns null it should return a new TokenType object with its information

src/hooks/useTokens.tsx Line: 82

In this line there is the function useTokenFromActiveNetwork, should look for the token information (id, address, symbol, name)

There is a lot of commented code from the uniswap interface, deleted if there is no use to it

getExpectedInputAmount(contract_id, token0, token1, amount1) -> int:

create function getExpectedInputAmount(contract_id, token0, token1, amount1) -> int: Given contract_id (pair contract), token0 contract address, token1 contract address and amount for token1, it returns the amount0 a user has to input in order to receive the amount1 when swapping.

(Liquidity): calculatePoolTokenOptimalAmount(pairAddress, tokenAddress, inputAmount

Create function calculatePoolTokenOptimalAmount(pairAddress, tokenAddress, inputAmount → Calculate) optimalOtherAmount Given a contract_id (I mean pair contract address) an amount and a token Address it returns an integer that indicates what’s the optimal amount of the other token in the pair contract to deposit.
Check github preriphery contracts and uniswap sdk https://github.com/Uniswap/v2-sdk/
Write this in a good way.

Liquidity Pools Add liquidity

V2 Provide liquidity

The add liquidity button should take you to this screen, where you can select 2 tokens and provide liquidity to them or create the pair if it doesnt exist, the settings menu is exactly the same as #68

Image

You should be able to make it work right away, provide liquidity old component is already working, see how uniswap function works too see if we can improve ours

Please refer to uniswap interface for the styled components and how the component is compose. I've been running this project locally to see the files and its workings.

Error: Handle error when contract does not exist

How to replicate:

  • Deploy in Futurenet
  • Configure your wallet to use Futurenet in localhost:8000
  • Run quistart node with Standalone in port 8000
  • Try to use Soroswap

Current: Nothing happens, there is only an error in the console

error: HostError
Value: Status(HostStorageError(AccessToUnknownEntry))

What we want:
Warn the user

deposit(tokenAddress0, tokenAddress1, amount0, amount1)->reponse

Create function deposit(tokenAddress0, tokenAddress1, amount0, amount1)->reponse to make user sign transaction and deposit the given amounts It returns a response object (a json) which indicates if the transaction was successful or if it has been an error.

tokenBalance (tokenAddress, userAddress?) -> int/bigint:

Create a function tokenBalance (tokenAddress, userAddress?) -> int/bigint: Given a token address it returns a balance for the account on context. If the user_address is set, look the balance of the user, otherwise, use the address in the context.

Transaction Submitted Modal

Dependant of #71

This modal will be used in multiple situations, every time a transaction is submitted to the blockchain, for now it should show after Swapping and providing liquidity

Please refer to uniswap interface for the styled components and how the component is compose. I've been running this project locally to see the files and its workings.

createTrustline(tokenAddress) -> response:

Create function createTrustline(tokenAddress) -> response: Given a token address creates a trustline for the account on context. It asks user to sign the trustline creation for the token. It returns a response object (a json) which indicates if the transaction was successful or if it has been an error.

Swap.tsx:

In CArd on file Swap.tsx:
It should have 2 dropdowns with its corresponding input fields
first dropdown should have all tokens
second dropdown should have the tokens available to swap with
If you modify one input field, the other input field should change using getInputAmount() or getExpectedInputAmount()
Button should create trustline if output token doesn’t have a trustline :)
Button calls swap() function

Open Token Modal after connecting wallet for the first time

Hay un error que al conectar la wallet por primera vez y luego abrir el modal de los tokens se cae al montar el componente, si se monta el componente antes de conectar la wallet y luego la conecto ahi funciona bien

  • Reproducir
  • Entender por qué
  • Solucionar

tokenBalances(userAddress??) -> Array(int/bigint):

  • Create function tokenBalances(userAddress??) -> Array(int/bigint): Iterates from the tokens.json lists and returns the balances of those tokens for the given account or the account in context
  • use this function to show a list of balances in Balances.tsx:

ProvideLiquidity.tsx:

In Card on file ProvideLiquidity.tsx:

  • It should have 2 dropdowns with its corresponding input fields
  • first dropdown should have all tokens
  • second dropdown should have the tokens available to add liquidity with
  • If you modify one input field, the other input field should change using calculatePoolTokenOptimalAmount() function
  • Button to add liquidity and send transaction that calls deposit function

user balance below the token selector

selectedCurrencyBalance const is hardcoded to 1000 there is commented code on what it should do

  const selectedCurrencyBalance = 1000 //useFormattedTokenBalance(currency?.token_address, address)

if useFormattedTokenBalance is used, when you connect the wallet immediately after loading the website it shows an error... this should be fixed

file

src/components/currencyInputPanel/SwapCurrencyInputPanel.tsx

max button should also work and set the input amount to the max possible amount, if its XLM it should count for the fees

mintTokens(address, amount) -> response:

Create function mintTokens(address, amount) -> response: Given a token address and an amount, it mints the token for the account on context. It returns a response object (a json) which indicates if the transaction was successful or if it has been an error.

Liquidity Pools Main Section

This section should show your open positions (LP Tokens), i like how the liquidity pools are showed in uniswap, we can do a combination between V3 and V2.

V3 Pools section

Image

With the V2 pools warning about the fees below the pools and without those 2 other options

Image

Please refer to uniswap interface for the styled components and how the component is compose. I've been running this project locally to see the files and its workings.

swap()

create function swap() that allow user to sign and send tx to blockchain

Mint.tsx:

In Card on file Mint.tsx:
Update Dropdown to show all tokens
Button on bottom should call functions: createTrustline() and mintTokens()
Verify input amount is positive and integer.

Sort tokens with balances

There used to be a function that sorts the tokens with balances to show them at the beginning of the list in the Token Selector modal. It was taken out because it generated problems while rendering the app...

Needs to find another way to sort the tokens and show the ones with balances first

Add second token selector to swap

Add second token selector to the swap section

Image

Image

  • Add inverse button
  • Add Second token input/selector
  • Add Swap Button

Please refer to uniswap interface for the styled components and how the component is compose. I've been running this project locally to see the files and its workings

Swap: Information Component

Add this swap information component

Image
(From 1 DERC = 0.00008 ETH to Order Routing)

This components appear after two tokens have been selected and it shows information about the swap; The component can be closed or open, it shows the conversion (x PYR = x ETH) and if clicked, it shows the other way around

Network fees, Price Impact, Minimum output, Expected output

Please refer to uniswap interface for the styled components and how the component is compose. I've been running this project locally to see the files and its workings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.