Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #10 from SwipeWallet/develop
Browse files Browse the repository at this point in the history
release v0.0.1
  • Loading branch information
gryincent authored Dec 3, 2020
2 parents 795d7e3 + 7857b86 commit 94f3841
Show file tree
Hide file tree
Showing 44 changed files with 854 additions and 779 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2020 Compound Labs, Inc.
Copyright 2020 Venus Labs, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
104 changes: 52 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Compound.js
# Venus.js

A JavaScript SDK for Ethereum and the Compound Protocol. Wraps around [Ethers.js](https://github.com/ethers-io/ethers.js/). Works in the **web browser** and **Node.js**.
A JavaScript SDK for Ethereum and the Venus Protocol. Wraps around [Ethers.js](https://github.com/ethers-io/ethers.js/). Works in the **web browser** and **Node.js**.

[Compound.js Documentation](https://compound.finance/docs/compound-js)
[Venus.js Documentation](https://docs927beta.venus.io)

This SDK is in **open beta**, and is constantly under development. **USE AT YOUR OWN RISK**.

Expand All @@ -13,12 +13,12 @@ JSON RPC based Ethereum **read** and **write**.
### Read

```js
const Compound = require('@compound-finance/compound-js'); // in Node.js
const cUsdtAddress = Compound.util.getAddress(Compound.cUSDT);
const Venus = require('@swipewallet/venus-js'); // in Node.js
const cUsdtAddress = Venus.util.getAddress(Venus.vUSDT);

(async function() {

let supplyRatePerBlock = await Compound.eth.read(
let supplyRatePerBlock = await Venus.eth.read(
cUsdtAddress,
'function supplyRatePerBlock() returns (uint)',
[], // [optional] parameters
Expand All @@ -37,35 +37,35 @@ const toAddress = '0xa0df350d2637096571F7A701CBc1C5fdE30dF76A';

(async function() {

const trx = await Compound.eth.trx(
const trx = await Venus.eth.trx(
toAddress,
'function send() external payable',
[],
{
value: Compound._ethers.utils.parseEther('1.0'), // 1 ETH
value: Venus._ethers.utils.parseEther('1.0'), // 1 ETH
provider: window.ethereum, // in a web browser
}
);

const toAddressEthBalance = await Compound.eth.getBalance(toAddress);
const toAddressEthBalance = await Venus.eth.getBalance(toAddress);

})().catch(console.error);
```

## Compound Protocol
## Venus Protocol

Simple methods for using the Compound protocol.
Simple methods for using the Venus protocol.

```js
const compound = new Compound(window.ethereum); // in a web browser
const venus = new Venus(window.ethereum); // in a web browser

// Ethers.js overrides are an optional 3rd parameter for `supply`
// const trxOptions = { gasLimit: 250000, mantissa: false };

(async function() {

console.log('Supplying ETH to the Compound protocol...');
const trx = await compound.supply(Compound.ETH, 1);
console.log('Supplying ETH to the Venus protocol...');
const trx = await venus.supply(Venus.ETH, 1);
console.log('Ethers.js transaction object', trx);

})().catch(console.error);
Expand All @@ -76,54 +76,54 @@ const compound = new Compound(window.ethereum); // in a web browser
Web Browser

```html
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@compound-finance/compound-js@latest/dist/browser/compound.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@swipewallet/venus-js@latest/dist/browser/venus.min.js"></script>

<script type="text/javascript">
window.Compound; // or `Compound`
window.Venus; // or `Venus`
</script>
```

Node.js

```
npm install @compound-finance/compound-js
npm install @swipewallet/venus-js
```

```js
const Compound = require('@compound-finance/compound-js');
const Venus = require('@swipewallet/venus-js');

// or, when using ES6

import Compound from '@compound-finance/compound-js';
import Venus from '@swipewallet/venus-js';
```

## More Code Examples

- [Node.js](https://github.com/compound-finance/compound-js/tree/master/examples)
- [Web Browser](https://compound-finance.github.io/compound-js/examples/web/)
- [Node.js](https://github.com/SwipeWallet/venus-js/tree/master/examples)
- [Web Browser](https://github.com/SwipeWallet/venus-js/examples/web/)

[To run, boot Ganache fork of mainnet locally](https://github.com/compound-finance/compound-js/tree/master/examples)
[To run, boot Ganache fork of mainnet locally](https://github.com/SwipeWallet/venus-js/tree/master/examples)

## Instance Creation

The following are valid Ethereum providers for initialization of the SDK.

```js
var compound = new Compound(window.ethereum); // web browser
var venus = new Venus(window.ethereum); // web browser

var compound = new Compound('http://127.0.0.1:8545'); // HTTP provider
var venus = new Venus('http://127.0.0.1:8545'); // HTTP provider

var compound = new Compound(); // Uses Ethers.js fallback mainnet (for testing only)
var venus = new Venus(); // Uses Ethers.js fallback mainnet (for testing only)

var compound = new Compound('ropsten'); // Uses Ethers.js fallback (for testing only)
var venus = new Venus('ropsten'); // Uses Ethers.js fallback (for testing only)

// Init with private key (server side)
var compound = new Compound('https://mainnet.infura.io/v3/_your_project_id_', {
var venus = new Venus('https://mainnet.infura.io/v3/_your_project_id_', {
privateKey: '0x_your_private_key_', // preferably with environment variable
});

// Init with HD mnemonic (server side)
var compound = new Compound('mainnet' {
var venus = new Venus('mainnet' {
mnemonic: 'clutch captain shoe...', // preferably with environment variable
});
```
Expand All @@ -133,10 +133,10 @@ var compound = new Compound('mainnet' {
Names of contracts, their addresses, ABIs, token decimals, and more can be found in `/src/constants.ts`. Addresses, for all networks, can be easily fetched using the `getAddress` function, combined with contract name constants.

```js
console.log(Compound.DAI, Compound.ETH, Compound.cETH);
// DAI, ETH, cETH
console.log(Venus.DAI, Venus.BNB, Venus.vSXP);
// DAI, BNB, vSXP

const cUsdtAddress = Compound.util.getAddress(Compound.cUSDT);
const cUsdtAddress = Venus.util.getAddress(Venus.vUSDT);
// Mainnet cUSDT address. Second parameter can be a network like 'ropsten'.
```

Expand All @@ -146,10 +146,10 @@ Parameters of number values can be plain numbers or their scaled up mantissa val

```js
// 1 Dai
await compound.borrow(Compound.DAI, '1000000000000000000', { mantissa: true });
await venus.borrow(Venus.DAI, '1000000000000000000', { mantissa: true });

// `mantissa` defaults to false if it is not specified or if an options object is not passed
await compound.borrow(Compound.DAI, 1, { mantissa: false });
await venus.borrow(Venus.DAI, 1, { mantissa: false });
```

## Transaction Options
Expand All @@ -163,27 +163,27 @@ const trxOptions = {
provider, // JSON RPC string, Web3 object, or Ethers.js fallback network (string)
network, // Ethers.js fallback network provider, "provider" has precedence over "network"
from, // Address that the Ethereum transaction is send from
gasPrice, // Ethers.js override `Compound._ethers.utils.parseUnits('10.0', 'gwei')`
gasPrice, // Ethers.js override `Venus._ethers.utils.parseUnits('10.0', 'gwei')`
gasLimit, // Ethers.js override - see https://docs.ethers.io/ethers.js/v5-beta/api-contract.html#overrides
value, // Number or string
data, // Number or string
chainId, // Number
nonce, // Number
privateKey, // String, meant to be used with `Compound.eth.trx` (server side)
mnemonic, // String, meant to be used with `Compound.eth.trx` (server side)
privateKey, // String, meant to be used with `Venus.eth.trx` (server side)
mnemonic, // String, meant to be used with `Venus.eth.trx` (server side)
};
```

## API

The [Compound API](https://compound.finance/docs/api) is accessible from Compound.js. The corresponding services are defined in the `api` namespace on the class.
The [Venus API](https://docs927beta.venus.io/docs/api) is accessible from Venus.js. The corresponding services are defined in the `api` namespace on the class.

- `Compound.api.account`
- `Compound.api.cToken`
- `Compound.api.marketHistory`
- `Compound.api.governance`
- `Venus.api.account`
- `Venus.api.cToken`
- `Venus.api.marketHistory`
- `Venus.api.governance`

The governance method requires a second parameter (string) for the corresponding endpoint shown in the [documentation](https://compound.finance/docs/api#GovernanceService).
The governance method requires a second parameter (string) for the corresponding endpoint shown in the [documentation](https://docs927beta.venus.io/docs/venus-js/api#GovernanceService).

- `proposals`
- `voteReceipts`
Expand All @@ -193,23 +193,23 @@ Here is an example for using the `account` endpoint. The `network` parameter in

```js
const main = async () => {
const account = await Compound.api.account({
const account = await Venus.api.account({
"addresses": "0xB61C5971d9c0472befceFfbE662555B78284c307",
"network": "ropsten"
});

let daiBorrowBalance = 0;
let sxpBorrowBalance = 0;
if (Object.isExtensible(account) && account.accounts) {
account.accounts.forEach((acc) => {
acc.tokens.forEach((tok) => {
if (tok.symbol === Compound.cDAI) {
if (tok.symbol === Venus.vSXP) {
daiBorrowBalance = +tok.borrow_balance_underlying.value;
}
});
});
}

console.log('daiBorrowBalance', daiBorrowBalance);
console.log('sxpBorrowBalance', sxpBorrowBalance);
}

main().catch(console.error);
Expand All @@ -218,26 +218,26 @@ main().catch(console.error);
## Build for Node.js & Web Browser

```
git clone [email protected]:compound-finance/compound-js.git
cd compound-js/
git clone [email protected]:SwipeWallet/venus-js.git
cd venus-js/
npm install
npm run build
```

### Web Browser Build
```html
<!-- Local build (do `npm install` first) -->
<script type="text/javascript" src="./dist/browser/compound.min.js"></script>
<script type="text/javascript" src="./dist/browser/venus.min.js"></script>

<!-- Public NPM -> jsdeliver build -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@compound-finance/compound-js@latest/dist/browser/compound.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@swipewallet/venus-js@latest/dist/browser/venus.min.js"></script>
```

### Node.js Build
```js
// Local build (do `npm install` first)
const Compound = require('./dist/nodejs/index.js');
const Venus = require('./dist/nodejs/index.js');

// Public NPM build
const Compound = require('@compound-finance/compound-js');
const Venus = require('@swipewallet/venus-js');
```
Loading

0 comments on commit 94f3841

Please sign in to comment.