forked from BitGo/smart-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repayBorrow.ts
28 lines (22 loc) · 1.2 KB
/
repayBorrow.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
import { getContractsFactory } from '../../../src/index';
const repayTokenName = 'USDC';
const compoundTokenName = 'cUSDC';
const repayAmount = 1e5; // 0.1 USDC
const underlyingTokenContract = getContractsFactory('eth').getContract('StandardERC20').instance(repayTokenName);
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, address } = underlyingTokenContract.methods().approve.call(
{
_spender: compoundTokenContract.address,
_value: repayAmount.toString(10),
});
console.log(`To approve ${repayAmount} ${repayTokenName} to compound token contract, send:`);
console.log(`Data: ${data}`);
console.log(`Amount: ${amount} ETH`);
console.log(`To: ${address}`);
// Then we can tell the compound contract that we want to repay
({ data, amount, address } = compoundTokenContract.methods().repayBorrow.call({ repayAmount: repayAmount.toString(10) }));
console.log(`\nTo repay ${repayAmount} ${repayTokenName} from compound, send:`);
console.log(`Data: ${data}`);
console.log(`Amount: ${amount} ETH`);
console.log(`To: ${compoundTokenContract.address}`);