Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Latest commit

 

History

History
236 lines (168 loc) · 12 KB

README.md

File metadata and controls

236 lines (168 loc) · 12 KB

Unlockd logo Unlockd logo

figma typescript solidity google-cloud

Unlockd is a decentralized non-custodial NFT lending protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized fashion, using NFTs as collaterl.

This repository contains the smart contracts source code and markets configuration for Unlockd Protocol. The repository uses Hardhat as development enviroment for compilation, testing and deployment tasks.


🙇‍♂️ Thanks Unlockd protocol refers to the architecture design and adopts some of the code of AAVE. We are very grateful to AAVE for providing us with an excellent DeFi platform.

You can join at the Discord channel or at the Governance for asking questions about the protocol or talk about Unlockd with other peers.

🗂️ Index

📝 Documentation

The documentation of Unlockd Protocol is in the following Unlockd documentation link. At the documentation you can learn more about the protocol, see the contract interfaces, integration guides and audits.

For getting the latest contracts addresses, please check the Deployed contracts page at the documentation to stay up to date.

🎬 Setup

  • Install

To run Unlockd, install its dependencies using yarn. You will need yarn installed in your system.

yarn install
  • Create an enviroment file named .env and fill the next enviroment variables
# Private key. Add it if you just want to interact with Hardhat with a single address.
PRIVATE_KEY=""

# Mnemonic. Used by Hardhat if PRIVATE_KEY is not set. Also used in  `./unlockd-tasks`.
MNEMONIC=""

# Used in `./unlockd-tasks` to simulate a user different than the owner.
PRIVATE_KEY_USER=""

# Alchemy/Infura RPC endpoint URL.
RPC_ENDPOINT=""

# Optional Etherscan key, for automatize the verification of the contracts at Etherscan
ETHERSCAN_KEY=""
ETHERSCAN_NETWORK="" # network in use

# Optional, add it if you want to run tasks in a forked network environment
FORK=""

# Optional, add it if you want to specify block number running tasks in a forked network
FORK_BLOCK_NUMBER=""

🧪 Test

You can run the full test suite with the following commands. All of them are explained in detail in the tasks section:

yarn test

yarn test:localhost

yarn test:file

Markets configuration

The configurations related with the Unlockd Markets are located at markets directory. You can follow the IUnlockdConfiguration interface to create new Markets configuration or extend the current Unlockd configuration.

Each market should have his own Market configuration file, and their own set of deployment tasks, using the Unlockd market config and tasks as a reference.

✅ Tasks

General tasks

You can run the general tasks defined in the package.json file by using yarn and specifying the task you want to run. For example, we can run the compile task with the following command:

yarn compile
Show general tasks
Task Description
run-env Installs dependencies without verbose logging
hardhat Executes hardhat command
hardhat:node Starts a Hardhat Network node
hardhat:localhost Executes hardhat command, setting network to localhost
hardhat:goerli Executes hardhat command, setting network to goerli
hardhat:main Executes hardhat command, setting network to main
size Logs size of current contracts
compile Compiles the contracts
test Runs all tests in ./test/, setting network to Hardhat network
test:localhost Runs all tests in ./test/, setting network to localhost network
test:file Allows to test for a specific file. The file can be specified in the command line setting it to be equal to TEST_FILE var
dev:update-abis Fetches abis from latest contracts data in ./artifacts and sets them to ./abis folder
prettier:abis Standarizes the abis code style in ./abis folder
prettier:check Checks the code style in the project
prettier:write Standarizes the code style in the project
ci:clean Runs a hardhat clean and removes all temporal and autogenerated files and folders
unlockd:hardhat:dev:migration Deploys the Unlockd protocol development environment in the hardhat network
unlockd:localhost:dev:migration Deploys the Unlockd protocol development environment in localhost
unlockd:goerli:mock:migration Deploys mock environment in Goerli testnet
unlockd:localhost:full:migration Deploys the full Unlockd protocol in localhost
unlockd:goerli:full:migration Deploys the full Unlockd protocol in Goerli testnet
unlockd:fork:full:migration Deploys the full Unlockd protocol in the forked network of choice, set at the environment variables
unlockd:main:full:migration Deploys the full Unlockd protocol in Ethereum mainnet
goerli:verify Verifies in Etherscan all contracts deployed in Goerli
goerli:verify:reserves Verifies in Etherscan all reserves contracts deployed in Goerli testnet
goerli:print-contracts Prints all current deployed contracts in Goerli testnet
goerli:print-config Prints all addresses and configuration set in Goerli deployed contracts
main:verify Verifies in Etherscan all reserves contracts deployed in Ethereum mainnet
main:verify:reserves Verifies in Etherscan all reserves contracts deployed in Ethereum mainnet
main:print-contracts Prints all current deployed contracts in Ethereum mainnet
main:print-config Prints all addresses and configuration set in Ethereum mainnet deployed contracts

🚀 Deployments

For deploying Unlockd Protocol, you can use the available scripts located at package.json. For a complete list, run npm run to see all the tasks.

Prepare

# install dependencies
yarn install

Localhost dev deployment

# In first terminal
npm run hardhat:node

# In second terminal
npm run unlockd:localhost:dev:migration

Localhost full deployment

# In first terminal
npm run hardhat:node

# In second terminal
npx hardhat --network localhost "dev:deploy-mock-reserves"
# then update pool config reserve address

npx hardhat --network localhost "dev:deploy-mock-nfts"
# then update pool config nft address

npx hardhat --network localhost "dev:deploy-all-mock-aggregators" --pool Unlockd
# then update pool config reserve aggregators address

npx hardhat --network localhost "dev:deploy-mock-unft-registry" --pool Unlockd
# then update pool config unft registry address

npx hardhat --network localhost "dev:deploy-mock-unft-tokens" --pool Unlockd

Goerli mock deployment (a full deployment may not run because of ERC20 and ERC721 Reserves)

# In one terminal
npm run unlockd:goerli:mock:migration

Interact with Unlockd in Mainnet via console

You can interact with Unlockd at Mainnet network using the Hardhat console, in the scenario where the frontend is down or you want to interact directly. You can check the deployed addresses at deployed-contracts.

Run the Hardhat console pointing to the Mainnet network:

npx hardhat --network main console

At the Hardhat console, you can interact with the protocol:

// Load the HRE into helpers to access signers
run("set-DRE");

// Import getters to instance any Unlockd contract
const contractGetters = require("./helpers/contracts-getters");

// Load the first signer
const signer = await contractGetters.getFirstSigner();

// Lend pool instance
const lendPool = await contractGetters.getLendPool("");

// ERC20 token WETH Mainnet instance
const WETH = await contractGetters.getIErc20Detailed("");

// Approve 10 WETH to LendPool address
await WETH.connect(signer).approve(lendPool.address, ethers.utils.parseUnits("10"));

// Deposit 10 WETH
await lendPool.connect(signer).deposit(DAI.address, ethers.utils.parseUnits("10"), await signer.getAddress(), "0");