kandi background
Explore Kits

compound-supply-examples | Code examples for supplying Ethereum assets | Cryptocurrency library

 by   compound-developers JavaScript Version: Current License: MIT

 by   compound-developers JavaScript Version: Current License: MIT

Download this library from

kandi X-RAY | compound-supply-examples Summary

compound-supply-examples is a JavaScript library typically used in Financial Services, Fintech, Blockchain, Cryptocurrency, Ethereum applications. compound-supply-examples has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.
Compound is an open-source, decentralized autonomous protocol built for developers, to unlock a universe of new financial applications. Users can earn interest on their crypto assets and borrow crypto assets. Learn more on the website:.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • compound-supply-examples has a low active ecosystem.
  • It has 98 star(s) with 35 fork(s). There are 4 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 0 open issues and 6 have been closed. On average issues are closed in 96 days. There are 1 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of compound-supply-examples is current.
This Library - Support
Best in #Cryptocurrency
Average in #Cryptocurrency
This Library - Support
Best in #Cryptocurrency
Average in #Cryptocurrency

quality kandi Quality

  • compound-supply-examples has 0 bugs and 0 code smells.
This Library - Quality
Best in #Cryptocurrency
Average in #Cryptocurrency
This Library - Quality
Best in #Cryptocurrency
Average in #Cryptocurrency

securitySecurity

  • compound-supply-examples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • compound-supply-examples code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
This Library - Security
Best in #Cryptocurrency
Average in #Cryptocurrency
This Library - Security
Best in #Cryptocurrency
Average in #Cryptocurrency

license License

  • compound-supply-examples is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
This Library - License
Best in #Cryptocurrency
Average in #Cryptocurrency
This Library - License
Best in #Cryptocurrency
Average in #Cryptocurrency

buildReuse

  • compound-supply-examples releases are not available. You will need to build from source code and install.
  • Installation instructions, examples and code snippets are available.
This Library - Reuse
Best in #Cryptocurrency
Average in #Cryptocurrency
This Library - Reuse
Best in #Cryptocurrency
Average in #Cryptocurrency
Top functions reviewed by kandi - BETA

kandi has reviewed compound-supply-examples and discovered the below as its top functions. This is intended to give you an instant insight into compound-supply-examples implemented functionality, and help decide if they suit your requirements.

  • Speeds a new address to the given address
  • supports a compound contract
  • supports the enclosed address to the end of the chain
  • Requests redeemor tokens from the blockchain .
  • Transfer an address to the receiver .
  • Rewrite transactions to redeem transaction .
  • Get current exchange rate
  • Get the balance of an asset
  • Get the balance of the given account .
  • Main entry point

compound-supply-examples Key Features

Code examples for supplying Ethereum assets to the Compound Protocol.

Setup

copy iconCopydownload iconDownload
git clone git@github.com:compound-developers/compound-supply-examples.git
cd compound-supply-examples/
npm install

Running a Local Ethereum Testnet with Hardhat

copy iconCopydownload iconDownload
cd compound-supply-examples/

## Set environment variables for the script to use
export MAINNET_PROVIDER_URL="https://mainnet.infura.io/v3/<YOUR INFURA API KEY HERE>"
export DEV_ETH_MNEMONIC="clutch captain shoe salt awake harvest setup primary inmate ugly among become"

## Runs the Hardhat node locally
## Also seeds your first mnemonic account with test Ether and ERC20s
node ./scripts/run-localhost-fork.js

Script Output Examples

copy iconCopydownload iconDownload
$ node ./examples-js/web3-js/supply-eth.js
My wallet's ETH balance: 10000

Supplying ETH to the Compound Protocol...

cETH "Mint" operation successful.

ETH supplied to the Compound Protocol: 0.999999999922754

My wallet's cETH Token Balance: 49.86379983

Current exchange rate from cETH to ETH: 0.020054628875698224

Redeeming the cETH for ETH...

Exchanging all cETH based on cToken amount...

My wallet's cETH Token Balance: 0
My wallet's ETH balance: 9999.993847840284

Ethers.js & Compound.js Examples

copy iconCopydownload iconDownload
## Ethers.js Examples
node ./examples-solidity/ethers-js/supply-erc20.js
node ./examples-solidity/ethers-js/supply-eth.js
node ./examples-js/ethers-js/supply-erc20.js
node ./examples-js/ethers-js/supply-eth.js

## Compound.js Examples
node ./examples-solidity/compound-js/supply-erc20.js
node ./examples-solidity/compound-js/supply-eth.js
node ./examples-js/compound-js/supply-erc20.js
node ./examples-js/compound-js/supply-eth.js

## Web3.js
node ./examples-solidity/web3-js/supply-erc20.js
node ./examples-solidity/web3-js/supply-eth.js
node ./examples-js/web3-js/supply-erc20.js
node ./examples-js/web3-js/supply-eth.js

