---
# System prepended metadata

title: Workshop AmsterDOT

---

# Workshop AmsterDOT

We build a trade page for a Basilisk XYK pool and display any price movement in a graph. This graphs shows the historical and current spot price.

**Conceptual tree**

- UI
    - XYK Pool
        - High level understanding
            - AMM
            - asset pairs
        - ID of pool
            - deterministic
            - getId() exposed in RPC
        - Read current state of pool
            - data structure in pallet
                - balances
                - tokens
            - calculate spot price of pool 
                - forumla
                - implementation in RUST
                - how it is exposed in JS through WASM
    - Call extrinsic
      
        - Parameters
            - decide on parameters that will pass trade limits
                - enough slippage
                - min/max out
                - less than 1/3rd of pool in trade
            - otherwise errors
                - how to read them (module, index parsing)
                - substrate errors
                - pallet errors
                    - common one: min/max
        - cost structure of extrinsic
            - weight
            - protocol fee
    - Graph/history of prices
        - extrensic calls move the spot price
        - current price (discussed above)
        - historical price/asset balances for pool ID
            - high level architecture indexer/processor
            - processor strategy
                - which events
                - finality on blocks
                - implementation of handler
                - custom starting block for processing
            - graphql endpoint
                - show the playground
                - example queries
                    - explain built in filtering methods (etc.)
                    - takeaway task from the workshop - figure out historical data bucketing in a proper way
        
            
        


## Call Buy on pool (we wanna do sell)
Dependencies: 
* custom React app (create-react-app)
* WASM library (first calc manually, then import wasm + typedef)
* Basilisk API (no running of a testnet, just a slim processor from subsquid template)
* PolkadotJS SDK + PolkadotJS apps
    * verify chain state vs implmentation in react
    * monitor events and block production
    * send extrinsics
    * show concepts in apps before implementing

Call extrensics on Basilisk XYK Pool through an UI.
Understand the parameters to avoid errors.
* How to calculate spot price
    * Query storage for balances of pool (Basilisk RPC)
        * Understanding storage representation. Maybe look at RUST code.
    * How to get pool id for asset ids (Basilisk RPC)
        * Maybe RUST code, explaining how pools are deterministic?
    * How to use WASM library 
        * Definitely showing RUST code to compare.
        * https://github.com/galacticcouncil/HydraDX-wasm/blob/main/src/lib.rs#L20-L26

Callback function for .signAndSend
How to translate errors into proper messages.
Different phases of transaction (eg. tx status).
"Weights" or transaction ordering. (paymentInfo)
Block hash of finalized. What is reordering (briefly).

Querying graphql endpoint for historical balances to calculate spotprice in UI. (diff between @client fields and remote/processor fields).

Note: we won't have "active account" fetching for the polkadot webwallet, instead hardcode account id.

## Graph
Dependencies:
* subsquid framework
* offer working API/processor/indexer as NPX starter

Data of historical balances for given pool id. (someone can transfer to the pool loosing their asset).
High level architecture of indexer and processor.
Writing the processor (new frameworkstyle without manifest) for this task.
Interacting with GRAPHQL endpoint. (show the playground)


### Debriefing

#### Learning objectives

dWe'll build a web3 app for the Basilisk AMM to execute trades and view historical price movements. Join this comprehensive workshop to acquire hands-on experience interacting with polkadot based chains and leverage this foundation to build future products (such as an arbitrage bot). Among others, we'll learn how to read and navigate RUST code, identify emitted events and build effective strategies to process data, precompute parameters for trading, basics of GraphQL and writing resolvers in React.

    * writing a resolver
    * basics of GraphQL
    * polkadotjs
    * casting data types
    * parsing errors
    * building web3 app for a polkadot based chain in react
    * read chain data
    * data structure for assets on basilisk (native/non-native)
    * read rust code and navigate through pallets
    * identify (emitted) events in source code
    * develop a strategy for processing data
    * AMM pools on basilisk
    * calculating spot-price in clients with same accuracy as runtime (WASM library)
    * interacting with the blockchain by executing extrinsics
    * AMM trading buy/sell assets
    * precompute parameters for trading
    * transaction flow
    * fee calculation for trades
    * setting up an indexer (high level)
    * writing a processor for historical balances
    * creating a graph for historical spot prices of an AMM pool

    

* storage reading
    * current
    * historical
        * processor
* custom pallet
    * navigating through source code
    * interacting using extrinsics
* transaction flow/states

=> use this for: 
* arbitrage bot
* cross chain swap aggregator


# Content delivery

Slide deck for workshop.
> Do not forget to incorporate insights from workshop before releasing it to the public.

High level blogpost with links (substack? medium?).

