Deposit & Withdraw
Let's build a bar chart to show the daily deposit and withdraw of the WBTC-USDC pool.

1.Choose Transaction data source.

2. Use Filter instruction.

Search all the transactions which have Withdraw(payer, receiver, isBaseToken, amount, lpTokenAm) and Deposit(payer, receiver, isBaseToken, amount, lpTokenAm) logs. You also want to limit the logs.address to the address of WBTC-USDC trading pair which is 0x2109F78

3. Use Project and the filter operator to put the logs into four buckets:

depositbase (deposit WBTC),
withdrawbase (withdraw WBTC),
depositquote (deposit USDC),
withdrawquote (withdraw USDC).
Below is what a Deposit log looks like. If the value of the 3rd parameter isBaseToken is true , it's a WBTC token; Otherwise, it's a USDC token.
Deposit 2000 USDC tokens into the WBTC-USDC pool
Now let's use filter to form the first bucket: depositbase : gather all the Deposit logs from WBTC-USDC pair (0x2109F78b4) and also make sure the 3rd parameter isBaseToken ($this.params.2.value) is true. The logic is demonstrated in the below screenshot.
In the same Project, you will do the same thing for withdrawbase, depositquote, withdrawquote
withdrawquote
depositquote
withdrawbase
What the data looks like now:
Don't forget to bring the blockTimetamp with you since we need it to show data over time.

4. Use a new Project instruction and reduce operator to sum up the value of the 4th parameter amount from all the logs in every transaction.

Since we don't know how many Withdraw or Deposit actions could exist in a single transaction, this is the safest way to make sure we don't miss any one of them. Similar to our naming convention the previous step, we will call them depositbase_amt, withdrawbase_amt, depositquote_amt, withdrawquote_amt. Here is an example of depositbase_amt
The reduce operator iterate through the depositbase (based on the previous step, this is an array that contains all the Deposit logs whose 3rd parameter isBaseToken is true) and sum up the value of the 4th parameter amount ($this.params.3.value). This basically gives you the total amount of base token deposit in one transaction.
In the same Project, we will do the same for withdrawbase_amt, depositquote_amt, withdrawquote_amt:
withdrawbase_amt
depositquote_amt
withdrawquote_amt
What the data looks like now:

5. Use a new Project instruction and tokenExchange to convert the values to USD:

In the above screenshot, we also took care of the decimals. If it's the base token WETH, we will divide the amount by 10^18; If it's the quote token USDC, we will divide the amount by 10^6.
What data looks like now:

6. Use Group to organize the data by day:

7. Plug the data into the charts and you are golden
🍾

Copy link
Contents