strkfarm / starkfarm-client

https://www.strkfarm.xyz/
GNU Affero General Public License v3.0
13 stars 24 forks source link

feature: Integrate vesu.xyz #79

Open akiraonstarknet opened 1 month ago

akiraonstarknet commented 1 month ago

Is your feature request related to a problem? Please describe. Vesu.xyz is a new lending protocol on starknet and growing fast. Let's include their supply markets info on our Find pools tab

Describe the solution you'd like Similar to Nostra MM and zklend, integrate vesu

Requirements from contributor:

  1. If you are a new contributor, please share your experience with NextJS, typescript, Jotai and API in simple terms in comment.
  2. I can connect you with vesu team to get necessary data (APIs/contracts) from them
  3. Markets to integrate: ETH/USDC/USDT/BTC/wstETH
EjembiEmmanuel commented 1 month ago

@akiraonstarknet can I work on this?

Ugo-X commented 1 month ago

Hey Akira, I already worked on Nostra MM and would be able to handle this, can I be assigned to this?

josephchimebuka commented 1 month ago

Hello @akiraonstarknet I would like to work on this. I have worked with Nextjs, typescript, fetched APIS and also integrated state management in them too. Here are a couple of Nextjs and typescript projects I have worked on https://metacrypt.vercel.app/ https://mattedsgn.com/

akiraonstarknet commented 1 month ago

@josephchimebuka this issue is a little priority, so assigning to someone experienced in this task.

akiraonstarknet commented 1 month ago

Hey @Ugo-X, since vesu doesn't have an API, here's what to do to get pool APYs.

Broadly, their APY formula is utilization * ((1+interest_rate/10^18)^(360*86400) - 1). So for each pool, you will need current utilization and current interest rate to get this formula.

1. Compute Utilisation:

Contract: https://starkscan.co/contract/0x02545b2e5d519fc230e9cd781046d3a64e092114f07e44771e0d719d148725ef#read-write-contract
method: utilization_unsafe(pool_id,asset)
- pool_id is 2198503327643286920898110335698706244522220458610657370981979460625005526824
- asset is token address of the pool we want (i.e. TokenInfo.token from our TokenInfo array in constants file)

BTW, the output number is in 1018 terms (i.e. raw format, e.g. 653339095735462051), so should be divided with 1018 to get actual utilization factor (e.g. `653339095735462051/ 1018 = 0.6533`) (so that u can use in above APY formula).**

2. Compute interest rate

2.1. First need to get some asset info:**

contract: https://starkscan.co/contract/0x02545b2e5d519fc230e9cd781046d3a64e092114f07e44771e0d719d148725ef#read-write-contract
method: asset_config_unsafe(pool_id,asset)
- arguments same as above

You will get an output something like this. From this, last_updated & last_full_utilization_rate value is required. image

2.2. Compute interest rate**

contract: https://starkscan.co/contract/0x002334189e831d804d4a11d3f71d4a982ec82614ac12ed2e9ca2f8da4e6374fa
method: interest_rate(pool_id,asset,utilization,last_updated,last_full_utilization_rate)
- pool_id same as above
- asset logic same as above
- utilization is the raw amount you got in Step 1
- last_updated & last_full_utilization_rate are values you got in step 2.1

Output will be raw interest rate (e.g. 1852500364).

Now APY = utilization * ((1+interest_rate/10^18)^(360*86400) - 1)

=> 0.65 * ((1 + 1852500364 / 10**18)^(360 * 86400) - 1)
=> 0.03855316531
=> 3.855 %  // this base APY of USDC currently