체인의정석

compound 실행 순서 총정리 본문

블록체인/퍼블릭 블록체인

compound 실행 순서 총정리

체인의정석 2021. 2. 22. 11:04
728x90
반응형

medium.com/compound-finance/supplying-assets-to-the-compound-protocol-ec2cf5df5aa

 

Supplying Assets to the Compound Protocol

Learn how to supply assets to the Compound protocol through JSON RPC and proxy smart contracts

medium.com

 

The function first creates references to the production instances of Dai and cDAI contracts using our interface definitions.

Then the function logs the exchange rate and the supply rate. These calls are not necessary for supplying. They are there for illustration. You can see the amounts in the “events” output later in JavaScript.

Next, our function approves the transfer of ERC20 token from our contract’s address to Compound’s cToken contract using the approve method.

Finally, our contract calls the cToken contract mint function. This supplies some Dai to the protocol, and gives our custom contract a balance of cDAI.

After we have supplied some Dai, we can redeem it at any time. The following function shows how we can accomplish that in Solidity.

 

1-1. 이더리움 예치시키기

-> msg.value에 이더리움 넣기

-> mint cETH ()

 

 

 

 

2-2. ERC20 예치시키기

-> approve ERC20 token (Erc20 토큰 주소에서 approve를 cERC20 Token에다가 줌)

-> mint ERC20 token ()

 

 

 

medium.com/compound-finance/borrowing-assets-from-compound-quick-start-guide-f5e69af4b8f4

 

Borrowing Assets from the Compound Protocol

Quick Start Guide

medium.com

2-1. 자산 빌려오기(borrow) : 이더리움을 담보로 하여 erc20토큰 빌려오기

-> 컴파운드에 1 eth supply

-> comptroller를 사용하여 ETH를 collateral로 사용하겠다고 말함

-> compotroller를 사용하여 collateral factor를 가져옴

-> price oracle을 사용하여 ETH에서 Dai price를 가져옴

-> Calculate our maximum Dai borrow

-> 블록당 이자율 계산

-> DAI 빌려옴

-> 잔고 확인

-> 빌려온 액수만큼 다시 repay

 

함수 실행 순서

-> cETH - mint  

 

-> comptroller - entermarkets (cETH address) <send>

-> comptroller - getAccountLiquidity (내 지갑주소) <call>

공식 테스트넷에서 시도

[ getAccountLiquidity method Response ]
    uint256 :  0
    uint256 :  0
    uint256 :  0

 

-> comptorller - markets (cETH address) <call>

collateralFactor = (collateralFactor / 1e18) * 100; // Convert to percent

0:
bool: isListed true
1:
uint256: collateralFactorMantissa 0
2:
bool: isComped false

-> pricefeed - price (asset Name) <call>

// Price feed provides price in USD with 6 decimal places

 

-> cToken - borrowRatePerBlock <call>

 

*decimal 맞춰주기

const scaledUpBorrowAmount = (underlyingToBorrow * Math.pow(10, underlyingDecimals)).toString();

-> cToken - borrow(scaledUpBorrowAmount) <send>

 

-> cToken - borrowBalanceCurrent <call>

 

-> cToken - repayBorrow <send>

728x90
반응형
Comments