I am having a difficulty of understanding interfaces in Solidity. What am I missing?

copy iconCopydownload iconDownload
interface IERC20 { 
   function totalSupply() external view returns (uint256);
}

contract XYZ is IERC20 {
// then implement totalSupply here 
function totalSupply() external view returns (uint256) {
// implementiation goes here. 
address public add='0x123...4'
}
interface CEth {
    function mint() external payable;

    function exchangeRateCurrent() external returns (uint256);

    function supplyRatePerBlock() external returns (uint256);

    function redeem(uint) external returns (uint);

    function redeemUnderlying(uint) external returns (uint);
}
CEth cToken = CEth(_cEtherContract);
-----------------------
interface IERC20 { 
   function totalSupply() external view returns (uint256);
}

contract XYZ is IERC20 {
// then implement totalSupply here 
function totalSupply() external view returns (uint256) {
// implementiation goes here. 
address public add='0x123...4'
}
interface CEth {
    function mint() external payable;

    function exchangeRateCurrent() external returns (uint256);

    function supplyRatePerBlock() external returns (uint256);

    function redeem(uint) external returns (uint);

    function redeemUnderlying(uint) external returns (uint);
}
CEth cToken = CEth(_cEtherContract);
-----------------------
interface IERC20 { 
   function totalSupply() external view returns (uint256);
}

contract XYZ is IERC20 {
// then implement totalSupply here 
function totalSupply() external view returns (uint256) {
// implementiation goes here. 
address public add='0x123...4'
}
interface CEth {
    function mint() external payable;

    function exchangeRateCurrent() external returns (uint256);

    function supplyRatePerBlock() external returns (uint256);

    function redeem(uint) external returns (uint);

    function redeemUnderlying(uint) external returns (uint);
}
CEth cToken = CEth(_cEtherContract);

Community Discussions

Trending Discussions on compound-supply-examples
  • I am having a difficulty of understanding interfaces in Solidity. What am I missing?
Trending Discussions on compound-supply-examples

QUESTION

I am having a difficulty of understanding interfaces in Solidity. What am I missing?

Asked 2020-Nov-08 at 03:30

I came from Java OOP background and understand interfaces.

Currently working on a simple budgeting app (https://github.com/compound-developers/compound-supply-examples) that takes ETH or Stablecoin and put in in Compound and earn interest.

My confusion is how Solidity Interfaces are used. I came from OOP (Java) background and very familiar with interfaces.

So in this code(MyContracts.sol) you can see that there is a mint() function in the interface. However, there is no implementation for it but you can see that it's used here uint mintResult = cToken.mint(_numTokensToSupply); without any implementation.

Can anyone shade some lights on how interface functions are used without implementations ? When you call mint in this case, which code is actually being executed ?

ANSWER

Answered 2020-Nov-08 at 03:30

I believe I got the main issue that was confusing to me.

So if you come from OOP background this what we know about interfaces:

interface IERC20 { 
   function totalSupply() external view returns (uint256);
}

contract XYZ is IERC20 {
// then implement totalSupply here 
function totalSupply() external view returns (uint256) {
// implementiation goes here. 
address public add='0x123...4'
}

So at this point you can call XYZ's totalSupply() and you should be fine.

However, there is another way of using interfaces in Solidity. I will take this code from compound protocol as an example (https://github.com/compound-developers/compound-supply-examples)

If you see MyContracts.sol, it has the following interface:

interface CEth {
    function mint() external payable;

    function exchangeRateCurrent() external returns (uint256);

    function supplyRatePerBlock() external returns (uint256);

    function redeem(uint) external returns (uint);

    function redeemUnderlying(uint) external returns (uint);
}

However, there is no place in our contract that uses the keyword IS and implements any of the methods. So you might ask how is our interface being used ?

Now let's go back to MyContract contract in MyContracts.sol file and see this code under supplyEthToCompound function:

CEth cToken = CEth(_cEtherContract);

Here we are providing CEth interface with a contract address of Compound (i.e _cEtherContract and the contract at that address has a mint() function.)

When you call cToken.exchangeRateCurrent(); on the next line, what happens is we are basically calling a function exchangeRateCurrent on Compound Contract.

At first it seems like exchangeRateCurrent has no implementation in the file we are calling it but the implementation resides at _cEtherContract address.

I hope this clears the confusion especially if you come from traditional OOP background.

Feel free to point out anything that is misleading in my answer.

Source https://stackoverflow.com/questions/64733976

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install compound-supply-examples

The code in this repository can be used to supply assets to Compound on the Mainnet, any public test net, or your own localhost with Hardhat.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Reuse Pre-built Kits with compound-supply-examples
Consider Popular Cryptocurrency Libraries
Compare Cryptocurrency Libraries with Highest Support
Compare Cryptocurrency Libraries with Highest Quality
Compare Cryptocurrency Libraries with Highest Security
Compare Cryptocurrency Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.