Code Monkey home page Code Monkey logo

quanto-dimensions's Introduction

CodeQL Discord Twitter Follow GitPOAP Badge

Kwenta

A dApp enabling derivatives trading โ€” powered by the Synthetix protocol.

The decentralized trading UI is available at kwenta.eth.limo.

ENS link: kwenta.eth.

The latest IPFS hash can be found under releases.

Contributing

Kwenta welcomes contributors. Regardless of the time you have available, everyone can provide meaningful contributions to the project by submitting bug reports, feature requests or even the smallest of fixes! To submit your contribution, please fork, fix, commit and create a pull-request describing your work in detail. For more details, please have a look at the Contribution guidelines.

Tech stack

  • Next.js
  • React
  • Redux
  • Kwenta SDK
  • Styled-Components

Ethereum stack

Development

Install dependencies

pnpm install

Set up environment variables

Copy the .env.local.example file in the packages/app directory to .env.local (which will be ignored by Git):

cd packages/app
cp .env.local.example .env.local

Then, open .env.local and add the missing environment variables:

Required:

  • NEXT_PUBLIC_PROVIDER_ID - Specifies the default provider, options are INFURA or BLAST_API
  • NEXT_PUBLIC_INFURA_PROJECT_ID - Infura project id (get it from infura.io) or
  • NEXT_PUBLIC_BLASTAPI_PROJECT_ID - Blast API project id (get it from blastapi.io)
  • NEXT_PUBLIC_SOCKET_API_KEY - Socket API key (get it from socket.tech
  • NEXT_PUBLIC_SATSUMA_API_KEY - API key for Satsuma subgraph queries
  • NEXT_PUBLIC_THEGRAPH_API_KEY - API key for The Graph's decentralized service
  • NEXT_PUBLIC_DEFAULT_PRICE_SERVICE - Specifies the default price server, options are KWENTA or PYTH
  • NEXT_PUBLIC_SERVICES_PROXY - Specify Kwenta proxy server

Run

cd packages/app
pnpm dev

Open http://localhost:3000 to view it in the browser.

Build

cd packages/app
pnpm build
pnpm start

Unit Testing

cd packages/app
pnpm test:jest

For unit tests we use a combination of Jest and React Testing Library

Page tests should be added to the testing folder at the root as it is not possible to co-locate tests and pages in nextjs. Other tests should be co-located in a __tests__ folder next to their related file.

Contact

Join the community on the Kwenta Discord server!

quanto-dimensions's People

Contributors

flocqst avatar jaredborders avatar tommyrharper avatar

Watchers

 avatar  avatar

Forkers

flocqst

quanto-dimensions's Issues

๐Ÿงถ Compile Time Ballooning

Description

Compile time increases drastically when certain functionality and dependencies are added.

For example, adding toUint() to each int type and to256() to int128/uint128 types results in a huge increase in time to compile.

Troubleshooting

Flattening the src/UnitTypes.sol file results in a big (~5000 lines of code) contract but removing the functions and dependencies that balloon compile time only slightly reduce the flatten contract size (by a few hundred lines). However, removing the latter results in significantly shorter compile times.

Internal Discussion

Confirmed: at any commit I have checked out and tried compiling in the past (this one and this one too), compile time is very long (as expected).

However, I found that if you deleted the test/ directory, compile time goes down to <1s.

I used forge flatten src/UnitTypes.sol --output flattened to force all of the imports into one file just to see what that looked like. As expected, the file was ~5000 lines (4 directories * 6 directories * ~200 lines per nested directory == 4800). It is interesting to check out yourself bc when it flattens everything; it enumerates each add so you end up seeing:

using {
    add_23 as +,
    and2_23 as &,
    sub_23 as -,
    (...)
} for USDPerQuantoUint256 global;

What is more interesting is that looking at the latest commit (which compiles and works ~quickly <10s), the flattened output is still nearly 5000 lines.

So, what is going on?

What I suspect (and hopefully will confirm) is that since everything is file level (i.e., none of this code is in a contract or library outside of the known SafeCasting), each time there is a dependency in the src/ contracts, the amount of "work" to resolve it increases exponentially. So, let's say we import BaseInt128, which then imports BaseInt256, which then imports BaseQuantoPerUSDInt256, and so on; it eventually resolves everything (as we see in the flattened contract), but it does this without "caching" it. Also, the dependency graph doesn't increase linearly when you add a single dependency; it is more like a quadratic, which is why we see the compile time balloon quite suddenly.

There are still a bunch of questions I have about this; however, what I think might actually work is this:

Define each type (i.e. BaseInt128) as before, however, remove all outside dependencies (i.e. do not define yet how a BaseInt128 type interacts with a USDInt128 type in the helper file. Once this has been done for each type, then define a library (or libraries) that specify differing type interactions. Call this Interactions or something. The library will, much more efficiently, manage dependencies and not result in the crazy dependency tangle that has to be resolved over and over.

(also, a lot of these "intuitions" are also coming from me removing things here and there, keeping a single test, etc etc, and testing out compile times)

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.