forked from BitGo/smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlend.ts
29 lines (22 loc) · 1.14 KB
/
lend.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Contract } from '../../src/contract';
const underlyingTokenName = 'DAI';
const compoundTokenName = 'cDAI';
const lendAmount = 1e18; // 1 DAI
const underlyingTokenContract = new Contract('StandardERC20').instance(underlyingTokenName);
const compoundTokenContract = new Contract('Compound').instance(compoundTokenName);
// First we need to approve the amount of DAI for the compound DAI contract to control
let { data, amount, address } = underlyingTokenContract.methods().approve.call(
{
_spender: compoundTokenContract.getAddress(),
_value: lendAmount.toString(10),
});
console.log(`To approve ${lendAmount} ${underlyingTokenName} to compound token contract, send:`);
console.log(`Data: ${data}`);
console.log(`Amount: ${amount} ETH`);
console.log(`To: ${address}`);
// Then, once the above tx is confirmed, we can mint our new cTokens
({ data, amount, address } = compoundTokenContract.methods().mint.call({ mintAmount: lendAmount.toString(10) }));
console.log(`\nTo exchange ${lendAmount} ${underlyingTokenName} for compound tokens, send:`);
console.log(`Data: ${data}`);
console.log(`Amount: ${amount} ETH`);
console.log(`To: ${address}`);