-
Notifications
You must be signed in to change notification settings - Fork 9
/
lend.ts
29 lines (22 loc) · 1.23 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 { getContractsFactory } from '../../../src/index';
const underlyingTokenName = 'DAI';
const compoundTokenName = 'cDAI';
const lendAmount = 1e18; // 1 DAI
const underlyingTokenContract = getContractsFactory('eth').getContract('StandardERC20').instance(underlyingTokenName);
const compoundTokenContract = getContractsFactory('eth').getContract('Compound').instance(compoundTokenName);
// First we need to approve the amount of DAI for the compound DAI contract to control
let { data, amount } = underlyingTokenContract.methods().approve.call(
{
_spender: compoundTokenContract.address,
_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: ${underlyingTokenContract.address}`);
// Then, once the above tx is confirmed, we can mint our new cTokens
({ data, amount } = 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: ${compoundTokenContract.address}`);