Aave.

Post

Share your knowledge.

Aaveator.
Jan 25, 2023
Discussion

How to tell the code to, rather than "deposit 1 eth worth of WBTC" deposit "500$ worth of WBTC"?

Is there a way to tell the code to, rather than "deposit 1 eth worth of WBTC" deposit "500$ worth of WBTC" Lets say I am depositing 0.01 WBTC, but I want to work with USD in my app, so I want to be able to tell the app to deposit "284,96$" in WBTC rather than "0.01 ether". Is that possible ?

Can't find anything related to that in the Aave documentation

  • Aave Protocol
2
2
Share
Comments
.

Answers

2
Kryptouutiset.
Jan 25 2023, 14:57

To deposit a certain dollar value worth of a token, such as WBTC, on a decentralized lending platform like AAVE, you would need to first convert the dollar value to the equivalent value in the token using the current exchange rate. Then you would use the smart contract function for depositing the token on the platform, providing the converted token value as an argument.

Here is an example of how you might accomplish this using the web3.js library and the AAVE smart contract:

First, you would need to retrieve the current exchange rate for WBTC. You can do this by calling an API that provides the exchange rate or using a library like Uniswap-sdk to get the token price.

Once you have the exchange rate, you can calculate the amount of WBTC that is equivalent to $500 by dividing $500 by the exchange rate.

Then you can use the web3.js library to interact with the AAVE smart contract and call the deposit function, providing the amount of WBTC calculated in step 2 as the argument.

Here's an example of how you might call the deposit function:

web3.eth.contract(aaveAbi).at(aaveAddress).deposit(wbtcAddress,web3.toWei(wbtcAmount,'ether'),{from:accountAddress,value:0})

It's worth noting that you should always ensure that you are using the correct smart contract ABI and address for the platform you are interacting with, and also keep in mind that gas fee cost will vary depending on the Ethereum network conditions.

2
Comments
.
Aaveator.
Feb 2 2023, 17:26

Every function that takes an amount will be in the units of the asset you’re performing the action with. So if you’re trying to supply 0.1 WBTC, the amount field will be 10000000 because WBTC has 7 decimals. If you want to calculate how much WBTC corresponds to an amount in ETH, USD, etc. you’ll have to perform this conversion before you call the supply function;

More info.

0
Comments
.

Do you know the answer?

Please log in and share it.

We use cookies to ensure you get the best experience on our website.
More info