일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- SBT표준
- ethers websocket
- 스마트컨트렉트 예약어 함수이름 중복
- ethers
- chainlink 설명
- 스마트 컨트렉트 함수이름 중복
- erc4337 contract
- 러스트 기초 학습
- ethers typescript
- rust 기초
- Vue.js
- 티스토리챌린지
- 컨트렉트 동일한 함수이름 호출
- ambiguous function description
- 러스트 기초
- Vue
- ethers type
- ethers v6
- 체인의정석
- 스마트컨트렉트 함수이름 중복 호출
- 계정추상화
- erc4337
- git rebase
- multicall
- 스마트컨트렉트테스트
- 컨트렉트 배포 자동화
- 오블완
- vue기초
- 머신러닝기초
- 러스트기초
- Today
- Total
체인의정석
compound 실행 순서 총정리 본문
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>
'블록체인 > 퍼블릭 블록체인' 카테고리의 다른 글
Crypto scam DB) 이더리움 스캠 주소 데이터, 신고하고 보상받기 (0) | 2021.09.13 |
---|---|
EtherScan API 사용하여 데이터 가져오기 (0) | 2021.09.13 |
solidity 5.0 => 6.0 버전업 문법 변화 주의사항 (0) | 2021.02.08 |
Solidity - assert VS require (0) | 2021.02.01 |
Solidity 코드 로컬환경 & Remix에서 배포하기 (0) | 2021.01.28 |