Vineet
2023/02/15
Vineet’s Model Spotlight blog series is designed to highlight models deployed on the Credmark platform. Some will be highlighted because they’re generally useful, some because they are complicated and require some background, and others simply because Vineet finds them interesting.
These models are developed using the Credemark Model Framework (CMF). Model concept and reference docs are available here.
Inflow is defined as the amount of a token transferred into an account and outflow is defined as the amount of a token transferred from an account. NetFlow is the difference between inflow and outflow over a period of time.
For example, if 100 ETH were sent to an exchange account address and 150 ETH were withdrawn that day, then the NetFlow is -50 ETH indicating a net reduction in the on-exchange balance of ETH.
If the NetFlow value is above 0, it indicates that the volume of the token flowing into the account is greater than the volume that has flowed out of the account. If the value is below 0, it indicates the opposite.
NetFlow can provide valuable insights into the movement of funds within the cryptocurrency ecosystem. By tracking the flow of funds in and out of a wallet, users can gain a better understanding of how their own transactions fit into the larger picture of cryptocurrency usage and adoption.
The flow of funds can also be useful for identifying trends and patterns in cryptocurrency usage, such as which coins and tokens are gaining or losing popularity, which exchanges or platforms are being used most frequently, and which addresses or entities are the most active in terms of transactions.
This model takes 4 parameters: address/symbol, netflow_address, window & include_price.
This model outputs NetFlow, inflow, and outflow. It also includes the price value of each if not disabled explicitly in the input.
The best way to understand how to use a model is by example. Here are three.
Run the model using the CMF
$ credmark-dev run token.netflow-window -i '{"symbol": "AAVE", "window": "1 week", "netflow_address": "0x4da27a545c0c5b758a6ba100e3a049001de870f5"}'
Run the model using the DeFi API
$ curl -X 'POST' \
'https://gateway.credmark.com/v1/model/run' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H "Authorization: Bearer $CREDMARK_API_KEY" \
-d '{"slug": "token.netflow-window", "chainId": 1, "blockNumber": "latest", "input": {"symbol": "AAVE", "window": "1 week", "netflow_address": "0x4da27a545c0c5b758a6ba100e3a049001de870f5"}}'
{
"slug": "token.netflow-window",
"version": "1.4",
"chainId": 1,
"blockNumber": 16333134,
"output": {
"inflow": 39327942334209260000000,
"inflow_scaled": 39327.94233420926,
"outflow": 6351674908189999000000,
"outflow_scaled": 6351.674908189999,
"netflow": 32976267426019300000000,
"netflow_scaled": 32976.2674260193,
"price_last": 67.1551635440603,
"inflow_value_last": 2641074.3993051955,
"outflow_value_last": 426547.76723820355,
"netflow_value_last": 2214526.6320669944,
"from_block": 16282960,
"from_timestamp": 1672227011,
"to_block": 16333134,
"to_timestamp": 1672831799,
"address": "0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9"
},
"dependencies": {...}
}
In the output above, you can see that the model ran at block number 16333134 which was the latest block available at that time.
Staked AAVE’s NetFlow from 1672227011 (Wednesday, December 28, 2022 11:30:11 AM UTC) to 1672831799 (Wednesday, January 4, 2023 11:29:59 AM UTC) is approx 32,976 AAVE valued at $2,214,526.
Last week, $2.6M worth of AAVE was staked (inflow_value_last) and $0.4M worth of AAVE was unstaked (outflow_value_last). As the NetFlow is positive, we can conclude that a lot more AAVE is getting staked than unstaked.
ETH / USDT (0.05%) pool’s contract is deployed at 0x11b815efb8f581194ae79006d24e0d814b7697f6
USDC / USDT (0.01%) pool’s contract is deployed at 0x3416cf6c708da44db2624d63ea0aaef7113527c6
Since we need to run the same model but for 2 different inputs, we can use the compose.map-inputs model to get the results in a single request. It is a utility model which runs the same model for a list of inputs.
We need to get NetFlow for 2022, so we’ll run the model at block number 16308189 (Dec-31-2022 11:59:59 PM +UTC) with a window of “1 year”. We can speed up the model by excluding price as USDT is stablecoin and we can assume its price to be $1. In order to do that, just set “include_price” parameter in the input to “false”. Despite the very large amount of data needed to run this model, it typically executes in 25-30 seconds.
Run the model using the CMF
$ credmark-dev run compose.map-inputs -b 16308189 -i '{"modelSlug": "token.netflow-window", "modelInputs": [{"symbol": "USDT", "window": "1 year", "netflow_address": "0x11b815efb8f581194ae79006d24e0d814b7697f6", "include_price": false}, {"symbol": "USDT", "window": "1 year", "netflow_address": "0x3416cf6c708da44db2624d63ea0aaef7113527c6", "include_price": false}]}'
Run the model using the DeFi API
$ curl -X 'POST' \
'https://gateway.credmark.com/v1/model/run' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H "Authorization: Bearer $CREDMARK_API_KEY" \
-d '{"slug": "compose.map-inputs", "chainId": 1, "blockNumber": 16308189,
"input": {"modelSlug": "token.netflow-window", "modelInputs": [{"symbol": "USDT", "window": "1 year", "netflow_address": "0x11b815efb8f581194ae79006d24e0d814b7697f6", "include_price": false}, {"symbol": "USDT", "window": "1 year", "netflow_address": "0x3416cf6c708da44db2624d63ea0aaef7113527c6", "include_price": false}]}}'
{
"slug": "compose.map-inputs",
"version": "0.0",
"chainId": 1,
"blockNumber": 16308189,
"output": {
"results": [
{
"input": {
"symbol": "USDT",
"window": "1 year",
"netflow_address": "0x11b815efb8f581194ae79006d24e0d814b7697f6",
"include_price": false
},
"output": {
"inflow": 14813498973511786,
"inflow_scaled": 14813498973.511786,
"outflow": 14806432901044314,
"outflow_scaled": 14806432901.044313,
"netflow": 7066072467472,
"netflow_scaled": 7066072.467472,
"price_last": null,
"inflow_value_last": null,
"outflow_value_last": null,
"netflow_value_last": null,
"from_block": 13916166,
"from_timestamp": 1640995203,
"to_block": 16308189,
"to_timestamp": 1672531199,
"address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
},
"error": null
},
{
"input": {
"symbol": "USDT",
"window": "1 year",
"netflow_address": "0x3416cf6c708da44db2624d63ea0aaef7113527c6",
"include_price": false
},
"output": {
"inflow": 23495379228809476,
"inflow_scaled": 23495379228.809475,
"outflow": 23590007373710024,
"outflow_scaled": 23590007373.710026,
"netflow": -94628144900546,
"netflow_scaled": -94628144.900546,
"price_last": null,
"inflow_value_last": null,
"outflow_value_last": null,
"netflow_value_last": null,
"from_block": 13916166,
"from_timestamp": 1640995203,
"to_block": 16308189,
"to_timestamp": 1672531199,
"address": "0xdac17f958d2ee523a2206206994597c13d831ec7"
},
"error": null
}
]
},
"dependencies": {...}
}
In the result above, you can see the outputs for each pool. As we set include_price to false, the price values in the output are returned as “null”.
ETH / USDT (0.05%)’s NetFlow of USDT is approx 7M
USDC / USDT (0.01%)’s NetFlow of USDT is approx -95M
This indicates that USDT reserve of the USDC pool has decreased by 95M and ETH pool’s increased by 7M. The ETH pool performed magnitudes better than the USDC pool last year. Does it mean the ETH pool is a better investment opportunity for 2023? I am leaving it to you to figure out. Let’s move on to the next example.
Many of the tokens that you come across have a fixed total supply, but for some tokens it is variable. Tokens are burned and minted.
The amount of burning and minting of a token can be interesting because it can provide information about the overall demand for the token, which can be used to make trading decisions. If burning is happening, it could indicate that the token is becoming more scarce, which could lead to an increase in its value. Conversely, if minting is happening, it could indicate that the token's value is decreasing, which could lead to a decrease in its value.
One such token is DAI, a stablecoin by MakerDAO. DAI is minted when users borrow against locked collateral, and it is burned when loans are repaid. We can use this NetFlow model to track the minting and burning. When a token is minted it gets transferred from the ZERO address (0x0000000000000000000000000000000000000000) to the receiver and vice versa when the token is burned.
Let’s run this model for the ZERO NetFlow address.
Run the model using the CMF
$ credmark-dev run token.netflow-window -i '{"symbol": "DAI", "window": "1 hour", "netflow_address": "0x0000000000000000000000000000000000000000", "include_price": false}'
Run the model using the DeFi API
$ curl -X 'POST' \
'https://gateway.credmark.com/v1/model/run' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H "Authorization: Bearer $CREDMARK_API_KEY" \
-d '{"slug": "token.netflow-window", "chainId": 1, "blockNumber": "latest", "input": {"symbol": "DAI", "window": "1 hour", "netflow_address": "0x0000000000000000000000000000000000000000", "include_price": false}}'
{
"slug": "token.netflow-window",
"version": "1.4",
"chainId": 1,
"blockNumber": 16333284,
"output": {
"inflow": 13144482419958000000000000,
"inflow_scaled": 13144482.419958,
"outflow": 9616499555577000000000000,
"outflow_scaled": 9616499.555577,
"netflow": 3527982864381000000000000,
"netflow_scaled": 3527982.864381,
"price_last": null,
"inflow_value_last": null,
"outflow_value_last": null,
"netflow_value_last": null,
"from_block": 16332986,
"from_timestamp": 1672830011,
"to_block": 16333284,
"to_timestamp": 1672833599,
"address": "0x6b175474e89094c44da98b954eedeac495271d0f"
},
"dependencies": {...}
}
In the output above, the model ran at block number 16333284 which was the latest at the time of running the model.
inflow_scaled is the amount of DAI transferred to the ZERO address, i.e. the number of tokens that were burned. outflow_scaled is the amount of DAI transferred from the ZERO address, i.e. the number of tokens that were minted.
That would indicate approximately 13.1M DAI were burned and 9.6M DAI were minted in the last hour, a NetFlow of 3.5M DAI
Credmark runs a financial modeling platform powered by reliable on-chain data. We curate and manages DeFi data making it available via API and the Snowflake Marketplace around the globe and across industries.
Our community of quants, developers, and modelers actively build models for the DeFi community by leveraging our data API and tools. Join the growing community and together we will advance the next-generation financial system.
Sign up for our newsletter for the latest product updates, partnerships, and more.